Use correct cached characteristics

This commit is contained in:
Flakebi 2015-10-03 20:14:39 +02:00
parent 37ca28e868
commit abc2ae54ea
7 changed files with 27 additions and 49 deletions

View File

@ -340,7 +340,7 @@
<kart-types> <kart-types>
<characteristic name="light"> <characteristic name="light">
<turn radius="0:3.0 10:10.0 25:20.0 45:40.0" <turn radius="0:3.0 10:10.0 25:20.0 45:40.0"
time-full-steer ="0:0.15 0.5:0.15 0.5:0.25 1.0:0.25" time-full-steer="0:0.15 0.5:0.15 0.5:0.25 1.0:0.25"
time-reset-steer="0.1" /> time-reset-steer="0.1" />
<engine power="*0.46" max-speed="*0.92" brake-factor="*1" <engine power="*0.46" max-speed="*0.92" brake-factor="*1"
max-speed-reverse-ratio="*0.77" /> max-speed-reverse-ratio="*0.77" />
@ -358,7 +358,7 @@
</characteristic> </characteristic>
<characteristic name="medium"> <characteristic name="medium">
<turn radius="0:4.5 10:16.0 25:30.0 45:60.0" <turn radius="0:4.5 10:16.0 25:30.0 45:60.0"
time-full-steer ="0:0.17 0.5:0.17 0.5:0.28 1.0:0.28" time-full-steer="0:0.17 0.5:0.17 0.5:0.28 1.0:0.28"
time-reset-steer="0.1" /> time-reset-steer="0.1" />
<engine power="*0.63" max-speed="*1" brake-factor="*0.73" <engine power="*0.63" max-speed="*1" brake-factor="*0.73"
max-speed-reverse-ratio="*0.62" /> max-speed-reverse-ratio="*0.62" />
@ -374,7 +374,7 @@
</characteristic> </characteristic>
<characteristic name="heavy"> <characteristic name="heavy">
<turn radius="0:4.0 10:18.5 25:43.0 45:72.5" <turn radius="0:4.0 10:18.5 25:43.0 45:72.5"
time-full-steer ="0:0.23 0.5:0.23 0.5:0.41 1.0:0.41" time-full-steer="0:0.23 0.5:0.23 0.5:0.41 1.0:0.41"
time-reset-steer="0.1" /> time-reset-steer="0.1" />
<engine power="*1" max-speed="*1" brake-factor="*0.66" <engine power="*1" max-speed="*1" brake-factor="*0.66"
max-speed-reverse-ratio="*1" /> max-speed-reverse-ratio="*1" />

View File

