HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Recycling Systems

07-03-2008, 10:20 AM#1
Flame_Phoenix
I've talking to some people, they all agree that recycling timers is good.
Also, it seems that recycling groups is good as well.
Thing is, why don't we recycle everything ?
Would recycling effects and texttags be good and useful as well ?
Would people be interested in such a system ?
Would it be approved if I made it ?
07-03-2008, 11:01 AM#2
moyack
Because not all the handles allows a proper recycling like timers and groups.

For example an effect must be destroyed in order to change its model path for instance, so there's no recycling procedure there.

About the texttag, it's not necessary because they're recycled internally.
07-03-2008, 12:55 PM#3
grim001
It is quite a good thing to recycle units as well, however, it is sometimes quite difficult since you can't bring normal units back from the dead. You'd have to fake their death. Also, there would be no way to guarantee that the unit is facing the right way when it is "respawned," which is probably the most problematic aspect.

The more handle types you can find a way to recycle, the better.
07-03-2008, 01:06 PM#4
Flame_Phoenix
Ok, thx for your posts guys =)
07-03-2008, 01:38 PM#5
Vexorian
Quote:
It is quite a good thing to recycle units as well, however, it is sometimes quite difficult since you can't bring normal units back from the dead. You'd have to fake their death
in my arena I used a hidden area where I moved corpses and made a dummy unit cast ressurection.
07-03-2008, 06:53 PM#6
moyack
Now that we're talking about recycling handles.... I didi this just for fun:

Collapse JASS:
struct Timer
    private static integer index = 0
    timer t = CreateTimer()
    
    static method create takes nothing returns Timer
        local Timer T = Timer.allocate()
        if integer(T) > Timer.index then
            set Timer.index = integer(T)
        endif
        return T
    endmethod
    
    method Start takes real period, real periodic, code Loop returns nothing
        call TimerStart(.t, period, periodic, Loop)
    endmethod
    
    method Release takes nothing returns nothing
        call PauseTimer(.t)
        if integer(this) == Timer.index then
            set Timer.index = Timer.index - 1
        endif
        call .destroy()
    endmethod
    
    static method GetTimer takes timer t returns Timer
        local integer i = 1
        local Timer T
        loop
            exitwhen i > Timer.index
            set T = Timer(i)
            if t == T.t then
                return T
            endif
            set i = i + 1
        endloop
        return 0
    endmethod
endstruct

struct Group
    private static integer index = 0
    group g = CreateGroup()
    
    static method create takes nothing returns Group
        local Group G = Group.allocate()
        if integer(G) > Group.index then
            set Group.index = integer(G)
        endif
        return G
    endmethod
    
    method Release takes nothing returns nothing
        call GroupClear(.g)
        if integer(this) == Group.index then
            set Group.index = Group.index - 1
        endif
        call .destroy()
    endmethod
    
    static method GetGroup takes group g returns Group
        local integer i = 1
        local Group G
        loop
            exitwhen i > Group.index
            set G = Group(i)
            if g == G.g then
                return G
            endif
            set i = i + 1
        endloop
        return 0
    endmethod
endstruct

This will work (in theory) exactly like CSSafety in the last version.
07-03-2008, 07:49 PM#7
Here-b-Trollz
Quote:
Originally Posted by moyack
Now that we're talking about recycling handles.... I didi this just for fun:

Collapse JASS:
struct Timer
    private static integer index = 0
    timer t = CreateTimer()
    
    static method create takes nothing returns Timer
        local Timer T = Timer.allocate()
        if integer(T) > Timer.index then
            set Timer.index = integer(T)
        endif
        return T
    endmethod
    
    method start takes real period, real periodic, code Loop returns nothing
        call TimerStart(.t, period, periodic, Loop)
    endmethod
    
    method release takes nothing returns nothing
        call PauseTimer(.t)
        if integer(this) == Timer.index then
            set Timer.index = Timer.index - 1
        endif
        call .destroy()
    endmethod
    
    static method getExpired takes nothing returns Timer
        local integer i = 1
        local timer t=GetExpiredTimer()
        local Timer T
        loop
            exitwhen i > Timer.index
            set T = Timer(i)
            if t == T.t then
                    return T
            endif
            set i = i + 1
        endloop
        return 0
    endmethod
endstruct

This will work (in theory) exactly like CSSafety in the last version.

Or something similar.
07-03-2008, 07:51 PM#8
Flame_Phoenix
MMmm, so it is more advanced than CSSafety 14.1 and is better ??
You did your own system ! You should submit it ! xD
Which one you guys advice ?? This system or CSSafety 14.1 ?
07-03-2008, 07:59 PM#9
Here-b-Trollz
It's not advanced... it's OOP. Theoretically they should work the same, except the OOP version removes direct handle manipulation.

Collapse CSSafetyVersion:
function a takes nothing returns nothing
    local timer t=NewTimer()
    call StoreInteger(Cache(),I2S(H2I(t)),"tag",1234)
    call TimerStart(t,.035,true,function callback)
endfunction

Collapse OOPVersion:
function b takes nothing returns nothing
    local Timer T=Timer.create()
    set T.tag=1234
    call T.start(.035,true,function callback)
endfunction
07-03-2008, 08:32 PM#10
Flame_Phoenix
So, which one is the best ?
07-03-2008, 08:45 PM#11
Here-b-Trollz
The one that you'd rather use. It's mostly about syntax. As far as attaching goes, OOP is better, but there are ways to get around that... I can't remember the last time I actually had a *use* for attaching something to a timer.
07-03-2008, 08:51 PM#12
Vexorian
That thing moyack has created is leaking timers, not recycling them.
07-03-2008, 08:54 PM#13
moyack
Errrrr.... mine?

Mr trollz option is a small variant of mine (very valid BTW), which is more specific when we need to call it in a looping function to get the Timer variable related to the expired timer.

Quote:
That thing moyack has created is leaking timers, not recycling them.
WHAT!??!!!!
07-03-2008, 09:12 PM#14
Here-b-Trollz
Note that neither of the OOP versions (moyack's or my slightly edited version of moyacks) will actually compile, since I'm to lazy to fix 'real periodic' --> 'boolean periodic', and also the allocate method doesn't look very hopeful to me... but I've never understood this 'clever' allocate method.
07-03-2008, 09:40 PM#15
Flame_Phoenix
Lol ... i guess I will stick to CSSafety 14.1 for now right ? xD