summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2020-12-18 21:44:51 +0100
committerTiger Wang <ziwei.tiger@outlook.com>2020-12-21 14:52:15 +0100
commit491238f79967c397d75f3d1aaa87cd0c21390606 (patch)
treeafa441906048ced29b2a17f19a950eca11384e94
parentImprove Silverfish search (diff)
downloadcuberite-491238f79967c397d75f3d1aaa87cd0c21390606.tar
cuberite-491238f79967c397d75f3d1aaa87cd0c21390606.tar.gz
cuberite-491238f79967c397d75f3d1aaa87cd0c21390606.tar.bz2
cuberite-491238f79967c397d75f3d1aaa87cd0c21390606.tar.lz
cuberite-491238f79967c397d75f3d1aaa87cd0c21390606.tar.xz
cuberite-491238f79967c397d75f3d1aaa87cd0c21390606.tar.zst
cuberite-491238f79967c397d75f3d1aaa87cd0c21390606.zip
-rw-r--r--src/Chunk.h1
-rw-r--r--src/ChunkDef.h17
-rw-r--r--src/ChunkMap.cpp5
3 files changed, 6 insertions, 17 deletions
diff --git a/src/Chunk.h b/src/Chunk.h
index 04f305f69..bfd860b1c 100644
--- a/src/Chunk.h
+++ b/src/Chunk.h
@@ -43,7 +43,6 @@ typedef std::list<cClientHandle *> cClientHandleList;
// A convenience macro for calling GetChunkAndRelByAbsolute.
#define PREPARE_REL_AND_CHUNK(Position, OriginalChunk) cChunk * Chunk; Vector3i Rel; bool RelSuccess = (OriginalChunk).GetChunkAndRelByAbsolute(Position, &Chunk, Rel)
-#define PREPARE_BLOCKDATA BLOCKTYPE BlockType; NIBBLETYPE BlockMeta;
// This class is not to be used directly
diff --git a/src/ChunkDef.h b/src/ChunkDef.h
index b77eec38f..1e59f9fb7 100644
--- a/src/ChunkDef.h
+++ b/src/ChunkDef.h
@@ -187,7 +187,7 @@ public:
/** 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};
+ return { a_BlockPosition.x - a_ChunkPos.m_ChunkX * Width, a_BlockPosition.y, a_BlockPosition.z - a_ChunkPos.m_ChunkZ * Width };
}
@@ -234,24 +234,15 @@ public:
{
// This version is deprecated in favor of the vector version
// If you're developing new code, use the other version.
- auto ChunkCoords = BlockToChunk({a_X, 0, a_Z});
+ const auto ChunkCoords = BlockToChunk({ a_X, 0, a_Z });
a_ChunkX = ChunkCoords.m_ChunkX;
a_ChunkZ = ChunkCoords.m_ChunkZ;
}
/** The Y coordinate of a_Pos is ignored */
- inline static cChunkCoords BlockToChunk(Vector3i a_Pos)
+ inline static cChunkCoords BlockToChunk(const Vector3i a_Position)
{
- cChunkCoords Chunk(a_Pos.x / Width, a_Pos.z / Width);
- if ((a_Pos.x < 0) && (a_Pos.x % Width != 0))
- {
- Chunk.m_ChunkX--;
- }
- if ((a_Pos.z < 0) && (a_Pos.z % Width != 0))
- {
- Chunk.m_ChunkZ--;
- }
- return Chunk;
+ return { FAST_FLOOR_DIV(a_Position.x, Width), FAST_FLOOR_DIV(a_Position.z, Width) };
}
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index 46fafd480..aaa8cc0b1 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -153,9 +153,8 @@ bool cChunkMap::DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback a_Callbac
bool cChunkMap::DoWithChunkAt(Vector3i a_BlockPos, cChunkCallback a_Callback)
{
- int ChunkX, ChunkZ;
- cChunkDef::BlockToChunk(a_BlockPos.x, a_BlockPos.z, ChunkX, ChunkZ);
- return DoWithChunk(ChunkX, ChunkZ, a_Callback);
+ const auto Position = cChunkDef::BlockToChunk(a_BlockPos);
+ return DoWithChunk(Position.m_ChunkX, Position.m_ChunkZ, a_Callback);
}