Remove unnecessary move and add a bit documentation

This commit is contained in:
Flakebi 2015-07-08 22:07:46 +02:00
parent 2272002d5c
commit cb797c3145
4 changed files with 37 additions and 40 deletions

View File

@ -518,14 +518,14 @@ float AbstractCharacteristics::getStabilitySmoothFlyingImpulse() const
return result;
}
InterpolationArray&& AbstractCharacteristics::getTurnRadius() const
InterpolationArray AbstractCharacteristics::getTurnRadius() const
{
InterpolationArray result;
bool is_set = false;
process(TURN_RADIUS, &result, &is_set);
if (!is_set)
Log::fatal("AbstractCharacteristics", "Can't get characteristic %s", getName(TURN_RADIUS).c_str());
return std::move(result);
return result;
}
float AbstractCharacteristics::getTurnTimeResetSteer() const
@ -538,14 +538,14 @@ float AbstractCharacteristics::getTurnTimeResetSteer() const
return result;
}
InterpolationArray&& AbstractCharacteristics::getTurnTimeFullSteer() const
InterpolationArray AbstractCharacteristics::getTurnTimeFullSteer() const
{
InterpolationArray result;
bool is_set = false;
process(TURN_TIME_FULL_STEER, &result, &is_set);
if (!is_set)
Log::fatal("AbstractCharacteristics", "Can't get characteristic %s", getName(TURN_TIME_FULL_STEER).c_str());
return std::move(result);
return result;
}
float AbstractCharacteristics::getEnginePower() const
@ -598,24 +598,24 @@ float AbstractCharacteristics::getEngineMaxSpeedReverseRatio() const
return result;
}
std::vector<float>&& AbstractCharacteristics::getGearSwitchRatio() const
std::vector<float> AbstractCharacteristics::getGearSwitchRatio() const
{
std::vector<float> result;
bool is_set = false;
process(GEAR_SWITCH_RATIO, &result, &is_set);
if (!is_set)
Log::fatal("AbstractCharacteristics", "Can't get characteristic %s", getName(GEAR_SWITCH_RATIO).c_str());
return std::move(result);
return result;
}
std::vector<float>&& AbstractCharacteristics::getGearPowerIncrease() const
std::vector<float> AbstractCharacteristics::getGearPowerIncrease() const
{
std::vector<float> result;
bool is_set = false;
process(GEAR_POWER_INCREASE, &result, &is_set);
if (!is_set)
Log::fatal("AbstractCharacteristics", "Can't get characteristic %s", getName(GEAR_POWER_INCREASE).c_str());
return std::move(result);
return result;
}
float AbstractCharacteristics::getMass() const
@ -658,14 +658,14 @@ float AbstractCharacteristics::getWheelsRadius() const
return result;
}
std::vector<float>&& AbstractCharacteristics::getWheelsPosition() const
std::vector<float> AbstractCharacteristics::getWheelsPosition() const
{
std::vector<float> result;
bool is_set = false;
process(WHEELS_POSITION, &result, &is_set);
if (!is_set)
Log::fatal("AbstractCharacteristics", "Can't get characteristic %s", getName(WHEELS_POSITION).c_str());
return std::move(result);
return result;
}
float AbstractCharacteristics::getCameraDistance() const
@ -1018,24 +1018,24 @@ float AbstractCharacteristics::getPlungerInFaceTime() const
return result;
}
std::vector<float>&& AbstractCharacteristics::getStartupTime() const
std::vector<float> AbstractCharacteristics::getStartupTime() const
{
std::vector<float> result;
bool is_set = false;
process(STARTUP_TIME, &result, &is_set);
if (!is_set)
Log::fatal("AbstractCharacteristics", "Can't get characteristic %s", getName(STARTUP_TIME).c_str());
return std::move(result);
return result;
}
std::vector<float>&& AbstractCharacteristics::getStartupBoost() const
std::vector<float> AbstractCharacteristics::getStartupBoost() const
{
std::vector<float> result;
bool is_set = false;
process(STARTUP_BOOST, &result, &is_set);
if (!is_set)
Log::fatal("AbstractCharacteristics", "Can't get characteristic %s", getName(STARTUP_BOOST).c_str());
return std::move(result);
return result;
}
float AbstractCharacteristics::getRescueDuration() const

View File

