Class GlobalCollisionMap

java.lang.Object
net.storm.api.movement.pathfinder.GlobalCollisionMap
All Implemented Interfaces:
CollisionMap

public class GlobalCollisionMap extends Object implements CollisionMap
Pre-computed collision map containing walkability data for the entire game world.

GlobalCollisionMap stores collision data organized by region. Each region is a 64x64 tile area, and the entire map supports 256x256 regions (covering the full 16384x16384 tile game world). Collision data is stored efficiently using BitSet4D structures.

Data Structure

The collision data is stored as a 4-dimensional bit set per region:

  • Dimension 1 (X): 64 tiles in the X direction
  • Dimension 2 (Y): 64 tiles in the Y direction
  • Dimension 3 (Z): 4 planes/levels
  • Dimension 4 (W): 2 flags (North passable, East passable)

Usage

The global collision map is typically loaded from pre-computed data and used by the pathfinding algorithm to determine valid movement paths. It provides fast lookups but does not reflect real-time changes like opened doors or moved objects.


 GlobalCollisionMap collisionMap = Static.getGlobalCollisionMap();

 // Check if you can move north from a position
 boolean canMoveNorth = collisionMap.n(3200, 3200, 0);

 // Check if a tile is fully blocked
 boolean blocked = collisionMap.fullBlock(3200, 3200, 0);
 
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final BitSet4D[]
    Array of collision data organized by region.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty GlobalCollisionMap.
    GlobalCollisionMap(byte[] data)
    Constructs a GlobalCollisionMap from serialized binary data.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    e(int x, int y, int z)
    Checks if movement East (x+1) is allowed from the specified position.
    boolean
    get(int x, int y, int z, int w)
    Gets a collision flag at the specified position.
    getRegion(int x, int y)
    Gets the BitSet4D region containing the specified world coordinates.
    boolean
    n(int x, int y, int z)
    Checks if movement North (y+1) is allowed from the specified position.
    void
    set(int x, int y, int z, int w, boolean value)
    Sets a collision flag at the specified position.
    byte[]
    Serializes the collision map to a byte array.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface net.storm.api.movement.pathfinder.CollisionMap

    e, fullBlock, fullBlock, n, ne, ne, nw, nw, s, s, se, se, sw, sw, w, w
  • Field Details

    • regions

      public final BitSet4D[] regions
      Array of collision data organized by region. Index is calculated as: regionX * 256 + regionY where regionX = worldX / 64 and regionY = worldY / 64.
  • Constructor Details

    • GlobalCollisionMap

      public GlobalCollisionMap()
      Constructs an empty GlobalCollisionMap. Regions must be populated separately after construction.
    • GlobalCollisionMap

      public GlobalCollisionMap(byte[] data)
      Constructs a GlobalCollisionMap from serialized binary data.

      The data format consists of sequential region entries, each containing:

      • 2 bytes: Region ID (unsigned short)
      • Variable bytes: BitSet4D data for that region
      Parameters:
      data - the serialized collision data
  • Method Details

    • toBytes

      public byte[] toBytes()
      Serializes the collision map to a byte array.

      The output format matches the constructor input format, allowing round-trip serialization and deserialization.

      Returns:
      the serialized collision data as a byte array
    • set

      public void set(int x, int y, int z, int w, boolean value)
      Sets a collision flag at the specified position.
      Parameters:
      x - the world x coordinate
      y - the world y coordinate
      z - the plane/level (0-3)
      w - the flag index (0=North, 1=East)
      value - true if movement is allowed, false if blocked
    • getRegion

      public BitSet4D getRegion(int x, int y)
      Gets the BitSet4D region containing the specified world coordinates.
      Parameters:
      x - the world x coordinate
      y - the world y coordinate
      Returns:
      the BitSet4D for that region, or null if not loaded
    • get

      public boolean get(int x, int y, int z, int w)
      Gets a collision flag at the specified position.
      Parameters:
      x - the world x coordinate
      y - the world y coordinate
      z - the plane/level (0-3)
      w - the flag index (0=North, 1=East)
      Returns:
      true if movement is allowed, false if blocked or region not loaded
    • n

      public boolean n(int x, int y, int z)
      Checks if movement North (y+1) is allowed from the specified position.

      Checks the North flag (w=0) at the specified position.

      Specified by:
      n in interface CollisionMap
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the plane/level
      Returns:
      true if movement North is allowed
    • e

      public boolean e(int x, int y, int z)
      Checks if movement East (x+1) is allowed from the specified position.

      Checks the East flag (w=1) at the specified position.

      Specified by:
      e in interface CollisionMap
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the plane/level
      Returns:
      true if movement East is allowed