From 4feccaa64af02a7061b60fb17dcedca1e3e3269e Mon Sep 17 00:00:00 2001 From: tycho Date: Sat, 30 May 2015 00:18:52 +0100 Subject: Clean up Spawn Prepare Made cSpawnPrepare execute on the same thread since it is a syncronous operation, and most of the code happens on the lighting thread. Also moved cSpawnPrepare into its own file --- src/SpawnPrepare.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/SpawnPrepare.h (limited to 'src/SpawnPrepare.h') diff --git a/src/SpawnPrepare.h b/src/SpawnPrepare.h new file mode 100644 index 000000000..bd5c0e0c6 --- /dev/null +++ b/src/SpawnPrepare.h @@ -0,0 +1,47 @@ + +#pragma once + +class cWorld; + + + +/** Generates and lights the spawn area of the world. Runs as a separate thread. */ +class cSpawnPrepare: + public cChunkCoordCallback +{ + +public: + static void PrepareChunks(cWorld & a_World, int a_SpawnChunkX, int a_SpawnChunkZ, int a_PrepareDistance); + +protected: + cWorld & m_World; + int m_SpawnChunkX; + int m_SpawnChunkZ; + int m_PrepareDistance; + + /** The index of the next chunk to be queued in the lighting thread. */ + int m_NextIdx; + + /** The maximum index of the prepared chunks. Queueing stops when m_NextIdx reaches this number. */ + int m_MaxIdx; + + /** Total number of chunks already finished preparing. Preparation finishes when this number reaches m_MaxIdx. */ + int m_NumPrepared; + + /** Event used to signal that the preparation is finished. */ + cEvent m_EvtFinished; + + /** The timestamp of the last progress report emitted. */ + std::chrono::steady_clock::time_point m_LastReportTime; + + /** 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); + + virtual void Call(int a_ChunkX, int a_ChunkZ) override; + + /** Decodes the index into chunk coords. Provides the specific chunk ordering. */ + void DecodeChunkCoords(int a_Idx, int & a_ChunkX, int & a_ChunkZ); +}; + -- cgit v1.2.3 From 06a74e45e247a2d23c6b5a238a3c1b9b17b6c341 Mon Sep 17 00:00:00 2001 From: tycho Date: Sat, 30 May 2015 11:11:17 +0100 Subject: Made cLightingThread own its callbacks --- src/SpawnPrepare.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/SpawnPrepare.h') diff --git a/src/SpawnPrepare.h b/src/SpawnPrepare.h index bd5c0e0c6..cc0da504e 100644 --- a/src/SpawnPrepare.h +++ b/src/SpawnPrepare.h @@ -6,8 +6,7 @@ class cWorld; /** Generates and lights the spawn area of the world. Runs as a separate thread. */ -class cSpawnPrepare: - public cChunkCoordCallback +class cSpawnPrepare { public: @@ -39,9 +38,12 @@ protected: cSpawnPrepare(cWorld & a_World, int a_SpawnChunkX, int a_SpawnChunkZ, int a_PrepareDistance, int a_FirstIdx); - virtual void Call(int a_ChunkX, int a_ChunkZ) override; + 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); + + friend class cSpawnPrepareCallback; + }; -- cgit v1.2.3