11 years
edited 8 years
Description
This small library allows to attach data structs into timers in an easy way, following the structure proposed by Vexorian, just for compatibility.
Requirements:
- Microtable
- Alloc
Actual Code
This small library allows to attach data structs into timers in an easy way, following the structure proposed by Vexorian, just for compatibility.
Requirements:
- Microtable
- Alloc
Actual Code
12 library TimerUtils requires Alloc, MicroTable
13 14 private struct data extends array
15 static key K // used to connect the data struct with the variable
16 static key D // used to link other data struct to the timer
17 timer t
18
19 implement Alloc20
21 method destroy takes nothing returns nothing
22 call PauseTimer(.t)
23 call ClearData(.t, thistype.K)
24 call .deallocate()
25 endmethod26
27 static method create takes nothing returns thistype
28 local thistype this = thistype.allocate()
29 if this.t == null then
30 set this.t = CreateTimer()
31 endif32 call StoreData(this.t, thistype.K, this)
33 return this
34 endmethod35
36 endstruct37 38 function NewTimer takes nothing returns timer
39 return data(data.create()).t
40 endfunction41 42 function ReleaseTimer takes timer t returns nothing
43 call data(GetData(t, data.K)).destroy()
44 endfunction45 46 function SetTimerData takes timer t, integer d returns nothing
47 call StoreData(t, data.D, d)
48 endfunction49 50 function GetTimerData takes timer t returns integer
51 return GetData(t, data.D)
52 endfunction53 54 endlibrary