Restore swatter discard now in arena or soccer in network properly

This commit is contained in:
Benau 2018-09-30 16:10:58 +08:00
parent ab94fdfceb
commit c8db9e2490
4 changed files with 24 additions and 19 deletions

View File

@ -311,8 +311,6 @@ void Attachment::rewindTo(BareNetworkString *buffer)
if (m_type == new_type) if (m_type == new_type)
{ {
setTicksLeft(ticks_left); setTicksLeft(ticks_left);
if (m_type != new_type && new_type != ATTACH_SWATTER)
m_type = new_type;
return; return;
} }
@ -536,13 +534,19 @@ void Attachment::update(int ticks)
m_node->setVisible((division & 0x1) == 0); m_node->setVisible((division & 0x1) == 0);
} }
if(m_plugin) if (m_plugin)
{ {
bool discard = m_plugin->updateAndTestFinished(ticks); int discard_ticks = m_plugin->updateAndTestFinished(ticks);
if(discard) if (discard_ticks != -1)
{ {
clear(); // also removes the plugin // Save it for rewinding
return; m_ticks_left =
discard_ticks - World::getWorld()->getTicksSinceStart();
if (m_ticks_left <= 0)
{
clear(); // also removes the plugin
return;
}
} }
} }

View File

@ -53,8 +53,9 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Updates a plugin. This is called once each time frame. If the /** Updates a plugin. This is called once each time frame. If the
* function returns true, the attachment is discarded. */ * function returns a non-negative number, the attachment is discarded
virtual bool updateAndTestFinished(int ticks) = 0; * when world ticks >= that number. */
virtual int updateAndTestFinished(int ticks) = 0;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Called when the animation of the Attachment's node is done. */ /** Called when the animation of the Attachment's node is done. */

View File

@ -161,20 +161,20 @@ void Swatter::updateGrahpics(float dt)
/** Updates an armed swatter: it checks for any karts that are close enough /** Updates an armed swatter: it checks for any karts that are close enough
* and not invulnerable, it swats the kart. * and not invulnerable, it swats the kart.
* \param dt Time step size. * \param dt Time step size.
* \return True if the attachment should be discarded. * \return World ticks to discard the swatter.
*/ */
bool Swatter::updateAndTestFinished(int ticks) int Swatter::updateAndTestFinished(int ticks)
{ {
const int ticks_start = World::getWorld()->getTicksSinceStart(); const int ticks_start = World::getWorld()->getTicksSinceStart();
if (m_removed_bomb_ticks != std::numeric_limits<int>::max()) if (m_removed_bomb_ticks != std::numeric_limits<int>::max())
{ {
if (ticks_start >= m_removed_bomb_ticks) if (ticks_start >= m_removed_bomb_ticks)
return true; return m_removed_bomb_ticks;
return false; return -1;
} // if removing bomb } // if removing bomb
if (RewindManager::get()->isRewinding()) if (RewindManager::get()->isRewinding())
return false; return -1;
if (!m_discard_now) if (!m_discard_now)
{ {
@ -186,7 +186,7 @@ bool Swatter::updateAndTestFinished(int ticks)
// to make sure all clients know the existence of swatter each other // to make sure all clients know the existence of swatter each other
if (ticks_start - m_swatter_start_ticks < 60 || if (ticks_start - m_swatter_start_ticks < 60 ||
m_swatter_end_ticks - ticks_start < 60) m_swatter_end_ticks - ticks_start < 60)
return false; return -1;
chooseTarget(); chooseTarget();
pointToTarget(); pointToTarget();
@ -258,15 +258,15 @@ bool Swatter::updateAndTestFinished(int ticks)
if (m_discard_now) if (m_discard_now)
{ {
return ticks_start > m_end_swat_ticks; return m_end_swat_ticks;
} }
else if (ticks_start > m_end_swat_ticks) else if (ticks_start > m_end_swat_ticks)
{ {
m_animation_phase = SWATTER_AIMING; m_animation_phase = SWATTER_AIMING;
m_end_swat_ticks = std::numeric_limits<int>::max(); m_end_swat_ticks = std::numeric_limits<int>::max();
return false; return -1;
} }
return false; return -1;
} // updateAndTestFinished } // updateAndTestFinished
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -87,7 +87,7 @@ public:
scene::ISceneNode* bomb_scene_node, int ticks); scene::ISceneNode* bomb_scene_node, int ticks);
virtual ~Swatter(); virtual ~Swatter();
void updateGrahpics(float dt) OVERRIDE; void updateGrahpics(float dt) OVERRIDE;
bool updateAndTestFinished(int ticks) OVERRIDE; int updateAndTestFinished(int ticks) OVERRIDE;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Returns if the swatter is currently aiming, i.e. can be used to /** Returns if the swatter is currently aiming, i.e. can be used to