Class Flat
java.lang.Object
net.mtrop.doom.graphics.Flat
- All Implemented Interfaces:
BinaryObject,GraphicObject
Doom graphic data that has no header data for its dimensions/offsets.
Normally, flats are the floor/ceiling textures in the Doom engine that are a set size (64x64) and thus have no need for header information, but fullscreen pictures like Doom's TITLEPIC are also a straight mapping of pixels with assumed dimensions (in this case, 320x200). This class can read both, and its dimensions can be arbitrarily set by the programmer regardless of the amount of data inside.
NOTE: The readBytes(InputStream) method will only read as many bytes as possible to fill the
current dimensions of the flat, as this information is not found in the byte data.
- 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the pixel data to zeroes.static Flatcreate(int width, int height, byte[] bytes) Reads and creates a new Flat object from an array of bytes.intintintintgetPixel(int x, int y) Gets the pixel data at a location in the flat.intgetWidth()static Flatread(int width, int height, InputStream in) Reads and creates a new Flat from anInputStreamimplementation.voidreadBytes(InputStream in) Reads from anInputStreamand sets this object's fields.voidsetDimensions(int width, int height) Sets the dimensions of this flat.voidsetPixel(int x, int y, int value) Sets the pixel data at a location in the flat.voidwriteBytes(OutputStream out) Writes this object to anOutputStream.
-
Constructor Details
-
Flat
public Flat(int width, int height) Creates a new flat.- Parameters:
width- the width of the flat in pixels. Must be greater than 1.height- the height of the flat in pixels. Must be greater than 1.
-
-
Method Details
-
create
Reads and creates a new Flat object from an array of bytes. This reads until it reaches the end of the entry list.- Parameters:
width- the width of the flat in pixels. Must be greater than 1.height- the height of the flat in pixels. Must be greater than 1.bytes- the byte array to read.- Returns:
- a new Switches object.
- Throws:
IOException- if the stream cannot be read.
-
read
Reads and creates a new Flat from anInputStreamimplementation. This reads from the stream until enough bytes for the fullFlatare read. The stream is NOT closed at the end.- Parameters:
width- the width of the flat in pixels. Must be greater than 1.height- the height of the flat in pixels. Must be greater than 1.in- the openInputStreamto read from.- Returns:
- a new Flat with its fields set.
- Throws:
IOException- if the stream cannot be read.
-
getOffsetX
public int getOffsetX()- Specified by:
getOffsetXin interfaceGraphicObject- Returns:
- the offset from the center, horizontally, in pixels.
-
getOffsetY
public int getOffsetY()- Specified by:
getOffsetYin interfaceGraphicObject- Returns:
- the offset from the center, vertically, in pixels.
-
getWidth
public int getWidth()- Specified by:
getWidthin interfaceGraphicObject- Returns:
- the width of this graphic in pixels.
-
getHeight
public int getHeight()- Specified by:
getHeightin interfaceGraphicObject- Returns:
- the height of this graphic in pixels.
-
clear
public void clear()Clears the pixel data to zeroes. -
setDimensions
public void setDimensions(int width, int height) Sets the dimensions of this flat. WARNING: This will clear all of the data in the flat.- Parameters:
width- the width of the flat in pixels.height- the height of the flat in pixels.
-
setPixel
public void setPixel(int x, int y, int value) Sets the pixel data at a location in the flat. Valid values are in the range of 0 to 255, with 0 to 255 being palette indexes.- Specified by:
setPixelin interfaceGraphicObject- Parameters:
x- patch x-coordinate.y- patch y-coordinate.value- the value to set.- Throws:
IllegalArgumentException- if the value of the pixel is outside the range 0 to 255.ArrayIndexOutOfBoundsException- if the provided coordinates is outside the graphic.
-
getPixel
public int getPixel(int x, int y) Gets the pixel data at a location in the flat.- Specified by:
getPixelin interfaceGraphicObject- Parameters:
x- flat x-coordinate.y- flat y-coordinate.- Returns:
- a palette index value from 0 to 255.
- Throws:
ArrayIndexOutOfBoundsException- if the provided coordinates is outside the graphic.
-
readBytes
Description copied from interface:BinaryObjectReads from anInputStreamand 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:
readBytesin interfaceBinaryObject- Parameters:
in- theInputStreamto read from.- Throws:
IOException- if a read error occurs.
-
writeBytes
Description copied from interface:BinaryObjectWrites this object to anOutputStream.- Specified by:
writeBytesin interfaceBinaryObject- Parameters:
out- theOutputStreamto write to.- Throws:
IOException- if a write error occurs.
-