Snippet Custom Polled Wait

T.s.e

Wish I was old and a little sentimental
Reaction score
133
JASS:
library CustomWait
function CustomPolledWait takes real duration returns nothing
    local timer t
    local real  timeRemaining

    if (duration > 0) then
        set t = CreateTimer()
        call TimerStart(t, duration, false, null)
        loop
            set timeRemaining = TimerGetRemaining(t)
            exitwhen timeRemaining <= 0
            
            if (timeRemaining > bj_POLLED_WAIT_SKIP_THRESHOLD) then
                call TriggerSleepAction(0.1 * timeRemaining)
            else
                call TriggerSleepAction(bj_POLLED_WAIT_INTERVAL)
            endif
        endloop
        call DestroyTimer(t)
        set t = null
    endif
endfunction
endlibrary

This is basically the same as the regular Polled Wait, except it does not leak a handle like the original does.
 

Switch33

New Member
Reaction score
12
What's the advantage of this over just simply using TriggerSleepAction?
I'm pretty sure TriggerSleepAction is the one that doesn't screw up when someone is lagging on the map also right?
 

Flare

Stops copies me!
Reaction score
662
PolledWait is slightly more accurate I believe, and this is just a fixed version of PolledWait (since the original has a handle leak)

Nice to see that someone actually submitted this :D

I'm pretty sure TriggerSleepAction is the one that doesn't screw up when someone is lagging on the map also right?

Nope, TriggerSleepAction goes through pauses in games such as lag window (while PolledWait stops until the window has disappeared), unless stopping itself when the lag window appears, then restarting it afterwards is a bad thing
 

PurgeandFire

zxcvmkgdfg
Reaction score
508
TriggerSleepAction, I believe, has a delay sometimes determined on the amount of players playing. Vexorian's polled wait is better because it creates a global timer rather than creating and destroying one everytime on execution.

You can find it at Wc3jass.com. It is a non-leaking polled wait. Not sure if I've ever gotten it to work though. :p

This is fine I guess, but you basically just added the "set t = null". :p
 

Switch33

New Member
Reaction score
12
Yes, it's not a bad thing to stop, and restart it afterwards because when someone is lagging it's usually a problem syncing and running more triggers instead of waiting it could cause more lag or disconnect the lagging player.

You should definitely update this by adding a private global timer and just using it in the function also wouldn't need to set it to null/destroy it i think after use cause it's a global.
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
I'd rather have MUI-ness than 2 less lines of code anytime.
 

quraji

zap
Reaction score
144
A PolledWait is more accurate because it doesn't run through game pauses/lag. As you can see in the code, it loops (which are put on hold during a pause) to keep a small wait going, so the most time that it can possibly run through during lag is .1 seconds (unless there is left than 2 seconds left).
 

PurgeandFire

zxcvmkgdfg
Reaction score
508
I'd rather have MUI-ness than 2 less lines of code anytime.

Um.. Yeah, that is fine. I mean sure, practically everyone would have 2 more lines just for MUI-ness. :)

But I don't see how that relates to the function. It is still MUI. :p

http://wc3jass.com/viewtopic.php?t=206

I think... :\ I'm not positive, I think there might be a few bugs with it though.

If you periodically use that PolledWait it might affect the gameplay a bit. If you use it for some spell or something or you don't use it like every 0.03 seconds, I think it should be fine. xP
 

Switch33

New Member
Reaction score
12
Will the code work after the timer stops though at all?
It doesn't seem to make sense that it would.
JASS:
    if st <= 0 then
        set bj_gameStartedTimer = CreateTimer()
        call TimerStart(bj_gameStartedTimer, 1000000, false, null)
//So basically this system just ends if the timer reaches 1000000 because it doesn't reset it back to 0.
//also running it for 1000000 is bad as the comments say probably as theres maybe a max limit to how long a timer 
//could run without flipping out
    endif
Come to think of it... Vex's hero arena did seem to suddenly end after a certain amount of game time was played.


So far this is my solution:
JASS:
library CustomWait initializer InitWait
function RestartWait takes nothing returns nothing
//Restarts the timer once it ends again and again.
call TimerStart(bj_gameStartedTimer, 7200, false, function RestartWait)
endfunction

function InitWait takes nothing returns nothing
 local real st=TimerGetElapsed( bj_gameStartedTimer)
    if st <= 0 then
//starts the game timer
        set bj_gameStartedTimer = CreateTimer()
        call TimerStart(bj_gameStartedTimer, 7200, false, function RestartWait)
    endif
endfunction

function CustomPolledWait takes real duration returns nothing
 local real timeRemaining
 local real st=TimerGetElapsed( bj_gameStartedTimer)
    if (duration > 0) then
        loop
            set timeRemaining = duration - TimerGetElapsed( bj_gameStartedTimer) + st
//Right here it makes use of just using one single timer that starts as soon as the game starts by subtracting it to 
//get a duration passed making it MUI.
            exitwhen timeRemaining <= 0
            if (timeRemaining > bj_POLLED_WAIT_SKIP_THRESHOLD) then
                call TriggerSleepAction(0.1 * timeRemaining)
            else
                call TriggerSleepAction(bj_POLLED_WAIT_INTERVAL)
            endif
        endloop
    endif
endfunction
endlibrary
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
Sure it makes sense that it would work again.
JASS:
function CustomPolledWait takes real duration returns nothing
    local timer t
    local real  timeRemaining

    if (duration > 0) then
        set t = CreateTimer()
        call TimerStart(t, duration, false, null)
        loop

It checks if duration is larger than 0, then if it is, it creates the timer and starts it.
EDIT: You were talking about Vex's wait thingy, aha.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top