Port window and input events to flecs
This commit is contained in:
@@ -17,7 +17,7 @@ void Flycam::keyboard_movement(entt::registry& registry)
|
||||
};
|
||||
|
||||
auto& movement_context = registry.ctx().emplace<KeyboardMovementContext>();
|
||||
auto const& key_state = registry.ctx().get<Input::State<Input::KeyCode>>();
|
||||
auto const& key_state = registry.ctx().get<Input::ButtonInput<Input::KeyCode>>();
|
||||
auto const& delta_time = registry.ctx().get<Time::Delta>();
|
||||
|
||||
auto camera_view =
|
||||
|
||||
@@ -1,38 +1,25 @@
|
||||
#include <input/input.h>
|
||||
#include <window/window.h>
|
||||
#include <flecs.h>
|
||||
#include <input/input.h>
|
||||
#include <iostream>
|
||||
#include <window/window.h>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
flecs::world world;
|
||||
|
||||
world.import<WindowModule>();
|
||||
spawn_window(world);
|
||||
auto window = world.singleton<Window>();
|
||||
|
||||
world.import <Window::WindowModule>();
|
||||
auto window = Window::spawn_window(world);
|
||||
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);
|
||||
}
|
||||
});
|
||||
world.import <Input::InputModule>();
|
||||
|
||||
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";
|
||||
world.progress();
|
||||
|
||||
Input::State<Input::KeyCode>::update_state(window);
|
||||
glfwSwapBuffers(glfw_window->get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user