start with input
This commit is contained in:
38
apps/flecs-test/main.cpp
Normal file
38
apps/flecs-test/main.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <input/input.h>
|
||||
#include <window/window.h>
|
||||
#include <flecs.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
glfwInit();
|
||||
|
||||
flecs::world world;
|
||||
flecs::entity window_entity = world.entity();
|
||||
window_entity.add<Input::State<Input::KeyCode>>();
|
||||
Window window(&world, window_entity);
|
||||
|
||||
window_entity.observe<Input::KeyInput>([window_entity](Input::KeyInput& key_input) {
|
||||
auto* key_state = window_entity.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(&window.handle()) == GLFW_FALSE) {
|
||||
glfwPollEvents();
|
||||
|
||||
// X just pressed
|
||||
auto* keycode= window_entity.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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user