From e527e85b9c9819a41a037c83241e336b25cc77d0 Mon Sep 17 00:00:00 2001 From: CatChow0 Date: Tue, 24 Jun 2025 18:41:13 +0200 Subject: [PATCH] Minor - ECS use in save - V12.6.0 --- enginecustom/DemoScene_V10.1.2.ker | 1 - enginecustom/DemoScene_V10.8.1.ker | 1 - enginecustom/DemoScene_V12.6.0.ker | 1 + enginecustom/enginecustom.vcxproj | 1 - enginecustom/imgui.ini | 4 +- enginecustom/src/inc/system/scene_manager.h | 4 + enginecustom/src/src/system/scene_manager.cpp | 127 ++++++++++++------ 7 files changed, 95 insertions(+), 44 deletions(-) delete mode 100644 enginecustom/DemoScene_V10.1.2.ker delete mode 100644 enginecustom/DemoScene_V10.8.1.ker create mode 100644 enginecustom/DemoScene_V12.6.0.ker diff --git a/enginecustom/DemoScene_V10.1.2.ker b/enginecustom/DemoScene_V10.1.2.ker deleted file mode 100644 index 0278198..0000000 --- a/enginecustom/DemoScene_V10.1.2.ker +++ /dev/null @@ -1 +0,0 @@ -1 isosphere 0 10 0 0 -0 0 1 1 1 Content/Assets/Kobject/isosphere.obj ALPHA_MAPPING 1 Unknown 1 0 2 assets/Texture/Bricks2K.png F:\Github_Repo\khaotic-engine-Reborn\enginecustom\assets\Texture\moss01.png 1 assets/Texture/BricksNRM2K.png 1 assets/Texture/BricksGLOSS2K.png 1 F:\Github_Repo\khaotic-engine-Reborn\enginecustom\assets\Texture\alpha01.png diff --git a/enginecustom/DemoScene_V10.8.1.ker b/enginecustom/DemoScene_V10.8.1.ker deleted file mode 100644 index 1a43e79..0000000 --- a/enginecustom/DemoScene_V10.8.1.ker +++ /dev/null @@ -1 +0,0 @@ -0 vaisseautri 0 50 0 0 -0 0 1 1 1 Content/Assets/Kobject/vaisseautri.obj CEL_SHADING 1 Unknown 1 0 1 F:\Github_Repo\khaotic-engine-Reborn\enginecustom\assets\Texture\marble01.png 1 assets/Texture/BricksNRM2K.png 1 assets/Texture/BricksGLOSS2K.png 0 diff --git a/enginecustom/DemoScene_V12.6.0.ker b/enginecustom/DemoScene_V12.6.0.ker new file mode 100644 index 0000000..9e2f391 --- /dev/null +++ b/enginecustom/DemoScene_V12.6.0.ker @@ -0,0 +1 @@ +1 CubePart_0_0_0 0 0 0 0 -0 0 1 1 1 LIGHTING 0 Terrain 0 0 1 assets/Texture/Bricks2K.png 1 assets/Texture/BricksNRM2K.png 1 assets/Texture/BricksGLOSS2K.png 0 diff --git a/enginecustom/enginecustom.vcxproj b/enginecustom/enginecustom.vcxproj index dce4560..d899b40 100644 --- a/enginecustom/enginecustom.vcxproj +++ b/enginecustom/enginecustom.vcxproj @@ -144,7 +144,6 @@ - diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index ab6c9d5..69eaeb0 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -22,12 +22,12 @@ DockId=0x00000009,0 [Window][Objects] Pos=0,19 -Size=234,842 +Size=234,609 Collapsed=0 DockId=0x0000000B,0 [Window][Terrain] -Pos=0,19 +Pos=236,19 Size=266,609 Collapsed=0 DockId=0x00000007,0 diff --git a/enginecustom/src/inc/system/scene_manager.h b/enginecustom/src/inc/system/scene_manager.h index 850453d..098d153 100644 --- a/enginecustom/src/inc/system/scene_manager.h +++ b/enginecustom/src/inc/system/scene_manager.h @@ -3,6 +3,8 @@ #include #include +#include "ecs/entity.h" + class d_3d_class; class object; class application_class; @@ -26,6 +28,8 @@ public: private: + std::vector> entity_; + application_class* app_; std::string scene_path_; std::vector object_vec_; diff --git a/enginecustom/src/src/system/scene_manager.cpp b/enginecustom/src/src/system/scene_manager.cpp index bf9355f..9ef6926 100644 --- a/enginecustom/src/src/system/scene_manager.cpp +++ b/enginecustom/src/src/system/scene_manager.cpp @@ -52,7 +52,7 @@ bool scene_manager::save_scene_as() { // Mettre à jour le chemin de scène scene_path_ = convert_w_string_to_string(filepath.wstring()); - //object_vec_ = app_->get_kobjects(); // TODO + //object_vec_ = app_->get_kobjects(); // TODO // Sauvegarder la scène avec le nouveau chemin save_scene(); @@ -238,6 +238,7 @@ bool scene_manager::load_scene() { bool scene_manager::save_scene() { + entity_ = app_->get_entity_manager()->GetAllEntities(); if (scene_path_.empty()) { Logger::Get().Log("Scene path is empty. Cannot save scene.", __FILE__, __LINE__, Logger::LogLevel::Error); @@ -250,56 +251,104 @@ bool scene_manager::save_scene() { return false; } - for (const auto& object : object_vec_) { + for (const auto& object : entity_) { XMFLOAT3 position, scale, rotation; - XMStoreFloat3(&position, object->GetPosition()); - XMStoreFloat3(&scale, object->GetScale()); - XMStoreFloat3(&rotation, object->GetRotation()); + int id = 0; + int mass = 0; + float boundingRadius = 0; + std::string name = "NONE"; + std::string shaderType = "NONE"; + std::string objectType = "NONE"; + std::wstring model_path = L""; + bool physics_enabled = false; + + auto transform = object->GetComponent(); + if (transform) { + // convert XMVECTOR to XMFLOAT3 + XMStoreFloat3(&position, transform->GetPosition()); + XMStoreFloat3(&rotation, transform->GetRotation()); + XMStoreFloat3(&scale, transform->GetScale()); + } + + + auto identity = object->GetComponent(); + if (identity) { + + id = identity->GetId(); + name = identity->GetName(); + objectType = identity->ObjectTypeToString(identity->GetType()); + + } + + auto model_path_component = object->GetComponent(); + if (model_path_component) { + + model_path = model_path_component->GetPath(); + } + + auto shader = object->GetComponent(); + if (shader) + { + shaderType = shader->ShaderTypeToString(shader->GetActiveShader()); + } + + auto physics = object->GetComponent(); + if (physics) { + physics_enabled = physics->IsPhysicsEnabled(); + mass = physics->GetMass(); + boundingRadius = physics->GetBoundingRadius(); + } + + // Écrire les données de base de l'objet - outFile << object->GetId() << " " - << object->GetName() << " " + outFile << id << " " + << name << " " << position.x << " " << position.y << " " << position.z << " " << rotation.x << " " << rotation.y << " " << rotation.z << " " << scale.x << " " << scale.y << " " << scale.z << " " - << convert_w_string_to_string(object->GetModelPath()) << " " - << object->ShaderTypeToString(object->GetActiveShader()) << " " - << object->GetBoundingRadius() << " " - << object->ObjectTypeToString(object->GetType()) << " " - << object->GetMass() << " " - << object->IsPhysicsEnabled(); + << convert_w_string_to_string(model_path) << " " + << shaderType << " " + << boundingRadius << " " + << objectType << " " + << mass << " " + << physics_enabled; // Sauvegarder les chemins des textures_ // Format: nombre de textures_ diffuses, puis les chemins // Même chose pour les autres types de textures_ - - // Textures diffuses - const auto& diffusePaths = object->get_model()->GetTextureContainer().GetPaths(TextureType::Diffuse); - outFile << " " << diffusePaths.size(); - for (const auto& path : diffusePaths) { - outFile << " " << convert_w_string_to_string(path); + + + auto render = object->GetComponent(); + if (render) + { + const auto& model = render->GetModel(); + + const auto& textureContainer = model->GetTextureContainer(); + + const auto& diffusePaths = textureContainer.GetPaths(TextureType::Diffuse); + outFile << " " << diffusePaths.size(); + for (const auto& path : diffusePaths) { + outFile << " " << convert_w_string_to_string(path); + } + + const auto& normalPaths = textureContainer.GetPaths(TextureType::Normal); + outFile << " " << normalPaths.size(); + for (const auto& path : normalPaths) { + outFile << " " << convert_w_string_to_string(path); + } + const auto& specularPaths = textureContainer.GetPaths(TextureType::Specular); + outFile << " " << specularPaths.size(); + for (const auto& path : specularPaths) { + outFile << " " << convert_w_string_to_string(path); + } + const auto& alphaPaths = textureContainer.GetPaths(TextureType::Alpha); + outFile << " " << alphaPaths.size(); + for (const auto& path : alphaPaths) { + outFile << " " << convert_w_string_to_string(path); + } } - // Textures normales - const auto& normalPaths = object->get_model()->GetTextureContainer().GetPaths(TextureType::Normal); - outFile << " " << normalPaths.size(); - for (const auto& path : normalPaths) { - outFile << " " << convert_w_string_to_string(path); - } - - // Textures spéculaires - const auto& specularPaths = object->get_model()->GetTextureContainer().GetPaths(TextureType::Specular); - outFile << " " << specularPaths.size(); - for (const auto& path : specularPaths) { - outFile << " " << convert_w_string_to_string(path); - } - - // Textures alpha - const auto& alphaPaths = object->get_model()->GetTextureContainer().GetPaths(TextureType::Alpha); - outFile << " " << alphaPaths.size(); - for (const auto& path : alphaPaths) { - outFile << " " << convert_w_string_to_string(path); - } outFile << std::endl; }