From 491c3dee3441d01af42ceeee32eb778f8f7d06ec Mon Sep 17 00:00:00 2001 From: Alayan <25536748+Alayan-stk-2@users.noreply.github.com> Date: Fri, 10 Nov 2023 19:39:15 +0100 Subject: [PATCH] Fix updateAndTestFinished to use time2ticks Also remove the useless function parameter --- src/items/attachment.cpp | 2 +- src/items/attachment_plugin.hpp | 2 +- src/items/swatter.cpp | 14 +++++++------- src/items/swatter.hpp | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/items/attachment.cpp b/src/items/attachment.cpp index 7b99d568c..739432556 100644 --- a/src/items/attachment.cpp +++ b/src/items/attachment.cpp @@ -472,7 +472,7 @@ void Attachment::update(int ticks) if (m_plugin) { - if (m_plugin->updateAndTestFinished(ticks)) + if (m_plugin->updateAndTestFinished()) { clear(); // also removes the plugin return; diff --git a/src/items/attachment_plugin.hpp b/src/items/attachment_plugin.hpp index c9f1e0b1c..24611013b 100644 --- a/src/items/attachment_plugin.hpp +++ b/src/items/attachment_plugin.hpp @@ -57,7 +57,7 @@ public: // ------------------------------------------------------------------------ /** Updates a plugin. This is called once each time frame. If the * function returns true, the attachment is discarded. */ - virtual bool updateAndTestFinished(int ticks) = 0; + virtual bool updateAndTestFinished() = 0; // ------------------------------------------------------------------------ virtual void restoreState(BareNetworkString *buffer) {} // ------------------------------------------------------------------------ diff --git a/src/items/swatter.cpp b/src/items/swatter.cpp index c6bab3cf6..e6562fc69 100644 --- a/src/items/swatter.cpp +++ b/src/items/swatter.cpp @@ -231,7 +231,7 @@ void Swatter::updateGraphics(float dt) * \param ticks Time step size. * \return True if the attachment should be discarded. */ -bool Swatter::updateAndTestFinished(int ticks) +bool Swatter::updateAndTestFinished() { const int ticks_start = World::getWorld()->getTicksSinceStart(); 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 // to make sure all clients know the existence of swatter each other - if (m_swatter_duration - m_attachment->getTicksLeft() < 60 || - m_attachment->getTicksLeft() < 90) // ~20 and ~60 below + if (m_swatter_duration - m_attachment->getTicksLeft() < stk_config->time2Ticks(0.5f) || + m_attachment->getTicksLeft() < stk_config->time2Ticks(0.75f) ) // ~0.167f and ~0.5f below return false; chooseTarget(); @@ -278,7 +278,7 @@ bool Swatter::updateAndTestFinished(int ticks) // Start squashing m_animation_phase = SWATTER_TO_TARGET; m_swatter_animation_ticks = - m_attachment->getTicksLeft() - 20; + m_attachment->getTicksLeft() - stk_config->time2Ticks(0.167f); } } break; @@ -286,13 +286,13 @@ bool Swatter::updateAndTestFinished(int ticks) { // Did we just finish the first part of the movement? 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 // change the current phase squashThingsAround(); 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() || RaceManager::get()->isSoccerMode()) { @@ -302,7 +302,7 @@ bool Swatter::updateAndTestFinished(int ticks) m_discard_ticks = end_ticks; } m_swatter_animation_ticks = - m_attachment->getTicksLeft() - 60; + m_attachment->getTicksLeft() - stk_config->time2Ticks(0.5f); } } break; diff --git a/src/items/swatter.hpp b/src/items/swatter.hpp index 759e9c813..d52cb46fc 100644 --- a/src/items/swatter.hpp +++ b/src/items/swatter.hpp @@ -98,7 +98,7 @@ public: Attachment* attachment); virtual ~Swatter(); 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