From ab528e2840297c25985bfa87349f994c0af0ce24 Mon Sep 17 00:00:00 2001 From: Benau Date: Thu, 12 Jul 2018 12:41:06 +0800 Subject: [PATCH] Add a unique identity to each rewinder --- src/items/network_item_manager.cpp | 2 +- src/karts/kart_rewinder.cpp | 8 +++++--- src/network/rewind_manager.cpp | 3 --- src/network/rewind_queue.cpp | 2 +- src/network/rewinder.cpp | 3 ++- src/network/rewinder.hpp | 10 ++++++++-- src/physics/physical_object.cpp | 5 ++++- 7 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/items/network_item_manager.cpp b/src/items/network_item_manager.cpp index 26fb7f843..f6688f86f 100644 --- a/src/items/network_item_manager.cpp +++ b/src/items/network_item_manager.cpp @@ -39,7 +39,7 @@ void NetworkItemManager::create() /** Creates a new instance of the item manager. This is done at startup * of each race. */ NetworkItemManager::NetworkItemManager() - : Rewinder(/*can be deleted*/false), + : Rewinder("nim", /*can be deleted*/false), ItemManager() { m_last_confirmed_item_ticks.clear(); diff --git a/src/karts/kart_rewinder.cpp b/src/karts/kart_rewinder.cpp index 1df38c645..7fe3df980 100644 --- a/src/karts/kart_rewinder.cpp +++ b/src/karts/kart_rewinder.cpp @@ -33,11 +33,13 @@ #include -KartRewinder::KartRewinder(const std::string& ident,unsigned int world_kart_id, - int position, const btTransform& init_transform, +KartRewinder::KartRewinder(const std::string& ident, + unsigned int world_kart_id, int position, + const btTransform& init_transform, PerPlayerDifficulty difficulty, std::shared_ptr ri) - : Rewinder(/*can_be_destroyed*/ false) + : Rewinder(ident + StringUtils::toString(world_kart_id), + /*can_be_destroyed*/ false) , Kart(ident, world_kart_id, position, init_transform, difficulty, ri) { diff --git a/src/network/rewind_manager.cpp b/src/network/rewind_manager.cpp index f6fc3fa8b..9ed449f4d 100644 --- a/src/network/rewind_manager.cpp +++ b/src/network/rewind_manager.cpp @@ -214,11 +214,8 @@ void RewindManager::update(int ticks_not_used) m_not_rewound_ticks.store(ticks, std::memory_order_relaxed); - // Clients don't save state, so they just exit. if (ticks - m_last_saved_state < m_state_frequency) - { return; - } // Save state if (NetworkConfig::get()->isClient()) diff --git a/src/network/rewind_queue.cpp b/src/network/rewind_queue.cpp index e0e7a021c..1e61b2930 100644 --- a/src/network/rewind_queue.cpp +++ b/src/network/rewind_queue.cpp @@ -417,7 +417,7 @@ void RewindQueue::unitTesting() virtual void rewind(BareNetworkString *s) {} virtual void saveTransform() {} virtual void computeError() {} - DummyRewinder() : Rewinder(true) {} + DummyRewinder() : Rewinder("", true) {} }; DummyRewinder *dummy_rewinder = new DummyRewinder(); diff --git a/src/network/rewinder.cpp b/src/network/rewinder.cpp index 08812f39e..6c55c759b 100644 --- a/src/network/rewinder.cpp +++ b/src/network/rewinder.cpp @@ -23,7 +23,8 @@ /** Constructor. It will add this object to the list of all rewindable * objects in the rewind manager. */ -Rewinder::Rewinder(bool can_be_destroyed, bool auto_add) +Rewinder::Rewinder(const std::string& ui, bool can_be_destroyed, bool auto_add) + : m_unique_identity(ui) { m_can_be_destroyed = can_be_destroyed; if (auto_add) diff --git a/src/network/rewinder.hpp b/src/network/rewinder.hpp index 3a74cb682..89c620265 100644 --- a/src/network/rewinder.hpp +++ b/src/network/rewinder.hpp @@ -19,6 +19,7 @@ #ifndef HEADER_REWINDER_HPP #define HEADER_REWINDER_HPP +#include #include class BareNetworkString; @@ -28,6 +29,8 @@ class Rewinder protected: void add(); private: + const std::string m_unique_identity; + /** True if this object can be destroyed, i.e. if this object is a 'stand * alone' (i.e. not used in inheritance). If the object is used in * inheritance (e.g. KartRewinder, which is a Rewinder and Kart), then @@ -36,7 +39,8 @@ private: bool m_can_be_destroyed; public: - Rewinder(bool can_be_destroyed, bool auto_add = true); + Rewinder(const std::string& ui, bool can_be_destroyed, + bool auto_add = true); virtual ~Rewinder(); /** Called before a rewind. Is used to save the previous position of an @@ -86,7 +90,9 @@ public: bool canBeDestroyed() const { return m_can_be_destroyed; } // ------------------------------------------------------------------------- virtual std::function getLocalStateRestoreFunction() - { return nullptr; } + { return nullptr; } + // ------------------------------------------------------------------------- + const std::string& getUniqueIdentity() const { return m_unique_identity; } }; // Rewinder #endif diff --git a/src/physics/physical_object.cpp b/src/physics/physical_object.cpp index 76245be48..3cd207c75 100644 --- a/src/physics/physical_object.cpp +++ b/src/physics/physical_object.cpp @@ -135,7 +135,10 @@ PhysicalObject* PhysicalObject::fromXML(bool is_dynamic, PhysicalObject::PhysicalObject(bool is_dynamic, const PhysicalObject::Settings& settings, TrackObject* object) - : Rewinder(false/*can_be_destroyed*/, false/*auto_add*/) + : Rewinder(settings.m_id + + (object->getParentLibrary() ? + object->getParentLibrary()->getID() : "") , + false/*can_be_destroyed*/, false/*auto_add*/) { m_shape = NULL; m_body = NULL;