Cuberite
A lightweight, fast and extensible game server for Minecraft
|
Represents an area of blocks that are represented using a palette. More...
#include <PalettedBlockArea.h>
Public Member Functions | |
const std::pair< AString, BlockState > & | block (Vector3i aPos) const |
Returns the full blockspec of the block at the specified position. More... | |
UInt32 | blockPaletteIndex (Vector3i aPos) const |
Returns the index into the palette for the block at the specified pos. More... | |
void | crop (const cCuboid &aArea) |
Crops this PBA by the specified coords. More... | |
void | fill (const AString &aBlockTypeName, const BlockState &aBlockState) |
Fills the entire PBA with a single block of the specified type. More... | |
bool | isPositionValid (Vector3i aPos) const |
Returns true if the specified position is within the size bounds of the area. More... | |
std::pair< UInt32, bool > | maybePaletteIndex (const AString &aBlockTypeName, const BlockState &aBlockState) const |
Returns the <index, true> into the palette that is used by the specified full blockspec. More... | |
const BlockTypePalette & | palette () |
Returns the (reqd-only) palette used internally by this object. More... | |
const std::pair< AString, BlockState > & | paletteEntry (UInt32 aPaletteIndex) const |
Returns the blockspec represented by the specified palette index. More... | |
UInt32 | paletteIndex (const AString &aBlockTypeName, const BlockState &aBlockState) |
Returns the index into the palette that is used by the specified full blockspec. More... | |
void | paste (const PalettedBlockArea &aSrc, const cCuboid &aSrcCuboid, Vector3i aDstOrigin=Vector3i()) |
Pastes (copies verbatim) a cCuboid out of the src PBA into this PBA. More... | |
void | paste (const PalettedBlockArea &aSrc, Vector3i aDstOrigin=Vector3i()) |
Pastes (copies verbatim) the entire src PBA into this PBA. More... | |
void | setBlock (Vector3i aPos, const AString &aBlockTypeName, const BlockState &aBlockState) |
Sets a single block using its full blockspec. More... | |
void | setBlock (Vector3i aPos, UInt32 aPaletteIndex) |
Sets a single block using an index to the palette (retrieved earlier by paletteIndex()). More... | |
const Vector3i & | size () const |
Returns the actual size of the area in all 3 axes. More... | |
cCuboid | whole () const |
Returns a cCuboid that encompasses the entire PBA. More... | |
Static Public Member Functions | |
static PalettedBlockArea | createFilled (Vector3i aSize, const AString &aBlockTypeName, const BlockState &aBlockState) |
Creates a new PBA of the specified size filled with the specified block. More... | |
Protected Member Functions | |
PalettedBlockArea () | |
Creates a new uninitialized instance (all sizes zero). More... | |
UInt32 | positionToIndex (Vector3i aPos) const |
Converts the position to index in mBlocks. More... | |
Protected Attributes | |
std::vector< UInt32 > | mBlocks |
The blocks contained in the area, stored as indices into mPalette. More... | |
BlockTypePalette | mPalette |
The palette used in the area. More... | |
Vector3i | mSize |
The size (dimensions) of the area. More... | |
Represents an area of blocks that are represented using a palette.
The object itself provides no thread safety, users of this class need to handle locking, if required. The PalettedBlockArea always contains Blocks and their associated BlockEntities, it may optionally contain Entities. There's no way to instantiate this class directly, you need to use either createFilled(), or read from cWorld.
Definition at line 20 of file PalettedBlockArea.h.
|
protected |
Creates a new uninitialized instance (all sizes zero).
Definition at line 8 of file PalettedBlockArea.cpp.
const std::pair< AString, BlockState > & PalettedBlockArea::block | ( | Vector3i | aPos | ) | const |
Returns the full blockspec of the block at the specified position.
The position must be valid (ASSERTed).
Definition at line 99 of file PalettedBlockArea.cpp.
Returns the index into the palette for the block at the specified pos.
The position must be valid (ASSERTed).
Definition at line 89 of file PalettedBlockArea.cpp.
|
static |
Creates a new PBA of the specified size filled with the specified block.
Throws if there is an error (memory allocation etc.)
Definition at line 17 of file PalettedBlockArea.cpp.
void PalettedBlockArea::crop | ( | const cCuboid & | aArea | ) |
Crops this PBA by the specified coords.
aArea is first cropped to the size of this PBA (so it's only possible to shrink a PBA, not enlarge).
Definition at line 219 of file PalettedBlockArea.cpp.
void PalettedBlockArea::fill | ( | const AString & | aBlockTypeName, |
const BlockState & | aBlockState | ||
) |
Fills the entire PBA with a single block of the specified type.
The palette is reset to one containing only the single block.
Definition at line 129 of file PalettedBlockArea.cpp.
bool PalettedBlockArea::isPositionValid | ( | Vector3i | aPos | ) | const |
Returns true if the specified position is within the size bounds of the area.
Definition at line 117 of file PalettedBlockArea.cpp.
std::pair< UInt32, bool > PalettedBlockArea::maybePaletteIndex | ( | const AString & | aBlockTypeName, |
const BlockState & | aBlockState | ||
) | const |
Returns the <index, true> into the palette that is used by the specified full blockspec.
Returns <undefined, false> if blockspec not in palette.
Definition at line 80 of file PalettedBlockArea.cpp.
|
inline |
Returns the (reqd-only) palette used internally by this object.
Definition at line 93 of file PalettedBlockArea.h.
const std::pair< AString, BlockState > & PalettedBlockArea::paletteEntry | ( | UInt32 | aPaletteIndex | ) | const |
Returns the blockspec represented by the specified palette index.
The index must be valid (ASSERTed).
Definition at line 108 of file PalettedBlockArea.cpp.
UInt32 PalettedBlockArea::paletteIndex | ( | const AString & | aBlockTypeName, |
const BlockState & | aBlockState | ||
) |
Returns the index into the palette that is used by the specified full blockspec.
Adds the blockspec to palette if not already there.
Definition at line 71 of file PalettedBlockArea.cpp.
void PalettedBlockArea::paste | ( | const PalettedBlockArea & | aSrc, |
const cCuboid & | aSrcCuboid, | ||
Vector3i | aDstOrigin = Vector3i() |
||
) |
Pastes (copies verbatim) a cCuboid out of the src PBA into this PBA.
aSrcCuboid is the coord range in aSrc that will be copied (min-coord is inclusive, max-coord is exclusive). aDstOrigin is the coord relative to this PBA where the lowest coords of the copied area will be put. aDstOrigin can be outside of this PBA's coord range (only part of the src is copied). Automatically crops aSrcCuboid so that the copied part is entirely inside this PBA's coord range.
Definition at line 141 of file PalettedBlockArea.cpp.
|
inline |
Pastes (copies verbatim) the entire src PBA into this PBA.
aDstOrigin is the coord relative to this PBA where the lowest coords of the copied area will be put. aDstOrigin can be outside of this PBA's coord range (only part of the src is copied). Gracefully handles situations where the copied src PBA goes outside of this PBA's coord range.
Definition at line 83 of file PalettedBlockArea.h.
Converts the position to index in mBlocks.
This may be removed later on when optimizing the RAM usage of this class by compressing low-palette-count PBAs.
Definition at line 257 of file PalettedBlockArea.cpp.
void PalettedBlockArea::setBlock | ( | Vector3i | aPos, |
const AString & | aBlockTypeName, | ||
const BlockState & | aBlockState | ||
) |
Sets a single block using its full blockspec.
The position must be valid (ASSERTed). If the block is not already in palette, it is added.
Definition at line 49 of file PalettedBlockArea.cpp.
Sets a single block using an index to the palette (retrieved earlier by paletteIndex()).
The position must be valid (ASSERTed). The palette index must be valid (ASSERTed).
Definition at line 58 of file PalettedBlockArea.cpp.
|
inline |
Returns the actual size of the area in all 3 axes.
Definition at line 29 of file PalettedBlockArea.h.
cCuboid PalettedBlockArea::whole | ( | ) | const |
Returns a cCuboid that encompasses the entire PBA.
Technically, {0, 0, 0} to mSize.
Definition at line 40 of file PalettedBlockArea.cpp.
|
protected |
The blocks contained in the area, stored as indices into mPalette.
Definition at line 102 of file PalettedBlockArea.h.
|
protected |
The palette used in the area.
Definition at line 99 of file PalettedBlockArea.h.
|
protected |
The size (dimensions) of the area.
Definition at line 105 of file PalettedBlockArea.h.