Hatebreeder
So many apples
- Reaction score
- 381
Personally I think it would do you good to make some spells.
It would give you some time off this thread. (no offense intended)
Whats wrong with asking?
Well, whatever...
Personally I think it would do you good to make some spells.
It would give you some time off this thread. (no offense intended)
I will once it gets approved at WC3C else I aren't using this as I prefer TimerUtils since it is a universal attaching system for people.
He may have meant that for me. He posted 2 minutes after your post. Your questions are certainly welcome.
>So, I can't pass on Data from one function to a timer, in which I pass on the same Data to a timer from the previous timer?
That... is very hard to understand. Let me get this straight...
Data gets passed to KT_Add attached to Func. Func calls KT_Add attaching either itself again, or something else, attaching the same Data.
Works fine. I think you'll be hard pressed to find obscure restrictions in this system.
As said, try it out. KT2 is actually a very neat and pleasant system to use.
Is the system serving you well?
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~ HT ~~ Hibernate Timer ~~ By Jesus4Lyf ~~ PROTOTYPE ~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// What the hell is this?
// - This is a prototype system for higher periods, to be bolted onto KT2.
// - DO NOT USE THIS ON IT'S OWN! Except for testing.
//
// =Pros=
// - It's awesome. <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue :p" loading="lazy" data-shortname=":p" />
// - Very accurate period expiration!
// - Theoretically faster than KT2 version 1.5 for periods above about 0.3 seconds.
//
// =Cons=
// - It's slower than KT2 for periods below about 0.3.
//
// Functions:
// THIS IS JUST A PROTOTYPE! REMEMBER THAT! UNOFFICIAL SYSTEM BE WARNED.
// - HT_Add(userFunc, struct, period)
// - HT_GetData returns the struct
//
// - userFunc is to be a user function that takes nothing and return boolean.
// It will be executed by the system every period until it returns true.
//
// - HT_GetData is to be used inside func, it will return struct passed to
// to the Add function.
//
// How to import:
// - Create a trigger named HT.
// - Convert it to custom text and replace the whole trigger text with this.
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
library HT initializer HTinit
globals
private constant real MarginOfError=0.01
endglobals
// Rawr!
globals
private timer HT_Timer=CreateTimer()
private timer HT_Moderator=CreateTimer()
private real HT_Time=0.0
private HTnode HT_Top
endglobals
globals
private HTnode newHTnode
endglobals
struct HTnode
HTnode prev // Make sure to link this before use
HTnode next // Make sure to link this before use
real period
real firewhen // = HT_Time at creation
trigger trig
integer data
static method new takes code func, integer data, real period returns HTnode
set newHTnode=HTnode.create()
if newHTnode.trig==null then
set newHTnode.trig=CreateTrigger()
else
call TriggerClearConditions(newHTnode.trig)
endif
call TriggerAddCondition(newHTnode.trig,Condition(func))
set newHTnode.data=data
set newHTnode.period=period
set newHTnode.firewhen=HT_Time
return newHTnode
endmethod
method link takes HTnode prev, HTnode next returns nothing
set prev.next=this
set next.prev=this
set this.next=next
set this.prev=prev
endmethod
method unlink takes nothing returns nothing
set this.prev.next=this.next
set this.next.prev=this.prev
endmethod
method autolink takes HTnode start returns nothing
loop
if start.next==0 then
call this.link(start,0)
return
endif
if start.next.firewhen > this.firewhen then
call this.link(start,start.next)
return
endif
set start=start.next
endloop
endmethod
endstruct
globals//locals
private HTnode HT_handlenode
private HTnode HT_handlenext
endglobals
private function HT_Handler takes nothing returns nothing
set HT_handlenode=HT_Top
set HT_handlenext=HT_handlenode.next
loop
set HT_handlenode=HT_handlenext
exitwhen HT_handlenode==0 // Pause timer, nothing left to fire.
set HT_handlenext=HT_handlenode.next
if HT_handlenode.firewhen<=HT_Time+MarginOfError then
if TriggerEvaluate(HT_handlenode.trig) then
call HT_handlenode.unlink()
call HT_handlenode.destroy()
else
set HT_handlenode.firewhen=HT_handlenode.firewhen+HT_handlenode.period
call HT_handlenode.unlink()
call HT_handlenode.autolink(HT_handlenode.prev)
endif
else
// More to fire, but not yet.
call TimerStart(HT_Timer,HT_handlenode.firewhen-HT_Time,false,function HT_Handler)
return
endif
endloop
endfunction
public function GetData takes nothing returns integer
return HT_handlenode.data
endfunction
globals//locals
private HTnode HT_addnode
endglobals
public function Add takes code func, integer data, real period returns nothing
set HT_addnode=HTnode.new(func, data, period)
set HT_addnode.firewhen=HT_Time+period
call HT_addnode.autolink(HT_Top)
if HT_Top.next==HT_addnode then
call TimerStart(HT_Timer,period,false,function HT_Handler)
endif
endfunction
private function HT_ModeratorLoop takes nothing returns nothing
set HT_Time=HT_Time+MarginOfError
endfunction
private function HTinit takes nothing returns nothing
call TimerStart(HT_Moderator,MarginOfError,true,function HT_ModeratorLoop)
set HT_Top=HTnode.create()
set HT_Top.prev=0
set HT_Top.next=0
set HT_Top.firewhen=0.0
endfunction
endlibrary
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~ HT ~~ Hibernate Timer ~~ By Jesus4Lyf ~~ PROTOTYPE ~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// What the hell is this?
// - This is a prototype system for higher periods, to be bolted onto KT2.
// - DO NOT USE THIS ON IT'S OWN! Except for testing.
//
// =Pros=
// - It's awesome.
// - Very accurate period expiration!
// - Theoretically faster than KT2 version 1.5 for periods above about 0.3 seconds.
//
// =Cons=
// - It's slower than KT2 for periods below about 0.3.
//
// Functions:
// THIS IS JUST A PROTOTYPE! REMEMBER THAT! UNOFFICIAL SYSTEM BE WARNED.
// - HT_Add(userFunc, struct, period)
// - HT_GetData returns the struct
//
// - userFunc is to be a user function that takes nothing and return boolean.
// It will be executed by the system every period until it returns true.
//
// - HT_GetData is to be used inside func, it will return struct passed to
// to the Add function.
//
// How to import:
// - Create a trigger named HT.
// - Convert it to custom text and replace the whole trigger text with this.
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
library HT initializer HTinit
globals
private constant real MarginOfError=0.01
endglobals
// Rawr!
globals
private timer HT_Moderator=CreateTimer()
private real HT_Time=0.0
private HTnode HT_Top
endglobals
globals
private HTnode newHTnode
endglobals
struct HTnode
HTnode prev // Make sure to link this before use
HTnode next // Make sure to link this before use
real period
real firewhen // = HT_Time at creation
trigger trig
integer data
static method new takes code func, integer data, real period returns HTnode
set newHTnode=HTnode.create()
if newHTnode.trig==null then
set newHTnode.trig=CreateTrigger()
endif
call TriggerAddCondition(newHTnode.trig,Condition(func))
set newHTnode.data=data
set newHTnode.period=period
set newHTnode.firewhen=HT_Time
return newHTnode
endmethod
method link takes HTnode prev, HTnode next returns nothing
set prev.next=this
set next.prev=this
set this.next=next
set this.prev=prev
endmethod
method unlink takes nothing returns nothing
set this.prev.next=this.next
set this.next.prev=this.prev
endmethod
method autolink takes HTnode start returns nothing
loop
if start.next==0 then
call this.link(start,0)
return
endif
if start.next.firewhen > this.firewhen then
call this.link(start,start.next)
return
endif
set start=start.next
endloop
endmethod
endstruct
globals//locals
private HTnode HT_handlenode
private HTnode HT_handlenext
endglobals
private function HT_Handler takes nothing returns nothing
set HT_handlenode=HT_Top
set HT_handlenext=HT_handlenode.next
loop
set HT_handlenode=HT_handlenext
exitwhen HT_handlenode==0 // Pause timer, nothing left to fire.
set HT_handlenext=HT_handlenode.next
if HT_handlenode.firewhen<HT_Time+MarginOfError then
if TriggerEvaluate(HT_handlenode.trig) then
call HT_handlenode.unlink()
call TriggerClearConditions(HT_handlenode.trig)
call HT_handlenode.destroy()
else
set HT_handlenode.firewhen=HT_handlenode.firewhen+HT_handlenode.period
call HT_handlenode.unlink()
call HT_handlenode.autolink(HT_handlenode.prev)
if HT_handlenext==0 then
set HT_handlenext=HT_handlenode
endif
endif
else
// More to fire, but not yet.
return
endif
endloop
endfunction
public function GetData takes nothing returns integer
return HT_handlenode.data
endfunction
globals//locals
private HTnode HT_addnode
endglobals
public function Add takes code func, integer data, real period returns nothing
set HT_addnode=HTnode.new(func, data, period)
set HT_addnode.firewhen=HT_Time+period
call HT_addnode.autolink(HT_Top)
//if HT_Top.next==HT_addnode then
// //Old start timer stuff
//endif
endfunction
private function HT_ModeratorLoop takes nothing returns nothing
set HT_Time=HT_Time+MarginOfError
if HT_Top.next.firewhen<HT_Time then
call HT_Handler()
endif
endfunction
private function HTinit takes nothing returns nothing
call TimerStart(HT_Moderator,MarginOfError,true,function HT_ModeratorLoop)
set HT_Top=HTnode.create()
set HT_Top.prev=0
set HT_Top.next=0
set HT_Top.firewhen=0.0
endfunction
endlibrary