From 506ca9e9d9d79c1464baf185389a1750e37e9a0a Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Thu, 21 Nov 2013 08:33:58 +0100 Subject: old stuff backup --- tricks/sectorTimes.lua | 159 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 tricks/sectorTimes.lua (limited to 'tricks/sectorTimes.lua') diff --git a/tricks/sectorTimes.lua b/tricks/sectorTimes.lua new file mode 100644 index 0000000..426bb0c --- /dev/null +++ b/tricks/sectorTimes.lua @@ -0,0 +1,159 @@ + +-- true to show the total delta splits sector 1 + sector 2 +-- false to show the delta of sector 2 only +mDelta_total_split_sectors = false + +-- display sector split times +mSectorSplitDelay = 8000 + + +mLastSectorTime = {} +mBestSectorTime = {} +mCurrentSector = 0 +mSectors = 0 + +function initSectorTimes() + --mSectors = GetContextInfo("sectorcount") + mLastSectorTime = {} + mBestSectorTime = {} + mCurrentSector = 1 +end + +function getSector(sector) + local currentSector = GetCarInfo("sector") + if sector == nil or sector == 0 then + sector = currentSector + elseif sector == -1 then + sector = currentSector - 1 + if sector == 0 then + sector = table.getn(mLastSectorTime) + end + end + return sector +end +function getSectorBest(sector) + + --return GetContextInfo(string.format("bestsector%d", getSector(sector))) + return mBestSectorTime{getSector(sector)}{1} + +end +function getSectorTime(sector) + + --if isAppRFactor(GetContextInfo("simulation")) then + -- return GetContextInfo(string.format("sector%d", getSector(sector))) + --else + -- return GetContextInfo(string.format("lastsector%d", getSector(sector))) + --end + return mLastSectorTime{getSector(sector)}{1} + +end + + + +function UpdateSectorTimes() + local sector = GetCarInfo("sector") + + if mCurrentSector ~= sector then + local lastSector = sector - 1 + if lastSector == 0 then lastSector = table.getn(mLastSectorTime) end + + local ls = 0.00000 + + if isAppRFactor(GetContextInfo("simulation")) then + ls = GetTimeInfo(string.format("sector%d", lastSector)) + else + ls = GetTimeInfo(string.format("lastsector%d", lastSector)) + end + + print ( "sector "..lastSector.." : " .. ls) + + -- + if mLastSectorTime[lastSector] == nil then + mLastSectorTime[lastSector] = {0.00000, 0.00000} + end + -- save previous best sector for sector split times + mLastSectorTime[lastSector][2] = mLastSectorTime[lastSector][1] + -- stores last sector time + mLastSectorTime[lastSector][1] = ls + + -- + if mBestSectorTime[lastSector] == nil then + mBestSectorTime[lastSector] = {0.00000, 0.00000} + end + -- save previous best sector for sector split times + mBestSectorTime[lastSector][2] = mBestSectorTime[lastSector][1] + if ls ~= 0.0 and mBestSectorTime[lastSector][1] > ls then + -- stores best sector time if better than best :) + mBestSectorTime[lastSector][1] = ls + end + + + -- save current sector value + mCurrentSector = sector + -- set ticks for display + mDiffSectorDelay = GetTicks() + mSectorSplitDelay + end +end + +-- return delta time vs last time + sector diff +function SectorSplitLast() + + local lastSector = GetCarInfo("sector") - 1 + if lastSector == 0 then lastSector = table.getn(mLastSectorTime) end + + local ls = 0.00000 + + if isAppRFactor(GetContextInfo("simulation")) then + ls = GetTimeInfo(string.format("sector%d", lastSector)) + else + ls = GetTimeInfo(string.format("lastsector%d", lastSector)) + end + + local start = lastSector + -- check whether to sum all sector diff values or not + if mDelta_total_split_sectors then start = 1 end + for i = start, lastSector, 1 do + local ls = mLastSectorTime[i][1] + local old_ls = mLastSectorTime[i][2] + if ls > 0 and old_ls > 0 then + lpt = lpt + (ls - old_ls) + end + end + + + return lpt +end + +-- return delta time vs best time + sector diff +function SectorSplitBest() + + local lpt = 0.0 + + if mDiffSectorDelay ~= nil and GetTicks() < mDiffSectorDelay then + + local lastSector = GetCarInfo("sector") - 1 + if lastSector == 0 then lastSector = mSectors end + + local ls = 0.00000 + + local start = lastSector + -- check whether to sum all sector diff values or not + if mDelta_total_split_sectors then start = 1 end + for i = start, lastSector, 1 do + local ls = mLastSectorTime[i][1] + local old_bs = mBestSectorTime[i][2] + if ls > 0 and old_bs > 0 then + lpt = lpt + (ls - old_bs) + end + end + + else + -- display delta by default + lpt = GetTimeInfo("realdiffbest") + end + + return lpt +end + +--============================================== +require "scripts/slidevice" -- cgit v1.2.3