- Joined
- Aug 26, 2010
- Messages
- 573
Content:
Intro:
I am not sure if such script doesn't exist, but if it doesn't I think it worth submission because it saves u some time if u work with array-structs.
I writed it for my SoD map recently when I understood I have to add dozen array-structs. Also thanks to Nestharus for his [thread=187477]Coding efficient vJASS structs[/thread] guide and Bribe for his Table lib.
Macros:
JASS:
//! textmacro ArrayStructCreateBegin takes createParams
private static Table recicleNext
private static thistype recicle = 0
private static integer instanceCount = 0
static method create takes $createParams$ returns thistype
local thistype t
if recicle == 0 then
set instanceCount = instanceCount + 1
set t = instanceCount
else
set t = recicle
set recicle = recicleNext[recicle]
endif
//! endtextmacro
//! textmacro ArrayStructCreateEnd
return t
endmethod
//! endtextmacro
//! textmacro ArrayStructDestroyBegin
method destroy takes nothing returns nothing
debug local thistype t
debug if this != 0 then
debug set t = recicle
debug loop
debug exitwhen t == 0 or t == this
debug set t = recicleNext[t]
debug endloop
debug if t != this then
set recicleNext[this] = recicle
set recicle = this
//! endtextmacro
//! textmacro ArrayStructDestroyEnd
debug else
debug call BJDebugMsg("Double free of array struct")
debug endif
debug else
debug call BJDebugMsg("Trying to free null array struct")
debug endif
endmethod
//! endtextmacro
//! textmacro ArrayStructInitBegin
static method onInit takes nothing returns nothing
set recicleNext = Table.create()
//! endtextmacro
//! textmacro ArrayStructInitEnd
endmethod
//! endtextmacro
API description:
This macro requires Table!!! This macro is divided into 3 parts:
- ArrayStructInitCreate...
- ArrayStructInitDestroy...
- ArrayStructInitInit...
JASS:
struct MyArrayStruct extends array
<your code>
//! runtextmacro ArrayStructCreateBegin("<create method parameters>")
<initializing code in create method>
//! runtextmacro ArrayStructCreateEnd()
//! runtextmacro ArrayStructDestroyBegin()
<deinitializing code in destroy method>
//! runtextmacro ArrayStructDestroyEnd()
//! runtextmacro ArrayStructInitBegin()
<deinitializing code in onInit method>
//! runtextmacro ArrayStructInitEnd()
endstruct
Example of my struct with this macro:
JASS:
struct Item extends array
ItemType Type
item it
method operator[] takes item k returns thistype
return GetItemUserData(k)
endmethod
//! runtextmacro ArrayStructCreateBegin("ItemType Type, real x, real y")
set t.Type = Type
set t.it = CreateItem(Type.typeId, x, y)
call SetItemUserData(t.it, t)
//! runtextmacro ArrayStructBeginEnd()
//! runtextmacro ArrayStructDestroyBegin()
if it != null then
call RemoveItem(it)
set it = null
endif
//! runtextmacro ArrayStructDestroyEnd()
//! runtextmacro ArrayStructInitBegin()
//! runtextmacro ArrayStructInitEnd()
endstruct
Changelog:
- Added onInit part
- Changed interface a lot
Changed array -> Table
- Bug fix
- Removed onInit
- Changed lastInstance -> instanceCount
First version
Last edited: