diff --git a/data/stk_config.xml b/data/stk_config.xml
index f4316a4f3..18d1cb51c 100644
--- a/data/stk_config.xml
+++ b/data/stk_config.xml
@@ -487,7 +487,7 @@
-
+
diff --git a/src/karts/kart_model.cpp b/src/karts/kart_model.cpp
index a2462dfed..e9f69652c 100644
--- a/src/karts/kart_model.cpp
+++ b/src/karts/kart_model.cpp
@@ -38,6 +38,37 @@
float KartModel::UNDEFINED = -99.9f;
+// ------------------------------------------------------------
+// SpeedWeightedObject implementation
+
+#define SPEED_WEIGHTED_OBJECT_PROPERTY_UNDEFINED -99.f
+
+SpeedWeightedObject::Properties::Properties()
+{
+ m_strength_factor = m_speed_factor = m_texture_speed.X = m_texture_speed.Y = SPEED_WEIGHTED_OBJECT_PROPERTY_UNDEFINED;
+}
+
+void SpeedWeightedObject::Properties::loadFromXMLNode(const XMLNode* xml_node)
+{
+ xml_node->get("strength-factor", &m_strength_factor);
+ xml_node->get("speed-factor", &m_speed_factor);
+ xml_node->get("texture-speed-x", &m_texture_speed.X);
+ xml_node->get("texture-speed-y", &m_texture_speed.Y);
+}
+
+void SpeedWeightedObject::Properties::checkAllSet()
+{
+#define CHECK_NEG( a,strA) if(a<=SPEED_WEIGHTED_OBJECT_PROPERTY_UNDEFINED) { \
+ Log::fatal("SpeedWeightedObject", "Missing default value for '%s'.", \
+ strA); \
+ }
+ CHECK_NEG(m_strength_factor, "speed-weighted strength-factor" );
+ CHECK_NEG(m_speed_factor, "speed-weighted speed-factor" );
+ CHECK_NEG(m_texture_speed.X, "speed-weighted texture speed X" );
+ CHECK_NEG(m_texture_speed.Y, "speed-weighted texture speed Y" );
+#undef CHECK_NEG
+}
+
/** Default constructor which initialises all variables with defaults.
* Note that the KartModel is copied, so make sure to update makeCopy
* if any more variables are added to this object.
@@ -148,12 +179,15 @@ void KartModel::loadInfo(const XMLNode &node)
m_has_nitro_emitter = true;
}
- if(const XMLNode *speedWeighted_node=node.getNode("speed-weighted"))
+ if(const XMLNode *speed_weighted_objects_node=node.getNode("speed-weighted-objects"))
{
- for(unsigned int i=0 ; i < speedWeighted_node->getNumNodes() ; i++)
- {
- loadSpeedWeightedInfo(speedWeighted_node->getNode(i));
- }
+ SpeedWeightedObject::Properties fallback_properties;
+ fallback_properties.loadFromXMLNode(speed_weighted_objects_node);
+
+ for(unsigned int i=0 ; i < speed_weighted_objects_node->getNumNodes() ; i++)
+ {
+ loadSpeedWeightedInfo(speed_weighted_objects_node->getNode(i), fallback_properties);
+ }
}
if(const XMLNode *hat_node=node.getNode("hat"))
@@ -279,11 +313,9 @@ KartModel* KartModel::makeCopy()
km->m_speed_weighted_objects.resize(m_speed_weighted_objects.size());
for(size_t i=0; im_speed_weighted_objects[i].m_model = m_speed_weighted_objects[i].m_model;
// Master should not have any speed weighted nodes.
assert(!m_speed_weighted_objects[i].m_node);
- km->m_speed_weighted_objects[i].m_name = m_speed_weighted_objects[i].m_name;
- km->m_speed_weighted_objects[i].m_position = m_speed_weighted_objects[i].m_position;
+ km->m_speed_weighted_objects[i] = m_speed_weighted_objects[i];
}
for(unsigned int i=AF_BEGIN; i<=AF_END; i++)
@@ -511,9 +543,11 @@ void KartModel::loadNitroEmitterInfo(const XMLNode &node,
} // loadNitroEmitterInfo
/** Loads a single speed weighted node. */
-void KartModel::loadSpeedWeightedInfo(const XMLNode* speed_weighted_node)
+void KartModel::loadSpeedWeightedInfo(const XMLNode* speed_weighted_node, const SpeedWeightedObject::Properties& fallback_properties)
{
SpeedWeightedObject obj;
+ obj.m_properties = fallback_properties;
+ obj.m_properties.loadFromXMLNode(speed_weighted_node);
speed_weighted_node->get("position", &obj.m_position);
speed_weighted_node->get("model", &obj.m_name);
@@ -767,9 +801,13 @@ void KartModel::update(float dt, float rotation_dt, float steer, const float sus
{
SpeedWeightedObject& obj = m_speed_weighted_objects[i];
+#define GET_VALUE(obj, value_name) \
+ obj.m_properties.value_name > SPEED_WEIGHTED_OBJECT_PROPERTY_UNDEFINED ? obj.m_properties.value_name : \
+ m_kart->getKartProperties()->getSpeedWeightedObjectProperties().value_name
+
// Animation strength
float strength = 1.0f;
- const float strength_factor = m_kart->getKartProperties()->getSpeedWeightedStrengthFactor();
+ const float strength_factor = GET_VALUE(obj, m_strength_factor);
if(strength_factor >= 0.0f)
{
strength = speed * strength_factor;
@@ -778,7 +816,7 @@ void KartModel::update(float dt, float rotation_dt, float steer, const float sus
obj.m_node->setAnimationStrength(strength);
// Animation speed
- const float speed_factor = m_kart->getKartProperties()->getSpeedWeightedSpeedFactor();
+ const float speed_factor = GET_VALUE(obj, m_speed_factor);
if(speed_factor >= 0.0f)
{
float anim_speed = speed * speed_factor;
@@ -786,7 +824,9 @@ void KartModel::update(float dt, float rotation_dt, float steer, const float sus
}
// Texture animation
- const core::vector2df& tex_speed = m_kart->getKartProperties()->getSpeedWeightedTextureSpeed();
+ core::vector2df tex_speed;
+ tex_speed.X = GET_VALUE(obj, m_texture_speed.X);
+ tex_speed.Y = GET_VALUE(obj, m_texture_speed.Y);
if(tex_speed != core::vector2df(0.0f, 0.0f))
{
obj.m_texture_cur_offset += speed * tex_speed * dt;
@@ -805,6 +845,7 @@ void KartModel::update(float dt, float rotation_dt, float steer, const float sus
} // for j SpeedWeightedObjectList;
@@ -181,7 +205,7 @@ private:
void loadNitroEmitterInfo(const XMLNode &node,
const std::string &emitter_name, int index);
- void loadSpeedWeightedInfo(const XMLNode* speed_weighted_node);
+ void loadSpeedWeightedInfo(const XMLNode* speed_weighted_node, const SpeedWeightedObject::Properties& fallback_properties);
void OnAnimationEnd(scene::IAnimatedMeshSceneNode *node);
diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp
index a06453857..d8e714351 100644
--- a/src/karts/kart_properties.cpp
+++ b/src/karts/kart_properties.cpp
@@ -68,9 +68,7 @@ KartProperties::KartProperties(const std::string &filename)
m_nitro_max_speed_increase = m_nitro_duration = m_nitro_fade_out_time =
m_suspension_stiffness = m_wheel_damping_relaxation = m_wheel_base =
m_wheel_damping_compression = m_friction_slip = m_roll_influence =
- m_wheel_radius = m_speed_weighted_strength_factor = m_speed_weighted_speed_factor =
- m_speed_weighted_texture_speed.X = m_speed_weighted_texture_speed.Y =
- m_chassis_linear_damping = m_max_suspension_force =
+ m_wheel_radius = m_chassis_linear_damping = m_max_suspension_force =
m_chassis_angular_damping = m_suspension_rest =
m_max_speed_reverse_ratio = m_rescue_vert_offset =
m_upright_tolerance = m_collision_terrain_impulse =
@@ -428,12 +426,9 @@ void KartProperties::getAllData(const XMLNode * root)
wheels_node->get("radius", &m_wheel_radius );
}
- if(const XMLNode *speed_weighted_node = root->getNode("speed-weighted"))
+ if(const XMLNode *speed_weighted_objects_node = root->getNode("speed-weighted-objects"))
{
- speed_weighted_node->get("strength-factor", &m_speed_weighted_strength_factor);
- speed_weighted_node->get("speed-factor", &m_speed_weighted_speed_factor);
- speed_weighted_node->get("texture-speed-x", &m_speed_weighted_texture_speed.X);
- speed_weighted_node->get("texture-speed-y", &m_speed_weighted_texture_speed.Y);
+ m_speed_weighted_object_properties.loadFromXMLNode(speed_weighted_objects_node);
}
if(const XMLNode *friction_node = root->getNode("friction"))
@@ -636,8 +631,6 @@ void KartProperties::checkAllSet(const std::string &filename)
CHECK_NEG(m_time_reset_steer, "turn time-reset-steer" );
CHECK_NEG(m_wheel_damping_relaxation, "wheels damping-relaxation" );
CHECK_NEG(m_wheel_damping_compression, "wheels damping-compression" );
- CHECK_NEG(m_speed_weighted_strength_factor, "speed-weighted strength-factor" );
- CHECK_NEG(m_speed_weighted_speed_factor, "speed-weighted speed-factor" );
CHECK_NEG(m_wheel_radius, "wheels radius" );
CHECK_NEG(m_friction_slip, "friction slip" );
CHECK_NEG(m_roll_influence, "stability roll-influence" );
@@ -719,6 +712,8 @@ void KartProperties::checkAllSet(const std::string &filename)
CHECK_NEG(m_plunger_in_face_duration[i],"plunger in-face-time");
}
+ m_speed_weighted_object_properties.checkAllSet();
+
m_skidding_properties->checkAllSet(filename);
for(unsigned int i=0; icheckAllSet(filename);
diff --git a/src/karts/kart_properties.hpp b/src/karts/kart_properties.hpp
index c3e21e6e2..8e65d14c7 100644
--- a/src/karts/kart_properties.hpp
+++ b/src/karts/kart_properties.hpp
@@ -264,10 +264,8 @@ private:
float m_roll_influence;
float m_wheel_radius;
- // Parameters for speed-weighted objects
- float m_speed_weighted_strength_factor;
- float m_speed_weighted_speed_factor;
- core::vector2df m_speed_weighted_texture_speed;
+ /** Parameters for the speed-weighted objects */
+ SpeedWeightedObject::Properties m_speed_weighted_object_properties;
/** An impulse pushing the kart down which is proportional to speed. So
* the actual impulse is speed * m_downward_impulse_factor. Set it to
@@ -534,14 +532,8 @@ public:
float getWheelRadius () const {return m_wheel_radius; }
// ------------------------------------------------------------------------
- /** Returns animation strength factor for speed-weighted objects */
- float getSpeedWeightedStrengthFactor() const {return m_speed_weighted_strength_factor;}
-
- // ------------------------------------------------------------------------
- /** Returns animation speed factor for speed-weighted objects */
- float getSpeedWeightedSpeedFactor() const {return m_speed_weighted_speed_factor;}
-
- const core::vector2df& getSpeedWeightedTextureSpeed() const {return m_speed_weighted_texture_speed;}
+ /** Returns parameters for the speed-weighted objects */
+ const SpeedWeightedObject::Properties& getSpeedWeightedObjectProperties() const {return m_speed_weighted_object_properties;}
// ------------------------------------------------------------------------
/** Returns the wheel base (distance front to rear axis). */