• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

AC: Recycling System v1.0

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
Short documentation:
1. What is AC?
AC stands for Aghora Core.
Aghora Core is the basic functions of upcoming TGM Team project: Aghora: The Beginning of the Path.
The core will be available to download and comment at The Hive Workshop.

2. What is Recycling System?
Recycling System is the system that allows to re-use objects that had been created before.
How it works?

Timers:
- If no timers in the database or all the timers are busy now, then creating a new timer.
- If the timer was marked to the system as used, it will be available to re-use.

Units:
- If no units in the database or all the units of this type are busy now, then creating a new unit.
- If the unit was marked to the system as used, it will be available to re-use.

3. How to use this Recycling System?
RS_GetRecycledTimer - use instead of CreateTimer(), that function will return a timer that can be recycled.
RS_RecycleTimer - use instead of PauseTimer() and DestroyTimer() when destroying the timer in your code.
NOTE! When you want just to pause the timer temporarily, use PauseTimer() function!
RS_PlaceRecycledUnit - use instead of CreateUnit(), that function will return a unit that can be recycled.
RS_RecycleUnit - use instead of RemoveUnit() function to make it available for recycling.
NOTE! That will make the unit disappear, not killed!
RS_RecycleUnitTimed - use instead of UnitApplyTimedLife() function when you want to wait some time and remove the unit.
RS_RecycleUnitWithModel - use instead of KillUnit(), that will play Death animation, but give a correct duration of this animation!
RS_Initialization - the function that initializes the system. Call it in Map Initialization.

4. How to import the system?
1. Create a global hashtable named 'E_RecycleHash'.
2. Import the code from this map code to the map code of your map.
3. Enjoy using the system!

JASS:
// ********************************************************
// *                                                      *
// *                   RECYCLING SYSTEM                   *
// *               for AC, by Simplar Duoson              *
// *                    aka bowser499                     *
// *                                                      *
// ********************************************************

// Timer Recycling

function RS_GetRecycledTimer takes nothing returns timer 
    local integer timerIndex = LoadInteger(udg_E_RecycleHash,1,0)
    if timerIndex == 0 then
        call SaveTimerHandle(udg_E_RecycleHash,1,timerIndex,CreateTimer())
    else
        set timerIndex = timerIndex - 1
        call SaveInteger(udg_E_RecycleHash,1,0,timerIndex)
    endif
    return LoadTimerHandle(udg_E_RecycleHash,1,timerIndex)
endfunction

function RS_RecycleTimer takes timer whichTimer returns nothing
    local integer timerIndex = LoadInteger(udg_E_RecycleHash,1,0)
    if whichTimer != null then
        call PauseTimer(whichTimer)
        call SaveTimerHandle(udg_E_RecycleHash,1,timerIndex,whichTimer)  
        call SaveInteger(udg_E_RecycleHash,1,0,timerIndex+1)  
    endif    
endfunction

// Unit Recycling

function RS_PlaceRecycledUnit takes player unitOwner, integer unitType, real unitX, real unitY, real unitFacing returns unit
    local integer unitIndex = LoadInteger(udg_E_RecycleHash,unitType,0)
    local unit loadedUnit
    if unitIndex == 0 then
        call SaveUnitHandle(udg_E_RecycleHash,unitType,unitIndex,CreateUnit(unitOwner,unitType,unitX,unitY,unitFacing))
    else
        set unitIndex = unitIndex - 1
        call SaveInteger(udg_E_RecycleHash,unitType,0,unitIndex)
        set loadedUnit = LoadUnitHandle(udg_E_RecycleHash,unitType,unitIndex)
        call SetUnitAnimation(loadedUnit,"stand")
        call SetUnitX(loadedUnit,unitX)
        call SetUnitY(loadedUnit,unitY)
        call SetUnitFacing(loadedUnit,unitFacing)
        set loadedUnit = null
    endif
    return LoadUnitHandle(udg_E_RecycleHash,unitType,unitIndex)
endfunction

function RS_RecycleUnit takes unit whichUnit returns nothing
    local integer unitType = GetUnitTypeId(whichUnit)
    local integer unitIndex = LoadInteger(udg_E_RecycleHash,unitType,0)
    if whichUnit != null then
        call SetUnitX(whichUnit,GetRectMinX(bj_mapInitialPlayableArea))
        call SetUnitY(whichUnit,GetRectMinY(bj_mapInitialPlayableArea))
        call SaveUnitHandle(udg_E_RecycleHash,unitType,unitIndex,whichUnit)  
        call SaveInteger(udg_E_RecycleHash,unitType,0,unitIndex+1)  
    endif    
endfunction

// Timed Unit Recycling

