Fixed EntityParser to handle string enums properly.

This commit is contained in:
2016-01-19 12:15:20 +01:00
parent 162523d3ca
commit a6445c65aa
4 changed files with 56 additions and 29 deletions
@@ -9,7 +9,9 @@
<Entity name="X"> <Entity name="X">
<Components> <Components>
<c:EditorWidget> <c:EditorWidget>
<Type>2</Type> <Type>
<Rotate/>
</Type>
<Axis X="1" Y="0" Z="0"/> <Axis X="1" Y="0" Z="0"/>
</c:EditorWidget> </c:EditorWidget>
<c:Model> <c:Model>
@@ -22,7 +24,9 @@
<Entity name="Y"> <Entity name="Y">
<Components> <Components>
<c:EditorWidget> <c:EditorWidget>
<Type>2</Type> <Type>
<Rotate/>
</Type>
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:EditorWidget> </c:EditorWidget>
<c:Model> <c:Model>
@@ -35,7 +39,9 @@
<Entity name="Z"> <Entity name="Z">
<Components> <Components>
<c:EditorWidget> <c:EditorWidget>
<Type>2</Type> <Type>
<Rotate/>
</Type>
<Axis X="0" Y="0" Z="1"/> <Axis X="0" Y="0" Z="1"/>
</c:EditorWidget> </c:EditorWidget>
<c:Model> <c:Model>
@@ -12,7 +12,9 @@
<Entity name="X"> <Entity name="X">
<Components> <Components>
<c:EditorWidget> <c:EditorWidget>
<Type>3</Type> <Type>
<Scale/>
</Type>
<Axis X="1" Y="0" Z="0"/> <Axis X="1" Y="0" Z="0"/>
</c:EditorWidget> </c:EditorWidget>
<c:Model> <c:Model>
@@ -25,7 +27,9 @@
<Entity name="Y"> <Entity name="Y">
<Components> <Components>
<c:EditorWidget> <c:EditorWidget>
<Type>3</Type> <Type>
<Scale/>
</Type>
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:EditorWidget> </c:EditorWidget>
<c:Model> <c:Model>
@@ -38,7 +42,9 @@
<Entity name="Z"> <Entity name="Z">
<Components> <Components>
<c:EditorWidget> <c:EditorWidget>
<Type>3</Type> <Type>
<Scale/>
</Type>
<Axis X="0" Y="0" Z="1"/> <Axis X="0" Y="0" Z="1"/>
</c:EditorWidget> </c:EditorWidget>
<c:Model> <c:Model>
@@ -12,7 +12,9 @@
<Entity name="X"> <Entity name="X">
<Components> <Components>
<c:EditorWidget> <c:EditorWidget>
<Type>1</Type> <Type>
<Translate/>
</Type>
<Axis X="1" Y="0" Z="0"/> <Axis X="1" Y="0" Z="0"/>
</c:EditorWidget> </c:EditorWidget>
<c:Model> <c:Model>
@@ -25,7 +27,9 @@
<Entity name="Y"> <Entity name="Y">
<Components> <Components>
<c:EditorWidget> <c:EditorWidget>
<Type>1</Type> <Type>
<Translate/>
</Type>
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:EditorWidget> </c:EditorWidget>
<c:Model> <c:Model>
@@ -38,7 +42,9 @@
<Entity name="Z"> <Entity name="Z">
<Components> <Components>
<c:EditorWidget> <c:EditorWidget>
<Type>1</Type> <Type>
<Translate/>
</Type>
<Axis X="0" Y="0" Z="1"/> <Axis X="0" Y="0" Z="1"/>
</c:EditorWidget> </c:EditorWidget>
<c:Model> <c:Model>
@@ -51,7 +57,9 @@
<Entity name="XPlane"> <Entity name="XPlane">
<Components> <Components>
<c:EditorWidget> <c:EditorWidget>
<Type>1</Type> <Type>
<Translate/>
</Type>
<Axis X="0" Y="1" Z="1"/> <Axis X="0" Y="1" Z="1"/>
</c:EditorWidget> </c:EditorWidget>
<c:Model> <c:Model>
@@ -64,7 +72,9 @@
<Entity name="YPlane"> <Entity name="YPlane">
<Components> <Components>
<c:EditorWidget> <c:EditorWidget>
<Type>1</Type> <Type>
<Translate/>
</Type>
<Axis X="1" Y="0" Z="1"/> <Axis X="1" Y="0" Z="1"/>
</c:EditorWidget> </c:EditorWidget>
<c:Model> <c:Model>
@@ -77,7 +87,9 @@
<Entity name="ZPlane"> <Entity name="ZPlane">
<Components> <Components>
<c:EditorWidget> <c:EditorWidget>
<Type>1</Type> <Type>
<Translate/>
</Type>
<Axis X="1" Y="1" Z="0"/> <Axis X="1" Y="1" Z="0"/>
</c:EditorWidget> </c:EditorWidget>
<c:Model> <c:Model>
+20 -17
View File
@@ -86,23 +86,26 @@ void EntityFile::WriteAttributeData(char* outData, const ComponentInfo::Field_t&
void EntityFile::WriteValueData(char* outData, const ComponentInfo::Field_t& field, const char* valueData) void EntityFile::WriteValueData(char* outData, const ComponentInfo::Field_t& field, const char* valueData)
{ {
if (field.Type == "int" || field.Type == "enum") { // Catch and ignore casting errors so whitespace around string enums won't mess anything up
int value = boost::lexical_cast<int>(valueData); try {
memcpy(outData, reinterpret_cast<char*>(&value), field.Stride); if (field.Type == "int" || field.Type == "enum") {
} else if (field.Type == "float") { int value = boost::lexical_cast<int>(valueData);
float value = boost::lexical_cast<float>(valueData); memcpy(outData, reinterpret_cast<char*>(&value), field.Stride);
memcpy(outData, reinterpret_cast<char*>(&value), field.Stride); } else if (field.Type == "float") {
} else if (field.Type == "double") { float value = boost::lexical_cast<float>(valueData);
double value = boost::lexical_cast<double>(valueData); memcpy(outData, reinterpret_cast<char*>(&value), field.Stride);
memcpy(outData, reinterpret_cast<char*>(&value), field.Stride); } else if (field.Type == "double") {
} else if (field.Type == "bool") { double value = boost::lexical_cast<double>(valueData);
bool value = (valueData[0] == 't'); // Lazy bool evaluation memcpy(outData, reinterpret_cast<char*>(&value), field.Stride);
memcpy(outData, reinterpret_cast<char*>(&value), field.Stride); } else if (field.Type == "bool") {
} else if (field.Type == "string") { bool value = (valueData[0] == 't'); // Lazy bool evaluation
new (outData) std::string(valueData); memcpy(outData, reinterpret_cast<char*>(&value), field.Stride);
} else { } else if (field.Type == "string") {
LOG_WARNING("Unknown value data type: %s", field.Type.c_str()); new (outData) std::string(valueData);
} } else {
LOG_WARNING("Unknown value data type: %s", field.Type.c_str());
}
} catch (const boost::bad_lexical_cast&) { }
} }
EntityFileSAXHandler::EntityFileSAXHandler(const EntityFileHandler* handler, xercesc::SAX2XMLReader* reader) : m_Handler(handler) EntityFileSAXHandler::EntityFileSAXHandler(const EntityFileHandler* handler, xercesc::SAX2XMLReader* reader) : m_Handler(handler)