Comments on yet another timer "system"?

Azlier

Old World Ghost
Reaction score
461
It seems that everything but zero second timers has been done in the best way. TimerUtils handles low frequency timers, T32 handles high frequency "timers".

Is this any good?
JASS:
// OnZero, by Azlier

// OnZero simply runs a function after zero seconds in the most efficient way possible.
// The given function must return a boolean. Any boolean. For efficiency reasons.
// Who cares about good API?

// Syntax:
//   call OnZero(function FunctionToRunAfterZeroSeconds)

library OnZero initializer Init

globals
    private trigger t = CreateTrigger()
    private boolean b
    private timer ti = CreateTimer()
endglobals

function OnZero takes code c returns nothing
    set b = true
    call ResumeTimer(ti)
    call TriggerAddCondition(t, Filter(c))
endfunction

private function Fire takes nothing returns nothing
    if b then
        call PauseTimer(ti)
        set b = false
        call TriggerEvaluate(t)
        call TriggerClearConditions(t)
    endif
endfunction

private function Init takes nothing returns nothing
    call TimerStart(ti, 0, true, function Fire)
    call PauseTimer(ti)
endfunction

endlibrary
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
JASS:
function doStuff takes nothing returns nothing
    call OnZero(function youLost)
    call OnZero(function theGame)
endfunction


break?
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Does what it says on the tin. Don't know if anyone would use it in liu of DIY.

Is ResumeTimer faster than restarting it with 0.00?

Would it be faster to add a timer expiration event to the trigger rather than calling TriggerEvaluate? And in such a case, you could omit the boolean entirely and just disable/enable the trigger.
 

Azlier

Old World Ghost
Reaction score
461
I do not require passing data. If I do require passing data, I always implement a stack in about 5 lines of code. If this system is unfitting for public release, that's fine. I use it for ease of use and leaklessness.

>Is ResumeTimer faster than restarting it with 0.00?

I hear so.

>Would it be faster to add a timer expiration event to the trigger

No idea.

>break?

No.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
That won't kill the world to add an integer argument, and simply use 0 if you don't need it.
But sure it will be so much slower :D

I use Builder Bob's script because it's useful with some events, and i definitely need to keep the track of datas, implement a stack each time i need it is lame.

I guess it's a matter of taste.
 

Azlier

Old World Ghost
Reaction score
461
For optimal data passing, you would need to call the GetData function in every function you want to fire after 0 seconds. I prefer a stack. Luckily, this system is for personal use, so none of you have to deal with the insanity.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
You really care to much about efficiency despite usability, but it's fine if you like it i guess.
 

Azlier

Old World Ghost
Reaction score
461
I find a stack much more usable. But that's me, the local Communist Overlord.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top