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
509
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
509
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.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      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