convert IDs to UUIDs

This commit is contained in:
ZappoMan 2014-08-07 17:02:11 -07:00
parent 2a65de8026
commit 6f479a1026
17 changed files with 160 additions and 123 deletions

View file

@ -64,8 +64,9 @@ qDebug() << "EntityServer::entityCreated() newEntity.getEntityItemID()=" << newE
packetLength += sizeof(creatorTokenID); packetLength += sizeof(creatorTokenID);
// encode the entity ID // encode the entity ID
uint32_t entityID = newEntity.getID(); QUuid entityID = newEntity.getID();
memcpy(copyAt, &entityID, sizeof(entityID)); QByteArray encodedID = entityID.toRfc4122();
memcpy(copyAt, encodedID.constData(), encodedID.size());
copyAt += sizeof(entityID); copyAt += sizeof(entityID);
packetLength += sizeof(entityID); packetLength += sizeof(entityID);

View file

@ -131,7 +131,7 @@ Model* EntityTreeRenderer::getModel(const ModelEntityItem* modelEntityItem) {
if (QUrl(modelEntityItem->getModelURL()) != model->getURL()) { if (QUrl(modelEntityItem->getModelURL()) != model->getURL()) {
delete model; // delete the old model... delete model; // delete the old model...
model = NULL; model = NULL;
_unknownEntityItemModels.remove(modelEntityItem->getID()); _unknownEntityItemModels.remove(modelEntityItem->getCreatorTokenID());
} }
} }

View file

@ -65,7 +65,7 @@ public:
protected: protected:
void clearModelsCache(); void clearModelsCache();
QMap<uint32_t, Model*> _knownEntityItemModels; QMap<QUuid, Model*> _knownEntityItemModels;
QMap<uint32_t, Model*> _unknownEntityItemModels; QMap<uint32_t, Model*> _unknownEntityItemModels;
}; };

View file

@ -112,14 +112,12 @@ qDebug() << "BoxEntityItem::readEntityDataFromBuffer()... <<<<<<<<<<<<<<<< <<<<
const unsigned char* dataAt = data; const unsigned char* dataAt = data;
// id // id
QByteArray encodedID = originalDataBuffer.mid(bytesRead); // maximum possible size QByteArray encodedID = originalDataBuffer.mid(bytesRead, NUM_BYTES_RFC4122_UUID); // maximum possible size
ByteCountCoded<quint32> idCoder = encodedID; _id = QUuid::fromRfc4122(encodedID);
encodedID = idCoder; // determine true length
dataAt += encodedID.size();
bytesRead += encodedID.size();
_id = idCoder;
_creatorTokenID = UNKNOWN_ENTITY_TOKEN; // if we know the id, then we don't care about the creator token _creatorTokenID = UNKNOWN_ENTITY_TOKEN; // if we know the id, then we don't care about the creator token
_newlyCreated = false; _newlyCreated = false;
dataAt += encodedID.size();
bytesRead += encodedID.size();
// type // type
QByteArray encodedType = originalDataBuffer.mid(bytesRead); // maximum possible size QByteArray encodedType = originalDataBuffer.mid(bytesRead); // maximum possible size
@ -267,8 +265,8 @@ qDebug() << "BoxEntityItem::appendEntityData()... ******************************
OctreeElement::AppendState appendState = OctreeElement::COMPLETED; // assume the best OctreeElement::AppendState appendState = OctreeElement::COMPLETED; // assume the best
// encode our ID as a byte count coded byte stream // encode our ID as a byte count coded byte stream
ByteCountCoded<quint32> idCoder = getID(); //ByteCountCoded<quint32> idCoder = getID();
QByteArray encodedID = idCoder; QByteArray encodedID = getID().toRfc4122();
// encode our type as a byte count coded byte stream // encode our type as a byte count coded byte stream

View file

