- Joined
- May 9, 2014
- Messages
- 1,808
Code
JASS:
library TimerQueue
struct TimeQueue
thistype prev
thistype next
// these methods are for ease in typing later on...
method pop takes nothing returns nothing
set next.prev = prev
set prev.next = next
endmethod
method push takes thistype nodeNext returns nothing
set next = nodeNext
set prev = next.prev
set next.prev = this
set prev.next = this
endmethod
// the main member of the struct...
private static constant timer oneTimer = CreateTimer()
real timeStamp
method destroy takes nothing returns nothing
set timeStamp = 0
call pop()
call deallocate()
endmethod
private static method onExpire takes nothing returns nothing
local thistype this = thistype(0).next
call this.destroy()
set this = this.next
call TimerStart(oneTimer, this.timeStamp, false, function thistype.onExpire)
endmethod
method adjust takes nothing returns nothing
local thistype that = thistype(0).next
loop
exitwhen that == 0 or that.timeStamp - GetTimerExpired() > this.timeStamp
set that = that.next
endloop
if that == 0 then
call this.push(0)
set this.timeStamp = this.timeStamp - that.prev.timeStamp
else
set that.timeStamp = that.timeStamp - GetTimerExpired() - this.timeStamp
call this.push(that)
call PauseTimer(oneTimer)
endif
call TimerStart(oneTimer, this.timeStamp, false, function thistype.onExpire)
endmethod
static method create takes real dur returns thistype
local thistype this = allocate()
set this.timeStamp = dur
call this.adjust()
return this
endmethod
endstruct
endlibrary
Mission Performed: Double Linked List
Last edited: