Move more properties
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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 &&
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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). */
|
||||
|
||||
@@ -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; i<m_turn_angle_at_speed.size(); i++)
|
||||
{
|
||||
m_turn_angle_at_speed.setY( i,
|
||||
sin(m_wheel_base/m_turn_angle_at_speed.getY(i)) );
|
||||
}
|
||||
|
||||
m_shadow_texture = irr_driver->getTexture(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
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -219,8 +219,6 @@ void KartPropertiesManager::loadCharacteristics(const XMLNode *root)
|
||||
(*type)->get("name", &name);
|
||||
m_kart_type_characteristics.emplace(name,
|
||||
std::unique_ptr<AbstractCharacteristic>(new XmlCharacteristic(*type)));
|
||||
XmlCharacteristic *c = (XmlCharacteristic*) &(*((--m_kart_type_characteristics.end())->second));
|
||||
c->getMass();
|
||||
}
|
||||
// Load player difficulties
|
||||
nodes.clear();
|
||||
|
||||
@@ -49,21 +49,34 @@ void XmlCharacteristic::process(CharacteristicType type, Value value, bool *is_s
|
||||
{
|
||||
const std::vector<std::string> 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<float>::iterator fit = value.fv->begin();
|
||||
for (std::vector<std::string>::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<float>::iterator fit = value.fv->begin();
|
||||
for (std::vector<std::string>::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<float>::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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user