1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[vJASS] [Snippet] MasterTimer

Discussion in 'Submissions' started by AGD, Sep 30, 2016.

  1. AGD

    AGD

    Joined:
    Mar 29, 2016
    Messages:
    397
    Resources:
    13
    Spells:
    7
    Tutorials:
    1
    JASS:
    5
    Resources:
    13
    So If I understand correctly, there's exactly one timer per timeout. For each timeout, there are a list of buckets/triggers that will expire at different times. When a timer expires, the first trigger in its list will be poped, executed, and enqueued. Where I'm a bit confused is here: The timers I'm going to use will be non-periodic right? And after doing the things to the executing trigger, I still need to iterate over the whole list to update each trigger's remaining time then set the next timeout of the timer to the remaining time of the new head of the list, which is also like in a single timer at least in complexity (O(n)). So I think I didn't understood fully coz I think what you have in mind is something that's O(1).


    Indeed. I have not thought of this.
     
  2. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Well, it's actually more than 1 timer per timeout, oops ;D. It's 1 timer per function that is executing at the precise same moment : O.


    If you have a timeout of 5 and 4 functions that are executing on that timeout at the following times

    +1, +2, +3, +4

    Then it stands to reason that you have a list

    [ 1, 2, 3, 4 ]


    Really, a list of lists

    [ [ 1 ], [ 2 ], [ 3 ], [ 4 ] ]

    Whenever a timer of the given timeout expires, pop from the list and treat that as the thing that just expired. Push it to the back of the list if it repeats : ).

    [ [ 1 ], [ 2 ], [ 3 ], [ 4 ] ] -> [ 1 ] expired

    [ [ 1 ], [ 2 ], [ 3 ], [ 4 ] ] -> [ [ 2 ], [ 3 ], [ 4 ], [ 1 ] ] ( [ 2 ] will expire next ) ( system doesn't care when )

    It doesn't really save anything on the timer handle count front : /. The only time anything is really going to be saved is when two functions that happen to expire at the same moment are run as they will be merged into one timer. As such, it only really works well with small timeouts. I think in my little timer library I had some crazy merging algorithm that would fudge up the expiration times. It guaranteed that the initial expiration of a timer would only be accurate to a certain point. This allowed it to merge timers more often, thus saving on the total number of timers active in the system : ).

    I never really went anywhere with my own implementation of the idea. For some reason, it broke Warcraft 3 native timers, lmao. Don't ask me how I managed to pull that one off. It was enough to copy and paste the system into a map to make it so that TimerStart(CreateTimer(), ...) would not work. I don't really have any plans to take it anywhere as well... a user wouldn't really gain that much : ). Seems smarter to just run independent timers or very specific timer queues.

    A timer queue takes the idea I had above but only supports 1 timeout. As a result, no GetHandleId or anything is required. Simply pop from the list and push it to the back and you've got your ids!

    I actually used a timer queue module implementation when I was working on a footmen wars map way back when. Makes sense right? The map is only going to have a few timeouts at any given time. Why not just have 1 timer for each timeout? : ).


    I hope that my findings when I worked on this years ago helps you figure out where to go ^_^. My general purpose timer system ended up being nothing more than a novel idea, but atleast got timer queues out of it :3.