From 6e36c223b9f67b27f9bfdfc443fb5fa1da39cb31 Mon Sep 17 00:00:00 2001 From: Flakebi Date: Mon, 23 Nov 2015 01:19:00 +0100 Subject: [PATCH] Hold one kart properties object per player --- src/karts/abstract_kart.cpp | 5 +++-- src/karts/abstract_kart.hpp | 7 ++----- src/karts/kart.cpp | 2 +- src/karts/kart_properties.cpp | 35 +++++++++++++++++++++++------------ src/karts/kart_properties.hpp | 6 ++++-- 5 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/karts/abstract_kart.cpp b/src/karts/abstract_kart.cpp index e3ed8e993..e8e9044b1 100644 --- a/src/karts/abstract_kart.cpp +++ b/src/karts/abstract_kart.cpp @@ -41,10 +41,11 @@ AbstractKart::AbstractKart(const std::string& ident, : Moveable() { m_world_kart_id = world_kart_id; - m_kart_properties = kart_properties_manager->getKart(ident); + m_kart_properties.reset(new KartProperties()); + m_kart_properties->copyForPlayer(kart_properties_manager->getKart(ident)); m_difficulty = difficulty; m_kart_animation = NULL; - assert(m_kart_properties != NULL); + assert(m_kart_properties); // We have to take a copy of the kart model, since otherwise // the animations will be mixed up (i.e. different instances of diff --git a/src/karts/abstract_kart.hpp b/src/karts/abstract_kart.hpp index 78c6187a4..516c87200 100644 --- a/src/karts/abstract_kart.hpp +++ b/src/karts/abstract_kart.hpp @@ -74,7 +74,7 @@ private: protected: /** The kart properties. */ - const KartProperties *m_kart_properties; + std::unique_ptr m_kart_properties; /** The per-player difficulty. */ PerPlayerDifficulty m_difficulty; @@ -128,10 +128,7 @@ public: // ------------------------------------------------------------------------ /** Returns the kart properties of this kart. */ const KartProperties* getKartProperties() const - { return m_kart_properties; } - // ------------------------------------------------------------------------ - /** Sets the kart properties. */ - void setKartProperties(const KartProperties *kp) { m_kart_properties=kp; } + { return m_kart_properties.get(); } // ------------------------------------------------------------------------ /** Returns the characteristics of this kart. */ const AbstractCharacteristic* getCharacteristic() const; diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 4ea131bf0..9ab4f1888 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -2455,7 +2455,7 @@ void Kart::loadData(RaceManager::KartType type, bool is_animated_model) if (!CVS->supportsShadows()) { - m_shadow = new Shadow(m_kart_properties, m_node, + m_shadow = new Shadow(m_kart_properties.get(), m_node, -m_kart_model->getLowestPoint()); } World::getWorld()->kartAdded(this, m_node); diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index cb9af29f6..882ab7854 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -94,14 +94,12 @@ KartProperties::KartProperties(const std::string &filename) // The default constructor for stk_config uses filename="" if (filename != "") { - for(unsigned int i=0; im_ai_properties[i]; } @@ -337,7 +348,7 @@ void KartProperties::getAllData(const XMLNode * root) root->get("shadow-x-offset", &m_shadow_x_offset ); root->get("shadow-z-offset", &m_shadow_z_offset ); - root->get("type", &m_kart_type ); + root->get("type", &m_kart_type ); if(const XMLNode *dimensions_node = root->getNode("center")) dimensions_node->get("gravity-shift", &m_gravity_center_shift); diff --git a/src/karts/kart_properties.hpp b/src/karts/kart_properties.hpp index dbd54747d..604feb6a2 100644 --- a/src/karts/kart_properties.hpp +++ b/src/karts/kart_properties.hpp @@ -19,6 +19,7 @@ #ifndef HEADER_KART_PROPERTIES_HPP #define HEADER_KART_PROPERTIES_HPP +#include #include #include @@ -63,7 +64,7 @@ private: * reduce dependencies (and therefore compile time) when changing * any AI property. There is one separate object for each * difficulty. */ - AIProperties *m_ai_properties[RaceManager::DIFFICULTY_COUNT]; + std::shared_ptr m_ai_properties[RaceManager::DIFFICULTY_COUNT]; /** The absolute path of the icon texture to use. */ Material *m_icon_material; @@ -212,6 +213,7 @@ public: KartProperties (const std::string &filename=""); ~KartProperties (); + void copyForPlayer (const KartProperties *source); void copyFrom (const KartProperties *source); void getAllData (const XMLNode * root); void checkAllSet (const std::string &filename); @@ -373,7 +375,7 @@ public: /** Returns a pointer to the AI properties. */ const AIProperties *getAIPropertiesForDifficulty() const { - return m_ai_properties[race_manager->getDifficulty()]; + return m_ai_properties[race_manager->getDifficulty()].get(); } // getAIProperties // ------------------------------------------------------------------------