Bugfix: characteristics could not be overwritten in kart.xml files.
First part of #2560.
This commit is contained in:
@@ -227,6 +227,7 @@ public:
|
||||
public:
|
||||
AbstractCharacteristic();
|
||||
virtual ~AbstractCharacteristic() {}
|
||||
virtual void copyFrom(const AbstractCharacteristic *other) = 0;
|
||||
|
||||
/**
|
||||
* The process function is the core of this characteristics system.
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
|
||||
#include "karts/abstract_characteristic.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
class CachedCharacteristic : public AbstractCharacteristic
|
||||
{
|
||||
private:
|
||||
@@ -46,7 +48,7 @@ public:
|
||||
|
||||
/** Fetches all cached values from the original source. */
|
||||
void updateSource();
|
||||
|
||||
virtual void copyFrom(const AbstractCharacteristic *other) { assert(false); }
|
||||
virtual void process(CharacteristicType type, Value value, bool *is_set) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
|
||||
#include "karts/abstract_characteristic.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
class CombinedCharacteristic : public AbstractCharacteristic
|
||||
{
|
||||
private:
|
||||
@@ -32,6 +34,10 @@ public:
|
||||
void addCharacteristic(const AbstractCharacteristic *characteristic);
|
||||
|
||||
virtual void process(CharacteristicType type, Value value, bool *is_set) const;
|
||||
virtual void copyFrom(const AbstractCharacteristic *other)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -125,8 +125,10 @@ void KartProperties::copyForPlayer(const KartProperties *source)
|
||||
// So all pointer variables need to be separately allocated and assigned.
|
||||
if (source->m_characteristic)
|
||||
{
|
||||
// Remove the shared reference by creating a new pointer
|
||||
m_characteristic.reset(new XmlCharacteristic());
|
||||
*m_characteristic = *source->m_characteristic;
|
||||
m_characteristic->copyFrom(source->getCharacteristic());
|
||||
|
||||
// Combine the characteristics for this object. We can't copy it because
|
||||
// this object has other pointers (to m_characteristic).
|
||||
combineCharacteristics();
|
||||
|
||||
@@ -31,6 +31,17 @@ XmlCharacteristic::XmlCharacteristic(const XMLNode *node) :
|
||||
load(node);
|
||||
} // XmlCharacteristic constructor
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Copies the characteristics from the specified other characteristic class
|
||||
* into this class.
|
||||
*/
|
||||
void XmlCharacteristic::copyFrom(const AbstractCharacteristic *other)
|
||||
{
|
||||
const XmlCharacteristic *xc = dynamic_cast<const XmlCharacteristic*>(other);
|
||||
assert(xc!=NULL);
|
||||
m_values = xc->m_values;
|
||||
} // operator=
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** process will execute the operation that is specified in the saved string.
|
||||
* The format of the operations is specified in kart_characteristics.xml.
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
virtual void process(CharacteristicType type, Value value, bool *is_set) const;
|
||||
|
||||
void load(const XMLNode *node);
|
||||
virtual void copyFrom(const AbstractCharacteristic *other);
|
||||
|
||||
private:
|
||||
static void processFloat(const std::string &processor, float *value, bool *is_set);
|
||||
|
||||
Reference in New Issue
Block a user