Run input and rendering in systems
This commit is contained in:
@@ -15,13 +15,15 @@ int main()
|
||||
world.import <Window::WindowModule>();
|
||||
world.import <Input::InputModule>();
|
||||
|
||||
auto window = Window::spawn_window(world);
|
||||
auto glfw_window = window.get<std::shared_ptr<GLFWwindow>>();
|
||||
#ifndef NDEBUG
|
||||
world.import <flecs::stats>();
|
||||
world.set<flecs::Rest>({});
|
||||
#endif
|
||||
|
||||
world.system<Window::Window, Input::ButtonInput<Input::KeyCode> const>().each(
|
||||
[](flecs::entity e,
|
||||
Window::Window,
|
||||
Input::ButtonInput<Input::KeyCode> const& button_input) {
|
||||
world.system<Window::Window, Input::ButtonInput<Input::KeyCode> const>("CatchMouse")
|
||||
.each([](flecs::entity e,
|
||||
Window::Window,
|
||||
Input::ButtonInput<Input::KeyCode> const& button_input) {
|
||||
if (button_input.just_pressed(Input::KeyCode(GLFW_KEY_LEFT_CONTROL))) {
|
||||
auto glfw_window = e.get<std::shared_ptr<GLFWwindow>>();
|
||||
auto input_mode = glfwGetInputMode(glfw_window->get(), GLFW_CURSOR);
|
||||
@@ -34,21 +36,21 @@ int main()
|
||||
}
|
||||
});
|
||||
|
||||
world.system<Window::Window, Input::ButtonInput<Input::KeyCode> const>().each(
|
||||
[](flecs::entity e,
|
||||
Window::Window,
|
||||
Input::ButtonInput<Input::KeyCode> const& button_input) {
|
||||
world.system<Window::Window, Input::ButtonInput<Input::KeyCode> const>("CloseOnEsc")
|
||||
.each([](flecs::entity e,
|
||||
Window::Window,
|
||||
Input::ButtonInput<Input::KeyCode> const& button_input) {
|
||||
if (button_input.just_pressed(Input::KeyCode(GLFW_KEY_ESCAPE))) {
|
||||
auto glfw_window = e.get<std::shared_ptr<GLFWwindow>>();
|
||||
glfwSetWindowShouldClose(glfw_window->get(), GLFW_TRUE);
|
||||
e.world().quit();
|
||||
}
|
||||
});
|
||||
|
||||
while (glfwWindowShouldClose(glfw_window->get()) == GLFW_FALSE) {
|
||||
glfwPollEvents();
|
||||
world.system("PollEvents").kind(flecs::PreUpdate).run([](flecs::iter&) { glfwPollEvents(); });
|
||||
|
||||
world.progress();
|
||||
world.system<std::shared_ptr<GLFWwindow>>("Render")
|
||||
.kind(flecs::PostUpdate)
|
||||
.each([](std::shared_ptr<GLFWwindow>& glfw_window) { glfwSwapBuffers(glfw_window.get()); });
|
||||
|
||||
glfwSwapBuffers(glfw_window->get());
|
||||
while (world.progress()) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user