16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 01:19:19 +02:00

New Components/ Prepare to new scene loading system

This commit is contained in:
2026-06-16 21:33:29 +02:00
parent 2c599cb419
commit cb739365b4
15 changed files with 712 additions and 57 deletions

View File

@@ -22,6 +22,7 @@ http://mozilla.org/MPL/2.0/.
#include "entitysystem/ECScene.h"
#include "entitysystem/components/BasicComponents.h"
#include "entitysystem/components/RenderComponents.h"
#include "entitysystem/ECSPersistence.h"
driver_ui::driver_ui()
{
@@ -366,6 +367,100 @@ void driver_ui::register_driver_commands()
dev::Console.print_ok("ParticleEmitter added to: " + args[1]);
});
con.register_command("ecs.addspotlight",
"Spawn SpotLight at position: ecs.addspotlight <name> <x> <y> <z> [r g b] [intensity] [range]",
[](const dev::args_t &args) {
if (args.size() < 5) { dev::Console.print_error("Usage: ecs.addspotlight <name> <x> <y> <z> [r g b] [intensity] [range]"); return; }
ECScene *scene = Application.sceneManager.CurrentScene();
if (!scene) { dev::Console.print_warn("No active scene"); return; }
ECWorld &world = scene->World();
auto entity = world.CreateEntity();
auto& id = world.AddComponent<ECSComponent::Identification>(entity);
id.Name = args[1];
auto& t = world.AddComponent<ECSComponent::Transform>(entity);
t.Position = glm::dvec3(std::stod(args[2]), std::stod(args[3]), std::stod(args[4]));
auto& spot = world.AddComponent<ECSComponent::SpotLight>(entity);
if (args.size() > 7) {
spot.Color = glm::vec3(std::stof(args[5]), std::stof(args[6]), std::stof(args[7]));
}
if (args.size() > 8) spot.Intensity = std::stof(args[8]);
if (args.size() > 9) spot.Range = std::stof(args[9]);
spot.Enabled = true;
dev::Console.print_ok("SpotLight '" + args[1] + "' spawned at ("
+ args[2] + ", " + args[3] + ", " + args[4] + ")");
});
con.register_command("ecs.clone",
"Clone entity with optional offset: ecs.clone <src> <newname> [dx dy dz]",
[](const dev::args_t &args) {
if (args.size() < 3) { dev::Console.print_error("Usage: ecs.clone <src> <newname> [dx dy dz]"); return; }
ECScene *scene = Application.sceneManager.CurrentScene();
if (!scene) { dev::Console.print_warn("No active scene"); return; }
ECWorld &world = scene->World();
entt::entity src = world.FindEntityByName(args[1]);
if (src == entt::null) { dev::Console.print_error("Entity not found: " + args[1]); return; }
if (world.FindEntityByName(args[2]) != entt::null) { dev::Console.print_error("Name already exists: " + args[2]); return; }
glm::dvec3 offset{0.0};
if (args.size() >= 6) {
offset = glm::dvec3(std::stod(args[3]), std::stod(args[4]), std::stod(args[5]));
}
auto dst = world.CreateEntity();
auto &id = world.AddComponent<ECSComponent::Identification>(dst);
id.Name = args[2];
if (auto *t = world.GetComponent<ECSComponent::Transform>(src)) {
auto &nt = world.AddComponent<ECSComponent::Transform>(dst);
nt = *t;
nt.Position += offset;
}
if (auto *s = world.GetComponent<ECSComponent::SpotLight>(src))
world.AddComponent<ECSComponent::SpotLight>(dst) = *s;
if (auto *p = world.GetComponent<ECSComponent::ParticleEmitter>(src))
world.AddComponent<ECSComponent::ParticleEmitter>(dst) = *p;
if (auto *b = world.GetComponent<ECSComponent::Billboard>(src))
world.AddComponent<ECSComponent::Billboard>(dst) = *b;
if (auto *l = world.GetComponent<ECSComponent::Line>(src))
world.AddComponent<ECSComponent::Line>(dst) = *l;
if (auto *lod = world.GetComponent<ECSComponent::LODController>(src))
world.AddComponent<ECSComponent::LODController>(dst) = *lod;
dev::Console.print_ok("Cloned '" + args[1] + "' → '" + args[2] + "'");
});
con.register_command("ecs.save",
"Save ECS entities to JSON: ecs.save [filename=ecs_save.json]",
[](const dev::args_t &args) {
ECScene *scene = Application.sceneManager.CurrentScene();
if (!scene) { dev::Console.print_warn("No active scene"); return; }
std::string filename = (args.size() > 1) ? args[1] : "ecs_save.json";
int n = ecs_persistence::save(scene->World(), filename);
if (n >= 0)
dev::Console.print_ok("Saved " + std::to_string(n) + " entities to " + filename);
else
dev::Console.print_error("Cannot write: " + filename);
});
con.register_command("ecs.load",
"Load ECS entities from JSON: ecs.load [filename=ecs_save.json]",
[](const dev::args_t &args) {
ECScene *scene = Application.sceneManager.CurrentScene();
if (!scene) { dev::Console.print_warn("No active scene"); return; }
std::string filename = (args.size() > 1) ? args[1] : "ecs_save.json";
int n = ecs_persistence::load(scene->World(), filename);
if (n >= 0)
dev::Console.print_ok("Loaded " + std::to_string(n) + " entities from " + filename);
else
dev::Console.print_error("Cannot read or parse: " + filename);
});
con.print_info("Driver console ready. Type 'help' for commands.");
}

