mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 19:30:41 +02:00
add EntityTypes::extractEntityTypeAndID(), remove one spaghetti
This commit is contained in:
parent
1815d71158
commit
0083c77280
4 changed files with 22 additions and 18 deletions
|
@ -93,7 +93,7 @@ void EntityItemProperties::setLastEdited(quint64 usecTime) {
|
||||||
|
|
||||||
bool EntityItemProperties::constructFromBuffer(const unsigned char* data, int dataLength) {
|
bool EntityItemProperties::constructFromBuffer(const unsigned char* data, int dataLength) {
|
||||||
ReadBitstreamToTreeParams args;
|
ReadBitstreamToTreeParams args;
|
||||||
EntityItemPointer tempEntity = EntityTypes::constructEntityItem(data, dataLength, args);
|
EntityItemPointer tempEntity = EntityTypes::constructEntityItem(data, dataLength);
|
||||||
if (!tempEntity) {
|
if (!tempEntity) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,7 +174,7 @@ int EntityTree::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
||||||
addToNeedsParentFixupList(entity);
|
addToNeedsParentFixupList(entity);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
entity = EntityTypes::constructEntityItem(dataAt, bytesLeftToRead, args);
|
entity = EntityTypes::constructEntityItem(dataAt, bytesLeftToRead);
|
||||||
if (entity) {
|
if (entity) {
|
||||||
bytesForThisEntity = entity->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args);
|
bytesForThisEntity = entity->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args);
|
||||||
|
|
||||||
|
|
|
@ -107,8 +107,7 @@ EntityItemPointer EntityTypes::constructEntityItem(EntityType entityType, const
|
||||||
return newEntityItem;
|
return newEntityItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityItemPointer EntityTypes::constructEntityItem(const unsigned char* data, int bytesToRead,
|
void EntityTypes::extractEntityTypeAndID(const unsigned char* data, int dataLength, EntityTypes::EntityType& typeOut, QUuid& idOut) {
|
||||||
ReadBitstreamToTreeParams& args) {
|
|
||||||
|
|
||||||
// Header bytes
|
// Header bytes
|
||||||
// object ID [16 bytes]
|
// object ID [16 bytes]
|
||||||
|
@ -119,28 +118,32 @@ EntityItemPointer EntityTypes::constructEntityItem(const unsigned char* data, in
|
||||||
// ~27-35 bytes...
|
// ~27-35 bytes...
|
||||||
const int MINIMUM_HEADER_BYTES = 27;
|
const int MINIMUM_HEADER_BYTES = 27;
|
||||||
|
|
||||||
|
if (dataLength >= MINIMUM_HEADER_BYTES) {
|
||||||
int bytesRead = 0;
|
int bytesRead = 0;
|
||||||
if (bytesToRead >= MINIMUM_HEADER_BYTES) {
|
QByteArray originalDataBuffer = QByteArray::fromRawData((const char*)data, dataLength);
|
||||||
int originalLength = bytesToRead;
|
|
||||||
QByteArray originalDataBuffer((const char*)data, originalLength);
|
|
||||||
|
|
||||||
// id
|
// id
|
||||||
QByteArray encodedID = originalDataBuffer.mid(bytesRead, NUM_BYTES_RFC4122_UUID); // maximum possible size
|
QByteArray encodedID = originalDataBuffer.mid(bytesRead, NUM_BYTES_RFC4122_UUID); // maximum possible size
|
||||||
QUuid actualID = QUuid::fromRfc4122(encodedID);
|
idOut = QUuid::fromRfc4122(encodedID);
|
||||||
bytesRead += encodedID.size();
|
bytesRead += encodedID.size();
|
||||||
|
|
||||||
// type
|
// type
|
||||||
QByteArray encodedType = originalDataBuffer.mid(bytesRead); // maximum possible size
|
QByteArray encodedType = originalDataBuffer.mid(bytesRead); // maximum possible size
|
||||||
ByteCountCoded<quint32> typeCoder = encodedType;
|
ByteCountCoded<quint32> typeCoder = encodedType;
|
||||||
encodedType = typeCoder; // determine true length
|
encodedType = typeCoder; // determine true length
|
||||||
bytesRead += encodedType.size();
|
|
||||||
quint32 type = typeCoder;
|
quint32 type = typeCoder;
|
||||||
EntityTypes::EntityType entityType = (EntityTypes::EntityType)type;
|
typeOut = (EntityTypes::EntityType)type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
EntityItemID tempEntityID(actualID);
|
EntityItemPointer EntityTypes::constructEntityItem(const unsigned char* data, int bytesToRead) {
|
||||||
|
QUuid id;
|
||||||
|
EntityTypes::EntityType type = EntityTypes::Unknown;
|
||||||
|
extractEntityTypeAndID(data, bytesToRead, type, id);
|
||||||
|
if (type > EntityTypes::Unknown && type <= EntityTypes::LAST) {
|
||||||
|
EntityItemID tempEntityID(id);
|
||||||
EntityItemProperties tempProperties;
|
EntityItemProperties tempProperties;
|
||||||
return constructEntityItem(entityType, tempEntityID, tempProperties);
|
return constructEntityItem(type, tempEntityID, tempProperties);
|
||||||
}
|
}
|
||||||
|
return nullptr;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,8 +112,9 @@ public:
|
||||||
static const QString& getEntityTypeName(EntityType entityType);
|
static const QString& getEntityTypeName(EntityType entityType);
|
||||||
static EntityTypes::EntityType getEntityTypeFromName(const QString& name);
|
static EntityTypes::EntityType getEntityTypeFromName(const QString& name);
|
||||||
static bool registerEntityType(EntityType entityType, const char* name, EntityTypeFactory factoryMethod);
|
static bool registerEntityType(EntityType entityType, const char* name, EntityTypeFactory factoryMethod);
|
||||||
|
static void extractEntityTypeAndID(const unsigned char* data, int dataLength, EntityTypes::EntityType& typeOut, QUuid& idOut);
|
||||||
static EntityItemPointer constructEntityItem(EntityType entityType, const EntityItemID& entityID, const EntityItemProperties& properties);
|
static EntityItemPointer constructEntityItem(EntityType entityType, const EntityItemID& entityID, const EntityItemProperties& properties);
|
||||||
static EntityItemPointer constructEntityItem(const unsigned char* data, int bytesToRead, ReadBitstreamToTreeParams& args);
|
static EntityItemPointer constructEntityItem(const unsigned char* data, int bytesToRead);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QMap<EntityType, QString> _typeToNameMap;
|
static QMap<EntityType, QString> _typeToNameMap;
|
||||||
|
|
Loading…
Reference in a new issue