Start ECSsing the window

This commit is contained in:
2025-04-14 23:15:00 +02:00
parent 82ddc88246
commit e590203234
6 changed files with 69 additions and 51 deletions

View File

@@ -58,7 +58,7 @@ void Controller::update()
{
Flycam::keyboard_movement(registry());
if (registry().ctx().get<Window::MouseCatched>().catched) {
if (registry().ctx().get<WindowDeprecated::MouseCatched>().catched) {
Flycam::mouse_orientation(registry());
}
}

View File

@@ -7,15 +7,15 @@
int main()
{
glfwInit();
flecs::world world;
flecs::entity window_entity = world.entity();
window_entity.add<Input::State<Input::KeyCode>>();
Window window(&world, window_entity);
world.import<WindowModule>();
spawn_window(world);
auto window = world.singleton<Window>();
auto glfw_window = window.get<std::shared_ptr<GLFWwindow>>();
window_entity.observe<Input::KeyInput>([window_entity](Input::KeyInput& key_input) {
auto* key_state = window_entity.get_mut<Input::State<Input::KeyCode>>();
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);
@@ -24,15 +24,15 @@ int main()
}
});
while (glfwWindowShouldClose(&window.handle()) == GLFW_FALSE) {
while (glfwWindowShouldClose(glfw_window->get()) == GLFW_FALSE) {
glfwPollEvents();
// X just pressed
auto* keycode= window_entity.get<Input::State<Input::KeyCode>>();
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_entity);
glfwSwapBuffers(&window.handle());
Input::State<Input::KeyCode>::update_state(window);
glfwSwapBuffers(glfw_window->get());
}
}