Not sure if this should be here or in Jass Theory. But anyway.
I have tried to see if it is possible to use just one timer for one map (in my case; all: attackfunctions, timed effects, spells, calculation for time before a projectile reaches its destination etc with just one timer) and got inspired by the (not as efficient as they say) KT2. Now, KT2 have been successfully used in a number of things, but it could not handle the attacked-triggered functions well at all. So I tried my own way to make something using the KT2 ideas (tick-periods with a period time of 0.00125 seconds and register functions as triggers in initialisations and so on) However, My idea was using a loop inside the function triggered by the timer to find the first function that should ran, then let that function call a continuer to check for next etc until al functions that should run at the moment have been executed. Check code
However, when the NextFunction code is executed, the game shuts of. I don't know if it just is a protection against looping or if it actually creates an infinitive-loop here somewhere..
If someone have another way of using a singletimer for everything, or could tell me that their efficiency ain't much to talk about, I would like to hear ^^ (:
This topic isn't really a superimportant one for me, it's more a theory-question in that aspect.
I have tried to see if it is possible to use just one timer for one map (in my case; all: attackfunctions, timed effects, spells, calculation for time before a projectile reaches its destination etc with just one timer) and got inspired by the (not as efficient as they say) KT2. Now, KT2 have been successfully used in a number of things, but it could not handle the attacked-triggered functions well at all. So I tried my own way to make something using the KT2 ideas (tick-periods with a period time of 0.00125 seconds and register functions as triggers in initialisations and so on) However, My idea was using a loop inside the function triggered by the timer to find the first function that should ran, then let that function call a continuer to check for next etc until al functions that should run at the moment have been executed. Check code
/*Don't use/check this code, I got a WAY faster one further down in this thread*/
library TimeralaRV
globals
constant timer SMALLTIMER = CreateTimer()
constant timer LARGETIMER = CreateTimer() /*This timmer is added due to experiements with one low-freqency timer and one high-freqency timer*/
constant integer SMALLTIMERARRAY = 80
constant integer LARGETIMERARRAY = 180
constant real SMALLTIMEOUT = 0.00125
constant real LARGETIMEOUT = 0.2
integer SmallTimerWhichArray = 0
integer LargeTimerWhichArray = 0
boolean array SmallTimerArrayUsed[SMALLTIMERARRAY]
integer array SmallTimerArrayTicksLeft[SMALLTIMERARRAY]
trigger array SmallTimerArrayTrigger[SMALLTIMERARRAY]
unit array SmallTimerArrayDealer[SMALLTIMERARRAY]
unit array SmallTimerArrayReci[SMALLTIMERARRAY]
boolean array LargeTimerArrayUsed[LARGETIMERARRAY]
integer array LargeTimerArrayTicksLeft[LARGETIMERARRAY]
trigger array LargeTimerArrayTrigger[LARGETIMERARRAY]
endglobals
function TimeRunSmall takes nothing returns nothing
local integer i = 0
local boolean b = FALSE
if SmallTimerArrayTicksLeft[0] == 1 then
call TriggerExecute(SmallTimerArrayTrigger[0])
set SmallTimerArrayTicksLeft[0] = 0
set SmallTimerArrayUsed[0] = FALSE
else
if SmallTimerArrayTicksLeft[0] != 0 then
set SmallTimerArrayTicksLeft[0] = SmallTimerArrayTicksLeft[0] - 1
endif
loop
exitwhen b == TRUE
set i = i + 1
if SmallTimerArrayTicksLeft[i] == 1 then
set SmallTimerWhichArray = i
call TriggerExecute(SmallTimerArrayTrigger[i])
set SmallTimerArrayTicksLeft[i] = 0
set SmallTimerArrayUsed[i] = FALSE
set b = TRUE
else
if SmallTimerArrayTicksLeft[0] != 0 then
set SmallTimerArrayTicksLeft[i] = SmallTimerArrayTicksLeft[i] - 1
endif
if i > SMALLTIMERARRAY then
set b = TRUE
endif
endif
endloop
endif
endfunction
function NextFunction takes nothing returns nothing /* A bit simplified, in reality I would need a simple way of determine if it should use the small or the large timer, but it is not relevant for the moment*/
local integer i = SmallTimerWhichArray + 1
local boolean b
if SmallTimerArrayTicksLeft[i] == 1 then
call TriggerExecute(SmallTimerArrayTrigger[0])
set SmallTimerArrayTicksLeft[i] = 0
set SmallTimerArrayUsed[i] = FALSE
else
if SmallTimerArrayTicksLeft[i] != 0 then
set SmallTimerArrayTicksLeft[i] = SmallTimerArrayTicksLeft[i] - 1
endif
loop
exitwhen b == TRUE
set i = i + 1
if SmallTimerArrayTicksLeft[i] == 1 then
set SmallTimerWhichArray = i
call TriggerExecute(SmallTimerArrayTrigger[i])
set SmallTimerArrayTicksLeft[i] = 0
set SmallTimerArrayUsed[i] = FALSE
set b = TRUE
else
if SmallTimerArrayTicksLeft[0] != 0 then
set SmallTimerArrayTicksLeft[i] = SmallTimerArrayTicksLeft[i] - 1
endif
if i > SMALLTIMERARRAY then
set b = TRUE
endif
endif
endloop
endif
endfunction
endlibrary
However, when the NextFunction code is executed, the game shuts of. I don't know if it just is a protection against looping or if it actually creates an infinitive-loop here somewhere..
If someone have another way of using a singletimer for everything, or could tell me that their efficiency ain't much to talk about, I would like to hear ^^ (:
This topic isn't really a superimportant one for me, it's more a theory-question in that aspect.
