summaryrefslogtreecommitdiffstats
path: root/src/SpawnPrepare.h
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2016-12-18 19:31:44 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2016-12-18 19:31:44 +0100
commit1f109febbaae43612c8f47058055ce3b101b3b12 (patch)
tree92ff2e9a36cc0c78bed7f7ec038bfa24fb5df433 /src/SpawnPrepare.h
parentAdded cWorld:SetSpawn() API and Lua binding (#3316) (diff)
downloadcuberite-1f109febbaae43612c8f47058055ce3b101b3b12.tar
cuberite-1f109febbaae43612c8f47058055ce3b101b3b12.tar.gz
cuberite-1f109febbaae43612c8f47058055ce3b101b3b12.tar.bz2
cuberite-1f109febbaae43612c8f47058055ce3b101b3b12.tar.lz
cuberite-1f109febbaae43612c8f47058055ce3b101b3b12.tar.xz
cuberite-1f109febbaae43612c8f47058055ce3b101b3b12.tar.zst
cuberite-1f109febbaae43612c8f47058055ce3b101b3b12.zip
Diffstat (limited to 'src/SpawnPrepare.h')
-rw-r--r--src/SpawnPrepare.h35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/SpawnPrepare.h b/src/SpawnPrepare.h
index 1c7a42b2f..4d6064af4 100644
--- a/src/SpawnPrepare.h
+++ b/src/SpawnPrepare.h
@@ -12,25 +12,19 @@ class cSpawnPrepare
{
public:
- static void PrepareChunks(cWorld & a_World, int a_SpawnChunkX, int a_SpawnChunkZ, int a_PrepareDistance);
+ cSpawnPrepare(cWorld & a_World, int a_PrepareDistance, std::function<void()> a_PreparationCompletedCallback);
-protected:
- cWorld & m_World;
- int m_SpawnChunkX;
- int m_SpawnChunkZ;
- int m_PrepareDistance;
+ static void PrepareChunks(cWorld & a_World, int a_PrepareDistance, std::function<void()> a_PreparationCompletedCallback = {});
- /** The index of the next chunk to be queued in the lighting thread. */
- int m_NextIdx;
+ /** Generates a random spawnpoint on solid land by walking chunks and finding their biomes */
+ static Vector3d GenerateRandomSpawn(cWorld & a_World, int a_PrepareDistance);
- /** The maximum index of the prepared chunks. Queueing stops when m_NextIdx reaches this number. */
- int m_MaxIdx;
+protected:
+ cWorld & m_World;
+ const int m_TotalChunks;
/** Total number of chunks already finished preparing. Preparation finishes when this number reaches m_MaxIdx. */
- std::atomic<int> m_NumPrepared;
-
- /** Event used to signal that the preparation is finished. */
- cEvent m_EvtFinished;
+ int m_NumPrepared;
/** The timestamp of the last progress report emitted. */
std::chrono::steady_clock::time_point m_LastReportTime;
@@ -38,12 +32,19 @@ protected:
/** Number of chunks prepared when the last progress report was emitted. */
int m_LastReportChunkCount;
- cSpawnPrepare(cWorld & a_World, int a_SpawnChunkX, int a_SpawnChunkZ, int a_PrepareDistance, int a_FirstIdx);
+ std::function<void()> m_PreparationCompletedCallback;
void PreparedChunkCallback(int a_ChunkX, int a_ChunkZ);
- /** Decodes the index into chunk coords. Provides the specific chunk ordering. */
- void DecodeChunkCoords(int a_Idx, int & a_ChunkX, int & a_ChunkZ);
+ /** Returns if the biome of the given chunk coordinates is a valid spawn candidate. */
+ static bool IsValidSpawnBiome(cWorld & a_World, int a_ChunkX, int a_ChunkZ);
+
+ /** Can the specified coordinates be used as a spawn point?
+ Returns true if spawn position is valid and sets a_Y to the valid spawn height */
+ static bool CanSpawnAt(cWorld & a_World, double a_X, double & a_Y, double a_Z);
+
+ /** Check if player starting point is acceptable */
+ static bool CheckPlayerSpawnPoint(cWorld & a_World, int a_PosX, int a_PosY, int a_PosZ);
friend class cSpawnPrepareCallback;