Skip to content

Commit ee0e3b5

Browse files
committed
Amélioration de la gestion des chunks dans ChunkManager
Ajout d'une clé de destruction pour les chunks dans `_destroy_list` et modification de la création des chunks pour utiliser `m_render_min` et `m_render_max`. Une variable `z_offset` a été ajoutée, bien qu'elle ne soit pas utilisée. Dans la fonction `copy_to_render`, suppression des chunks de `m_chunk_map` après leur suppression pour améliorer la gestion de la mémoire.
1 parent 3dc25d0 commit ee0e3b5

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

R3DVoxel/VoxelEngine/ChunkManager.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,19 @@ render_update_t ChunkManager::compute_world_update_x(const Camera& camera)
215215
{
216216
const ChunkKey key = { .x = m_render_max.x, .y = y, .z = z };
217217
_setup_list.insert(std::pair<ChunkKey, std::unique_ptr<Chunk>>(key, nullptr));
218+
219+
const ChunkKey destroy_key = { .x = m_render_min.x, .y = y, .z = z };
220+
_destroy_list.insert(std::pair<ChunkKey, std::unique_ptr<Chunk>>(destroy_key, nullptr));
218221
}
219222
}
220223

224+
const int32_t z_offset = std::abs(m_render_min.z);
221225
for (int32_t z = m_render_min.z; z <= m_render_max.z; z++)
222226
{
223227
for (int32_t y = m_render_min.y; y <= m_render_max.y; y++)
224228
{
225229
_setup_list.at({ m_render_max.x, y, z }) = create_chunk(m_render_max.x, y, z);
226-
// DestroyChunk(m_render_min.x, y, z);
230+
_destroy_list.at({ m_render_min.x, y, z }) = create_chunk(m_render_min.x, y, z);
227231
}
228232
}
229233

@@ -247,15 +251,19 @@ render_update_t ChunkManager::compute_world_update_x(const Camera& camera)
247251
{
248252
const ChunkKey key = { .x = m_render_min.x, .y = y, .z = z };
249253
_setup_list.insert(std::pair<ChunkKey, std::unique_ptr<Chunk>>(key, nullptr));
254+
255+
const ChunkKey destroy_key = { .x = m_render_max.x, .y = y, .z = z };
256+
_destroy_list.insert(std::pair<ChunkKey, std::unique_ptr<Chunk>>(destroy_key, nullptr));
250257
}
251258
}
252259

260+
const int32_t z_offset = std::abs(m_render_min.z);
253261
for (int32_t z = m_render_min.z; z <= m_render_max.z; z++)
254262
{
255263
for (int32_t y = m_render_min.y; y <= m_render_max.y; y++)
256264
{
257265
_setup_list.at({ m_render_min.x, y, z }) = create_chunk(m_render_min.x, y, z);
258-
// DestroyChunk(m_render_max.x, y, z);
266+
_destroy_list.at({ m_render_max.x, y, z }) = create_chunk(m_render_max.x, y, z);
259267
}
260268
}
261269

@@ -362,6 +370,7 @@ void ChunkManager::copy_to_render()
362370
{
363371
if (chunk)
364372
{
373+
m_chunk_map.at(key)->DeleteChunk(mp_world);
365374
m_chunk_map.erase(key);
366375
}
367376
}

0 commit comments

Comments
 (0)