11#include " ChunkManager.h"
22
3- ChunkManager::ChunkManager (std::shared_ptr<GameObject> pworld, std::shared_ptr<Material> p_world_mat, std::shared_ptr<Camera> p_camera) : mp_world(pworld), mp_world_mat(p_world_mat), m_worldmenu(m_load_radius)
3+ #include < utility>
4+
5+ ChunkManager::ChunkManager (std::shared_ptr<GameObject> pworld, std::shared_ptr<Material> p_world_mat, std::shared_ptr<Camera> p_camera) :
6+ mp_world(std::move(pworld)), mp_world_mat(std::move(p_world_mat)), m_worldmenu(m_load_radius)
47{
58 mp_terrain_generator = std::make_unique<TerrainGenerator>();
69 m_render_position = p_camera->GetPosition ();
710 m_render_max = { m_render_position.x + m_load_radius, m_render_position.y + m_load_radius, m_render_position.z + m_load_radius };
811 m_render_min = { m_render_position.x - m_load_radius, m_render_position.y - m_load_radius, m_render_position.z - m_load_radius };
912}
1013
11- ChunkManager::~ChunkManager ()
12- {
13- }
14-
1514void ChunkManager::CreateWorld ()
1615{
1716 for (int32_t x = m_render_min.x ; x <= m_render_max.x ; x++)
@@ -61,9 +60,9 @@ void ChunkManager::UpdateWorld(std::shared_ptr<Scene> p_scene, std::shared_ptr<C
6160
6261 m_render_min.x = m_render_min.x + 1 ;
6362
64- create_x = static_cast < int32_t >( m_render_max.x ) ;
65- update_xplus = static_cast < int32_t >( m_render_max.x ) - 1 ;
66- update_xmin = static_cast < int32_t >( m_render_min.x ) ;
63+ create_x = m_render_max.x ;
64+ update_xplus = m_render_max.x - 1 ;
65+ update_xmin = m_render_min.x ;
6766 scene_x_need_update = true ;
6867 }
6968 else if (p_camera->GetPosition ().x < m_render_position.x - Voxel::CHUNK_SIZE)
@@ -83,9 +82,9 @@ void ChunkManager::UpdateWorld(std::shared_ptr<Scene> p_scene, std::shared_ptr<C
8382
8483 m_render_max.x = m_render_max.x - 1 ;
8584
86- create_x = static_cast < int32_t >( m_render_min.x ) ;
87- update_xplus = static_cast < int32_t >( m_render_min.x ) + 1 ;
88- update_xmin = static_cast < int32_t >( m_render_max.x ) ;
85+ create_x = m_render_min.x ;
86+ update_xplus = m_render_min.x + 1 ;
87+ update_xmin = m_render_max.x ;
8988 scene_x_need_update = true ;
9089 }
9190
@@ -111,9 +110,9 @@ void ChunkManager::UpdateWorld(std::shared_ptr<Scene> p_scene, std::shared_ptr<C
111110
112111 m_render_min.z = m_render_min.z + 1 ;
113112
114- create_z = static_cast < int32_t >( m_render_max.z ) ;
115- update_zplus = static_cast < int32_t >( m_render_max.z ) - 1 ;
116- update_zmin = static_cast < int32_t >( m_render_min.z ) ;
113+ create_z = m_render_max.z ;
114+ update_zplus = m_render_max.z - 1 ;
115+ update_zmin = m_render_min.z ;
117116 scene_z_need_update = true ;
118117 }
119118 else if (p_camera->GetPosition ().z < m_render_position.z - Voxel::CHUNK_SIZE)
@@ -133,9 +132,9 @@ void ChunkManager::UpdateWorld(std::shared_ptr<Scene> p_scene, std::shared_ptr<C
133132
134133 m_render_max.z = m_render_max.z - 1 ;
135134
136- create_z = static_cast < int32_t >( m_render_min.z ) ;
137- update_zplus = static_cast < int32_t >( m_render_min.z ) + 1 ;
138- update_zmin = static_cast < int32_t >( m_render_max.z ) ;
135+ create_z = m_render_min.z ;
136+ update_zplus = m_render_min.z + 1 ;
137+ update_zmin = m_render_max.z ;
139138 scene_z_need_update = true ;
140139 }
141140
@@ -175,15 +174,15 @@ void ChunkManager::UpdateWorld(std::shared_ptr<Scene> p_scene, std::shared_ptr<C
175174
176175void ChunkManager::CreateNewChunk (int32_t x, int32_t y, int32_t z)
177176{
178- ChunkKey key = { x, y, z };
177+ const ChunkKey key = { x, y, z };
179178
180179 std::unique_ptr<Chunk> p_chunk = mp_terrain_generator->SetupWorld (x, y, z);
181180 m_chunk_map.insert (std::pair<ChunkKey, std::unique_ptr<Chunk>>(key, std::move (p_chunk)));
182181}
183182
184183void ChunkManager::DestroyChunk (const int32_t x, const int32_t y, const int32_t z)
185184{
186- ChunkKey key = { x, y, z };
185+ const ChunkKey key = { x, y, z };
187186
188187 m_chunk_map.at (key)->DeleteChunk (mp_world);
189188
0 commit comments