diff --git a/CMakeLists.txt b/CMakeLists.txt index 891cb6b..9abd3c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,12 @@ project(user-interface) include(FetchContent) -set(CMAKE_CXX_STANDARD 20) +if(MSVC) + # see https://gitlab.kitware.com/cmake/cmake/-/issues/22606 + set(CMAKE_CXX_STANDARD 23) +else() + set(CMAKE_CXX_STANDARD 20) +endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) message(STATUS "Looking for lld") @@ -23,7 +28,7 @@ if (LOCAL_PIVOT_DIRECTORY STREQUAL "") FetchContent_Declare( pivot GIT_REPOSITORY https://github.com/EIP-Pivot/pivot.git - GIT_TAG v0.1.0-a.2 + GIT_TAG c1f3b50a477909dfbdaf800794096d8375089656 ) if (NOT pivot_POPULATED) message(STATUS "Populating pivot") diff --git a/include/ImGuiCore/ComponentEditor.hxx b/include/ImGuiCore/ComponentEditor.hxx index 1f19a45..6cfc742 100644 --- a/include/ImGuiCore/ComponentEditor.hxx +++ b/include/ImGuiCore/ComponentEditor.hxx @@ -12,6 +12,8 @@ #include #include +#include + #include #include @@ -20,6 +22,8 @@ extern SceneManager gSceneManager; using ObjectVector = std::vector>; +using namespace pivot::ecs::component; + class ComponentEditor { public: @@ -29,36 +33,10 @@ public: void setVectorObject(LevelId scene); std::unordered_map &getVectorObject(); ObjectVector getObject(); - - template - void addComponent(Entity entity, T component) - { - if (!gSceneManager.getCurrentLevel().isRegister()) gSceneManager.getCurrentLevel().RegisterComponent(); - gSceneManager.getCurrentLevel().AddComponent(entity, component); - } private: - template - void addComponent(T component) - { - if (!gSceneManager.getCurrentLevel().isRegister()) - gSceneManager.getCurrentLevel().RegisterComponent(); - gSceneManager.getCurrentLevel().AddComponent(currentEntity, component); - } - template - void displayComponent(std::string name) - { - if (gSceneManager.getCurrentLevel().hasComponent(currentEntity)) { - if (ImGui::TreeNode(name.c_str())) { - ImGui::TreePop(); - createComponent(gSceneManager.getCurrentLevel().GetComponent(currentEntity)); - } - } - } - + void addComponent(const Description &description); + void displayComponent(); void createPopUp(); - void createComponent(RigidBody &rigidBody); - void createComponent(Gravity &gravity); - void createComponent(RenderObject &renderObject); private : Entity currentEntity; @@ -68,9 +46,4 @@ private : std::unordered_map sceneObject; std::array textures = {"rouge", "vert", "bleu", "cyan", "orange", "jaune", "blanc", "violet"}; std::array models = {"cube", "plane"}; -}; - -template <> -void ComponentEditor::addComponent(Entity entity, RenderObject renderObject); -template <> -void ComponentEditor::addComponent(RenderObject renderObject); \ No newline at end of file +}; \ No newline at end of file diff --git a/include/ImGuiCore/Editor.hxx b/include/ImGuiCore/Editor.hxx index d800262..9734b1e 100644 --- a/include/ImGuiCore/Editor.hxx +++ b/include/ImGuiCore/Editor.hxx @@ -5,7 +5,7 @@ #include #include -#include +#include class Editor { diff --git a/include/ImGuiCore/EntityModule.hxx b/include/ImGuiCore/EntityModule.hxx index c8190e2..8fe86c2 100644 --- a/include/ImGuiCore/EntityModule.hxx +++ b/include/ImGuiCore/EntityModule.hxx @@ -6,6 +6,9 @@ #include +#include +#include + class EntityModule { public: diff --git a/include/ImGuiCore/SystemsEditor.hxx b/include/ImGuiCore/SystemsEditor.hxx index e143953..ba135ca 100644 --- a/include/ImGuiCore/SystemsEditor.hxx +++ b/include/ImGuiCore/SystemsEditor.hxx @@ -6,32 +6,18 @@ #include "Systems/PhysicsSystem.hxx" #include +#include extern SceneManager gSceneManager; +using namespace pivot::ecs::systems; + class SystemsEditor { public: void create(); - void addSystem(); - - template - void addSystem() - { - auto system = gSceneManager.getCurrentLevel().RegisterSystem(); - gSceneManager.getCurrentLevel().SetSystemSignature(system->getSignature()); - system->Init(); - } private: - template - void displaySystem(std::string name) - { - if (gSceneManager.getCurrentLevel().hasSystem()) { - if (ImGui::TreeNode(name.c_str())) { - ImGui::TreePop(); - } - } - } + void displaySystem(); void createPopUp(); }; diff --git a/include/ImGuiCore/TypeTemplate/Template.hxx b/include/ImGuiCore/TypeTemplate/Template.hxx new file mode 100644 index 0000000..94cc7e7 --- /dev/null +++ b/include/ImGuiCore/TypeTemplate/Template.hxx @@ -0,0 +1,44 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include +#include + +using namespace pivot::ecs::component; +using namespace pivot::ecs::data; + +void draw(Value &value, std::string name); +void draw(glm::vec3 &value, std::string name) { ImGui::InputFloat3(name.c_str(), glm::value_ptr(value)); } + +void draw(std::string &value, std::string name) { ImGui::InputText(name.c_str(), &value); } + +void draw(int &value, std::string name) +{ + // ImGui::InputText("Name", &value); +} + +void draw(bool &value, std::string name) +{ + // ImGui::InputText("Name", &value); +} + +void draw(double &value, std::string name) +{ + ImGui::InputDouble(name.c_str(), &value); + // ImGui::InputText("Name", &value); +} + +void draw(Record &values, std::string name) +{ + for (auto &[name, value]: values) draw(value, name); +} + +void draw(Value &value, std::string name) +{ + std::visit([&name](auto &&arg) { draw(arg, name); }, static_cast(value)); +} diff --git a/include/ImGuiCore/TypeTemplate/createValue.hxx b/include/ImGuiCore/TypeTemplate/createValue.hxx new file mode 100644 index 0000000..349f584 --- /dev/null +++ b/include/ImGuiCore/TypeTemplate/createValue.hxx @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include +#include + +using namespace pivot::ecs::component; +using namespace pivot::ecs::data; + +Value createValue(const BasicType &type); +Value createValue(const RecordType &types); + +Value createValue(const Type &type) +{ + return std::visit([](auto &t) {return createValue(t);}, static_cast(type)); +} + +Value createValue(const BasicType &type) +{ + switch (type) { + case BasicType::String: return Value{""}; + case BasicType::Number: return Value{0.0}; + case BasicType::Integer: return Value{0}; + case BasicType::Boolean: return Value{false}; + case BasicType::Vec3: return Value{glm::vec3(0.0f)}; + } + throw std::runtime_error("Illegal BasicType value."); +} + +Value createValue(const RecordType &types) +{ + Record record; + for (auto &[name, type]: types) { + record.insert({name, createValue(type)}); + } + return {record}; +} diff --git a/include/Systems/PhysicsSystem.hxx b/include/Systems/PhysicsSystem.hxx index 74dd36e..e2abfc0 100644 --- a/include/Systems/PhysicsSystem.hxx +++ b/include/Systems/PhysicsSystem.hxx @@ -1,11 +1,7 @@ #pragma once -#include "pivot/ecs/Core/System.hxx" +#include -class PhysicsSystem : public System -{ -public: - void Update(float dt); +using namespace pivot::ecs; - Signature getSignature(); -}; \ No newline at end of file +void physicsSystem(const systems::Description &, systems::Description::systemArgs &, const event::Event &); \ No newline at end of file diff --git a/scripts/components.pvt b/scripts/components.pvt new file mode 100644 index 0000000..ca0e597 --- /dev/null +++ b/scripts/components.pvt @@ -0,0 +1,26 @@ +component Najo + Vector3 position + Number note + +component Thomas + String leopard + Number QI + +component ZAC + Number PEPETTE + Number QI + +component Position + Number pos_x + Number pos_y + Number pos_z + +component Velocity + Number vel_x + Number vel_y + Number vel_z + +system onTickPhysics(anyEntity) + anyEntity.Position.pos_x = anyEntity.Position.pos_x + anyEntity.Velocity.vel_x + anyEntity.Position.pos_y = anyEntity.Position.pos_y + anyEntity.Velocity.vel_y + anyEntity.Position.pos_z = anyEntity.Position.pos_z + anyEntity.Velocity.vel_z \ No newline at end of file diff --git a/source/ImGuiCore/ComponentEditor.cxx b/source/ImGuiCore/ComponentEditor.cxx index 9623c50..2b478b2 100644 --- a/source/ImGuiCore/ComponentEditor.cxx +++ b/source/ImGuiCore/ComponentEditor.cxx @@ -1,4 +1,7 @@ #include "ImGuiCore/ComponentEditor.hxx" +#include "ImGuiCore/TypeTemplate/Template.hxx" +#include "ImGuiCore/TypeTemplate/createValue.hxx" +#include #include void ComponentEditor::create(Entity entity) @@ -6,10 +9,7 @@ void ComponentEditor::create(Entity entity) currentEntity = entity; ImGui::Begin("Component editor"); createPopUp(); - ImGui::InputText("Name", &gSceneManager.getCurrentLevel().getEntityName(currentEntity)); - displayComponent("Rigid body"); - displayComponent("Gravity"); - displayComponent("Render Object"); + displayComponent(); if (ImGui::Button("Add Component")) { ImGui::OpenPopup("AddComponent"); } ImGui::End(); } @@ -29,99 +29,38 @@ ObjectVector ComponentEditor::getObject() { return sceneObject[gSceneManager.get void ComponentEditor::createPopUp() { + auto &cm = gSceneManager.getCurrentLevel().getComponentManager(); if (ImGui::BeginPopup("AddComponent")) { - if (!gSceneManager.getCurrentLevel().hasComponent(currentEntity)) { - if (ImGui::MenuItem("Rigid Body")) { addComponent(RigidBody()); } - } - if (!gSceneManager.getCurrentLevel().hasComponent(currentEntity)) { - if (ImGui::MenuItem("Gravity")) { addComponent(Gravity()); } - } - if (!gSceneManager.getCurrentLevel().hasComponent(currentEntity)) { - if (ImGui::MenuItem("Render object")) { - addComponent({ - .meshID = "cube", - .objectInformation = - { - .transform = Transform(glm::vec3(), glm::vec3(), glm::vec3(1.0f)), - .textureIndex = "blanc", - .materialIndex = "white", - }, - }); - } - } - ImGui::EndPopup(); - } - if (ImGui::BeginPopup("Textures")) { - for (std::string texture: textures) { - if (ImGui::MenuItem(texture.c_str())) { - gSceneManager.getCurrentLevel() - .GetComponent(currentEntity) - .objectInformation.textureIndex = texture; - } - } - ImGui::EndPopup(); - } - if (ImGui::BeginPopup("Models")) { - for (std::string model: models) { - if (ImGui::MenuItem(model.c_str())) { - gSceneManager.getCurrentLevel().GetComponent(currentEntity).meshID = model; + for (const auto &[name, description]: GlobalIndex::getSingleton()) { + if (cm.GetComponent(currentEntity, cm.GetComponentId(name).value()) == std::nullopt) { + if (ImGui::MenuItem(name.c_str())) { addComponent(description); } } } ImGui::EndPopup(); } } -void ComponentEditor::createComponent(RigidBody &rigidBody) +void ComponentEditor::displayComponent() { - ImGui::Indent(); - ImGui::InputFloat3("Acceleration", glm::value_ptr(rigidBody.acceleration)); - ImGui::InputFloat3("Velocity", glm::value_ptr(rigidBody.velocity)); - ImGui::Unindent(); -} - -void ComponentEditor::createComponent(Gravity &gravity) -{ - ImGui::Indent(); - ImGui::InputFloat3("Force", glm::value_ptr(gravity.force)); - ImGui::Unindent(); -} - -void ComponentEditor::createComponent(RenderObject &renderObject) -{ - ImGui::Indent(); - if (ImGui::InputFloat3("Tr", glm::value_ptr(matrixTranslation))) - renderObject.objectInformation.transform.setPosition(matrixTranslation); - if (ImGui::InputFloat3("Rt", glm::value_ptr(matrixRotation))) - renderObject.objectInformation.transform.setRotation(matrixRotation); - if (ImGui::InputFloat3("Sc", glm::value_ptr(matrixScale))) - renderObject.objectInformation.transform.setScale(matrixScale); - if (ImGui::Selectable(gSceneManager.getCurrentLevel() - .GetComponent(currentEntity) - .objectInformation.textureIndex.c_str(), - false, 0, ImVec2(50, 15))) - ImGui::OpenPopup("Textures"); - if (ImGui::Selectable(gSceneManager.getCurrentLevel().GetComponent(currentEntity).meshID.c_str(), - false, 0, ImVec2(50, 15))) - ImGui::OpenPopup("Models"); - ImGui::Unindent(); + auto &cm = gSceneManager.getCurrentLevel().getComponentManager(); + for (auto [description, component]: cm.GetAllComponents(currentEntity)) { + auto id = cm.GetComponentId(description.name).value(); + auto &compArray = cm.GetComponentArray(id).value().get(); + ComponentRef compRef(compArray, currentEntity); + if (ImGui::TreeNode(description.name.c_str())) { + ImGui::TreePop(); + ImGui::Indent(); + draw(component, "oui"); + compRef.set(component); + ImGui::Unindent(); + } + } } -template <> -void ComponentEditor::addComponent(RenderObject renderObject) +void ComponentEditor::addComponent(const Description &description) { - if (!gSceneManager.getCurrentLevel().isRegister()) - gSceneManager.getCurrentLevel().RegisterComponent(); - gSceneManager.getCurrentLevel().AddComponent(currentEntity, renderObject); - sceneObject[gSceneManager.getCurrentLevelId()].push_back( - gSceneManager.getCurrentLevel().GetComponent(currentEntity)); + auto &cm = gSceneManager.getCurrentLevel().getComponentManager(); + auto id = cm.GetComponentId(description.name).value(); + Value newComponent = createValue(description.type); + cm.AddComponent(currentEntity, newComponent, id); } - -template <> -void ComponentEditor::addComponent(Entity entity, RenderObject renderObject) -{ - if (!gSceneManager.getCurrentLevel().isRegister()) - gSceneManager.getCurrentLevel().RegisterComponent(); - gSceneManager.getCurrentLevel().AddComponent(entity, renderObject); - sceneObject[gSceneManager.getCurrentLevelId()].push_back( - gSceneManager.getCurrentLevel().GetComponent(entity)); -} \ No newline at end of file diff --git a/source/ImGuiCore/Editor.cxx b/source/ImGuiCore/Editor.cxx index d31e41a..10eed71 100644 --- a/source/ImGuiCore/Editor.cxx +++ b/source/ImGuiCore/Editor.cxx @@ -49,7 +49,7 @@ void Editor::create() } else { currentGizmoMode = ImGuizmo::LOCAL; } - ImGui::Checkbox("", &useSnap); + ImGui::Checkbox("##", &useSnap); ImGui::SameLine(); switch (currentGizmoOperation) { case ImGuizmo::TRANSLATE: ImGui::InputFloat3("Snap", &snap[0]); break; @@ -72,7 +72,7 @@ LevelId Editor::addScene() { LevelId newScene = gSceneManager.registerLevel(); gSceneManager.setCurrentLevelId(newScene); - gSceneManager.getCurrentLevel().Init(); + // gSceneManager.getCurrentLevel().Init(); return newScene; } @@ -80,7 +80,7 @@ LevelId Editor::addScene(std::string name) { LevelId newScene = gSceneManager.registerLevel(name); gSceneManager.setCurrentLevelId(newScene); - gSceneManager.getCurrentLevel().Init(); + // gSceneManager.getCurrentLevel().Init(); return newScene; } @@ -92,18 +92,18 @@ void Editor::setAspectRatio(float aspect) { aspectRatio = aspect; } void Editor::DisplayGuizmo(Entity entity) { - const auto view = camera.getView(); - const auto projection = camera.getProjection(80.9f, aspectRatio); + // const auto view = camera.getView(); + // const auto projection = camera.getProjection(80.9f, aspectRatio); - const float *view_ptr = glm::value_ptr(view); - const float *projection_ptr = glm::value_ptr(projection); - float *matrix = glm::value_ptr(gSceneManager.getCurrentLevel() - .GetComponent(entity) - .objectInformation.transform.getModelMatrix()); - ImGuiIO &io = ImGui::GetIO(); - ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y); - ImGuizmo::Manipulate(view_ptr, projection_ptr, currentGizmoOperation, currentGizmoMode, matrix, NULL, - useSnap ? &snap[0] : NULL); + // const float *view_ptr = glm::value_ptr(view); + // const float *projection_ptr = glm::value_ptr(projection); + // float *matrix = glm::value_ptr(gSceneManager.getCurrentLevel() + // .GetComponent(entity) + // .objectInformation.transform.getModelMatrix()); + // ImGuiIO &io = ImGui::GetIO(); + // ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y); + // ImGuizmo::Manipulate(view_ptr, projection_ptr, currentGizmoOperation, currentGizmoMode, matrix, NULL, + // useSnap ? &snap[0] : NULL); } void Editor::createPopUp() @@ -111,7 +111,7 @@ void Editor::createPopUp() if (ImGui::BeginPopup("AddScene")) { static std::string sceneName; ImGui::SetKeyboardFocusHere(); - if (ImGui::InputText("", &sceneName, ImGuiInputTextFlags_EnterReturnsTrue)) { + if (ImGui::InputText("##", &sceneName, ImGuiInputTextFlags_EnterReturnsTrue)) { if (sceneName.empty()) addScene(); else diff --git a/source/ImGuiCore/EntityModule.cxx b/source/ImGuiCore/EntityModule.cxx index ed6ba82..9dd42f8 100644 --- a/source/ImGuiCore/EntityModule.cxx +++ b/source/ImGuiCore/EntityModule.cxx @@ -1,10 +1,13 @@ #include "ImGuiCore/EntityModule.hxx" #include +#include extern SceneManager gSceneManager; void EntityModule::create() { + auto &componentManager = gSceneManager.getCurrentLevel().getComponentManager(); + auto tagId = componentManager.GetComponentId("Tag").value(); if (gSceneManager.getCurrentLevelId() != currentScene) { _hasSelected = false; entitySelected = -1; @@ -12,8 +15,8 @@ void EntityModule::create() currentScene = gSceneManager.getCurrentLevelId(); ImGui::Begin("Entity"); createPopUp(); - for (auto const &[entity,_]: gSceneManager.getCurrentLevel().getEntities()) { - if (ImGui::Selectable(gSceneManager.getCurrentLevel().GetComponent(entity).name.c_str(), + for (auto const &[entity, _]: gSceneManager.getCurrentLevel().getEntities()) { + if (ImGui::Selectable(std::get(std::get(componentManager.GetComponent(entity, tagId).value()).at("name")).c_str(), entitySelected == entity)) { _hasSelected = true; entitySelected = entity; @@ -60,7 +63,7 @@ void EntityModule::createPopUp() if (ImGui::BeginPopup("NewEntity")) { static std::string entityName; ImGui::SetKeyboardFocusHere(); - if (ImGui::InputText("", &entityName, ImGuiInputTextFlags_EnterReturnsTrue)) { + if (ImGui::InputText("##", &entityName, ImGuiInputTextFlags_EnterReturnsTrue)) { if (entityName.empty()) addEntity(); else diff --git a/source/ImGuiCore/SystemsEditor.cxx b/source/ImGuiCore/SystemsEditor.cxx index d5a1339..778b921 100644 --- a/source/ImGuiCore/SystemsEditor.cxx +++ b/source/ImGuiCore/SystemsEditor.cxx @@ -3,7 +3,7 @@ void SystemsEditor::create() { ImGui::Begin("Systems"); - displaySystem("Physics system"); + displaySystem(); if (ImGui::Button("Add System")) { ImGui::OpenPopup("AddSystem"); } createPopUp(); ImGui::End(); @@ -11,10 +11,21 @@ void SystemsEditor::create() void SystemsEditor::createPopUp() { + auto &sm = gSceneManager.getCurrentLevel().getSystemManager(); if (ImGui::BeginPopup("AddSystem")) { - if (!gSceneManager.getCurrentLevel().hasSystem()) { - if (ImGui::MenuItem("Physics system")) { addSystem(); } + for (const auto &[name, description]: GlobalIndex::getSingleton()) { + auto used = sm.getSystemUsed(); + if (std::find(used.begin(), used.end(), name) == used.end()) + if (ImGui::MenuItem(name.c_str())) sm.useSystem(name); } ImGui::EndPopup(); } -} \ No newline at end of file +} + +void SystemsEditor::displaySystem() +{ + auto &sm = gSceneManager.getCurrentLevel().getSystemManager(); + for (const auto &system: sm.getSystemUsed()) { + if (ImGui::TreeNode(system.c_str())) ImGui::TreePop(); + } +} diff --git a/source/Systems/PhysicsSystem.cxx b/source/Systems/PhysicsSystem.cxx index 4bbace8..ce47035 100644 --- a/source/Systems/PhysicsSystem.cxx +++ b/source/Systems/PhysicsSystem.cxx @@ -1,38 +1,28 @@ #include "Systems/PhysicsSystem.hxx" -#include "pivot/ecs/Components/Gravity.hxx" -#include "pivot/ecs/Components/RigidBody.hxx" -#include -#include +using namespace pivot::ecs; -extern SceneManager gSceneManager; - -void PhysicsSystem::Update(float dt) +void physicsSystem(const systems::Description &systemDescription, systems::Description::systemArgs &entities, const event::Event &event) { - for (auto const &entity: mEntities) { - auto &rigidBody = gSceneManager.getCurrentLevel().GetComponent(entity); - auto &renderObject = gSceneManager.getCurrentLevel().GetComponent(entity); + auto dt = (float)std::get(event.payload); + for (auto combination: entities) { + auto gravity = combination[0].get(); + auto rigidBody = combination[1].get(); + auto najo = combination[2].get(); + auto thomas = combination[3].get(); - // Forces - auto const &gravity = gSceneManager.getCurrentLevel().GetComponent(entity); + auto &force = std::get(std::get(gravity).at("force")); - renderObject.objectInformation.transform.addPosition(rigidBody.velocity * dt); + auto &velocity = std::get(std::get(rigidBody).at("velocity")); + velocity += force * dt; + combination[1].set(rigidBody); - rigidBody.velocity += gravity.force * dt; - } -} + auto ¬e = std::get(std::get(najo).at("note")); + note += 1 * dt; + combination[2].set(najo); -Signature PhysicsSystem::getSignature() -{ - if (!gSceneManager.getCurrentLevel().isRegister()) - gSceneManager.getCurrentLevel().RegisterComponent(); - if (!gSceneManager.getCurrentLevel().isRegister()) - gSceneManager.getCurrentLevel().RegisterComponent(); - if (!gSceneManager.getCurrentLevel().isRegister()) - gSceneManager.getCurrentLevel().RegisterComponent(); - Signature signature; - signature.set(gSceneManager.getCurrentLevel().GetComponentType()); - signature.set(gSceneManager.getCurrentLevel().GetComponentType()); - signature.set(gSceneManager.getCurrentLevel().GetComponentType()); - return signature; + auto &qi = std::get(std::get(thomas).at("QI")); + qi += note * dt; + combination[3].set(thomas); + } } diff --git a/source/main.cxx b/source/main.cxx index 3a51b91..5961823 100644 --- a/source/main.cxx +++ b/source/main.cxx @@ -15,12 +15,19 @@ #include #include +#include +#include + +#include +#include + #include // #include "Scene.hxx" #include "Systems/PhysicsSystem.hxx" #include #include +#include #include #include @@ -34,76 +41,41 @@ #include "FrameLimiter.hpp" -Logger *logger = nullptr; - -class Application : public VulkanApplication +class Application : public pivot::graphics::VulkanApplication { public: Application(): VulkanApplication(), editor(Editor()), camera(editor.getCamera()){}; - void addRandomObject(std::string object) - { - std::array textures = {"rouge", "vert", "bleu", "cyan", "orange", "jaune", "blanc", "violet"}; - std::random_device generator; - std::uniform_real_distribution randPositionY(0.0f, 50.0f); - std::uniform_real_distribution randPositionXZ(-50.0f, 50.0f); - std::uniform_real_distribution randRotation(0.0f, 3.0f); - std::uniform_real_distribution randColor(0.0f, 1.0f); - std::uniform_real_distribution randGravity(-10.0f, -1.0f); - std::uniform_real_distribution randVelocityY(10.0f, 200.0f); - std::uniform_real_distribution randVelocityXZ(-200.0f, 200.0f); - std::uniform_real_distribution randScale(0.5f, 1.0f); - std::uniform_int_distribution randTexture(0, textures.size() - 1); - auto newEntity = entity.addEntity(); - if (newEntity == 1997) - gSceneManager.getCurrentLevel().GetComponent(newEntity).name = - "Best Entity = " + std::to_string(newEntity); - else - gSceneManager.getCurrentLevel().GetComponent(newEntity).name = "Entity " + std::to_string(newEntity); - componentEditor.addComponent(newEntity, { - .force = glm::vec3(0.0f, randGravity(generator), 0.0f), - }); - componentEditor.addComponent( - newEntity, - { - .velocity = glm::vec3(randVelocityXZ(generator), randVelocityY(generator), randVelocityXZ(generator)), - .acceleration = glm::vec3(0.0f, 0.0f, 0.0f), - }); - glm::vec3 position = glm::vec3(randPositionXZ(generator), randPositionY(generator), randPositionXZ(generator)); - glm::vec3 rotation = glm::vec3(randRotation(generator), randRotation(generator), randRotation(generator)); - glm::vec3 scale = glm::vec3(randScale(generator)); - componentEditor.addComponent(newEntity, - { - .meshID = object, - .objectInformation = - { - .transform = Transform(position, rotation, scale), - .textureIndex = textures[randTexture(generator)], - .materialIndex = "white", - }, - }); - } - - void DemoScene() - { - editor.addScene("Demo"); - systemsEditor.addSystem(); - - std::vector entities(MAX_OBJECT - 1); - - for (auto &_entity: entities) { addRandomObject("cube"); } - } - + void loadScene() { LevelId defaultScene = editor.addScene("Default"); - DemoScene(); gSceneManager.setCurrentLevelId(defaultScene); } void init() { - gSceneManager.Init(); + loadResult = _engine.loadFile("../scripts/components.pvt", true); + event::Description tick { + .name = "Tick", + .entities = {}, + .payload = pivot::ecs::data::BasicType::Number, + }; + pivot::ecs::event::GlobalIndex::getSingleton().registerEvent(tick); + + pivot::ecs::systems::Description description{ + .name = "Physics System", + .systemComponents = + { + "Gravity", + "RigidBody", + "Najo", + }, + .eventListener = tick, + .system = &physicsSystem, + }; + pivot::ecs::systems::GlobalIndex::getSingleton().registerSystem(description); + loadScene(); window.captureCursor(true); @@ -156,9 +128,9 @@ class Application : public VulkanApplication last = pos; ControlSystem::processMouseMovement(camera, glm::dvec2(xoffset, yoffset)); }); - load3DModels({"../assets/plane.obj", "../assets/cube.obj"}); - loadTextures({"../assets/rouge.png", "../assets/vert.png", "../assets/bleu.png", "../assets/cyan.png", - "../assets/orange.png", "../assets/jaune.png", "../assets/blanc.png", "../assets/violet.png"}); + assetStorage.loadModels("../assets/plane.obj", "../assets/cube.obj"); + assetStorage.loadTextures("../assets/rouge.png", "../assets/vert.png", "../assets/bleu.png", "../assets/cyan.png", + "../assets/orange.png", "../assets/jaune.png", "../assets/blanc.png", "../assets/violet.png"); } void processKeyboard(const Camera::Movement direction, float dt) noexcept { @@ -223,6 +195,9 @@ class Application : public VulkanApplication imGuiManager.newFrame(); + ImGui::Begin("Message"); + ImGui::Text("- %s", loadResult.output.c_str()); + ImGui::End(); editor.create(); if (!editor.getRun()) { editor.setAspectRatio(getAspectRatio()); @@ -230,12 +205,12 @@ class Application : public VulkanApplication entity.hasSelected() ? componentEditor.create(entity.getEntitySelected()) : componentEditor.create(); systemsEditor.create(); - if (entity.hasSelected() && - gSceneManager.getCurrentLevel().hasComponent(entity.getEntitySelected())) { - editor.DisplayGuizmo(entity.getEntitySelected()); - } + // if (entity.hasSelected() && + // gSceneManager.getCurrentLevel().hasComponent(entity.getEntitySelected())) { + // editor.DisplayGuizmo(entity.getEntitySelected()); + // } } else { - gSceneManager.getCurrentLevel().Update(dt); + gSceneManager.getCurrentLevel().getEventManager().sendEvent("Tick", data::Value(dt)); } UpdateCamera(dt); @@ -260,6 +235,8 @@ class Application : public VulkanApplication } public: + pivot::ecs::script::ScriptEngine _engine; + pivot::ecs::script::LoadResult loadResult; ImGuiManager imGuiManager; Editor editor; EntityModule entity; @@ -275,15 +252,11 @@ class Application : public VulkanApplication int main() try { - logger = new Logger(std::cout); - logger->start(); - Application app; app.init(); app.run(); return 0; } catch (std::exception &e) { - logger->err("THROW") << e.what(); - LOGGER_ENDL; + logger.err("THROW") << e.what(); return 1; }