diff --git a/deltabar/deltabar_lib/deltabar_lib.py b/deltabar/deltabar_lib/deltabar_lib.py index fc0da08..c9c34c8 100644 --- a/deltabar/deltabar_lib/deltabar_lib.py +++ b/deltabar/deltabar_lib/deltabar_lib.py @@ -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: @@ -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() @@ -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): @@ -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: diff --git a/deltabar/deltabar_lib/lap.py b/deltabar/deltabar_lib/lap.py index 162a4eb..9f4a3bb 100644 --- a/deltabar/deltabar_lib/lap.py +++ b/deltabar/deltabar_lib/lap.py @@ -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() @@ -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]