|
这是一个名为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的生命周期设置得更小。
就是这样 |
|