- Joined
- Apr 27, 2008
- Messages
- 2,455
Because there are not already enough timer systems available, i come with this one to save the world.
The main point is to keep it simple, you don't have to know how many timers at max you will use, and cut off much verbosity.
This is not for speedfreaks.
Personnaly when i need to get a timer, i obviously need to start it and most of time link an integer data to it (even if you don't need it you can still use 0).
Also, there is no real point to decide if it will be a periodic time or not, since if it is not supposed to be a periodic one, you will still have to release it on timer expiration, always periodic is enough.
And when you need to release it on timer expiration, the release function will give the integer data linked to the timer (less verbosity).
Well, i don't really know if it's enough for approval, but i don't care that much if it's rejected, at least it's a proof of concept.
The main point is to keep it simple, you don't have to know how many timers at max you will use, and cut off much verbosity.
This is not for speedfreaks.
Personnaly when i need to get a timer, i obviously need to start it and most of time link an integer data to it (even if you don't need it you can still use 0).
Also, there is no real point to decide if it will be a periodic time or not, since if it is not supposed to be a periodic one, you will still have to release it on timer expiration, always periodic is enough.
And when you need to release it on timer expiration, the release function will give the integer data linked to the timer (less verbosity).
Well, i don't really know if it's enough for approval, but i don't care that much if it's rejected, at least it's a proof of concept.
JASS:
library TimerStack
globals
private constant integer DOUBLE_FREE = -42 // used on debug mode only
private integer N = 0
private timer array Tim
private hashtable Hash_t = InitHashtable()
endglobals
function TimerSetData takes timer tim , integer data returns nothing // public for completness reason but i have not used it yet
call SaveInteger(Hash_t,GetHandleId(tim),0,data)
endfunction
function TimerNew takes real period, code c , integer data returns timer
if N == 0 then
set Tim[0] = CreateTimer()
else
set N = N-1
endif
call TimerSetData(Tim[N],data)
call TimerStart(Tim[N],period,true,c)
return Tim[N]
endfunction
function TimerGetData takes timer tim returns integer
return LoadInteger(Hash_t,GetHandleId(tim),0)
endfunction
function TimerRelease takes timer tim returns integer
local integer data = TimerGetData(tim)
debug if not SaveTimerHandle(Hash_t,0,0,tim) then
debug call BJDebugMsg("TimerRelease : invalid timer (null or ghost) on trigger : " + I2S(GetHandleId(GetTriggeringTrigger())))
debug return 0
debug endif
debug if TimerGetData(tim) == DOUBLE_FREE then
debug call BJDebugMsg("TimerRelease : double free of timer : " + I2S(GetHandleId(tim)) + " on trigger : " + I2S(GetHandleId(GetTriggeringTrigger())))
debug return 0
debug endif
debug call TimerSetData(tim,DOUBLE_FREE)
set Tim[N] = tim
call PauseTimer(tim)
set N = N+1
debug if N > 8190 then
debug call BJDebugMsg("TimerRelease : something really wrong is happening, you were using more than 8190 timers at the same time !")
debug return 0
debug endif
return data
endfunction
endlibrary