summaryrefslogtreecommitdiffstats
path: root/src/ChunkDef.h
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2016-08-20 14:34:29 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2016-08-20 14:34:29 +0200
commit7175b9e435a54cff33914d21384625a445cc5cf0 (patch)
tree7feb44f1e8e4ed7ea4d5bf0ba1d173abd3417f34 /src/ChunkDef.h
parentAdded cWorld:SetSpawn() API and Lua binding (#3316) (diff)
downloadcuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.gz
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.bz2
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.lz
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.xz
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.zst
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.zip
Diffstat (limited to '')
-rw-r--r--src/ChunkDef.h55
1 files changed, 33 insertions, 22 deletions
diff --git a/src/ChunkDef.h b/src/ChunkDef.h
index b3cf9049f..f99cc761b 100644
--- a/src/ChunkDef.h
+++ b/src/ChunkDef.h
@@ -31,7 +31,7 @@ class cEntity;
class cClientHandle;
class cBlockEntity;
-typedef std::list<cEntity *> cEntityList;
+typedef std::vector<std::unique_ptr<cEntity>> cEntityList;
typedef std::list<cBlockEntity *> cBlockEntityList;
@@ -53,6 +53,32 @@ typedef unsigned char HEIGHTTYPE;
+
+class cChunkCoords
+{
+public:
+ int m_ChunkX;
+ int m_ChunkZ;
+
+ 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);
+ }
+};
+
+typedef std::vector<cChunkCoords> cChunkCoordsVector;
+
+
+
+
+
/** Constants used throughout the code, useful typedefs and utility functions */
class cChunkDef
{
@@ -142,6 +168,12 @@ public:
}
}
+ /** Converts absolute block coords to chunk coords. */
+ inline static cChunkCoords BlockToChunk(const Vector3i & a_Position)
+ {
+ return { FloorC(a_Position.x / cChunkDef::Width), FloorC(a_Position.x / cChunkDef::Width) };
+ }
+
inline static int MakeIndex(int x, int y, int z)
{
@@ -411,27 +443,6 @@ typedef std::vector<sSetBlock> sSetBlockVector;
-class cChunkCoords
-{
-public:
- int m_ChunkX;
- int m_ChunkZ;
-
- 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));
- }
-} ;
-
-typedef std::list<cChunkCoords> cChunkCoordsList;
-typedef std::vector<cChunkCoords> cChunkCoordsVector;
-
-
-
-
-
/** A simple hash function for chunk coords, we assume that chunk coords won't use more than 16 bits, so the hash is almost an identity.
Used for std::unordered_map<cChunkCoords, ...> */
class cChunkCoordsHash