HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[???]Why PolledWait is set so?

10-11-2003, 03:54 PM#1
danny760311
Original Polled wait:

Code:
// We can't do game-time waits, so this simulates one by starting a timer
// and polling until the timer expires.
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([color=red]0.1[/color]  * timeRemaining)
            else
                call TriggerSleepAction(bj_POLLED_WAIT_INTERVAL)
            endif
        endloop
        call DestroyTimer(t)
    endif
endfunction


Why set 0.1?? If it is set 0.9, wouldn't it be better? And the workload of computer will be lowered, wouldn't it???

I've tested a new polledwait with 0.9 on it, it seemed to have no bug...
10-11-2003, 04:04 PM#2
KaTTaNa
Yeah, that makes sense, but I think it depends on what bj_POLLED_WAIT_SKIP_THRESHOLD is.
10-11-2003, 04:06 PM#3
danny760311
bj_POLLED_WAIT_SKIP_THRESHOLD = 2
bj_POLLED_WAIT_INTERVAL = 0.1

So it should be no problem if it set 0.9...
10-11-2003, 05:53 PM#4
jmoritz
No they did 0.1 very much on purpose. Usually people will only use waits of a few seconds, like 0.5, or 4. If you would sleep for 0.9 * 2 = 1.8 seconds, you might sleep to long if another player lags severely. The wait-lag problem is exactly why they created PolledWait.

Better to do a few more loops (about 10), than too few.
10-12-2003, 02:24 AM#5
danny760311
Well, if you do PolledWait(0.5), it would > 2 and do the ELSE action (Sleep 0.1, not 0.9 * 0.4). So the problem is none.