找回密码
 点一下
查看: 1200|回复: 4

同样是时间, 差别咋这么大呢.

[复制链接]
发表于 2009-10-23 23:44:12 | 显示全部楼层 |阅读模式
做技能经常需要用到循环每0.X秒移动单位位置.

触发动作里面有等待时间. 让他等待0.01秒, 实际时间相当慢.
不管是wait 0.01秒还是wait Game-Time 0.01秒都很慢, 感觉大概相当于真实时间的0.1秒

而改成事件中用 Every循环时间却快多了, 比如每0.05秒执行一次, 都比在一条触发的FOR里用等待0.01秒快数倍.

有没有比较简单精确的时间函数, 希望有段代码用到 Custom Script动作里, 来取代繁杂的Every循环时间.
发表于 2009-10-24 01:05:15 | 显示全部楼层
wait本身就含有误差……约为0.2s左右吧
wait game-time,参见下面函数
[codes=jass]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[/codes]
回复

使用道具 举报

发表于 2009-10-24 01:23:51 | 显示全部楼层
jass里就没有一个精确的时间函数。

timer也只是相对精确,然而实际上它是游戏时间,而非现实流逝时间,因此机器卡的时候它就走起来慢。

至于wait,更不消说了,虽然它不是游戏时间,但是准确度低,而且最重要的是,你的时间估计得没错,其实等待的最小时间间隔是0.125秒,因此wait 0.125秒以下的间隔是完全没效果的。至于wait game-time,其实是一个在非常特殊环境下才用得到的东西,希望等待一定游戏时间,又希望之后的动作能在原有触发器里执行。
回复

使用道具 举报

 楼主| 发表于 2009-10-24 14:29:57 | 显示全部楼层
事件里的 Every循环时间比较合适.
如果找不到合适的等待动作, 就只有用循环时间事件了, 这样简单几句指令将变得异常复杂.
郁闷啊
回复

使用道具 举报

发表于 2009-10-24 18:05:16 | 显示全部楼层
[jass]function Wait takes real time returns nothing

    local timer t=CreatTimer()

    call TimerStart(t,time,false,null)

    loop

        if TimerGetRemaining(t)==0.0 then

            call DestroyTimer(t)

            return

        else

            call TriggerSleepAction(0)

        endif

    endloop

endfunction
[/jass]

这个会跳出吧……
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-7-22 06:13 , Processed in 0.030237 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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