diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-08 07:40:29 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-08 07:40:29 +0100 |
| commit | c9195f997f3e797f03ab90464e4158717198a167 (patch) | |
| tree | 331304f42870246efdc64cc97ad42de59444ef3a /src/tests/test_scene_loader.cc | |
| parent | b8e6929cafa41681f0b27ac104c9cf1d4e510837 (diff) | |
style: Apply clang-format to all source files
Diffstat (limited to 'src/tests/test_scene_loader.cc')
| -rw-r--r-- | src/tests/test_scene_loader.cc | 225 |
1 files changed, 126 insertions, 99 deletions
diff --git a/src/tests/test_scene_loader.cc b/src/tests/test_scene_loader.cc index e14054b..21bcbaa 100644 --- a/src/tests/test_scene_loader.cc +++ b/src/tests/test_scene_loader.cc @@ -1,107 +1,134 @@ #include "3d/scene_loader.h" -#include "util/mini_math.h" -#include "util/asset_manager.h" #include "generated/assets.h" +#include "util/asset_manager.h" +#include "util/mini_math.h" +#include <cassert> #include <cstdio> #include <cstring> #include <vector> -#include <cassert> int main() { - Scene scene; - std::vector<uint8_t> buffer; - - // Header - const char* magic = "SCN1"; - for(int i=0; i<4; ++i) buffer.push_back(magic[i]); - - uint32_t num_obj = 2; // Increased to 2 - uint32_t num_cam = 0; - uint32_t num_light = 0; - - auto push_u32 = [&](uint32_t v) { - uint8_t* p = (uint8_t*)&v; - for(int i=0; i<4; ++i) buffer.push_back(p[i]); - }; - auto push_f = [&](float v) { - uint8_t* p = (uint8_t*)&v; - for(int i=0; i<4; ++i) buffer.push_back(p[i]); - }; - - push_u32(num_obj); - push_u32(num_cam); - push_u32(num_light); - - // --- Object 1: Basic Cube --- - char name1[64] = {0}; - std::strcpy(name1, "TestObject"); - for(int i=0; i<64; ++i) buffer.push_back(name1[i]); - - push_u32(0); // CUBE - - // Pos - push_f(1.0f); push_f(2.0f); push_f(3.0f); - // Rot (0,0,0,1) - push_f(0.0f); push_f(0.0f); push_f(0.0f); push_f(1.0f); - // Scale - push_f(1.0f); push_f(1.0f); push_f(1.0f); - // Color - push_f(1.0f); push_f(0.0f); push_f(0.0f); push_f(1.0f); - - // Mesh Name length 0 - push_u32(0); - - // Physics - push_f(10.0f); // mass - push_f(0.8f); // restitution - push_u32(1); // static - - // --- Object 2: Mesh with Asset Ref --- - char name2[64] = {0}; - std::strcpy(name2, "MeshObject"); - for(int i=0; i<64; ++i) buffer.push_back(name2[i]); - - push_u32(6); // MESH - - // Pos - push_f(0.0f); push_f(0.0f); push_f(0.0f); - // Rot - push_f(0.0f); push_f(0.0f); push_f(0.0f); push_f(1.0f); - // Scale - push_f(1.0f); push_f(1.0f); push_f(1.0f); - // Color - push_f(0.0f); push_f(1.0f); push_f(0.0f); push_f(1.0f); - - // Mesh Name "MESH_CUBE" - const char* mesh_name = "MESH_CUBE"; - uint32_t mesh_name_len = std::strlen(mesh_name); - push_u32(mesh_name_len); - for(size_t i=0; i<mesh_name_len; ++i) buffer.push_back(mesh_name[i]); - - // Physics - push_f(1.0f); - push_f(0.5f); - push_u32(0); // dynamic - - // --- Load --- - if (SceneLoader::LoadScene(scene, buffer.data(), buffer.size())) { - printf("Scene loaded successfully.\n"); - assert(scene.objects.size() == 2); - - // Check Obj 1 - assert(scene.objects[0].type == ObjectType::CUBE); - assert(scene.objects[0].position.x == 1.0f); - assert(scene.objects[0].is_static == true); - - // Check Obj 2 - assert(scene.objects[1].type == ObjectType::MESH); - assert(scene.objects[1].mesh_asset_id == AssetId::ASSET_MESH_CUBE); - printf("Mesh Asset ID resolved to: %d (Expected %d)\n", (int)scene.objects[1].mesh_asset_id, (int)AssetId::ASSET_MESH_CUBE); - - } else { - printf("Scene load failed.\n"); - return 1; - } - - return 0; + Scene scene; + std::vector<uint8_t> buffer; + + // Header + const char* magic = "SCN1"; + for (int i = 0; i < 4; ++i) + buffer.push_back(magic[i]); + + uint32_t num_obj = 2; // Increased to 2 + uint32_t num_cam = 0; + uint32_t num_light = 0; + + auto push_u32 = [&](uint32_t v) { + uint8_t* p = (uint8_t*)&v; + for (int i = 0; i < 4; ++i) + buffer.push_back(p[i]); + }; + auto push_f = [&](float v) { + uint8_t* p = (uint8_t*)&v; + for (int i = 0; i < 4; ++i) + buffer.push_back(p[i]); + }; + + push_u32(num_obj); + push_u32(num_cam); + push_u32(num_light); + + // --- Object 1: Basic Cube --- + char name1[64] = {0}; + std::strcpy(name1, "TestObject"); + for (int i = 0; i < 64; ++i) + buffer.push_back(name1[i]); + + push_u32(0); // CUBE + + // Pos + push_f(1.0f); + push_f(2.0f); + push_f(3.0f); + // Rot (0,0,0,1) + push_f(0.0f); + push_f(0.0f); + push_f(0.0f); + push_f(1.0f); + // Scale + push_f(1.0f); + push_f(1.0f); + push_f(1.0f); + // Color + push_f(1.0f); + push_f(0.0f); + push_f(0.0f); + push_f(1.0f); + + // Mesh Name length 0 + push_u32(0); + + // Physics + push_f(10.0f); // mass + push_f(0.8f); // restitution + push_u32(1); // static + + // --- Object 2: Mesh with Asset Ref --- + char name2[64] = {0}; + std::strcpy(name2, "MeshObject"); + for (int i = 0; i < 64; ++i) + buffer.push_back(name2[i]); + + push_u32(6); // MESH + + // Pos + push_f(0.0f); + push_f(0.0f); + push_f(0.0f); + // Rot + push_f(0.0f); + push_f(0.0f); + push_f(0.0f); + push_f(1.0f); + // Scale + push_f(1.0f); + push_f(1.0f); + push_f(1.0f); + // Color + push_f(0.0f); + push_f(1.0f); + push_f(0.0f); + push_f(1.0f); + + // Mesh Name "MESH_CUBE" + const char* mesh_name = "MESH_CUBE"; + uint32_t mesh_name_len = std::strlen(mesh_name); + push_u32(mesh_name_len); + for (size_t i = 0; i < mesh_name_len; ++i) + buffer.push_back(mesh_name[i]); + + // Physics + push_f(1.0f); + push_f(0.5f); + push_u32(0); // dynamic + + // --- Load --- + if (SceneLoader::LoadScene(scene, buffer.data(), buffer.size())) { + printf("Scene loaded successfully.\n"); + assert(scene.objects.size() == 2); + + // Check Obj 1 + assert(scene.objects[0].type == ObjectType::CUBE); + assert(scene.objects[0].position.x == 1.0f); + assert(scene.objects[0].is_static == true); + + // Check Obj 2 + assert(scene.objects[1].type == ObjectType::MESH); + assert(scene.objects[1].mesh_asset_id == AssetId::ASSET_MESH_CUBE); + printf("Mesh Asset ID resolved to: %d (Expected %d)\n", + (int)scene.objects[1].mesh_asset_id, (int)AssetId::ASSET_MESH_CUBE); + + } else { + printf("Scene load failed.\n"); + return 1; + } + + return 0; } |
