diff options
Diffstat (limited to '')
-rw-r--r-- | src/ChunkDef.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 425e829a5..f3621c787 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -245,6 +245,14 @@ public: } + + inline static int MakeIndexNoCheck(Vector3i a_RelPos) + { + return MakeIndexNoCheck(a_RelPos.x, a_RelPos.y, a_RelPos.z); + } + + + inline static Vector3i IndexToCoordinate(size_t index) { #if AXIS_ORDER == AXIS_ORDER_XZY @@ -279,6 +287,13 @@ public: } + inline static BLOCKTYPE GetBlock(const BLOCKTYPE * a_BlockTypes, Vector3i a_RelPos) + { + ASSERT(IsValidRelPos(a_RelPos)); + return a_BlockTypes[MakeIndexNoCheck(a_RelPos)]; + } + + inline static BLOCKTYPE GetBlock(const BLOCKTYPE * a_BlockTypes, int a_X, int a_Y, int a_Z) { ASSERT((a_X >= 0) && (a_X < Width)); @@ -358,6 +373,18 @@ public: } + static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, Vector3i a_RelPos) + { + if (IsValidRelPos(a_RelPos)) + { + auto Index = MakeIndexNoCheck(a_RelPos); + return (a_Buffer[static_cast<size_t>(Index / 2)] >> ((Index & 1) * 4)) & 0x0f; + } + ASSERT(!"Coords out of chunk range!"); + return 0; + } + + static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, int x, int y, int z) { if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) |