13 years
edited 13 years
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
1 2 3 /*Don't use/check this code, I got a WAY faster one further down in this thread*/4 library TimeralaRV5 globals6 constant timer SMALLTIMER = CreateTimer()
7 constant timer LARGETIMER = CreateTimer() /*This timmer is added due to experiements with one low-freqency timer and one high-freqency timer*/
8 constant integer SMALLTIMERARRAY = 80
9 constant integer LARGETIMERARRAY = 180
10 constant real SMALLTIMEOUT = 0.00125
11 constant real LARGETIMEOUT = 0.2
12 integer SmallTimerWhichArray = 0
13 integer LargeTimerWhichArray = 0
14 boolean array SmallTimerArrayUsed[SMALLTIMERARRAY]
15 integer array SmallTimerArrayTicksLeft[SMALLTIMERARRAY]
16 trigger array SmallTimerArrayTrigger[SMALLTIMERARRAY]
17 unit array SmallTimerArrayDealer[SMALLTIMERARRAY]
18 unit array SmallTimerArrayReci[SMALLTIMERARRAY]
19 boolean array LargeTimerArrayUsed[LARGETIMERARRAY]
20 integer array LargeTimerArrayTicksLeft[LARGETIMERARRAY]
21 trigger array LargeTimerArrayTrigger[LARGETIMERARRAY]
22 endglobals23 24 function TimeRunSmall takes nothing returns nothing
25 local integer i = 0
26 local boolean b = FALSE
27 if SmallTimerArrayTicksLeft[0] == 1 then
28 call TriggerExecute(SmallTimerArrayTrigger[0])
29 set SmallTimerArrayTicksLeft[0] = 0
30 set SmallTimerArrayUsed[0] = FALSE
31 else32 if SmallTimerArrayTicksLeft[0] != 0 then
33 set SmallTimerArrayTicksLeft[0] = SmallTimerArrayTicksLeft[0] - 1
34 endif35 loop36 exitwhen b == TRUE
37 set i = i + 1
38 if SmallTimerArrayTicksLeft[i] == 1 then
39 set SmallTimerWhichArray = i
40 call TriggerExecute(SmallTimerArrayTrigger[i])
41 set SmallTimerArrayTicksLeft[i] = 0
42 set SmallTimerArrayUsed[i] = FALSE
43 set b = TRUE
44 else45 if SmallTimerArrayTicksLeft[0] != 0 then
46 set SmallTimerArrayTicksLeft[i] = SmallTimerArrayTicksLeft[i] - 1
47 endif48 if i > SMALLTIMERARRAY then
49 set b = TRUE
50 endif51 endif52 endloop53 endif54 endfunction55 56 57 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*/
58 local integer i = SmallTimerWhichArray + 1
59 local boolean b
60 if SmallTimerArrayTicksLeft[i] == 1 then
61 call TriggerExecute(SmallTimerArrayTrigger[0])
62 set SmallTimerArrayTicksLeft[i] = 0
63 set SmallTimerArrayUsed[i] = FALSE
64 else65 if SmallTimerArrayTicksLeft[i] != 0 then
66 set SmallTimerArrayTicksLeft[i] = SmallTimerArrayTicksLeft[i] - 1
67 endif68 loop69 exitwhen b == TRUE
70 set i = i + 1
71 if SmallTimerArrayTicksLeft[i] == 1 then
72 set SmallTimerWhichArray = i
73 call TriggerExecute(SmallTimerArrayTrigger[i])
74 set SmallTimerArrayTicksLeft[i] = 0
75 set SmallTimerArrayUsed[i] = FALSE
76 set b = TRUE
77 else78 if SmallTimerArrayTicksLeft[0] != 0 then
79 set SmallTimerArrayTicksLeft[i] = SmallTimerArrayTicksLeft[i] - 1
80 endif81 if i > SMALLTIMERARRAY then
82 set b = TRUE
83 endif84 endif85 endloop86 endif87 endfunction88 89 endlibrary90
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.
