diff options
author | Mattes D <github@xoft.cz> | 2019-10-11 11:02:53 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2019-10-28 10:45:43 +0100 |
commit | 61904af626b036b6e4e045ca219b2a361aa45a6e (patch) | |
tree | 60b99ab37c9ec87ca96d403b3254a4da023cf6ac /src/ChunkDef.h | |
parent | Update README.md (#4423) (diff) | |
download | cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.gz cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.bz2 cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.lz cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.xz cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.zst cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.zip |
Diffstat (limited to '')
-rw-r--r-- | src/ChunkDef.h | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/src/ChunkDef.h b/src/ChunkDef.h index f3621c787..57e4adcfa 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -61,16 +61,33 @@ public: cChunkCoords(int a_ChunkX, int a_ChunkZ) : m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ) {} + bool operator == (const cChunkCoords & a_Other) const { return ((m_ChunkX == a_Other.m_ChunkX) && (m_ChunkZ == a_Other.m_ChunkZ)); } + bool operator != (const cChunkCoords & a_Other) const { return !(operator == (a_Other)); } + + /** Simple comparison, to support ordering. */ + bool operator < (const cChunkCoords & a_Other) const + { + if (a_Other.m_ChunkX == m_ChunkX) + { + return (m_ChunkZ < a_Other.m_ChunkZ); + } + else + { + return (m_ChunkX < a_Other.m_ChunkX); + } + } + + /** Returns a string that describes the chunk coords, suitable for logging. */ AString ToString() const { @@ -152,24 +169,45 @@ public: a_Z = a_Z - a_ChunkZ * Width; } + + + + + /** Converts the specified absolute position into a relative position within its chunk. + Use BlockToChunk to query the chunk coords. */ inline static Vector3i AbsoluteToRelative(Vector3i a_BlockPosition) { - cChunkCoords ChunckPos = BlockToChunk(a_BlockPosition); - - return {a_BlockPosition.x - ChunckPos.m_ChunkX * Width, a_BlockPosition.y, a_BlockPosition.z - ChunckPos.m_ChunkZ * Width}; + cChunkCoords chunkPos = BlockToChunk(a_BlockPosition); + return AbsoluteToRelative(a_BlockPosition, chunkPos); } + + + + + /** Converts the absolute coords into coords relative to the specified chunk. */ inline static Vector3i AbsoluteToRelative(Vector3i a_BlockPosition, cChunkCoords a_ChunkPos) { return {a_BlockPosition.x - a_ChunkPos.m_ChunkX * Width, a_BlockPosition.y, a_BlockPosition.z - a_ChunkPos.m_ChunkZ * Width}; } + + + /** Converts relative block coordinates into absolute coordinates with a known chunk location */ - inline static Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition, int a_ChunkX, int a_ChunkZ) + inline static Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition, cChunkCoords a_ChunkCoords) { - return {a_RelBlockPosition.x + a_ChunkX * Width, a_RelBlockPosition.y, a_RelBlockPosition.z + a_ChunkZ * Width}; + return Vector3i( + a_RelBlockPosition.x + a_ChunkCoords.m_ChunkX * Width, + a_RelBlockPosition.y, + a_RelBlockPosition.z + a_ChunkCoords.m_ChunkZ * Width + ); } + + + + /** Validates a height-coordinate. Returns false if height-coordiante is out of height bounds */ inline static bool IsValidHeight(int a_Height) { |