找回密码
 点一下
查看: 1058|回复: 2

关于两种等待时间的疑问

[复制链接]
发表于 2010-3-6 12:57:54 | 显示全部楼层 |阅读模式
我在循环中使用PolledWait()和TriggerSleepAction(  )出现了一些时间的误差,
关于这两个函数,说明写的是PolledWait()是指游戏中的时间,TriggerSleepAction(  )写的是实际时间,
但是如果我这样
set x = 0
loop
     PolledWait(2)
     set x = x + 1
     exitwhen  x >4
endloop


set x = 0
loop
     TriggerSleepAction(2)
     set x = x + 1
     exitwhen  x >4
endloop


时间上循环执行结束的时间都不是10s
这是为什么呢?
发表于 2010-3-6 14:31:06 | 显示全部楼层
Wait与Timer计时精度研究
答案:因为精度问题
回复

使用道具 举报

发表于 2010-3-6 15:43:12 | 显示全部楼层
[jass]
globals
constant real      bj_POLLED_WAIT_SKIP_THRESHOLD    =  2.00
constant real      bj_POLLED_WAIT_INTERVAL          =  0.10
endglobals

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)
//TimerGetRemaining是计时器剩余时间
            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[/jass]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-10-6 03:48 , Processed in 0.057741 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表