testbed: prepare input system

This commit is contained in:
skypjack
2025-04-28 17:01:53 +02:00
parent b0afed4bd0
commit f505050391
5 changed files with 38 additions and 13 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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();

View File

@@ -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

View File

@@ -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