• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Polled Waits vs Timers for desyncs

Status
Not open for further replies.
Level 6
Joined
Mar 20, 2008
Messages
208
Was wondering if PolledWaits are any good with stopping a map from desyncing

IE: I want the trigger to wait a second before taking an action.

Sample code below, would a polled wait be sufficient in not desyncing the game? Or do I need to implement a timer?

JASS:
function MCA takes nothing returns nothing
      local unit u = GetTriggerUnit()
      local player p = GetOwningPlayer(u)     
      local unit z = GetSpellTargetUnit()  
      local integer i = GetUnitAbilityLevel(u, 'A01P')
      local real x = GetUnitX(z)
      local real y = GetUnitY(z)
        
     call TriggerSleepAction(1)

     loop
         exitwhen i == 0
            set u = CreateUnit(p,'nmrl',x,y,0)
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Other\\CrushingWave\\CrushingWaveDamage.mdl",u,"overhead"))
            call IssueTargetOrder(u,"attack",z)           
            
         set i = i-1
     endloop
 
     set z = null
     set u = null
     set p = null
endfunction
 
That is fine. Polled wait leaks though. (But you're using TSA so it is fine)

Since the waiting time is not that low (1 second), it should be fairly accurate with TriggerSleepAction().

Using a timer, yes it would be more accurate, but it wouldn't make the greatest difference and would be a hassle to use attachments just for a simple 1 second wait.

Waits don't necessarily cause desyncs btw, so there shouldn't be anything to really worry about.
 
Level 6
Joined
Mar 20, 2008
Messages
208
Don't mess up with waits, whatever they are. A timer would do the job without any doubts.

I know timers are as accurate as we can get, but they are a bit of a hassle to work with. So if I can get away with polled waits I'd be glad.

That is fine. Polled wait leaks though. (But you're using TSA so it is fine)

Since the waiting time is not that low (1 second), it should be fairly accurate with TriggerSleepAction().

Using a timer, yes it would be more accurate, but it wouldn't make the greatest difference and would be a hassle to use attachments just for a simple 1 second wait.

Waits don't necessarily cause desyncs btw, so there shouldn't be anything to really worry about.

So what numbers will TSAs cause a desync? I use around .3 to 1 second. Majority of my ~.3s are breaks in the code so there is less of a lag spike.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
This is what it would look like with a timer, though depending on what you're using it for you may be able to use different methods.

JASS:
scope Example
    globals
        private hashtable hashData = InitHashtable()
    endglobals

    struct s_data
        unit u  = null
        unit t  = null
        
        real x
        real y
        
        integer i
    endstruct

    function MCADelayed takes nothing returns nothing
        local timer t=GetExpiredTimer()
        local s_data d=s_data(LoadInteger(hashData, GetHandleId(t), 1))
        local player p=GetOwningPlayer(d.u)
        local unit u
        
        loop
            exitwhen (d.i==0)
            set u=CreateUnit(p, 'nmrl', d.x, d.y, 0)
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Other\\CrushingWave\\CrushingWaveDamage.mdl",u,"overhead"))
            call IssueTargetOrder(u, "attack", d.t)
            
            set d.i=d.i-1
        endloop
        
        call RemoveSavedInteger(hashData, GetHandleId(t), 1)
        call d.destroy()        

        set p=null
        set u=null
        set t=null
    endfunction
    
    function MCA takes nothing returns nothing
        local s_data d = s_data.create()
        local timer t = CreateTimer()
        
        set d.u = GetTriggerUnit()
        set d.t = GetSpellTargetUnit()
        set d.i = GetUnitAbilityLevel(d.u, 'A01P')
        set d.x = GetUnitX(d.t)
        set d.y = GetUnitY(d.t)

        call SaveInteger(hashData, GetHandleId(t), 1, d)
        call TimerStart(t, 1, false, function MCADelayed)
        
        set t=null
    endfunction
endscope

PurgeandFire111 said:
it'll be off only by maybe a few milliseconds)

Actually it can be off by seconds, and its varying. Its completely inaccurate.
 
Level 6
Joined
Mar 20, 2008
Messages
208
This is what it would look like with a timer, though depending on what you're using it for you may be able to use different methods.

Actually it can be off by seconds, and its varying. Its completely inaccurate.

The accuracy is not a problem if its not going to cause a desync/server split.

Theres two areas in my map that cause server splits almost without fail when area effectish abilities, and sometimes even general fighting. I figured it was use of too many TSAs.

It happens even more since i've gone through some triggers and made them more efficient/faster.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Since when does TriggerSleepAction cause desyncs?

If you were to do:

JASS:
if (GetLocalPlayer() == somePlayer) then
    call TriggerSleepAction(0)
endif

This may cause somePlayer to desync, I'm not sure, but this is the only instance I can imagine that TriggerSleepAction would cause a desync.
 
Level 6
Joined
Mar 20, 2008
Messages
208
Beats me, could swear I read somewhere on here that they will cause splits.

If they don't then great.
 
Level 9
Joined
May 28, 2007
Messages
365
TSA do not cause desyncs. PolledWaits are just awful.

I remember I was asking similar questions, but Rising_Dusk told me never use PolledWaits, as it is bad coding practice, leaks, and is just stupid (since it uses TSA anyway).

It took me a while to get use to it, but use Timers for everything wait-dependant.
 
Status
Not open for further replies.
Top