Добавлен PT153
Решил протестировать этот хак.
function callback3 takes nothing returns nothing
call ClearTextMessages()
call DebugMsg("\nNonperiodic Timer\nRemaining: " + R2SX(TimerGetRemaining(T1)) + "\nElapsed: " + R2SX(TimerGetElapsed(T1)) + "\nTimeout: " + R2SX(TimerGetTimeout(T1)) + "\nData: " + I2S(R2I(TimerGetRemaining(T1) + 0.5)))
call DebugMsg("\nPeriodic Timer\nRemaining: " + R2SX(TimerGetRemaining(T2)) + "\nElapsed: " + R2SX(TimerGetElapsed(T2)) + "\nTimeout: " + R2SX(TimerGetTimeout(T2)) + "\nData: " + I2S(R2I(TimerGetRemaining(T2) + 0.5)))
endfunction
function callback2 takes nothing returns nothing
set Counter2 = Counter2 + 1
endfunction
function callback1 takes nothing returns nothing
set Counter1 = Counter1 + 1
endfunction
function TimerExploit takes timer t, real period, integer data, boolean periodic, code callb returns nothing
call TimerStart(t, I2R(data), false, null)
call PauseTimer(t)
call TimerStart(t, period, periodic, callb)
endfunction
function Trig_TimerExploitTest_Actions takes nothing returns nothing
set T1 = CreateTimer()
set T2 = CreateTimer()
call TimerExploit(T1, 8., 5, false, function callback1)
call TimerExploit(T2, 8., 6, true, function callback2)
call TimerStart(T3, 1. / 2., true, function callback3)
endfunction
function InitTrig_TimerExploitTest takes nothing returns nothing
set gg_trg_TimerExploitTest = CreateTrigger( )
call TriggerRegisterTimerEvent(gg_trg_TimerExploitTest, 1., false)
call TriggerAddAction( gg_trg_TimerExploitTest, function Trig_TimerExploitTest_Actions )
endfunction
globals
//constant timer T1 = CreateTimer()
//constant timer T2 = CreateTimer()
timer T1
timer T2
constant timer T3 = CreateTimer()
integer Counter1 = 0
integer Counter2 = 0
endglobals
Получить сохранённое число можно только после того как таймер истёк. Так и должно быть?
Принятый ответ
Этот баг все еще работает
К сожалению.
Он даже работает если запаузить через некоторое время, а ещё через некоторое время вновь его запустить. Как только таймер истечёт, TimerGetRemaining будет возвращать значение оставшегося времени перед последней паузой.
Он даже работает если запаузить через некоторое время, а ещё через некоторое время вновь его запустить. Как только таймер истечёт, TimerGetRemaining будет возвращать значение оставшегося времени перед последней паузой.
// Test PauseTimer outside timer callback for nonperiodic timer
function GetT1Conf takes nothing returns nothing
call ClearTextMessages()
call DebugMsg("\nRemaining: " + R2SX(TimerGetRemaining(T1)))
call DebugMsg("Elapsed: " + R2SX(TimerGetElapsed(T1)))
call DebugMsg("Timeout: " + R2SX(TimerGetTimeout(T1)))
endfunction
function callback1 takes nothing returns nothing
set Counter1 = Counter1 + 1
call DebugMsg("\nRemaining in callback: " + R2SX(TimerGetRemaining(T1))) // outputs time remaining that was during last pause.
call DebugMsg("Elapsed in callback: " + R2SX(TimerGetElapsed(T1))) // outputs TimerGetTimeout - (time remaining that was during last pause).
call DebugMsg("Timeout in callback: " + R2SX(TimerGetTimeout(T1))) // correct.
call DebugMsg(I2S(Counter1))
endfunction
function f5 takes nothing returns nothing
call TimerStart(T1, 1., Periodic, function callback1)
call DebugMsg("\nResumed")
call GetT1Conf()
endfunction
function f4 takes nothing returns nothing
call PauseTimer(T1)
call DebugMsg("\nPaused")
call GetT1Conf()
call TimerStart(T3, 1., false, function f5)
endfunction
function f3 takes nothing returns nothing
call TimerStart(T1, 8., Periodic, function callback1)
call TimerStart(T3, 2., false, function f4)
endfunction
function f2 takes nothing returns nothing
call TimerStart(T1, 1., Periodic, function callback1)
call DebugMsg("\nResumed")
call GetT1Conf()
call TimerStart(T3, 2., false, function f3)
endfunction
function f1 takes nothing returns nothing
call PauseTimer(T1)
call DebugMsg("\nPaused")
call GetT1Conf()
call TimerStart(T3, 1., false, function f2)
endfunction
function TimerTest_Actions takes nothing returns nothing
call TimerStart(T1, 8., Periodic, function callback1)
call TimerStart(T3, 1., false, function f1)
endfunction
function TimerTest takes nothing returns nothing
set trig = CreateTrigger( )
call TriggerRegisterTimerEvent(trig, 1., false)
call TriggerAddAction( trig, function TimerTest_Actions )
endfunction
globals
trigger trig
constant timer T1 = CreateTimer()
constant timer T3 = CreateTimer()
integer Counter1 = 0
boolean Periodic = false // no bugs for 'true' value.
endglobals
`
ОЖИДАНИЕ РЕКЛАМЫ...
Чтобы оставить комментарий, пожалуйста, войдите на сайт.
Там все завазано на кривой функции таймера, многократный и однократный таймер - в движке игры это вроде как разные обьекты, и в функции запуска таймера стоит ветвление, данные задаются сразу, но однократным таймером Remaning не юзается, по этому получается передать 1 реал в функцию таймера. Собственно полнейший мусор, бага которая может накрыться медным тазом в любой момент, туча паразитных функций ради одного долбаного вещественного числа которое можно передать.
Отредактирован PT153
Он даже работает если запаузить через некоторое время, а ещё через некоторое время вновь его запустить. Как только таймер истечёт, TimerGetRemaining будет возвращать значение оставшегося времени перед последней паузой.