Moderator
M
Moderator
13:41, 8th Jun 2013
Magtheridon96: No. Just No. Seriously.
Magtheridon96: No. Just No. Seriously.
//*************************************************************************************
//*
//* Simple Timer Recycler by Almia
//*
//*************************************************************************************
//*
//* Simple Timer Recycling and Timer Indexing
//*
//* Created for OaD2
//*
//*************************************************************************************
//*
//* API
//*
//* function GetRecycledTimer takes nothing returns timer
//* function GetTimerData takes timer t returns integer
//* function RecycleTimer takes timer t returns nothing
//*
//*************************************************************************************
function GetRecycledTimer takes nothing returns timer
local integer i = udg_TR_RC[0]
if 0 == i then
if null == udg_TR_Hash then
set udg_TR_Hash = InitHashtable()
endif
set i = udg_TR_C + 1
set udg_TR_C = i
set udg_TR_Timers[i] = CreateTimer()
call SaveInteger(udg_TR_Hash, GetHandleId(udg_TR_Timers[i]), 0, udg_TR_C)
endif
set udg_TR_RC[0] = udg_TR_RC[i]
return udg_TR_Timers[i]
endfunction
function GetTimerData takes timer t returns integer
return LoadInteger(udg_TR_Hash, GetHandleId(t), 0)
endfunction
function RecycleTimer takes timer t returns nothing
local integer i = GetTimerData(t)
call PauseTimer(t)
set udg_TR_RC[i] = udg_TR_RC[0]
set udg_TR_RC[0] = i
endfunction
constant function Chars takes nothing returns string
return"abcdefghijklmnopqrstuvwxyz"
endfunction
function PrintLoop takes nothing returns nothing
local integer i = 5
local integer sl = StringLength(Chars())
local integer s
local timer t = GetExpiredTimer()
loop
exitwhen i == 0
set s = GetRandomInt(0, sl - 1)
call BJDebugMsg(SubString(Chars(),s , s + 1))
set i = i -1
endloop
call BJDebugMsg("TimerData : " + I2S(GetTimerData(t)))
call RecycleTimer(t)
endfunction
function InitTrig_Demo takes nothing returns nothing
call TimerStart(GetRecycledTimer(), 1.0, true, function PrintLoop)
call TimerStart(GetRecycledTimer(), 0.75, true, function PrintLoop)
call TimerStart(GetRecycledTimer(), 0.5, true, function PrintLoop)
call TimerStart(GetRecycledTimer(), 0.25, true, function PrintLoop)
endfunction