diff options
author | Alexander Harkness <me@bearbin.net> | 2024-11-02 22:27:47 +0100 |
---|---|---|
committer | Alexander Harkness <me@bearbin.net> | 2024-11-02 22:27:47 +0100 |
commit | cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a (patch) | |
tree | f647b20e1823f1846af88e832cf82a4a02e96e69 /src/SpawnPrepare.cpp | |
parent | Improve clang-format config file, remove automatically enforced code style from contrib guide. (diff) | |
download | cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.gz cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.bz2 cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.lz cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.xz cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.zst cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.zip |
Diffstat (limited to 'src/SpawnPrepare.cpp')
-rw-r--r-- | src/SpawnPrepare.cpp | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/src/SpawnPrepare.cpp b/src/SpawnPrepare.cpp index d79e12754..b254a889b 100644 --- a/src/SpawnPrepare.cpp +++ b/src/SpawnPrepare.cpp @@ -8,17 +8,16 @@ -class cSpawnPrepareCallback : - public cChunkCoordCallback +class cSpawnPrepareCallback : public cChunkCoordCallback { -public: + public: cSpawnPrepareCallback(std::shared_ptr<cSpawnPrepare> a_SpawnPrepare) : m_SpawnPrepare(std::move(a_SpawnPrepare)) { ASSERT(m_SpawnPrepare != nullptr); } -protected: + protected: std::shared_ptr<cSpawnPrepare> m_SpawnPrepare; virtual void Call(cChunkCoords a_Coords, bool a_IsSuccess) override @@ -31,7 +30,14 @@ protected: -cSpawnPrepare::cSpawnPrepare(cWorld & a_World, int a_SpawnChunkX, int a_SpawnChunkZ, int a_PrepareDistance, int a_FirstIdx, sMakeSharedTag): +cSpawnPrepare::cSpawnPrepare( + cWorld & a_World, + int a_SpawnChunkX, + int a_SpawnChunkZ, + int a_PrepareDistance, + int a_FirstIdx, + sMakeSharedTag +) : m_World(a_World), m_SpawnChunkX(a_SpawnChunkX), m_SpawnChunkZ(a_SpawnChunkZ), @@ -54,7 +60,14 @@ void cSpawnPrepare::PrepareChunks(cWorld & a_World, int a_SpawnChunkX, int a_Spa // Queue the initial chunks: int MaxIdx = a_PrepareDistance * a_PrepareDistance; int maxQueue = std::min(MaxIdx - 1, 100); // Number of chunks to queue at once - auto prep = std::make_shared<cSpawnPrepare>(a_World, a_SpawnChunkX, a_SpawnChunkZ, a_PrepareDistance, maxQueue, sMakeSharedTag{}); + auto prep = std::make_shared<cSpawnPrepare>( + a_World, + a_SpawnChunkX, + a_SpawnChunkZ, + a_PrepareDistance, + maxQueue, + sMakeSharedTag {} + ); for (int i = 0; i < maxQueue; i++) { int chunkX, chunkZ; @@ -107,7 +120,8 @@ void cSpawnPrepare::PreparedChunkCallback(int a_ChunkX, int a_ChunkZ) { int chunkX, chunkZ; DecodeChunkCoords(m_NextIdx, chunkX, chunkZ); - m_World.GetLightingThread().QueueChunk(chunkX, chunkZ, std::make_unique<cSpawnPrepareCallback>(shared_from_this())); + m_World.GetLightingThread() + .QueueChunk(chunkX, chunkZ, std::make_unique<cSpawnPrepareCallback>(shared_from_this())); m_NextIdx += 1; } @@ -116,12 +130,15 @@ void cSpawnPrepare::PreparedChunkCallback(int a_ChunkX, int a_ChunkZ) if (Now - m_LastReportTime > std::chrono::seconds(1)) { float PercentDone = static_cast<float>(m_NumPrepared * 100) / m_MaxIdx; - float ChunkSpeed = static_cast<float>((m_NumPrepared - m_LastReportChunkCount) * 1000) / std::chrono::duration_cast<std::chrono::milliseconds>(Now - m_LastReportTime).count(); + float ChunkSpeed = static_cast<float>((m_NumPrepared - m_LastReportChunkCount) * 1000) / + std::chrono::duration_cast<std::chrono::milliseconds>(Now - m_LastReportTime).count(); LOG("Preparing spawn (%s): %.02f%% (%d/%d; %.02f chunks / sec)", - m_World.GetName().c_str(), PercentDone, m_NumPrepared.load(std::memory_order_seq_cst), m_MaxIdx, ChunkSpeed - ); + m_World.GetName().c_str(), + PercentDone, + m_NumPrepared.load(std::memory_order_seq_cst), + m_MaxIdx, + ChunkSpeed); m_LastReportTime = Now; m_LastReportChunkCount = m_NumPrepared; } } - |