|
|
#1 | ||
|
User
Join Date: Aug 2007
Posts: 50
![]()
|
A third flavor to accompany Vexorian's Blue and Red TimerUtils.
Table:
In short, this thing is faster than the Blue flavor but still safe enough for most. A speed freak with a carefully handled Red TimerUtils might not be interested, but for the rest I believe this is a good choice. EDIT: After 1.23b the Blue flavor became much faster than it was before, so the above might not hold true anymore. Purple TimerUtils (patch 1.23b or later):library_once TimerUtils //********************************************************************* //* TimerUtils (Purple flavor for 1.23b or later) //* ---------- //* //* To implement it , create a custom text trigger called TimerUtils //* and paste the contents of this script there. //* //* To copy from a map to another, copy the trigger holding this //* library to your map. //* //* (requires vJass) More scripts: http://www.wc3c.net/ //* //* For your timer needs: //* * Attaching //* * Recycling (with double-free protection) //* //* set t=NewTimer() : Get a timer (alternative to CreateTimer) //* ReleaseTimer(t) : Relese a timer (alt to DestroyTimer) //* SetTimerData(t,2) : Attach value 2 to timer //* GetTimerData(t) : Get the timer's value. //* You can assume a timer's value is 0 //* after NewTimer. //* //* Purple Flavor: Slower than the red flavor by a multiplication and a //* division, and as such faster than the blue flavor. Has //* a theoretical limit of timers, which is HASH_SIZE, but //* you should keep your timer count below 3/4 of that to //* insure good performance of the NewTimer function. //* //* Credits: * Hash algorithm by Cohadar (used in an early version //* of his ABCT timer system) //* //* * TimerUtils "interface" by Vexorian. //* //* * This library by Iron_Doors. //* //******************************************************************** //================================================================ globals // These are the hash constants Cohadar used in an early version of ABCT private constant integer HASH_SIZE = 4096 // 2^12 private constant integer HASH_UP = 2138046464 // 2^(31-(12-1)) * 2039 private constant integer HASH_DOWN = 1048576 // 2^(31-(12-1)) private constant integer HASH_BIAS = 2048 // 2^(12-1) endglobals //================================================================================================== globals private integer array Data[HASH_SIZE] private timer array Timer[HASH_SIZE] endglobals function SetTimerData takes timer t, integer value returns nothing debug if (Timer[GetHandleId(t) * HASH_UP / HASH_DOWN + HASH_BIAS] != t) then debug call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer") debug endif set Data[GetHandleId(t) * HASH_UP / HASH_DOWN + HASH_BIAS] = value endfunction function GetTimerData takes timer t returns integer debug if (Timer[GetHandleId(t) * HASH_UP / HASH_DOWN + HASH_BIAS] != t) then debug call BJDebugMsg("GetTimerData: Wrong handle id, only use GetTimerData on timers created by NewTimer") debug endif return Data[GetHandleId(t) * HASH_UP / HASH_DOWN + HASH_BIAS] endfunction //========================================================================================== globals private integer array tH private integer tN = 0 private constant integer HELD=0x28829022 //use a totally random number here, the more improbable someone uses it, the better. endglobals //========================================================================================== function NewTimer takes nothing returns timer local timer t if (tN == 0) then loop set t = CreateTimer() set tH[0] = GetHandleId(t) * HASH_UP / HASH_DOWN + HASH_BIAS exitwhen Timer[tH[0]] == null endloop set Timer[tH[0]] = t else set tN = tN - 1 endif set Data[tH[tN]] = 0 return Timer[tH[tN]] endfunction //========================================================================================== function ReleaseTimer takes timer t returns nothing if (t == null) then debug call BJDebugMsg("Warning: attempt to release a null timer") return endif debug if (Timer[GetHandleId(t) * HASH_UP / HASH_DOWN + HASH_BIAS] != t) then debug call BJDebugMsg("ReleaseTimer: Wrong handle id, only use ReleaseTimer on timers created by NewTimer") debug endif call PauseTimer(t) set tH[tN] = GetHandleId(t) * HASH_UP / HASH_DOWN + HASH_BIAS if (Data[tH[tN]] == HELD) then debug call BJDebugMsg("Warning: ReleaseTimer: Double free!") return endif set Data[tH[tN]] = HELD set tN = tN + 1 endfunction endlibrary Last edited by Iron_Doors : 08-15-2009 at 04:30 PM. |
||
|
|
|
| Sponsored Links - Login to hide this ad! |
|
|
|
|
#2 |
|
Free Software Terrorist
Technical Director
|
- Pick another color, green is reserved for a different implementation.
__________________- This is faster than blue when using certain definitions of faster. |
|
|
|
|
|
#3 | ||
|
User
Join Date: Aug 2007
Posts: 50
![]()
|
Quote:
Quote:
|
||
|
|
|
|
|
#4 |
|
Alpha Male of Wc3c
Official Map Reviewer
|
So... like, how big of a difference are we talking here? Just saying its faster means nothing until you show it with benchmarks.
__________________ |
|
|
|
|
|
#6 |
|
Free Software Terrorist
Technical Director
|
I am not sure if it would be better to post it in TimerUtils, maybe it is better this way.
__________________ |
|
|
|
|
|
#8 |
|
Dread Lord of the Cookies
Content Director
|
Benchmarks or I graveyard. Particularly against red, since this is almost no safer than red. You'll die to a timer leak, exactly the same conditions under which red will die if properly setup.
__________________ |
|
|
|
|
|
#9 |
|
Alpha Male of Wc3c
Official Map Reviewer
|
Well he did say it was slower than red but faster than blue. I really think it's just another example of "pick which of the 50 timer storages suits you best".
__________________ |
|
|
|
|
|
#10 | |
|
retired coder | real ilfe
|
Quote:
|
|
|
|
|
|
|
#11 | |
|
Dread Lord of the Cookies
Content Director
|
Quote:
Slower and not really any more safe implies GY. |
|
|
|
|
|
|
#12 |
|
Obscurity, the Art
|
I'm with Griffen on this one. I don't think having infinitely many storage systems merits anything other than Blue or Red. Those two cover everything we could possibly need fine and dandy. Unless this method is faster than Blue, it really isn't valid. Red works totally differently, which is why it's a different flavour in the first place.
__________________ |
|
|
|
|
|
#13 | ||||
|
retired coder | real ilfe
|
Quote:
Quote:
Quote:
Quote:
So, before we all make more posts about this matter, to resume what we should do/need: benchmarks |
||||
|
|
|
|
|
#15 | |
|
retired coder | real ilfe
|
Quote:
|
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
|
|
|
Donate |