- Joined
- Feb 12, 2012
- Messages
- 413
OneTimer have been defeated.
Last edited:
* module CTL
*
* Allows creation/destruction of timers in a struct. Provides instancing of those timers.
*
* - static method create takes nothing returns thistype
* - method destroy takes nothing returns nothing
*
* CTL (optional)
* local variables, code before running any timers
* CTLExpire (not optional)
* timer code
* CTLNull (optional)
* null any locals, runs after all timers
* CTLEnd (not optional)
struct CTL_Test extends array
implement CTLExpire
implement CTLEnd
endstruct
struct T32x_Test extends array
private method periodic takes nothing returns nothing
endmethod
implement T32x
endstruct
library Test requires OTimer
globals
private OneTimer a
private integer M = 0
private integer array StructData
endglobals
private module Init
private static method onInit takes nothing returns nothing
call init()
endmethod
endmodule
private struct test
private method destroyData takes nothing returns nothing
set StructData[i] = StructData[M]
set StructData[M] = -1
set M = M - 1
call a.recycleData(M)
call destroy()
endmethod
static method onPeriodic takes nothing returns boolean
local thistype this
local integer i = 1
loop
exitwhen i > M
set this = StructData[i]
set i = i + 1
endloop
return false
endmethod
static method create takes nothing returns nothing
local thistype this = allocate()
set M = M + 1
set StructData[M] = this
if not a.havedata then
set a.addPeriodic = function thistype.onPeriodic
endif
endmethod
private static method init takes nothing returns nothing
set a = OneTimer.create()
endmethod
implement Init
endstruct
endlibrary
spam timers in multiple structs until fps goes down. Be sure to constantly add/remove timers. State which has higher fps.
library test15 requires CTL
struct test15
implement CTLExpire
call this.destroy()
//--------------------------------------
implement CTLEnd
static method onCast takes nothing returns nothing
local thistype this = create()
endmethod
endstruct
endlibrary
This code is correct ? right, after test it (though 15 struct, 4 period trigger call back), it causes laggy on my PC and OneTimer work perfectly fine.