The array package is marked as Compatible, which means any game can use it.
This package contains 30 classes, all of them variations on a theme. You can create a densely packed fixed-size array of either 1, 2, or 3 dimensions, containing Lua numbers, booleans, signed/unsigned 8-, 16-, or 32-bit integers, or 32- or 64-bit floating point values.
Class | Dim. | Range |
---|---|---|
PackedArray1D | 1D | any number |
PackedArray1D_B | 1D | true or false |
PackedArray1D_S8 | 1D | -128 <= integer <= 127 |
PackedArray1D_U8 | 1D | 0 <= integer <= 255 |
PackedArray1D_S16 | 1D | -32768 <= integer <= 32767 |
PackedArray1D_U16 | 1D | 0 <= integer <= 65535 |
PackedArray1D_S32 | 1D | -2147483648 <= integer <= 2147483647 |
PackedArray1D_U32 | 1D | 0 <= integer <= 4294967295 |
PackedArray1D_F32 | 1D | -126 <= exponent <= 127, 23+1 digits (binary) |
PackedArray1D_F64 | 1D | -1022 <= exponent <= 1023, 52+1 digits (binary) |
PackedArray2D | 2D | any number |
PackedArray2D_B | 2D | true or false |
PackedArray2D_S8 | 2D | -128 <= integer <= 127 |
PackedArray2D_U8 | 2D | 0 <= integer <= 255 |
PackedArray2D_S16 | 2D | -32768 <= integer <= 32767 |
PackedArray2D_U16 | 2D | 0 <= integer <= 65535 |
PackedArray2D_S32 | 2D | -2147483648 <= integer <= 2147483647 |
PackedArray2D_U32 | 2D | 0 <= integer <= 4294967295 |
PackedArray2D_F32 | 2D | -126 <= exponent <= 127, 23+1 digits (binary) |
PackedArray2D_F64 | 2D | -1022 <= exponent <= 1023, 52+1 digits (binary) |
PackedArray3D | 3D | any number |
PackedArray3D_B | 3D | true or false |
PackedArray3D_S8 | 3D | -128 <= integer <= 127 |
PackedArray3D_U8 | 3D | 0 <= integer <= 255 |
PackedArray3D_S16 | 3D | -32768 <= integer <= 32767 |
PackedArray3D_U16 | 3D | 0 <= integer <= 65535 |
PackedArray3D_S32 | 3D | -2147483648 <= integer <= 2147483647 |
PackedArray3D_U32 | 3D | 0 <= integer <= 4294967295 |
PackedArray3D_F32 | 3D | -126 <= exponent <= 127, 23+1 digits (binary) |
PackedArray3D_F64 | 3D | -1022 <= exponent <= 1023, 52+1 digits (binary) |
Each variant takes up the minimum necessary memory to store its contents, and accesses are performed in O(1) time.
All of the above classes implement the following:
Here are some examples:
-- Create a PackedArray containing a 32x32 quarter-circle. array = SubCritical.Construct("PackedArray2D_B", 32, 32) for x=0,31 do for y=0,31 do array:Set(math.sqrt(x*x+y*y) <= 31, x, y) end end
-- Create a PackedArray containing a multiplication table. -- array[x][y] contains (x+1)*(y+1). -- 12 * 12 = 144, which is less than 256, so our numbers will fit in a U8. array = SubCritical.Construct("PackedArray2D_U8", 12, 12) for x=1,12 do for y=1,12 do array:Set(x*y, x-1, y-1) end end