wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 02-17-2009, 10:46 AM   #1
Iron_Doors
User
 
Join Date: Aug 2007
Posts: 50

Submissions (1)

Iron_Doors will become famous soon enough (31)Iron_Doors will become famous soon enough (31)

Default TimerUtils (Purple)

A third flavor to accompany Vexorian's Blue and Red TimerUtils.

Table:
Purple TimerUtils
- Uses the attaching method used in an early version of Cohadar's ABCT (which is a tiny bit different from what he uses now)
- array lookup, multiplication, division, subtraction, H2I (Get/SetTimerData get inlined)
- There is a theoretical condition for this to work in your map, which is that you can have no more than 4096 timers simultaneously, and in practice I'd assume no more than 3000.

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.

Collapse 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.
Iron_Doors is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 02-17-2009, 12:46 PM   #2
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

- Pick another color, green is reserved for a different implementation.
- This is faster than blue when using certain definitions of faster.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 02-17-2009, 01:09 PM   #3
Iron_Doors
User
 
Join Date: Aug 2007
Posts: 50

Submissions (1)

Iron_Doors will become famous soon enough (31)Iron_Doors will become famous soon enough (31)

Default

Quote:
Originally Posted by Vexorian
- Pick another color, green is reserved for a different implementation.
As you wish :)

Quote:
Originally Posted by Vexorian
- This is faster than blue when using certain definitions of faster.
I don't get what you're trying to say here to be honest, but I hope its nothing bad.
Iron_Doors is offline   Reply With Quote
Old 02-17-2009, 01:57 PM   #4
darkwulfv
Alpha Male of Wc3c
 
darkwulfv's Avatar


Official Map Reviewer
 
Join Date: Mar 2006
Posts: 3,646

Submissions (6)

darkwulfv is just really nice (270)darkwulfv is just really nice (270)

Send a message via AIM to darkwulfv
Default

So... like, how big of a difference are we talking here? Just saying its faster means nothing until you show it with benchmarks.
__________________
The Spell Request Thread
Quote:
Originally Posted by Joe-Black-5
a dota like map but with unique stuff
(There was no map attached, and that was all the thread said.)
Spells I've Made

Darkwulfv's Lightning Grapple || Tritanis' Lazy Bolt

darkwulfv is offline   Reply With Quote
Old 02-17-2009, 02:07 PM   #5
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,727

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

You know, just posting TimerUtils with a different implementation of its storage doesn't merit approval or anything. Post it in the TimerUtils thread.
__________________
Rising_Dusk is offline   Reply With Quote
Old 02-17-2009, 02:09 PM   #6
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

I am not sure if it would be better to post it in TimerUtils, maybe it is better this way.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 02-17-2009, 02:11 PM   #7
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,727

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

Well you're the boss. I think this is quite silly, though.
__________________
Rising_Dusk is offline   Reply With Quote
Old 02-17-2009, 02:41 PM   #8
Captain Griffen
Dread Lord of the Cookies
 
Captain Griffen's Avatar


Content Director
 
Join Date: Sep 2003
Posts: 5,368

Submissions (2)

Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)

Approved Map: Warlords[Quicksilver #2] - 1st Place

Default

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.
__________________
Quote:
Originally Posted by Earth-Fury
Griffen is correct, you are not.
Quote:
[13:32] <Akolyt0r> hmm.. stil i want to have some unused women
Captain Griffen is offline   Reply With Quote
Old 02-17-2009, 02:47 PM   #9
darkwulfv
Alpha Male of Wc3c
 
darkwulfv's Avatar


Official Map Reviewer
 
Join Date: Mar 2006
Posts: 3,646

Submissions (6)

darkwulfv is just really nice (270)darkwulfv is just really nice (270)

Send a message via AIM to darkwulfv
Default

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".
__________________
The Spell Request Thread
Quote:
Originally Posted by Joe-Black-5
a dota like map but with unique stuff
(There was no map attached, and that was all the thread said.)
Spells I've Made

Darkwulfv's Lightning Grapple || Tritanis' Lazy Bolt

darkwulfv is offline   Reply With Quote
Old 02-17-2009, 02:49 PM   #10
Flame_Phoenix
retired coder | real ilfe
 
Flame_Phoenix's Avatar
 
Join Date: Mar 2007
Posts: 2,208

Submissions (10)

Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)