@ -205,12 +205,16 @@ public:
virtual const SkiddingProperties* getSkiddingProperties() const;
/**
* TODO
* The process function is the core of this characteristics system.
* Any computation of the properties should happen here and modify the
* values of the value-pointer (be sure to use the right type!) and the
* is_set parameter when the value was set by the call (and wasn't set
* before).
*
* \param type The characteristic that should be modified.
* \param value The current value and result at the same time.
* \param is_set If the current value was already set (so it can be used
* for computations.
* for computations).
*/
virtual void process(CharacteristicType type, Value value, bool *is_set) const;
@ -231,9 +235,9 @@ public:
float getStabilityTrackConnectionAccel() const;
float getStabilitySmoothFlyingImpulse() const;
InterpolationArray&& getTurnRadius() const;
InterpolationArray getTurnRadius() const;
float getTurnTimeResetSteer() const;
InterpolationArray&& getTurnTimeFullSteer() const;
InterpolationArray getTurnTimeFullSteer() const;
float getEnginePower() const;
float getEngineMaxSpeed() const;
@ -241,15 +245,15 @@ public:
float getEngineBrakeTimeIncrease() const;
float getEngineMaxSpeedReverseRatio() const;
std::vector<float>&& getGearSwitchRatio() const;
std::vector<float>&& getGearPowerIncrease() const;
std::vector<float> getGearSwitchRatio() const;
std::vector<float> getGearPowerIncrease() const;
float getMass() const;
float getWheelsDampingRelaxation() const;
float getWheelsDampingCompression() const;
float getWheelsRadius() const;
std::vector<float>&& getWheelsPosition() const;
std::vector<float> getWheelsPosition() const;
float getCameraDistance() const;
float getCameraForwardUpAngle() const;
@ -295,8 +299,8 @@ public:
float getPlungerFadeOutTime() const;
float getPlungerInFaceTime() const;
std::vector<float>&& getStartupTime() const;
std::vector<float>&& getStartupBoost() const;
std::vector<float> getStartupTime() const;
std::vector<float> getStartupBoost() const;
float getRescueDuration() const;
float getRescueVertOffset() const;

View File

@ -101,8 +101,8 @@ void XmlCharacteristics::process(CharacteristicType type, Value value, bool *is_
for (std::vector<std::string>::const_iterator it = processors.begin();
it != processors.end(); it++)
{
std::vector<std::string> pair = StringUtils::split(*it,':');
if (!pair.size() == 2)
std::vector<std::string> pair = StringUtils::split(*it, ':');
if (pair.size() != 2)
Log::error("XmlCharacteristics::process",
"Can't process %s: Wrong format", getName(type).c_str());
else
@ -140,7 +140,7 @@ void XmlCharacteristics::process(CharacteristicType type, Value value, bool *is_
it != processors.end(); it++)
{
std::vector<std::string> pair = StringUtils::split(*it,':');
if (!pair.size() == 2)
if (pair.size() != 2)
Log::error("XmlCharacteristics::process",
"Can't process %s: Wrong format", getName(type).c_str());
else
@ -229,6 +229,9 @@ void XmlCharacteristics::processFloat(const std::string &processor, float *value
*value += val;
else if (operations[index - 1] == "-")
*value -= val;
else
Log::fatal("XmlCharacteristics::processFloat",
"Unknown operator (%s)", operations[index - 1].c_str());
}
*is_set = true;
}

View File

@ -24,7 +24,7 @@
import sys
# Input data
#FIXME is wheelPosition needed??
#FIXME is wheelPosition needed?
characteristics = """Suspension: stiffness, rest, travelCm, expSpringResponse, maxForce
Stability: rollInfluence, chassisLinearDamping, chassisAngularDamping, downwardImpulseFactor, trackConnectionAccel, smoothFlyingImpulse
Turn: radius(InterpolationArray), timeResetSteer, timeFullSteer(InterpolationArray)
@ -54,9 +54,6 @@ class GroupMember:
self.typeC = typeC
self.typeStr = typeStr
def shouldMove(self):
return self.typeC != "float"
"""E.g. power(std::vector<float>/floatVector)
or speed(InterpolationArray)
The default type is float"""
@ -163,10 +160,7 @@ def main():
for m in g.members:
nameTitle = joinSubName(g, m, True)
nameUnderscore = joinSubName(g, m, False)
if m.shouldMove():
typeC = m.typeC + "&&"
else:
typeC = m.typeC
typeC = m.typeC
print(" {0} get{1}() const;".
format(typeC, nameTitle, nameUnderscore))
@ -175,12 +169,8 @@ def main():
for m in g.members:
nameTitle = joinSubName(g, m, True)
nameUnderscore = joinSubName(g, m, False)
if m.shouldMove():
typeC = m.typeC + "&&"
result = "std::move(result)"
else:
typeC = m.typeC
result = "result"
typeC = m.typeC
result = "result"
print("""{3} AbstractCharacteristics::get{1}() const
{{