-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtime.lua
More file actions
43 lines (35 loc) · 695 Bytes
/
time.lua
File metadata and controls
43 lines (35 loc) · 695 Bytes
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
local event = require "event"
local M = {}
local time = 0
local list = {}
M.update = function (dt)
time = time + dt
local e = list[#list]
while #list > 0 and e.time <= time do
list[#list] = nil
event.notify(e.name, e.data)
e = list[#list]
end
end
M.get = function ()
return time
end
M.delay = function (event, data, dt)
M.notify(event, data, time+dt)
end
M.notify = function (name, data, time)
local e = {name=name, data=data, time=time}
if #list > 0 then
do i = #list,1
if e.time < list[i].time then
table.insert(list,i+1,e)
return
end
end
end
table.insert(list,1,e)
end
M.clear = function ()
list = {}
end
return M