Class BitSet4D
java.lang.Object
net.storm.api.movement.pathfinder.BitSet4D
A four-dimensional bit set for storing collision flags.
BitSet4D provides efficient storage and retrieval of boolean flags in a 4-dimensional space. In the pathfinding context, the dimensions typically represent:
- X - X coordinate within a region (0-63)
- Y - Y coordinate within a region (0-63)
- Z - Plane/level (0-3)
- W - Flag type (0=North passable, 1=East passable)
Data Layout
The bits are stored in a linear BitSet with the index calculated as:
index = ((z * sizeY + y) * sizeX + x) * sizeW + w
Serialization
BitSet4D supports reading from and writing to ByteBuffer for efficient
storage and transmission of collision data.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionBitSet4D(int sizeX, int sizeY, int sizeZ, int sizeW) Constructs an empty BitSet4D with the specified dimensions.BitSet4D(ByteBuffer buffer, int sizeX, int sizeY, int sizeZ, int sizeW) Constructs a BitSet4D by reading data from a ByteBuffer. -
Method Summary
Modifier and TypeMethodDescriptionbooleanget(int index) Gets the bit value at the specified linear index.booleanget(int x, int y, int z, int w) Gets the bit value at the specified 4D coordinates.intgetIndex(int x, int y, int z, int w) Calculates the linear index for the specified 4D coordinates.voidset(int x, int y, int z, int flag, boolean value) Sets the bit value at the specified 4D coordinates.voidsetAll(boolean value) Sets all bits to the specified value.voidwrite(ByteBuffer buffer) Writes this BitSet4D to a ByteBuffer.
-
Constructor Details
-
BitSet4D
public BitSet4D(int sizeX, int sizeY, int sizeZ, int sizeW) Constructs an empty BitSet4D with the specified dimensions.- Parameters:
sizeX- size of the X dimensionsizeY- size of the Y dimensionsizeZ- size of the Z dimensionsizeW- size of the W dimension
-
BitSet4D
Constructs a BitSet4D by reading data from a ByteBuffer.- Parameters:
buffer- the buffer to read fromsizeX- size of the X dimensionsizeY- size of the Y dimensionsizeZ- size of the Z dimensionsizeW- size of the W dimension
-
-
Method Details
-
write
Writes this BitSet4D to a ByteBuffer.- Parameters:
buffer- the buffer to write to
-
get
public boolean get(int index) Gets the bit value at the specified linear index.- Parameters:
index- the linear index- Returns:
- the bit value
-
get
public boolean get(int x, int y, int z, int w) Gets the bit value at the specified 4D coordinates.- Parameters:
x- the X coordinatey- the Y coordinatez- the Z coordinate (plane)w- the W coordinate (flag)- Returns:
- the bit value
-
set
public void set(int x, int y, int z, int flag, boolean value) Sets the bit value at the specified 4D coordinates.- Parameters:
x- the X coordinatey- the Y coordinatez- the Z coordinate (plane)flag- the W coordinate (flag)value- the value to set
-
setAll
public void setAll(boolean value) Sets all bits to the specified value.- Parameters:
value- the value to set for all bits
-
getIndex
public int getIndex(int x, int y, int z, int w) Calculates the linear index for the specified 4D coordinates.- Parameters:
x- the X coordinatey- the Y coordinatez- the Z coordinate (plane)w- the W coordinate (flag)- Returns:
- the linear index
- Throws:
IndexOutOfBoundsException- if any coordinate is out of range
-