Le DeleteChunk est maintenant en multi-thread et peux enfin keep up avec le reste!
This commit is contained in:
@@ -54,7 +54,7 @@ void World::TransposeWorld(Player& player, Bullet* bullets[MAX_BULLETS]) {
|
||||
if (ax - x >= 0) {
|
||||
m_chunks.Set(ax - x, ay,
|
||||
m_chunks.Remove(ax, ay));
|
||||
if (ax == WORLD_SIZE_X - 1 && m_chunks.Get(ax - x, ay))
|
||||
if (ax == WORLD_SIZE_X - 1 && m_chunks.Get(ax - x, ay))
|
||||
m_chunks.Get(ax - x, ay)->MakeDirty();
|
||||
}
|
||||
else if (m_chunks.Get(ax, ay)) m_tbDeleted.emplace_back(m_chunks.Remove(ax, ay));
|
||||
@@ -65,7 +65,7 @@ void World::TransposeWorld(Player& player, Bullet* bullets[MAX_BULLETS]) {
|
||||
if (ax - x < WORLD_SIZE_X) {
|
||||
m_chunks.Set(ax - x, ay,
|
||||
m_chunks.Remove(ax, ay));
|
||||
if (ax == 0 && m_chunks.Get(ax - x, ay))
|
||||
if (ax == 0 && m_chunks.Get(ax - x, ay))
|
||||
m_chunks.Get(ax - x, ay)->MakeDirty();
|
||||
}
|
||||
else if (m_chunks.Get(ax, ay)) m_tbDeleted.emplace_back(m_chunks.Remove(ax, ay));
|
||||
@@ -77,7 +77,7 @@ void World::TransposeWorld(Player& player, Bullet* bullets[MAX_BULLETS]) {
|
||||
if (ay - y >= 0) {
|
||||
m_chunks.Set(ax, ay - y,
|
||||
m_chunks.Remove(ax, ay));
|
||||
if (ay == WORLD_SIZE_Y - 1 && m_chunks.Get(ax, ay - y))
|
||||
if (ay == WORLD_SIZE_Y - 1 && m_chunks.Get(ax, ay - y))
|
||||
m_chunks.Get(ax, ay - y)->MakeDirty();
|
||||
}
|
||||
else if (m_chunks.Get(ax, ay)) m_tbDeleted.emplace_back(m_chunks.Remove(ax, ay));
|
||||
@@ -88,7 +88,7 @@ void World::TransposeWorld(Player& player, Bullet* bullets[MAX_BULLETS]) {
|
||||
if (ay - y < WORLD_SIZE_Y) {
|
||||
m_chunks.Set(ax, ay - y,
|
||||
m_chunks.Remove(ax, ay));
|
||||
if (ay == 0 && m_chunks.Get(ax, ay - y))
|
||||
if (ay == 0 && m_chunks.Get(ax, ay - y))
|
||||
m_chunks.Get(ax, ay - y)->MakeDirty();
|
||||
}
|
||||
else if (m_chunks.Get(ax, ay)) m_tbDeleted.emplace_back(m_chunks.Remove(ax, ay));
|
||||
@@ -109,6 +109,11 @@ void World::CleanUpWorld(int& deleteframes, bool clear = false) {
|
||||
}
|
||||
}
|
||||
if (!m_tbDeleted.empty() && !deleteframes) {
|
||||
int deleted = 0;
|
||||
while (deleted < THREADS_DELETE_CHUNKS) {
|
||||
|
||||
|
||||
}
|
||||
delete m_tbDeleted.back();
|
||||
m_tbDeleted.pop_back();
|
||||
deleteframes = FRAMES_DELETE_CHUNKS;
|
||||
@@ -302,6 +307,7 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY
|
||||
int threads = 0;
|
||||
std::future<Chunk*> genThList[THREADS_GENERATE_CHUNKS];
|
||||
std::future<Chunk*> updateThList[THREADS_UPDATE_CHUNKS];
|
||||
std::future<void> delThList[THREADS_DELETE_CHUNKS];
|
||||
|
||||
if (frameGenerate > 0) --frameGenerate;
|
||||
if (frameUpdate > 0) --frameUpdate;
|
||||
@@ -446,5 +452,23 @@ void World::UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTY
|
||||
}
|
||||
}
|
||||
|
||||
CleanUpWorld(frameDelete);
|
||||
}
|
||||
threads = 0;
|
||||
|
||||
while (!m_tbDeleted.empty() && !frameDelete) {
|
||||
if (m_tbDeleted.back()) {
|
||||
m_tbDeleted.back()->FlushVBO();
|
||||
delThList[threads] =
|
||||
std::async(std::launch::async,
|
||||
[](Chunk* chunk) { delete chunk; }, m_tbDeleted.back());
|
||||
m_tbDeleted.pop_back();
|
||||
if (++threads > THREADS_DELETE_CHUNKS) frameDelete = FRAMES_DELETE_CHUNKS;
|
||||
}
|
||||
else m_tbDeleted.pop_back();
|
||||
}
|
||||
|
||||
for (int x = 0; x < threads; ++x)
|
||||
delThList[x].wait();
|
||||
|
||||
}
|
||||
|
||||
int World::GettbDeleted() const { return m_tbDeleted.size(); }
|
Reference in New Issue
Block a user