Package net.mtrop.doom.map.data
Class Blockmap
java.lang.Object
net.mtrop.doom.map.data.Blockmap
- All Implemented Interfaces:
BinaryObject
Representation of the Blockmap lump for a map.
This aids in collision detection for linedefs.
- Author:
- Matthew Tropiano
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.mtrop.doom.object.BinaryObject
BinaryObject.InlineScanner<BO extends BinaryObject>, BinaryObject.Reflect, BinaryObject.Scanner<BO extends BinaryObject>, BinaryObject.Shared, BinaryObject.Transformer<BO extends BinaryObject>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addIndex
(int x, int y, int linedefIndex) Adds a linedef index to this blockmap.int
getColumnByMapPosition
(int posX) Returns the column index used by a particular map position, according to this grid's startX value.getIndexList
(int x, int y) Returns an iterable structure for linedef indices for a certain block.getIndexListForPosition
(int posX, int posY) Returns an iterable structure for linedef indices for a certain block using a map position.int
getRowByMapPosition
(int posY) Returns the row index used by a particular map position, according to this grid's startY value.float
float
void
readBytes
(InputStream in) Reads from anInputStream
and sets this object's fields.boolean
removeIndex
(int x, int y, int linedefIndex) Removes a linedef index to this blockmap.void
writeBytes
(OutputStream out) Writes this object to anOutputStream
.
-
Constructor Details
-
Blockmap
public Blockmap()Creates a new Blockmap, startX and startY set to 0. -
Blockmap
public Blockmap(int startX, int startY) Creates a new Blockmap.- Parameters:
startX
- the grid lower-left start position (x-axis).startY
- the grid lower-left start position (y-axis).- Throws:
IllegalArgumentException
- ifstartX
orstartY
is outside the range of -32768 to 32767.
-
-
Method Details
-
addIndex
public void addIndex(int x, int y, int linedefIndex) Adds a linedef index to this blockmap.- Parameters:
x
- the grid row.y
- the grid column.linedefIndex
- the linedef index to add.- Throws:
IllegalArgumentException
- ifx
ory
is outside the range 0 to 512 orlinedefIndex
is outside the range 0 to 65535.
-
removeIndex
public boolean removeIndex(int x, int y, int linedefIndex) Removes a linedef index to this blockmap.- Parameters:
x
- the grid column.y
- the grid row.linedefIndex
- the linedef index to remove.- Returns:
- true if removed, false if not.
- Throws:
IllegalArgumentException
- ifx
ory
is outside the range 0 to 512 orlinedefIndex
is outside the range 0 to 65535.
-
getStartX
public float getStartX()- Returns:
- the map position start, X coordinate.
-
getStartY
public float getStartY()- Returns:
- the map position start, Y coordinate.
-
getColumnByMapPosition
public int getColumnByMapPosition(int posX) Returns the column index used by a particular map position, according to this grid's startX value. If posX is less than startX, this returns -1.- Parameters:
posX
- the map position x-coordinate.- Returns:
- the corresponding block column or if
posX
is less thangetStartX()
, this returns -1.
-
getRowByMapPosition
public int getRowByMapPosition(int posY) Returns the row index used by a particular map position, according to this grid's startY value.- Parameters:
posY
- the map position y-coordinate.- Returns:
- the corresponding block row or if
posY
is less thangetStartY()
, this returns -1.
-
getIndexList
Returns an iterable structure for linedef indices for a certain block.- Parameters:
x
- the grid column.y
- the grid row.- Returns:
- an iterable structure for a particular block.
-
getIndexListForPosition
Returns an iterable structure for linedef indices for a certain block using a map position.- Parameters:
posX
- the map position, X-coordinate.posY
- the map position, Y-coordinate.- Returns:
- an iterable structure for a particular block that corresponds to the map position.
-
readBytes
Description copied from interface:BinaryObject
Reads from anInputStream
and sets this object's fields. Only reads the amount of bytes that it takes to read a single instance of the object. Note that not every object may have a consistent length!- Specified by:
readBytes
in interfaceBinaryObject
- Parameters:
in
- theInputStream
to read from.- Throws:
IOException
- if a read error occurs.
-
writeBytes
Description copied from interface:BinaryObject
Writes this object to anOutputStream
.- Specified by:
writeBytes
in interfaceBinaryObject
- Parameters:
out
- theOutputStream
to write to.- Throws:
IOException
- if a write error occurs.
-