GetTriggerUnit-
DogEntrepreneur
- Reaction score
- 129
I was passing time and got the idea of a map which needs sereval timers but can run all of em on only one timer. I came up with this code. I know it could be better, thats why I'm posting it here. It would need Array recycling, I know.
I tested the code at low and high periods with sereval instances, no lag, no delay, no bugs.
At 0.001, String leaks starts to make it laggy but it isn't the system at all thats lags...
I tested the code at low and high periods with sereval instances, no lag, no delay, no bugs.
JASS:
library OneTimer initializer init
globals
// At what period is recalls
private constant real Period = 0.001
// The global Timer
private timer Timer = CreateTimer()
// Instances Count
private integer Count = 0
// Globals array
private integer array Counts
private integer array Maxs
private string array Names
endglobals
public function AddFunction takes string fctname, real period returns nothing
// I know this will need recycling and to be re-done...
set Names[Count] = fctname
set Counts[Count] = 0
set Maxs[Count] = R2I(period / Period)
set Count = Count + 1
endfunction
private function Periodic takes nothing returns nothing
local integer i = 0
loop
if (Counts<i> >= Maxs<i>) then
call ExecuteFunc(Names<i>)
set Counts<i> = 0
endif
set Counts<i> = Counts<i> + 1
exitwhen i == Count
set i = i + 1
endloop
endfunction
private function init takes nothing returns nothing
call TimerStart(Timer, Period, true, function Periodic)
endfunction
endlibrary
</i></i></i></i></i></i>
At 0.001, String leaks starts to make it laggy but it isn't the system at all thats lags...
JASS:
function First takes nothing returns nothing
call BJDebugMsg("Instance : 0.50")
endfunction
function Second takes nothing returns nothing
call BJDebugMsg("Instance : 1.00")
endfunction
function Third takes nothing returns nothing
call BJDebugMsg("Instance : 1.50")
endfunction
function Fourth takes nothing returns nothing
call BJDebugMsg("Instance : 2.00")
endfunction
function Fifth takes nothing returns nothing
call BJDebugMsg("Instance : 2.50")
endfunction
function Sixth takes nothing returns nothing
call BJDebugMsg("Instance : 3.00")
endfunction
function Seventh takes nothing returns nothing
call BJDebugMsg("Instance : 3.50")
endfunction
function Eighth takes nothing returns nothing
call BJDebugMsg("Instance : 4.00")
endfunction
function Nineth takes nothing returns nothing
call BJDebugMsg("Instance : 4.50")
endfunction
function fast takes nothing returns nothing
//call BJDebugMsg("FAST")
// Because when it's working, it makes too many string leaks
// and make map buggy as hell
endfunction
function InitTrig_test takes nothing returns nothing
call OneTimer_AddFunction("fast", 0.001)
call OneTimer_AddFunction("First", 0.50)
call OneTimer_AddFunction("Second", 1.00)
call OneTimer_AddFunction("Third", 1.50)
call OneTimer_AddFunction("Fourth", 2.00)
call OneTimer_AddFunction("Fifth", 2.50)
call OneTimer_AddFunction("Sixth", 3.00)
call OneTimer_AddFunction("Seventh", 3.50)
call OneTimer_AddFunction("Eighth", 4.00)
call OneTimer_AddFunction("Nineth", 4.50)
endfunction