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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top