Skip to content

Commit

Permalink
Common/ChunkEntities: Add lock guard around invalidated chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLynix committed Sep 10, 2024
1 parent 5c51008 commit 768a329
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/CommonLib/ChunkEntities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace tsom
NazaraSlot(ChunkContainer, OnChunkUpdated, m_onChunkUpdated);
NazaraSlot(Nz::Node, OnNodeInvalidation, m_onParentNodeInvalidated);

std::mutex m_invalidatedChunkMutex;
entt::handle m_parentEntity;
tsl::hopscotch_map<ChunkIndices, DirectionMask> m_invalidatedChunks;
tsl::hopscotch_map<ChunkIndices, std::shared_ptr<UpdateJob>> m_updateJobs;
Expand Down
2 changes: 2 additions & 0 deletions src/CommonLib/ChunkEntities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace tsom

m_onChunkUpdated.Connect(chunkContainer.OnChunkUpdated, [this](ChunkContainer* /*emitter*/, Chunk* chunk, DirectionMask neighborMask)
{
// Chunks can be updated in parallel (e.g. planet generation)
std::lock_guard lock(m_invalidatedChunkMutex);
m_invalidatedChunks[chunk->GetIndices()] |= neighborMask;
});
}
Expand Down

0 comments on commit 768a329

Please sign in to comment.