-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.lua
53 lines (44 loc) · 1.16 KB
/
timer.lua
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
-- timer.lua : Track that time!
local log = require('log')
local timer = {
total = 0,
trackers = {},
}
function timer.track(tracker)
if not tracker then
error('cannot setup tracker for nil')
return
end
timer.trackers[tracker] = {
_time = 0,
_isTracking = false
}
log.debug('timer.track: ' .. tracker)
end
function timer.reset(tracker)
timer.trackers[tracker]._time = 0
log.debug('timer.reset: ' .. tracker)
end
function timer.start(tracker)
timer.trackers[tracker]._isTracking = true
log.debug('timer.start: ' .. tracker
.. ' at: ' .. timer.trackers[tracker]._time)
end
function timer.stop(tracker)
timer.trackers[tracker]._isTracking = false
log.debug('timer.stop: ' .. tracker
.. ' at: ' .. timer.trackers[tracker]._time)
end
function timer.update(timeDelta)
timer.total = timer.total + timeDelta
for tracker in pairs(timer.trackers) do
local t = timer.trackers[tracker]
if t._isTracking then
t._time = t._time + timeDelta
end
end
end
function timer.getTime(tracker)
return timer.trackers[tracker]._time
end
return timer