testbed: prepare input system
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 ®istry, const context &context) const {
|
||||
SDL_RenderPresent(context);
|
||||
}
|
||||
|
||||
void application::input() {
|
||||
void application::input(entt::registry ®istry) {
|
||||
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;
|
||||
|
||||
@@ -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
testbed/system/input_system.cpp
Normal file
22
testbed/system/input_system.cpp
Normal 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 ®istry, 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
testbed/system/input_system.h
Normal file
10
testbed/system/input_system.h
Normal 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
|
||||
Reference in New Issue
Block a user