summaryrefslogtreecommitdiff
path: root/tricks/sectorTimes.lua
blob: 426bb0c9b593ef59d43efef67987f3c002e72ad2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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"