找回密码
 点一下
查看: 2830|回复: 7

一个比较精确效率高的WAIT-GAMETIME函数

[复制链接]
发表于 2007-3-18 15:22:08 | 显示全部楼层 |阅读模式
RT
一个比较精确的函数
[codes=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(TimerGetRemaining(t))
        endif
    endloop
endfunction[/codes]
发表于 2007-3-18 15:50:30 | 显示全部楼层
其实 TriggerSleepAction()的误差不是一般的大。
基本上0~0.3的误差都有
回复

使用道具 举报

发表于 2007-3-18 16:09:03 | 显示全部楼层
好眼熟啊  好象是BJ里的函数PolledWait
LZ的函数还有点错误
没有CreateTimer(),TimerStart()怎么执行??
即使有CreateTimer(),后面也要有个call DestroyTimer(t)
还有  好象某地方少了半个括号
回复

使用道具 举报

 楼主| 发表于 2007-3-18 16:56:13 | 显示全部楼层
以前在网吧写过,但GA上不了留到了现在,以前一直以为POLLEDWAIT的误差是函数的原因,没想到是SLEEP ACTION的原因,而且在网吧是写的时候用的是CALL STARTTIMERBJ
不是TIMERSTART,后面发上来的时候可能是因为换了TIMERSTART时漏了个括号.....补上
回复

使用道具 举报

 楼主| 发表于 2007-3-18 17:31:14 | 显示全部楼层
哎~~~~~几乎都是0-0.2秒的误差,算了,当作PolledWait的高效版吧
回复

使用道具 举报

发表于 2007-3-19 10:11:21 | 显示全部楼层
引用第1楼hackwaly于2007-03-18 15:50发表的  :
其实 TriggerSleepAction()的误差不是一般的大。
基本上0~0.3的误差都有

TriggerSleepAction()在玩家掉线或卡机之类的情况能导致几十秒的误差,这才是PolledWait存在的原因,虽然我从来不用这种低效的东西

楼主的函数比BJ的要好多了,最后还要加个set t=null
回复

使用道具 举报

发表于 2007-6-5 23:14:11 | 显示全部楼层
在某处找到一个图像,说的是triggersleepaction.X坐标指的是参数,Y坐标是实际时间。

在一定程度上,我认为你的有问题。
[codes=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(TimerGetRemaining(t))
          endif
          call DisPlayTextToPlayer(Player(0),0,0,"text")
     endloop
endfunction
[/codes]
这段代码会知道loop了几次,我测试的结果都是1次。
也就是说,这个loop是无意义的。


triggersleepaction的时间会是:真实时间+不可避免的误差+网络原因。
这个时间永远会比真实时间要长,而且会因为联网游戏的人数的增加而变大。

猜测这个误差不会大于0.3,可以这样做:
[codes=jass]
function myPollWait takes real delay returns nothing
    local timer t=CreateTimer()
    call TimerStart(t,delay,false,null)
    if(delay>0.3) then
    call TriggerSleepAction(delay-0.3)
    endif
   
    loop
        if(TimerGetRemaining(t)==.0) then
             call PauseTimer(t)
             call DestroyTimer(t)
             set t=null
             return
        endif
        call TriggerSleepAction(.0)
    endloop
endfunction
[/codes]
waittime.png
回复

使用道具 举报

发表于 2007-7-2 18:51:01 | 显示全部楼层
只循环1次这是正常情况,只有在玩家掉线或卡机之类的情况下,真实时间和游戏时间不同步,才会出现多次循环
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-18 18:18 , Processed in 0.104212 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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