diff --git a/CMakeLists.txt b/CMakeLists.txt index c573287..7f3db6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/lib) add_library(fever_core src/components/transform.cpp - src/core/application.cpp + # src/core/application.cpp src/core/camera.cpp src/core/glad.cpp src/core/graphics/framebuffer.cpp diff --git a/src/core/application.cpp b/src/core/application.cpp index b85050c..1077c46 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -20,7 +20,7 @@ namespace FeverCore { Application::~Application() = default; Application::Application() : - game_window(std::make_shared(event_dispatcher)), + game_window(std::make_shared(&_world)), post_processing_framebuffer(game_window->physical_dimensions()), key_listener{.registry = entt_registry}, cursor_listener{.registry = entt_registry}, @@ -68,7 +68,7 @@ void Application::run() this->update(); - Input::State::update_state(entt_registry); + // Input::State::update_state(entt_registry); Input::reset_mouse_motion(entt_registry); // --- Render and buffer swap --- diff --git a/src/core/application.h b/src/core/application.h index d7259ee..2a051ea 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -2,12 +2,11 @@ #include "core/graphics/framebuffer.h" #include "core/shader.h" -#include "entt/entity/fwd.hpp" -#include "entt/signal/fwd.hpp" #include "input/input.h" #include "scene/gltf_loader.h" #include +#include #include #include @@ -30,8 +29,8 @@ public: auto registry() -> entt::registry& { return entt_registry; } auto registry() const -> entt::registry const& { return entt_registry; } - auto dispatcher() -> entt::dispatcher& { return event_dispatcher; } - auto dispatcher() const -> entt::dispatcher const& { return event_dispatcher; } + auto world() -> flecs::world& { return _world; } + auto world() const -> flecs::world const& { return _world; } void run(); @@ -47,6 +46,7 @@ protected: Framebuffer post_processing_framebuffer; entt::registry entt_registry; + flecs::world _world; entt::dispatcher event_dispatcher{}; Input::KeyListener key_listener; diff --git a/src/input/input.cpp b/src/input/input.cpp index af518f9..79c8e36 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -4,22 +4,22 @@ namespace Input { -void KeyListener::key_event(KeyInput const& key_input_event) -{ - auto& key_state = registry.ctx().get>(); +// void KeyListener::key_event(KeyInput const& key_input_event) +// { +// auto& key_state = registry.ctx().get>(); - if (key_input_event.action == static_cast(GLFW_PRESS)) { - key_state.press(key_input_event.key_code); - } else if (key_input_event.action == static_cast(GLFW_RELEASE)) { - key_state.release(key_input_event.key_code); - } -} +// if (key_input_event.action == static_cast(GLFW_PRESS)) { +// key_state.press(key_input_event.key_code); +// } else if (key_input_event.action == static_cast(GLFW_RELEASE)) { +// key_state.release(key_input_event.key_code); +// } +// } -void CursorListener::cursor_event(MouseMotion const& mouse_motion_event) -{ - auto& mouse_motion = registry.ctx().get(); - mouse_motion.delta += mouse_motion_event.delta; -} +// void CursorListener::cursor_event(MouseMotion const& mouse_motion_event) +// { +// auto& mouse_motion = registry.ctx().get(); +// mouse_motion.delta += mouse_motion_event.delta; +// } void reset_mouse_motion(entt::registry& registry) { @@ -27,11 +27,11 @@ void reset_mouse_motion(entt::registry& registry) mouse_motion = {}; } -template void State::update_state(entt::registry& registry) +template void State::update_state(flecs::entity window_entity) { - auto& state = registry.ctx().get>(); - state.just_pressed_keys.clear(); - state.just_released_keys.clear(); + auto* state = window_entity.get_mut>(); + state->just_pressed_keys.clear(); + state->just_released_keys.clear(); } template class State; diff --git a/src/input/input.h b/src/input/input.h index cb60202..47a09ef 100644 --- a/src/input/input.h +++ b/src/input/input.h @@ -2,6 +2,7 @@ #include "entt/entity/fwd.hpp" #include +#include #include #include #include @@ -34,9 +35,9 @@ public: auto just_pressed(T input) const -> bool { return just_pressed_keys.contains(input); } auto just_released(T input) const -> bool { return just_pressed_keys.contains(input); } - static void update_state(entt::registry& registry); + static void update_state(flecs::entity window_entity); -private: +// private: void press(T input) { if (pressed_keys.insert(input).second) { @@ -59,17 +60,17 @@ private: friend class CursorListener; }; -struct KeyListener -{ - entt::registry& registry; - void key_event(KeyInput const& key_input_event); -}; +// struct KeyListener +// { +// entt::registry& registry; +// void key_event(KeyInput const& key_input_event); +// }; -struct CursorListener -{ - entt::registry& registry; - void cursor_event(MouseMotion const& mouse_motion_event); -}; +// struct CursorListener +// { +// entt::registry& registry; +// void cursor_event(MouseMotion const& mouse_motion_event); +// }; void reset_mouse_motion(entt::registry& registry); diff --git a/src/window/window.cpp b/src/window/window.cpp index 8991a05..84b6b81 100644 --- a/src/window/window.cpp +++ b/src/window/window.cpp @@ -5,12 +5,14 @@ #include #include +#include #include static constexpr unsigned INIT_WINDOW_WIDTH = 1280; static constexpr unsigned INIT_WINDOW_HEIGHT = 720; -Window::Window(entt::dispatcher& event_dispatcher) : event_dispatcher(event_dispatcher) +Window::Window(flecs::world* world, flecs::entity window_entity) : + world(world), window_entity(window_entity) { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); @@ -42,7 +44,7 @@ Window::Window(entt::dispatcher& event_dispatcher) : event_dispatcher(event_disp glfwSetFramebufferSizeCallback(glfw_window.get(), framebuffer_size_callback); init_glad(); - + { int width, height; glfwGetFramebufferSize(glfw_window.get(), &width, &height); @@ -60,7 +62,8 @@ void Window::framebuffer_size_callback(GLFWwindow* glfw_window, int width, int h auto& window = *static_cast(glfwGetWindowUserPointer(glfw_window)); glViewport(0, 0, width, height); - window.event_dispatcher.enqueue(); + // world->event().emit(); + // window.event_dispatcher.enqueue(); } void Window::key_callback(GLFWwindow* glfw_window, @@ -71,28 +74,29 @@ void Window::key_callback(GLFWwindow* glfw_window, { auto& window = *static_cast(glfwGetWindowUserPointer(glfw_window)); - window.event_dispatcher.enqueue( + window.window_entity.emit( Input::KeyInput{.key_code = static_cast(key), .action = static_cast(action)}); } void Window::mouse_cursor_callback(GLFWwindow* glfw_window, double xpos, double ypos) { - auto& window = *static_cast(glfwGetWindowUserPointer(glfw_window)); + // auto* world = static_cast(glfwGetWindowUserPointer(glfw_window)); - glm::vec2 delta{xpos - window.last_cursor_pos.x, ypos - window.last_cursor_pos.y}; + // glm::vec2 delta{xpos - window.last_cursor_pos.x, ypos - window.last_cursor_pos.y}; - window.last_cursor_pos = {xpos, ypos}; - delta *= MOUSE_SENSITIVITY; + // window.last_cursor_pos = {xpos, ypos}; + // delta *= MOUSE_SENSITIVITY; - // Check if this is the first VALID mouse event after window being resized - if (window.first_mouse_input && (delta.x >= std::numeric_limits::epsilon() || - delta.y >= std::numeric_limits::epsilon())) { - window.first_mouse_input = false; - return; - } + // // Check if this is the first VALID mouse event after window being resized + // if (window.first_mouse_input && (delta.x >= std::numeric_limits::epsilon() || + // delta.y >= std::numeric_limits::epsilon())) { + // window.first_mouse_input = false; + // return; + // } - window.event_dispatcher.enqueue(Input::MouseMotion{.delta = delta}); + // TODO remove with flecs + // window.event_dispatcher.enqueue(Input::MouseMotion{.delta = delta}); } auto Window::logical_dimensions() const -> glm::u32vec2 diff --git a/src/window/window.h b/src/window/window.h index 86e8c67..2506f2c 100644 --- a/src/window/window.h +++ b/src/window/window.h @@ -1,10 +1,9 @@ #pragma once #include +#include #include #include -#include -#include class GLFWwindow; @@ -25,7 +24,7 @@ public: struct ResizeEvent {}; - Window(entt::dispatcher& event_dispatcher); + Window(flecs::world* world, flecs::entity window_entity); // TODO: not like this... [[nodiscard]] auto handle() -> GLFWwindow& { return *glfw_window; } [[nodiscard]] auto physical_dimensions() const -> glm::u32vec2; @@ -43,9 +42,10 @@ private: static constexpr float MOUSE_SENSITIVITY = 0.15F; - std::shared_ptr glfw_window; + flecs::world* world; + flecs::entity window_entity; - entt::dispatcher& event_dispatcher; + std::shared_ptr glfw_window; glm::vec2 last_cursor_pos{}; bool first_mouse_input = true; diff --git a/vcpkg.json b/vcpkg.json index 64a598e..cbe0582 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -21,5 +21,5 @@ "fx-gltf", "flecs" ], - "builtin-baseline": "c14d62387153eaa2d720113542dbde2e9754ee71" + "builtin-baseline": "bc994510d2eb11aac7b43b03f67a7751d5bfe0e4" }