function RS_RecycleUnitTimed_Timer takes nothing returns nothing
    local timer timePasser = GetExpiredTimer()
    local integer timePasserId = GetHandleId(timePasser)
    local unit whichUnit = LoadUnitHandle(udg_E_RecycleHash,timePasserId,0)
    
    call RS_RecycleUnit(whichUnit)    
    call FlushChildHashtable(udg_E_RecycleHash,timePasserId)
    call RS_RecycleTimer(timePasser)
    
    set timePasser = null
    set whichUnit = null
endfunction

function RS_RecycleUnitTimed takes unit whichUnit, real timeBeforeRecycling returns nothing
    local timer timePasser = RS_GetRecycledTimer()
    local integer timePasserId = GetHandleId(timePasser)
    
    call SaveUnitHandle(udg_E_RecycleHash,timePasserId,0,whichUnit)
    call TimerStart(timePasser,timeBeforeRecycling,false,function RS_RecycleUnitTimed_Timer)
    
    set timePasser = null
endfunction

function RS_RecycleUnitWithModel takes unit whichUnit, real deathAnimDuration returns nothing
    call SetUnitAnimation(whichUnit,"death")
    call RS_RecycleUnitTimed(whichUnit,deathAnimDuration)
endfunction

// Recycle Initialization

function RS_Initialization takes nothing returns nothing
    set udg_E_RecycleHash = InitHashtable()
endfunction

Credit bowser499 aka [DUOS] if you will use it.

Keywords:
Aghora, Core, Recycling, System, Timer, Unit, Code, Jass, Useful, Optimize, Lags
Contents

AC Recycling System v1.0 (Map)

Reviews
12th Dec 2015 IcemanBo: Too long as NeedsFix. Rejected. 23:07, 2nd Jan 2013 Magtheridon96: In the timer recycler: call SaveTimerHandle(udg_E_RecycleHash,1,timerIndex,CreateTimer()) This can be replaced with return CreateTimer(). Also...

Moderator

M

Moderator

12th Dec 2015
IcemanBo: Too long as NeedsFix. Rejected.

23:07, 2nd Jan 2013
Magtheridon96:

In the timer recycler:
call SaveTimerHandle(udg_E_RecycleHash,1,timerIndex,CreateTimer())
This can be replaced with return CreateTimer().

Also, the unit recycler has bad semantics.
A user will pass in a player, expecting you to create a dummy for that player, but if a recycled unit already exists in the stack, you will give him a unit with an unknown owner.

I think the best solution is to ignore coordinates.
Just return a unit from the stack after setting his animation to "stand".
Facing and coordinates should be handled by the user.

Currently, this unit recycler is unsuitable for projectile systems in the aesthetic field because of the absence of a by-angle recycling method :/. I'd recommend looking into Nestharus' Dummy lib. It's perfect for this kind of thing. In fact, if you would take his code in the compiled JASS form and clean it, I would approve the resource with Nes' permission.

(You made this for projectile recycling mainly, am I right?)
 
Level 3
Joined
Sep 12, 2011
Messages
47
hmmm.not bad.Even though we have Timer Utils and Unit Recyler codes.
I think some of your JASS functions w/c are used in other triggers only works for JASSHelper.Standard JASS functions only work w/ ExecuteFunc when used by other triggers.Anyways,ill rank 4/5 because some systems are better than this.
Coded on JASS2?
 
Last edited:
Level 14
Joined
Jun 27, 2008
Messages
1,325
4. How to import the system?
1. Create a global hashtable named 'E_RecycleHash'.
Would be cooler if the creation of globals was done automatically...


JASS:
function RS_GetRecycledTimer takes nothing returns timer 
    local integer timerIndex = LoadInteger(udg_E_RecycleHash,1,0)
    if timerIndex == 0 then
        call SaveTimerHandle(udg_E_RecycleHash,1,timerIndex,CreateTimer())
    else
        set timerIndex = timerIndex - 1
        call SaveInteger(udg_E_RecycleHash,1,0,timerIndex)
    endif
    return LoadTimerHandle(udg_E_RecycleHash,1,timerIndex)
endfunction

JASS:
function RS_GetRecycledTimer takes nothing returns timer 
    local integer timerIndex = LoadInteger(udg_E_RecycleHash,1,0)
	local timer t
    if timerIndex == 0 then
		set t = CreateTimer()
        call SaveTimerHandle(udg_E_RecycleHash,1,timerIndex,t)
    else
        set timerIndex = timerIndex - 1
        call SaveInteger(udg_E_RecycleHash,1,0,timerIndex)
		set t = LoadTimerHandle(udg_E_RecycleHash,1,timerIndex)
    endif
    return t
endfunction
this should be faster
 
Top