From 365cbc6e1cea96741e26c9ce912b003f8fd2c62c Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 29 Sep 2019 14:59:24 +0200 Subject: Refactored more of Entities and BlockEntities to use Vector3. (#4403) --- src/ChunkDef.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/ChunkDef.h') 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(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)) -- cgit v1.2.3