Periodic Timer Modules

Solmyr

Ultra Cool Member
Reaction score
30
This should do better than your current version.
JASS:
library PeriodicLoop

    globals
        private constant real TIMEOUT = 0.03125
        private timer mainTimer = CreateTimer()
        private trigger mainTrigger = CreateTrigger()
        private integer N = 0
    endglobals

    struct PeriodicLoop
    
        private thistype next
        private thistype prev
    
        stub method onPeriodicLoop takes nothing returns nothing
            return
        endmethod

        private static method onExpire takes nothing returns boolean
            local thistype this = thistype(0).next
            loop
                exitwhen (this == 0)
                call this.onPeriodicLoop()
                set this = this.next
            endloop
            return false
        endmethod
    
        public static method stopPeriodicLoop takes thistype t returns nothing
            set t.prev.next = t.next
            set t.next.prev = t.prev
            call t.destroy()
            set N = N - 1
            if (N == 0) then
                call PauseTimer(mainTimer)
            endif
        endmethod
    
        private static method tick takes nothing returns nothing
            call TriggerEvaluate(mainTrigger)
        endmethod
    
        public static method startPeriodicLoop takes thistype t returns nothing
            set thistype(0).next.prev = t
            set t.next = thistype(0).next
            set thistype(0).next = t
            set t.prev = thistype(0)
            set N = N + 1
            if (N == 1) then
                call TimerStart(mainTimer, TIMEOUT, true, function PeriodicLoop.tick)
            endif
        endmethod

        private static method onInit takes nothing returns nothing
            call TriggerAddCondition(mainTrigger, Condition(function PeriodicLoop.onExpire))
        endmethod
    
    endstruct

endlibrary
 

emjlr3

Change can be a good thing
Reaction score
395
using a stub, neat (didn't know they existed) - will see if that adds any speed increase.
 

Nestharus

o-o
Reaction score
84
Stub identical to interface.. that's a trigger evaluation + triggercondition + array read + function call + function call + array set every single call.

In the module, it'd be 1 trigger evaluation for all, triggercondition + function call + array read + array set. At 1 method, they'd run the same. At 2, the module wins.

I'll update T32s to have a trigger evaluation in the module (allowing me to get rid of a timer). Also planning on a few other updates. Hopefully get to them today ^)^.


But yea, I hope by showing you the operations you can see why the module wins now.
 

emjlr3

Change can be a good thing
Reaction score
395
adds a lot more code to the map though... :)
 
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