mOldSector = -1 mBestSectors = {0.00, 0.00, 0.00} mLastSectors = {0.00, 0.00, 0.00} mSectorSplit_Vs_LastSector = 0.0 mSectorSplit_Vs_BestSector = 0.0 mSectorSplit_Vs_BestLap = 0.0 mSectorSplit = nil function SectorUpdate() local sector = GetCarInfo("sector") local laps = GetContextInfo("laps") if mSectorSplit == nil or mOldSector ~= sector then mSectorSplit = GetTicks() + mSectorSplitDelay -- Std values ------------------------ local s1 = GetTimeInfo("sector1") local s2 = GetTimeInfo("sector2") local s3 = GetTimeInfo("sector3") local ls1 = GetTimeInfo("lastsector1") local ls2 = GetTimeInfo("lastsector2") local ls3 = GetTimeInfo("lastsector3") local llt = GetTimeInfo("lastlaptime") local bs1 = GetTimeInfo("bestsector1") local bs2 = GetTimeInfo("bestsector2") local bs3 = GetTimeInfo("bestsector3") local blt = GetTimeInfo("bestlaptime") -------------------------------------- -- Computed values --------------------------------------------------------------------------- local Ls1 = mLastSectors[1] local Ls2 = mLastSectors[2] local Ls3 = mLastSectors[3] local Llt = Ls1 + Ls2 + Ls3 -- for Debug local Bs1 = mBestSectors[1] local Bs2 = mBestSectors[2] local Bs3 = mBestSectors[3] -- Don’t compute Best sector times if irrelevant last lap time. if llt >= 0 then if Bs1 ~= 0 then Bs1 = math.min(Bs1, bs1, ls1) else Bs1 = math.min(bs1, ls1) end if Bs2 ~= 0 then Bs2 = math.min(Bs2, bs2, ls2) else Bs2 = math.min(bs2, ls2) end if Bs3 ~= 0 then Bs3 = math.min(Bs3, bs3, ls3) else Bs3 = math.min(bs3, ls3) end -- store new values mBestSectors[1] = Bs1 mBestSectors[2] = Bs2 mBestSectors[3] = Bs3 end local Blt = Bs1 + Bs2 + Bs3 -- Virtual Best Lap time ---------------------------------------------------------------------------------------------- -- Sectors split ----------------------------------------------------- mSectorSplit_Vs_LastSector = 0.0 mSectorSplit_Vs_BestSector = 0.0 mSectorSplit_Vs_BestLap = 0.0 if mOldSector == 1 or (mOldSector > 1 and mSectorSplitCumulate) then mSectorSplit_Vs_LastSector = mSectorSplit_Vs_LastSector + s1 - Ls1 mSectorSplit_Vs_BestSector = mSectorSplit_Vs_BestSector + s1 - Bs1 mSectorSplit_Vs_BestLap = mSectorSplit_Vs_BestLap + s1 - bs1 end if mOldSector == 2 or (mOldSector > 2 and mSectorSplitCumulate) then mSectorSplit_Vs_LastSector = mSectorSplit_Vs_LastSector + s2 - Ls2 mSectorSplit_Vs_BestSector = mSectorSplit_Vs_BestSector + s2 - Bs2 mSectorSplit_Vs_BestLap = mSectorSplit_Vs_BestLap + s2 - bs2 end if mOldSector == 3 then mSectorSplit_Vs_LastSector = mSectorSplit_Vs_LastSector + s3 - Ls3 mSectorSplit_Vs_BestSector = mSectorSplit_Vs_BestSector + s3 - Bs3 mSectorSplit_Vs_BestLap = mSectorSplit_Vs_BestLap + s3 - bs3 end ---------------------------------------------------------------------- -- Sectors times debugging -------------------------------------------------------------------- if true then if mOldSector == 1 then print (" sector " ..mOldSector) elseif mOldSector == 2 then print (" sector " ..mOldSector) else -- mOldSector == 3 print (" sector " ..mOldSector) end print ("[curr] " .. s1 .. " " .. s2 .. " " .. s3 ) print ("[last] " ..ls1 .. " " ..ls2 .. " " ..ls3 ) print ("[Last] " ..Ls1 .. " " ..Ls2 .. " " ..Ls3 .. " | " .. (mSectorSplit_Vs_LastSector) ) print ("[best] " ..bs1 .. " " ..bs2 .. " " ..bs3 .. " | " .. (mSectorSplit_Vs_BestLap ) ) print ("[Best] " ..Bs1 .. " " ..Bs2 .. " " ..Bs3 .. " | " .. (mSectorSplit_Vs_BestSector) ) end ----------------------------------------------------------------------------------------------- if sector == 1 then -- new lap mLastSectors = { ls1 , ls2 , ls3 } print ("") print (" last best") print ("[lapt] " .. llt .. " - " .. blt ) print ("[sect] " .. (ls1+ls2+ls3) .. " - " .. (bs1+bs2+bs3) ) print ("[comp] " .. Llt .. " - " .. Blt ) print ("--- lap "..(laps - 1).." --------------------------------") end mOldSector = sector end end -- return delta time vs last/best time + sector splits function RealTimeDiff_SectorSplits(Best, Lap) local lpt = 0.0 if mSectorSplit ~= nil and mSectorSplit > GetTicks() then if Best and Lap then lpt = mSectorSplit_Vs_BestLap elseif Best then lpt = mSectorSplit_Vs_BestSector else lpt = mSectorSplit_Vs_LastSector end else -- display delta by default if Best then lpt = GetTimeInfo("realdiffbest") else lpt = GetTimeInfo("realdifflast") end end return lpt end