Add comments

This commit is contained in:
Flakebi 2015-10-03 17:45:25 +02:00
parent cb4dd91e08
commit a789f346ad
5 changed files with 61 additions and 2 deletions

View File

@ -34,6 +34,11 @@ const SkiddingProperties* AbstractCharacteristic::getSkiddingProperties() const
} // getSkiddingProperties
// ----------------------------------------------------------------------------
/** The process function should change the given value.
* The input and output argument is saved in value.
* is_set describes if the value is already set or if it's undefined.
* The function also has to set is_set if the state changed.
*/
void AbstractCharacteristic::process(CharacteristicType type, Value value,
bool *is_set) const
{
@ -41,6 +46,7 @@ void AbstractCharacteristic::process(CharacteristicType type, Value value,
} // process
// ----------------------------------------------------------------------------
/** Returns the type of a given characteristic. */
AbstractCharacteristic::ValueType AbstractCharacteristic::getType(
CharacteristicType type)
{
@ -230,6 +236,7 @@ AbstractCharacteristic::ValueType AbstractCharacteristic::getType(
} // getType
// ----------------------------------------------------------------------------
/** Converts the enum value to a string. */
std::string AbstractCharacteristic::getName(CharacteristicType type)
{
switch (type)

View File

@ -28,6 +28,7 @@ CachedCharacteristic::CachedCharacteristic(const AbstractCharacteristic *origin)
}
// ----------------------------------------------------------------------------
/** Deletes all allocated values. */
CachedCharacteristic::~CachedCharacteristic()
{
// Delete all not-null values
@ -47,6 +48,9 @@ CachedCharacteristic::~CachedCharacteristic()
case TYPE_INTERPOLATION_ARRAY:
delete static_cast<InterpolationArray*>(v.content);
break;
case TYPE_BOOL:
delete static_cast<InterpolationArray*>(v.content);
break;
}
v.content = nullptr;
}
@ -54,6 +58,9 @@ CachedCharacteristic::~CachedCharacteristic()
} // ~CachedCharacteristic
// ----------------------------------------------------------------------------
/** Recompute the values of all characteristics based on the list of
* source-characteristics.
*/
void CachedCharacteristic::updateSource()
{
for (int i = 0; i < CHARACTERISTIC_COUNT; i++)
@ -113,7 +120,6 @@ void CachedCharacteristic::updateSource()
}
break;
}
break;
case TYPE_INTERPOLATION_ARRAY:
{
InterpolationArray value;
@ -139,6 +145,31 @@ void CachedCharacteristic::updateSource()
}
break;
}
case TYPE_BOOL:
{
bool value;
bool *ptr = static_cast<bool*>(v.content);
m_origin->process(static_cast<CharacteristicType>(i), &value, &is_set);
if (is_set)
{
if (!ptr)
{
bool *newPtr = new bool();
v.content = newPtr;
ptr = newPtr;
}
*ptr = value;
}
else
{
if (ptr)
{
delete ptr;
v.content = nullptr;
}
}
break;
}
} // switch (type)
} // foreach characteristic
} // updateSource
@ -150,6 +181,7 @@ const SkiddingProperties* CachedCharacteristic::getSkiddingProperties() const
} // getSkiddingProperties
// ----------------------------------------------------------------------------
/** Returns the stored value. */
void CachedCharacteristic::process(CharacteristicType type, Value value,
bool *is_set) const
{
@ -167,6 +199,9 @@ void CachedCharacteristic::process(CharacteristicType type, Value value,
case TYPE_INTERPOLATION_ARRAY:
*value.ia = *static_cast<InterpolationArray*>(v);
break;
case TYPE_BOOL:
*value.f = *static_cast<bool*>(v);
break;
}
*is_set = true;
}

View File

@ -37,6 +37,7 @@ const SkiddingProperties* CombinedCharacteristic::getSkiddingProperties() const
} // getSkiddingProperties
// ----------------------------------------------------------------------------
/** Combines all contained source characteristics. */
void CombinedCharacteristic::process(CharacteristicType type, Value value,
bool *is_set) const
{

View File

@ -32,6 +32,9 @@ XmlCharacteristic::XmlCharacteristic(const XMLNode *node) :
} // XmlCharacteristic constructor
// ----------------------------------------------------------------------------
/** process will execute the operation that is specified in the saved string.
* The format of the operations is specified in kart_characteristics.xml.
*/
void XmlCharacteristic::process(CharacteristicType type, Value value,
bool *is_set) const
{
@ -204,6 +207,7 @@ void XmlCharacteristic::process(CharacteristicType type, Value value,
} // process
// ----------------------------------------------------------------------------
/** Executes an operation on a float value. */
void XmlCharacteristic::processFloat(const std::string &processor, float *value,
bool *is_set)
{
@ -278,6 +282,7 @@ void XmlCharacteristic::processFloat(const std::string &processor, float *value,
} // processFloat
// ----------------------------------------------------------------------------
/** Executes an operation on a bool value. */
void XmlCharacteristic::processBool(const std::string &processor, bool *value,
bool *is_set)
{
@ -297,6 +302,9 @@ void XmlCharacteristic::processBool(const std::string &processor, bool *value,
} // processBool
// ----------------------------------------------------------------------------
/** Loads all commands from a given xml file.
* Non-existing tags will be omitted.
*/
void XmlCharacteristic::load(const XMLNode *node)
{
// Script-generated content generated by tools/create_kart_properties.py getXml

View File

@ -24,6 +24,8 @@
import sys
# Input data
# Each line contains a topic and the attributes of that topic.
# This model is used for the xml file and to access the kart properties in the code.
characteristics = """Suspension: stiffness, rest, travel, expSpringResponse(bool), maxForce
Stability: rollInfluence, chassisLinearDamping, chassisAngularDamping, downwardImpulseFactor, trackConnectionAccel, smoothFlyingImpulse
Turn: radius(InterpolationArray), timeResetSteer, timeFullSteer(InterpolationArray)
@ -46,7 +48,10 @@ Explosion: duration, radius, invulnerabilityTime
Nitro: duration, engineForce, consumption, smallContainer, bigContainer, maxSpeedIncrease, fadeOutTime, max
Slipstream: duration, length, width, collectTime, useTime, addPower, minSpeed, maxSpeedIncrease, fadeOutTime"""
""" A GroupMember is an attribute of a group.
In the xml files, a value will be assigned to it.
If the name of the attribute is 'value', the getter method will only
contain the group name and 'value' will be omitted (e.g. used for mass). """
class GroupMember:
def __init__(self, name, typeC, typeStr):
self.name = name
@ -81,11 +86,14 @@ class GroupMember:
return GroupMember(name, typeC, typeStr)
""" A Group has a base name and can contain GroupMembers.
In the xml files, a group is a tag. """
class Group:
def __init__(self, baseName):
self.baseName = baseName
self.members = []
""" Parses and adds a member to this group """
def addMember(self, content):
self.members.append(GroupMember.parse(content))