diff options
Diffstat (limited to 'src/3d/scene_loader.cc')
| -rw-r--r-- | src/3d/scene_loader.cc | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/src/3d/scene_loader.cc b/src/3d/scene_loader.cc index 936d8a2..286edca 100644 --- a/src/3d/scene_loader.cc +++ b/src/3d/scene_loader.cc @@ -1,13 +1,13 @@ #include "3d/scene_loader.h" #include "generated/assets.h" +#include "plane_data.h" #include "util/asset_manager.h" #include "util/mini_math.h" #include <cstdio> #include <cstring> -#include <vector> #include <memory> // For std::shared_ptr #include <new> // For std::nothrow -#include "plane_data.h" +#include <vector> bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) { if (!data || size < 16) { // Header size check @@ -77,18 +77,23 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) { vec3 scale(sx, sy, sz); // Color components (cr, cg, cb, ca) - float cr = *reinterpret_cast<const float*>(data + offset); offset += 4; - float cg = *reinterpret_cast<const float*>(data + offset); offset += 4; - float cb = *reinterpret_cast<const float*>(data + offset); offset += 4; + float cr = *reinterpret_cast<const float*>(data + offset); + offset += 4; + float cg = *reinterpret_cast<const float*>(data + offset); + offset += 4; + float cb = *reinterpret_cast<const float*>(data + offset); + offset += 4; // Read ca, advance offset AFTER reading ca, then construct color - float ca = *reinterpret_cast<const float*>(data + offset); offset += 4; // Offset is now after ca + float ca = *reinterpret_cast<const float*>(data + offset); + offset += 4; // Offset is now after ca vec4 color(cr, cg, cb, ca); // Plane Distance (if type == PLANE) float plane_distance = 0.0f; if (type == ObjectType::PLANE) { // Check bounds before reading plane_distance - if (offset + 4 > size) return false; + if (offset + 4 > size) + return false; plane_distance = *reinterpret_cast<const float*>(data + offset); offset += 4; // Advance offset after reading plane_distance } @@ -96,7 +101,8 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) { // Mesh Asset Name Length // The offset is now correctly positioned for name_len, // either after ca (if not PLANE) or after plane_distance (if PLANE). - if (offset + 4 > size) return false; + if (offset + 4 > size) + return false; uint32_t name_len = *reinterpret_cast<const uint32_t*>(data + offset); offset += 4; @@ -145,12 +151,14 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) { // Store plane distance in shared_user_data if it's a plane if (type == ObjectType::PLANE) { - // Allocate PlaneData on the heap and manage with shared_ptr - // Use std::make_shared for exception safety and efficiency - obj.shared_user_data = std::make_shared<PlaneData>(); - // Assign the plane distance - // Safely cast void* to PlaneData* using static_cast on the shared_ptr's get() - static_cast<PlaneData*>(obj.shared_user_data.get())->distance = plane_distance; + // Allocate PlaneData on the heap and manage with shared_ptr + // Use std::make_shared for exception safety and efficiency + obj.shared_user_data = std::make_shared<PlaneData>(); + // Assign the plane distance + // Safely cast void* to PlaneData* using static_cast on the shared_ptr's + // get() + static_cast<PlaneData*>(obj.shared_user_data.get())->distance = + plane_distance; } // Add to scene |
