HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

PolledWait2() Vs. TimerStart()

10-21-2008, 05:04 PM#1
Karawasa
I was wondering what are the pros and cons of each of these functions. Is it worth it to convert a wait to a timer? If so, what duration does it make sense for?

Here is example code below that uses a PolledWait2(), would it be worth it to convert it to a timer event like the one below it?

Collapse JASS:
scope Napalm

globals
    //config options:
    private constant integer abil_id = 'A04E' //Ability To Be Added
    private constant real delay = 0.3 //Delay Until Removed
    private constant string sfx = "Abilities\\Spells\\Other\\Incinerate\\IncinerateBuff.mdl" //Buff Effect On Units
    private constant string position = "chest" //Buff Effect Location
endglobals

function Napalm_Actions takes nothing returns nothing
    local unit atkr = GetEventDamageSource()
    local unit targ = GetTriggerUnit()
    local integer bonus
    local effect light
    
    if GetUnitAbilityLevel(atkr, 'B00A') > 0 then
        set bonus = 1
    elseif GetUnitAbilityLevel(atkr, 'B00J') > 0 then
        set bonus = 2
    elseif GetUnitAbilityLevel(atkr, 'B00K') > 0 then
        set bonus = 3
    else
        set bonus = 0
    endif
   
    if GetUnitAbilityLevel(targ, abil_id) == 0 then
        call UnitAddAbility(targ, abil_id)
    endif
    
    if GetUnitTypeId(atkr) == TOWER_FLAMETHROWER then
        call SetUnitAbilityLevel(targ, abil_id, 1+bonus)
        set light = AddSpecialEffectTarget(sfx, targ, position)
        call TriggerSleepAction(delay)
        call UnitRemoveAbility(targ, abil_id)
        call DestroyEffect(light)
    elseif GetUnitTypeId(atkr) == TOWER_FLAMESPEWER then
        call SetUnitAbilityLevel(targ, abil_id, 5+bonus)
        set light = AddSpecialEffectTarget(sfx, targ, position)
        call TriggerSleepAction(delay)
        call UnitRemoveAbility(targ, abil_id)
        call DestroyEffect(light)
    endif
    
    set atkr = null
    set targ = null
    set light = null
endfunction

endscope
//==== Init Trigger Napalm ====
function InitTrig_Napalm takes nothing returns nothing
    call ORBEngine_RegisterOrb(TOWER_FLAMETHROWER, function Napalm_Actions, "TOWER_FLAMETHROWER: napalm")
    call ORBEngine_RegisterOrb(TOWER_FLAMESPEWER, function Napalm_Actions, "TOWER_FLAMESPEWER: napalm")
endfunction

Collapse JASS:
library UndeadReincarnate uses PUI

globals
    private trigger array PUI_Trigger
    private unit array Unit
    private integer    Index   = 0
    private timer      Timer   = CreateTimer()
endglobals


//===========================================================================
private function Order takes nothing returns nothing
    local integer i
    local integer index = 0
    loop
        exitwhen index >= Index
        set i = GetPlayerId(udg_CreepOwner[GetUnitUserData(Unit[index])])
        call IssuePointOrder(Unit[index],"move",udg_LeakX[i],udg_LeakY[i])
        set index = index + 1
    endloop
    set Index = 0
    call PauseTimer(Timer)
endfunction

//===========================================================================
private function Revive takes nothing returns boolean
    local unit u = GetTriggerUnit()
    
    if GetUnitAbilityLevel(u,'A00U') > 0 then
        call UnitRemoveAbility(u,'A00U')
        call SetUnitLifePercentBJ(u,33.33)
    
        if Index == 0 then
            call TimerStart(Timer, .0, false, function Order)
        endif
    
        set Unit[Index] = u
        set Index = Index + 1
    endif
    
    set u = null
    return false
endfunction

//===========================================================================
public function Register takes unit whichUnit returns nothing
    local integer index  = GetUnitIndex(whichUnit)
   
    if PUI_Trigger[index] != null then
        call DestroyTrigger(PUI_Trigger[index])
    endif
    set PUI_Trigger[index] = CreateTrigger()

    call TriggerRegisterUnitStateEvent(PUI_Trigger[index], whichUnit, UNIT_STATE_LIFE, GREATER_THAN_OR_EQUAL, 0.405)
    call TriggerAddCondition(PUI_Trigger[index], Condition(function Revive))
