Snippet Recycle

Nestharus

o-o
Reaction score
84
JASS:
library Recycle
//settings
globals
    public constant boolean AUTO_CLEAR = true
endglobals
/*Utility Information
//===================================================================
Name: Recycle
Version: 6.0
Author: Nestharus
-Help from Jesus4Lyf for initial designs

Description:
    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

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

Functions:
------------------------------------------------------------------
-get returns type
    will return the type
    
    Timer.get()
    Group.get()
    
    ex-
    timer t = Timer.get()

-release(type h)
    Will release the type and stop it.
    
    Timer.release(h)
    Group.release(h)
    
    ex-
    timer t = Timer.get()
    Timer.release(t)
------------------------------------------------------------------*/
    //! 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.")
                    endif
                    if $name$.index > 8190 then
                        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "ERROR - Recycle: Overfilled recycle stack (8191 released objects)!")
                    endif
                endif
                static if AUTO_CLEAR then
                    $clean$
                endif
                set $name$[$name$.index].handles = h
                set $name$.index = $name$.index + 1
            endmethod

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

Renendaru

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

Nestharus

o-o
Reaction score
84
Huh..

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
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
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.
 

Nestharus

o-o
Reaction score
84
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
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
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.
 

Nestharus

o-o
Reaction score
84
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 ^_^.
 

Azlier

Old World Ghost
Reaction score
461
JASS:
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.
 

Nestharus

o-o
Reaction score
84
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
 
Reaction score
91
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:
 

Nestharus

o-o
Reaction score
84
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.
 

Nestharus

o-o
Reaction score
84
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.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
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.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top