Fix updateAndTestFinished to use time2ticks

Also remove the useless function parameter
This commit is contained in:
Alayan 2023-11-10 19:39:15 +01:00
parent f5cc8b4bde
commit 491c3dee34
No known key found for this signature in database
4 changed files with 10 additions and 10 deletions

View File

@ -472,7 +472,7 @@ void Attachment::update(int ticks)
if (m_plugin) if (m_plugin)
{ {
if (m_plugin->updateAndTestFinished(ticks)) if (m_plugin->updateAndTestFinished())
{ {
clear(); // also removes the plugin clear(); // also removes the plugin
return; return;

View File

@ -57,7 +57,7 @@ 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 true, the attachment is discarded. */
virtual bool updateAndTestFinished(int ticks) = 0; virtual bool updateAndTestFinished() = 0;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual void restoreState(BareNetworkString *buffer) {} virtual void restoreState(BareNetworkString *buffer) {}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------

View File

@ -231,7 +231,7 @@ void Swatter::updateGraphics(float dt)
* \param ticks Time step size. * \param ticks Time step size.
* \return True if the attachment should be discarded. * \return True if the attachment should be discarded.
*/ */
bool Swatter::updateAndTestFinished(int ticks) bool Swatter::updateAndTestFinished()
{ {
const int ticks_start = World::getWorld()->getTicksSinceStart(); const int ticks_start = World::getWorld()->getTicksSinceStart();
if (World::getWorld()->getTicksSinceStart() > m_discard_ticks) if (World::getWorld()->getTicksSinceStart() > m_discard_ticks)
@ -250,8 +250,8 @@ bool Swatter::updateAndTestFinished(int ticks)
{ {
// Avoid swatter near the start and the end lifetime of swatter // Avoid swatter near the start and the end lifetime of swatter
// 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 (m_swatter_duration - m_attachment->getTicksLeft() < 60 || if (m_swatter_duration - m_attachment->getTicksLeft() < stk_config->time2Ticks(0.5f) ||
m_attachment->getTicksLeft() < 90) // ~20 and ~60 below m_attachment->getTicksLeft() < stk_config->time2Ticks(0.75f) ) // ~0.167f and ~0.5f below
return false; return false;
chooseTarget(); chooseTarget();
@ -278,7 +278,7 @@ bool Swatter::updateAndTestFinished(int ticks)
// Start squashing // Start squashing
m_animation_phase = SWATTER_TO_TARGET; m_animation_phase = SWATTER_TO_TARGET;
m_swatter_animation_ticks = m_swatter_animation_ticks =
m_attachment->getTicksLeft() - 20; m_attachment->getTicksLeft() - stk_config->time2Ticks(0.167f);
} }
} }
break; break;
@ -286,13 +286,13 @@ bool Swatter::updateAndTestFinished(int ticks)
{ {
// Did we just finish the first part of the movement? // Did we just finish the first part of the movement?
if (m_attachment->getTicksLeft() < m_swatter_animation_ticks && if (m_attachment->getTicksLeft() < m_swatter_animation_ticks &&
m_attachment->getTicksLeft() > 60) m_attachment->getTicksLeft() > stk_config->time2Ticks(0.5f))
{ {
// Squash the karts and items around and // Squash the karts and items around and
// change the current phase // change the current phase
squashThingsAround(); squashThingsAround();
m_animation_phase = SWATTER_FROM_TARGET; m_animation_phase = SWATTER_FROM_TARGET;
const int end_ticks = ticks_start + 60; const int end_ticks = ticks_start + stk_config->time2Ticks(0.5f);
if (RaceManager::get()->isBattleMode() || if (RaceManager::get()->isBattleMode() ||
RaceManager::get()->isSoccerMode()) RaceManager::get()->isSoccerMode())
{ {
@ -302,7 +302,7 @@ bool Swatter::updateAndTestFinished(int ticks)
m_discard_ticks = end_ticks; m_discard_ticks = end_ticks;
} }
m_swatter_animation_ticks = m_swatter_animation_ticks =
m_attachment->getTicksLeft() - 60; m_attachment->getTicksLeft() - stk_config->time2Ticks(0.5f);
} }
} }
break; break;

View File

@ -98,7 +98,7 @@ public:
Attachment* attachment); Attachment* attachment);
virtual ~Swatter(); virtual ~Swatter();
void updateGraphics(float dt) OVERRIDE; void updateGraphics(float dt) OVERRIDE;
bool updateAndTestFinished(int ticks) OVERRIDE; bool updateAndTestFinished() 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