@ -70,8 +70,7 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet
OctreeElement::AppendState appendState = OctreeElement::COMPLETED; // assume the best OctreeElement::AppendState appendState = OctreeElement::COMPLETED; // assume the best
// encode our ID as a byte count coded byte stream // encode our ID as a byte count coded byte stream
ByteCountCoded<quint32> idCoder = getID(); QByteArray encodedID = getID().toRfc4122();
QByteArray encodedID = idCoder;
// encode our type as a byte count coded byte stream // encode our type as a byte count coded byte stream
ByteCountCoded<quint32> typeCoder = getType(); ByteCountCoded<quint32> typeCoder = getType();
@ -389,7 +388,9 @@ qDebug() << "EntityItem::appendEntityData() ... lastEdited=" << lastEdited;
return appendState; return appendState;
} }
// TODO: correct this to reflect changes...
int EntityItem::expectedBytes() { int EntityItem::expectedBytes() {
int expectedBytes = sizeof(uint32_t) // id int expectedBytes = sizeof(uint32_t) // id
+ sizeof(float) // age + sizeof(float) // age
+ sizeof(quint64) // last updated + sizeof(quint64) // last updated
@ -402,21 +403,6 @@ int EntityItem::expectedBytes() {
} }
EntityItemID EntityItem::readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead,
ReadBitstreamToTreeParams& args) {
EntityItemID result;
if (bytesLeftToRead >= sizeof(uint32_t)) {
// id
QByteArray encodedID((const char*)data, bytesLeftToRead);
ByteCountCoded<quint32> idCoder = encodedID;
quint32 id = idCoder;
result.id = id;
result.isKnownID = true;
result.creatorTokenID = UNKNOWN_ENTITY_TOKEN;
}
return result;
}
int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) { int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) {
if (args.bitstreamVersion < VERSION_ENTITIES_SUPPORT_SPLIT_MTU) { if (args.bitstreamVersion < VERSION_ENTITIES_SUPPORT_SPLIT_MTU) {
@ -444,14 +430,20 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
const unsigned char* dataAt = data; const unsigned char* dataAt = data;
// id // id
QByteArray encodedID = originalDataBuffer.mid(bytesRead); // maximum possible size QByteArray encodedID = originalDataBuffer.mid(bytesRead, NUM_BYTES_RFC4122_UUID); // maximum possible size
_id = QUuid::fromRfc4122(encodedID);
_creatorTokenID = UNKNOWN_ENTITY_TOKEN; // if we know the id, then we don't care about the creator token
_newlyCreated = false;
dataAt += encodedID.size();
bytesRead += encodedID.size();
/**
ByteCountCoded<quint32> idCoder = encodedID; ByteCountCoded<quint32> idCoder = encodedID;
encodedID = idCoder; // determine true length encodedID = idCoder; // determine true length
dataAt += encodedID.size(); dataAt += encodedID.size();
bytesRead += encodedID.size(); bytesRead += encodedID.size();
_id = idCoder; _id = idCoder;
_creatorTokenID = UNKNOWN_ENTITY_TOKEN; // if we know the id, then we don't care about the creator token **/
_newlyCreated = false;
// type // type
QByteArray encodedType = originalDataBuffer.mid(bytesRead); // maximum possible size QByteArray encodedType = originalDataBuffer.mid(bytesRead); // maximum possible size
@ -462,13 +454,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
quint32 type = typeCoder; quint32 type = typeCoder;
_type = (EntityTypes::EntityType)type; _type = (EntityTypes::EntityType)type;
// XXXBHG: is this a good place to handle the last edited time client vs server??
// If the edit time encoded in the packet is NEWER than our known edit time...
// then we WANT to over-write our local data.
// If the edit time encoded in the packet is OLDER than our known edit time...
// then we WANT to preserve our local data. (NOTE: what if I change color, and you change position?? last one wins!)
bool overwriteLocalData = true; // assume the new content overwrites our local data bool overwriteLocalData = true; // assume the new content overwrites our local data
quint64 lastEditedFromBuffer = 0; quint64 lastEditedFromBuffer = 0;
@ -696,8 +681,11 @@ bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID
// id // id
// encode our ID as a byte count coded byte stream // encode our ID as a byte count coded byte stream
/*
ByteCountCoded<quint32> idCoder = id.id; ByteCountCoded<quint32> idCoder = id.id;
QByteArray encodedID = idCoder; QByteArray encodedID = idCoder;
*/
QByteArray encodedID = id.id.toRfc4122(); // NUM_BYTES_RFC4122_UUID
// encode our ID as a byte count coded byte stream // encode our ID as a byte count coded byte stream
ByteCountCoded<quint32> tokenCoder; ByteCountCoded<quint32> tokenCoder;

View file

@ -38,8 +38,8 @@ public:
virtual void somePureVirtualFunction() = 0; virtual void somePureVirtualFunction() = 0;
// ID and EntityItemID related methods // ID and EntityItemID related methods
uint32_t getID() const { return _id; } QUuid getID() const { return _id; }
void setID(uint32_t id) { _id = id; } void setID(const QUuid& id) { _id = id; }
uint32_t getCreatorTokenID() const { return _creatorTokenID; } uint32_t getCreatorTokenID() const { return _creatorTokenID; }
void setCreatorTokenID(uint32_t creatorTokenID) { _creatorTokenID = creatorTokenID; } void setCreatorTokenID(uint32_t creatorTokenID) { _creatorTokenID = creatorTokenID; }
bool isNewlyCreated() const { return _newlyCreated; } bool isNewlyCreated() const { return _newlyCreated; }
@ -114,8 +114,8 @@ public:
protected: protected:
virtual void initFromEntityItemID(const EntityItemID& entityItemID); // maybe useful to allow subclasses to init virtual void initFromEntityItemID(const EntityItemID& entityItemID); // maybe useful to allow subclasses to init
quint32 _id;
EntityTypes::EntityType _type; EntityTypes::EntityType _type;
QUuid _id;
uint32_t _creatorTokenID; uint32_t _creatorTokenID;
bool _newlyCreated; bool _newlyCreated;
quint64 _lastUpdated; quint64 _lastUpdated;

View file

@ -16,10 +16,10 @@
#include "EntityItemID.h" #include "EntityItemID.h"
uint32_t EntityItemID::_nextID = 0; // TODO: should be changed to UUID //uint32_t EntityItemID::_nextID = 0; // TODO: should be changed to UUID
// for locally created models // for locally created models
std::map<uint32_t,uint32_t> EntityItemID::_tokenIDsToIDs; QHash<uint32_t, QUuid> EntityItemID::_tokenIDsToIDs;
uint32_t EntityItemID::_nextCreatorTokenID = 0; uint32_t EntityItemID::_nextCreatorTokenID = 0;
@ -42,7 +42,7 @@ EntityItemID::EntityItemID(const EntityItemID& other) :
} }
EntityItemID::EntityItemID(uint32_t id, uint32_t creatorTokenID, bool isKnownID) : EntityItemID::EntityItemID(const QUuid& id, uint32_t creatorTokenID, bool isKnownID) :
id(id), id(id),
creatorTokenID(creatorTokenID), creatorTokenID(creatorTokenID),
isKnownID(isKnownID) isKnownID(isKnownID)
@ -51,7 +51,7 @@ EntityItemID::EntityItemID(uint32_t id, uint32_t creatorTokenID, bool isKnownID)
// << isKnownID << "id=" << id << "creatorTokenID=" << creatorTokenID; // << isKnownID << "id=" << id << "creatorTokenID=" << creatorTokenID;
}; };
EntityItemID::EntityItemID(uint32_t id) : EntityItemID::EntityItemID(const QUuid& id) :
id(id), id(id),
creatorTokenID(UNKNOWN_ENTITY_TOKEN), creatorTokenID(UNKNOWN_ENTITY_TOKEN),
isKnownID(true) isKnownID(true)
@ -60,11 +60,11 @@ EntityItemID::EntityItemID(uint32_t id) :
// << isKnownID << "id=" << id << "creatorTokenID=" << creatorTokenID; // << isKnownID << "id=" << id << "creatorTokenID=" << creatorTokenID;
}; };
uint32_t EntityItemID::getIDfromCreatorTokenID(uint32_t creatorTokenID) { EntityItemID EntityItemID::getIDfromCreatorTokenID(uint32_t creatorTokenID) {
if (_tokenIDsToIDs.find(creatorTokenID) != _tokenIDsToIDs.end()) { if (_tokenIDsToIDs.find(creatorTokenID) != _tokenIDsToIDs.end()) {
return _tokenIDsToIDs[creatorTokenID]; return EntityItemID(_tokenIDsToIDs[creatorTokenID], creatorTokenID, true);
} }
return UNKNOWN_ENTITY_ID; return EntityItemID(UNKNOWN_ENTITY_ID);
} }
uint32_t EntityItemID::getNextCreatorTokenID() { uint32_t EntityItemID::getNextCreatorTokenID() {
@ -78,8 +78,8 @@ EntityItemID EntityItemID::assignActualIDForToken() const {
newlyAssignedEntityID.creatorTokenID = creatorTokenID; newlyAssignedEntityID.creatorTokenID = creatorTokenID;
newlyAssignedEntityID.isKnownID = true; newlyAssignedEntityID.isKnownID = true;
newlyAssignedEntityID.id = _nextID; newlyAssignedEntityID.id = QUuid::createUuid();
_nextID++; //_nextID++;
return newlyAssignedEntityID; return newlyAssignedEntityID;
} }
@ -104,41 +104,58 @@ EntityItemID EntityItemID::convertToCreatorTokenVersion() const {
return knownIDVersionEntityID; return knownIDVersionEntityID;
} }
EntityItemID EntityItemID::readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead) {
EntityItemID result;
if (bytesLeftToRead >= NUM_BYTES_RFC4122_UUID) {
// id
QByteArray encodedID((const char*)data, NUM_BYTES_RFC4122_UUID);
result.id = QUuid::fromRfc4122(encodedID);
result.isKnownID = true;
result.creatorTokenID = UNKNOWN_ENTITY_TOKEN;
}
return result;
}
void EntityItemID::handleAddEntityResponse(const QByteArray& packet) { void EntityItemID::handleAddEntityResponse(const QByteArray& packet) {
qDebug() << "EntityItemID::handleAddEntityResponse()..."; qDebug() << "EntityItemID::handleAddEntityResponse()...";
const unsigned char* dataAt = reinterpret_cast<const unsigned char*>(packet.data()); const unsigned char* dataAt = reinterpret_cast<const unsigned char*>(packet.data());
int numBytesPacketHeader = numBytesForPacketHeader(packet); int numBytesPacketHeader = numBytesForPacketHeader(packet);
int bytesRead = numBytesPacketHeader;
dataAt += numBytesPacketHeader; dataAt += numBytesPacketHeader;
uint32_t creatorTokenID; uint32_t creatorTokenID;
memcpy(&creatorTokenID, dataAt, sizeof(creatorTokenID)); memcpy(&creatorTokenID, dataAt, sizeof(creatorTokenID));
dataAt += sizeof(creatorTokenID); dataAt += sizeof(creatorTokenID);
bytesRead += sizeof(creatorTokenID);
uint32_t entityItemID; QUuid entityID = QUuid::fromRfc4122(packet.mid(bytesRead, NUM_BYTES_RFC4122_UUID));
memcpy(&entityItemID, dataAt, sizeof(entityItemID)); dataAt += NUM_BYTES_RFC4122_UUID;
dataAt += sizeof(entityItemID);
qDebug() << "EntityItemID::handleAddEntityResponse()... entityItemID=" << entityItemID << "creatorTokenID=" << creatorTokenID; qDebug() << "EntityItemID::handleAddEntityResponse()... entityID=" << entityID << "creatorTokenID=" << creatorTokenID;
// add our token to id mapping // add our token to id mapping
_tokenIDsToIDs[creatorTokenID] = entityItemID; _tokenIDsToIDs[creatorTokenID] = entityID;
} }
QScriptValue EntityItemIDtoScriptValue(QScriptEngine* engine, const EntityItemID& id) { QScriptValue EntityItemIDtoScriptValue(QScriptEngine* engine, const EntityItemID& id) {
QScriptValue obj = engine->newObject(); QScriptValue obj = engine->newObject();
obj.setProperty("id", id.id); obj.setProperty("id", id.id.toString());
obj.setProperty("creatorTokenID", id.creatorTokenID); obj.setProperty("creatorTokenID", id.creatorTokenID);
obj.setProperty("isKnownID", id.isKnownID); obj.setProperty("isKnownID", id.isKnownID);
return obj; return obj;
} }
void EntityItemIDfromScriptValue(const QScriptValue &object, EntityItemID& id) { void EntityItemIDfromScriptValue(const QScriptValue &object, EntityItemID& id) {
id.id = object.property("id").toVariant().toUInt(); id.id = QUuid(object.property("id").toVariant().toString());
id.creatorTokenID = object.property("creatorTokenID").toVariant().toUInt(); id.creatorTokenID = object.property("creatorTokenID").toVariant().toUInt();
id.isKnownID = object.property("isKnownID").toVariant().toBool(); id.isKnownID = object.property("isKnownID").toVariant().toBool();
} }

