minor refactor

This commit is contained in:
MihailRis
2024-04-04 18:40:36 +03:00
parent 0c411cf227
commit 40c3ce0cb1
2 changed files with 9 additions and 4 deletions
+8 -4
View File
@@ -90,6 +90,13 @@ void ChunksRenderer::process(std::shared_ptr<Chunk> chunk, BlocksRenderer& rende
renderer.build(chunk.get(), level->chunksStorage.get()); renderer.build(chunk.get(), level->chunksStorage.get());
} }
void ChunksRenderer::enqueueJob(std::shared_ptr<Chunk> job) {
jobsMutex.lock();
jobs.push(job);
jobsMutex.unlock();
jobsMutexCondition.notify_one();
}
std::shared_ptr<Mesh> ChunksRenderer::render(std::shared_ptr<Chunk> chunk, bool important) { std::shared_ptr<Mesh> ChunksRenderer::render(std::shared_ptr<Chunk> chunk, bool important) {
chunk->setModified(false); chunk->setModified(false);
@@ -106,10 +113,7 @@ std::shared_ptr<Mesh> ChunksRenderer::render(std::shared_ptr<Chunk> chunk, bool
} }
inwork[key] = true; inwork[key] = true;
jobsMutex.lock(); enqueueJob(chunk);
jobs.push(chunk);
jobsMutex.unlock();
jobsMutexCondition.notify_one();
return nullptr; return nullptr;
} }
+1
View File
@@ -51,6 +51,7 @@ class ChunksRenderer {
const EngineSettings& settings; const EngineSettings& settings;
std::vector<std::unique_lock<std::mutex>> workersBlocked; std::vector<std::unique_lock<std::mutex>> workersBlocked;
void enqueueJob(std::shared_ptr<Chunk> chunk);
void threadLoop(int index); void threadLoop(int index);
void process(std::shared_ptr<Chunk> chunk, BlocksRenderer& renderer); void process(std::shared_ptr<Chunk> chunk, BlocksRenderer& renderer);
public: public: