Files
fall-fever/apps/flecs-test/main.cpp
2025-04-14 23:15:00 +02:00

38 lines
1.2 KiB
C++

#include <input/input.h>
#include <window/window.h>
#include <flecs.h>
#include <iostream>
#include <GLFW/glfw3.h>
int main()
{
flecs::world world;
world.import<WindowModule>();
spawn_window(world);
auto window = world.singleton<Window>();
auto glfw_window = window.get<std::shared_ptr<GLFWwindow>>();
window.observe<Input::KeyInput>([window](Input::KeyInput& key_input) {
auto* key_state = window.get_mut<Input::State<Input::KeyCode>>();
if (key_input.action == static_cast<Input::Action>(GLFW_PRESS)) {
key_state->press(key_input.key_code);
} else if (key_input.action == static_cast<Input::Action>(GLFW_RELEASE)) {
key_state->release(key_input.key_code);
}
});
while (glfwWindowShouldClose(glfw_window->get()) == GLFW_FALSE) {
glfwPollEvents();
// X just pressed
auto* keycode= window.get<Input::State<Input::KeyCode>>();
if (keycode->just_pressed(Input::KeyCode{GLFW_KEY_X}))
std::cout << "X was just pressed!\n";
Input::State<Input::KeyCode>::update_state(window);
glfwSwapBuffers(glfw_window->get());
}
}