diff --git a/external/entt b/external/entt index dd6863f..8e0747f 160000 --- a/external/entt +++ b/external/entt @@ -1 +1 @@ -Subproject commit dd6863f71da1b360ec09c25912617a3423f08149 +Subproject commit 8e0747fd505beb6861939a141ec0962c376d36f2 diff --git a/framework/imgui/src/mm/imgui/imgui_entt_entity_editor.hpp b/framework/imgui/src/mm/imgui/imgui_entt_entity_editor.hpp index c9e71f8..d044c7f 100644 --- a/framework/imgui/src/mm/imgui/imgui_entt_entity_editor.hpp +++ b/framework/imgui/src/mm/imgui/imgui_entt_entity_editor.hpp @@ -129,11 +129,19 @@ public: if (registry.valid(e)) { ImGui::SameLine(); - // clone would go here - //if (ImGui::Button("Clone")) { - //auto old_e = e; - //e = registry.create(); - //} + if (ImGui::Button("Clone")) { + auto old_e = e; + e = registry.create(); + + // create a copy of an entity component by component + for (auto &&curr: registry.storage()) { + if (auto &storage = curr.second; storage.contains(old_e)) { + // TODO: do something with the return value. returns false on failure. + storage.emplace(e, storage.get(old_e)); + } + } + } + ImGui::SameLine(); ImGui::Dummy({10, 0}); // space destroy a bit, to not accidentally click it ImGui::SameLine(); @@ -229,8 +237,10 @@ public: if (comp_list.empty()) { ImGui::Text("Orphans:"); - registry.orphans([®istry](auto e){ - MM_IEEE_ENTITY_WIDGET(e, registry, false); + registry.each([®istry](auto e){ + if (registry.orphan(e)) { + MM_IEEE_ENTITY_WIDGET(e, registry, false); + } }); } else { auto view = registry.runtime_view(comp_list.begin(), comp_list.end()); diff --git a/framework/imgui/src/mm/imgui/widgets/entity.cpp b/framework/imgui/src/mm/imgui/widgets/entity.cpp index dcbbdf1..5d2f761 100644 --- a/framework/imgui/src/mm/imgui/widgets/entity.cpp +++ b/framework/imgui/src/mm/imgui/widgets/entity.cpp @@ -1,4 +1,4 @@ -#include "entity.hpp" +#include "./entity.hpp" #include @@ -15,9 +15,9 @@ void Entity(MM::Entity& e, MM::Scene& ecs, bool dropTarget) { if (ecs.valid(e)) { if (ecs.all_of(e)) { - ImGui::Text(ICON_II_CUBE "E: %d v%d (%s)", entt::to_integral(ecs.entity(e)), ecs.version(e), ecs.get(e).str.c_str()); + ImGui::Text(ICON_II_CUBE "E: %d v%d (%s)", entt::to_entity(e), entt::to_version(e), ecs.get(e).str.c_str()); } else { - ImGui::Text(ICON_II_CUBE "E: %d v%d", entt::to_integral(ecs.entity(e)), ecs.version(e)); + ImGui::Text(ICON_II_CUBE "E: %d v%d", entt::to_entity(e), entt::to_version(e)); } } else { ImGui::Text(ICON_II_CUBE "E: invalid"); @@ -26,7 +26,7 @@ void Entity(MM::Entity& e, MM::Scene& ecs, bool dropTarget) { if (ecs.valid(e)) { if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) { ImGui::SetDragDropPayload(MM_IEEE_IMGUI_PAYLOAD_TYPE_ENTITY, &e, sizeof(e)); - ImGui::Text(ICON_II_CUBE "E: %d v%d", entt::to_integral(ecs.entity(e)), ecs.version(e)); + ImGui::Text(ICON_II_CUBE "E: %d v%d", entt::to_entity(e), entt::to_version(e)); ImGui::EndDragDropSource(); } } diff --git a/framework/imgui/src/mm/services/scene_tools.cpp b/framework/imgui/src/mm/services/scene_tools.cpp index 2a06e1d..a6595b1 100644 --- a/framework/imgui/src/mm/services/scene_tools.cpp +++ b/framework/imgui/src/mm/services/scene_tools.cpp @@ -112,7 +112,11 @@ namespace MM::Services { ImGui::Text("size: %lu", scene.size()); ImGui::Text("alive: %lu", scene.alive()); size_t orphans = 0; - scene.orphans([&](auto) { orphans++; }); + scene.each([&orphans, &scene](auto entity) { + if (scene.orphan(entity)) { + orphans++; + } + }); ImGui::Text("orphans: %lu", orphans); } ImGui::End(); diff --git a/framework/opengl_renderer/test/batched_spritesheet_render_task_test.cpp b/framework/opengl_renderer/test/batched_spritesheet_render_task_test.cpp index 31a69d3..3904a22 100644 --- a/framework/opengl_renderer/test/batched_spritesheet_render_task_test.cpp +++ b/framework/opengl_renderer/test/batched_spritesheet_render_task_test.cpp @@ -28,7 +28,7 @@ using namespace entt::literals; const char* argv0; -void update_spritesheet_animation(entt::view, MM::OpenGL::SpriteSheetRenderable> view, float& accu, const MM::Components::TimeDelta& td) { +void update_spritesheet_animation(entt::view> view, float& accu, const MM::Components::TimeDelta& td) { accu += td.tickDelta; if (accu >= 1.f/10) { diff --git a/framework/opengl_renderer/test/simple_spritesheet_render_task_test.cpp b/framework/opengl_renderer/test/simple_spritesheet_render_task_test.cpp index 936cc3f..e7c2dcf 100644 --- a/framework/opengl_renderer/test/simple_spritesheet_render_task_test.cpp +++ b/framework/opengl_renderer/test/simple_spritesheet_render_task_test.cpp @@ -24,7 +24,7 @@ using namespace entt::literals; -void update_spritesheet_animation(entt::view, MM::OpenGL::SpriteSheetRenderable> view, float& accu, const MM::Components::TimeDelta& td) { +void update_spritesheet_animation(entt::view> view, float& accu, const MM::Components::TimeDelta& td) { accu += td.tickDelta; if (accu >= 1.f/10) { diff --git a/screens/mm_logo/src/mm/screens/mm_logo_screen.cpp b/screens/mm_logo/src/mm/screens/mm_logo_screen.cpp index fb1a461..bb253a2 100644 --- a/screens/mm_logo/src/mm/screens/mm_logo_screen.cpp +++ b/screens/mm_logo/src/mm/screens/mm_logo_screen.cpp @@ -51,7 +51,7 @@ namespace Systems { } // elastic scale easing - void elasic_scale_easing(entt::view, MM::Components::Transform2D, Components::easing> view, const MM::Components::TimeDelta& td) { + void elasic_scale_easing(entt::view> view, const MM::Components::TimeDelta& td) { view.each([&td](auto& t, auto& easing_comp) { easing_comp.accumulator += td.tickDelta; diff --git a/systems/player_velocity/src/mm/systems/player_velocity2d_system.cpp b/systems/player_velocity/src/mm/systems/player_velocity2d_system.cpp index ae786a2..531088f 100644 --- a/systems/player_velocity/src/mm/systems/player_velocity2d_system.cpp +++ b/systems/player_velocity/src/mm/systems/player_velocity2d_system.cpp @@ -6,7 +6,7 @@ namespace MM::Systems { -void player_velocity2d(entt::view, MM::Input::PlayerID, MM::Components::Velocity2D> view, const MM::Engine* engine) { +void player_velocity2d(entt::view> view, const MM::Engine* engine) { ZoneScopedN("MM::Systems::PlayerVelocity2D"); auto& input_ss = engine->getService(); diff --git a/systems/player_velocity/src/mm/systems/player_velocity2d_system.hpp b/systems/player_velocity/src/mm/systems/player_velocity2d_system.hpp index 7b038c3..bb0e5cd 100644 --- a/systems/player_velocity/src/mm/systems/player_velocity2d_system.hpp +++ b/systems/player_velocity/src/mm/systems/player_velocity2d_system.hpp @@ -8,7 +8,7 @@ namespace MM::Systems { // this system transforms the input from the input_service into velocity - void player_velocity2d(entt::view, MM::Input::PlayerID, MM::Components::Velocity2D> view, const MM::Engine* engine); + void player_velocity2d(entt::view> view, const MM::Engine* engine); } // MM::Systems diff --git a/systems/simple_velocity/CMakeLists.txt b/systems/simple_velocity/CMakeLists.txt index 8b5f35f..f331050 100644 --- a/systems/simple_velocity/CMakeLists.txt +++ b/systems/simple_velocity/CMakeLists.txt @@ -1,15 +1,11 @@ cmake_minimum_required(VERSION 3.2) project(simple_velocity_system CXX) -set(HPP_FILES +add_library(simple_velocity_system src/mm/systems/simple_velocity_system2d.hpp + src/mm/systems/simple_velocity_system2d.cpp ) -set(CPP_FILES -) - -add_library(simple_velocity_system ${CPP_FILES} ${HPP_FILES}) - target_include_directories(simple_velocity_system PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") target_link_libraries(simple_velocity_system diff --git a/systems/simple_velocity/src/mm/systems/simple_velocity_system2d.cpp b/systems/simple_velocity/src/mm/systems/simple_velocity_system2d.cpp new file mode 100644 index 0000000..a1a990d --- /dev/null +++ b/systems/simple_velocity/src/mm/systems/simple_velocity_system2d.cpp @@ -0,0 +1,22 @@ +#include "./simple_velocity_system2d.hpp" + +#include + +namespace MM::Systems { + + void simple_velocity( + entt::view> view, + const Components::TimeDelta& td + ) { + view.each([delta = td.tickDelta](auto, auto& t, auto& v) { + t.position += v.velocity * delta; + t.rotation += v.rotation * delta; + } + ); + } + +} // MM::Systems + diff --git a/systems/simple_velocity/src/mm/systems/simple_velocity_system2d.hpp b/systems/simple_velocity/src/mm/systems/simple_velocity_system2d.hpp index 482a372..59628ac 100644 --- a/systems/simple_velocity/src/mm/systems/simple_velocity_system2d.hpp +++ b/systems/simple_velocity/src/mm/systems/simple_velocity_system2d.hpp @@ -1,7 +1,5 @@ #pragma once -#include - #include #include #include @@ -9,12 +7,14 @@ #include namespace MM::Systems { - inline void simple_velocity(entt::view, Components::Transform2D, const Components::Velocity2D> view, const Components::TimeDelta& td) { - view.each([delta = td.tickDelta](auto, auto& t, auto& v) { - t.position += v.velocity * delta; - t.rotation += v.rotation * delta; - } - ); - } -} + + void simple_velocity( + entt::view> view, + const Components::TimeDelta& td + ); + +} // MM::Systems