Skip to content

Commit a042741

Browse files
author
Dan Liebault
committed
Correction pour évité les conversion implicite sur les distances de rendu
Utilisation de std::move dans le constructeur pour éviter des copies inutiles. Simplification des variables `create_x`, `update_xplus`, et `update_xmin` en supprimant les conversions explicites en `int32_t`. Déclaration de la clé de chunk comme `const` dans `CreateNewChunk` et `DestroyChunk` pour renforcer la sécurité du code. Modification du destructeur pour utiliser `= default` dans `ChunkManager.h`. Changement des types des vecteurs `m_render_max` et `m_render_min` de `glm::vec3` à `glm::i32vec3` pour une meilleure précision des coordonnées entières.
1 parent 11a4bca commit a042741

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

R3DVoxel/VoxelEngine/ChunkManager.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
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-
1514
void 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

176175
void 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

184183
void 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

R3DVoxel/VoxelEngine/ChunkManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ChunkManager
1313
{
1414
public:
1515
ChunkManager(std::shared_ptr<GameObject> pworld, std::shared_ptr<Material> p_world_mat, std::shared_ptr<Camera> p_camera);
16-
~ChunkManager();
16+
~ChunkManager() = default;
1717

1818
void CreateWorld();
1919
void UpdateWorld(std::shared_ptr<Scene> p_scene, std::shared_ptr<Camera> p_camera);
@@ -34,8 +34,8 @@ class ChunkManager
3434
uint8_t m_load_radius = 10;
3535
glm::vec3 m_render_position;
3636

37-
glm::vec3 m_render_max;
38-
glm::vec3 m_render_min;
37+
glm::i32vec3 m_render_max;
38+
glm::i32vec3 m_render_min;
3939

4040
WorldMenu m_worldmenu;
4141
};

0 commit comments

Comments
 (0)