Class GlobalCollisionMap
- All Implemented Interfaces:
CollisionMap
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 -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty GlobalCollisionMap.GlobalCollisionMap(byte[] data) Constructs a GlobalCollisionMap from serialized binary data. -
Method Summary
Modifier and TypeMethodDescriptionbooleane(int x, int y, int z) Checks if movement East (x+1) is allowed from the specified position.booleanget(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.booleann(int x, int y, int z) Checks if movement North (y+1) is allowed from the specified position.voidset(int x, int y, int z, int w, boolean value) Sets a collision flag at the specified position.byte[]toBytes()Serializes the collision map to a byte array.
-
Field Details
-
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 coordinatey- the world y coordinatez- the plane/level (0-3)w- the flag index (0=North, 1=East)value- true if movement is allowed, false if blocked
-
getRegion
Gets the BitSet4D region containing the specified world coordinates.- Parameters:
x- the world x coordinatey- 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 coordinatey- the world y coordinatez- 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:
nin interfaceCollisionMap- Parameters:
x- the x coordinatey- the y coordinatez- 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:
ein interfaceCollisionMap- Parameters:
x- the x coordinatey- the y coordinatez- the plane/level- Returns:
- true if movement East is allowed
-