Files
fall-fever/apps/flecs-test/main.cpp
2025-04-20 19:36:17 +02:00

65 lines
2.1 KiB
C++

#include <asset/asset_manager.h>
#include <flecs.h>
#include <input/input.h>
#include <log/log.h>
#include <window/window.h>
#include <GLFW/glfw3.h>
#include <iostream>
int main()
{
Log::initialize();
flecs::world world;
world.import <Window::WindowModule>();
world.import <Input::InputModule>();
world.import <Asset::AssetModule>();
Asset::AssetManager manager;
manager.register_asset_type<int>(world);
auto handle0 = manager.load<int>(world, "hi");
auto handle1 = manager.load<int>(world, "hi");
auto handle2 = manager.load<int>(world, "hi2");
#ifndef NDEBUG
world.import <flecs::stats>();
world.set<flecs::Rest>({});
#endif
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);
if (input_mode == GLFW_CURSOR_NORMAL) {
glfwSetInputMode(glfw_window->get(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
} else {
glfwSetInputMode(glfw_window->get(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
}
});
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))) {
e.world().quit();
}
});
world.system("PollEvents").kind(flecs::PreUpdate).run([](flecs::iter&) { glfwPollEvents(); });
world.system<std::shared_ptr<GLFWwindow>>("Render")
.kind(flecs::PostUpdate)
.each([](std::shared_ptr<GLFWwindow>& glfw_window) { glfwSwapBuffers(glfw_window.get()); });
while (world.progress()) {
}
}