找回密码
 点一下
查看: 2885|回复: 10

事实证明Timer的精度和Timer的寿命有关

  [复制链接]
发表于 2007-2-23 09:30:46 | 显示全部楼层 |阅读模式
这是一个名为HACKWALY的T的JASS文本
[codes=jass]
//+-----------------------------------------------------------------
//+ Return Bug Function
//+-----------------------------------------------------------------
function  H2I  takes handle  h returns integer
    return h
    return 0
endfunction
function  I2H  takes integer i returns handle
    return i
    return null
endfunction
//==
function H2TRG takes handle  h returns trigger
    return h
    return null
endfunction
function H2TMR takes handle  h returns timer
    return h
    return null
endfunction
//+-----------------------------------------------------------------
//+ The Init Function
//+-----------------------------------------------------------------
function InitTrig_HACKWALY takes nothing returns nothing
    local timer t = CreateTimer()
    local gamecache gc = InitGameCache("HACKWALY.w3v")
    set gg_trg_HACKWALY = H2TRG(gc)
    call StoreInteger(gc,"TimeSign","GlobalTimer",H2I(t))
    call TimerStart(t,8000000.00,true,null)
endfunction
function HGC takes nothing returns gamecache
    return gg_trg_HACKWALY
endfunction
function HGT takes nothing returns timer
    return H2TMR(I2H(GetStoredInteger(HGC(),"TimeSign","GlobalTimer")))
endfunction
//+-----------------------------------------------------------------
//+ The API Function
//+-----------------------------------------------------------------
function SetTimeSign takes string sign returns nothing
    call StoreReal(HGC(),"TimeSign",sign,TimerGetElapsed(HGT()))
endfunction
function GetSignTime takes string sign returns real
    return GetStoredReal(HGC(),"TimeSign",sign)
endfunction
function TimeFromSign takes string sign returns real
    return TimerGetElapsed(HGT())-GetSignTime(sign)
endfunction
function WaitForAppoint takes string sign, real appoint returns nothing
    local timer t = HGT()
    local real r = GetSignTime(sign) + appoint
    local real d = 0
    loop
        set d = r - TimerGetElapsed(t)
        exitwhen d <= 0
        if d > 2.00 then
            call TriggerSleepAction(0.1*d)
        else
            call TriggerSleepAction(0.1)
        endif
    endloop
endfunction
[/codes]
这是测试用到的T的JASS文本
[codes=jass]
function Trig_test_Actions takes nothing returns nothing
    if ModuloInteger(GetTriggerExecCount(GetTriggeringTrigger()), 2) == 1 then
        call SetTimeSign("test")
        call BJDebugMsg("sign")
        call BJDebugMsg(R2S(TimeFromSign("test")))
    else
        call BJDebugMsg("time")
        call BJDebugMsg(R2S(TimeFromSign("test")))
    endif
endfunction

//======================================
function InitTrig_test takes nothing returns nothing
    set gg_trg_test = CreateTrigger(  )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_test, Player(0) )
    call TriggerAddAction( gg_trg_test, function Trig_test_Actions )
endfunction
[/codes]

结果发现timer的精度为1/8秒,所有time都是1/8的整数倍
当我把GlobalTimer的生命周期调小了后,精度就回来了

经过更多的测试证实Timer的最大信息容为8000000000,也就是说如果我们要精确到1/1000秒,那么我们能够设置的Timer的生命周期最大为8000000000/1000=8000000。如果还要更高的精度就把Timer的生命周期设置得更小。

就是这样
发表于 2007-2-23 10:26:16 | 显示全部楼层
路过,J盲看不明白
回复

使用道具 举报

发表于 2007-2-23 10:44:41 | 显示全部楼层
好H的T
回复

使用道具 举报

发表于 2007-2-23 13:09:08 | 显示全部楼层
好厉害。
这是啥?
回复

使用道具 举报

发表于 2007-2-23 18:06:37 | 显示全部楼层
嗯嗯~~所以那个启动时间其实是假象~~

显示的启动时间其实是它们的最小精度~~我为我的错误理解感到抱歉~~
回复

使用道具 举报

 楼主| 发表于 2007-2-23 18:08:08 | 显示全部楼层
其实以前我也那样认为来着
回复

使用道具 举报

发表于 2007-2-23 18:25:53 | 显示全部楼层
MB嗯嗯~~楼主也在jass区发一份罢~~好让白银大人甲酚的说~~
回复

使用道具 举报

 楼主| 发表于 2007-2-23 19:15:34 | 显示全部楼层
不料,这个东西和jass没多少关系,放那里顶多得几点GA币。嘿嘿
回复

使用道具 举报

发表于 2007-2-23 19:30:04 | 显示全部楼层
不一定哪...JASS写的TIMER精确度比WAR3的T高多了~~多少跟JASS沾点边~
回复

使用道具 举报

 楼主| 发表于 2007-2-24 09:35:09 | 显示全部楼层
发现BJ把TimerGetElapsed()设计成这样:每0.1秒之内的两次同一个对于timer的返回值是一样地。
所以要想计时到0.1秒以下,用我写在主题里的函数是做不到的,必须新建一个timer才行。

用全局的timer还是不太科学,其实BJ的timer应该也是靠一个全局的timer实现的。

另外TriggerSleepAction()的误差更大,最大误差超过0.4秒。
回复

使用道具 举报

发表于 2007-2-24 15:03:47 | 显示全部楼层
MB了
看不懂的就MB吧
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-28 21:08 , Processed in 0.030576 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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