Class Blockmap

java.lang.Object
net.mtrop.doom.map.data.Blockmap
All Implemented Interfaces:
BinaryObject

public class Blockmap extends Object implements BinaryObject
Representation of the Blockmap lump for a map. This aids in collision detection for linedefs.
Author:
Matthew Tropiano
  • 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 - if startX or startY 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 - if x or y is outside the range 0 to 512 or linedefIndex 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 - if x or y is outside the range 0 to 512 or linedefIndex 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 than getStartX(), 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 than getStartY(), this returns -1.
    • getIndexList

      public Iterable<Integer> getIndexList(int x, int y)
      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

      public Iterable<Integer> getIndexListForPosition(int posX, int posY)
      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

      public void readBytes(InputStream in) throws IOException
      Description copied from interface: BinaryObject
      Reads from an InputStream 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 interface BinaryObject
      Parameters:
      in - the InputStream to read from.
      Throws:
      IOException - if a read error occurs.
    • writeBytes

      public void writeBytes(OutputStream out) throws IOException
      Description copied from interface: BinaryObject
      Writes this object to an OutputStream.
      Specified by:
      writeBytes in interface BinaryObject
      Parameters:
      out - the OutputStream to write to.
      Throws:
      IOException - if a write error occurs.