- Joined
- Nov 23, 2008
- Messages
- 512
a simple library that converts 2d or 3d arrays to a 1d array.
please note that the max size is 8192^1/(dimensions)
that means you can have max a [90,90] or a [20,20,20] array
usefull for grid so you don't have to loop quadratic trough all things (good tutourial here: n-game technique)
please note that the max size is 8192^1/(dimensions)
that means you can have max a [90,90] or a [20,20,20] array
usefull for grid so you don't have to loop quadratic trough all things (good tutourial here: n-game technique)
JASS:
library MultiArray
globals
constant integer TWODIMENSIONMAX = 90 // 8192^(1/2)
constant integer THREEDIMENSIONMAX = 20 // 8192^(1/3)
endglobals
function GetTwoDimensionArray takes integer x, integer y returns integer
if x >= TWODIMENSIONMAX or y >= TWODIMENSIONMAX then
debug call BJDebugMsg("Multi Array Error: Can not handle this size!")
return 0
elseif x < 0 or y <0 then
debug call BJDebugMsg("Multi Array Error: One or more indexes are too small!")
return 0
endif
return x+y*TWODIMENSIONMAX
endfunction
function GetThreeDimensionArray takes integer x, integer y, integer z returns integer
if x >= THREEDIMENSIONMAX or y >= THREEDIMENSIONMAX or z >= THREEDIMENSIONMAX then
debug call BJDebugMsg("Multi Array Error: Can not handle this size!")
return 0
elseif x < 0 or y <0 or z <0 then
debug call BJDebugMsg("Multi Array Error: One or more indexes are too small!")
return 0
endif
return (x+y*THREEDIMENSIONMAX)+z*(THREEDIMENSIONMAX*THREEDIMENSIONMAX)
endfunction
endlibrary