Fixed component type resolution order to prioritize custom types before native ones, since namespace information doesn't exist at that stage.

This commit is contained in:
2015-12-14 16:12:20 +01:00
parent f8d927cd91
commit ea239b19bd
3 changed files with 46 additions and 58 deletions
-6
View File
@@ -1,6 +0,0 @@
<c:Test>
<Integer>1</Integer>
<Float>1.333</Float>
<Vector X="1.33333" Y="2.33333" Z="3.33333"/>
<Quaternion X="1.33333" Y="2.33333" Z="3.33333" W="4.44444"/>
</c:Test>
-20
View File
@@ -1,20 +0,0 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="Test">
<xs:annotation>
<xs:documentation>ECS Test Component</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="Integer" type="t:int" minOccurs="0"/>
<xs:element name="Double" type="t:double" minOccurs="0"/>
<xs:element name="String" type="t:string" minOccurs="0"/>
<xs:element name="Vector" type="t:Vector" minOccurs="0"/>
<xs:element name="Quaternion" type="t:Quaternion" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
+21 -7
View File
@@ -415,6 +415,7 @@ std::size_t EntityXMLFile::getTypeStride(std::string typeName)
std::map<std::string, size_t> typeStrides{ std::map<std::string, size_t> typeStrides{
{ "bool", sizeof(bool) }, { "bool", sizeof(bool) },
{ "int", sizeof(int) }, { "int", sizeof(int) },
{ "float", sizeof(float) },
{ "double", sizeof(double) }, { "double", sizeof(double) },
{ "string", sizeof(std::string) }, { "string", sizeof(std::string) },
{ "Vector", sizeof(glm::vec3) }, { "Vector", sizeof(glm::vec3) },
@@ -443,8 +444,6 @@ void EntityXMLFile::writeData(const xercesc::DOMElement* element, std::string ty
{ {
using namespace xercesc; using namespace xercesc;
XSValue::DataType dataType = XSValue::getDataType(XSTR(typeName.c_str()));
if (dataType == XSValue::DataType::dt_MAXCOUNT) {
if (typeName == "Vector") { if (typeName == "Vector") {
glm::vec3 vec; glm::vec3 vec;
vec.x = getFloatAttribute(element, "X"); vec.x = getFloatAttribute(element, "X");
@@ -465,17 +464,32 @@ void EntityXMLFile::writeData(const xercesc::DOMElement* element, std::string ty
q.z = getFloatAttribute(element, "Z"); q.z = getFloatAttribute(element, "Z");
q.w = getFloatAttribute(element, "W"); q.w = getFloatAttribute(element, "W");
memcpy(outData, reinterpret_cast<char*>(&q), getTypeStride(typeName)); memcpy(outData, reinterpret_cast<char*>(&q), getTypeStride(typeName));
} } else if (typeName == "float") {
} else if (dataType == XSValue::DataType::dt_string) { XSValue::Status status;
XSValue* val = XSValue::getActualValue(element->getTextContent(), xercesc::XSValue::DataType::dt_float, status);
memcpy(outData, reinterpret_cast<char*>(&val->fData.fValue.f_float), getTypeStride(typeName));
} else if (typeName == "double") {
XSValue::Status status;
XSValue* val = XSValue::getActualValue(element->getTextContent(), xercesc::XSValue::DataType::dt_double, status);
memcpy(outData, reinterpret_cast<char*>(&val->fData.fValue.f_double), getTypeStride(typeName));
} else if (typeName == "bool") {
XSValue::Status status;
XSValue* val = XSValue::getActualValue(element->getTextContent(), xercesc::XSValue::DataType::dt_boolean, status);
memcpy(outData, reinterpret_cast<char*>(&val->fData.fValue.f_bool), getTypeStride(typeName));
} else {
XSValue::DataType dataType = XSValue::getDataType(XSTR(typeName.c_str()));
if (dataType == XSValue::DataType::dt_string) {
char* str = XMLString::transcode(element->getTextContent()); char* str = XMLString::transcode(element->getTextContent());
std::string standardString(str); std::string standardString(str);
new (outData) std::string(str); new (outData) std::string(str);
XMLString::release(&str); XMLString::release(&str);
//memcpy(outData, reinterpret_cast<char*>(&standardString), getTypeStride(typeName)); //memcpy(outData, reinterpret_cast<char*>(&standardString), getTypeStride(typeName));
} else { } else {
XSValue::Status status; //XSValue::Status status;
XSValue* val = XSValue::getActualValue(element->getTextContent(), dataType, status); //XSValue* val = XSValue::getActualValue(element->getTextContent(), dataType, status);
memcpy(outData, reinterpret_cast<char*>(&val->fData.fValue), getTypeStride(typeName)); //memcpy(outData, reinterpret_cast<char*>(&val->fData.fValue), getTypeStride(typeName));
LOG_WARNING("Unknown native data type: %s", typeName.c_str());
}
} }
} }