This repository was archived by the owner on Apr 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeutils.txt
More file actions
83 lines (71 loc) · 2.18 KB
/
timeutils.txt
File metadata and controls
83 lines (71 loc) · 2.18 KB
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
--@name timeutils
--@author katsu
--@shared
timeutils = {}
function timeutils.newDTtween()
local savedTime = timer.systime()
local firstExecAfterCompleted = true
return function(length,delay,func)
if func == nil then
func = delay
delay = 0
end
local time = timer.systime()
local beforeDelayDT = time - savedTime
local DT = beforeDelayDT - delay
if beforeDelayDT >= delay then
if DT <= length then
local up = DT/length
func(up)
return false
else
if firstExecAfterCompleted then
func(1) --incase this function is ever tick divided
firstExecAfterCompleted = false
end
return true
end
end
end
end
function timeutils.newEdgeTrigger()
local savedTime = timer.systime()
local risingFuncCalled = false
local fallingFuncCalled = false
return function(length,delay,risingEdgeFunc,fallingEdgeFunc)
if fallingEdgeFunc == nil then
fallingEdgeFunc = risingEdgeFunc
risingEdgeFunc = delay
delay = 0
end
local time = timer.systime()
local beforeDelayDT = time - savedTime
local DT = beforeDelayDT - delay
if beforeDelayDT >= delay then
if DT <= length then
if not risingFuncCalled and risingEdgeFunc ~= nil then
risingEdgeFunc()
risingFuncCalled = true
end
return false
else
if not fallingFuncCalled and fallingEdgeFunc ~= nil then
fallingEdgeFunc()
fallingFuncCalled = true
end
return true
end
end
end
end
function timeutils.newTickDivider()
local savedTime = timer.systime()
return function(length,func)
local time = timer.systime()
local DT = time - savedTime
if DT > length then
func()
savedTime = time
end
end
end