@ -20,6 +20,7 @@
#include "karts/abstract_kart.hpp" #include "karts/abstract_kart.hpp"
#include "items/powerup.hpp" #include "items/powerup.hpp"
#include "karts/cached_characteristic.hpp"
#include "karts/combined_characteristic.hpp" #include "karts/combined_characteristic.hpp"
#include "karts/abstract_kart_animation.hpp" #include "karts/abstract_kart_animation.hpp"
#include "karts/kart_model.hpp" #include "karts/kart_model.hpp"
@ -60,10 +61,10 @@ AbstractKart::AbstractKart(const std::string& ident,
m_wheel_graphics_position = m_kart_model->getWheelsGraphicsPosition(); m_wheel_graphics_position = m_kart_model->getWheelsGraphicsPosition();
// Combine the characteristics for this player // Combine the characteristics for this player
m_characteristic.reset(new CombinedCharacteristic()); m_combined_characteristic.reset(new CombinedCharacteristic());
m_characteristic->addCharacteristic(kart_properties_manager-> m_combined_characteristic->addCharacteristic(kart_properties_manager->
getBaseCharacteristic()); getBaseCharacteristic());
m_characteristic->addCharacteristic(kart_properties_manager-> m_combined_characteristic->addCharacteristic(kart_properties_manager->
getDifficultyCharacteristic(race_manager->getDifficultyAsString( getDifficultyCharacteristic(race_manager->getDifficultyAsString(
race_manager->getDifficulty()))); race_manager->getDifficulty())));
@ -71,12 +72,13 @@ AbstractKart::AbstractKart(const std::string& ident,
const AbstractCharacteristic *characteristic = kart_properties_manager-> const AbstractCharacteristic *characteristic = kart_properties_manager->
getKartTypeCharacteristic(m_kart_properties->getKartType()); getKartTypeCharacteristic(m_kart_properties->getKartType());
if (characteristic) if (characteristic)
m_characteristic->addCharacteristic(characteristic); m_combined_characteristic->addCharacteristic(characteristic);
m_characteristic->addCharacteristic(kart_properties_manager-> m_combined_characteristic->addCharacteristic(kart_properties_manager->
getPlayerCharacteristic(KartProperties::getPerPlayerDifficultyAsString( getPlayerCharacteristic(KartProperties::getPerPlayerDifficultyAsString(
m_difficulty))); m_difficulty)));
m_characteristic->addCharacteristic(m_kart_properties->getCharacteristic()); m_combined_characteristic->addCharacteristic(m_kart_properties->getCharacteristic());
m_characteristic.reset(new CachedCharacteristic(m_combined_characteristic.get()));
} // AbstractKart } // AbstractKart
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -39,6 +39,7 @@ class AbstractKartAnimation;
class Attachment; class Attachment;
class btKart; class btKart;
class btQuaternion; class btQuaternion;
class CachedCharacteristic;
class CombinedCharacteristic; class CombinedCharacteristic;
class Controller; class Controller;
class Item; class Item;
@ -78,7 +79,9 @@ protected:
/** The per-player difficulty. */ /** The per-player difficulty. */
PerPlayerDifficulty m_difficulty; PerPlayerDifficulty m_difficulty;
/** The combined properties of the kart, the player, etc. */ /** The combined properties of the kart, the player, etc. */
std::unique_ptr<CombinedCharacteristic> m_characteristic; std::unique_ptr<CombinedCharacteristic> m_combined_characteristic;
/** The cached combined characteristics. */
std::unique_ptr<CachedCharacteristic> m_characteristic;
/** This stores a copy of the kart model. It has to be a copy /** This stores a copy of the kart model. It has to be a copy
* since otherwise incosistencies can happen if the same kart * since otherwise incosistencies can happen if the same kart

View File

@ -39,7 +39,7 @@
#include "graphics/stars.hpp" #include "graphics/stars.hpp"
#include "guiengine/scalable_font.hpp" #include "guiengine/scalable_font.hpp"
#include "karts/abstract_characteristic.hpp" #include "karts/abstract_characteristic.hpp"
#include "karts/combined_characteristic.hpp" #include "karts/cached_characteristic.hpp"
#include "karts/explosion_animation.hpp" #include "karts/explosion_animation.hpp"
#include "karts/kart_gfx.hpp" #include "karts/kart_gfx.hpp"
#include "karts/rescue_animation.hpp" #include "karts/rescue_animation.hpp"

View File

@ -73,9 +73,6 @@ KartProperties::KartProperties(const std::string &filename)
m_shadow_scale = 1.0f; m_shadow_scale = 1.0f;
m_shadow_x_offset = 0.0f; m_shadow_x_offset = 0.0f;
m_shadow_z_offset = 0.0f; m_shadow_z_offset = 0.0f;
m_characteristic = NULL;
m_combined_characteristic = NULL;
m_cached_characteristic = NULL;
m_groups.clear(); m_groups.clear();
m_custom_sfx_id.resize(SFXManager::NUM_CUSTOMS); m_custom_sfx_id.resize(SFXManager::NUM_CUSTOMS);
@ -118,12 +115,6 @@ KartProperties::~KartProperties()
delete m_kart_model; delete m_kart_model;
if(m_skidding_properties) if(m_skidding_properties)
delete m_skidding_properties; delete m_skidding_properties;
if (m_characteristic)
delete m_characteristic;
if (m_combined_characteristic)
delete m_combined_characteristic;
if (m_cached_characteristic)
delete m_cached_characteristic;
for(unsigned int i=0; i<RaceManager::DIFFICULTY_COUNT; i++) for(unsigned int i=0; i<RaceManager::DIFFICULTY_COUNT; i++)
if(m_ai_properties[i]) if(m_ai_properties[i])
delete m_ai_properties[i]; delete m_ai_properties[i];
@ -148,8 +139,7 @@ void KartProperties::copyFrom(const KartProperties *source)
if (source->m_characteristic) if (source->m_characteristic)
{ {
m_characteristic = new XmlCharacteristic(); m_characteristic.reset(new XmlCharacteristic());
assert(m_characteristic);
*m_characteristic = *source->m_characteristic; *m_characteristic = *source->m_characteristic;
// Combine the characteristics for this object. We can't copy it because // Combine the characteristics for this object. We can't copy it because
// this object has other pointers (to m_characteristic). // this object has other pointers (to m_characteristic).
@ -216,9 +206,7 @@ void KartProperties::load(const std::string &filename, const std::string &node)
throw std::runtime_error(msg.str()); throw std::runtime_error(msg.str());
} }
getAllData(root); getAllData(root);
if (m_characteristic) m_characteristic.reset(new XmlCharacteristic(root));
delete m_characteristic;
m_characteristic = new XmlCharacteristic(root);
combineCharacteristics(); combineCharacteristics();
} }
catch(std::exception& err) catch(std::exception& err)
@ -316,11 +304,7 @@ void KartProperties::load(const std::string &filename, const std::string &node)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void KartProperties::combineCharacteristics() void KartProperties::combineCharacteristics()
{ {
if (m_combined_characteristic) m_combined_characteristic.reset(new CombinedCharacteristic());
delete m_combined_characteristic;
if (m_cached_characteristic)
delete m_cached_characteristic;
m_combined_characteristic = new CombinedCharacteristic();
m_combined_characteristic->addCharacteristic(kart_properties_manager-> m_combined_characteristic->addCharacteristic(kart_properties_manager->
getBaseCharacteristic()); getBaseCharacteristic());
@ -334,8 +318,7 @@ void KartProperties::combineCharacteristics()
// Kart type found // Kart type found
m_combined_characteristic->addCharacteristic(characteristic); m_combined_characteristic->addCharacteristic(characteristic);
m_combined_characteristic->addCharacteristic(m_characteristic); m_combined_characteristic->addCharacteristic(m_characteristic.get());
m_cached_characteristic = new CachedCharacteristic(m_combined_characteristic);
} // combineCharacteristics } // combineCharacteristics
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -531,13 +514,13 @@ bool KartProperties::operator<(const KartProperties &other) const
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
const AbstractCharacteristic* KartProperties::getCharacteristic() const const AbstractCharacteristic* KartProperties::getCharacteristic() const
{ {
return m_characteristic; return m_characteristic.get();
} // getCharacteristic } // getCharacteristic
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
const AbstractCharacteristic* KartProperties::getCombinedCharacteristic() const const AbstractCharacteristic* KartProperties::getCombinedCharacteristic() const
{ {
return m_cached_characteristic; return m_combined_characteristic.get();
} // getCombinedCharacteristic } // getCombinedCharacteristic
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -550,8 +533,8 @@ bool KartProperties::isInGroup(const std::string &group) const
float KartProperties::getAvgPower() const float KartProperties::getAvgPower() const
{ {
float sum = 0; float sum = 0;
std::vector<float> gear_power_increase = m_cached_characteristic->getGearPowerIncrease(); std::vector<float> gear_power_increase = m_combined_characteristic->getGearPowerIncrease();
float power = m_cached_characteristic->getEnginePower(); float power = m_combined_characteristic->getEnginePower();
for (unsigned int i = 0; i < gear_power_increase.size(); ++i) for (unsigned int i = 0; i < gear_power_increase.size(); ++i)
sum += gear_power_increase[i] * power; sum += gear_power_increase[i] * power;
return sum / gear_power_increase.size(); return sum / gear_power_increase.size();

View File

@ -39,7 +39,6 @@ using namespace irr;
class AbstractCharacteristic; class AbstractCharacteristic;
class AIProperties; class AIProperties;
class CachedCharacteristic;
class CombinedCharacteristic; class CombinedCharacteristic;
class Material; class Material;
class SkiddingProperties; class SkiddingProperties;
@ -126,11 +125,9 @@ private:
/** The physical, item, etc. characteristics of this kart that are loaded /** The physical, item, etc. characteristics of this kart that are loaded
* from the xml file. * from the xml file.
*/ */
AbstractCharacteristic *m_characteristic; std::shared_ptr<AbstractCharacteristic> m_characteristic;
/** The base characteristics combined with the characteristics of this kart. */ /** The base characteristics combined with the characteristics of this kart. */
CombinedCharacteristic *m_combined_characteristic; std::shared_ptr<CombinedCharacteristic> m_combined_characteristic;
/** The cached combined characteristics. */
CachedCharacteristic *m_cached_characteristic;
// Physic properties // Physic properties
// ----------------- // -----------------

View File

@ -141,14 +141,6 @@ void XmlCharacteristic::process(CharacteristicType type, Value value,
found = true; found = true;
break; break;
} }
if (!*is_set)
{
Log::error("XmlCharacteristic::process",
"Can't process %s",
pair[1].c_str());
value.fv->clear();
break;
}
} }
if (!found) if (!found)
{ {
@ -168,6 +160,7 @@ void XmlCharacteristic::process(CharacteristicType type, Value value,
if (shouldReplace) if (shouldReplace)
{ {
value.ia->clear();
// Replace all values // Replace all values
for (const std::string &processor : processors) for (const std::string &processor : processors)
{ {