Skip to content

Commit

Permalink
[World] Small performance improvement.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed May 8, 2023
1 parent 390ff5e commit 91f3883
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
18 changes: 18 additions & 0 deletions source/common/world/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@ void World::setData(int x, int y, int z, u16 data) const {
chunk->setData(x & (CHUNK_WIDTH - 1), y & (CHUNK_DEPTH - 1), z & (CHUNK_HEIGHT - 1), data);
}

bool World::addChunkToUpdate(Chunk *chunk) {
if (m_chunksToUpdate.find(chunk) == m_chunksToUpdate.end()) {
m_chunksToUpdate.emplace(chunk);
m_chunkUpdateQueue.emplace(chunk);
return true;
}
return false;
}

bool World::addChunkToProcess(Chunk *chunk) {
if (m_chunksToProcess.find(chunk) == m_chunksToProcess.end()) {
m_chunksToProcess.emplace(chunk);
m_chunkProcessQueue.emplace(chunk);
return true;
}
return false;
}

void World::clearUpdateQueues() {
while (!m_chunkUpdateQueue.empty())
m_chunkUpdateQueue.pop();
Expand Down
19 changes: 2 additions & 17 deletions source/common/world/World.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,8 @@ class World {
u16 getData(int x, int y, int z) const;
void setData(int x, int y, int z, u16 data) const;

bool addChunkToUpdate(Chunk *chunk) {
if (m_chunksToUpdate.count(chunk) < 1) {
m_chunksToUpdate.emplace(chunk);
m_chunkUpdateQueue.emplace(chunk);
return true;
}
return false;
}

bool addChunkToProcess(Chunk *chunk) {
if (m_chunksToProcess.count(chunk) < 1) {
m_chunksToProcess.emplace(chunk);
m_chunkProcessQueue.emplace(chunk);
return true;
}
return false;
}
bool addChunkToUpdate(Chunk *chunk);
bool addChunkToProcess(Chunk *chunk);

virtual void onBlockPlaced(int, int, int, const Block &) {}

Expand Down

0 comments on commit 91f3883

Please sign in to comment.