- Joined
- Jan 21, 2006
- Messages
- 2,552
Utilities Library by Berb
This is a really basic library based on a concept that was mentioned in the forums by azlier I believe. It takes advantage of the vJass struct syntax, using the struct recycling system in order to grab global and timer handles without having to ever destroy a timer.
This is a really basic library based on a concept that was mentioned in the forums by azlier I believe. It takes advantage of the vJass struct syntax, using the struct recycling system in order to grab global and timer handles without having to ever destroy a timer.
JASS:
library UtilityLib
//##################################################################################################
//# ________________________________________________________________________________________________
//#
//# U T I L I T I E S v 1.0
//# by Berb
//#
//# ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
//##################################################################################################
/***************************
* Description:
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* This library uses the built-in recycling system used for structs (global arrays) to produce a
* basic syntax in order to take advantage of this and eliminate some of the problems that can
* arise when these types of handles are created and destroyed. Instead they will merely be
* recycled using very basic vJass syntax.
*
* s_timer
* ================================================================================================
* static method create( ) -> This will allocate a global array from the stack
* encapsulated in a struct, so that the recycling is
* handled by the vJass syntax conversion.
*
* method destroy( ) -> This will cause a timer to be recycled; basically
* it will simply pause the timer and ready it for the
* next time it needs to be used.
*
* s_group
* ================================================================================================
* static method create( ) -> This will allocate a global array from the stack
* encapsulated in a struct, similar to s_timer.create( ).
*
* method destroy( ) -> This will recycle the group for further use, similar
* to s_timer's .destroy( ) static method.
*
***************************************************************************************************/
// Implementation:
// local s_group g = s_group.create()
//
// // Now you can reference your group as "g.group".
// call GroupEnumUnitsInRange(g.group, 0, 0, 500, null)
// call ForGroup(g.group, function DoNothing) //you get the point
//
// // Remember you need to destroy the group when you're done with it.
// call g.destroy( )
//
struct s_group
group group
method onDestroy takes nothing returns nothing
call GroupClear(group)
endmethod
static method create takes nothing returns thistype
local thistype g=allocate( )
if g.group==null then
set g.group=CreateGroup( )
endif
return g
endmethod
endstruct
// Implementation:
// local s_timer t = s_timer.create()
//
// // Now you can reference your timer as "t.timer"
// call TimerStart(t.timer, 0, false, null)
// call TriggerSleepAction(0)
//
// // Remember you need to destroy the timer when you're done with it.
// call t.destroy( )
//
struct s_timer
timer timer
method onDestroy takes nothing returns nothing
call PauseTimer(timer)
endmethod
static method create takes nothing returns thistype
local thistype t=allocate( )
if t.timer==null then
set t.timer=CreateTimer( )
endif
return t
endmethod
endstruct
endlibrary