Split plunger drawing in race GUI to update graphics

Avoid overwriting the values by rewind
This commit is contained in:
Benau 2018-09-28 19:27:05 +08:00
parent 759a1d5a33
commit 97e5e63e7c
4 changed files with 28 additions and 4 deletions

View File

@ -261,6 +261,8 @@ public:
/** Returns true if the kart has a plunger attached to its face. */ /** Returns true if the kart has a plunger attached to its face. */
virtual int getBlockedByPlungerTicks() const = 0; virtual int getBlockedByPlungerTicks() const = 0;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual float getGraphicalViewBlockedByPlunger() const = 0;
// ------------------------------------------------------------------------
/** Sets that the view is blocked by a plunger. The duration depends on /** Sets that the view is blocked by a plunger. The duration depends on
* the difficulty, see KartPorperties getPlungerInFaceTime. */ * the difficulty, see KartPorperties getPlungerInFaceTime. */
virtual void blockViewWithPlunger() = 0; virtual void blockViewWithPlunger() = 0;

View File

@ -185,7 +185,7 @@ Kart::Kart (const std::string& ident, unsigned int world_kart_id,
m_terrain_sound = NULL; m_terrain_sound = NULL;
m_last_sound_material = NULL; m_last_sound_material = NULL;
m_previous_terrain_sound = NULL; m_previous_terrain_sound = NULL;
m_graphical_view_blocked_by_plunger = 0.0f;
} // Kart } // Kart
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -370,6 +370,7 @@ void Kart::reset()
m_current_lean = 0.0f; m_current_lean = 0.0f;
m_falling_time = 0.0f; m_falling_time = 0.0f;
m_view_blocked_by_plunger = 0; m_view_blocked_by_plunger = 0;
m_graphical_view_blocked_by_plunger = 0.0f;
m_has_caught_nolok_bubblegum = false; m_has_caught_nolok_bubblegum = false;
m_is_jumping = false; m_is_jumping = false;
m_flying = false; m_flying = false;
@ -590,8 +591,15 @@ void Kart::blockViewWithPlunger()
{ {
// Avoid that a plunger extends the plunger time // Avoid that a plunger extends the plunger time
if(m_view_blocked_by_plunger<=0 && !isShielded()) if(m_view_blocked_by_plunger<=0 && !isShielded())
{
m_view_blocked_by_plunger = m_view_blocked_by_plunger =
stk_config->time2Ticks(m_kart_properties->getPlungerInFaceTime()); 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()) if(isShielded())
{ {
decreaseShieldTime(); decreaseShieldTime();
@ -1434,7 +1442,10 @@ void Kart::update(int ticks)
if(m_view_blocked_by_plunger > 0) m_view_blocked_by_plunger -= ticks; if(m_view_blocked_by_plunger > 0) m_view_blocked_by_plunger -= ticks;
//unblock the view if kart just became shielded //unblock the view if kart just became shielded
if(isShielded()) if(isShielded())
{
m_view_blocked_by_plunger = 0; m_view_blocked_by_plunger = 0;
m_graphical_view_blocked_by_plunger = 0.0f;
}
// Decrease remaining invulnerability time // Decrease remaining invulnerability time
if(m_invulnerable_ticks>0) if(m_invulnerable_ticks>0)
{ {
@ -1674,6 +1685,7 @@ void Kart::update(int ticks)
if (emergency) if (emergency)
{ {
m_view_blocked_by_plunger = 0; m_view_blocked_by_plunger = 0;
m_graphical_view_blocked_by_plunger = 0.0f;
if (m_flying) if (m_flying)
{ {
stopFlying(); stopFlying();
@ -3050,6 +3062,10 @@ void Kart::updateGraphics(float dt)
unsetSquash(); unsetSquash();
} }
} // if squashed } // 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 #endif
for (int i = 0; i < EMITTER_COUNT; i++) for (int i = 0; i < EMITTER_COUNT; i++)

View File

@ -223,6 +223,9 @@ protected:
/** When a kart has its view blocked by the plunger, this variable will be /** 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. */ * > 0 the number it contains is the time left before removing plunger. */
int16_t m_view_blocked_by_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. */ /** The current speed (i.e. length of velocity vector) of this kart. */
float m_speed; float m_speed;
@ -394,6 +397,9 @@ public:
virtual int getBlockedByPlungerTicks() const OVERRIDE virtual int getBlockedByPlungerTicks() const OVERRIDE
{ return m_view_blocked_by_plunger; } { 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 /** Sets that the view is blocked by a plunger. The duration depends on
* the difficulty, see KartPorperties getPlungerInFaceTime. */ * the difficulty, see KartPorperties getPlungerInFaceTime. */
virtual void blockViewWithPlunger() OVERRIDE; virtual void blockViewWithPlunger() OVERRIDE;

View File

@ -987,7 +987,7 @@ void RaceGUIBase::drawGlobalPlayerIcons(int bottom_margin)
} }
//Plunger //Plunger
if (kart->getBlockedByPlungerTicks()>0) if (kart->getGraphicalViewBlockedByPlunger() > 0.0f)
{ {
video::ITexture *icon_plunger = video::ITexture *icon_plunger =
powerup_manager->getIcon(PowerupManager::POWERUP_PLUNGER)->getTexture(); powerup_manager->getIcon(PowerupManager::POWERUP_PLUNGER)->getTexture();
@ -1031,7 +1031,7 @@ void RaceGUIBase::drawPlungerInFace(const Camera *camera, float dt)
{ {
#ifndef SERVER_ONLY #ifndef SERVER_ONLY
const AbstractKart *kart = camera->getKart(); const AbstractKart *kart = camera->getKart();
if (kart->getBlockedByPlungerTicks()<=0) if (kart->getGraphicalViewBlockedByPlunger() <= 0.0f)
{ {
m_plunger_state = PLUNGER_STATE_INIT; m_plunger_state = PLUNGER_STATE_INIT;
return; 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) if(m_plunger_move_time < dt && m_plunger_state!=PLUNGER_STATE_FAST)
{ {
const float fast_time = 0.3f; const float fast_time = 0.3f;
if(kart->getBlockedByPlungerTicks()<stk_config->time2Ticks(fast_time)) if (kart->getGraphicalViewBlockedByPlunger() < fast_time)
{ {
// First time we reach faste state: select random target point // First time we reach faste state: select random target point
// at top of screen and set speed accordingly // at top of screen and set speed accordingly