Nestharus
o-o
- Reaction score
- 84
note
Still working this out ><. Current design only has safety in debug for red, but red can crash the map if you have too many handles because it tries to be as fast as possible :\. It generates a pool of timers and groups at the start based on how many you specify as well. Actually, without safety red is just like TimerUtils orange :\. With safety, it might be slower than blue ><.
Uh... I just don't see how to make red version stable unless I do linked offsets.
Fast but optional Data Attachment for use with Recycle
In essence, this is very much like TimerUtils and so on, except that it goes through Recycle. It was split from Recycle to give two different venues for handle retrieval. Releasing a handle from here will automatically go through data attachment clearing in the release. Releasing a handle from Recycle won't.
Also, if you want to attach data to a given handle, you can use any handle in this. Next, you don't have to release a handle with attached data with this process. If you automatically initialize data, then it'd be better to release thru Recycle.
Still working this out ><. Current design only has safety in debug for red, but red can crash the map if you have too many handles because it tries to be as fast as possible :\. It generates a pool of timers and groups at the start based on how many you specify as well. Actually, without safety red is just like TimerUtils orange :\. With safety, it might be slower than blue ><.
Uh... I just don't see how to make red version stable unless I do linked offsets.
Fast but optional Data Attachment for use with Recycle
In essence, this is very much like TimerUtils and so on, except that it goes through Recycle. It was split from Recycle to give two different venues for handle retrieval. Releasing a handle from here will automatically go through data attachment clearing in the release. Releasing a handle from Recycle won't.
Also, if you want to attach data to a given handle, you can use any handle in this. Next, you don't have to release a handle with attached data with this process. If you automatically initialize data, then it'd be better to release thru Recycle.
JASS:
library Data initializer Initialization uses Recycle
//settings
globals
private constant boolean ATTACH_RED = true
private constant boolean ATTACH_BLUE = false
private constant boolean GLOBAL_GROUP = true
private constant integer TIMER_POOL_SIZE = 350
private constant integer GROUP_POOL_SIZE = 10
endglobals
/*Utility Information
//===================================================================
Name: Data
Version: 3.0
Author: Nestharus
Description:
What does it do-
Uses internal Recycle Vars for recycling handles and does data attachment
Requirements: Recycle- thehelper.net/forums/showthread.php?t=136087
Installation: NA
Variables:
------------------------------------------------------------------
ATTACH_RED-
Similiar to TimerUtils red
ATTACH_BLUE-
Similiar to TimerUtils blue
GLOBAL_GROUP-
A global group for use in enumerations
TIMER_POOL_SIZE-
How many timers for the timer pool to initially have
GROUP_POOL_SIZE-
How many groups for the group pool to initially have
Functions:
------------------------------------------------------------------
*ONLY IF GLOBAL GROUP IS ENABLED*
-GetGroup()
Returns a global group
-SetGroupData()
Sets value in global group
-GetGroupData()
Gets value from global group
-----------------------------------------------------------
-release(type h)
Will release the type and stop it.
DataTimer.release(h)
DataGroup.release(h)
ex-
timer t = DataTimer.get()
DataTimer.release(t)
-----------------------------------------------------------
*THESE ARE ONLY ENABLED IF ATTACH_RED OR ATTACH_BLUE ARE TRUE*
-setData(type var, integer value)
Sets integer data on type
DataTimer.setData(myTimer, 5)
DataGroup.setData(myGroup, 5)
-getData(type var) returns integer
Gets integer data on type
local integer hello = DataTimer.getData(myTimer)
local integer hello = DataGroup.getData(myGroup)
------------------------------------------------------------------*/
globals
private hashtable memory
private integer handleIterator
private group globalGroup
private integer globalGroupData
private integer handleId
private integer offsetId
endglobals
function GetGroup takes nothing returns group
return globalGroup
endfunction
function SetGroupData takes integer val returns nothing
set globalGroupData = val
endfunction
function GetGroupData takes nothing returns integer
return globalGroupData
endfunction
//! textmacro CREATE_DATA_STACK takes name, type, clean, create
struct Data$name$ extends array
private static delegate $name$ data$name$
public static integer offset
private static integer array data
public static method setData takes $type$ var, integer value returns nothing
static if ATTACH_RED
static if DEBUG_MODE then
if GetHandleId(var)-.offset > 8191 then
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "ERROR - Attach: Too many handles.")
return
endif
if GetHandleId(var)-.offset > 8191 then
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "More than one red offset, consider blue style")
return
endif
endif
set .data[GetHandleId(var)-.offset] = value
endif
static if ATTACH_BLUE
call SaveInteger(memory, GetHandleId(var), 0, value)
endif
endmethod
public static method getData takes $type$ var returns integer
static if ATTACH_RED
static if DEBUG_MODE then
if GetHandleId(var)-.offset > 8191 then
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "ERROR - Attach: Too many handles.")
return 0
endif
if GetHandleId(var)-.offset > 8191 then
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "More than one red offset, consider blue style")
return 0
endif
endif
return .data[GetHandleId(var)-.offset]
endif
static if ATTACH_BLUE
return LoadInteger(memory, GetHandleId(var), 0)
endif
return 0
endmethod
public static method release takes $type$ h returns nothing
static if DEBUG_MODE then
if .index > 8190 then
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "ERROR - Recycle: Overfilled recycle stack (8191 released objects)!")
endif
if h == null then
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "ERROR - Recycle: Freed null handle.")
endif
if GetHandleId(h)-.offset > 8191 then
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "More than one red offset, consider blue style")
return
endif
endif
static if Recycle_AUTO_CLEAR then
$clean$
endif
set $name$[.index].handles = h
set .index = .index + 1
static if ATTACH_RED
static if DEBUG_MODE then
if GetHandleId(h)-.offset > 8191 then
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "ERROR - Attach: Too many handles.")
return
endif
endif
set .data[GetHandleId(h)-.offset] = 0
endif
static if ATTACH_BLUE
call FlushChildHashtable(memory, GetHandleId(h))
endif
endmethod
endstruct
//! endtextmacro
//! runtextmacro CREATE_DATA_STACK("Timer", "timer", "call PauseTimer(h)", "CreateTimer()")
//! runtextmacro CREATE_DATA_STACK("Group", "group", "call GroupClear(h)", "CreateGroup()")
private function Initialization takes nothing returns nothing
static if GLOBAL_GROUP
set globalGroup = CreateGroup()
endif
static if ATTACH_RED
if GROUP_POOL_SIZE != 0 then
set handleIterator = GROUP_POOL_SIZE-1
set Group.index = GROUP_POOL_SIZE
loop
set Group[handleIterator].handles = CreateGroup()
set handleIterator = handleIterator - 1
exitwhen handleIterator < 0
endloop
set DataGroup.offset = GetHandleId(Group[Group.index-1].handles)
endif
if TIMER_POOL_SIZE != 0 then
set Timer.index = TIMER_POOL_SIZE
set handleIterator = TIMER_POOL_SIZE-1
loop
set Timer[handleIterator].handles = CreateTimer()
set handleIterator = handleIterator - 1
exitwhen handleIterator < 0
endloop
set DataTimer.offset = GetHandleId(Timer[Timer.index-1].handles)
endif
endif
static if ATTACH_BLUE
set memory = InitHashtable()
endif
endfunction
endlibrary