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\position_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\shadow_map.h" />
<ClInclude Include="src\inc\system\Skybox.h" />

View File

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

View File

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

View File

@ -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<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
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);
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();
for (const auto& path : diffusePaths) {
outFile << " " << convert_w_string_to_string(path);
}
// Textures normales
const auto& normalPaths = object->get_model()->GetTextureContainer().GetPaths(TextureType::Normal);
const auto& normalPaths = textureContainer.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);
const auto& specularPaths = textureContainer.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);
const auto& alphaPaths = textureContainer.GetPaths(TextureType::Alpha);
outFile << " " << alphaPaths.size();
for (const auto& path : alphaPaths) {
outFile << " " << convert_w_string_to_string(path);
}
}
outFile << std::endl;
}