Add more to xml reading
This commit is contained in:
parent
cedd816ca1
commit
c22d5c8e6e
File diff suppressed because it is too large
Load Diff
@ -209,10 +209,10 @@ public:
|
||||
*
|
||||
* \param type The characteristic that should be modified.
|
||||
* \param value The current value and result at the same time.
|
||||
* \param isSet If the current value was already set (so it can be used
|
||||
* \param is_set If the current value was already set (so it can be used
|
||||
* for computations.
|
||||
*/
|
||||
virtual void process(CharacteristicType type, Value value, bool *isSet) const;
|
||||
virtual void process(CharacteristicType type, Value value, bool *is_set) const;
|
||||
|
||||
static ValueType getType(CharacteristicType type);
|
||||
static std::string getName(CharacteristicType type);
|
||||
|
@ -58,15 +58,15 @@ void CachedCharacteristics::updateSource()
|
||||
{
|
||||
SaveValue &v = m_values[i];
|
||||
|
||||
bool isSet = false;
|
||||
bool is_set = false;
|
||||
switch (getType(static_cast<CharacteristicType>(i)))
|
||||
{
|
||||
case TYPE_FLOAT:
|
||||
{
|
||||
float value;
|
||||
float *ptr = static_cast<float*>(v.content);
|
||||
m_origin->process(static_cast<CharacteristicType>(i), &value, &isSet);
|
||||
if (isSet)
|
||||
m_origin->process(static_cast<CharacteristicType>(i), &value, &is_set);
|
||||
if (is_set)
|
||||
{
|
||||
if (!ptr)
|
||||
{
|
||||
@ -90,8 +90,8 @@ void CachedCharacteristics::updateSource()
|
||||
{
|
||||
std::vector<float> value;
|
||||
std::vector<float> *ptr = static_cast<std::vector<float>*>(v.content);
|
||||
m_origin->process(static_cast<CharacteristicType>(i), &value, &isSet);
|
||||
if (isSet)
|
||||
m_origin->process(static_cast<CharacteristicType>(i), &value, &is_set);
|
||||
if (is_set)
|
||||
{
|
||||
if (!ptr)
|
||||
{
|
||||
@ -116,8 +116,8 @@ void CachedCharacteristics::updateSource()
|
||||
{
|
||||
InterpolationArray value;
|
||||
InterpolationArray *ptr = static_cast<InterpolationArray*>(v.content);
|
||||
m_origin->process(static_cast<CharacteristicType>(i), &value, &isSet);
|
||||
if (isSet)
|
||||
m_origin->process(static_cast<CharacteristicType>(i), &value, &is_set);
|
||||
if (is_set)
|
||||
{
|
||||
if (!ptr)
|
||||
{
|
||||
@ -147,7 +147,7 @@ const SkiddingProperties* CachedCharacteristics::getSkiddingProperties() const
|
||||
return m_origin->getSkiddingProperties();
|
||||
}
|
||||
|
||||
void CachedCharacteristics::process(CharacteristicType type, Value value, bool *isSet) const
|
||||
void CachedCharacteristics::process(CharacteristicType type, Value value, bool *is_set) const
|
||||
{
|
||||
void *v = m_values[type].content;
|
||||
if (v)
|
||||
@ -164,7 +164,7 @@ void CachedCharacteristics::process(CharacteristicType type, Value value, bool *
|
||||
*value.ia = *static_cast<InterpolationArray*>(v);
|
||||
break;
|
||||
}
|
||||
*isSet = true;
|
||||
*is_set = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
void updateSource();
|
||||
|
||||
virtual const SkiddingProperties* getSkiddingProperties() const;
|
||||
virtual void process(CharacteristicType type, Value value, bool *isSet) const;
|
||||
virtual void process(CharacteristicType type, Value value, bool *is_set) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -34,9 +34,9 @@ const SkiddingProperties* CombinedCharacteristics::getSkiddingProperties() const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CombinedCharacteristics::process(CharacteristicType type, Value value, bool *isSet) const
|
||||
void CombinedCharacteristics::process(CharacteristicType type, Value value, bool *is_set) const
|
||||
{
|
||||
for (const AbstractCharacteristics *characteristic : m_childs)
|
||||
characteristic->process(type, value, isSet);
|
||||
characteristic->process(type, value, is_set);
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
void addCharacteristic(const AbstractCharacteristics *characteristic);
|
||||
|
||||
virtual const SkiddingProperties* getSkiddingProperties() const;
|
||||
virtual void process(CharacteristicType type, Value value, bool *isSet) const;
|
||||
virtual void process(CharacteristicType type, Value value, bool *is_set) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -18,6 +18,10 @@
|
||||
|
||||
#include "karts/xml_characteristics.hpp"
|
||||
|
||||
#include "utils/interpolation_array.hpp"
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
#include "io/xml_node.hpp"
|
||||
|
||||
XmlCharacteristics::XmlCharacteristics(const XMLNode *node) :
|
||||
@ -33,21 +37,141 @@ const SkiddingProperties* XmlCharacteristics::getSkiddingProperties() const
|
||||
return m_skidding;
|
||||
}
|
||||
|
||||
void XmlCharacteristics::process(CharacteristicType type, Value value, bool *isSet) const
|
||||
void XmlCharacteristics::process(CharacteristicType type, Value value, bool *is_set) const
|
||||
{
|
||||
switch (getType(type))
|
||||
{
|
||||
case TYPE_FLOAT:
|
||||
processFloat(m_values[type], value.f, isSet);
|
||||
processFloat(m_values[type], value.f, is_set);
|
||||
break;
|
||||
case TYPE_FLOAT_VECTOR:
|
||||
{
|
||||
const std::vector<std::string> processors =
|
||||
StringUtils::split(m_values[type], ' ');
|
||||
if (*is_set)
|
||||
{
|
||||
if (processors.size() != value.fv->size())
|
||||
{
|
||||
Log::error("XmlCharacteristics::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);
|
||||
}
|
||||
else
|
||||
{
|
||||
value.fv->resize(processors.size());
|
||||
std::vector<float>::iterator fit = value.fv->begin();
|
||||
for (std::vector<std::string>::const_iterator it = processors.begin();
|
||||
it != processors.end(); it++, fit++)
|
||||
{
|
||||
*is_set = false;
|
||||
processFloat(*it, &*fit, is_set);
|
||||
|
||||
if (!*is_set)
|
||||
{
|
||||
Log::error("XmlCharacteristics::process", "Can't process %s",
|
||||
getName(type).c_str());
|
||||
value.fv->clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TYPE_INTERPOLATION_ARRAY:
|
||||
{
|
||||
const std::vector<std::string> processors =
|
||||
StringUtils::split(m_values[type], ' ');
|
||||
if (*is_set)
|
||||
{
|
||||
if (processors.size() != value.fv->size())
|
||||
{
|
||||
Log::error("XmlCharacteristics::process",
|
||||
"InterpolationArrays have different sizes for %s",
|
||||
getName(type).c_str());
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
Log::error("XmlCharacteristics::process",
|
||||
"Can't process %s: Wrong format", getName(type).c_str());
|
||||
else
|
||||
{
|
||||
float x;
|
||||
if (!StringUtils::fromString(pair[0], x))
|
||||
Log::error("XmlCharacteristics::process",
|
||||
"Can't process %s: Not a float", getName(type).c_str());
|
||||
else
|
||||
{
|
||||
// Search the index of this x value
|
||||
bool found = false;
|
||||
for (unsigned int i = 0; i < value.ia->size(); i++)
|
||||
{
|
||||
if (value.ia->getX(i) == x)
|
||||
{
|
||||
float val;
|
||||
processFloat(pair[1], &val, is_set);
|
||||
value.ia->setY(i, val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
Log::error("XmlCharacteristics::process",
|
||||
"Can't find the %f in %s", x,
|
||||
getName(type).c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
Log::error("XmlCharacteristics::process",
|
||||
"Can't process %s: Wrong format", getName(type).c_str());
|
||||
else
|
||||
{
|
||||
float x;
|
||||
if (!StringUtils::fromString(pair[0], x))
|
||||
Log::error("XmlCharacteristics::process",
|
||||
"Can't process %s: Not a float", getName(type).c_str());
|
||||
else
|
||||
{
|
||||
float val;
|
||||
*is_set = false;
|
||||
processFloat(pair[1], &val, is_set);
|
||||
if (!*is_set)
|
||||
{
|
||||
Log::error("XmlCharacteristics::process", "Can't process %s",
|
||||
getName(type).c_str());
|
||||
value.ia->clear();
|
||||
break;
|
||||
}
|
||||
value.ia->push_back(x, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void XmlCharacteristics::processFloat(const std::string &processor, float *value, bool *isSet)
|
||||
void XmlCharacteristics::processFloat(const std::string &processor, float *value, bool *is_set)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -36,12 +36,12 @@ public:
|
||||
XmlCharacteristics(const XMLNode *node = nullptr);
|
||||
|
||||
virtual const SkiddingProperties* getSkiddingProperties() const;
|
||||
virtual void process(CharacteristicType type, Value value, bool *isSet) const;
|
||||
virtual void process(CharacteristicType type, Value value, bool *is_set) const;
|
||||
|
||||
void load(const XMLNode *node);
|
||||
|
||||
private:
|
||||
static void processFloat(const std::string &processor, float *value, bool *isSet);
|
||||
static void processFloat(const std::string &processor, float *value, bool *is_set);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -185,9 +185,9 @@ def main():
|
||||
print("""{3} AbstractCharacteristics::get{1}() const
|
||||
{{
|
||||
{0} result;
|
||||
bool isSet = false;
|
||||
process({2}, &result, &isSet);
|
||||
if (!isSet)
|
||||
bool is_set = false;
|
||||
process({2}, &result, &is_set);
|
||||
if (!is_set)
|
||||
Log::fatal("AbstractCharacteristics", "Can't get characteristic %s", getName({2}).c_str());
|
||||
return {4};
|
||||
}}
|
||||
|
Loading…
Reference in New Issue
Block a user