diff --git a/src/karts/abstract_kart.hpp b/src/karts/abstract_kart.hpp index 780b739a4..30b924edc 100644 --- a/src/karts/abstract_kart.hpp +++ b/src/karts/abstract_kart.hpp @@ -152,6 +152,10 @@ public: * speed. */ virtual float getMaxSteerAngle () const = 0; // ------------------------------------------------------------------------ + /** Returns the (maximum) speed for a given turn radius. + * \param radius The radius for which the speed needs to be computed. */ + virtual float getSpeedForTurnRadius(float radius) const = 0; + // ------------------------------------------------------------------------ /** Returns the time till full steering is reached for this kart. * This can depend on the current steering value, which must be >= 0. */ diff --git a/src/karts/controller/skidding_ai.cpp b/src/karts/controller/skidding_ai.cpp index b8fd50c07..9dccb8280 100644 --- a/src/karts/controller/skidding_ai.cpp +++ b/src/karts/controller/skidding_ai.cpp @@ -443,8 +443,7 @@ void SkiddingAI::handleBraking() m_current_track_direction==GraphNode::DIR_RIGHT ) { float max_turn_speed = - m_kart->getKartProperties() - ->getSpeedForTurnRadius(m_current_curve_radius); + m_kart->getSpeedForTurnRadius(m_current_curve_radius); if(m_kart->getSpeed() > 1.5f*max_turn_speed && m_kart->getSpeed()>MIN_SPEED && diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 12df080ba..b0e0ad70b 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -807,6 +807,34 @@ void Kart::updateWeight() m_body->setMassProps(mass, inertia); } // updateWeight +// ------------------------------------------------------------------------ +/** Returns the (maximum) speed for a given turn radius. + * \param radius The radius for which the speed needs to be computed. */ +float Kart::getSpeedForTurnRadius(float radius) const +{ + InterpolationArray turn_angle_at_speed = m_characteristic->getTurnRadius(); + // Convert the turn radius into turn angle + for(std::size_t i = 0; i < turn_angle_at_speed.size(); i++) + turn_angle_at_speed.setY(i, sin(m_kart_properties->getWheelBase() / + turn_angle_at_speed.getY(i))); + + float angle = sin(m_kart_properties->getWheelBase() / radius); + return turn_angle_at_speed.getReverse(angle); +} // getSpeedForTurnRadius + +// ------------------------------------------------------------------------ +/** Returns the maximum steering angle (depending on speed). */ +float Kart::getMaxSteerAngle(float speed) const +{ + InterpolationArray turn_angle_at_speed = m_characteristic->getTurnRadius(); + // Convert the turn radius into turn angle + for(std::size_t i = 0; i < turn_angle_at_speed.size(); i++) + turn_angle_at_speed.setY(i, sin(m_kart_properties->getWheelBase() / + turn_angle_at_speed.getY(i))); + + return turn_angle_at_speed.get(speed); +} // getMaxSteerAngle + //----------------------------------------------------------------------------- /** Sets that this kart has finished the race and finishing time. It also * notifies the race_manager about the race completion for this kart. diff --git a/src/karts/kart.hpp b/src/karts/kart.hpp index 6d8bce9b4..884152f1d 100644 --- a/src/karts/kart.hpp +++ b/src/karts/kart.hpp @@ -244,6 +244,8 @@ public: const btQuaternion& off_rotation); virtual void createPhysics (); virtual void updateWeight (); + virtual float getSpeedForTurnRadius(float radius) const; + virtual float getMaxSteerAngle(float speed) const; virtual bool isInRest () const; virtual void applyEngineForce (float force); @@ -346,7 +348,7 @@ public: /** Returns the maximum steering angle for this kart, which depends on the * speed. */ virtual float getMaxSteerAngle () const - { return m_kart_properties->getMaxSteerAngle(getSpeed()); } + { return getMaxSteerAngle(getSpeed()); } // ------------------------------------------------------------------------ /** Returns the skidding object for this kart (which can be used to query * skidding related values). */ diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index bf8031e52..e9e298f49 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -296,13 +296,6 @@ void KartProperties::load(const std::string &filename, const std::string &node) m_wheel_base = fabsf(m_kart_model->getLength() - 2 * m_combined_characteristic->getWheelsRadius()); - // Now convert the turn radius into turn angle: - for(unsigned int i=0; igetTexture(m_shadow_file); irr_driver->unsetTextureErrorMessage(); @@ -401,13 +394,6 @@ void KartProperties::getAllData(const XMLNode * root) } } - if (const XMLNode *turn_node = root->getNode("turn")) - { - turn_node->get("turn-radius", &m_turn_angle_at_speed ); - // For now store the turn radius in turn angle, the correct - // value can only be determined later in ::load - } - //TODO: wheel front right and wheel front left is not loaded, yet is //TODO: listed as an attribute in the xml file after wheel-radius //TODO: same goes for their rear equivalents diff --git a/src/karts/kart_properties.hpp b/src/karts/kart_properties.hpp index bf67f4dc8..f53ae3537 100644 --- a/src/karts/kart_properties.hpp +++ b/src/karts/kart_properties.hpp @@ -132,9 +132,6 @@ private: // Physic properties // ----------------- - /** The turn angle depending on speed. */ - InterpolationArray m_turn_angle_at_speed; - /** If != 0 a bevelled box shape is used by using a point cloud as a * collision shape. */ Vec3 m_bevel_factor; @@ -243,19 +240,6 @@ public: */ const AbstractCharacteristic* getCombinedCharacteristic() const; - // ------------------------------------------------------------------------ - /** Returns the (maximum) speed for a given turn radius. - * \param radius The radius for which the speed needs to be computed. */ - float getSpeedForTurnRadius(float radius) const { - float angle = sin(m_wheel_base / radius); - return m_turn_angle_at_speed.getReverse(angle); - } // getSpeedForTurnRadius - // ------------------------------------------------------------------------ - /** Returns the maximum steering angle (depending on speed). */ - float getMaxSteerAngle(float speed) const { - return m_turn_angle_at_speed.get(speed); - } // getMaxSteerAngle - // ------------------------------------------------------------------------ /** Returns the material for the kart icons. */ Material* getIconMaterial () const {return m_icon_material; } diff --git a/src/karts/kart_properties_manager.cpp b/src/karts/kart_properties_manager.cpp index a9eaa5b3c..4794c410c 100644 --- a/src/karts/kart_properties_manager.cpp +++ b/src/karts/kart_properties_manager.cpp @@ -219,8 +219,6 @@ void KartPropertiesManager::loadCharacteristics(const XMLNode *root) (*type)->get("name", &name); m_kart_type_characteristics.emplace(name, std::unique_ptr(new XmlCharacteristic(*type))); - XmlCharacteristic *c = (XmlCharacteristic*) &(*((--m_kart_type_characteristics.end())->second)); - c->getMass(); } // Load player difficulties nodes.clear(); diff --git a/src/karts/xml_characteristic.cpp b/src/karts/xml_characteristic.cpp index 56ede87df..1d534d4a9 100644 --- a/src/karts/xml_characteristic.cpp +++ b/src/karts/xml_characteristic.cpp @@ -49,21 +49,34 @@ void XmlCharacteristic::process(CharacteristicType type, Value value, bool *is_s { const std::vector processors = StringUtils::split(m_values[type], ' '); + // If the array should be completely replaced + // That has to happen when the size is not the same or it is not yet set + bool shouldReplace = false; if (*is_set) { if (processors.size() != value.fv->size()) + shouldReplace = true; + else { - Log::error("XmlCharacteristic::process", - "FloatVectors have different sizes for %s", - getName(type).c_str()); - break; + std::vector::iterator fit = value.fv->begin(); + for (std::vector::const_iterator it = processors.begin(); + it != processors.end(); it++, fit++) + { + processFloat(*it, &*fit, is_set); + if (!*is_set) + { + Log::error("XmlCharacteristic::process", "Can't process %s", + it->c_str()); + value.fv->clear(); + break; + } + } } - std::vector::iterator fit = value.fv->begin(); - for (std::vector::const_iterator it = processors.begin(); - it != processors.end(); it++, fit++) - processFloat(*it, &*fit, is_set); } else + shouldReplace = true; + + if (shouldReplace) { value.fv->resize(processors.size()); std::vector::iterator fit = value.fv->begin(); @@ -123,6 +136,13 @@ void XmlCharacteristic::process(CharacteristicType type, Value value, bool *is_s value.ia->setY(i, val); break; } + if (!*is_set) + { + Log::error("XmlCharacteristic::process", "Can't process %s", + pair[1].c_str()); + value.fv->clear(); + break; + } } if (!found) {