@@ -57,13 +57,11 @@ void ChunkManager::CreateWorld()
5757 {
5858 for (int32_t z = m_render_min.z ; z <= m_render_max.z ; z++)
5959 {
60- // _chunk_map.at({ x, y, z })->BuildChunk(_chunk_map, mp_world, mp_world_mat);
6160 if (_chunk_map.at ({ x, y, z })->is_active ())
6261 {
6362 auto mesh = _chunk_map.at ({ x, y, z })->compute_mesh (_chunk_map);
6463 _chunk_map.at ({ x, y, z })->render_mesh (mesh, *mp_world, mp_world_mat);
6564 }
66- // _chunk_map.at({ x, y, z })->update_mesh(mesh, *mp_world);
6765 }
6866 }
6967 }
@@ -145,12 +143,14 @@ std::map<ChunkKey, Geometry> ChunkManager::compute_meshes(std::optional<render_u
145143 const ChunkKey key = { x, y, z_update.created };
146144 meshes.emplace (std::pair<ChunkKey, Geometry>(key, new_chunk->compute_mesh (_setup_list)));
147145 }
146+
148147 Chunk* front_chunk = _setup_list.at ({ x, y, z_update.update_plus }).get ();
149148 if (front_chunk->is_active () && front_chunk->mesh_id () != -1 )
150149 {
151150 const ChunkKey key = { x, y, z_update.update_plus };
152151 meshes.emplace (std::pair<ChunkKey, Geometry>(key, front_chunk->compute_mesh (_setup_list)));
153152 }
153+
154154 Chunk* back_chunk = _setup_list.at ({ x, y, z_update.update_min }).get ();
155155 if (back_chunk->is_active () && back_chunk->mesh_id () != -1 )
156156 {
@@ -246,26 +246,13 @@ void ChunkManager::copy_to_world()
246246
247247void ChunkManager::copy_to_render ()
248248{
249- // for (auto& [key, chunk] : _setup_list)
250- // {
251- // const auto update = _chunk_map.contains(key);
252-
253- // if (chunk && !update) // should make a simple list of keys of created chunks to prevent lookup
254- // {
255- // _chunk_map.insert(std::pair<ChunkKey, std::unique_ptr<Chunk>>(key, std::move(chunk)));
256- // }
257- // else if (chunk)
258- // {
259- // _chunk_map.at(key) = std::move(chunk);
260- // }
261- // }
262-
263249 _chunk_map = std::move (_setup_list);
264250
265251 for (auto & [key, chunk] : _destroy_list) // maybe store pointers to be deleted (prevents lookup in map)
266252 {
267253 if (chunk)
268254 {
255+ // chunk->DeleteChunk(mp_world);
269256 _chunk_map.at (key)->DeleteChunk (mp_world);
270257 _chunk_map.erase (key);
271258 }
@@ -306,7 +293,7 @@ render_update_t ChunkManager::update_x_forward(const Camera& camera)
306293 _setup_list.insert(std::pair<ChunkKey, std::unique_ptr<Chunk>>(back_key, std::move(copy_back)));*/
307294
308295 const ChunkKey destroy_key = { .x = m_render_min.x , .y = y, .z = z };
309- _destroy_list.insert (std::pair<ChunkKey, std::unique_ptr< Chunk>> (destroy_key, nullptr ));
296+ _destroy_list.insert (std::pair<ChunkKey, Chunk*> (destroy_key, _chunk_map. at (destroy_key). get () ));
310297 }
311298 }
312299
@@ -317,7 +304,7 @@ render_update_t ChunkManager::update_x_forward(const Camera& camera)
317304 for (int32_t y = m_render_min.y ; y <= m_render_max.y ; y++)
318305 {
319306 _setup_list.at ({ m_render_max.x , y, z }) = create_chunk (m_render_max.x , y, z);
320- _destroy_list.at ({ m_render_min.x , y, z }) = create_chunk (m_render_min.x , y, z);
307+ // _destroy_list.at({ m_render_min.x, y, z }) = create_chunk(m_render_min.x, y, z);
321308 }
322309
323310 sync.arrive_and_drop ();
@@ -361,7 +348,7 @@ render_update_t ChunkManager::update_x_backward(const Camera& camera)
361348 _setup_list.insert(std::pair<ChunkKey, std::unique_ptr<Chunk>>(back_key, std::move(copy_back)));*/
362349
363350 const ChunkKey destroy_key = { .x = m_render_max.x , .y = y, .z = z };
364- _destroy_list.insert (std::pair<ChunkKey, std::unique_ptr< Chunk>> (destroy_key, nullptr ));
351+ _destroy_list.insert (std::pair<ChunkKey, Chunk*> (destroy_key, _chunk_map. at (destroy_key). get () ));
365352 }
366353 }
367354
@@ -375,7 +362,7 @@ render_update_t ChunkManager::update_x_backward(const Camera& camera)
375362 for (int32_t y = m_render_min.y ; y <= m_render_max.y ; y++)
376363 {
377364 _setup_list.at ({ m_render_min.x , y, z }) = create_chunk (m_render_min.x , y, z);
378- _destroy_list.at ({ m_render_max.x , y, z }) = create_chunk (m_render_max.x , y, z);
365+ // _destroy_list.at({ m_render_max.x, y, z }) = create_chunk(m_render_max.x, y, z);
379366 }
380367
381368 sync.arrive_and_drop ();
@@ -423,7 +410,7 @@ render_update_t ChunkManager::update_z_forward(const Camera& camera)
423410 _setup_list.insert(std::pair<ChunkKey, std::unique_ptr<Chunk>>(back_key, std::move(copy_back)));*/
424411
425412 const ChunkKey destroy_key = { .x = x, .y = y, .z = m_render_min.z };
426- _destroy_list.insert (std::pair<ChunkKey, std::unique_ptr< Chunk>> (destroy_key, nullptr ));
413+ _destroy_list.insert (std::pair<ChunkKey, Chunk*> (destroy_key, _chunk_map. at (destroy_key). get () ));
427414 }
428415 }
429416
@@ -434,7 +421,7 @@ render_update_t ChunkManager::update_z_forward(const Camera& camera)
434421 for (int32_t y = m_render_min.y ; y <= m_render_max.y ; y++)
435422 {
436423 _setup_list.at ({ x, y, m_render_max.z }) = create_chunk (x, y, m_render_max.z );
437- _destroy_list.at ({ x, y, m_render_min.z }) = create_chunk (x, y, m_render_min.z );
424+ // _destroy_list.at({ x, y, m_render_min.z }) = create_chunk(x, y, m_render_min.z);
438425 }
439426 sync.arrive_and_drop ();
440427 };
@@ -480,7 +467,7 @@ render_update_t ChunkManager::update_z_backward(const Camera& camera)
480467 _setup_list.insert(std::pair<ChunkKey, std::unique_ptr<Chunk>>(back_key, std::move(copy_back)));*/
481468
482469 const ChunkKey destroy_key = { .x = x, .y = y, .z = m_render_max.z };
483- _destroy_list.insert (std::pair<ChunkKey, std::unique_ptr< Chunk>> (destroy_key, nullptr ));
470+ _destroy_list.insert (std::pair<ChunkKey, Chunk*> (destroy_key, _chunk_map. at (destroy_key). get () ));
484471 }
485472 }
486473
@@ -491,7 +478,7 @@ render_update_t ChunkManager::update_z_backward(const Camera& camera)
491478 for (int32_t y = m_render_min.y ; y <= m_render_max.y ; y++)
492479 {
493480 _setup_list.at ({ x, y, m_render_min.z }) = create_chunk (x, y, m_render_min.z );
494- _destroy_list.at ({ x, y, m_render_max.z }) = create_chunk (x, y, m_render_max.z );
481+ // _destroy_list.at({ x, y, m_render_max.z }) = create_chunk(x, y, m_render_max.z);
495482 }
496483
497484 sync.arrive_and_drop ();
0 commit comments