Преглед изворни кода

testbed: prepare input system

skypjack пре 10 месеци
родитељ
комит
f505050391

+ 1 - 0
testbed/CMakeLists.txt

@@ -52,6 +52,7 @@ target_sources(
         application/application.cpp
         application/context.cpp
         system/imgui_system.cpp
+        system/input_system.cpp
         system/rendering_system.cpp
 		testbed.cpp
         ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl3.cpp

+ 4 - 12
testbed/application/application.cpp

@@ -7,6 +7,7 @@
 #include <entt/entity/registry.hpp>
 #include <imgui.h>
 #include <system/imgui_system.h>
+#include <system/input_system.h>
 #include <system/rendering_system.h>
 
 namespace testbed {
@@ -35,22 +36,13 @@ void application::draw(entt::registry &registry, const context &context) const {
     SDL_RenderPresent(context);
 }
 
-void application::input() {
+void application::input(entt::registry &registry) {
     ImGuiIO &io = ImGui::GetIO();
     SDL_Event event{};
 
     while(SDL_PollEvent(&event)) {
         ImGui_ImplSDL3_ProcessEvent(&event);
-
-        switch(event.type) {
-        case SDL_EVENT_KEY_DOWN:
-            switch(event.key.key) {
-            case SDLK_ESCAPE:
-                quit = true;
-                break;
-            }
-            break;
-        }
+        input_system(registry, event, quit);
     }
 }
 
@@ -81,7 +73,7 @@ int application::run() {
     while(!quit) {
         update(registry);
         draw(registry, context);
-        input();
+        input(registry);
     }
 
     return 0;

+ 1 - 1
testbed/application/application.h

@@ -13,7 +13,7 @@ struct context;
 class application {
     void update(entt::registry &);
     void draw(entt::registry &, const context &) const;
-    void input();
+    void input(entt::registry &);
 
 public:
     application();

+ 22 - 0
testbed/system/input_system.cpp

@@ -0,0 +1,22 @@
+#include <application/context.h>
+#include <entt/entity/registry.hpp>
+#include <system/input_system.h>
+
+namespace testbed {
+
+void input_system(entt::registry &registry, const SDL_Event &event, bool &quit) {
+    switch(event.type) {
+    case SDL_EVENT_QUIT:
+        quit = true;
+        break;
+    case SDL_EVENT_KEY_DOWN:
+        switch(event.key.key) {
+        case SDLK_ESCAPE:
+            quit = true;
+            break;
+        }
+        break;
+    }
+}
+
+} // namespace testbed

+ 10 - 0
testbed/system/input_system.h

@@ -0,0 +1,10 @@
+#pragma once
+
+#include <SDL3/SDL_events.h>
+#include <entt/entity/fwd.hpp>
+
+namespace testbed {
+
+void input_system(entt::registry &, const SDL_Event &, bool &);
+
+} // namespace testbed