View File

@@ -579,18 +579,22 @@ void ui_layer::render_entity_hierarchy(ECWorld& world)
{
if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen))
{
float pos[3] = { static_cast<float>(transform->Position.x), static_cast<float>(transform->Position.y), static_cast<float>(transform->Position.z) };
float pos[3] = {
static_cast<float>(transform->Position.x),
static_cast<float>(transform->Position.y),
static_cast<float>(transform->Position.z) };
if (ImGui::DragFloat3("Position", pos, 0.1f)) {
transform->Position.x = pos[0];
transform->Position.y = pos[1];
transform->Position.z = pos[2];
}
if(ImGui::DragFloat3("Position", pos, 0.1f)){
glm::vec3 euler = glm::degrees(glm::eulerAngles(transform->Rotation));
if (ImGui::DragFloat3("Rotation (deg)", &euler.x, 0.5f)) {
transform->Rotation = glm::quat(glm::radians(euler));
}
}
ImGui::DragFloat3("Rotation",
&transform->Rotation.x, 0.1, -360.0, 360.0);
ImGui::DragFloat3("Scale",
&transform->Scale.x, 0.01, 0.0, 100000.0);
ImGui::DragFloat3("Scale", &transform->Scale.x, 0.01f, 0.0f, 100000.0f);
}
}
@@ -599,13 +603,9 @@ void ui_layer::render_entity_hierarchy(ECWorld& world)
{
if (ImGui::CollapsingHeader("Velocity", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::DragFloat3("Value",
&velocity->Value.x, 0.1);
if (ImGui::Button("Stop"))
{
velocity->Value = glm::dvec3(0.0);
}
ImGui::DragFloat3("Value", &velocity->Value.x, 0.1f);
if (ImGui::Button("Stop"))
velocity->Value = glm::vec3(0.0f);
}
}
@@ -614,10 +614,12 @@ void ui_layer::render_entity_hierarchy(ECWorld& world)
{
if (ImGui::CollapsingHeader("LODController", ImGuiTreeNodeFlags_DefaultOpen))
{
float range_min = lod->RangeMin;
float range_max = lod->RangeMax;
ImGui::DragFloat("Range Min", &range_min, 0.1, 0.0, 100000.0);
ImGui::DragFloat("Range Max", &range_max, 0.1, 0.0, 100000.0);
float range_min = static_cast<float>(lod->RangeMin);
float range_max = static_cast<float>(lod->RangeMax);
if (ImGui::DragFloat("Range Min", &range_min, 0.1f, 0.0f, 100000.0f))
lod->RangeMin = range_min;
if (ImGui::DragFloat("Range Max", &range_max, 0.1f, 0.0f, 100000.0f))
lod->RangeMax = range_max;
}
}
@@ -646,7 +648,6 @@ void ui_layer::render_entity_hierarchy(ECWorld& world)
}
// SpotLight
if (auto* light = world.GetComponent<ECSComponent::SpotLight>(m_selected_entity))
{
if (ImGui::CollapsingHeader("SpotLight", ImGuiTreeNodeFlags_DefaultOpen))
@@ -661,6 +662,58 @@ void ui_layer::render_entity_hierarchy(ECWorld& world)
}
}
// SunLight
if (auto* sun = world.GetComponent<ECSComponent::SunLight>(m_selected_entity))
{
if (ImGui::CollapsingHeader("SunLight", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::Checkbox("Enabled", &sun->Enabled);
ImGui::ColorEdit3("Color", &sun->Color.x);
ImGui::DragFloat("Intensity", &sun->Intensity, 0.01f, 0.0f, 10.0f);
}
}
// ParticleEmitter
if (auto* em = world.GetComponent<ECSComponent::ParticleEmitter>(m_selected_entity))
{
if (ImGui::CollapsingHeader("ParticleEmitter", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::Checkbox("Active", &em->isActive);
ImGui::DragFloat("Spawn Rate", &em->spawnRate, 0.5f, 0.0f, 1000.0f);
ImGui::DragFloat("Lifetime", &em->particleLifetime, 0.1f, 0.1f, 60.0f);
ImGui::DragFloat("Air Resistance", &em->airResistance, 0.01f, 0.0f, 5.0f);
ImGui::DragFloat3("Gravity", &em->gravity.x, 0.01f);
ImGui::DragFloat4("Color Fade", &em->colorFade.x, 0.01f, -1.0f, 1.0f);
ImGui::Text("Particles alive: %zu", em->particles.size());
if (ImGui::Button("Clear particles"))
em->particles.clear();
}
}
// Billboard
if (auto* bill = world.GetComponent<ECSComponent::Billboard>(m_selected_entity))
{
if (ImGui::CollapsingHeader("Billboard", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::Checkbox("Active", &bill->active);
ImGui::DragFloat("Size", &bill->size, 0.05f, 0.01f, 100.0f);
ImGui::Text("Texture: %s", bill->texturePath.ToString().c_str());
}
}
// Line
if (auto* line = world.GetComponent<ECSComponent::Line>(m_selected_entity))
{
if (ImGui::CollapsingHeader("Line", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::Checkbox("Active", &line->active);
ImGui::DragFloat3("Start", &line->start.x, 0.1f);
ImGui::DragFloat3("End", &line->end.x, 0.1f);
ImGui::ColorEdit3("Color", &line->color.x);
ImGui::DragFloat("Thickness", &line->thickness, 0.1f, 0.1f, 20.0f);
}
}
ImGui::EndChild();
ImGui::End();
}