- Joined
- Jun 21, 2012
- Messages
- 431
JASS:
library HandlerCode/*
***************************************************************************************
*
* HandlerCode
* ¯¯¯¯¯¯¯¯¯¯¯
* v2.0.0.0
* by Thelordmarshall
*
* Allow to set/run "codes" in array vars; this version no longer uses hashtable,
* unsafest but more fastest. HOWEVER you can change the max code size.
*
* local HandlerCode h = 0
* set h.code = function MyFunction
* - or -
* set h = HandlerCode.getHandle(function MyFunction)
* call h.run() or call h.debugRun()
*
* API:
* ¯¯¯
* struct HandlerCode extends array
*
* - readonly static integer size
*
* - method operator code= takes code c returns HandlerCode
* - static method getHandle takes code c returns HandlerCode
* - method run takes nothing returns boolean
* - debug method debugRun takes nothing returns boolean
*
**************************************************************************************/
globals
//if you need more arrays, change this value
private constant integer MAX_CODE_SIZE = 0x4000
endglobals
struct HandlerCode extends array
readonly static integer size=0
private static integer array handleId[MAX_CODE_SIZE]
private static trigger array trigger[MAX_CODE_SIZE]
private static method id takes conditionfunc c returns thistype
local integer i=GetHandleId(c)-0x100000
local integer id=handleId[i]
if(0!=id)then
return id
endif
set size=size+1
set handleId[i]=size
set trigger[size]=CreateTrigger()
call TriggerAddCondition(trigger[size],c)
return size
endmethod
method run takes nothing returns boolean
return TriggerEvaluate(trigger[this])
endmethod
debug method debugRun takes nothing returns boolean
debug if(null==trigger[this])then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"[HandlerCode] error: attempted to run null code")
debug endif
debug return run()
debug endmethod
static method getHandle takes code c returns HandlerCode
return id(Condition(c))
endmethod
method operator code= takes code c returns HandlerCode
return id(Condition(c))
endmethod
endstruct
endlibrary
Last edited: