From de579ccda69af2a7cce9913ded6450c6434f4224 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 14 Jun 2021 10:42:50 +0200 Subject: [PATCH] Handling ready buttons --- lib/Ray/sources/Drawables/Texture.cpp | 1 + sources/Component/Lobby/LobbyComponent.hpp | 5 ++++- sources/System/Lobby/LobbySystem.cpp | 22 +++++++++++----------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/Ray/sources/Drawables/Texture.cpp b/lib/Ray/sources/Drawables/Texture.cpp index ae01b881..7a70a459 100644 --- a/lib/Ray/sources/Drawables/Texture.cpp +++ b/lib/Ray/sources/Drawables/Texture.cpp @@ -38,6 +38,7 @@ namespace RAY { return *this; this->_texture = this->_texturesCache.fetch(filename); this->_resourcePath = filename; + this->_dimensions = Vector2(this->_texture->width, this->_texture->height); return *this; } diff --git a/sources/Component/Lobby/LobbyComponent.hpp b/sources/Component/Lobby/LobbyComponent.hpp index 76146d6c..28135c11 100644 --- a/sources/Component/Lobby/LobbyComponent.hpp +++ b/sources/Component/Lobby/LobbyComponent.hpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace BBM { @@ -24,8 +25,10 @@ namespace BBM bool ready = false; //! @brief The entity containing the ready display. WAL::Entity &readyButton; + //! @brief The time of last input that this lobby player has made. + std::chrono::time_point lastInput; - Component * clone(WAL::Entity &entity) const override; + Component *clone(WAL::Entity &entity) const override; //! @brief Create a new lobby component. explicit LobbyComponent(WAL::Entity &entity, int playerID, WAL::Entity &readyButton); diff --git a/sources/System/Lobby/LobbySystem.cpp b/sources/System/Lobby/LobbySystem.cpp index bef333a8..ccc368d9 100644 --- a/sources/System/Lobby/LobbySystem.cpp +++ b/sources/System/Lobby/LobbySystem.cpp @@ -18,6 +18,11 @@ namespace BBM void LobbySystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) { auto &lobby = entity.get(); + + auto lastTick = std::chrono::steady_clock::now(); + if (lastTick - lobby.lastInput < std::chrono::milliseconds(150)) + return; + if (lobby.layout == ControllableComponent::NONE) { for (auto &[_, controller] : this->_wal.getScene()->view()) { if (controller.jump) { @@ -25,27 +30,22 @@ namespace BBM return view.get().layout == controller.layout; })) return; + lobby.lastInput = lastTick; lobby.layout = controller.layout; entity.get().drawable = std::make_shared("assets/player/icons/blue.png"); return; } } } + for (auto &[_, controller] : this->_wal.getScene()->view()) { if (controller.layout == lobby.layout && controller.jump) { lobby.ready = true; - if (lobby.ready) { - auto *texture = dynamic_cast(lobby.readyButton.getComponent().drawable.get()); - if (texture) - texture->use("assets/player/icons/ready.png"); - } + lobby.lastInput = lastTick; + auto *texture = dynamic_cast(lobby.readyButton.getComponent().drawable.get()); + if (texture) + texture->use("assets/player/icons/ready.png"); } } } - - //void LobbySystem::updateEntityConnectedUser(WAL::Entity &entity) - //{ - // RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); - // texture->use("assets/player/icons/blue.png"); - //} } \ No newline at end of file