Warcraft (WC3) Modding > Jass Theory & Questions

One map, one Timer

(1/3) > >>

rvonsonsnadtz:
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


--- Code: jass --- /*Don't use/check this code, I got a WAY faster one further down in this thread*/library TimeralaRVglobals    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 nothinglocal integer i = 0local boolean b = FALSEif SmallTimerArrayTicksLeft[0] == 1 then     call TriggerExecute(SmallTimerArrayTrigger[0])    set SmallTimerArrayTicksLeft[0] = 0    set SmallTimerArrayUsed[0] = FALSEelse    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    endloopendifendfunction  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 + 1local boolean bif SmallTimerArrayTicksLeft[i] == 1 then     call TriggerExecute(SmallTimerArrayTrigger[0])    set SmallTimerArrayTicksLeft[i] = 0    set SmallTimerArrayUsed[i] = FALSEelse    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    endloopendifendfunction 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.

moyack:
This approach is very good in fact, because you reduce the handle count considerably. But this can bring issues in relation to the chances to have running at the same time several elements.

For example in my project PoC,  I did this approach and I had in some cases lags due too many instances happening at the same time (AI vs AI attacking each other with full army) this implied to use several timers (3 - 6) timers running at the same time distributing the load of the custom spells.

I separated them in this way:

1 timer for stuff with low frequency (period of 0.5s)
1 timer for hero abilities (high frequency)
1 timer for unit abilities (high frequency)

The load of the game was reduced.

SonofJay:
Hmm, I dunno man, but don't you think it will just cause the game to be slow?

moyack:
No, I run in my map 6 timers during all the game. Waht it makes slow the game is the amount of code running, like looping a big aount of data.

I remember when I used timerutils and from time to time the game got slowed, that's because it generates a lot of timers running at the same time. Timerutils works fine in AOS or games where custom spells and system not exceed more than 100 events or codes running at the same time.

rvonsonsnadtz:
I would really like to see the code of that function, cause, as said in another thread by me, I am using a jass-scripted attackfunction, which means that it have to handle the max-number of units on the map hitting a target at the same time (10players with a max of 12units inc. summons + 2computerplayers in dota or ts style, to be sure that I never reach the max-amount, I estimate about 200 timers would be needed JUST FOR THE ATTACKS in my current approach. With that, I estimated a max of about 150-200 timers for the spells/timed effects/some other misc stuff. Now, it have to be a very massive thing when all timers would be active at the same time, but still, 300-400 timers running can't be good on performance...

Now, as I said, by some reason, the wc3 wants to shut down if I register more than one attackfunction to the timer, probably cause it recognises some kind of loop, cause it SHOULD not run the exact same function with the exact same data in all infinity, but, well, it sure looks so..
You PoC aren't protected right? Would it be ok if I downloaded it and took some inpiration from your time-functions? (:

Off-topic question; It seems to me that you, Moyack, uses struct quite a lot, now, what I wonder is, are they in some way faster than array-variables, or do u just use them to simplifie code for you?

Navigation

[0] Message Index

[#] Next page

Go to full version