- Joined
- Jul 6, 2009
- Messages
- 1,885
So, well. I've updated it following Nestharus' advices although there's maybe space for more improvement.
It's an improved version of T32.
I didn't really like T32's Tick, kinda long method names and the fact J4L doesn't pause the timer so i made this.
It's an improved version of T32.
JASS:
library II //Instance Iterator 1.1.0.1 by Garfield1337
// Iterates struct instances, for more info, check T32:
// [url]http://www.thehelper.net/forums/showthread.php/132538-Timer32[/url]
// Usage:
// -Implement II module
// -Add a method named "periodic" above the module implementation that doesn't
// take any arguments, this method will be called each iteration
// -call start() method to start iterating an instance
// -call end() method to stop
globals
private trigger t = CreateTrigger()
private integer C = 0 //Global instance count
private timer m = CreateTimer()
endglobals
private function e takes nothing returns nothing
call TriggerEvaluate(t)
endfunction
module II
private static boolexpr b
private static triggercondition d
private thistype n //next
private thistype p //previous
private integer c //Struct's instance count
private static method l takes nothing returns boolean
local thistype this=thistype(0).n
loop
exitwhen 0==this
call .periodic()
set this=.n
endloop
return false
endmethod
method start takes nothing returns nothing
if 0==C then
call TimerStart(m,0.031250000,true,function e) //ResumeTimer() doesn't seem to work on a looping timer
set .d=TriggerAddCondition(t,.b)
elseif 0==.c then
set .d=TriggerAddCondition(t,.b)
endif
set C=C+1
set .c=.c+1
set thistype(0).n.p=this
set .n=thistype(0).n
set thistype(0).n=this
set .p=thistype(0)
endmethod
method end takes nothing returns nothing
set C=C-1
set .c=.c-1
if 0==C then
call PauseTimer(m)
call TriggerClearConditions(t)
elseif 0==.c then
call TriggerRemoveCondition(t,.d)
endif
set .p.n=.n
set .n.p=.p
endmethod
private static method onInit takes nothing returns nothing
set .b=Condition(function thistype.l)
set .d=TriggerAddCondition(t,.b)
endmethod
endmodule
endlibrary
Last edited: