Class BitSet4D

java.lang.Object
net.storm.api.movement.pathfinder.BitSet4D

public class BitSet4D extends Object
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

    Constructors
    Constructor
    Description
    BitSet4D(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 Type
    Method
    Description
    boolean
    get(int index)
    Gets the bit value at the specified linear index.
    boolean
    get(int x, int y, int z, int w)
    Gets the bit value at the specified 4D coordinates.
    int
    getIndex(int x, int y, int z, int w)
    Calculates the linear index for the specified 4D coordinates.
    void
    set(int x, int y, int z, int flag, boolean value)
    Sets the bit value at the specified 4D coordinates.
    void
    setAll(boolean value)
    Sets all bits to the specified value.
    void
    write(ByteBuffer buffer)
    Writes this BitSet4D to a ByteBuffer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 dimension
      sizeY - size of the Y dimension
      sizeZ - size of the Z dimension
      sizeW - size of the W dimension
    • BitSet4D

      public BitSet4D(ByteBuffer buffer, int sizeX, int sizeY, int sizeZ, int sizeW)
      Constructs a BitSet4D by reading data from a ByteBuffer.
      Parameters:
      buffer - the buffer to read from
      sizeX - size of the X dimension
      sizeY - size of the Y dimension
      sizeZ - size of the Z dimension
      sizeW - size of the W dimension
  • Method Details

    • write

      public void write(ByteBuffer buffer)
      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 coordinate
      y - the Y coordinate
      z - 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 coordinate
      y - the Y coordinate
      z - 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 coordinate
      y - the Y coordinate
      z - the Z coordinate (plane)
      w - the W coordinate (flag)
      Returns:
      the linear index
      Throws:
      IndexOutOfBoundsException - if any coordinate is out of range