From 2fa71b3bf0ca2ee9034583a013a51b46bf54adf9 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 17 Jan 2025 01:44:46 +0300 Subject: [PATCH] feat: players interpolation & add hud.set_allow_pause(...) --- .../scripts/components/player_animator.lua | 2 +- res/modules/internal/stdcomp.lua | 1 + src/frontend/hud.cpp | 30 +++++++--- src/frontend/hud.hpp | 4 ++ src/frontend/screens/LevelScreen.cpp | 3 +- src/graphics/render/Decorator.cpp | 7 ++- src/graphics/render/WorldRenderer.cpp | 3 +- src/graphics/ui/GUI.cpp | 4 +- src/graphics/ui/elements/Menu.cpp | 4 ++ src/graphics/ui/elements/Menu.hpp | 2 + src/logic/LevelController.cpp | 1 + src/logic/PlayerController.cpp | 4 +- .../scripting/lua/libs/lib__skeleton.cpp | 18 ++++++ src/logic/scripting/lua/libs/libhud.cpp | 6 ++ src/logic/scripting/lua/libs/libplayer.cpp | 5 +- src/objects/Entities.cpp | 17 +++++- src/objects/Entities.hpp | 4 ++ src/objects/Player.cpp | 13 ++++ src/objects/Player.hpp | 10 +++- src/objects/rigging.cpp | 28 ++++++--- src/objects/rigging.hpp | 19 ++++-- src/util/Interpolation.hpp | 60 +++++++++++++++++++ src/window/Events.cpp | 18 +++--- src/window/Events.hpp | 6 +- src/window/Window.cpp | 4 +- 25 files changed, 232 insertions(+), 41 deletions(-) create mode 100644 src/util/Interpolation.hpp diff --git a/res/content/base/scripts/components/player_animator.lua b/res/content/base/scripts/components/player_animator.lua index 6419d543..8862c6c2 100644 --- a/res/content/base/scripts/components/player_animator.lua +++ b/res/content/base/scripts/components/player_animator.lua @@ -19,7 +19,7 @@ function on_render() return end - local rx, ry, rz = player.get_rot(pid) + local rx, ry, rz = player.get_rot(pid, true) rig:set_matrix(headIndex, mat4.rotate({1, 0, 0}, ry)) rig:set_matrix(bodyIndex, mat4.rotate({0, 1, 0}, rx)) diff --git a/res/modules/internal/stdcomp.lua b/res/modules/internal/stdcomp.lua index dfa14175..9e208038 100644 --- a/res/modules/internal/stdcomp.lua +++ b/res/modules/internal/stdcomp.lua @@ -49,6 +49,7 @@ local Skeleton = {__index={ set_visible=function(self, i, b) return __skeleton.set_visible(self.eid, i, b) end, get_color=function(self) return __skeleton.get_color(self.eid) end, set_color=function(self, color) return __skeleton.set_color(self.eid, color) end, + set_interpolated=function(self, b) return __skeleton.set_interpolated(self.eid, b) end, }} local function new_Skeleton(eid) diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index ff22523a..d8f95715 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -223,7 +223,8 @@ void Hud::cleanup() { } void Hud::processInput(bool visible) { - if (!Window::isFocused() && !pause && !isInventoryOpen()) { + auto menu = gui.getMenu(); + if (!Window::isFocused() && !menu->hasOpenPage() && !isInventoryOpen()) { setPause(true); } if (!pause && visible && Events::jactive(BIND_HUD_INVENTORY)) { @@ -318,14 +319,13 @@ void Hud::update(bool visible) { if (!visible && inventoryOpen) { closeInventory(); } - if (pause && menu->getCurrent().panel == nullptr) { + if (pause && !menu->hasOpenPage()) { setPause(false); } - if (!gui.isFocusCaught()) { processInput(visible); } - if ((pause || inventoryOpen) == Events::_cursor_locked) { + if ((menu->hasOpenPage() || inventoryOpen) == Events::isCursorLocked()) { Events::toggleCursor(); } @@ -590,7 +590,9 @@ void Hud::draw(const DrawContext& ctx){ const Viewport& viewport = ctx.getViewport(); const uint width = viewport.getWidth(); const uint height = viewport.getHeight(); + auto menu = gui.getMenu(); + darkOverlay->setVisible(menu->hasOpenPage()); updateElementsPosition(viewport); uicamera->setFov(height); @@ -676,19 +678,20 @@ void Hud::setPause(bool pause) { if (this->pause == pause) { return; } - this->pause = pause; + if (allowPause) { + this->pause = pause; + } if (inventoryOpen) { closeInventory(); } const auto& menu = gui.getMenu(); - if (pause) { - menu->setPage("pause"); - } else { + if (menu->hasOpenPage()) { menu->reset(); + } else { + menu->setPage("pause"); } - darkOverlay->setVisible(pause); menu->setVisible(pause); } @@ -721,3 +724,12 @@ void Hud::setDebugCheats(bool flag) { debugPanel->setZIndex(2); gui.add(debugPanel); } + +void Hud::setAllowPause(bool flag) { + if (pause) { + auto menu = gui.getMenu(); + setPause(false); + menu->setPage("pause", true); + } + allowPause = flag; +} diff --git a/src/frontend/hud.hpp b/src/frontend/hud.hpp index 2a537157..07affc66 100644 --- a/src/frontend/hud.hpp +++ b/src/frontend/hud.hpp @@ -113,6 +113,8 @@ class Hud : public util::ObjectsKeeper { bool showContentPanel = true; /// @brief Provide cheat controllers to the debug panel bool allowDebugCheats = true; + /// @brief Allow actual pause + bool allowPause = true; bool debug = false; /// @brief UI element will be dynamicly positioned near to inventory or in screen center std::shared_ptr secondUI; @@ -206,6 +208,8 @@ public: void setDebugCheats(bool flag); + void setAllowPause(bool flag); + static bool showGeneratorMinimap; /// @brief Runtime updating debug visualization texture diff --git a/src/frontend/screens/LevelScreen.cpp b/src/frontend/screens/LevelScreen.cpp index f2933f0b..0dce2bc0 100644 --- a/src/frontend/screens/LevelScreen.cpp +++ b/src/frontend/screens/LevelScreen.cpp @@ -168,8 +168,9 @@ void LevelScreen::updateHotkeys() { void LevelScreen::update(float delta) { gui::GUI* gui = engine.getGUI(); + auto menu = gui->getMenu(); - bool inputLocked = hud->isPause() || + bool inputLocked = menu->hasOpenPage() || hud->isInventoryOpen() || gui->isFocusCaught(); if (!gui->isFocusCaught()) { diff --git a/src/graphics/render/Decorator.cpp b/src/graphics/render/Decorator.cpp index e9fda381..e6331820 100644 --- a/src/graphics/render/Decorator.cpp +++ b/src/graphics/render/Decorator.cpp @@ -12,6 +12,7 @@ #include "window/Camera.hpp" #include "objects/Player.hpp" #include "objects/Players.hpp" +#include "objects/Entities.hpp" #include "logic/LevelController.hpp" #include "util/stringutil.hpp" #include "engine/Engine.hpp" @@ -159,7 +160,11 @@ void Decorator::update(float delta, const Camera& camera) { renderer.texts->remove(textsIter->second); textsIter = playerTexts.erase(textsIter); } else { - note->setPosition(player->getPosition() + glm::vec3(0, 1, 0)); + glm::vec3 position = player->getPosition(); + if (auto entity = level.entities->get(player->getEntity())) { + position = entity->getInterpolatedPosition(); + } + note->setPosition(position + glm::vec3(0, 1, 0)); ++textsIter; } } diff --git a/src/graphics/render/WorldRenderer.cpp b/src/graphics/render/WorldRenderer.cpp index cefb61d5..4d36c286 100644 --- a/src/graphics/render/WorldRenderer.cpp +++ b/src/graphics/render/WorldRenderer.cpp @@ -274,8 +274,9 @@ void WorldRenderer::renderHands( glm::mat4(1.0f), -glm::pi() * 0.5f, glm::vec3(0, 1, 0) ); prevRotation = rotation; + glm::vec3 cameraRotation = player.getRotation(); auto offset = -(camera.position - player.getPosition()); - float angle = glm::radians(player.rotation.x - 90); + float angle = glm::radians(cameraRotation.x - 90); float cos = glm::cos(angle); float sin = glm::sin(angle); diff --git a/src/graphics/ui/GUI.cpp b/src/graphics/ui/GUI.cpp index 4285179e..95d65540 100644 --- a/src/graphics/ui/GUI.cpp +++ b/src/graphics/ui/GUI.cpp @@ -166,7 +166,7 @@ void GUI::actFocused() { focus->keyPressed(key); } - if (!Events::_cursor_locked) { + if (!Events::isCursorLocked()) { if (Events::clicked(mousecode::BUTTON_1) && (Events::jclicked(mousecode::BUTTON_1) || Events::delta.x || Events::delta.y)) { @@ -189,7 +189,7 @@ void GUI::act(float delta, const Viewport& vp) { auto prevfocus = focus; updateTooltip(delta); - if (!Events::_cursor_locked) { + if (!Events::isCursorLocked()) { actMouse(delta); } else { if (hover) { diff --git a/src/graphics/ui/elements/Menu.cpp b/src/graphics/ui/elements/Menu.cpp index 1756baec..da827489 100644 --- a/src/graphics/ui/elements/Menu.cpp +++ b/src/graphics/ui/elements/Menu.cpp @@ -91,6 +91,10 @@ Page& Menu::getCurrent() { return current; } +bool Menu::hasOpenPage() const { + return current.panel != nullptr; +} + void Menu::clearHistory() { pageStack = std::stack(); } diff --git a/src/graphics/ui/elements/Menu.hpp b/src/graphics/ui/elements/Menu.hpp index a6550907..478c985a 100644 --- a/src/graphics/ui/elements/Menu.hpp +++ b/src/graphics/ui/elements/Menu.hpp @@ -64,5 +64,7 @@ namespace gui { /// @brief Get current page Page& getCurrent(); + + bool hasOpenPage() const; }; } diff --git a/src/logic/LevelController.cpp b/src/logic/LevelController.cpp index 5e537750..f99d7fd6 100644 --- a/src/logic/LevelController.cpp +++ b/src/logic/LevelController.cpp @@ -73,6 +73,7 @@ void LevelController::update(float delta, bool pause) { if (player->isSuspended()) { continue; } + player->rotationInterpolation.updateTimer(delta); player->updateEntity(); glm::vec3 position = player->getPosition(); player->chunks->configure( diff --git a/src/logic/PlayerController.cpp b/src/logic/PlayerController.cpp index eafb2e32..583eee66 100644 --- a/src/logic/PlayerController.cpp +++ b/src/logic/PlayerController.cpp @@ -54,7 +54,7 @@ void CameraControl::refresh() { } void CameraControl::updateMouse(PlayerInput& input) { - glm::vec3& rotation = player.rotation; + glm::vec3 rotation = player.getRotation(); float sensitivity = (input.zoom ? settings.sensitivity.get() / 4.f @@ -75,6 +75,8 @@ void CameraControl::updateMouse(PlayerInput& input) { rotation.x += 360.f; } + player.setRotation(rotation); + camera->rotation = glm::mat4(1.0f); camera->rotate( glm::radians(rotation.y), diff --git a/src/logic/scripting/lua/libs/lib__skeleton.cpp b/src/logic/scripting/lua/libs/lib__skeleton.cpp index 1e0365b7..2cb9c44e 100644 --- a/src/logic/scripting/lua/libs/lib__skeleton.cpp +++ b/src/logic/scripting/lua/libs/lib__skeleton.cpp @@ -130,6 +130,22 @@ static int l_set_color(lua::State* L) { return 0; } +static int l_is_interpolated(lua::State* L) { + if (auto entity = get_entity(L, 1)) { + auto& skeleton = entity->getSkeleton(); + return lua::pushboolean(L, skeleton.interpolation.isEnabled()); + } + return 0; +} + +static int l_set_interpolated(lua::State* L) { + if (auto entity = get_entity(L, 1)) { + auto& skeleton = entity->getSkeleton(); + skeleton.interpolation.setEnabled(lua::toboolean(L, 2)); + } + return 0; +} + const luaL_Reg skeletonlib[] = { {"get_model", lua::wrap}, {"set_model", lua::wrap}, @@ -142,4 +158,6 @@ const luaL_Reg skeletonlib[] = { {"set_visible", lua::wrap}, {"get_color", lua::wrap}, {"set_color", lua::wrap}, + {"is_interpolated", lua::wrap}, + {"set_interpolated", lua::wrap}, {NULL, NULL}}; diff --git a/src/logic/scripting/lua/libs/libhud.cpp b/src/logic/scripting/lua/libs/libhud.cpp index 642121cf..1c4245ba 100644 --- a/src/logic/scripting/lua/libs/libhud.cpp +++ b/src/logic/scripting/lua/libs/libhud.cpp @@ -170,6 +170,11 @@ static int l_set_debug_cheats(lua::State* L) { return 0; } +static int l_set_allow_pause(lua::State* L) { + hud->setAllowPause(lua::toboolean(L, 1)); + return 0; +} + const luaL_Reg hudlib[] = { {"open_inventory", lua::wrap}, {"close_inventory", lua::wrap}, @@ -187,5 +192,6 @@ const luaL_Reg hudlib[] = { {"_is_content_access", lua::wrap}, {"_set_content_access", lua::wrap}, {"_set_debug_cheats", lua::wrap}, + {"set_allow_pause", lua::wrap}, {NULL, NULL} }; diff --git a/src/logic/scripting/lua/libs/libplayer.cpp b/src/logic/scripting/lua/libs/libplayer.cpp index c20d5ee5..12b78a97 100644 --- a/src/logic/scripting/lua/libs/libplayer.cpp +++ b/src/logic/scripting/lua/libs/libplayer.cpp @@ -61,7 +61,7 @@ static int l_set_vel(lua::State* L) { static int l_get_rot(lua::State* L) { if (auto player = get_player(L, 1)) { - return lua::pushvec_stack(L, player->rotation); + return lua::pushvec_stack(L, player->getRotation(lua::toboolean(L, 2))); } return 0; } @@ -71,7 +71,7 @@ static int l_set_rot(lua::State* L) { if (!player) { return 0; } - glm::vec3& rotation = player->rotation; + glm::vec3 rotation = player->getRotation(); auto x = lua::tonumber(L, 2); auto y = lua::tonumber(L, 3); @@ -82,6 +82,7 @@ static int l_set_rot(lua::State* L) { rotation.x = x; rotation.y = y; rotation.z = z; + player->setRotation(rotation); return 0; } diff --git a/src/objects/Entities.cpp b/src/objects/Entities.cpp index 07b76585..32200cf8 100644 --- a/src/objects/Entities.cpp +++ b/src/objects/Entities.cpp @@ -38,6 +38,18 @@ void Transform::refresh() { dirty = false; } +void Entity::setInterpolatedPosition(const glm::vec3& position) { + getSkeleton().interpolation.refresh(position); +} + +glm::vec3 Entity::getInterpolatedPosition() const { + const auto& skeleton = getSkeleton(); + if (skeleton.interpolation.isEnabled()) { + return skeleton.interpolation.getCurrent(); + } + return getTransform().pos; +} + void Entity::destroy() { if (isValid()) { entities.despawn(id); @@ -561,11 +573,14 @@ void Entities::render( if (transform.dirty) { transform.refresh(); } + if (skeleton.interpolation.isEnabled()) { + skeleton.interpolation.updateTimer(delta); + } const auto& pos = transform.pos; const auto& size = transform.size; if (!frustum || frustum->isBoxVisible(pos - size, pos + size)) { const auto* rigConfig = skeleton.config; - rigConfig->render(assets, batch, skeleton, transform.combined); + rigConfig->render(assets, batch, skeleton, transform.combined, pos); } } } diff --git a/src/objects/Entities.hpp b/src/objects/Entities.hpp index 3d183014..6518b599 100644 --- a/src/objects/Entities.hpp +++ b/src/objects/Entities.hpp @@ -170,6 +170,10 @@ public: registry.get(entity).player = id; } + void setInterpolatedPosition(const glm::vec3& position); + + glm::vec3 getInterpolatedPosition() const; + void destroy(); }; diff --git a/src/objects/Player.cpp b/src/objects/Player.cpp index 38fdbc30..777fd8ed 100644 --- a/src/objects/Player.cpp +++ b/src/objects/Player.cpp @@ -181,6 +181,7 @@ void Player::teleport(glm::vec3 position) { if (auto entity = level.entities->get(eid)) { entity->getRigidbody().hitbox.position = position; entity->getTransform().setPos(position); + entity->setInterpolatedPosition(position); } } @@ -296,6 +297,18 @@ glm::vec3 Player::getSpawnPoint() const { return spawnpoint; } +glm::vec3 Player::getRotation(bool interpolated) const { + if (interpolated) { + return rotationInterpolation.getCurrent(); + } + return rotation; +} + +void Player::setRotation(const glm::vec3& rotation) { + this->rotation = rotation; + rotationInterpolation.refresh(rotation); +} + dv::value Player::serialize() const { auto root = dv::object(); diff --git a/src/objects/Player.hpp b/src/objects/Player.hpp index 8caf7a63..b695c75e 100644 --- a/src/objects/Player.hpp +++ b/src/objects/Player.hpp @@ -7,6 +7,7 @@ #include "interfaces/Serializable.hpp" #include "settings.hpp" #include "voxels/voxel.hpp" +#include "util/Interpolation.hpp" class Chunks; class Camera; @@ -55,11 +56,15 @@ class Player : public Serializable { bool loadingChunks = true; entityid_t eid; entityid_t selectedEid = 0; + + glm::vec3 rotation {}; public: + util::VecInterpolation<3, float, true> rotationInterpolation {true}; + std::unique_ptr chunks; std::shared_ptr fpCamera, spCamera, tpCamera; std::shared_ptr currentCamera; - glm::vec3 rotation {}; + CursorSelection selection {}; Player( @@ -123,6 +128,9 @@ public: void setSpawnPoint(glm::vec3 point); glm::vec3 getSpawnPoint() const; + glm::vec3 getRotation(bool interpolated=false) const; + void setRotation(const glm::vec3& rotation); + dv::value serialize() const override; void deserialize(const dv::value& src) override; diff --git a/src/objects/rigging.cpp b/src/objects/rigging.cpp index b08b8441..69ec5ce1 100644 --- a/src/objects/rigging.cpp +++ b/src/objects/rigging.cpp @@ -6,9 +6,8 @@ #include "graphics/commons/Model.hpp" #include "graphics/render/ModelBatch.hpp" -#define GLM_ENABLE_EXPERIMENTAL #include -#include +#include using namespace rigging; @@ -69,7 +68,7 @@ SkeletonConfig::SkeletonConfig( } size_t SkeletonConfig::update( - size_t index, Skeleton& skeleton, Bone* node, glm::mat4 matrix + size_t index, Skeleton& skeleton, Bone* node, const glm::mat4& matrix ) const { auto boneMatrix = skeleton.pose.matrices[index]; auto boneOffset = node->getOffset(); @@ -90,17 +89,32 @@ size_t SkeletonConfig::update( return count; } -void SkeletonConfig::update(Skeleton& skeleton, glm::mat4 matrix) const { - update(0, skeleton, root.get(), matrix); +void SkeletonConfig::update( + Skeleton& skeleton, const glm::mat4& matrix, const glm::vec3& position +) const { + if (skeleton.interpolation.isEnabled()) { + const auto& interpolation = skeleton.interpolation; + glm::vec3 scale, translation, skew; + glm::quat rotation; + glm::vec4 perspective; + glm::decompose(matrix, scale, rotation, translation, skew, perspective); + + auto delta = interpolation.getCurrent() - position; + auto interpolatedMatrix = glm::translate(matrix, delta); + update(0, skeleton, root.get(), interpolatedMatrix); + } else { + update(0, skeleton, root.get(), matrix); + } } void SkeletonConfig::render( const Assets& assets, ModelBatch& batch, Skeleton& skeleton, - const glm::mat4& matrix + const glm::mat4& matrix, + const glm::vec3& position ) const { - update(skeleton, matrix); + update(skeleton, matrix, position); if (!skeleton.visible) { return; diff --git a/src/objects/rigging.hpp b/src/objects/rigging.hpp index de083f9b..2c326a4a 100644 --- a/src/objects/rigging.hpp +++ b/src/objects/rigging.hpp @@ -1,12 +1,15 @@ #pragma once -#include +#define GLM_ENABLE_EXPERIMENTAL +#include #include #include +#include #include #include #include "typedefs.hpp" +#include "util/Interpolation.hpp" class Assets; class ModelBatch; @@ -83,6 +86,8 @@ namespace rigging { bool visible; glm::vec3 tint {1.0f, 1.0f, 1.0f}; + util::VecInterpolation<3, float> interpolation {false}; + Skeleton(const SkeletonConfig* config); }; @@ -100,7 +105,7 @@ namespace rigging { std::vector nodes; size_t update( - size_t index, Skeleton& skeleton, Bone* node, glm::mat4 matrix + size_t index, Skeleton& skeleton, Bone* node, const glm::mat4& matrix ) const; public: SkeletonConfig( @@ -109,12 +114,18 @@ namespace rigging { size_t nodesCount ); - void update(Skeleton& skeleton, glm::mat4 matrix) const; + void update( + Skeleton& skeleton, + const glm::mat4& matrix, + const glm::vec3& position + ) const; + void render( const Assets& assets, ModelBatch& batch, Skeleton& skeleton, - const glm::mat4& matrix + const glm::mat4& matrix, + const glm::vec3& position ) const; Skeleton instance() const { diff --git a/src/util/Interpolation.hpp b/src/util/Interpolation.hpp new file mode 100644 index 00000000..d0f62a00 --- /dev/null +++ b/src/util/Interpolation.hpp @@ -0,0 +1,60 @@ +#pragma once + +#include +#include + +namespace util { + template + class VecInterpolation { + bool enabled; + glm::vec prevPos {std::numeric_limits::quiet_NaN()}; + glm::vec nextPos {}; + T refreshInterval = 0.0; + T timer = 0.0; + T intervalUpdateFactor = 0.1; + public: + VecInterpolation(bool enabled) : enabled(enabled) {} + + void refresh(const glm::vec& position) { + auto current = getCurrent(); + prevPos = current; + nextPos = position; + refreshInterval = timer * intervalUpdateFactor + + refreshInterval * (1.0 - intervalUpdateFactor); + timer = 0.0; + + if constexpr (angular) { + for (int i = 0; i < N; i++) { + T diff = nextPos[i] - prevPos[i]; + if (glm::abs(diff) > 180.0f) { + nextPos[i] += (diff > 0.0f ? -360.0f : 360.0f); + } + } + } + } + + void updateTimer(T delta) { + timer += delta; + } + + glm::vec getCurrent() const { + if (refreshInterval < 0.001 || std::isnan(prevPos.x)) { + return nextPos; + } + T t = timer / refreshInterval; + return nextPos * t + prevPos * (1.0f - t); + } + + T getRefreshInterval() const { + return refreshInterval; + } + + bool isEnabled() const { + return enabled; + } + + void setEnabled(bool enabled) { + this->enabled = enabled; + } + }; +} diff --git a/src/window/Events.cpp b/src/window/Events.cpp index 1652e595..49cdf929 100644 --- a/src/window/Events.cpp +++ b/src/window/Events.cpp @@ -18,8 +18,8 @@ uint Events::currentFrame = 0; int Events::scroll = 0; glm::vec2 Events::delta = {}; glm::vec2 Events::cursor = {}; -bool Events::cursor_drag = false; -bool Events::_cursor_locked = false; +bool Events::cursorDrag = false; +bool Events::cursorLocked = false; std::vector Events::codepoints; std::vector Events::pressedKeys; std::unordered_map Events::bindings; @@ -61,10 +61,10 @@ bool Events::jclicked(int button) { } void Events::toggleCursor() { - cursor_drag = false; - _cursor_locked = !_cursor_locked; + cursorDrag = false; + cursorLocked = !cursorLocked; Window::setCursorMode( - _cursor_locked ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL + cursorLocked ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL ); } @@ -170,11 +170,11 @@ void Events::setButton(int button, bool b) { } void Events::setPosition(float xpos, float ypos) { - if (Events::cursor_drag) { + if (Events::cursorDrag) { Events::delta.x += xpos - Events::cursor.x; Events::delta.y += ypos - Events::cursor.y; } else { - Events::cursor_drag = true; + Events::cursorDrag = true; } Events::cursor.x = xpos; Events::cursor.y = ypos; @@ -249,3 +249,7 @@ void Events::enableBindings() { binding.enable = true; } } + +bool Events::isCursorLocked() { + return cursorLocked; +} diff --git a/src/window/Events.hpp b/src/window/Events.hpp index 67ab111a..92a97ab0 100644 --- a/src/window/Events.hpp +++ b/src/window/Events.hpp @@ -19,12 +19,12 @@ class Events { static bool keys[KEYS_BUFFER_SIZE]; static uint frames[KEYS_BUFFER_SIZE]; static uint currentFrame; - static bool cursor_drag; + static bool cursorDrag; + static bool cursorLocked; public: static int scroll; static glm::vec2 delta; static glm::vec2 cursor; - static bool _cursor_locked; static std::vector codepoints; static std::vector pressedKeys; static std::unordered_map bindings; @@ -65,4 +65,6 @@ public: BindType bindType ); static void enableBindings(); + + static bool isCursorLocked(); }; diff --git a/src/window/Window.cpp b/src/window/Window.cpp index b4361fd0..0c1cccee 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -389,7 +389,9 @@ void Window::toggleFullscreen() { GLFWmonitor* monitor = glfwGetPrimaryMonitor(); const GLFWvidmode* mode = glfwGetVideoMode(monitor); - if (Events::_cursor_locked) Events::toggleCursor(); + if (Events::isCursorLocked()){ + Events::toggleCursor(); + } if (fullscreen) { glfwGetWindowPos(window, &posX, &posY);