- Joined
- Dec 12, 2008
- Messages
- 7,385
If I were to post this Timer system, ... well, let me rephrase that:
What do you think of this:
It's a timer system that makes your lives way easier.
A spell that needs tons of extra code for allocation/deallocation, linked list adding and removing, and timer managing would shrink drastically.
It works just like CTL, but you have to declare a constant real INTERVAL to define the timer's interval.
This Timer system very easy to use. If you know how to use CTL, you'd know how to use it.
Example:
I really need feedback because I'm not sure if I should post it or not.
What do you think of this:
JASS:
library TimerLoop
globals
private integer c = 0
private integer array r
endglobals
private function A takes nothing returns integer
local integer i = r[0]
if i == 0 then
set c = c + 1
return c
endif
set r[0] = r[i]
return i
endfunction
private function D takes integer i returns nothing
set r[i] = r[0]
set r[0] = i
endfunction
module TL
static integer am = 0
static integer array nx
static integer array pv
static timer tt = CreateTimer()
static method e takes nothing returns nothing
local thistype this = nx[0]
endmodule
module TLExpire
loop
exitwhen this == 0
endmodule
module TLNull
set this = nx[this]
endloop
endmodule
module TLEnd
endmethod
private static method create takes nothing returns thistype
local thistype i = A()
set nx[i] = 0
set pv[i] = pv[0]
set nx[pv[0]] = i
set pv[0] = i
set am = am + 1
if am == 1 then
call TimerStart(tt, INTERVAL, true, function thistype.e)
endif
return i
endmethod
private method destroy takes nothing returns nothing
call D(this)
set nx[pv[this]] = nx[this]
set pv[nx[this]] = pv[this]
set am = am - 1
if am == 0 then
call PauseTimer(tt)
endif
endmethod
endmodule
endlibrary
It's a timer system that makes your lives way easier.
A spell that needs tons of extra code for allocation/deallocation, linked list adding and removing, and timer managing would shrink drastically.
It works just like CTL, but you have to declare a constant real INTERVAL to define the timer's interval.
This Timer system very easy to use. If you know how to use CTL, you'd know how to use it.
Example:
JASS:
struct DoT extends array
private static real INTERVAL = 0.5
private static unit array caster
private static unit array target
private static real array damage
static method getDamage takes integer level returns real
return 30. + level * 50
endmethod
implement TL
// locals here
// init code here
implement TLExpire
call UnitDamageTarget(caster[this], target[this], damage[this], false, false, null, null, null)
implement TLNull
// null locals here
// end code here
implement TLEnd
static method run takes nothing returns nothing
local thistype this = create()
set caster[this] = GetTriggerUnit()
set target[this] = GetSpellTargetUnit()
set damage[this] = getDamage(GetUnitAbilityLevel(caster[this], 'A000'))
endmethod
private static method onInit takes nothing returns nothing
call RegisterSpellEffectEvent('A000', function thistype.run)
endmethod
endstruct
I really need feedback because I'm not sure if I should post it or not.