From 2bb0428add0200b7e56f6da9a4bc7a1d3e376cdd Mon Sep 17 00:00:00 2001 From: Vsevolod Kremianskii Date: Wed, 28 Oct 2020 10:26:43 +0700 Subject: [PATCH] refactor: Simplify HUD updates Get camera matrices directly from the Game object. --- src/game/game.cpp | 5 ----- src/game/gui/hud.cpp | 6 ++++-- src/game/gui/hud.h | 4 ++-- src/game/gui/selectoverlay.cpp | 6 +++++- src/game/gui/selectoverlay.h | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index c78d4aa3..d6ae9a41 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -376,11 +376,6 @@ void Game::update() { _module->update(dt); } - if (_screen == GameScreen::InGame) { - Camera *camera = _module->area()->getCamera(); - _hud->prepare(camera->sceneNode()->projection(), camera->sceneNode()->view()); - } - _window.update(dt); } diff --git a/src/game/gui/hud.cpp b/src/game/gui/hud.cpp index b4ab9cab..6aec815b 100644 --- a/src/game/gui/hud.cpp +++ b/src/game/gui/hud.cpp @@ -147,7 +147,9 @@ void HUD::load() { hideControl("TB_STEALTH"); } -void HUD::prepare(const glm::mat4 &projection, const glm::mat4 &view) { +void HUD::update(float dt) { + GUI::update(dt); + Party &party = _game->party(); for (int i = 0; i < 3; ++i) { @@ -165,7 +167,7 @@ void HUD::prepare(const glm::mat4 &projection, const glm::mat4 &view) { } } - _select.prepare(projection, view); + _select.update(); } void HUD::render() const { diff --git a/src/game/gui/hud.h b/src/game/gui/hud.h index 3f102002..bddd2038 100644 --- a/src/game/gui/hud.h +++ b/src/game/gui/hud.h @@ -34,9 +34,9 @@ public: HUD(Game *game); void load() override; - void render() const override; - void prepare(const glm::mat4 &projection, const glm::mat4 &view); + void update(float dt) override; + void render() const override; private: Game *_game { nullptr }; diff --git a/src/game/gui/selectoverlay.cpp b/src/game/gui/selectoverlay.cpp index 208f806c..f379ffa6 100644 --- a/src/game/gui/selectoverlay.cpp +++ b/src/game/gui/selectoverlay.cpp @@ -44,10 +44,14 @@ void SelectionOverlay::load() { _friendlyReticle2 = Textures::instance().get("friendlyreticle2", TextureType::GUI); } -void SelectionOverlay::prepare(const glm::mat4 &projection, const glm::mat4 &view) { +void SelectionOverlay::update() { shared_ptr area(_game->module()->area()); ObjectSelector &selector = area->objectSelector(); + Camera *camera = area->getCamera(); + glm::mat4 projection(camera->sceneNode()->projection()); + glm::mat4 view(camera->sceneNode()->view()); + int hilightedObjectId = selector.hilightedObjectId(); if (hilightedObjectId != -1) { _hilightedScreenCoords = area->getSelectableScreenCoords(hilightedObjectId, projection, view); diff --git a/src/game/gui/selectoverlay.h b/src/game/gui/selectoverlay.h index 54e72ddf..fe6530e3 100644 --- a/src/game/gui/selectoverlay.h +++ b/src/game/gui/selectoverlay.h @@ -38,8 +38,8 @@ public: SelectionOverlay(Game *game); void load(); - void prepare(const glm::mat4 &projection, const glm::mat4 &view); + void update(); void render() const; private: