36 m_SpawnChunkX(a_SpawnChunkX),
37 m_SpawnChunkZ(a_SpawnChunkZ),
38 m_PrepareDistance(a_PrepareDistance),
39 m_NextIdx(a_FirstIdx),
40 m_MaxIdx(a_PrepareDistance * a_PrepareDistance),
42 m_LastReportTime(
std::chrono::steady_clock::now()),
43 m_LastReportChunkCount(0)
55 int MaxIdx = a_PrepareDistance * a_PrepareDistance;
56 int maxQueue = std::min(MaxIdx - 1, 100);
57 auto prep = std::make_shared<cSpawnPrepare>(a_World, a_SpawnChunkX, a_SpawnChunkZ, a_PrepareDistance, maxQueue,
sMakeSharedTag{});
58 for (
int i = 0; i < maxQueue; i++)
61 prep->DecodeChunkCoords(i, chunkX, chunkZ);
62 a_World.
PrepareChunk(chunkX, chunkZ, std::make_unique<cSpawnPrepareCallback>(prep));
68 prep->m_EvtFinished.Wait();
115 auto Now = std::chrono::steady_clock::now();
120 LOG(
"Preparing spawn (%s): %.02f%% (%d/%d; %.02f chunks / sec)",
void LOG(std::string_view a_Format, const Args &... args)
Wraps the chunk coords into a single structure.
Interface class used as a callback for operations that involve chunk coords.
void QueueChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr< cChunkCoordCallback > a_CallbackAfter)
Queues the entire chunk for lighting.
void Set(void)
Sets the event - releases one thread that has been waiting in Wait().
virtual void Call(cChunkCoords a_Coords, bool a_IsSuccess) override
Called with the chunk's coords, and an optional operation status flag for operations that support it.
std::shared_ptr< cSpawnPrepare > m_SpawnPrepare
cSpawnPrepareCallback(std::shared_ptr< cSpawnPrepare > a_SpawnPrepare)
static void PrepareChunks(cWorld &a_World, int a_SpawnChunkX, int a_SpawnChunkZ, int a_PrepareDistance)
std::chrono::steady_clock::time_point m_LastReportTime
The timestamp of the last progress report emitted.
int m_LastReportChunkCount
Number of chunks prepared when the last progress report was emitted.
void PreparedChunkCallback(int a_ChunkX, int a_ChunkZ)
int m_MaxIdx
The maximum index of the prepared chunks.
std::atomic< int > m_NumPrepared
Total number of chunks already finished preparing.
void DecodeChunkCoords(int a_Idx, int &a_ChunkX, int &a_ChunkZ)
Decodes the index into chunk coords.
cEvent m_EvtFinished
Event used to signal that the preparation is finished.
int m_NextIdx
The index of the next chunk to be queued in the lighting thread.
cSpawnPrepare(cWorld &a_World, int a_SpawnChunkX, int a_SpawnChunkZ, int a_PrepareDistance, int a_FirstIdx, sMakeSharedTag)
Private tag allows public constructors that can only be used with private access.
void PrepareChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr< cChunkCoordCallback > a_CallAfter={})
Queues the chunk for preparing - making sure that it's generated and lit.
const AString & GetName(void) const
Returns the name of the world.
cLightingThread & GetLightingThread(void)