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