Send a message via MSN to Flame_Phoenix
Default

Quote:
"pick which of the 50 timer storages suits you best".
Amen
__________________
Check out my tutorials at:
1-Creating a Hero Tavern
2-Complete Icon Tutorial - ALL about Icons
3-Making a spell in vJass - Practice Session 1
Check out all my current spells at here
Finally, check my project:
Castle vs Castle Flame Edition
Flame_Phoenix is offline   Reply With Quote
Old 02-17-2009, 04:27 PM   #11
Captain Griffen
Dread Lord of the Cookies
 
Captain Griffen's Avatar


Content Director
 
Join Date: Sep 2003
Posts: 5,368

Submissions (2)

Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)

Approved Map: Warlords[Quicksilver #2] - 1st Place

Default

Quote:
Originally Posted by darkwulfv
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".

Slower and not really any more safe implies GY.
__________________
Quote:
Originally Posted by Earth-Fury
Griffen is correct, you are not.
Quote:
[13:32] <Akolyt0r> hmm.. stil i want to have some unused women
Captain Griffen is offline   Reply With Quote
Old 02-17-2009, 05:15 PM   #12
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,727

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

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.
__________________
Rising_Dusk is offline   Reply With Quote
Old 02-17-2009, 06:35 PM   #13
Flame_Phoenix
retired coder | real ilfe
 
Flame_Phoenix's Avatar
 
Join Date: Mar 2007
Posts: 2,208

Submissions (10)

Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)

Send a message via MSN to Flame_Phoenix
Default

Quote:
Originally Posted by Rising_Dusk
Unless this method is faster than Blue, it really isn't valid.
Quote:
Originally Posted by Iron_Doors
In short, this thing is faster than the Blue flavor but still safe enough for most.
Quote:
Originally Posted by Vexorian
- This is faster than blue when using certain definitions of faster.
Quote:
Originally Posted by Griffen
Benchmarks or I graveyard.

So, before we all make more posts about this matter, to resume what we should do/need: benchmarks
__________________
Check out my tutorials at:
1-Creating a Hero Tavern
2-Complete Icon Tutorial - ALL about Icons
3-Making a spell in vJass - Practice Session 1
Check out all my current spells at here
Finally, check my project:
Castle vs Castle Flame Edition
Flame_Phoenix is offline   Reply With Quote
Old 02-17-2009, 06:59 PM   #14
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,727

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

We all know it needs benchmarks, dude, but we're still free to voice our stance on the matter pending such benchmarks.
__________________
Rising_Dusk is offline   Reply With Quote
Old 02-17-2009, 07:14 PM   #15
Flame_Phoenix
retired coder | real ilfe
 
Flame_Phoenix's Avatar
 
Join Date: Mar 2007
Posts: 2,208

Submissions (10)

Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)Flame_Phoenix has a spectacular aura about (90)

Send a message via MSN to Flame_Phoenix
Default

Quote:
We all know it needs benchmarks, dude, but we're still free to voice our stance on the matter pending such benchmarks.
True, but there isn't much to talk about without benchmarks, I mean, most of it will be speculation (which is bad imho).
__________________
Check out my tutorials at:
1-Creating a Hero Tavern
2-Complete Icon Tutorial - ALL about Icons
3-Making a spell in vJass - Practice Session 1
Check out all my current spells at here
Finally, check my project:
Castle vs Castle Flame Edition
Flame_Phoenix is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 11:04 PM.


Donate

Affiliates
The Hubb http://bylur.com - Warcraft, StarCraft, Diablo and DotA Blog & Forums The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2014, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services