refactor: Simplify HUD updates

Get camera matrices directly from the Game object.
This commit is contained in:
Vsevolod Kremianskii 2020-10-28 10:26:43 +07:00
parent 8f3af5a5b0
commit 2bb0428add
5 changed files with 12 additions and 11 deletions

View file

@ -376,11 +376,6 @@ void Game::update() {
_module->update(dt); _module->update(dt);
} }
if (_screen == GameScreen::InGame) {
Camera *camera = _module->area()->getCamera();
_hud->prepare(camera->sceneNode()->projection(), camera->sceneNode()->view());
}
_window.update(dt); _window.update(dt);
} }

View file

@ -147,7 +147,9 @@ void HUD::load() {
hideControl("TB_STEALTH"); 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(); Party &party = _game->party();
for (int i = 0; i < 3; ++i) { 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 { void HUD::render() const {

View file

@ -34,9 +34,9 @@ public:
HUD(Game *game); HUD(Game *game);
void load() override; 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: private:
Game *_game { nullptr }; Game *_game { nullptr };

View file

@ -44,10 +44,14 @@ void SelectionOverlay::load() {
_friendlyReticle2 = Textures::instance().get("friendlyreticle2", TextureType::GUI); _friendlyReticle2 = Textures::instance().get("friendlyreticle2", TextureType::GUI);
} }
void SelectionOverlay::prepare(const glm::mat4 &projection, const glm::mat4 &view) { void SelectionOverlay::update() {
shared_ptr<Area> area(_game->module()->area()); shared_ptr<Area> area(_game->module()->area());
ObjectSelector &selector = area->objectSelector(); ObjectSelector &selector = area->objectSelector();
Camera *camera = area->getCamera();
glm::mat4 projection(camera->sceneNode()->projection());
glm::mat4 view(camera->sceneNode()->view());
int hilightedObjectId = selector.hilightedObjectId(); int hilightedObjectId = selector.hilightedObjectId();
if (hilightedObjectId != -1) { if (hilightedObjectId != -1) {
_hilightedScreenCoords = area->getSelectableScreenCoords(hilightedObjectId, projection, view); _hilightedScreenCoords = area->getSelectableScreenCoords(hilightedObjectId, projection, view);

View file

@ -38,8 +38,8 @@ public:
SelectionOverlay(Game *game); SelectionOverlay(Game *game);
void load(); void load();
void prepare(const glm::mat4 &projection, const glm::mat4 &view);
void update();
void render() const; void render() const;
private: private: