-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathETKTimer.eps
More file actions
80 lines (68 loc) · 1.4 KB
/
ETKTimer.eps
File metadata and controls
80 lines (68 loc) · 1.4 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
// ETKTimer
import customText as ct;
const timerLength = 100;
const timers = EUDArray(100);
object Entry {
var callback: EUDFuncPtr (1, 0);
var index;
var time;
var ptr;
function tick() {
if (this.time > 0) {
this.time--;
}
}
function call() {
this.callback(this.ptr);
}
};
function _getTimerEntry(i): Entry {
return timers[i];
}
function _getNextFreeTimerSlot() {
for (var i = 0; i < timerLength; i++) {
if (timers[i] == 0) {
return i;
}
}
return 0;
}
function getTimerIDForUnit(unitPointer) {
for (var i = 0; i < timerLength; i++) {
if (_getTimerEntry(i) != 0 && _getTimerEntry(i).ptr == unitPointer) {
return i;
}
}
return timerLength;
}
function isTimerRunningForUnit(unitPointer) {
return getTimerIDForUnit(unitPointer) != timerLength;
}
function _addTimerEntry(entry: Entry) {
const i = _getNextFreeTimerSlot();
entry.index = i;
timers[i] = entry;
//ct.print("addTimerEntry ", i);
return i;
}
function tick() {
for (var i = 0; i < timerLength; i++) {
if (timers[i] != 0) {
const entry = _getTimerEntry(i);
entry.tick();
if (entry.time == 0) {
timers[i] = 0;
entry.call();
Entry.free(entry);
//ct.print("destroyTimer ", i);
}
}
}
}
function add(time, ptr, callback) {
const entry = Entry.alloc();
entry.callback = callback;
entry.time = time;
entry.ptr = ptr;
_addTimerEntry(entry);
}