skypjack 4 дней назад
Родитель
Сommit
f982598fa5

+ 1 - 0
testbed/CMakeLists.txt

@@ -47,6 +47,7 @@ target_sources(
         application/application.cpp
         application/context.cpp
         meta/meta.cpp
+        system/command_system.cpp
         system/hud_system.cpp
         system/imgui_system.cpp
         system/input_system.cpp

+ 2 - 0
testbed/application/application.cpp

@@ -11,6 +11,7 @@
 #include <entt/entity/registry.hpp>
 #include <imgui.h>
 #include <meta/meta.h>
+#include <system/command_system.h>
 #include <system/hud_system.h>
 #include <system/imgui_system.h>
 #include <system/input_system.h>
@@ -24,6 +25,7 @@ void application::update(entt::registry &registry) {
     ImGui_ImplSDL3_NewFrame();
     ImGui::NewFrame();
 
+    command_system(registry);
     movement_system(registry);
 }
 

+ 31 - 0
testbed/system/command_system.cpp

@@ -0,0 +1,31 @@
+#include <component/input_listener_component.h>
+#include <component/velocity_component.h>
+#include <entt/entity/registry.hpp>
+#include <system/command_system.h>
+
+namespace testbed {
+
+void command_system(entt::registry &registry) {
+    for([[maybe_unused]] auto [entt, input, vel]: registry.view<input_listener_component, velocity_component>().each()) {
+        switch(input.command) {
+        case input_listener_component::type::UP:
+            vel.dy = -1.0f;
+            break;
+        case input_listener_component::type::DOWN:
+            vel.dy = 1.0f;
+            break;
+        case input_listener_component::type::LEFT:
+            vel.dx = -1.0f;
+            break;
+        case input_listener_component::type::RIGHT:
+            vel.dx = 1.0f;
+            break;
+        default:
+            break;
+        }
+
+        input.command = input_listener_component::type::NONE;
+    }
+}
+
+} // namespace testbed

+ 9 - 0
testbed/system/command_system.h

@@ -0,0 +1,9 @@
+#pragma once
+
+#include <entt/entity/fwd.hpp>
+
+namespace testbed {
+
+void command_system(entt::registry &);
+
+}