Snippet Recycle

library Recycle
    public constant boolean AUTO_CLEAR = true
/*Utility Information
Name: Recycle
Version: 6.0
Author: Nestharus
-Help from Jesus4Lyf for initial designs

    What does it do-
        Recycles handles so that when getting new handles of the same type,
        a recycled handle can be returned instead of creating a new handle. This
        increases map performance.
Requirements: NA

Installation: NA

    If true, will automatically clear out recycled handles (GroupClear,
    PauseTimer) at a slight performance hit.

-get returns type
    will return the type
    timer t = Timer.get()

-release(type h)
    Will release the type and stop it.
    timer t = Timer.get()
    //! textmacro CREATE_STACK takes name, type, clean, create
        struct $name$ extends array
            public $type$ handles
            public static integer index = 0
            public static method release takes $type$ h returns nothing
                static if DEBUG_MODE then
                    if h == null then
                        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "ERROR - Recycle: Freed null handle.")
                    if $name$.index > 8190 then
                        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "ERROR - Recycle: Overfilled recycle stack (8191 released objects)!")
                static if AUTO_CLEAR then
                set $name$[$name$.index].handles = h
                set $name$.index = $name$.index + 1

            public static method get takes nothing returns $type$
                if $name$.index == 0 then
                    return $create$
                set $name$.index = $name$.index - 1
                return $name$[$name$.index].handles
    //! endtextmacro
    //! runtextmacro CREATE_STACK("Timer", "timer", "call PauseTimer(h)", "CreateTimer()")
    //! runtextmacro CREATE_STACK("Group", "group", "call GroupClear(h)", "CreateGroup()")


(Evol)ution is nothing without love.
This is way overdone, couldn't you have added "plugins", and etc. at least?

I just made this because I was making a variety of things that used unit groups and timers and so on, but I didn't necessarily need data attachment and I didn't want them all to use their own pools because that'd be pointless =).

I could have made a whole bundle of pools, or I could have just made it a small text macro with standardized names =).

Also I don't see how it is overdone...

It's 2 vars, 2 functions, and the functions are only like 3-5 lines long.. : o


(Evol)ution is nothing without love.
I mean... Add functions similar to groups within Warcraft 3, count the number of items, or other stuff, for handles such as integers or units.
Oh you mean.. return how many free handles there are?

why? lol

This is for handles that aren't being used aka not in the map aka don't exist


(Evol)ution is nothing without love.
The name threw me off, a pool is a stack of something, so you can get it at any time within the pool or etc. It's named kind of weird for that purpose.
That's what a pool is in normal programming, lol... well, pools normally create like 25 things or w/e first and then w/e uses those things =). It's mostly used for like when people access a server so you don't have to create/destroy for every user ^_^.


Old World Ghost
call $stop$

And if you don't have a stop function for your type? It tries to call "call <blank>" and you get a syntax error? I recommend taking out "call" there and let the one using the textmacro add it in if needed.
This had a really stupid suggestion in it and I removed it and so... to replace the suggestion I guess I'll say-

Comments anyone? ; o
This is cool, but I wish it could use function syntax instead of method/struct one. I was thinking the usual stuff like New/Release but that may cause interference with Timer/Group Utils.

Actually, just leave it like this, it seems fine. :thup:
Also, I think TimerUtils is a thing of the past as it has pretty much the exact same stack as this. The difference is this doesn't do the arbitrary GetHandleId on NewTimer().

Now people can attach data to timers themselves with the very simple GetHandleId-offset or SaveInteger(hash, GetHandleId)

It will be slightly faster than TimerUtils red and blue versions respectively in every scenario because of the -1 function call : ). Also, it will only attach data and remove data when there is actually data as people will manage it themselves. It's too simple to make a whole attachment system like that. Attachment systems are just things of the past ^_^, unless of course they're handling very complex parallel arrays... ^_^.

The cool thing is Key Timers 2 and Timer32 will still have their places. Why? Key Timers 2 runs arbitrary code faster than even regular timers and Timer32 does timed stacks : D.

Key Timers 2 might be even faster by using which ever recycle utility becomes the standard : D.
And KT2 doesn't destroy timers or triggers, so it has no need to use a recycle system like this - it recycles things internally, actually - complicated things.
I know =), but if you used a global pool you'd be making the overall map faster wouldn't you : ). People would use timers created by KT2 when they weren't in use and KT2 would be using timers created by people when they aren't in use. It was just a thought, that's why I said it might be faster ^_^, but then again you are the author of KT2 so you would know better : D.

It will be slightly faster than TimerUtils red and blue versions respectively in every scenario
This will only be faster for waits, not periodic things.
Not sure how that would work ^_^.

Oh well, a lot of this was just speculation on my part ; ), but I just don't see how TimerUtils can be faster than timers if TimerUtils does GetHandleId where the timers might now : o.


You can change this now in User CP.
Actually i suspect GetHandleId is the only one return bug allowed, i mean when the script is compiled, it basically convert GetHandleId to the return bug.
Pure guess, thought, and sorry if i say some shit.

At least that would give a sense to this sentence :
GetHandleId takes a handle and returns an integer. GetHandleId works exactly like H2I functions that were written with the return bug. In order to reduce the number of JASS naming conflicts with existing maps, we named the function GetHandleId. We ask map makers to not create a GetHandleId alias function with the name H2I, as we will add a native H2I function to JASS in the future.
So maybe if/when this new native will come, it will be faster.
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    The old shoutbox wasn't supported anymore. We updated xenForo, so it had to be replaced.
  • jonas jonas:
    let's see if everyone finds it... the nice thing about the shoutbox was I could check on it even while logged out, but the existence of this one is hidden when you're not logged in
  • Ghan Ghan:
    We can fix that.
  • Ghan Ghan:
    Chat should show on the sidebar when not logged in now.
  • Ghan Ghan:
    (You'll still need to log in to post messages)
  • Ghan Ghan:
  • tom_mai78101 tom_mai78101:
    I must be in a test server.
  • tom_mai78101 tom_mai78101:
    Nice, Twitter tweets embedding now works
  • Wizard Wizard:
  • Ghan Ghan:
  • Ghan Ghan:
    @tom_mai78101 Hello there.
  • Ghan Ghan:
    Tagging works in the chat too.
  • tom_mai78101 tom_mai78101:
    @Ghan Missed it.
  • Wizard Wizard:
    Still fixing things here and there. Added widgets to the portal, will make it match the ones here on the forum index tomorrow.
  • Ghan Ghan:
    The venerable World Editor Tutorials site has been converted to HTTPS at last.
  • jonas jonas:
  • jonas jonas:
    and I can even edit my messages, nice
  • seph ir oth seph ir oth:
  • Ghan Ghan:
    Hello there
  • The Helper The Helper:
    this new chatbox is great and the forum software update is great too
  • The Helper The Helper:
    upgrade has fixed forum registration spam problem
  • tom_mai78101 tom_mai78101:
    Something tells me we might be able to customize the chatbox a bit, considering that there's a gap under every message.
  • Wizard Wizard:
    Going to deploy a fix soon, just had to take some time for myself this weekend.
  • Varine Varine:
    Unbelievable. Time for yourself? How dare you!

    Staff online

    Members online


    Hive Workshop