24 auto numBlocks =
static_cast<UInt64>(aSize.
x) * static_cast<UInt64>(aSize.
y) *
static_cast<UInt64>(aSize.
z);
25 if (numBlocks >= std::numeric_limits<UInt32>::max())
28 throw std::runtime_error(
"Size is too large");
31 res.
mBlocks.resize(static_cast<size_t>(numBlocks));
32 res.
fill(aBlockTypeName, aBlockState);
120 (aPos.
x >= 0) && (aPos.
y >= 0) && (aPos.
z >= 0) &&
132 auto idx = btp.
index(aBlockTypeName, aBlockState);
154 srcCuboid.
p1.
x -= dstOrigin.
x;
155 if (srcCuboid.
p1.
x >= srcCuboid.
p2.
x)
163 srcCuboid.
p1.
y -= dstOrigin.
y;
164 if (srcCuboid.
p1.
y >= srcCuboid.
p2.
y)
172 srcCuboid.
p1.
z -= dstOrigin.
z;
173 if (srcCuboid.
p1.
z >= srcCuboid.
p2.
z)
197 for (
UInt32 y = minY; y < maxY; ++y)
199 UInt32 srcOfsY = y * srcStrideY;
200 UInt32 dstOfsY = (y - minY + dstY) * dstStrideY;
201 for (
UInt32 z = minZ; z < maxZ; ++z)
203 UInt32 srcOfs = srcOfsY + z * srcStrideZ + minX;
204 UInt32 dstOfs = dstOfsY + (z - minZ + dstZ) * dstStrideZ + dstX;
205 for (
UInt32 x = minX; x < maxX; ++x)
235 for (
UInt32 y = minY; y < maxY; ++y)
237 UInt32 srcOfsY = (y - minY) * srcStrideY;
238 UInt32 dstOfsY = y * dstStrideY;
239 for (
UInt32 z = minZ; z < maxZ; ++z)
241 UInt32 srcOfs = srcOfsY + (z - minZ) * srcStrideZ + minX;
242 UInt32 dstOfs = dstOfsY + z * dstStrideZ;
243 for (
UInt32 x = minX; x < maxX; ++x)
void ClampSize(Vector3i a_MaxSize)
Clamps this cuboid's p2 so that the cuboid's size doesn't exceed the specified max size...
std::pair< UInt32, bool > maybeIndex(const AString &aBlockTypeName, const BlockState &aBlockState) const
Returns the <index, true> of the specified block type name and state, if it exists.
const std::pair< AString, BlockState > & entry(UInt32 aIndex) const
Returns the blockspec represented by the specified palette index.
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.
const Vector3i & size() const
Returns the actual size of the area in all 3 axes.
UInt32 index(const AString &aBlockTypeName, const BlockState &aBlockState)
Returns the index of the specified block type name and state.
UInt32 blockPaletteIndex(Vector3i aPos) const
Returns the index into the palette for the block at the specified pos.
std::map< UInt32, UInt32 > createTransformMapAddMissing(const BlockTypePalette &aFrom)
Returns an index-transform map from aFrom to this (this.entry(idx) == aFrom.entry(res[idx])).
UInt32 positionToIndex(Vector3i aPos) const
Converts the position to index in mBlocks.
Holds a palette that maps between block type + state and numbers.
void fill(const AString &aBlockTypeName, const BlockState &aBlockState)
Fills the entire PBA with a single block of the specified type.
Represents an area of blocks that are represented using a palette.
void paste(const PalettedBlockArea &aSrc, const cCuboid &aSrcCuboid, Vector3i aDstOrigin=Vector3i())
Pastes (copies verbatim) a cCuboid out of the src PBA into this PBA.
cCuboid whole() const
Returns a cCuboid that encompasses the entire PBA.
bool isPositionValid(Vector3i aPos) const
Returns true if the specified position is within the size bounds of the area.
Vector3i mSize
The size (dimensions) of the area.
const std::pair< AString, BlockState > & paletteEntry(UInt32 aPaletteIndex) const
Returns the blockspec represented by the specified palette index.
UInt32 paletteIndex(const AString &aBlockTypeName, const BlockState &aBlockState)
Returns the index into the palette that is used by the specified full blockspec.
static PalettedBlockArea createFilled(Vector3i aSize, const AString &aBlockTypeName, const BlockState &aBlockState)
Creates a new PBA of the specified size filled with the specified block.
void Clamp(const cCuboid &a_Limits)
Clamps this cuboid, so that it doesn't reach outside of a_Limits in any direction.
unsigned long long UInt64
const std::pair< AString, BlockState > & block(Vector3i aPos) const
Returns the full blockspec of the block at the specified position.
std::vector< UInt32 > mBlocks
The blocks contained in the area, stored as indices into mPalette.
void crop(const cCuboid &aArea)
Crops this PBA by the specified coords.
PalettedBlockArea()
Creates a new uninitialized instance (all sizes zero).
BlockTypePalette mPalette
The palette used in the area.
UInt32 count() const
Returns the total number of entries in the palette.
Represents the state of a single block (previously known as "block meta").
void setBlock(Vector3i aPos, const AString &aBlockTypeName, const BlockState &aBlockState)
Sets a single block using its full blockspec.