mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 02:53:43 +02:00
convert IDs to UUIDs
This commit is contained in:
parent
2a65de8026
commit
6f479a1026
17 changed files with 160 additions and 123 deletions
|
@ -64,8 +64,9 @@ qDebug() << "EntityServer::entityCreated() newEntity.getEntityItemID()=" << newE
|
|||
packetLength += sizeof(creatorTokenID);
|
||||
|
||||
// encode the entity ID
|
||||
uint32_t entityID = newEntity.getID();
|
||||
memcpy(copyAt, &entityID, sizeof(entityID));
|
||||
QUuid entityID = newEntity.getID();
|
||||
QByteArray encodedID = entityID.toRfc4122();
|
||||
memcpy(copyAt, encodedID.constData(), encodedID.size());
|
||||
copyAt += sizeof(entityID);
|
||||
packetLength += sizeof(entityID);
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ Model* EntityTreeRenderer::getModel(const ModelEntityItem* modelEntityItem) {
|
|||
if (QUrl(modelEntityItem->getModelURL()) != model->getURL()) {
|
||||
delete model; // delete the old model...
|
||||
model = NULL;
|
||||
_unknownEntityItemModels.remove(modelEntityItem->getID());
|
||||
_unknownEntityItemModels.remove(modelEntityItem->getCreatorTokenID());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
|
||||
protected:
|
||||
void clearModelsCache();
|
||||
QMap<uint32_t, Model*> _knownEntityItemModels;
|
||||
QMap<QUuid, Model*> _knownEntityItemModels;
|
||||
QMap<uint32_t, Model*> _unknownEntityItemModels;
|
||||
};
|
||||
|
||||
|
|
|
@ -112,14 +112,12 @@ qDebug() << "BoxEntityItem::readEntityDataFromBuffer()... <<<<<<<<<<<<<<<< <<<<
|
|||
const unsigned char* dataAt = data;
|
||||
|
||||
// id
|
||||
QByteArray encodedID = originalDataBuffer.mid(bytesRead); // maximum possible size
|
||||
ByteCountCoded<quint32> idCoder = encodedID;
|
||||
encodedID = idCoder; // determine true length
|
||||
dataAt += encodedID.size();
|
||||
bytesRead += encodedID.size();
|
||||
_id = idCoder;
|
||||
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();
|
||||
|
||||
// type
|
||||
QByteArray encodedType = originalDataBuffer.mid(bytesRead); // maximum possible size
|
||||
|
@ -267,8 +265,8 @@ qDebug() << "BoxEntityItem::appendEntityData()... ******************************
|
|||
OctreeElement::AppendState appendState = OctreeElement::COMPLETED; // assume the best
|
||||
|
||||
// encode our ID as a byte count coded byte stream
|
||||
ByteCountCoded<quint32> idCoder = getID();
|
||||
QByteArray encodedID = idCoder;
|
||||
//ByteCountCoded<quint32> idCoder = getID();
|
||||
QByteArray encodedID = getID().toRfc4122();
|
||||
|
||||
// encode our type as a byte count coded byte stream
|
||||
|
||||
|
|
|
@ -70,8 +70,7 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet
|
|||
OctreeElement::AppendState appendState = OctreeElement::COMPLETED; // assume the best
|
||||
|
||||
// encode our ID as a byte count coded byte stream
|
||||
ByteCountCoded<quint32> idCoder = getID();
|
||||
QByteArray encodedID = idCoder;
|
||||
QByteArray encodedID = getID().toRfc4122();
|
||||
|
||||
// encode our type as a byte count coded byte stream
|
||||
ByteCountCoded<quint32> typeCoder = getType();
|
||||
|
@ -389,7 +388,9 @@ qDebug() << "EntityItem::appendEntityData() ... lastEdited=" << lastEdited;
|
|||
return appendState;
|
||||
}
|
||||
|
||||
// TODO: correct this to reflect changes...
|
||||
int EntityItem::expectedBytes() {
|
||||
|
||||
int expectedBytes = sizeof(uint32_t) // id
|
||||
+ sizeof(float) // age
|
||||
+ 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) {
|
||||
|
||||
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;
|
||||
|
||||
// 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;
|
||||
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
|
||||
_newlyCreated = false;
|
||||
**/
|
||||
|
||||
// type
|
||||
QByteArray encodedType = originalDataBuffer.mid(bytesRead); // maximum possible size
|
||||
|
@ -462,13 +454,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
|||
quint32 type = typeCoder;
|
||||
_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
|
||||
|
||||
quint64 lastEditedFromBuffer = 0;
|
||||
|
@ -696,8 +681,11 @@ bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID
|
|||
|
||||
// id
|
||||
// encode our ID as a byte count coded byte stream
|
||||
/*
|
||||
ByteCountCoded<quint32> idCoder = id.id;
|
||||
QByteArray encodedID = idCoder;
|
||||
*/
|
||||
QByteArray encodedID = id.id.toRfc4122(); // NUM_BYTES_RFC4122_UUID
|
||||
|
||||
// encode our ID as a byte count coded byte stream
|
||||
ByteCountCoded<quint32> tokenCoder;
|
||||
|
|
|
@ -38,8 +38,8 @@ public:
|
|||
virtual void somePureVirtualFunction() = 0;
|
||||
|
||||
// ID and EntityItemID related methods
|
||||
uint32_t getID() const { return _id; }
|
||||
void setID(uint32_t id) { _id = id; }
|
||||
QUuid getID() const { return _id; }
|
||||
void setID(const QUuid& id) { _id = id; }
|
||||
uint32_t getCreatorTokenID() const { return _creatorTokenID; }
|
||||
void setCreatorTokenID(uint32_t creatorTokenID) { _creatorTokenID = creatorTokenID; }
|
||||
bool isNewlyCreated() const { return _newlyCreated; }
|
||||
|
@ -114,8 +114,8 @@ public:
|
|||
protected:
|
||||
virtual void initFromEntityItemID(const EntityItemID& entityItemID); // maybe useful to allow subclasses to init
|
||||
|
||||
quint32 _id;
|
||||
EntityTypes::EntityType _type;
|
||||
QUuid _id;
|
||||
uint32_t _creatorTokenID;
|
||||
bool _newlyCreated;
|
||||
quint64 _lastUpdated;
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
|
||||
#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
|
||||
std::map<uint32_t,uint32_t> EntityItemID::_tokenIDsToIDs;
|
||||
QHash<uint32_t, QUuid> EntityItemID::_tokenIDsToIDs;
|
||||
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),
|
||||
creatorTokenID(creatorTokenID),
|
||||
isKnownID(isKnownID)
|
||||
|
@ -51,7 +51,7 @@ EntityItemID::EntityItemID(uint32_t id, uint32_t creatorTokenID, bool isKnownID)
|
|||
// << isKnownID << "id=" << id << "creatorTokenID=" << creatorTokenID;
|
||||
};
|
||||
|
||||
EntityItemID::EntityItemID(uint32_t id) :
|
||||
EntityItemID::EntityItemID(const QUuid& id) :
|
||||
id(id),
|
||||
creatorTokenID(UNKNOWN_ENTITY_TOKEN),
|
||||
isKnownID(true)
|
||||
|
@ -60,11 +60,11 @@ EntityItemID::EntityItemID(uint32_t id) :
|
|||
// << isKnownID << "id=" << id << "creatorTokenID=" << creatorTokenID;
|
||||
};
|
||||
|
||||
uint32_t EntityItemID::getIDfromCreatorTokenID(uint32_t creatorTokenID) {
|
||||
EntityItemID EntityItemID::getIDfromCreatorTokenID(uint32_t creatorTokenID) {
|
||||
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() {
|
||||
|
@ -78,8 +78,8 @@ EntityItemID EntityItemID::assignActualIDForToken() const {
|
|||
|
||||
newlyAssignedEntityID.creatorTokenID = creatorTokenID;
|
||||
newlyAssignedEntityID.isKnownID = true;
|
||||
newlyAssignedEntityID.id = _nextID;
|
||||
_nextID++;
|
||||
newlyAssignedEntityID.id = QUuid::createUuid();
|
||||
//_nextID++;
|
||||
|
||||
return newlyAssignedEntityID;
|
||||
}
|
||||
|
@ -104,41 +104,58 @@ EntityItemID EntityItemID::convertToCreatorTokenVersion() const {
|
|||
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) {
|
||||
|
||||
qDebug() << "EntityItemID::handleAddEntityResponse()...";
|
||||
|
||||
const unsigned char* dataAt = reinterpret_cast<const unsigned char*>(packet.data());
|
||||
int numBytesPacketHeader = numBytesForPacketHeader(packet);
|
||||
int bytesRead = numBytesPacketHeader;
|
||||
dataAt += numBytesPacketHeader;
|
||||
|
||||
uint32_t creatorTokenID;
|
||||
memcpy(&creatorTokenID, dataAt, sizeof(creatorTokenID));
|
||||
dataAt += sizeof(creatorTokenID);
|
||||
bytesRead += sizeof(creatorTokenID);
|
||||
|
||||
uint32_t entityItemID;
|
||||
memcpy(&entityItemID, dataAt, sizeof(entityItemID));
|
||||
dataAt += sizeof(entityItemID);
|
||||
QUuid entityID = QUuid::fromRfc4122(packet.mid(bytesRead, NUM_BYTES_RFC4122_UUID));
|
||||
dataAt += NUM_BYTES_RFC4122_UUID;
|
||||
|
||||
qDebug() << "EntityItemID::handleAddEntityResponse()... entityItemID=" << entityItemID << "creatorTokenID=" << creatorTokenID;
|
||||
qDebug() << "EntityItemID::handleAddEntityResponse()... entityID=" << entityID << "creatorTokenID=" << creatorTokenID;
|
||||
|
||||
// add our token to id mapping
|
||||
_tokenIDsToIDs[creatorTokenID] = entityItemID;
|
||||
_tokenIDsToIDs[creatorTokenID] = entityID;
|
||||
}
|
||||
|
||||
QScriptValue EntityItemIDtoScriptValue(QScriptEngine* engine, const EntityItemID& id) {
|
||||
QScriptValue obj = engine->newObject();
|
||||
obj.setProperty("id", id.id);
|
||||
obj.setProperty("id", id.id.toString());
|
||||
obj.setProperty("creatorTokenID", id.creatorTokenID);
|
||||
obj.setProperty("isKnownID", id.isKnownID);
|
||||
return obj;
|
||||
}
|
||||
|
||||
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.isKnownID = object.property("isKnownID").toVariant().toBool();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -14,12 +14,19 @@
|
|||
|
||||
#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_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
|
||||
|
@ -29,10 +36,12 @@ class EntityItemID {
|
|||
public:
|
||||
EntityItemID();
|
||||
EntityItemID(const EntityItemID& other);
|
||||
EntityItemID(uint32_t id, uint32_t creatorTokenID, bool isKnownID);
|
||||
EntityItemID(uint32_t id);
|
||||
EntityItemID(const QUuid& id, uint32_t creatorTokenID, bool isKnownID);
|
||||
EntityItemID(const QUuid& id);
|
||||
|
||||
uint32_t id;
|
||||
//uint32_t id;
|
||||
QUuid id;
|
||||
|
||||
uint32_t creatorTokenID;
|
||||
bool isKnownID;
|
||||
|
||||
|
@ -41,17 +50,19 @@ public:
|
|||
EntityItemID convertToCreatorTokenVersion() const;
|
||||
|
||||
// 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 void handleAddEntityResponse(const QByteArray& packet);
|
||||
static EntityItemID readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead);
|
||||
|
||||
private:
|
||||
friend class 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 std::map<uint32_t,uint32_t> _tokenIDsToIDs;
|
||||
static QHash<uint32_t, QUuid> _tokenIDsToIDs;
|
||||
};
|
||||
|
||||
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) {
|
||||
qint64 temp;
|
||||
QUuid temp;
|
||||
if (a.id == UNKNOWN_ENTITY_ID) {
|
||||
temp = -a.creatorTokenID;
|
||||
temp = QUuid(a.creatorTokenID,0,0,0,0,0,0,0,0,0,0);
|
||||
} else {
|
||||
temp = a.id;
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons
|
|||
QScriptValue properties = engine->newObject();
|
||||
|
||||
if (_idSet) {
|
||||
properties.setProperty("id", _id);
|
||||
properties.setProperty("id", _id.toString());
|
||||
bool isKnownID = (_id != UNKNOWN_ENTITY_ID);
|
||||
properties.setProperty("isKnownID", isKnownID);
|
||||
//qDebug() << "EntityItemProperties::copyToScriptValue()... isKnownID=" << isKnownID << "id=" << _id;
|
||||
|
|
|
@ -166,7 +166,7 @@ private:
|
|||
EntityItemID& entityID, EntityItemProperties& properties);
|
||||
void setLastEdited(quint64 lastEdited) { _lastEdited = lastEdited; }
|
||||
|
||||
quint32 _id;
|
||||
QUuid _id;
|
||||
bool _idSet;
|
||||
quint64 _lastEdited;
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& pro
|
|||
}
|
||||
|
||||
EntityItemID EntityScriptingInterface::identifyEntity(EntityItemID entityID) {
|
||||
uint32_t actualID = entityID.id;
|
||||
EntityItemID actualID = entityID;
|
||||
|
||||
if (!entityID.isKnownID) {
|
||||
actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID);
|
||||
|
@ -54,7 +54,7 @@ EntityItemID EntityScriptingInterface::identifyEntity(EntityItemID entityID) {
|
|||
}
|
||||
|
||||
// found it!
|
||||
entityID.id = actualID;
|
||||
entityID.id = actualID.id;
|
||||
entityID.isKnownID = true;
|
||||
qDebug() << "EntityScriptingInterface::identifyEntity() ...found it... isKnownID=" << entityID.isKnownID << "id=" << entityID.id << "creatorTokenID=" << entityID.creatorTokenID;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID
|
|||
}
|
||||
if (_entityTree) {
|
||||
_entityTree->lockForRead();
|
||||
EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByID(identity.id, true));
|
||||
EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(identity));
|
||||
if (entity) {
|
||||
|
||||
// TODO: look into sitting points!!!
|
||||
|
@ -89,7 +89,7 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID
|
|||
|
||||
|
||||
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 (!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 (actualID != UNKNOWN_ENTITY_ID) {
|
||||
entityID.id = actualID;
|
||||
if (actualID.id != UNKNOWN_ENTITY_ID) {
|
||||
entityID.id = actualID.id;
|
||||
entityID.isKnownID = true;
|
||||
//qDebug() << "EntityScriptingInterface::editEntity()... isKnownID=" << entityID.isKnownID << "id=" << entityID.id << "creatorTokenID=" << entityID.creatorTokenID;
|
||||
queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties);
|
||||
|
@ -127,7 +127,7 @@ void EntityScriptingInterface::deleteEntity(EntityItemID entityID) {
|
|||
EntityItemProperties properties;
|
||||
properties.setShouldBeDeleted(true);
|
||||
|
||||
uint32_t actualID = entityID.id;
|
||||
EntityItemID actualID = entityID;
|
||||
|
||||
// if the model is unknown, attempt to look it up
|
||||
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 (actualID != UNKNOWN_ENTITY_ID) {
|
||||
entityID.id = actualID;
|
||||
if (actualID.id != UNKNOWN_ENTITY_ID) {
|
||||
entityID.id = actualID.id;
|
||||
entityID.isKnownID = true;
|
||||
//qDebug() << "EntityScriptingInterface::deleteEntity()... isKnownID=" << entityID.isKnownID << "id=" << entityID.id << "creatorTokenID=" << entityID.creatorTokenID;
|
||||
queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties);
|
||||
|
|
|
@ -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()
|
||||
EntityTreeElement* containingElement = getContainingElement(entityID);
|
||||
if (containingElement) {
|
||||
qDebug() << "UNEXPECTED!!! ----- EntityTree::addEntity()... entityID=" << entityID << "containingElement=" << containingElement;
|
||||
assert(containingElement == NULL); // don't call addEntity() on existing entity items
|
||||
return result;
|
||||
}
|
||||
|
@ -769,19 +770,20 @@ void EntityTree::handleAddEntityResponse(const QByteArray& packet) {
|
|||
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);
|
||||
|
||||
const unsigned char* dataAt = reinterpret_cast<const unsigned char*>(packet.data()) + numBytesPacketHeader;
|
||||
int bytesRead = numBytesPacketHeader;
|
||||
dataAt += numBytesPacketHeader;
|
||||
|
||||
uint32_t creatorTokenID;
|
||||
memcpy(&creatorTokenID, dataAt, sizeof(creatorTokenID));
|
||||
dataAt += sizeof(creatorTokenID);
|
||||
bytesRead += sizeof(creatorTokenID);
|
||||
|
||||
uint32_t entityID;
|
||||
memcpy(&entityID, dataAt, sizeof(entityID));
|
||||
dataAt += sizeof(entityID);
|
||||
QUuid entityID = QUuid::fromRfc4122(packet.mid(bytesRead, NUM_BYTES_RFC4122_UUID));
|
||||
dataAt += NUM_BYTES_RFC4122_UUID;
|
||||
|
||||
qDebug() << "EntityTree::handleAddEntityResponse()... entityID=" << entityID << "creatorTokenID=" << creatorTokenID;
|
||||
|
||||
// TODO: do we want callers to lock the tree before using this method???
|
||||
|
||||
|
@ -792,6 +794,7 @@ void EntityTree::handleAddEntityResponse(const QByteArray& packet) {
|
|||
|
||||
lockForWrite();
|
||||
|
||||
bool wantDebug = false;
|
||||
if (wantDebug) {
|
||||
qDebug() << "EntityTree::handleAddEntityResponse()...";
|
||||
qDebug() << " creatorTokenID=" << creatorTokenID;
|
||||
|
@ -925,6 +928,7 @@ void EntityTree::findEntities(const AACube& cube, QVector<EntityItem*> foundEnti
|
|||
foundEntities.swap(args._foundEntities);
|
||||
}
|
||||
|
||||
#if 0 ///////////////////////////////////
|
||||
EntityItem* EntityTree::findEntityByID(uint32_t id, bool alreadyLocked) /*const*/ {
|
||||
EntityItemID entityID(id);
|
||||
|
||||
|
@ -938,6 +942,7 @@ EntityItem* EntityTree::findEntityByID(uint32_t id, bool alreadyLocked) /*const
|
|||
|
||||
return findEntityByEntityItemID(entityID);
|
||||
}
|
||||
#endif ////////////////////////////
|
||||
|
||||
EntityItem* EntityTree::findEntityByEntityItemID(const EntityItemID& entityID) /*const*/ {
|
||||
EntityItem* foundEntity = NULL;
|
||||
|
@ -1003,7 +1008,9 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char
|
|||
|
||||
|
||||
// this is a new entity... assign a new entityID
|
||||
qDebug() << "EntityTree::processEditPacketData() ... BEFORE assignEntityID()... entityItemID=" << entityItemID;
|
||||
entityItemID = assignEntityID(entityItemID);
|
||||
qDebug() << "EntityTree::processEditPacketData() ... AFTER assignEntityID()... entityItemID=" << entityItemID;
|
||||
|
||||
EntityItem* newEntity = addEntity(entityItemID, properties);
|
||||
if (newEntity) {
|
||||
|
@ -1327,6 +1334,8 @@ void EntityTree::forgetEntitiesDeletedBefore(quint64 sinceTime) {
|
|||
|
||||
|
||||
void EntityTree::processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode) {
|
||||
|
||||
#if 0 ///////////////
|
||||
|
||||
|
||||
qDebug() << "EntityTree::processEraseMessage()...";
|
||||
|
@ -1368,6 +1377,9 @@ void EntityTree::processEraseMessage(const QByteArray& dataByteArray, const Shar
|
|||
qDebug() << "EntityTree::processEraseMessage()... deleteEntities(entityItemIDsToDelete)";
|
||||
deleteEntities(entityItemIDsToDelete);
|
||||
}
|
||||
|
||||
#endif // 0 ///////////////
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -470,6 +470,7 @@ void EntityTreeElement::getEntities(const AACube& box, QVector<EntityItem*>& fou
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
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?)
|
||||
const EntityItem* foundEntity = NULL;
|
||||
|
@ -482,6 +483,7 @@ const EntityItem* EntityTreeElement::getEntityWithID(uint32_t id) const {
|
|||
}
|
||||
return foundEntity;
|
||||
}
|
||||
*/
|
||||
|
||||
const EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemID& id) const {
|
||||
const EntityItem* foundEntity = NULL;
|
||||
|
@ -507,6 +509,7 @@ EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemID& id)
|
|||
return foundEntity;
|
||||
}
|
||||
|
||||
/*
|
||||
bool EntityTreeElement::removeEntityWithID(uint32_t id) {
|
||||
bool foundEntity = false;
|
||||
uint16_t numberOfEntities = _entityItems->size();
|
||||
|
@ -523,6 +526,7 @@ bool EntityTreeElement::removeEntityWithID(uint32_t id) {
|
|||
}
|
||||
return foundEntity;
|
||||
}
|
||||
*/
|
||||
|
||||
bool EntityTreeElement::removeEntityWithEntityItemID(const EntityItemID& id) {
|
||||
bool foundEntity = false;
|
||||
|
@ -593,7 +597,7 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
|
|||
if (bytesLeftToRead >= (int)(numberOfEntities * expectedBytesPerEntity)) {
|
||||
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
||||
int bytesForThisEntity = 0;
|
||||
EntityItemID entityItemID = EntityItem::readEntityItemIDFromBuffer(dataAt, bytesLeftToRead, args);
|
||||
EntityItemID entityItemID = EntityItemID::readEntityItemIDFromBuffer(dataAt, bytesLeftToRead);
|
||||
EntityItem* entityItem = _myTree->findEntityByEntityItemID(entityItemID);
|
||||
bool newEntity = false;
|
||||
|
||||
|
|
|
@ -112,11 +112,9 @@ EntityItem* EntityTypes::constructEntityItem(const unsigned char* data, int byte
|
|||
QByteArray originalDataBuffer((const char*)data, originalLength);
|
||||
|
||||
// id
|
||||
QByteArray encodedID = originalDataBuffer.mid(bytesRead); // maximum possible size
|
||||
ByteCountCoded<quint32> idCoder = encodedID;
|
||||
encodedID = idCoder; // determine true length
|
||||
QByteArray encodedID = originalDataBuffer.mid(bytesRead, NUM_BYTES_RFC4122_UUID); // maximum possible size
|
||||
QUuid actualID = QUuid::fromRfc4122(encodedID);
|
||||
bytesRead += encodedID.size();
|
||||
quint32 actualID = idCoder;
|
||||
qDebug() << "EntityTypes::constructEntityItem(data, bytesToRead).... NEW BITSTREAM!!! actualID=" << actualID;
|
||||
|
||||
// type
|
||||
|
@ -150,7 +148,7 @@ bool EntityTypes::decodeEntityEditPacket(const unsigned char* data, int bytesToR
|
|||
|
||||
bool wantDebug = true;
|
||||
if (wantDebug) {
|
||||
qDebug() << "EntityItem EntityItem::decodeEntityEditPacket() bytesToRead=" << bytesToRead;
|
||||
qDebug() << "EntityItem EntityTypes::decodeEntityEditPacket() bytesToRead=" << bytesToRead;
|
||||
}
|
||||
|
||||
const unsigned char* dataAt = data;
|
||||
|
@ -162,7 +160,7 @@ bool EntityTypes::decodeEntityEditPacket(const unsigned char* data, int bytesToR
|
|||
int bytesToReadOfOctcode = bytesRequiredForCodeLength(octets);
|
||||
|
||||
if (wantDebug) {
|
||||
qDebug() << "EntityItem EntityItem::decodeEntityEditPacket() bytesToReadOfOctcode=" << bytesToReadOfOctcode;
|
||||
qDebug() << "EntityItem EntityTypes::decodeEntityEditPacket() bytesToReadOfOctcode=" << bytesToReadOfOctcode;
|
||||
}
|
||||
|
||||
// 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));
|
||||
dataAt += sizeof(lastEdited);
|
||||
processedBytes += sizeof(lastEdited);
|
||||
qDebug() << "EntityItem::decodeEntityEditPacket() ... lastEdited=" << lastEdited;
|
||||
qDebug() << "EntityTypes::decodeEntityEditPacket() ... lastEdited=" << lastEdited;
|
||||
properties.setLastEdited(lastEdited);
|
||||
|
||||
// encoded id
|
||||
QByteArray encodedID((const char*)dataAt, (bytesToRead - processedBytes));
|
||||
ByteCountCoded<quint32> idCoder = encodedID;
|
||||
quint32 editID = idCoder;
|
||||
encodedID = idCoder; // determine true bytesToRead
|
||||
QByteArray encodedID((const char*)dataAt, NUM_BYTES_RFC4122_UUID); // maximum possible size
|
||||
QUuid editID = QUuid::fromRfc4122(encodedID);
|
||||
dataAt += encodedID.size();
|
||||
processedBytes += encodedID.size();
|
||||
|
||||
if (wantDebug) {
|
||||
qDebug() << "EntityItem EntityItem::decodeEntityEditPacket() editID=" << editID;
|
||||
qDebug() << "EntityItem EntityTypes::decodeEntityEditPacket() editID=" << editID;
|
||||
}
|
||||
|
||||
bool isNewEntityItem = (editID == NEW_ENTITY);
|
||||
|
||||
qDebug() << "EntityItem EntityTypes::decodeEntityEditPacket() isNewEntityItem=" << isNewEntityItem;
|
||||
|
||||
if (isNewEntityItem) {
|
||||
// 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
|
||||
|
@ -219,6 +217,8 @@ qDebug() << "EntityItem::decodeEntityEditPacket() ... lastEdited=" << lastEdited
|
|||
entityID.isKnownID = true;
|
||||
valid = true;
|
||||
}
|
||||
|
||||
qDebug() << "EntityItem EntityTypes::decodeEntityEditPacket() entityID=" << entityID;
|
||||
|
||||
// Entity Type...
|
||||
QByteArray encodedType((const char*)dataAt, (bytesToRead - processedBytes));
|
||||
|
|
|
@ -150,14 +150,12 @@ qDebug() << "ModelEntityItem::readEntityDataFromBuffer()... <<<<<<<<<<<<<<<< <<
|
|||
const unsigned char* dataAt = data;
|
||||
|
||||
// id
|
||||
QByteArray encodedID = originalDataBuffer.mid(bytesRead); // maximum possible size
|
||||
ByteCountCoded<quint32> idCoder = encodedID;
|
||||
encodedID = idCoder; // determine true length
|
||||
dataAt += encodedID.size();
|
||||
bytesRead += encodedID.size();
|
||||
_id = idCoder;
|
||||
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();
|
||||
|
||||
// type
|
||||
QByteArray encodedType = originalDataBuffer.mid(bytesRead); // maximum possible size
|
||||
|
@ -460,8 +458,8 @@ qDebug() << "ModelEntityItem::appendEntityData()... ****************************
|
|||
OctreeElement::AppendState appendState = OctreeElement::COMPLETED; // assume the best
|
||||
|
||||
// encode our ID as a byte count coded byte stream
|
||||
ByteCountCoded<quint32> idCoder = getID();
|
||||
QByteArray encodedID = idCoder;
|
||||
//ByteCountCoded<quint32> idCoder = getID();
|
||||
QByteArray encodedID = getID().toRfc4122();
|
||||
|
||||
// encode our type as a byte count coded byte stream
|
||||
ByteCountCoded<quint32> typeCoder = getType();
|
||||
|
|
|
@ -55,6 +55,12 @@ Model properties:
|
|||
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
|
||||
// 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:
|
||||
|
@ -136,7 +142,6 @@ Model properties:
|
|||
|
||||
|
||||
|
||||
// 18) change ID's to UUIDS????
|
||||
|
||||
// 19) what about??? rememberDirtyCube()...
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ void EntityTests::entityTreeTests(bool verbose) {
|
|||
|
||||
// Tree, id, and entity properties used in many tests below...
|
||||
EntityTree tree;
|
||||
uint32_t id = 1;
|
||||
QUuid id = QUuid::createUuid();
|
||||
EntityItemID entityID(id);
|
||||
entityID.isKnownID = false; // this is a temporary workaround to allow local tree entities to be added with known IDs
|
||||
EntityItemProperties properties;
|
||||
|
@ -68,7 +68,7 @@ void EntityTests::entityTreeTests(bool verbose) {
|
|||
|
||||
float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units
|
||||
const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionAtCenterInTreeUnits, targetRadius);
|
||||
const EntityItem* foundEntityByID = tree.findEntityByID(id);
|
||||
const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
|
||||
EntityTreeElement* containingElement = tree.getContainingElement(entityID);
|
||||
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
|
||||
const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionNearOriginInTreeUnits, targetRadius);
|
||||
const EntityItem* foundEntityByID = tree.findEntityByID(id);
|
||||
const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
|
||||
EntityTreeElement* containingElement = tree.getContainingElement(entityID);
|
||||
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
|
||||
const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionAtCenterInTreeUnits, targetRadius);
|
||||
const EntityItem* foundEntityByID = tree.findEntityByID(id);
|
||||
const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
|
||||
EntityTreeElement* containingElement = tree.getContainingElement(entityID);
|
||||
AACube elementCube = containingElement ? containingElement->getAACube() : AACube();
|
||||
|
||||
|
@ -218,8 +218,9 @@ void EntityTests::entityTreeTests(bool verbose) {
|
|||
|
||||
quint64 start = usecTimestampNow();
|
||||
const EntityItem* foundEntityByID = NULL;
|
||||
for (int i = 0; i < TEST_ITERATIONS; i++) {
|
||||
foundEntityByID = tree.findEntityByID(id);
|
||||
for (int i = 0; i < TEST_ITERATIONS; i++) {
|
||||
// TODO: does this need to be updated??
|
||||
foundEntityByID = tree.findEntityByEntityItemID(entityID);
|
||||
}
|
||||
quint64 end = usecTimestampNow();
|
||||
|
||||
|
@ -254,7 +255,7 @@ void EntityTests::entityTreeTests(bool verbose) {
|
|||
quint64 totalElapsedAdd = 0;
|
||||
quint64 totalElapsedFind = 0;
|
||||
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);
|
||||
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();
|
||||
float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units
|
||||
const EntityItem* foundEntityByRadius = tree.findClosestEntity(randomPositionInTreeUnits, targetRadius);
|
||||
const EntityItem* foundEntityByID = tree.findEntityByID(id);
|
||||
const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
|
||||
quint64 endFind = usecTimestampNow();
|
||||
totalElapsedFind += (endFind - startFind);
|
||||
|
||||
|
@ -358,7 +359,7 @@ void EntityTests::entityTreeTests(bool verbose) {
|
|||
quint64 totalElapsedDelete = 0;
|
||||
quint64 totalElapsedFind = 0;
|
||||
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);
|
||||
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();
|
||||
const EntityItem* foundEntityByID = tree.findEntityByID(id);
|
||||
const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
|
||||
quint64 endFind = usecTimestampNow();
|
||||
totalElapsedFind += (endFind - startFind);
|
||||
|
||||
|
@ -441,7 +442,8 @@ void EntityTests::entityTreeTests(bool verbose) {
|
|||
|
||||
QSet<EntityItemID> entitiesToDelete;
|
||||
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);
|
||||
entitiesToDelete << entityID;
|
||||
}
|
||||
|
@ -461,9 +463,10 @@ void EntityTests::entityTreeTests(bool verbose) {
|
|||
|
||||
quint64 startFind = usecTimestampNow();
|
||||
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);
|
||||
const EntityItem* foundEntityByID = tree.findEntityByID(id);
|
||||
const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
|
||||
EntityTreeElement* containingElement = tree.getContainingElement(entityID);
|
||||
|
||||
if (extraVerbose) {
|
||||
|
|
Loading…
Reference in a new issue