endfunction

endlibrary
10-21-2008, 05:36 PM#2
moyack
TimerStart wins too much because it's the native, manage timers which are way more precise than TriggerSleepAction and timers can be recycled.
10-21-2008, 06:57 PM#3
zen87
well unless you are lazy for an extra function or you don't really need a 99.999% accurate wait time, IMO TriggerSleepAction are still okay to use~
10-21-2008, 07:27 PM#4
Zerzax
I agree with Moyack. Precision, efficiency, and safe usage I think makes timers a better choice, for just a few lines of code...
10-21-2008, 07:45 PM#5
Troll-Brain
TriggerSleepAction suck, cause :
- It won't never be the same waiting time ( ~= +/- 0.2 s of the wanted one)
- When the game is paused, the wait still run
- The less little wait possible is ~= 0.2 s

So in loops that's a pity.
10-21-2008, 07:50 PM#6
darkwulfv
PolledWait is a decent choice (it's accurate, dammit, except in extremely high-end testing and anything under ~.21 seconds, in which case you'd be using a timer anyways) due to its cleanness, simplicity (no need to make new timers and functions just to wait 5 seconds), and DOES pause when the game pauses. No, it's not 100% accurate, but seriously; the way people use it, 100% accuracy compared to 99.7% accuracy is not a big deal.

It's completely stupid to completely shun PolledWait. Honestly, it is. What is the point of taking the extra effort to make a timer for the sole purpose of waiting 5 seconds? Then you have to carry data over (in a struct or otherwise) AND clean the timer. All of that could be done in a single line of "PolledWait(5.)"

Synopsis:
PolledWait is good for one-time (unless your loop is over a second in wait, in which case PolledWait is usually alright), No-need-for-laser-precision waits over .3 seconds.
Timers are good for everything else (repeating, precision, waits under .3 seconds)
10-21-2008, 09:42 PM#7
MaD[Lion]
Quote:
Originally Posted by zen87
well unless you are lazy for an extra function or you don't really need a 99.999% accurate wait time, IMO TriggerSleepAction are still okay to use~
this is why i made my timing system tat uses Wait("seconds") and has 0.01 accuracy.
so basically with tat system i can just do

pseudo:
Code:
loop
  exitwhen no unit left
  kill random unit
  wait("0.1")
endloop
10-22-2008, 09:20 AM#8
fX_
What's PolledWait2()? What's the difference between it and the regular PolledWait()?
10-22-2008, 10:09 AM#9
zen87
PolledWait2() uses a general timer while PolledWait() creates and destroy a timer whenever it is called.

- better performance
- keeps handle count low (H2I purpose)
10-22-2008, 10:34 AM#10
Captain Griffen
PolledWait also leaks a reference. Optimizer <3.
10-22-2008, 12:54 PM#11
emjlr3
am i missing something, because I see no polledwait2 function usage

with that said, listen to Dark - for things you dont need .1-.2s accuracy on(which is most things other then movement), polledwait is much easier to use, and gets the job done - garantee none of the player will notice a difference if your timer stops the effect exactly at 4 seconds, of your polledwait stops it somewhere between 3.9 and 4.1
10-22-2008, 01:18 PM#12
Captain Griffen
Quote:
Originally Posted by emjlr3
am i missing something, because I see no polledwait2 function usage

with that said, listen to Dark - for things you dont need .1-.2s accuracy on(which is most things other then movement), polledwait is much easier to use, and gets the job done - garantee none of the player will notice a difference if your timer stops the effect exactly at 4 seconds, of your polledwait stops it somewhere between 3.9 and 4.1

All PolledWait calls are replaced with PolledWait2 by the Optimizer.
10-22-2008, 02:05 PM#13
fX_
Quote:
Originally Posted by Captain Griffen
All PolledWait calls are replaced with PolledWait2 by the Optimizer.

What optimizer?
10-22-2008, 02:25 PM#14
Vexorian
"the" optimizer
10-22-2008, 02:58 PM#15
fX_
vJASS?