Minor - ECS use in save - V12.6.0

This commit is contained in:
CatChow0 2025-06-24 18:41:13 +02:00
parent 9d0d2d1dfd
commit e527e85b9c
7 changed files with 95 additions and 44 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -144,7 +144,6 @@
<ClInclude Include="src\inc\system\physics.h" /> <ClInclude Include="src\inc\system\physics.h" />
<ClInclude Include="src\inc\system\position_class.h" /> <ClInclude Include="src\inc\system\position_class.h" />
<ClInclude Include="src\inc\system\render_texture_class.h" /> <ClInclude Include="src\inc\system\render_texture_class.h" />
<ClInclude Include="src\inc\system\sceneManager.h" />
<ClInclude Include="src\inc\system\scene_manager.h" /> <ClInclude Include="src\inc\system\scene_manager.h" />
<ClInclude Include="src\inc\system\shadow_map.h" /> <ClInclude Include="src\inc\system\shadow_map.h" />
<ClInclude Include="src\inc\system\Skybox.h" /> <ClInclude Include="src\inc\system\Skybox.h" />

View File

@ -22,12 +22,12 @@ DockId=0x00000009,0
[Window][Objects] [Window][Objects]
Pos=0,19 Pos=0,19
Size=234,842 Size=234,609
Collapsed=0 Collapsed=0
DockId=0x0000000B,0 DockId=0x0000000B,0
[Window][Terrain] [Window][Terrain]
Pos=0,19 Pos=236,19
Size=266,609 Size=266,609
Collapsed=0 Collapsed=0
DockId=0x00000007,0 DockId=0x00000007,0

View File

@ -3,6 +3,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "ecs/entity.h"
class d_3d_class; class d_3d_class;
class object; class object;
class application_class; class application_class;
@ -26,6 +28,8 @@ public:
private: private:
std::vector<std::shared_ptr<ecs::Entity>> entity_;
application_class* app_; application_class* app_;
std::string scene_path_; std::string scene_path_;
std::vector<object*> object_vec_; std::vector<object*> object_vec_;

View File

@ -238,6 +238,7 @@ bool scene_manager::load_scene() {
bool scene_manager::save_scene() { bool scene_manager::save_scene() {
entity_ = app_->get_entity_manager()->GetAllEntities();
if (scene_path_.empty()) { if (scene_path_.empty()) {
Logger::Get().Log("Scene path is empty. Cannot save scene.", __FILE__, __LINE__, Logger::LogLevel::Error); 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; return false;
} }
for (const auto& object : object_vec_) { for (const auto& object : entity_) {
XMFLOAT3 position, scale, rotation; XMFLOAT3 position, scale, rotation;
XMStoreFloat3(&position, object->GetPosition()); int id = 0;
XMStoreFloat3(&scale, object->GetScale()); int mass = 0;
XMStoreFloat3(&rotation, object->GetRotation()); 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<ecs::TransformComponent>();
if (transform) {
// convert XMVECTOR to XMFLOAT3
XMStoreFloat3(&position, transform->GetPosition());
XMStoreFloat3(&rotation, transform->GetRotation());
XMStoreFloat3(&scale, transform->GetScale());
}
auto identity = object->GetComponent<ecs::IdentityComponent>();
if (identity) {
id = identity->GetId();
name = identity->GetName();
objectType = identity->ObjectTypeToString(identity->GetType());
}
auto model_path_component = object->GetComponent<ecs::ModelPathComponent>();
if (model_path_component) {
model_path = model_path_component->GetPath();
}
auto shader = object->GetComponent<ecs::ShaderComponent>();
if (shader)
{
shaderType = shader->ShaderTypeToString(shader->GetActiveShader());
}
auto physics = object->GetComponent<ecs::PhysicsComponent>();
if (physics) {
physics_enabled = physics->IsPhysicsEnabled();
mass = physics->GetMass();
boundingRadius = physics->GetBoundingRadius();
}
// Écrire les données de base de l'objet // Écrire les données de base de l'objet
outFile << object->GetId() << " " outFile << id << " "
<< object->GetName() << " " << name << " "
<< position.x << " " << position.y << " " << position.z << " " << position.x << " " << position.y << " " << position.z << " "
<< rotation.x << " " << rotation.y << " " << rotation.z << " " << rotation.x << " " << rotation.y << " " << rotation.z << " "
<< scale.x << " " << scale.y << " " << scale.z << " " << scale.x << " " << scale.y << " " << scale.z << " "
<< convert_w_string_to_string(object->GetModelPath()) << " " << convert_w_string_to_string(model_path) << " "
<< object->ShaderTypeToString(object->GetActiveShader()) << " " << shaderType << " "
<< object->GetBoundingRadius() << " " << boundingRadius << " "
<< object->ObjectTypeToString(object->GetType()) << " " << objectType << " "
<< object->GetMass() << " " << mass << " "
<< object->IsPhysicsEnabled(); << physics_enabled;
// Sauvegarder les chemins des textures_ // Sauvegarder les chemins des textures_
// Format: nombre de textures_ diffuses, puis les chemins // Format: nombre de textures_ diffuses, puis les chemins
// Même chose pour les autres types de textures_ // Même chose pour les autres types de textures_
// Textures diffuses
const auto& diffusePaths = object->get_model()->GetTextureContainer().GetPaths(TextureType::Diffuse); auto render = object->GetComponent<ecs::RenderComponent>();
if (render)
{
const auto& model = render->GetModel();
const auto& textureContainer = model->GetTextureContainer();
const auto& diffusePaths = textureContainer.GetPaths(TextureType::Diffuse);
outFile << " " << diffusePaths.size(); outFile << " " << diffusePaths.size();
for (const auto& path : diffusePaths) { for (const auto& path : diffusePaths) {
outFile << " " << convert_w_string_to_string(path); outFile << " " << convert_w_string_to_string(path);
} }
// Textures normales const auto& normalPaths = textureContainer.GetPaths(TextureType::Normal);
const auto& normalPaths = object->get_model()->GetTextureContainer().GetPaths(TextureType::Normal);
outFile << " " << normalPaths.size(); outFile << " " << normalPaths.size();
for (const auto& path : normalPaths) { for (const auto& path : normalPaths) {
outFile << " " << convert_w_string_to_string(path); outFile << " " << convert_w_string_to_string(path);
} }
const auto& specularPaths = textureContainer.GetPaths(TextureType::Specular);
// Textures spéculaires
const auto& specularPaths = object->get_model()->GetTextureContainer().GetPaths(TextureType::Specular);
outFile << " " << specularPaths.size(); outFile << " " << specularPaths.size();
for (const auto& path : specularPaths) { for (const auto& path : specularPaths) {
outFile << " " << convert_w_string_to_string(path); outFile << " " << convert_w_string_to_string(path);
} }
const auto& alphaPaths = textureContainer.GetPaths(TextureType::Alpha);
// Textures alpha
const auto& alphaPaths = object->get_model()->GetTextureContainer().GetPaths(TextureType::Alpha);
outFile << " " << alphaPaths.size(); outFile << " " << alphaPaths.size();
for (const auto& path : alphaPaths) { for (const auto& path : alphaPaths) {
outFile << " " << convert_w_string_to_string(path); outFile << " " << convert_w_string_to_string(path);
} }
}
outFile << std::endl; outFile << std::endl;
} }