Nestharus
o-o
- Reaction score
- 84
Code
Library Size: 648 Lines
The fastest timer system there is.
The speed blows away standard timers and all other timer systems, including T32x.
CTM specializes in all types of repeating timers from small timeout timers to timeouts up to 81.90. If it repeats, it can and should run on CTM, even if there is no data attachment to worry about.
The CTM (Constant Timer Method) Module contains 4 parts.
Aside from the module, Timer Tools also contains a variety of functions for your use.
Creating a constant repeating timer, which is common in most maps, is easy.
[ljass]call Timer[TIMEOUT].list.register(Condition(function MyFunction))[/ljass]
The above line returns the registered function, meaning it can be unregistered at a later time (for example, clean up on game end). This also means that you can use this function directly for things like projectile systems or whatever else you need.
TimerLists, which are retrieved from Timer[TIMEOUT].list, are created and destroyed, meaning that they should not be stored. A smart TimerList is created when it is first accessed via .list and is destroyed when it no longer has any boolean expressions registered to it. If the TimerList is an auto merging TimerList, it is never destroyed and can be stored safely. A constant merging TimerList occurs when the timeout is small enough that all timers on it will always merge regardless of when they are started. For example, a timeout of .05 and a CONSTANT_MERGE of .1 would cause that timeout to always merge, meaning that Timer[.05].list would be a constant merge list. Whether a list is a constant merge list or not is dependent upon more than just the CONSTANT_MERGE.
Any timeout that falls into the above scenario will be a constant merging list. Constant merging lists still have their timers paused, they are just never deallocated, meaning that the lists can be stored and accessed quickly. Whenever you are working with small constant timeouts, be sure to store the list so that you can quickly retrieve it and add to it.
[ljass]function TimerMethodAddInstance takes TimerList list, integer timerMethod returns integer[/ljass]
Adding instances requires the list. For constant merging timers, the list can still be quickly retrieved without having to be stored.
When working with the functions rather than the modules, be warned that accessing the first node within an expiring method using the function will read from a hashtable. To prevent this, store the firsts yourself into your own arrays.
Example
Be sure to update the actual first to the future first at the end of your loop in your expiration method.
Please note
[ljass]function GetExpired takes nothing returns integer[/ljass]
This will retrieve the parent -> GetTimerParent() within an expiring method, meaning that you will be able to retrieve the first node.
Except from CTM Module
When dealing with constant timeouts, use the CTC module.
When dealing with constant merging timeouts, use the CTCC module or TimerMethodAddInstanceC/TimerMethodRemoveInstanceC/GetTimerFirstC
Be sure to enable debug mode and SUGGEST_MODULE_CHANGES while in the testing phases of your map to pick up errors and possible efficiency gains.
That is about all you need to know to use Timer Tools effectively.
Happy mapping ;D
Library Size: 648 Lines
The fastest timer system there is.
The speed blows away standard timers and all other timer systems, including T32x.
CTM specializes in all types of repeating timers from small timeout timers to timeouts up to 81.90. If it repeats, it can and should run on CTM, even if there is no data attachment to worry about.
The CTM (Constant Timer Method) Module contains 4 parts.
JASS:
struct MyTimerMethod extends array
readonly integer value
//this is your constant method
implement CTM
//declare locals here
local string s="My Value: "
implement CTMExpire
//expiration code
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,s+I2S(value))
implement CTMNull
//null locals here
set s=null //pointless, but shows how to use null block
implement CTMEnd
//end constant method
private static method onInit takes nothing returns nothing
set create(2).value=1
endmethod
endstruct
Aside from the module, Timer Tools also contains a variety of functions for your use.
Creating a constant repeating timer, which is common in most maps, is easy.
[ljass]call Timer[TIMEOUT].list.register(Condition(function MyFunction))[/ljass]
The above line returns the registered function, meaning it can be unregistered at a later time (for example, clean up on game end). This also means that you can use this function directly for things like projectile systems or whatever else you need.
TimerLists, which are retrieved from Timer[TIMEOUT].list, are created and destroyed, meaning that they should not be stored. A smart TimerList is created when it is first accessed via .list and is destroyed when it no longer has any boolean expressions registered to it. If the TimerList is an auto merging TimerList, it is never destroyed and can be stored safely. A constant merging TimerList occurs when the timeout is small enough that all timers on it will always merge regardless of when they are started. For example, a timeout of .05 and a CONSTANT_MERGE of .1 would cause that timeout to always merge, meaning that Timer[.05].list would be a constant merge list. Whether a list is a constant merge list or not is dependent upon more than just the CONSTANT_MERGE.
JASS:
set merge = Ln(RELATIVE_MERGE/timeout)/230.258509*timeout
if (merge < CONSTANT_MERGE) then
set merge = CONSTANT_MERGE)
endif
set isConstantMerge = CONSTANT_MERGE < (timeout-merge)/2
Any timeout that falls into the above scenario will be a constant merging list. Constant merging lists still have their timers paused, they are just never deallocated, meaning that the lists can be stored and accessed quickly. Whenever you are working with small constant timeouts, be sure to store the list so that you can quickly retrieve it and add to it.
[ljass]function TimerMethodAddInstance takes TimerList list, integer timerMethod returns integer[/ljass]
Adding instances requires the list. For constant merging timers, the list can still be quickly retrieved without having to be stored.
JASS:
local integer list = first[this] //first timeout node
if (0 == list) then
return ...
endif
if (notConstantMerge[this]) then
return ...
endif
return list
When working with the functions rather than the modules, be warned that accessing the first node within an expiring method using the function will read from a hashtable. To prevent this, store the firsts yourself into your own arrays.
JASS:
* function GetTimerFirst takes nothing returns integer
* - Can only be called right after adding a new instance to a timer method
* - Useful for storing first into an array
* function GetTimerFutureFirst takes nothing returns integer
* - Can only be called right after adding a new instance to a timer method
* - Useful for storing future first into an array so that the first
* - can be updated after the timer expires.
* function GetTimerParent takes nothing returns integer
* - Retrieves parent of newly added instance
* - Can only be used directly after adding instance
Example
JASS:
set first[GetTimerParent()] = GetTimerFirst()
set futureFirst[GetTimerParent()] = GetTimerFutureFirst()
Be sure to update the actual first to the future first at the end of your loop in your expiration method.
Please note
[ljass]function GetExpired takes nothing returns integer[/ljass]
This will retrieve the parent -> GetTimerParent() within an expiring method, meaning that you will be able to retrieve the first node.
Except from CTM Module
JASS:
local thistype this = first[GetExpired()] //first is a custom array
loop
exitwhen 0 == this
set this = GetTimerNext(this)
endloop
set first[GetExpired()] = futureFirst[GetExpired()] //futureFirst is a custom array
When dealing with constant timeouts, use the CTC module.
When dealing with constant merging timeouts, use the CTCC module or TimerMethodAddInstanceC/TimerMethodRemoveInstanceC/GetTimerFirstC
Be sure to enable debug mode and SUGGEST_MODULE_CHANGES while in the testing phases of your map to pick up errors and possible efficiency gains.
That is about all you need to know to use Timer Tools effectively.
Happy mapping ;D