Created ComponentInfo::EnumType which defines which native type to use for enums.
This commit is contained in:
@@ -47,7 +47,7 @@ std::size_t EntityFile::GetTypeStride(std::string typeName)
|
||||
{ "float", sizeof(float) },
|
||||
{ "double", sizeof(double) },
|
||||
{ "string", sizeof(std::string) },
|
||||
{ "enum", sizeof(int) },
|
||||
{ "enum", sizeof(ComponentInfo::EnumType) },
|
||||
{ "Vector", sizeof(glm::vec3) },
|
||||
{ "Quaternion", sizeof(glm::quat) },
|
||||
{ "Color", sizeof(glm::vec4) }
|
||||
@@ -88,9 +88,12 @@ void EntityFile::WriteValueData(char* outData, const ComponentInfo::Field_t& fie
|
||||
{
|
||||
// Catch and ignore casting errors so whitespace around string enums won't mess anything up
|
||||
try {
|
||||
if (field.Type == "int" || field.Type == "enum") {
|
||||
if (field.Type == "int") {
|
||||
int value = boost::lexical_cast<int>(valueData);
|
||||
memcpy(outData, reinterpret_cast<char*>(&value), field.Stride);
|
||||
} else if (field.Type == "enum") {
|
||||
ComponentInfo::EnumType value = boost::lexical_cast<ComponentInfo::EnumType>(valueData);
|
||||
memcpy(outData, reinterpret_cast<char*>(&value), field.Stride);
|
||||
} else if (field.Type == "float") {
|
||||
float value = boost::lexical_cast<float>(valueData);
|
||||
memcpy(outData, reinterpret_cast<char*>(&value), field.Stride);
|
||||
|
||||
@@ -146,7 +146,7 @@ void EntityFilePreprocessor::parseComponentInfo()
|
||||
auto enumElement = xsChoiceParticles->elementAt(i)->getElementTerm();
|
||||
std::string enumName = XS::ToString(enumElement->getName());
|
||||
std::string enumValue = XS::ToString(enumElement->getConstraintValue());
|
||||
compInfo.Meta->FieldEnumDefinitions[name][enumName] = boost::lexical_cast<int>(enumValue);
|
||||
compInfo.Meta->FieldEnumDefinitions[name][enumName] = boost::lexical_cast<ComponentInfo::EnumType>(enumValue);
|
||||
LOG_DEBUG("ENUM %s = %s", enumName.c_str(), enumValue.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ void EntityFileWriter::appentEntityComponents(xercesc::DOMElement* parentElement
|
||||
const int& value = c[fieldName];
|
||||
fieldElement->appendChild(doc->createTextNode(X(boost::lexical_cast<std::string>(value))));
|
||||
} else if (field.Type == "enum") {
|
||||
const int& value = c[fieldName];
|
||||
const ComponentInfo::EnumType& value = c[fieldName];
|
||||
auto& enumDef = c.Info.Meta->FieldEnumDefinitions.at(fieldName);
|
||||
for (auto& kv : enumDef) {
|
||||
if (kv.second == value) {
|
||||
|
||||
Reference in New Issue
Block a user