GE Lua Documentation

Press F to search!

updateFastFromRace

Definition


-- @/lua/ge/extensions/core/lapTimes.lua:156

-- Update fast-changing data from race state
local function updateFastFromRace(race, playerId)
  if not race or not race.states or not race.states[playerId] then
    return
  end

  local state = race.states[playerId]

  -- Update current time
  currentTime = race.time or currentTime

  -- Calculate current lap/segment data
  local currentLapStart = state.startTime or 0
  if state.currentLap ~= 0 and #state.historicTimes > 0 then
    currentLapStart = state.historicTimes[#state.historicTimes].endTime
  end

  local segmentStart = currentLapStart
  if #state.currentTimes > 0 then
    segmentStart = state.currentTimes[#state.currentTimes].endTime
  end

  -- Calculate current lap and segment durations
  local currentLapDuration, currentSegmentDuration
  if state.complete then
    currentLapDuration = math.max(0, (state.endTime or 0) - currentLapStart)
    currentSegmentDuration = math.max(0, (state.endTime or 0) - segmentStart)
  else
    currentLapDuration = math.max(0, (race.time or 0) - currentLapStart)
    currentSegmentDuration = math.max(0, (race.time or 0) - segmentStart)
  end

  -- Populate fast stream data directly
  table.clear(fastStreamData)

  fastStreamData.currentTime = currentTime
  fastStreamData.currentTimeFormatted = M.formatTime(currentTime)

  -- Build lap data directly in stream
  if currentLapStart ~= nil then
    fastStreamData.currentLapTime = currentLapDuration
    fastStreamData.currentLapTimeFormatted = M.formatTime(currentLapDuration)
    fastStreamData.currentLapDiffToBest = nil
    fastStreamData.currentLapDiffToBestFormatted = nil
    fastStreamData.currentLapDiffToBestFlavor = nil
    fastStreamData.currentLapDiffToPrevious = nil
    fastStreamData.currentLapDiffToPreviousFormatted = nil
    fastStreamData.currentLapDiffToPreviousFlavor = nil
  else
    fastStreamData.currentLapTime = 0
    fastStreamData.currentLapTimeFormatted = M.formatTime(0)
    fastStreamData.currentLapDiffToBest = nil
    fastStreamData.currentLapDiffToBestFormatted = nil
    fastStreamData.currentLapDiffToBestFlavor = nil
    fastStreamData.currentLapDiffToPrevious = nil
    fastStreamData.currentLapDiffToPreviousFormatted = nil
    fastStreamData.currentLapDiffToPreviousFlavor = nil
  end

  -- Build segment data directly in stream
  if segmentStart ~= nil then
    fastStreamData.currentSegmentTime = currentSegmentDuration
    fastStreamData.currentSegmentTimeFormatted = M.formatTime(currentSegmentDuration)
    fastStreamData.currentSegmentDiffToBest = nil
    fastStreamData.currentSegmentDiffToBestFormatted = nil
    fastStreamData.currentSegmentDiffToBestFlavor = nil
    fastStreamData.currentSegmentDiffToPrevious = nil
    fastStreamData.currentSegmentDiffToPreviousFormatted = nil
    fastStreamData.currentSegmentDiffToPreviousFlavor = nil
  else
    fastStreamData.currentSegmentTime = 0
    fastStreamData.currentSegmentTimeFormatted = M.formatTime(0)
    fastStreamData.currentSegmentDiffToBest = nil
    fastStreamData.currentSegmentDiffToBestFormatted = nil
    fastStreamData.currentSegmentDiffToBestFlavor = nil
    fastStreamData.currentSegmentDiffToPrevious = nil
    fastStreamData.currentSegmentDiffToPreviousFormatted = nil
    fastStreamData.currentSegmentDiffToPreviousFlavor = nil
  end

  -- Set flag for onUpdate to send the stream
  needFastStream = true
end

Callers

@/lua/ge/extensions/gameplay/crawl/utils.lua
      updateRaceDataStructure(crawlerId, state, state.raceData)
      core_lapTimes.updateFastFromRace(state.raceData, crawlerId)
      core_lapTimes.updateStaticFromRace(state.raceData, crawlerId)
@/lua/ge/extensions/gameplay/race/race.lua
      if self.states[pid] then
        core_lapTimes.updateFastFromRace(self, pid)
      end