View file

@ -14,12 +14,19 @@
#include <stdint.h> #include <stdint.h>
#include <QtScript/QScriptEngine>
#include <QtCore/QObject>
const uint32_t NEW_ENTITY = 0xFFFFFFFF; #include <QObject>
#include <QHash>
#include <QScriptEngine>
#include <QUuid>
const uint32_t UNKNOWN_ENTITY_TOKEN = 0xFFFFFFFF; const uint32_t UNKNOWN_ENTITY_TOKEN = 0xFFFFFFFF;
const uint32_t UNKNOWN_ENTITY_ID = 0xFFFFFFFF;
//const uint32_t NEW_ENTITY = 0xFFFFFFFF;
//const uint32_t UNKNOWN_ENTITY_ID = 0xFFFFFFFF;
const QUuid NEW_ENTITY;
const QUuid UNKNOWN_ENTITY_ID;
/// Abstract ID for editing model items. Used in EntityItem JS API - When models are created in the JS api, they are given a /// Abstract ID for editing model items. Used in EntityItem JS API - When models are created in the JS api, they are given a
@ -29,10 +36,12 @@ class EntityItemID {
public: public:
EntityItemID(); EntityItemID();
EntityItemID(const EntityItemID& other); EntityItemID(const EntityItemID& other);
EntityItemID(uint32_t id, uint32_t creatorTokenID, bool isKnownID); EntityItemID(const QUuid& id, uint32_t creatorTokenID, bool isKnownID);
EntityItemID(uint32_t id); EntityItemID(const QUuid& id);
uint32_t id; //uint32_t id;
QUuid id;
uint32_t creatorTokenID; uint32_t creatorTokenID;
bool isKnownID; bool isKnownID;
@ -41,17 +50,19 @@ public:
EntityItemID convertToCreatorTokenVersion() const; EntityItemID convertToCreatorTokenVersion() const;
// these methods allow you to create models, and later edit them. // these methods allow you to create models, and later edit them.
static uint32_t getIDfromCreatorTokenID(uint32_t creatorTokenID); //static uint32_t getIDfromCreatorTokenID(uint32_t creatorTokenID);
static EntityItemID getIDfromCreatorTokenID(uint32_t creatorTokenID);
static uint32_t getNextCreatorTokenID(); static uint32_t getNextCreatorTokenID();
static void handleAddEntityResponse(const QByteArray& packet); static void handleAddEntityResponse(const QByteArray& packet);
static EntityItemID readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead);
private: private:
friend class EntityTree; friend class EntityTree;
EntityItemID assignActualIDForToken() const; // only called by EntityTree EntityItemID assignActualIDForToken() const; // only called by EntityTree
static quint32 _nextID;
static uint32_t _nextCreatorTokenID; /// used by the static interfaces for creator token ids static uint32_t _nextCreatorTokenID; /// used by the static interfaces for creator token ids
static std::map<uint32_t,uint32_t> _tokenIDsToIDs; static QHash<uint32_t, QUuid> _tokenIDsToIDs;
}; };
inline bool operator<(const EntityItemID& a, const EntityItemID& b) { inline bool operator<(const EntityItemID& a, const EntityItemID& b) {
@ -66,9 +77,9 @@ inline bool operator==(const EntityItemID& a, const EntityItemID& b) {
} }
inline uint qHash(const EntityItemID& a, uint seed) { inline uint qHash(const EntityItemID& a, uint seed) {
qint64 temp; QUuid temp;
if (a.id == UNKNOWN_ENTITY_ID) { if (a.id == UNKNOWN_ENTITY_ID) {
temp = -a.creatorTokenID; temp = QUuid(a.creatorTokenID,0,0,0,0,0,0,0,0,0,0);
} else { } else {
temp = a.id; temp = a.id;
} }

View file

@ -111,7 +111,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons
QScriptValue properties = engine->newObject(); QScriptValue properties = engine->newObject();
if (_idSet) { if (_idSet) {
properties.setProperty("id", _id); properties.setProperty("id", _id.toString());
bool isKnownID = (_id != UNKNOWN_ENTITY_ID); bool isKnownID = (_id != UNKNOWN_ENTITY_ID);
properties.setProperty("isKnownID", isKnownID); properties.setProperty("isKnownID", isKnownID);
//qDebug() << "EntityItemProperties::copyToScriptValue()... isKnownID=" << isKnownID << "id=" << _id; //qDebug() << "EntityItemProperties::copyToScriptValue()... isKnownID=" << isKnownID << "id=" << _id;

View file

@ -166,7 +166,7 @@ private:
EntityItemID& entityID, EntityItemProperties& properties); EntityItemID& entityID, EntityItemProperties& properties);
void setLastEdited(quint64 lastEdited) { _lastEdited = lastEdited; } void setLastEdited(quint64 lastEdited) { _lastEdited = lastEdited; }
quint32 _id; QUuid _id;
bool _idSet; bool _idSet;
quint64 _lastEdited; quint64 _lastEdited;

View file

@ -45,7 +45,7 @@ EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& pro
} }
EntityItemID EntityScriptingInterface::identifyEntity(EntityItemID entityID) { EntityItemID EntityScriptingInterface::identifyEntity(EntityItemID entityID) {
uint32_t actualID = entityID.id; EntityItemID actualID = entityID;
if (!entityID.isKnownID) { if (!entityID.isKnownID) {
actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID); actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID);
@ -54,7 +54,7 @@ EntityItemID EntityScriptingInterface::identifyEntity(EntityItemID entityID) {
} }
// found it! // found it!
entityID.id = actualID; entityID.id = actualID.id;
entityID.isKnownID = true; entityID.isKnownID = true;
qDebug() << "EntityScriptingInterface::identifyEntity() ...found it... isKnownID=" << entityID.isKnownID << "id=" << entityID.id << "creatorTokenID=" << entityID.creatorTokenID; qDebug() << "EntityScriptingInterface::identifyEntity() ...found it... isKnownID=" << entityID.isKnownID << "id=" << entityID.id << "creatorTokenID=" << entityID.creatorTokenID;
} }
@ -70,7 +70,7 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID
} }
if (_entityTree) { if (_entityTree) {
_entityTree->lockForRead(); _entityTree->lockForRead();
EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByID(identity.id, true)); EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(identity));
if (entity) { if (entity) {
// TODO: look into sitting points!!! // TODO: look into sitting points!!!
@ -89,7 +89,7 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID
EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const EntityItemProperties& properties) { EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const EntityItemProperties& properties) {
uint32_t actualID = entityID.id; EntityItemID actualID = entityID;
// if the model is unknown, attempt to look it up // if the model is unknown, attempt to look it up
if (!entityID.isKnownID) { if (!entityID.isKnownID) {
@ -97,8 +97,8 @@ EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const E
} }
// if at this point, we know the id, send the update to the model server // if at this point, we know the id, send the update to the model server
if (actualID != UNKNOWN_ENTITY_ID) { if (actualID.id != UNKNOWN_ENTITY_ID) {
entityID.id = actualID; entityID.id = actualID.id;
entityID.isKnownID = true; entityID.isKnownID = true;
//qDebug() << "EntityScriptingInterface::editEntity()... isKnownID=" << entityID.isKnownID << "id=" << entityID.id << "creatorTokenID=" << entityID.creatorTokenID; //qDebug() << "EntityScriptingInterface::editEntity()... isKnownID=" << entityID.isKnownID << "id=" << entityID.id << "creatorTokenID=" << entityID.creatorTokenID;
queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties);
@ -127,7 +127,7 @@ void EntityScriptingInterface::deleteEntity(EntityItemID entityID) {
EntityItemProperties properties; EntityItemProperties properties;
properties.setShouldBeDeleted(true); properties.setShouldBeDeleted(true);
uint32_t actualID = entityID.id; EntityItemID actualID = entityID;
// if the model is unknown, attempt to look it up // if the model is unknown, attempt to look it up
if (!entityID.isKnownID) { if (!entityID.isKnownID) {
@ -135,8 +135,8 @@ void EntityScriptingInterface::deleteEntity(EntityItemID entityID) {
} }
// if at this point, we know the id, send the update to the model server // if at this point, we know the id, send the update to the model server
if (actualID != UNKNOWN_ENTITY_ID) { if (actualID.id != UNKNOWN_ENTITY_ID) {
entityID.id = actualID; entityID.id = actualID.id;
entityID.isKnownID = true; entityID.isKnownID = true;
//qDebug() << "EntityScriptingInterface::deleteEntity()... isKnownID=" << entityID.isKnownID << "id=" << entityID.id << "creatorTokenID=" << entityID.creatorTokenID; //qDebug() << "EntityScriptingInterface::deleteEntity()... isKnownID=" << entityID.isKnownID << "id=" << entityID.id << "creatorTokenID=" << entityID.creatorTokenID;
queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties);

View file

@ -412,6 +412,7 @@ EntityItem* EntityTree::addEntity(const EntityItemID& entityID, const EntityItem
// You should not call this on existing entities that are already part of the tree! Call updateEntity() // You should not call this on existing entities that are already part of the tree! Call updateEntity()
EntityTreeElement* containingElement = getContainingElement(entityID); EntityTreeElement* containingElement = getContainingElement(entityID);
if (containingElement) { if (containingElement) {
qDebug() << "UNEXPECTED!!! ----- EntityTree::addEntity()... entityID=" << entityID << "containingElement=" << containingElement;
assert(containingElement == NULL); // don't call addEntity() on existing entity items assert(containingElement == NULL); // don't call addEntity() on existing entity items
return result; return result;
} }
@ -769,19 +770,20 @@ void EntityTree::handleAddEntityResponse(const QByteArray& packet) {
qDebug() << "UNEXPECTED!!! EntityTree::handleAddEntityResponse() with !getIsClient() ***"; qDebug() << "UNEXPECTED!!! EntityTree::handleAddEntityResponse() with !getIsClient() ***";
} }
const bool wantDebug = true; const unsigned char* dataAt = reinterpret_cast<const unsigned char*>(packet.data());
int numBytesPacketHeader = numBytesForPacketHeader(packet); int numBytesPacketHeader = numBytesForPacketHeader(packet);
int bytesRead = numBytesPacketHeader;
const unsigned char* dataAt = reinterpret_cast<const unsigned char*>(packet.data()) + numBytesPacketHeader; dataAt += numBytesPacketHeader;
uint32_t creatorTokenID; uint32_t creatorTokenID;
memcpy(&creatorTokenID, dataAt, sizeof(creatorTokenID)); memcpy(&creatorTokenID, dataAt, sizeof(creatorTokenID));
dataAt += sizeof(creatorTokenID); dataAt += sizeof(creatorTokenID);
bytesRead += sizeof(creatorTokenID);
uint32_t entityID; QUuid entityID = QUuid::fromRfc4122(packet.mid(bytesRead, NUM_BYTES_RFC4122_UUID));
memcpy(&entityID, dataAt, sizeof(entityID)); dataAt += NUM_BYTES_RFC4122_UUID;
dataAt += sizeof(entityID);
qDebug() << "EntityTree::handleAddEntityResponse()... entityID=" << entityID << "creatorTokenID=" << creatorTokenID;
// TODO: do we want callers to lock the tree before using this method??? // TODO: do we want callers to lock the tree before using this method???
@ -792,6 +794,7 @@ void EntityTree::handleAddEntityResponse(const QByteArray& packet) {
lockForWrite(); lockForWrite();
bool wantDebug = false;
if (wantDebug) { if (wantDebug) {
qDebug() << "EntityTree::handleAddEntityResponse()..."; qDebug() << "EntityTree::handleAddEntityResponse()...";
qDebug() << " creatorTokenID=" << creatorTokenID; qDebug() << " creatorTokenID=" << creatorTokenID;
@ -925,6 +928,7 @@ void EntityTree::findEntities(const AACube& cube, QVector<EntityItem*> foundEnti
foundEntities.swap(args._foundEntities); foundEntities.swap(args._foundEntities);
} }
#if 0 ///////////////////////////////////
EntityItem* EntityTree::findEntityByID(uint32_t id, bool alreadyLocked) /*const*/ { EntityItem* EntityTree::findEntityByID(uint32_t id, bool alreadyLocked) /*const*/ {
EntityItemID entityID(id); EntityItemID entityID(id);
@ -938,6 +942,7 @@ EntityItem* EntityTree::findEntityByID(uint32_t id, bool alreadyLocked) /*const
return findEntityByEntityItemID(entityID); return findEntityByEntityItemID(entityID);
} }
#endif ////////////////////////////
EntityItem* EntityTree::findEntityByEntityItemID(const EntityItemID& entityID) /*const*/ { EntityItem* EntityTree::findEntityByEntityItemID(const EntityItemID& entityID) /*const*/ {
EntityItem* foundEntity = NULL; EntityItem* foundEntity = NULL;
@ -1003,7 +1008,9 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char
// this is a new entity... assign a new entityID // this is a new entity... assign a new entityID
qDebug() << "EntityTree::processEditPacketData() ... BEFORE assignEntityID()... entityItemID=" << entityItemID;
entityItemID = assignEntityID(entityItemID); entityItemID = assignEntityID(entityItemID);
qDebug() << "EntityTree::processEditPacketData() ... AFTER assignEntityID()... entityItemID=" << entityItemID;
EntityItem* newEntity = addEntity(entityItemID, properties); EntityItem* newEntity = addEntity(entityItemID, properties);
if (newEntity) { if (newEntity) {
@ -1327,6 +1334,8 @@ void EntityTree::forgetEntitiesDeletedBefore(quint64 sinceTime) {
void EntityTree::processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode) { void EntityTree::processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode) {
#if 0 ///////////////
qDebug() << "EntityTree::processEraseMessage()..."; qDebug() << "EntityTree::processEraseMessage()...";
@ -1368,6 +1377,9 @@ void EntityTree::processEraseMessage(const QByteArray& dataByteArray, const Shar
qDebug() << "EntityTree::processEraseMessage()... deleteEntities(entityItemIDsToDelete)"; qDebug() << "EntityTree::processEraseMessage()... deleteEntities(entityItemIDsToDelete)";
deleteEntities(entityItemIDsToDelete); deleteEntities(entityItemIDsToDelete);
} }
#endif // 0 ///////////////
} }

View file

@ -470,6 +470,7 @@ void EntityTreeElement::getEntities(const AACube& box, QVector<EntityItem*>& fou
} }
} }
/*
const EntityItem* EntityTreeElement::getEntityWithID(uint32_t id) const { const EntityItem* EntityTreeElement::getEntityWithID(uint32_t id) const {
// NOTE: this lookup is O(N) but maybe we don't care? (guaranteed that num entities per elemen is small?) // NOTE: this lookup is O(N) but maybe we don't care? (guaranteed that num entities per elemen is small?)
const EntityItem* foundEntity = NULL; const EntityItem* foundEntity = NULL;
@ -482,6 +483,7 @@ const EntityItem* EntityTreeElement::getEntityWithID(uint32_t id) const {
} }
return foundEntity; return foundEntity;
} }
*/
const EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemID& id) const { const EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemID& id) const {
const EntityItem* foundEntity = NULL; const EntityItem* foundEntity = NULL;
@ -507,6 +509,7 @@ EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemID& id)
return foundEntity; return foundEntity;
} }
/*
bool EntityTreeElement::removeEntityWithID(uint32_t id) { bool EntityTreeElement::removeEntityWithID(uint32_t id) {
bool foundEntity = false; bool foundEntity = false;
uint16_t numberOfEntities = _entityItems->size(); uint16_t numberOfEntities = _entityItems->size();
@ -523,6 +526,7 @@ bool EntityTreeElement::removeEntityWithID(uint32_t id) {
} }
return foundEntity; return foundEntity;
} }
*/
bool EntityTreeElement::removeEntityWithEntityItemID(const EntityItemID& id) { bool EntityTreeElement::removeEntityWithEntityItemID(const EntityItemID& id) {
bool foundEntity = false; bool foundEntity = false;
@ -593,7 +597,7 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
if (bytesLeftToRead >= (int)(numberOfEntities * expectedBytesPerEntity)) { if (bytesLeftToRead >= (int)(numberOfEntities * expectedBytesPerEntity)) {
for (uint16_t i = 0; i < numberOfEntities; i++) { for (uint16_t i = 0; i < numberOfEntities; i++) {
int bytesForThisEntity = 0; int bytesForThisEntity = 0;
EntityItemID entityItemID = EntityItem::readEntityItemIDFromBuffer(dataAt, bytesLeftToRead, args); EntityItemID entityItemID = EntityItemID::readEntityItemIDFromBuffer(dataAt, bytesLeftToRead);
EntityItem* entityItem = _myTree->findEntityByEntityItemID(entityItemID); EntityItem* entityItem = _myTree->findEntityByEntityItemID(entityItemID);
bool newEntity = false; bool newEntity = false;

View file

@ -112,11 +112,9 @@ EntityItem* EntityTypes::constructEntityItem(const unsigned char* data, int byte
QByteArray originalDataBuffer((const char*)data, originalLength); QByteArray originalDataBuffer((const char*)data, originalLength);
// id // id
QByteArray encodedID = originalDataBuffer.mid(bytesRead); // maximum possible size QByteArray encodedID = originalDataBuffer.mid(bytesRead, NUM_BYTES_RFC4122_UUID); // maximum possible size
ByteCountCoded<quint32> idCoder = encodedID; QUuid actualID = QUuid::fromRfc4122(encodedID);
encodedID = idCoder; // determine true length
bytesRead += encodedID.size(); bytesRead += encodedID.size();
quint32 actualID = idCoder;
qDebug() << "EntityTypes::constructEntityItem(data, bytesToRead).... NEW BITSTREAM!!! actualID=" << actualID; qDebug() << "EntityTypes::constructEntityItem(data, bytesToRead).... NEW BITSTREAM!!! actualID=" << actualID;
// type // type
@ -150,7 +148,7 @@ bool EntityTypes::decodeEntityEditPacket(const unsigned char* data, int bytesToR
bool wantDebug = true; bool wantDebug = true;
if (wantDebug) { if (wantDebug) {
qDebug() << "EntityItem EntityItem::decodeEntityEditPacket() bytesToRead=" << bytesToRead; qDebug() << "EntityItem EntityTypes::decodeEntityEditPacket() bytesToRead=" << bytesToRead;
} }
const unsigned char* dataAt = data; const unsigned char* dataAt = data;
@ -162,7 +160,7 @@ bool EntityTypes::decodeEntityEditPacket(const unsigned char* data, int bytesToR
int bytesToReadOfOctcode = bytesRequiredForCodeLength(octets); int bytesToReadOfOctcode = bytesRequiredForCodeLength(octets);
if (wantDebug) { if (wantDebug) {
qDebug() << "EntityItem EntityItem::decodeEntityEditPacket() bytesToReadOfOctcode=" << bytesToReadOfOctcode; qDebug() << "EntityItem EntityTypes::decodeEntityEditPacket() bytesToReadOfOctcode=" << bytesToReadOfOctcode;
} }
// we don't actually do anything with this octcode... // we don't actually do anything with this octcode...
@ -176,23 +174,23 @@ bool EntityTypes::decodeEntityEditPacket(const unsigned char* data, int bytesToR
memcpy(&lastEdited, dataAt, sizeof(lastEdited)); memcpy(&lastEdited, dataAt, sizeof(lastEdited));
dataAt += sizeof(lastEdited); dataAt += sizeof(lastEdited);
processedBytes += sizeof(lastEdited); processedBytes += sizeof(lastEdited);
qDebug() << "EntityItem::decodeEntityEditPacket() ... lastEdited=" << lastEdited; qDebug() << "EntityTypes::decodeEntityEditPacket() ... lastEdited=" << lastEdited;
properties.setLastEdited(lastEdited); properties.setLastEdited(lastEdited);
// encoded id // encoded id
QByteArray encodedID((const char*)dataAt, (bytesToRead - processedBytes)); QByteArray encodedID((const char*)dataAt, NUM_BYTES_RFC4122_UUID); // maximum possible size
ByteCountCoded<quint32> idCoder = encodedID; QUuid editID = QUuid::fromRfc4122(encodedID);
quint32 editID = idCoder;
encodedID = idCoder; // determine true bytesToRead
dataAt += encodedID.size(); dataAt += encodedID.size();
processedBytes += encodedID.size(); processedBytes += encodedID.size();
if (wantDebug) { if (wantDebug) {
qDebug() << "EntityItem EntityItem::decodeEntityEditPacket() editID=" << editID; qDebug() << "EntityItem EntityTypes::decodeEntityEditPacket() editID=" << editID;
} }
bool isNewEntityItem = (editID == NEW_ENTITY); bool isNewEntityItem = (editID == NEW_ENTITY);
qDebug() << "EntityItem EntityTypes::decodeEntityEditPacket() isNewEntityItem=" << isNewEntityItem;
if (isNewEntityItem) { if (isNewEntityItem) {
// If this is a NEW_ENTITY, then we assume that there's an additional uint32_t creatorToken, that // If this is a NEW_ENTITY, then we assume that there's an additional uint32_t creatorToken, that
// we want to send back to the creator as an map to the actual id // we want to send back to the creator as an map to the actual id
@ -219,6 +217,8 @@ qDebug() << "EntityItem::decodeEntityEditPacket() ... lastEdited=" << lastEdited
entityID.isKnownID = true; entityID.isKnownID = true;
valid = true; valid = true;
} }
qDebug() << "EntityItem EntityTypes::decodeEntityEditPacket() entityID=" << entityID;
// Entity Type... // Entity Type...
QByteArray encodedType((const char*)dataAt, (bytesToRead - processedBytes)); QByteArray encodedType((const char*)dataAt, (bytesToRead - processedBytes));

View file

@ -150,14 +150,12 @@ qDebug() << "ModelEntityItem::readEntityDataFromBuffer()... <<<<<<<<<<<<<<<< <<
const unsigned char* dataAt = data; const unsigned char* dataAt = data;
// id // id
QByteArray encodedID = originalDataBuffer.mid(bytesRead); // maximum possible size QByteArray encodedID = originalDataBuffer.mid(bytesRead, NUM_BYTES_RFC4122_UUID); // maximum possible size
ByteCountCoded<quint32> idCoder = encodedID; _id = QUuid::fromRfc4122(encodedID);
encodedID = idCoder; // determine true length
dataAt += encodedID.size();
bytesRead += encodedID.size();
_id = idCoder;
_creatorTokenID = UNKNOWN_ENTITY_TOKEN; // if we know the id, then we don't care about the creator token _creatorTokenID = UNKNOWN_ENTITY_TOKEN; // if we know the id, then we don't care about the creator token
_newlyCreated = false; _newlyCreated = false;
dataAt += encodedID.size();
bytesRead += encodedID.size();
// type // type
QByteArray encodedType = originalDataBuffer.mid(bytesRead); // maximum possible size QByteArray encodedType = originalDataBuffer.mid(bytesRead); // maximum possible size
@ -460,8 +458,8 @@ qDebug() << "ModelEntityItem::appendEntityData()... ****************************
OctreeElement::AppendState appendState = OctreeElement::COMPLETED; // assume the best OctreeElement::AppendState appendState = OctreeElement::COMPLETED; // assume the best
// encode our ID as a byte count coded byte stream // encode our ID as a byte count coded byte stream
ByteCountCoded<quint32> idCoder = getID(); //ByteCountCoded<quint32> idCoder = getID();
QByteArray encodedID = idCoder; QByteArray encodedID = getID().toRfc4122();
// encode our type as a byte count coded byte stream // encode our type as a byte count coded byte stream
ByteCountCoded<quint32> typeCoder = getType(); ByteCountCoded<quint32> typeCoder = getType();

View file

@ -55,6 +55,12 @@ Model properties:
K) verify shadows work K) verify shadows work
L) sometimes assert/crashes in server about containing element? I think we're adding entityIDs with UNKNOWN_ID to our maps L) sometimes assert/crashes in server about containing element? I think we're adding entityIDs with UNKNOWN_ID to our maps
// this crash is definitely caused by starting a server with an existing models file which has ID's already in use...
M) change EntityTree::handleAddEntityResponse() to not scan entire tree... it can use the containing element stuff!!!
18) change ID's to UUIDS????
N) Handle the ID -> UUID swap in old files to new files
// NICE TO DO: // NICE TO DO:
@ -136,7 +142,6 @@ Model properties:
// 18) change ID's to UUIDS????
// 19) what about??? rememberDirtyCube()... // 19) what about??? rememberDirtyCube()...

View file

@ -41,7 +41,7 @@ void EntityTests::entityTreeTests(bool verbose) {
// Tree, id, and entity properties used in many tests below... // Tree, id, and entity properties used in many tests below...
EntityTree tree; EntityTree tree;
uint32_t id = 1; QUuid id = QUuid::createUuid();
EntityItemID entityID(id); EntityItemID entityID(id);
entityID.isKnownID = false; // this is a temporary workaround to allow local tree entities to be added with known IDs entityID.isKnownID = false; // this is a temporary workaround to allow local tree entities to be added with known IDs
EntityItemProperties properties; EntityItemProperties properties;
@ -68,7 +68,7 @@ void EntityTests::entityTreeTests(bool verbose) {
float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units
const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionAtCenterInTreeUnits, targetRadius); const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionAtCenterInTreeUnits, targetRadius);
const EntityItem* foundEntityByID = tree.findEntityByID(id); const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
EntityTreeElement* containingElement = tree.getContainingElement(entityID); EntityTreeElement* containingElement = tree.getContainingElement(entityID);
AACube elementCube = containingElement ? containingElement->getAACube() : AACube(); AACube elementCube = containingElement ? containingElement->getAACube() : AACube();
@ -111,7 +111,7 @@ void EntityTests::entityTreeTests(bool verbose) {
float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units
const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionNearOriginInTreeUnits, targetRadius); const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionNearOriginInTreeUnits, targetRadius);
const EntityItem* foundEntityByID = tree.findEntityByID(id); const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
EntityTreeElement* containingElement = tree.getContainingElement(entityID); EntityTreeElement* containingElement = tree.getContainingElement(entityID);
AACube elementCube = containingElement ? containingElement->getAACube() : AACube(); AACube elementCube = containingElement ? containingElement->getAACube() : AACube();
@ -151,7 +151,7 @@ void EntityTests::entityTreeTests(bool verbose) {
float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units
const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionAtCenterInTreeUnits, targetRadius); const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionAtCenterInTreeUnits, targetRadius);
const EntityItem* foundEntityByID = tree.findEntityByID(id); const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
EntityTreeElement* containingElement = tree.getContainingElement(entityID); EntityTreeElement* containingElement = tree.getContainingElement(entityID);
AACube elementCube = containingElement ? containingElement->getAACube() : AACube(); AACube elementCube = containingElement ? containingElement->getAACube() : AACube();
@ -218,8 +218,9 @@ void EntityTests::entityTreeTests(bool verbose) {
quint64 start = usecTimestampNow(); quint64 start = usecTimestampNow();
const EntityItem* foundEntityByID = NULL; const EntityItem* foundEntityByID = NULL;
for (int i = 0; i < TEST_ITERATIONS; i++) { for (int i = 0; i < TEST_ITERATIONS; i++) {
foundEntityByID = tree.findEntityByID(id); // TODO: does this need to be updated??
foundEntityByID = tree.findEntityByEntityItemID(entityID);
} }
quint64 end = usecTimestampNow(); quint64 end = usecTimestampNow();
@ -254,7 +255,7 @@ void EntityTests::entityTreeTests(bool verbose) {
quint64 totalElapsedAdd = 0; quint64 totalElapsedAdd = 0;
quint64 totalElapsedFind = 0; quint64 totalElapsedFind = 0;
for (int i = 0; i < TEST_ITERATIONS; i++) { for (int i = 0; i < TEST_ITERATIONS; i++) {
uint32_t id = i + 2; // make sure it doesn't collide with previous entity ids QUuid id = QUuid::createUuid();// make sure it doesn't collide with previous entity ids
EntityItemID entityID(id); EntityItemID entityID(id);
entityID.isKnownID = false; // this is a temporary workaround to allow local tree entities to be added with known IDs entityID.isKnownID = false; // this is a temporary workaround to allow local tree entities to be added with known IDs
@ -286,7 +287,7 @@ void EntityTests::entityTreeTests(bool verbose) {
quint64 startFind = usecTimestampNow(); quint64 startFind = usecTimestampNow();
float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units
const EntityItem* foundEntityByRadius = tree.findClosestEntity(randomPositionInTreeUnits, targetRadius); const EntityItem* foundEntityByRadius = tree.findClosestEntity(randomPositionInTreeUnits, targetRadius);
const EntityItem* foundEntityByID = tree.findEntityByID(id); const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
quint64 endFind = usecTimestampNow(); quint64 endFind = usecTimestampNow();
totalElapsedFind += (endFind - startFind); totalElapsedFind += (endFind - startFind);
@ -358,7 +359,7 @@ void EntityTests::entityTreeTests(bool verbose) {
quint64 totalElapsedDelete = 0; quint64 totalElapsedDelete = 0;
quint64 totalElapsedFind = 0; quint64 totalElapsedFind = 0;
for (int i = 0; i < TEST_ITERATIONS; i++) { for (int i = 0; i < TEST_ITERATIONS; i++) {
uint32_t id = i + 2; // These are the entities we added above QUuid id = QUuid::createUuid();// make sure it doesn't collide with previous entity ids
EntityItemID entityID(id); EntityItemID entityID(id);
entityID.isKnownID = true; // this is a temporary workaround to allow local tree entities to be added with known IDs entityID.isKnownID = true; // this is a temporary workaround to allow local tree entities to be added with known IDs
@ -376,7 +377,7 @@ void EntityTests::entityTreeTests(bool verbose) {
} }
quint64 startFind = usecTimestampNow(); quint64 startFind = usecTimestampNow();
const EntityItem* foundEntityByID = tree.findEntityByID(id); const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
quint64 endFind = usecTimestampNow(); quint64 endFind = usecTimestampNow();
totalElapsedFind += (endFind - startFind); totalElapsedFind += (endFind - startFind);
@ -441,7 +442,8 @@ void EntityTests::entityTreeTests(bool verbose) {
QSet<EntityItemID> entitiesToDelete; QSet<EntityItemID> entitiesToDelete;
for (int j = 0; j < ENTITIES_PER_ITERATION; j++) { for (int j = 0; j < ENTITIES_PER_ITERATION; j++) {
uint32_t id = 2 + (i * ENTITIES_PER_ITERATION) + j; // These are the entities we added above //uint32_t id = 2 + (i * ENTITIES_PER_ITERATION) + j; // These are the entities we added above
QUuid id = QUuid::createUuid();// make sure it doesn't collide with previous entity ids
EntityItemID entityID(id); EntityItemID entityID(id);
entitiesToDelete << entityID; entitiesToDelete << entityID;
} }
@ -461,9 +463,10 @@ void EntityTests::entityTreeTests(bool verbose) {
quint64 startFind = usecTimestampNow(); quint64 startFind = usecTimestampNow();
for (int j = 0; j < ENTITIES_PER_ITERATION; j++) { for (int j = 0; j < ENTITIES_PER_ITERATION; j++) {
uint32_t id = 2 + (i * ENTITIES_PER_ITERATION) + j; // These are the entities we added above //uint32_t id = 2 + (i * ENTITIES_PER_ITERATION) + j; // These are the entities we added above
QUuid id = QUuid::createUuid();// make sure it doesn't collide with previous entity ids
EntityItemID entityID(id); EntityItemID entityID(id);
const EntityItem* foundEntityByID = tree.findEntityByID(id); const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
EntityTreeElement* containingElement = tree.getContainingElement(entityID); EntityTreeElement* containingElement = tree.getContainingElement(entityID);
if (extraVerbose) { if (extraVerbose) {