Skip to content

Commit

Permalink
potential workaround for issue 7, with notes
Browse files Browse the repository at this point in the history
  • Loading branch information
jamessanford committed Oct 13, 2015
1 parent eab3334 commit c635cd0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
22 changes: 16 additions & 6 deletions deltabar/deltabar_lib/deltabar_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ def acUpdate(self, delta_t):
self.reinitialize_app()
self.reinitialize_statusbox()

pos = ac.getCarState(0, acsys.CS.NormalizedSplinePosition)

if self.lap is None:
if self.lap_wait is not None:
if time.time() < self.lap_wait:
Expand All @@ -230,10 +228,6 @@ def acUpdate(self, delta_t):
if ac.getCarState(0, acsys.CS.LapTime) == 0:
# Only record once the clock is ticking.
return
elif pos > 0.5:
# It appears we have not reached the start line yet.
# Or at least, not that we know about.
return
else:
self.lap = lap.Lap()
self.init_lap()
Expand All @@ -242,6 +236,7 @@ def acUpdate(self, delta_t):
current_sector = sim_info.info.graphics.currentSectorIndex

# NOTE: When acsys.CS.LapInvalidated works, add here or at numberOfTyresOut.
#
# Exceptional cases that we need to handle first.
if (current_lap < self.lap.lap_number or
sim_info.info.graphics.session != self.last_session):
Expand All @@ -255,6 +250,21 @@ def acUpdate(self, delta_t):
self.lap_wait = time.time() + 2.0 # Do not begin a new lap for 2 seconds.
return

pos = ac.getCarState(0, acsys.CS.NormalizedSplinePosition)
# NOTE: this is probably buggy, because sometimes the lap timer is running
# after resetting the car, but the car is not in the right spot.
#
# if that happens,
# we'll start recording wherever the car happens to be,
# but then we will go over 1.0, and wrap,
# but our historic data (and future data) will not wrap,
# so the delta times will not be found
#
# we should probably only allow this for KNOWN tracks that wrap.
# if it has wrapped and we know this track wraps...
if self.lap.position_wrapped(pos):
pos += 1.0

if not self.data.sectors_available:
# See if they have become available now.
if current_sector > 0:
Expand Down
15 changes: 15 additions & 0 deletions deltabar/deltabar_lib/lap.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self):
self.invalid_sectors = [] # should be False * sectorCount
self.lap_time = 0 # added when complete
self.splits = [] # added when available
self.wrapped = False # normalizedSplinePosition has wrapped during lap
self.fromfile = False # true when loaded from lap serializer

# internal state for reusing the objects during add()
Expand All @@ -37,6 +38,20 @@ def __init__(self):
self.gear = array.array('b')
self.distance_traveled = array.array('d') # for this lap only.

def position_wrapped(self, offset):
if self.wrapped:
return True

if self._next_index > 1:
first = self.offset[0]
last = self.offset[self._next_index - 1]

if offset < first and (offset - 0.05) < 0.0 and (last + 0.05) > 1.0:
self.wrapped = True
return True

return False

def next_offset_ok(self, offset):
if self._next_index > 0:
last = self.offset[self._next_index - 1]
Expand Down

0 comments on commit c635cd0

Please sign in to comment.