From c98c20e6a5ceb3a1a952300d0c60bcbda7bb4f29 Mon Sep 17 00:00:00 2001 From: Benau Date: Tue, 25 Dec 2018 10:02:19 +0800 Subject: [PATCH] Disable smoothing body for network when animation is playing --- src/karts/abstract_kart_animation.cpp | 13 +++++++++++++ src/karts/abstract_kart_animation.hpp | 2 ++ src/network/smooth_network_body.hpp | 2 ++ 3 files changed, 17 insertions(+) diff --git a/src/karts/abstract_kart_animation.cpp b/src/karts/abstract_kart_animation.cpp index 6ccbafa57..e3ac139d2 100644 --- a/src/karts/abstract_kart_animation.cpp +++ b/src/karts/abstract_kart_animation.cpp @@ -51,6 +51,7 @@ AbstractKartAnimation::AbstractKartAnimation(AbstractKart *kart, m_check_created_ticks = std::make_shared(-1); m_confirmed_by_network = false; m_ignore_undo = false; + m_has_smoothing_network_body = false; // Remove previous animation if there is one #ifndef DEBUG // Use this code in non-debug mode to avoid a memory leak (and messed @@ -68,6 +69,11 @@ AbstractKartAnimation::AbstractKartAnimation(AbstractKart *kart, // later). if (kart) { + m_has_smoothing_network_body = + dynamic_cast(kart)->isEnabled(); + // Disable smoothing network body so it doesn't smooth the animation + if (m_has_smoothing_network_body) + dynamic_cast(kart)->setEnable(false); kart->setKartAnimation(this); Physics::getInstance()->removeKart(m_kart); kart->getSkidding()->reset(); @@ -124,6 +130,13 @@ AbstractKartAnimation::~AbstractKartAnimation() Physics::getInstance()->addKart(kart); })); } + if (m_has_smoothing_network_body) + { + dynamic_cast(m_kart)->setEnable(true); + dynamic_cast(m_kart)->reset(); + dynamic_cast(m_kart) + ->setSmoothedTransform(transform); + } } } // ~AbstractKartAnimation diff --git a/src/karts/abstract_kart_animation.hpp b/src/karts/abstract_kart_animation.hpp index f0e79fc57..9574e92b4 100644 --- a/src/karts/abstract_kart_animation.hpp +++ b/src/karts/abstract_kart_animation.hpp @@ -61,6 +61,8 @@ private: bool m_ignore_undo; + bool m_has_smoothing_network_body; + protected: /** A pointer to the kart which is animated by this class. */ AbstractKart *m_kart; diff --git a/src/network/smooth_network_body.hpp b/src/network/smooth_network_body.hpp index e49f36eec..cb9512a45 100644 --- a/src/network/smooth_network_body.hpp +++ b/src/network/smooth_network_body.hpp @@ -88,6 +88,8 @@ public: // ------------------------------------------------------------------------ void setEnable(bool val) { m_enabled = val; } // ------------------------------------------------------------------------ + bool isEnabled() const { return m_enabled; } + // ------------------------------------------------------------------------ void setSmoothRotation(bool val) { m_smooth_rotation = val; } // ------------------------------------------------------------------------ void setAdjustVerticalOffset(bool val) { m_adjust_vertical_offset = val; }