// ===================================== //
// Start Allocator Core //
// ===================================== //
// ===================================== //
// Start Allocator Main //
// ===================================== //
function AllocMain_deallocate takes integer mainKey returns nothing
// Since it's possible for a wrong type of debug message to be printed.
if mainKey <= 0 then
if udg_Allocator_DEBUG_MODE then
if mainKey == 0 then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Main__deallocate:|r Null-pointer exception! [Key specified is 0].")
else
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Main__deallocate:|r Invalid-pointer exception! [Key {" + I2S(mainKey) + "} specified is less than 0].")
endif
endif
return
elseif HaveSavedInteger(udg_Allocator_HASH, 0, mainKey) then
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Main__deallocate:|r Double-free procedure detected! {Index " + I2S(mainKey) + "}")
endif
return
endif
// Clear out the contents of the mainKey first
call FlushChildHashtable(udg_Allocator_HASH, mainKey)
// Standard deallocation procedure. (Store reference as pointed by 0 in deallocated index and let 0 point to the index.
// From 0 -> 3 to (0 -> 2 -> 3), to (0 -> 3 -> 2 -> 3) [3 is deindex, and has been recently deallocated]
call SaveInteger(udg_Allocator_HASH, 0, mainKey, LoadInteger(udg_Allocator_HASH, 0, 0))
call SaveInteger(udg_Allocator_HASH, 0, 0, mainKey)
endfunction
function AllocMain_allocate takes nothing returns integer
local integer constantValue = 2147483647
set udg_Allocator_NewKey = LoadInteger(udg_Allocator_HASH, 0, 0)
if LoadInteger(udg_Allocator_HASH, 0, udg_Allocator_NewKey) == 0 then
set udg_Allocator_NewKey = udg_Allocator_NewKey + 1
call SaveInteger(udg_Allocator_HASH, 0, 0, udg_Allocator_NewKey)
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cff00ff00Allocator_Main__allocate:|r Retrieved a new key {" + I2S(udg_Allocator_NewKey) + "}")
endif
else
call SaveInteger(udg_Allocator_HASH, 0, 0, LoadInteger(udg_Allocator_HASH, 0, udg_Allocator_NewKey))
call RemoveSavedInteger(udg_Allocator_HASH, 0, udg_Allocator_NewKey)
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffffcc00Allocator_Main__allocate:|r Retrieved a recycled key {" + I2S(udg_Allocator_NewKey) + "}")
endif
endif
call SaveInteger(udg_Allocator_HASH, udg_Allocator_NewKey, -2, udg_Allocator_MaxInstances)
set udg_Allocator_MaxInstances = 2147483647
return udg_Allocator_NewKey
endfunction
// ===================================== //
// End Allocator Main //
// ===================================== //
// ===================================== //
// Start Allocator Engine //
// ===================================== //
// Added via _Guhun_'s request.
function GetKeySize takes integer mainKey returns integer
if udg_Allocator_DEBUG_MODE then
if not HaveSavedInteger(udg_Allocator_HASH, mainKey, -1) then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {GetKeySize} Invalid-pointer exception!")
return 0
elseif mainKey == 0 then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {GetKeySize} null-pointer exception!")
return 0
endif
endif
return LoadInteger(udg_Allocator_HASH, mainKey, -1)
endfunction
function SizeOfKey takes integer mainKey returns integer
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {SizeOfKey} This function is deprecated. Use SizeOfKey instead.")
endif
return GetKeySize(mainKey)
endfunction
function GetKeyBounds takes integer mainKey returns integer
if not HaveSavedInteger(udg_Allocator_HASH, mainKey, -2) then
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {GetKeyBounds} Invalid-pointer exception!")
endif
return 0
elseif mainKey == 0 then
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {GetKeyBounds} null-pointer exception!")
endif
return 0
endif
return LoadInteger(udg_Allocator_HASH, mainKey, -2)
endfunction
function SetKeyBounds takes integer mainKey, integer newSize returns nothing
if not HaveSavedInteger(udg_Allocator_HASH, mainKey, -2) then
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {SetKeyBounds} Invalid-pointer exception!")
endif
return
elseif mainKey == 0 then
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {SetKeyBounds} null-pointer exception!")
endif
return
elseif newSize < LoadInteger(udg_Allocator_HASH, mainKey, -2) then
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {SetKeyBounds} Reducing instance size might have some unintended consequences.")
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {SetKeyBounds} Are you sure?")
endif
endif
call SaveInteger(udg_Allocator_HASH, mainKey, -2, newSize)
endfunction
function IsInstanceAllocated takes integer mainKey, integer index returns boolean
set udg_Allocator_isAllocated = (HaveSavedInteger(udg_Allocator_HASH, mainKey, index) and LoadInteger(udg_Allocator_HASH, mainKey, index) == 0)
return udg_Allocator_isAllocated
endfunction
// Deallocates an instance.
function AllocEngine_deallocate takes integer mainKey, integer deindex returns nothing
// Check if instance is within bounds.
if deindex <= 0 then
if udg_Allocator_DEBUG_MODE then
if deindex == 0 then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine__deallocate:|r Null-pointer exception! [Index specified is 0].")
else
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine__deallocate:|r Invalid-pointer exception! [Index {" + I2S(deindex) + "} specified is less than 0].")
endif
endif
return
elseif not IsInstanceAllocated(mainKey, deindex) then
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine__deallocate:|r Double-free procedure detected! {Index " + I2S(deindex) + "}")
endif
return
elseif mainKey <= 0 then
if udg_Allocator_DEBUG_MODE then
if mainKey == 0 then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine__deallocate:|r Null-pointer exception! [Key specified is 0].")
else
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine__deallocate:|r Invalid-pointer exception! [Key {" + I2S(mainKey) + "} specified is less than 0].")
endif
endif
return
endif
call SaveInteger(udg_Allocator_HASH, mainKey, deindex, LoadInteger(udg_Allocator_HASH, mainKey, 0))
call SaveInteger(udg_Allocator_HASH, mainKey, 0, deindex)
// Updates the internal number of the list in specified key.
call SaveInteger(udg_Allocator_HASH, mainKey, -1, LoadInteger(udg_Allocator_HASH, mainKey, -1) - 1)
endfunction
function AllocEngine_allocate takes integer mainKey returns integer
if mainKey <= 0 then
if udg_Allocator_DEBUG_MODE then
if mainKey == 0 then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine__allocate:|r Null-pointer exception! [Key specified is 0].")
else
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine__allocate:|r Invalid-pointer exception! [Key {" + I2S(mainKey) + "} specified is invalid].")
endif
endif
set udg_Allocator_NewIndex = -1
else
set udg_Allocator_NewIndex = LoadInteger(udg_Allocator_HASH, mainKey, 0)
if LoadInteger(udg_Allocator_HASH, mainKey, udg_Allocator_NewIndex) == 0 then
if udg_Allocator_NewIndex >= LoadInteger(udg_Allocator_HASH, mainKey, -2) then
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cff00ff00Allocator_Engine__allocate:|r Exceeded maximum instance count {" + I2S(udg_Allocator_NewIndex) + "}")
endif
set udg_Allocator_NewIndex = 0
return udg_Allocator_NewIndex
endif
set udg_Allocator_NewIndex = udg_Allocator_NewIndex + 1
call SaveInteger(udg_Allocator_HASH, mainKey, 0, udg_Allocator_NewIndex)
call SaveInteger(udg_Allocator_HASH, mainKey, udg_Allocator_NewIndex, 0)
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cff00ff00Allocator_Engine__allocate:|r Retrieved a new Index {" + I2S(udg_Allocator_NewIndex) + "}")
endif
else
call SaveInteger(udg_Allocator_HASH, mainKey, 0, LoadInteger(udg_Allocator_HASH, mainKey, udg_Allocator_NewIndex))
call SaveInteger(udg_Allocator_HASH, mainKey, udg_Allocator_NewIndex, 0)
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffffcc00Allocator_Engine__allocate:|r Retrieved a recycled Index {" + I2S(udg_Allocator_NewIndex) + "}")
endif
endif
call SaveInteger(udg_Allocator_HASH, mainKey, -1, LoadInteger(udg_Allocator_HASH, mainKey, -1) + 1)
endif
return udg_Allocator_NewIndex
endfunction
// ===================================== //
// End Allocator Engine //
// ===================================== //
// ===================================== //
// End Allocator Core //
// ===================================== //
Name | Type | is_array | initial_value |
Allocator_DEBUG_MODE | boolean | No | |
Allocator_deIndex | integer | No | |
Allocator_deKey | integer | No | |
Allocator_HASH | hashtable | No | |
Allocator_Instruction | integer | No | |
Allocator_Instruction_ALLOC | integer | No | 1 |
Allocator_Instruction_DEALLOC | integer | No | 0 |
Allocator_Instruction_IS_ALLOC | integer | No | 2 |
Allocator_Instruction_RESIZE | integer | No | 3 |
Allocator_isAllocated | boolean | No | |
Allocator_MainIndex | integer | No | |
Allocator_MainKey | integer | No | |
Allocator_MaxInstances | integer | No | 32768 |
Allocator_NewIndex | integer | No | |
Allocator_NewKey | integer | No | |
Periodic_Stun__Current | integer | No | |
Periodic_Stun__Dummy | unit | Yes | |
Periodic_Stun__Duration | real | Yes | |
Periodic_Stun__Key | integer | No | |
Periodic_Stun__Target | unit | Yes | |
Periodic_Stun__Timer | timer | Yes | |
spell_HASH | hashtable | No | |
temp_pos | location | No | |
trig_unit | unit | No |
Documentation of the resource:
//----------------------------------------//
//Do not enable this trigger at all costs!//
//----------------------------------------//
Welcome to GUI Allocator Engine!
GUI Allocator Engine serves to aid the user when making virtually any resource that requires individual
instances, such as spell-making (common-use), system-making (other common use), and many other things
that require class-like behavior.
In order to do this, GUI Allocator Engine does the allocation for the user, so the user will not be
burdened with having to bother creating variables specifically for that purpose, saving at least 1
variable per class-like instance made.
In addition, GUI Allocator Engine keeps track of how many instances have been allocated at a specific key.
These may be helpful for those who need them, and do not want to iterate over the list of available
instances.
However, there is a condition, the value must be read only. This means that you cannot modify it whatsoever.
Only the system has the rights to do so.
Convenience:
To know how many instances are allocated, just read the hashtable at the following indices (if using the
natives); (mainKey, -1). For those in GUI, that would be (-1, mainKey), an inversion of the former.
A function specifically for that purpose is provided for you below.
Amendment:
A later discovery with the usage of the system proved that this can act more than just an allocator.
It can virtually act as a pseudo-variable creator. This means that you can allocate new keys specifically
just for storing additional data.
Functions:
There are eight functions made available for those JASS users. These are:
AllocMain_allocate() -> no parameters -> returns integer
- Allocates a key, a reserved space for further allocation processes involving the key.
AllocMain_deallocate(udg_Allocator_deKey) -> integer mainKey
- Deallocates a key, and flushes its'' content.
AllocEngine_allocate(udg_Allocator_MainKey) -> integer mainKey -> returns integer
- Allocates an instance in the reserved space from the key.
AllocEngine_deallocate(udg_Allocator_MainKey, udg_Allocator_deIndex) -> integer mainKey, deindex
- Deallocates an instance in the reserved space.
IsInstanceAllocated(udg_Allocator_MainKey, udg_Allocator_MainIndex) -> integer mainKey, index -> returns boolean
- Returns true if the instance has already been allocated. Otherwise, it returns false.
SizeOfKey(udg_Allocator_MainKey) -> integer mainKey -> returns integer
- Returns a valid size of the key if key itself is valid.
- For example, if you start with no instances, and you allocate 5, this will return 5.
GetKeyBounds(udg_Allocator_MainKey) -> integer mainKey -> returns integer
- Returns the maximum amount of instances for a certain key.
SetKeyBounds(udg_Allocator_MainKey, udg_Allocator_MaxInstances) -> integer mainKey, integer newMax
- Changes the maximum amount of instances of a certain key. Preferably not used to reduce
number of instances (automatic flushing of instances not yet supported).
Two triggers are available for GUI users. These are
<gen> Allocator Main
<gen> Allocator Engine
Allocator Main is used when getting new keys. It is recommended to do this only once on map initialization
for spells, systems or whatever you need.
Allocator Engine is used for getting new instances from the given key. This is the proper allocator,
so to speak.
Instructions must be assigned before proceeding with the evaluation or execution of the triggers above.
See Allocator Variables for more details on that.
If you want to know if your instances are being allocated properly, you can manipulate the DEBUG_MODE variable
offered by this system. Note that some errors may be ambiguous to you.
Safety is heavily enforced in this system. As such, it is naturally safe from double-free errors.
If DEBUG_MODE is enabled, you can even catch when an instance is double-freed or when an exception occurs.
Example Usage:
See GUI Example.
How to Import:
1. Make sure to enable the creation of unknown variables in Preferences, under the File tab.
2. Copy the following triggers:
Mandatory: (These are required for the system to work)
- Allocator Main
- Allocator Engine
Optional: (Used either for variable declaration or other things) (You may delete them afterwards).
- Allocator Variables
- Allocator Header (Place it on the map header.)
// ===================================== //
// Start Allocator Core //
// ===================================== //
// ===================================== //
// Start Allocator Main //
// ===================================== //
function AllocMain_deallocate takes integer mainKey returns nothing
// Since it's possible for a wrong type of debug message to be printed.
if mainKey <= 0 then
if udg_Allocator_DEBUG_MODE then
if mainKey == 0 then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Main__deallocate:|r Null-pointer exception! [Key specified is 0].")
else
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Main__deallocate:|r Invalid-pointer exception! [Key {" + I2S(mainKey) + "} specified is less than 0].")
endif
endif
return
elseif HaveSavedInteger(udg_Allocator_HASH, 0, mainKey) then
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Main__deallocate:|r Double-free procedure detected! {Index " + I2S(mainKey) + "}")
endif
return
endif
// Clear out the contents of the mainKey first
call FlushChildHashtable(udg_Allocator_HASH, mainKey)
// Standard deallocation procedure. (Store reference as pointed by 0 in deallocated index and let 0 point to the index.
// From 0 -> 3 to (0 -> 2 -> 3), to (0 -> 3 -> 2 -> 3) [3 is deindex, and has been recently deallocated]
call SaveInteger(udg_Allocator_HASH, 0, mainKey, LoadInteger(udg_Allocator_HASH, 0, 0))
call SaveInteger(udg_Allocator_HASH, 0, 0, mainKey)
endfunction
function AllocMain_allocate takes nothing returns integer
local integer constantValue = 2147483647
set udg_Allocator_NewKey = LoadInteger(udg_Allocator_HASH, 0, 0)
if LoadInteger(udg_Allocator_HASH, 0, udg_Allocator_NewKey) == 0 then
set udg_Allocator_NewKey = udg_Allocator_NewKey + 1
call SaveInteger(udg_Allocator_HASH, 0, 0, udg_Allocator_NewKey)
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cff00ff00Allocator_Main__allocate:|r Retrieved a new key {" + I2S(udg_Allocator_NewKey) + "}")
endif
else
call SaveInteger(udg_Allocator_HASH, 0, 0, LoadInteger(udg_Allocator_HASH, 0, udg_Allocator_NewKey))
call RemoveSavedInteger(udg_Allocator_HASH, 0, udg_Allocator_NewKey)
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffffcc00Allocator_Main__allocate:|r Retrieved a recycled key {" + I2S(udg_Allocator_NewKey) + "}")
endif
endif
call SaveInteger(udg_Allocator_HASH, udg_Allocator_NewKey, -2, udg_Allocator_MaxInstances)
set udg_Allocator_MaxInstances = 2147483647
return udg_Allocator_NewKey
endfunction
// ===================================== //
// End Allocator Main //
// ===================================== //
// ===================================== //
// Start Allocator Engine //
// ===================================== //
// Added via _Guhun_'s request.
function GetKeySize takes integer mainKey returns integer
if udg_Allocator_DEBUG_MODE then
if not HaveSavedInteger(udg_Allocator_HASH, mainKey, -1) then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {GetKeySize} Invalid-pointer exception!")
return 0
elseif mainKey == 0 then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {GetKeySize} null-pointer exception!")
return 0
endif
endif
return LoadInteger(udg_Allocator_HASH, mainKey, -1)
endfunction
function SizeOfKey takes integer mainKey returns integer
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {SizeOfKey} This function is deprecated. Use SizeOfKey instead.")
endif
return GetKeySize(mainKey)
endfunction
function GetKeyBounds takes integer mainKey returns integer
if not HaveSavedInteger(udg_Allocator_HASH, mainKey, -2) then
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {GetKeyBounds} Invalid-pointer exception!")
endif
return 0
elseif mainKey == 0 then
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {GetKeyBounds} null-pointer exception!")
endif
return 0
endif
return LoadInteger(udg_Allocator_HASH, mainKey, -2)
endfunction
function SetKeyBounds takes integer mainKey, integer newSize returns nothing
if not HaveSavedInteger(udg_Allocator_HASH, mainKey, -2) then
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {SetKeyBounds} Invalid-pointer exception!")
endif
return
elseif mainKey == 0 then
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {SetKeyBounds} null-pointer exception!")
endif
return
elseif newSize < LoadInteger(udg_Allocator_HASH, mainKey, -2) then
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {SetKeyBounds} Reducing instance size might have some unintended consequences.")
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine: {SetKeyBounds} Are you sure?")
endif
endif
call SaveInteger(udg_Allocator_HASH, mainKey, -2, newSize)
endfunction
function IsInstanceAllocated takes integer mainKey, integer index returns boolean
set udg_Allocator_isAllocated = (HaveSavedInteger(udg_Allocator_HASH, mainKey, index) and LoadInteger(udg_Allocator_HASH, mainKey, index) == 0)
return udg_Allocator_isAllocated
endfunction
// Deallocates an instance.
function AllocEngine_deallocate takes integer mainKey, integer deindex returns nothing
// Check if instance is within bounds.
if deindex <= 0 then
if udg_Allocator_DEBUG_MODE then
if deindex == 0 then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine__deallocate:|r Null-pointer exception! [Index specified is 0].")
else
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine__deallocate:|r Invalid-pointer exception! [Index {" + I2S(deindex) + "} specified is less than 0].")
endif
endif
return
elseif not IsInstanceAllocated(mainKey, deindex) then
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine__deallocate:|r Double-free procedure detected! {Index " + I2S(deindex) + "}")
endif
return
elseif mainKey <= 0 then
if udg_Allocator_DEBUG_MODE then
if mainKey == 0 then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine__deallocate:|r Null-pointer exception! [Key specified is 0].")
else
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine__deallocate:|r Invalid-pointer exception! [Key {" + I2S(mainKey) + "} specified is less than 0].")
endif
endif
return
endif
call SaveInteger(udg_Allocator_HASH, mainKey, deindex, LoadInteger(udg_Allocator_HASH, mainKey, 0))
call SaveInteger(udg_Allocator_HASH, mainKey, 0, deindex)
// Updates the internal number of the list in specified key.
call SaveInteger(udg_Allocator_HASH, mainKey, -1, LoadInteger(udg_Allocator_HASH, mainKey, -1) - 1)
endfunction
function AllocEngine_allocate takes integer mainKey returns integer
if mainKey <= 0 then
if udg_Allocator_DEBUG_MODE then
if mainKey == 0 then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine__allocate:|r Null-pointer exception! [Key specified is 0].")
else
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffff0000Allocator_Engine__allocate:|r Invalid-pointer exception! [Key {" + I2S(mainKey) + "} specified is invalid].")
endif
endif
set udg_Allocator_NewIndex = -1
else
set udg_Allocator_NewIndex = LoadInteger(udg_Allocator_HASH, mainKey, 0)
if LoadInteger(udg_Allocator_HASH, mainKey, udg_Allocator_NewIndex) == 0 then
if udg_Allocator_NewIndex >= LoadInteger(udg_Allocator_HASH, mainKey, -2) then
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cff00ff00Allocator_Engine__allocate:|r Exceeded maximum instance count {" + I2S(udg_Allocator_NewIndex) + "}")
endif
set udg_Allocator_NewIndex = 0
return udg_Allocator_NewIndex
endif
set udg_Allocator_NewIndex = udg_Allocator_NewIndex + 1
call SaveInteger(udg_Allocator_HASH, mainKey, 0, udg_Allocator_NewIndex)
call SaveInteger(udg_Allocator_HASH, mainKey, udg_Allocator_NewIndex, 0)
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cff00ff00Allocator_Engine__allocate:|r Retrieved a new Index {" + I2S(udg_Allocator_NewIndex) + "}")
endif
else
call SaveInteger(udg_Allocator_HASH, mainKey, 0, LoadInteger(udg_Allocator_HASH, mainKey, udg_Allocator_NewIndex))
call SaveInteger(udg_Allocator_HASH, mainKey, udg_Allocator_NewIndex, 0)
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffffcc00Allocator_Engine__allocate:|r Retrieved a recycled Index {" + I2S(udg_Allocator_NewIndex) + "}")
endif
endif
call SaveInteger(udg_Allocator_HASH, mainKey, -1, LoadInteger(udg_Allocator_HASH, mainKey, -1) + 1)
endif
return udg_Allocator_NewIndex
endfunction
// ===================================== //
// End Allocator Engine //
// ===================================== //
// ===================================== //
// End Allocator Core //
// ===================================== //
// ========================= //
// Backwards Compatibility //
// ========================= //
function Allocator_Main__allocate takes nothing returns integer
return AllocMain_allocate()
endfunction
function Allocator_Main__deallocate takes integer deKey returns nothing
call AllocMain_deallocate(deKey)
endfunction
// This function gets a new index for you
function Trig_Allocator_Main_Actions takes nothing returns nothing
if udg_Allocator_Instruction == udg_Allocator_Instruction_ALLOC then
call AllocMain_allocate()
elseif udg_Allocator_Instruction == udg_Allocator_Instruction_ALLOC then
call AllocMain_deallocate(udg_Allocator_deKey)
else
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffffcc00Allocator_Main_Actions:|r Unrecognized instruction!")
endif
endif
endfunction
//===========================================================================
function InitTrig_Allocator_Main takes nothing returns nothing
set udg_Allocator_HASH = InitHashtable()
set udg_Allocator_MaxInstances = 2147483647
set udg_Allocator_Instruction_RESIZE = 3
set udg_Allocator_Instruction_IS_ALLOC = 2
set udg_Allocator_Instruction_ALLOC = 1
set udg_Allocator_Instruction_DEALLOC = 0
set gg_trg_Allocator_Main = CreateTrigger( )
call TriggerAddAction( gg_trg_Allocator_Main, function Trig_Allocator_Main_Actions )
endfunction
// ========================= //
// Backwards Compatibility //
// ========================= //
function Allocator_Engine__allocate takes integer mainKey returns integer
return AllocEngine_allocate(mainKey)
endfunction
function Allocator_Engine__deallocate takes integer mainKey, integer deindex returns nothing
call AllocEngine_deallocate(mainKey, deindex)
endfunction
function Allocator_Engine__IsInstanceAllocated takes integer mainKey, integer index returns boolean
return IsInstanceAllocated(mainKey, index)
endfunction
function Trig_Allocator_Engine_Actions takes nothing returns nothing
if udg_Allocator_Instruction == udg_Allocator_Instruction_RESIZE then
call SetKeyBounds(udg_Allocator_MainKey, udg_Allocator_MaxInstances)
set udg_Allocator_MaxInstances = 2147483647
elseif udg_Allocator_Instruction == udg_Allocator_Instruction_IS_ALLOC then
call IsInstanceAllocated(udg_Allocator_MainKey, udg_Allocator_MainIndex)
elseif udg_Allocator_Instruction == udg_Allocator_Instruction_ALLOC then
call AllocEngine_allocate(udg_Allocator_MainKey)
elseif udg_Allocator_Instruction == udg_Allocator_Instruction_DEALLOC then
call AllocEngine_deallocate(udg_Allocator_MainKey, udg_Allocator_deIndex)
else
if udg_Allocator_DEBUG_MODE then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 50000, "-> |cffffcc00Allocator_Engine_Actions:|r Unrecognized instruction!")
endif
endif
endfunction
//===========================================================================
function InitTrig_Allocator_Engine takes nothing returns nothing
set gg_trg_Allocator_Engine = CreateTrigger( )
call TriggerAddAction( gg_trg_Allocator_Engine, function Trig_Allocator_Engine_Actions )
endfunction
// This was converted from GUI to JASS by accident.
function Trig_Periodic_Stun_Loop_Func004C takes nothing returns boolean
return udg_Periodic_Stun__Duration[udg_Periodic_Stun__Current] <= 0.00 or GetWidgetLife(udg_Periodic_Stun__Target[udg_Periodic_Stun__Current]) <= 0.405
endfunction
function Trig_Periodic_Stun_Loop_Actions takes nothing returns nothing
set udg_Periodic_Stun__Current = LoadInteger(udg_spell_HASH, 0, GetHandleId(GetExpiredTimer()))
call IssueTargetOrder( udg_Periodic_Stun__Dummy[udg_Periodic_Stun__Current], "thunderbolt", udg_Periodic_Stun__Target[udg_Periodic_Stun__Current] )
set udg_Periodic_Stun__Duration[udg_Periodic_Stun__Current] = ( udg_Periodic_Stun__Duration[udg_Periodic_Stun__Current] - TimerGetTimeout(GetExpiredTimer()) )
if ( Trig_Periodic_Stun_Loop_Func004C() ) then
// Time for deallocation
call RemoveSavedInteger(udg_spell_HASH, 0, GetHandleId(GetExpiredTimer()))
call RemoveUnit(udg_Periodic_Stun__Dummy[udg_Periodic_Stun__Current])
set udg_Periodic_Stun__Dummy[udg_Periodic_Stun__Current] = null
set udg_Periodic_Stun__Target[udg_Periodic_Stun__Current] = null
set udg_Periodic_Stun__Duration[udg_Periodic_Stun__Current] = 0.00
call PauseTimer( udg_Periodic_Stun__Timer[udg_Periodic_Stun__Current] )
// We proceed with deallocating the current instance.
set udg_Allocator_deIndex = udg_Periodic_Stun__Current
set udg_Allocator_MainKey = udg_Periodic_Stun__Key
set udg_Allocator_Instruction = 0
call ConditionalTriggerExecute( gg_trg_Allocator_Engine )
endif
endfunction
//===========================================================================
function InitTrig_Periodic_Stun_Loop takes nothing returns nothing
set gg_trg_Periodic_Stun_Loop = CreateTrigger( )
call TriggerAddAction( gg_trg_Periodic_Stun_Loop, function Trig_Periodic_Stun_Loop_Actions )
endfunction