So I've got a lot of GUI in my map. Specifically, a lot of waits for various things. I know the GUI wait (game-time) turns into call PolledWait( x.x) and I've been told PolledWait is terrible. Now today I saw firsthand that it is, indeed, terrible. Basically, all my waits were behaving badly all over the place. I'd previously not tested this map much with more than one person. I was playing with four people, over Hamachi. THere was a lot of lag. And for example, I'd cast a spell and its effect would come way later. (Way later means a second or so.)
So, what causes PolledWait to be so bad? What should I use instead?
What's wrong with PolledWait? (What should I use instead?)
-
- Noobite Warrior
- Posts: 16
- Joined: Sun Feb 28, 2010 1:05 am
- Fledermaus
- Keeper of the Keys
- Posts: 354
- Joined: Fri Feb 01, 2008 9:55 am
- Location: New Zealand
- Contact:
Re: What's wrong with PolledWait? (What should I use instead?)
Code: Select all
function PolledWait 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 we have a bit of time left, skip past 10% of the remaining
// duration instead of checking every interval, to minimize the
// polling on long waits.
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)
endif
endfunction
As for an alternative, Timers. More specifically, TimerUtils
I'll post some links that might help you:
http://www.wc3c.net/showthread.php?t=74894
http://www.wc3c.net/showthread.php?t=89072 - This is really out of date and you should make a mental note that whenever Dusk uses CreateTimer, you should use NewTimer (and the same with DestroyTimer and ReleaseTimer) (Oh he kinda goes over timer recycling anyway). Also ignore the shit about "Moving Values to the Callback Function", the tutorial below by Vex does a more up to date approach on that.
http://www.wc3c.net/showthread.php?t=91491
If you're still lost, or would like an example from your own code, feel free to ask.