From 97e5e63e7ca4cc6640b4c9ce9879238237c1441c Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 28 Sep 2018 19:27:05 +0800 Subject: [PATCH] Split plunger drawing in race GUI to update graphics Avoid overwriting the values by rewind --- src/karts/abstract_kart.hpp | 2 ++ src/karts/kart.cpp | 18 +++++++++++++++++- src/karts/kart.hpp | 6 ++++++ src/states_screens/race_gui_base.cpp | 6 +++--- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/karts/abstract_kart.hpp b/src/karts/abstract_kart.hpp index dc0725aa7..de7a572d5 100644 --- a/src/karts/abstract_kart.hpp +++ b/src/karts/abstract_kart.hpp @@ -261,6 +261,8 @@ public: /** Returns true if the kart has a plunger attached to its face. */ virtual int getBlockedByPlungerTicks() const = 0; // ------------------------------------------------------------------------ + virtual float getGraphicalViewBlockedByPlunger() const = 0; + // ------------------------------------------------------------------------ /** Sets that the view is blocked by a plunger. The duration depends on * the difficulty, see KartPorperties getPlungerInFaceTime. */ virtual void blockViewWithPlunger() = 0; diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index f9a26fa12..6fe256776 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -185,7 +185,7 @@ Kart::Kart (const std::string& ident, unsigned int world_kart_id, m_terrain_sound = NULL; m_last_sound_material = NULL; m_previous_terrain_sound = NULL; - + m_graphical_view_blocked_by_plunger = 0.0f; } // Kart // ----------------------------------------------------------------------------- @@ -370,6 +370,7 @@ void Kart::reset() m_current_lean = 0.0f; m_falling_time = 0.0f; m_view_blocked_by_plunger = 0; + m_graphical_view_blocked_by_plunger = 0.0f; m_has_caught_nolok_bubblegum = false; m_is_jumping = false; m_flying = false; @@ -590,8 +591,15 @@ void Kart::blockViewWithPlunger() { // Avoid that a plunger extends the plunger time if(m_view_blocked_by_plunger<=0 && !isShielded()) + { m_view_blocked_by_plunger = stk_config->time2Ticks(m_kart_properties->getPlungerInFaceTime()); + if (m_graphical_view_blocked_by_plunger == 0.0f) + { + m_graphical_view_blocked_by_plunger = + m_kart_properties->getPlungerInFaceTime(); + } + } if(isShielded()) { decreaseShieldTime(); @@ -1434,7 +1442,10 @@ void Kart::update(int ticks) if(m_view_blocked_by_plunger > 0) m_view_blocked_by_plunger -= ticks; //unblock the view if kart just became shielded if(isShielded()) + { m_view_blocked_by_plunger = 0; + m_graphical_view_blocked_by_plunger = 0.0f; + } // Decrease remaining invulnerability time if(m_invulnerable_ticks>0) { @@ -1674,6 +1685,7 @@ void Kart::update(int ticks) if (emergency) { m_view_blocked_by_plunger = 0; + m_graphical_view_blocked_by_plunger = 0.0f; if (m_flying) { stopFlying(); @@ -3050,6 +3062,10 @@ void Kart::updateGraphics(float dt) unsetSquash(); } } // if squashed + if (m_graphical_view_blocked_by_plunger > 0.0f) + m_graphical_view_blocked_by_plunger -= dt; + if (m_graphical_view_blocked_by_plunger < 0.0f) + m_graphical_view_blocked_by_plunger = 0.0f; #endif for (int i = 0; i < EMITTER_COUNT; i++) diff --git a/src/karts/kart.hpp b/src/karts/kart.hpp index 8b74ec36f..21143fbed 100644 --- a/src/karts/kart.hpp +++ b/src/karts/kart.hpp @@ -223,6 +223,9 @@ protected: /** When a kart has its view blocked by the plunger, this variable will be * > 0 the number it contains is the time left before removing plunger. */ int16_t m_view_blocked_by_plunger; + + float m_graphical_view_blocked_by_plunger; + /** The current speed (i.e. length of velocity vector) of this kart. */ float m_speed; @@ -394,6 +397,9 @@ public: virtual int getBlockedByPlungerTicks() const OVERRIDE { return m_view_blocked_by_plunger; } // ------------------------------------------------------------------------ + virtual float getGraphicalViewBlockedByPlunger() const OVERRIDE + { return m_graphical_view_blocked_by_plunger; } + // ------------------------------------------------------------------------ /** Sets that the view is blocked by a plunger. The duration depends on * the difficulty, see KartPorperties getPlungerInFaceTime. */ virtual void blockViewWithPlunger() OVERRIDE; diff --git a/src/states_screens/race_gui_base.cpp b/src/states_screens/race_gui_base.cpp index cebbc44f2..2f30d36fc 100644 --- a/src/states_screens/race_gui_base.cpp +++ b/src/states_screens/race_gui_base.cpp @@ -987,7 +987,7 @@ void RaceGUIBase::drawGlobalPlayerIcons(int bottom_margin) } //Plunger - if (kart->getBlockedByPlungerTicks()>0) + if (kart->getGraphicalViewBlockedByPlunger() > 0.0f) { video::ITexture *icon_plunger = powerup_manager->getIcon(PowerupManager::POWERUP_PLUNGER)->getTexture(); @@ -1031,7 +1031,7 @@ void RaceGUIBase::drawPlungerInFace(const Camera *camera, float dt) { #ifndef SERVER_ONLY const AbstractKart *kart = camera->getKart(); - if (kart->getBlockedByPlungerTicks()<=0) + if (kart->getGraphicalViewBlockedByPlunger() <= 0.0f) { m_plunger_state = PLUNGER_STATE_INIT; return; @@ -1056,7 +1056,7 @@ void RaceGUIBase::drawPlungerInFace(const Camera *camera, float dt) if(m_plunger_move_time < dt && m_plunger_state!=PLUNGER_STATE_FAST) { const float fast_time = 0.3f; - if(kart->getBlockedByPlungerTicks()time2Ticks(fast_time)) + if (kart->getGraphicalViewBlockedByPlunger() < fast_time) { // First time we reach faste state: select random target point // at top of screen and set speed accordingly