diff options
Diffstat (limited to 'src/ChunkDef.h')
-rw-r--r-- | src/ChunkDef.h | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 7be2fa2df..a5059348c 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -65,8 +65,8 @@ public: enum { // Chunk dimensions: - Width = 16, - Height = 256, + Width = 16U, + Height = 256U, NumBlocks = Width * Height * Width, /// If the data is collected into a single buffer, how large it needs to be: @@ -124,7 +124,9 @@ public: (z < Width) && (z > -1) ) { - return MakeIndexNoCheck(x, y, z); + return MakeIndexNoCheck(static_cast<unsigned int>(x), + static_cast<unsigned int>(y), + static_cast<unsigned int>(z)); } LOGERROR("cChunkDef::MakeIndex(): coords out of range: {%d, %d, %d}; returning fake index 0", x, y, z); ASSERT(!"cChunkDef::MakeIndex(): coords out of chunk range!"); @@ -132,7 +134,7 @@ public: } - inline static unsigned int MakeIndexNoCheck(int x, int y, int z) + inline static unsigned int MakeIndexNoCheck(unsigned int x, unsigned int y, unsigned int z) { #if AXIS_ORDER == AXIS_ORDER_XZY // For some reason, NOT using the Horner schema is faster. Weird. @@ -166,7 +168,9 @@ public: ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_Y >= 0) && (a_Y < Height)); ASSERT((a_Z >= 0) && (a_Z < Width)); - a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)] = a_Type; + a_BlockTypes[MakeIndexNoCheck(static_cast<unsigned int>(a_X), + static_cast<unsigned int>(a_Y), + static_cast<unsigned int>(a_Z))] = a_Type; } @@ -182,7 +186,9 @@ public: ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_Y >= 0) && (a_Y < Height)); ASSERT((a_Z >= 0) && (a_Z < Width)); - return a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)]; + return a_BlockTypes[MakeIndexNoCheck(static_cast<unsigned int>(a_X), + static_cast<unsigned int>(a_Y), + static_cast<unsigned int>(a_Z))]; } @@ -240,7 +246,9 @@ public: { if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) { - int Index = MakeIndexNoCheck(x, y, z); + unsigned int Index = MakeIndexNoCheck(static_cast<unsigned int>(x), + static_cast<unsigned int>(y), + static_cast<unsigned int>(z)); return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f; } ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!"); @@ -255,7 +263,7 @@ public: ASSERT(!"cChunkDef::SetNibble(): index out of range!"); return; } - a_Buffer[a_BlockIdx / 2] = ( + a_Buffer[a_BlockIdx / 2] = static_cast<NIBBLETYPE>( (a_Buffer[a_BlockIdx / 2] & (0xf0 >> ((a_BlockIdx & 1) * 4))) | // The untouched nibble ((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set ); @@ -274,21 +282,23 @@ public: return; } - int Index = MakeIndexNoCheck(x, y, z); - a_Buffer[Index / 2] = ( + unsigned int Index = MakeIndexNoCheck(static_cast<unsigned int>(x), + static_cast<unsigned int>(y), + static_cast<unsigned int>(z)); + a_Buffer[Index / 2] = static_cast<NIBBLETYPE>( (a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble ((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set ); } - inline static char GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos ) + inline static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos ) { return GetNibble(a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z ); } - inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, char a_Value ) + inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, NIBBLETYPE a_Value ) { SetNibble( a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, a_Value ); } @@ -306,6 +316,9 @@ The virtual methods are called in the same order as they're declared here. class cChunkDataCallback abstract { public: + + virtual ~cChunkDataCallback() {} + /** Called before any other callbacks to inform of the current coords (only in processes where multiple chunks can be processed, such as cWorld::ForEachChunkInRect()). If false is returned, the chunk is skipped. @@ -432,6 +445,9 @@ Used primarily for entity moving while both chunks are locked. class cClientDiffCallback { public: + + virtual ~cClientDiffCallback() {} + /// Called for clients that are in Chunk1 and not in Chunk2, virtual void Removed(cClientHandle * a_Client) = 0; @@ -492,6 +508,9 @@ typedef std::vector<cChunkCoords> cChunkCoordsVector; class cChunkCoordCallback { public: + + virtual ~cChunkCoordCallback() {} + virtual void Call(int a_ChunkX, int a_ChunkZ) = 0; } ; |