From 6b62c6b9764fd2d2348b511f7ca60ee26dcdadea Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 17 Jul 2014 11:16:03 -0700 Subject: [PATCH] get virtual entities constructing from buffers --- libraries/entities/src/EntityTreeElement.cpp | 44 +---------------- libraries/entities/src/EntityTreeElement.h | 11 ----- libraries/entities/src/EntityTypes.cpp | 51 +++++++++++++++++++- libraries/entities/src/EntityTypes.h | 4 +- 4 files changed, 52 insertions(+), 58 deletions(-) diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index f78ece0642..f3e48443d2 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -455,48 +455,6 @@ void EntityTreeElement::updateEntityItemID(const EntityItemID& creatorTokenEntit } } -/* -void EntityTreeElement::updateEntityItemID(FindAndUpdateEntityItemIDArgs* args) { - bool wantDebug = false; - uint16_t numberOfEntities = _entityItems->size(); - for (uint16_t i = 0; i < numberOfEntities; i++) { - EntityItem* thisEntity = (*_entityItems)[i]; - - if (!args->creatorTokenFound) { - // first, we're looking for matching creatorTokenIDs, if we find that, then we fix it to know the actual ID - if (thisEntity->getCreatorTokenID() == args->creatorTokenID) { - if (wantDebug) { - qDebug() << "EntityTreeElement::updateEntityItemID()... found the entity... updating it's ID... " - << "creatorTokenID=" << args->creatorTokenID - << "entityID=" << args->entityID; - } - - thisEntity->setID(args->entityID); - args->creatorTokenFound = true; - } - } - - // if we're in an isViewing tree, we also need to look for an kill any viewed entities - if (!args->viewedEntityFound && args->isViewing) { - if (thisEntity->getCreatorTokenID() == UNKNOWN_ENTITY_TOKEN && thisEntity->getID() == args->entityID) { - - if (wantDebug) { - qDebug() << "EntityTreeElement::updateEntityItemID()... VIEWED entity FOUND??? " - << "args->creatorTokenID=" << args->creatorTokenID - << "thisEntity->getCreatorTokenID()=" << thisEntity->getCreatorTokenID() - << "args->entityID=" << args->entityID; - } - - _entityItems->removeAt(i); // remove the entity at this index - numberOfEntities--; // this means we have 1 fewer entity in this list - i--; // and we actually want to back up i as well. - args->viewedEntityFound = true; - } - } - } -} -*/ - const EntityItem* EntityTreeElement::getClosestEntity(glm::vec3 position) const { const EntityItem* closestEntity = NULL; float closestEntityDistance = FLT_MAX; @@ -666,7 +624,7 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int _myTree->rememberDirtyCube(existingEntityCube); bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args); } else { - entityItem = EntityTypes::constructEntityItem(dataAt, bytesLeftToRead); + entityItem = EntityTypes::constructEntityItem(dataAt, bytesLeftToRead, args); if (entityItem) { bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args); diff --git a/libraries/entities/src/EntityTreeElement.h b/libraries/entities/src/EntityTreeElement.h index ae2e73da4b..570c81f707 100644 --- a/libraries/entities/src/EntityTreeElement.h +++ b/libraries/entities/src/EntityTreeElement.h @@ -35,16 +35,6 @@ public: int _movingItems; }; -class FindAndUpdateEntityItemIDArgs { -public: - uint32_t entityID; - uint32_t creatorTokenID; - bool creatorTokenFound; - bool viewedEntityFound; - bool isViewing; -}; - - class EntityTreeElementExtraEncodeData { public: QMap includedItems; @@ -125,7 +115,6 @@ public: void addEntityItem(EntityItem* entity); - //void updateEntityItemID(FindAndUpdateEntityItemIDArgs* args); void updateEntityItemID(const EntityItemID& creatorTokenEntityID, const EntityItemID& knownIDEntityID); const EntityItem* getClosestEntity(glm::vec3 position) const; diff --git a/libraries/entities/src/EntityTypes.cpp b/libraries/entities/src/EntityTypes.cpp index 316f436e2c..d4de946d61 100644 --- a/libraries/entities/src/EntityTypes.cpp +++ b/libraries/entities/src/EntityTypes.cpp @@ -12,6 +12,7 @@ #include #include +#include #include "EntityItem.h" #include "EntityItemProperties.h" @@ -75,9 +76,55 @@ EntityItem* EntityTypes::constructEntityItem(EntityType_t entityType, const Enti return newEntityItem; } -EntityItem* EntityTypes::constructEntityItem(const unsigned char* data, int bytesToRead) { +EntityItem* EntityTypes::constructEntityItem(const unsigned char* data, int bytesToRead, + ReadBitstreamToTreeParams& args) { -qDebug() << "EntityTypes::constructEntityItem(const unsigned char* data, int bytesToRead).... CALLED BUT NOT IMPLEMENTED!!!"; + //qDebug() << "EntityTypes::constructEntityItem(const unsigned char* data, int bytesToRead).... CALLED BUT NOT IMPLEMENTED!!!"; + + if (args.bitstreamVersion < VERSION_ENTITIES_SUPPORT_SPLIT_MTU) { + qDebug() << "EntityTypes::constructEntityItem(const unsigned char* data, int bytesToRead).... OLD BITSTREAM!!!"; + + EntityItemID tempEntityID; + EntityItemProperties tempProperties; + return new ModelEntityItem(tempEntityID, tempProperties); + } + + // Header bytes + // object ID [16 bytes] + // ByteCountCoded(type code) [~1 byte] + // last edited [8 bytes] + // ByteCountCoded(last_edited to last_updated delta) [~1-8 bytes] + // PropertyFlags<>( everything ) [1-2 bytes] + // ~27-35 bytes... + const int MINIMUM_HEADER_BYTES = 27; // TODO: this is not correct, we don't yet have 16 byte IDs + + int bytesRead = 0; + if (bytesToRead >= MINIMUM_HEADER_BYTES) { + int originalLength = bytesToRead; + QByteArray originalDataBuffer((const char*)data, originalLength); + + // id + QByteArray encodedID = originalDataBuffer.mid(bytesRead); // maximum possible size + ByteCountCoded idCoder = encodedID; + encodedID = idCoder; // determine true length + bytesRead += encodedID.size(); + + // type + QByteArray encodedType = originalDataBuffer.mid(bytesRead); // maximum possible size + ByteCountCoded typeCoder = encodedType; + encodedType = typeCoder; // determine true length + bytesRead += encodedType.size(); + quint32 type = typeCoder; + EntityTypes::EntityType_t entityType = (EntityTypes::EntityType_t)type; + + EntityItemID tempEntityID; + EntityItemProperties tempProperties; + + qDebug() << "EntityTypes::constructEntityItem(data, bytesToRead).... NEW BITSTREAM!!! entityType=" << entityType; + + return constructEntityItem(entityType, tempEntityID, tempProperties); + } + return NULL; // TODO Implement this for real! } diff --git a/libraries/entities/src/EntityTypes.h b/libraries/entities/src/EntityTypes.h index 2e9fe81f92..de2e398d6b 100644 --- a/libraries/entities/src/EntityTypes.h +++ b/libraries/entities/src/EntityTypes.h @@ -20,7 +20,7 @@ class EntityItem; class EntityItemID; class EntityItemProperties; - +class ReadBitstreamToTreeParams; class EntityTypes { public: @@ -40,7 +40,7 @@ public: static EntityTypes::EntityType_t getEntityTypeFromName(const QString& name); static EntityItem* constructEntityItem(EntityType_t entityType, const EntityItemID& entityID, const EntityItemProperties& properties); - static EntityItem* constructEntityItem(const unsigned char* data, int bytesToRead); + static EntityItem* constructEntityItem(const unsigned char* data, int bytesToRead, ReadBitstreamToTreeParams& args); static bool decodeEntityEditPacket(const unsigned char* data, int bytesToRead, int& processedBytes, EntityItemID& entityID, EntityItemProperties& properties); private: