TriggerSleepAction( x )
PolledWait( x )
library RealTime
globals
private real time
endglobals
private function Update takes nothing returns nothing
set time=time+1.
call TriggerSleepAction(1.00)
call ExecuteFunction(SCOPE_PRIVATE+"Update") // I forget, what's the prefix? // Romek: Fixed
endfunction
function GetRealTime takes nothing returns real
return time
endfunction
endlibrary
library Time initializer init
globals
private integer seconds = 0
endglobals
public function GetSeconds takes nothing returns integer
return seconds
endfunction
public function GetMinutes takes nothing returns real
return seconds * 0.01677777
endfunction
private function callback takes nothing returns nothing
seconds = seconds + 1
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterTimerEvent( t, 1.00, TRUE )
call TriggerAddAction( t, function callback )
endfunction
endlibrary
For this purpose, you can use the known multipliers for game time to real time for the set game speed, using [ljass]GetGameSpeed[/ljass]. "Fast" in the F10 menu is MAP_SPEED_NORMAL (1.0x), "Normal" is MAP_SPEED_SLOW (1.25x), "Slow" is MAP_SPEED_SLOWEST (1.66x). I have not tested the editor's Fast or Faster.Hi. How do you count real time instead of gametime? Like a periodic event that happens every 0.01 seconds of real time instead of game time...
globals
udg_Interval = 30.
udg_Adjustment = 0.
udg_Increment = 1.
endglobals
function tester takes nothing returns nothing
local timer t = CreateTimer()
call TimerStart(t, 2*udg_Interval, false, null)
call TriggerSleepAction(udg_Interval)
if TimerGetElapsed(t) > 0.10 and TimerGetElapsed(t) < TimerGetTimeout(t) then
set udg_Adjustment = (((1 - (1 / udg_Increment)) * udg_Adjustment) + ((udg_Interval / TimerGetElapsed(t)) / udg_Increment))
set udg_Increment = (udg_Increment + 1)
else
endif
call PauseTimer(t)
call DestroyTimer(t)
call BJDebugMsg("One game second is " + R2S(udg_Adjustment) + " real seconds.")
set t = null
endfunction
function runtest takes nothing returns nothing
call ExecuteFunc("tester")
endfunction
//===========================================================================
function InitTrig_Untitled_Trigger_001_Copy takes nothing returns nothing
local timer t = CreateTimer()
call TimerStart(t, bj_PI/3., true, function runtest)
endfunction
Because timers run in game time, which varies in scale with game speed.Why not Timer or periodic timer?
call TriggerSleepAction(udg_Interval)
TriggerSleepAction(0) appears to pass however much time is left until the next game tick. Longer waits are needed for a valid comparison.count game time, just like timer, try to measure TriggerSleepAction(0.0) with timer on different game speeds.
function GameToRealFactor takes nothing returns real
return (3+GetHandleId(GetGameSpeed()))/5
endfunction