client decides on new entity-ids, keep EntityItemID class

This commit is contained in:
Seth Alves 2015-05-20 10:42:19 -07:00
parent b32e069f1d
commit a769cfdaf2
68 changed files with 509 additions and 358 deletions

View file

@ -1975,7 +1975,7 @@ void Application::toggleFaceTrackerMute() {
} }
} }
bool Application::exportEntities(const QString& filename, const QVector<QUuid>& entityIDs) { bool Application::exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs) {
QVector<EntityItem*> entities; QVector<EntityItem*> entities;
auto entityTree = _entities.getTree(); auto entityTree = _entities.getTree();
@ -2006,7 +2006,7 @@ bool Application::exportEntities(const QString& filename, const QVector<QUuid>&
auto properties = entityItem->getProperties(); auto properties = entityItem->getProperties();
properties.setPosition(properties.getPosition() - root); properties.setPosition(properties.getPosition() - root);
exportTree.addEntity(entityItem->getID(), properties); exportTree.addEntity(entityItem->getEntityItemID(), properties);
} }
exportTree.writeToJSONFile(filename.toLocal8Bit().constData()); exportTree.writeToJSONFile(filename.toLocal8Bit().constData());
@ -2026,7 +2026,7 @@ bool Application::exportEntities(const QString& filename, float x, float y, floa
for (int i = 0; i < entities.size(); i++) { for (int i = 0; i < entities.size(); i++) {
EntityItemProperties properties = entities.at(i)->getProperties(); EntityItemProperties properties = entities.at(i)->getProperties();
QUuid id = entities.at(i)->getID(); EntityItemID id = entities.at(i)->getEntityItemID();
properties.setPosition(properties.getPosition() - root); properties.setPosition(properties.getPosition() - root);
exportTree.addEntity(id, properties); exportTree.addEntity(id, properties);
} }
@ -2075,7 +2075,7 @@ bool Application::importEntities(const QString& urlOrFilename) {
return success; return success;
} }
QVector<QUuid> Application::pasteEntities(float x, float y, float z) { QVector<EntityItemID> Application::pasteEntities(float x, float y, float z) {
return _entityClipboard.sendEntities(&_entityEditSender, _entities.getTree(), x, y, z); return _entityClipboard.sendEntities(&_entityEditSender, _entities.getTree(), x, y, z);
} }

View file

@ -383,8 +383,8 @@ public slots:
void nodeKilled(SharedNodePointer node); void nodeKilled(SharedNodePointer node);
void packetSent(quint64 length); void packetSent(quint64 length);
QVector<QUuid> pasteEntities(float x, float y, float z); QVector<EntityItemID> pasteEntities(float x, float y, float z);
bool exportEntities(const QString& filename, const QVector<QUuid>& entityIDs); bool exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs);
bool exportEntities(const QString& filename, float x, float y, float z, float scale); bool exportEntities(const QString& filename, float x, float y, float z, float scale);
bool importEntities(const QString& url); bool importEntities(const QString& url);

View file

@ -18,7 +18,7 @@ float ClipboardScriptingInterface::getClipboardContentsLargestDimension() {
return Application::getInstance()->getEntityClipboard()->getContentsLargestDimension(); return Application::getInstance()->getEntityClipboard()->getContentsLargestDimension();
} }
bool ClipboardScriptingInterface::exportEntities(const QString& filename, const QVector<QUuid>& entityIDs) { bool ClipboardScriptingInterface::exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs) {
return Application::getInstance()->exportEntities(filename, entityIDs); return Application::getInstance()->exportEntities(filename, entityIDs);
} }
@ -30,6 +30,6 @@ bool ClipboardScriptingInterface::importEntities(const QString& filename) {
return Application::getInstance()->importEntities(filename); return Application::getInstance()->importEntities(filename);
} }
QVector<QUuid> ClipboardScriptingInterface::pasteEntities(glm::vec3 position) { QVector<EntityItemID> ClipboardScriptingInterface::pasteEntities(glm::vec3 position) {
return Application::getInstance()->pasteEntities(position.x, position.y, position.z); return Application::getInstance()->pasteEntities(position.x, position.y, position.z);
} }

View file

@ -24,9 +24,9 @@ signals:
public slots: public slots:
float getClipboardContentsLargestDimension(); /// returns the largest dimension of everything on the clipboard float getClipboardContentsLargestDimension(); /// returns the largest dimension of everything on the clipboard
bool importEntities(const QString& filename); bool importEntities(const QString& filename);
bool exportEntities(const QString& filename, const QVector<QUuid>& entityIDs); bool exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs);
bool exportEntities(const QString& filename, float x, float y, float z, float s); bool exportEntities(const QString& filename, float x, float y, float z, float s);
QVector<QUuid> pasteEntities(glm::vec3 position); QVector<EntityItemID> pasteEntities(glm::vec3 position);
}; };
#endif // hifi_ClipboardScriptingInterface_h #endif // hifi_ClipboardScriptingInterface_h

View file

@ -66,8 +66,8 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterf
REGISTER_ENTITY_TYPE_WITH_FACTORY(Zone, RenderableZoneEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(Zone, RenderableZoneEntityItem::factory)
REGISTER_ENTITY_TYPE_WITH_FACTORY(Line, RenderableLineEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(Line, RenderableLineEntityItem::factory)
_currentHoverOverEntityID = QUuid(); // makes it the unknown ID _currentHoverOverEntityID = UNKNOWN_ENTITY_ID;
_currentClickingOnEntityID = QUuid(); // makes it the unknown ID _currentClickingOnEntityID = UNKNOWN_ENTITY_ID;
} }
EntityTreeRenderer::~EntityTreeRenderer() { EntityTreeRenderer::~EntityTreeRenderer() {
@ -86,7 +86,7 @@ EntityTreeRenderer::~EntityTreeRenderer() {
void EntityTreeRenderer::clear() { void EntityTreeRenderer::clear() {
leaveAllEntities(); leaveAllEntities();
foreach (const QUuid& entityID, _entityScripts.keys()) { foreach (const EntityItemID& entityID, _entityScripts.keys()) {
checkAndCallUnload(entityID); checkAndCallUnload(entityID);
} }
OctreeRenderer::clear(); OctreeRenderer::clear();
@ -123,9 +123,9 @@ void EntityTreeRenderer::shutdown() {
void EntityTreeRenderer::scriptContentsAvailable(const QUrl& url, const QString& scriptContents) { void EntityTreeRenderer::scriptContentsAvailable(const QUrl& url, const QString& scriptContents) {
if (_waitingOnPreload.contains(url)) { if (_waitingOnPreload.contains(url)) {
QList<QUuid> entityIDs = _waitingOnPreload.values(url); QList<EntityItemID> entityIDs = _waitingOnPreload.values(url);
_waitingOnPreload.remove(url); _waitingOnPreload.remove(url);
foreach(QUuid entityID, entityIDs) { foreach(EntityItemID entityID, entityIDs) {
checkAndCallPreload(entityID); checkAndCallPreload(entityID);
} }
} }
@ -137,7 +137,7 @@ void EntityTreeRenderer::errorInLoadingScript(const QUrl& url) {
} }
} }
QScriptValue EntityTreeRenderer::loadEntityScript(const QUuid& entityItemID, bool isPreload) { QScriptValue EntityTreeRenderer::loadEntityScript(const EntityItemID& entityItemID, bool isPreload) {
EntityItem* entity = static_cast<EntityTree*>(_tree)->findEntityByEntityItemID(entityItemID); EntityItem* entity = static_cast<EntityTree*>(_tree)->findEntityByEntityItemID(entityItemID);
return loadEntityScript(entity, isPreload); return loadEntityScript(entity, isPreload);
} }
@ -204,7 +204,7 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity, bool isPre
// application event loop, which may cause our entity to be deleted on // application event loop, which may cause our entity to be deleted on
// us. We don't really need access the entity after this point, can // us. We don't really need access the entity after this point, can
// can accomplish all we need to here with just the script "text" and the ID. // can accomplish all we need to here with just the script "text" and the ID.
QUuid entityID = entity->getID(); EntityItemID entityID = entity->getEntityItemID();
QString entityScript = entity->getScript(); QString entityScript = entity->getScript();
if (_entityScripts.contains(entityID)) { if (_entityScripts.contains(entityID)) {
@ -282,7 +282,7 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity, bool isPre
return entityScriptObject; // newly constructed return entityScriptObject; // newly constructed
} }
QScriptValue EntityTreeRenderer::getPreviouslyLoadedEntityScript(const QUuid& entityID) { QScriptValue EntityTreeRenderer::getPreviouslyLoadedEntityScript(const EntityItemID& entityID) {
if (_entityScripts.contains(entityID)) { if (_entityScripts.contains(entityID)) {
EntityScriptDetails details = _entityScripts[entityID]; EntityScriptDetails details = _entityScripts[entityID];
return details.scriptObject; // previously loaded return details.scriptObject; // previously loaded
@ -306,7 +306,7 @@ void EntityTreeRenderer::update() {
// Even if we're not moving the mouse, if we started clicking on an entity and we have // Even if we're not moving the mouse, if we started clicking on an entity and we have
// not yet released the hold then this is still considered a holdingClickOnEntity event // not yet released the hold then this is still considered a holdingClickOnEntity event
// and we want to simulate this message here as well as in mouse move // and we want to simulate this message here as well as in mouse move
if (_lastMouseEventValid && !_currentClickingOnEntityID.isNull()) { if (_lastMouseEventValid && !_currentClickingOnEntityID.isInvalidID()) {
emit holdingClickOnEntity(_currentClickingOnEntityID, _lastMouseEvent); emit holdingClickOnEntity(_currentClickingOnEntityID, _lastMouseEvent);
QScriptValueList currentClickingEntityArgs = createMouseEventArgs(_currentClickingOnEntityID, _lastMouseEvent); QScriptValueList currentClickingEntityArgs = createMouseEventArgs(_currentClickingOnEntityID, _lastMouseEvent);
QScriptValue currentClickingEntity = loadEntityScript(_currentClickingOnEntityID); QScriptValue currentClickingEntity = loadEntityScript(_currentClickingOnEntityID);
@ -325,7 +325,7 @@ void EntityTreeRenderer::checkEnterLeaveEntities() {
if (avatarPosition != _lastAvatarPosition) { if (avatarPosition != _lastAvatarPosition) {
float radius = 1.0f; // for now, assume 1 meter radius float radius = 1.0f; // for now, assume 1 meter radius
QVector<const EntityItem*> foundEntities; QVector<const EntityItem*> foundEntities;
QVector<QUuid> entitiesContainingAvatar; QVector<EntityItemID> entitiesContainingAvatar;
// find the entities near us // find the entities near us
_tree->lockForRead(); // don't let someone else change our tree while we search _tree->lockForRead(); // don't let someone else change our tree while we search
@ -334,7 +334,7 @@ void EntityTreeRenderer::checkEnterLeaveEntities() {
// create a list of entities that actually contain the avatar's position // create a list of entities that actually contain the avatar's position
foreach(const EntityItem* entity, foundEntities) { foreach(const EntityItem* entity, foundEntities) {
if (entity->contains(avatarPosition)) { if (entity->contains(avatarPosition)) {
entitiesContainingAvatar << entity->getID(); entitiesContainingAvatar << entity->getEntityItemID();
} }
} }
_tree->unlock(); _tree->unlock();
@ -344,7 +344,7 @@ void EntityTreeRenderer::checkEnterLeaveEntities() {
// for entity IDs that no longer exist. // for entity IDs that no longer exist.
// for all of our previous containing entities, if they are no longer containing then send them a leave event // for all of our previous containing entities, if they are no longer containing then send them a leave event
foreach(const QUuid& entityID, _currentEntitiesInside) { foreach(const EntityItemID& entityID, _currentEntitiesInside) {
if (!entitiesContainingAvatar.contains(entityID)) { if (!entitiesContainingAvatar.contains(entityID)) {
emit leaveEntity(entityID); emit leaveEntity(entityID);
QScriptValueList entityArgs = createEntityArgs(entityID); QScriptValueList entityArgs = createEntityArgs(entityID);
@ -357,7 +357,7 @@ void EntityTreeRenderer::checkEnterLeaveEntities() {
} }
// for all of our new containing entities, if they weren't previously containing then send them an enter event // for all of our new containing entities, if they weren't previously containing then send them an enter event
foreach(const QUuid& entityID, entitiesContainingAvatar) { foreach(const EntityItemID& entityID, entitiesContainingAvatar) {
if (!_currentEntitiesInside.contains(entityID)) { if (!_currentEntitiesInside.contains(entityID)) {
emit enterEntity(entityID); emit enterEntity(entityID);
QScriptValueList entityArgs = createEntityArgs(entityID); QScriptValueList entityArgs = createEntityArgs(entityID);
@ -377,7 +377,7 @@ void EntityTreeRenderer::leaveAllEntities() {
if (_tree && !_shuttingDown) { if (_tree && !_shuttingDown) {
// for all of our previous containing entities, if they are no longer containing then send them a leave event // for all of our previous containing entities, if they are no longer containing then send them a leave event
foreach(const QUuid& entityID, _currentEntitiesInside) { foreach(const EntityItemID& entityID, _currentEntitiesInside) {
emit leaveEntity(entityID); emit leaveEntity(entityID);
QScriptValueList entityArgs = createEntityArgs(entityID); QScriptValueList entityArgs = createEntityArgs(entityID);
QScriptValue entityScript = loadEntityScript(entityID); QScriptValue entityScript = loadEntityScript(entityID);
@ -704,7 +704,7 @@ void EntityTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args)
} else { } else {
// in the case of the volume being equal, we will use the // in the case of the volume being equal, we will use the
// EntityItemID to deterministically pick one entity over the other // EntityItemID to deterministically pick one entity over the other
if (entityItem->getID() < _bestZone->getID()) { if (entityItem->getEntityItemID() < _bestZone->getEntityItemID()) {
_bestZoneVolume = entityVolumeEstimate; _bestZoneVolume = entityVolumeEstimate;
_bestZone = dynamic_cast<const ZoneEntityItem*>(entityItem); _bestZone = dynamic_cast<const ZoneEntityItem*>(entityItem);
} }
@ -840,7 +840,7 @@ RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(cons
(void**)&intersectedEntity, lockType, &result.accurate, (void**)&intersectedEntity, lockType, &result.accurate,
precisionPicking); precisionPicking);
if (result.intersects && intersectedEntity) { if (result.intersects && intersectedEntity) {
result.entityID = intersectedEntity->getID(); result.entityID = intersectedEntity->getEntityItemID();
result.properties = intersectedEntity->getProperties(); result.properties = intersectedEntity->getProperties();
result.intersection = ray.origin + (ray.direction * result.distance); result.intersection = ray.origin + (ray.direction * result.distance);
result.entity = intersectedEntity; result.entity = intersectedEntity;
@ -875,24 +875,24 @@ void EntityTreeRenderer::connectSignalsToSlots(EntityScriptingInterface* entityS
connect(this, &EntityTreeRenderer::leaveEntity, entityScriptingInterface, &EntityScriptingInterface::leaveEntity); connect(this, &EntityTreeRenderer::leaveEntity, entityScriptingInterface, &EntityScriptingInterface::leaveEntity);
} }
QScriptValueList EntityTreeRenderer::createMouseEventArgs(const QUuid& entityID, QMouseEvent* event, unsigned int deviceID) { QScriptValueList EntityTreeRenderer::createMouseEventArgs(const EntityItemID& entityID, QMouseEvent* event, unsigned int deviceID) {
QScriptValueList args; QScriptValueList args;
args << quuidToScriptValue(_entitiesScriptEngine, entityID); args << entityID.toScriptValue(_entitiesScriptEngine);
args << MouseEvent(*event, deviceID).toScriptValue(_entitiesScriptEngine); args << MouseEvent(*event, deviceID).toScriptValue(_entitiesScriptEngine);
return args; return args;
} }
QScriptValueList EntityTreeRenderer::createMouseEventArgs(const QUuid& entityID, const MouseEvent& mouseEvent) { QScriptValueList EntityTreeRenderer::createMouseEventArgs(const EntityItemID& entityID, const MouseEvent& mouseEvent) {
QScriptValueList args; QScriptValueList args;
args << quuidToScriptValue(_entitiesScriptEngine, entityID); args << entityID.toScriptValue(_entitiesScriptEngine);
args << mouseEvent.toScriptValue(_entitiesScriptEngine); args << mouseEvent.toScriptValue(_entitiesScriptEngine);
return args; return args;
} }
QScriptValueList EntityTreeRenderer::createEntityArgs(const QUuid& entityID) { QScriptValueList EntityTreeRenderer::createEntityArgs(const EntityItemID& entityID) {
QScriptValueList args; QScriptValueList args;
args << quuidToScriptValue(_entitiesScriptEngine, entityID); args << entityID.toScriptValue(_entitiesScriptEngine);
return args; return args;
} }
@ -950,7 +950,7 @@ void EntityTreeRenderer::mouseReleaseEvent(QMouseEvent* event, unsigned int devi
// Even if we're no longer intersecting with an entity, if we started clicking on it, and now // Even if we're no longer intersecting with an entity, if we started clicking on it, and now
// we're releasing the button, then this is considered a clickOn event // we're releasing the button, then this is considered a clickOn event
if (!_currentClickingOnEntityID.isNull()) { if (!_currentClickingOnEntityID.isInvalidID()) {
emit clickReleaseOnEntity(_currentClickingOnEntityID, MouseEvent(*event, deviceID)); emit clickReleaseOnEntity(_currentClickingOnEntityID, MouseEvent(*event, deviceID));
QScriptValueList currentClickingEntityArgs = createMouseEventArgs(_currentClickingOnEntityID, event, deviceID); QScriptValueList currentClickingEntityArgs = createMouseEventArgs(_currentClickingOnEntityID, event, deviceID);
@ -961,7 +961,7 @@ void EntityTreeRenderer::mouseReleaseEvent(QMouseEvent* event, unsigned int devi
} }
// makes it the unknown ID, we just released so we can't be clicking on anything // makes it the unknown ID, we just released so we can't be clicking on anything
_currentClickingOnEntityID = QUuid(); _currentClickingOnEntityID = UNKNOWN_ENTITY_ID;
_lastMouseEvent = MouseEvent(*event, deviceID); _lastMouseEvent = MouseEvent(*event, deviceID);
_lastMouseEventValid = true; _lastMouseEventValid = true;
} }
@ -997,7 +997,7 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI
// if we were previously hovering over an entity, and this new entity is not the same as our previous entity // if we were previously hovering over an entity, and this new entity is not the same as our previous entity
// then we need to send the hover leave. // then we need to send the hover leave.
if (!_currentHoverOverEntityID.isNull() && rayPickResult.entityID != _currentHoverOverEntityID) { if (!_currentHoverOverEntityID.isInvalidID() && rayPickResult.entityID != _currentHoverOverEntityID) {
emit hoverLeaveEntity(_currentHoverOverEntityID, MouseEvent(*event, deviceID)); emit hoverLeaveEntity(_currentHoverOverEntityID, MouseEvent(*event, deviceID));
QScriptValueList currentHoverEntityArgs = createMouseEventArgs(_currentHoverOverEntityID, event, deviceID); QScriptValueList currentHoverEntityArgs = createMouseEventArgs(_currentHoverOverEntityID, event, deviceID);
@ -1031,7 +1031,7 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI
// handle the hover logic... // handle the hover logic...
// if we were previously hovering over an entity, and we're no longer hovering over any entity then we need to // if we were previously hovering over an entity, and we're no longer hovering over any entity then we need to
// send the hover leave for our previous entity // send the hover leave for our previous entity
if (!_currentHoverOverEntityID.isNull()) { if (!_currentHoverOverEntityID.isInvalidID()) {
emit hoverLeaveEntity(_currentHoverOverEntityID, MouseEvent(*event, deviceID)); emit hoverLeaveEntity(_currentHoverOverEntityID, MouseEvent(*event, deviceID));
QScriptValueList currentHoverEntityArgs = createMouseEventArgs(_currentHoverOverEntityID, event, deviceID); QScriptValueList currentHoverEntityArgs = createMouseEventArgs(_currentHoverOverEntityID, event, deviceID);
@ -1041,13 +1041,13 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI
currentHoverEntity.property("hoverLeaveEntity").call(currentHoverEntity, currentHoverEntityArgs); currentHoverEntity.property("hoverLeaveEntity").call(currentHoverEntity, currentHoverEntityArgs);
} }
_currentHoverOverEntityID = QUuid(); // makes it the unknown ID _currentHoverOverEntityID = UNKNOWN_ENTITY_ID; // makes it the unknown ID
} }
} }
// Even if we're no longer intersecting with an entity, if we started clicking on an entity and we have // Even if we're no longer intersecting with an entity, if we started clicking on an entity and we have
// not yet released the hold then this is still considered a holdingClickOnEntity event // not yet released the hold then this is still considered a holdingClickOnEntity event
if (!_currentClickingOnEntityID.isNull()) { if (!_currentClickingOnEntityID.isInvalidID()) {
emit holdingClickOnEntity(_currentClickingOnEntityID, MouseEvent(*event, deviceID)); emit holdingClickOnEntity(_currentClickingOnEntityID, MouseEvent(*event, deviceID));
QScriptValueList currentClickingEntityArgs = createMouseEventArgs(_currentClickingOnEntityID, event, deviceID); QScriptValueList currentClickingEntityArgs = createMouseEventArgs(_currentClickingOnEntityID, event, deviceID);
@ -1061,25 +1061,25 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI
_lastMouseEventValid = true; _lastMouseEventValid = true;
} }
void EntityTreeRenderer::deletingEntity(const QUuid& entityID) { void EntityTreeRenderer::deletingEntity(const EntityItemID& entityID) {
if (_tree && !_shuttingDown) { if (_tree && !_shuttingDown) {
checkAndCallUnload(entityID); checkAndCallUnload(entityID);
} }
_entityScripts.remove(entityID); _entityScripts.remove(entityID);
} }
void EntityTreeRenderer::addingEntity(const QUuid& entityID) { void EntityTreeRenderer::addingEntity(const EntityItemID& entityID) {
checkAndCallPreload(entityID); checkAndCallPreload(entityID);
} }
void EntityTreeRenderer::entitySciptChanging(const QUuid& entityID) { void EntityTreeRenderer::entitySciptChanging(const EntityItemID& entityID) {
if (_tree && !_shuttingDown) { if (_tree && !_shuttingDown) {
checkAndCallUnload(entityID); checkAndCallUnload(entityID);
checkAndCallPreload(entityID); checkAndCallPreload(entityID);
} }
} }
void EntityTreeRenderer::checkAndCallPreload(const QUuid& entityID) { void EntityTreeRenderer::checkAndCallPreload(const EntityItemID& entityID) {
if (_tree && !_shuttingDown) { if (_tree && !_shuttingDown) {
// load the entity script if needed... // load the entity script if needed...
QScriptValue entityScript = loadEntityScript(entityID, true); // is preload! QScriptValue entityScript = loadEntityScript(entityID, true); // is preload!
@ -1090,7 +1090,7 @@ void EntityTreeRenderer::checkAndCallPreload(const QUuid& entityID) {
} }
} }
void EntityTreeRenderer::checkAndCallUnload(const QUuid& entityID) { void EntityTreeRenderer::checkAndCallUnload(const EntityItemID& entityID) {
if (_tree && !_shuttingDown) { if (_tree && !_shuttingDown) {
QScriptValue entityScript = getPreviouslyLoadedEntityScript(entityID); QScriptValue entityScript = getPreviouslyLoadedEntityScript(entityID);
if (entityScript.property("unload").isValid()) { if (entityScript.property("unload").isValid()) {
@ -1101,7 +1101,7 @@ void EntityTreeRenderer::checkAndCallUnload(const QUuid& entityID) {
} }
void EntityTreeRenderer::changingEntityID(const QUuid& oldEntityID, const QUuid& newEntityID) { void EntityTreeRenderer::changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID) {
if (_entityScripts.contains(oldEntityID)) { if (_entityScripts.contains(oldEntityID)) {
EntityScriptDetails details = _entityScripts[oldEntityID]; EntityScriptDetails details = _entityScripts[oldEntityID];
_entityScripts.remove(oldEntityID); _entityScripts.remove(oldEntityID);
@ -1109,8 +1109,7 @@ void EntityTreeRenderer::changingEntityID(const QUuid& oldEntityID, const QUuid&
} }
} }
void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityTree* entityTree, void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityTree* entityTree, const EntityItemID& id, const Collision& collision) {
const QUuid& id, const Collision& collision) {
EntityItem* entity = entityTree->findEntityByEntityItemID(id); EntityItem* entity = entityTree->findEntityByEntityItemID(id);
if (!entity) { if (!entity) {
return; return;
@ -1168,8 +1167,8 @@ void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityT
injectorThread->start(); injectorThread->start();
} }
void EntityTreeRenderer::entityCollisionWithEntity(const QUuid& idA, const QUuid& idB, void EntityTreeRenderer::entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB,
const Collision& collision) { const Collision& collision) {
// If we don't have a tree, or we're in the process of shutting down, then don't // If we don't have a tree, or we're in the process of shutting down, then don't
// process these events. // process these events.
if (!_tree || _shuttingDown) { if (!_tree || _shuttingDown) {
@ -1199,8 +1198,8 @@ void EntityTreeRenderer::entityCollisionWithEntity(const QUuid& idA, const QUuid
QScriptValue entityScriptA = loadEntityScript(idA); QScriptValue entityScriptA = loadEntityScript(idA);
if (entityScriptA.property("collisionWithEntity").isValid()) { if (entityScriptA.property("collisionWithEntity").isValid()) {
QScriptValueList args; QScriptValueList args;
args << quuidToScriptValue(_entitiesScriptEngine, idA); args << idA.toScriptValue(_entitiesScriptEngine);
args << quuidToScriptValue(_entitiesScriptEngine, idB); args << idB.toScriptValue(_entitiesScriptEngine);
args << collisionToScriptValue(_entitiesScriptEngine, collision); args << collisionToScriptValue(_entitiesScriptEngine, collision);
entityScriptA.property("collisionWithEntity").call(entityScriptA, args); entityScriptA.property("collisionWithEntity").call(entityScriptA, args);
} }
@ -1208,8 +1207,8 @@ void EntityTreeRenderer::entityCollisionWithEntity(const QUuid& idA, const QUuid
QScriptValue entityScriptB = loadEntityScript(idB); QScriptValue entityScriptB = loadEntityScript(idB);
if (entityScriptB.property("collisionWithEntity").isValid()) { if (entityScriptB.property("collisionWithEntity").isValid()) {
QScriptValueList args; QScriptValueList args;
args << quuidToScriptValue(_entitiesScriptEngine, idA); args << idB.toScriptValue(_entitiesScriptEngine);
args << quuidToScriptValue(_entitiesScriptEngine, idB); args << idA.toScriptValue(_entitiesScriptEngine);
args << collisionToScriptValue(_entitiesScriptEngine, collision); args << collisionToScriptValue(_entitiesScriptEngine, collision);
entityScriptB.property("collisionWithEntity").call(entityScriptA, args); entityScriptB.property("collisionWithEntity").call(entityScriptA, args);
} }

View file

@ -97,23 +97,23 @@ signals:
void mouseMoveOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId); void mouseMoveOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId);
void mouseReleaseOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId); void mouseReleaseOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId);
void clickDownOnEntity(const QUuid& entityItemID, const MouseEvent& event); void clickDownOnEntity(const EntityItemID& entityItemID, const MouseEvent& event);
void holdingClickOnEntity(const QUuid& entityItemID, const MouseEvent& event); void holdingClickOnEntity(const EntityItemID& entityItemID, const MouseEvent& event);
void clickReleaseOnEntity(const QUuid& entityItemID, const MouseEvent& event); void clickReleaseOnEntity(const EntityItemID& entityItemID, const MouseEvent& event);
void hoverEnterEntity(const QUuid& entityItemID, const MouseEvent& event); void hoverEnterEntity(const EntityItemID& entityItemID, const MouseEvent& event);
void hoverOverEntity(const QUuid& entityItemID, const MouseEvent& event); void hoverOverEntity(const EntityItemID& entityItemID, const MouseEvent& event);
void hoverLeaveEntity(const QUuid& entityItemID, const MouseEvent& event); void hoverLeaveEntity(const EntityItemID& entityItemID, const MouseEvent& event);
void enterEntity(const QUuid& entityItemID); void enterEntity(const EntityItemID& entityItemID);
void leaveEntity(const QUuid& entityItemID); void leaveEntity(const EntityItemID& entityItemID);
public slots: public slots:
void addingEntity(const QUuid& entityID); void addingEntity(const EntityItemID& entityID);
void deletingEntity(const QUuid& entityID); void deletingEntity(const EntityItemID& entityID);
void changingEntityID(const QUuid& oldEntityID, const QUuid& newEntityID); void changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID);
void entitySciptChanging(const QUuid& entityID); void entitySciptChanging(const EntityItemID& entityID);
void entityCollisionWithEntity(const QUuid& idA, const QUuid& idB, const Collision& collision); void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
// optional slots that can be wired to menu items // optional slots that can be wired to menu items
void setDisplayElementChildProxies(bool value) { _displayElementChildProxies = value; } void setDisplayElementChildProxies(bool value) { _displayElementChildProxies = value; }
@ -126,37 +126,37 @@ protected:
private: private:
void renderElementProxy(EntityTreeElement* entityTreeElement); void renderElementProxy(EntityTreeElement* entityTreeElement);
void checkAndCallPreload(const QUuid& entityID); void checkAndCallPreload(const EntityItemID& entityID);
void checkAndCallUnload(const QUuid& entityID); void checkAndCallUnload(const EntityItemID& entityID);
QList<Model*> _releasedModels; QList<Model*> _releasedModels;
void renderProxies(const EntityItem* entity, RenderArgs* args); void renderProxies(const EntityItem* entity, RenderArgs* args);
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType,
bool precisionPicking); bool precisionPicking);
QUuid _currentHoverOverEntityID; EntityItemID _currentHoverOverEntityID;
QUuid _currentClickingOnEntityID; EntityItemID _currentClickingOnEntityID;
QScriptValueList createEntityArgs(const QUuid& entityID); QScriptValueList createEntityArgs(const EntityItemID& entityID);
void checkEnterLeaveEntities(); void checkEnterLeaveEntities();
void leaveAllEntities(); void leaveAllEntities();
glm::vec3 _lastAvatarPosition; glm::vec3 _lastAvatarPosition;
QVector<QUuid> _currentEntitiesInside; QVector<EntityItemID> _currentEntitiesInside;
bool _wantScripts; bool _wantScripts;
ScriptEngine* _entitiesScriptEngine; ScriptEngine* _entitiesScriptEngine;
ScriptEngine* _sandboxScriptEngine; ScriptEngine* _sandboxScriptEngine;
QScriptValue loadEntityScript(EntityItem* entity, bool isPreload = false); QScriptValue loadEntityScript(EntityItem* entity, bool isPreload = false);
QScriptValue loadEntityScript(const QUuid& entityItemID, bool isPreload = false); QScriptValue loadEntityScript(const EntityItemID& entityItemID, bool isPreload = false);
QScriptValue getPreviouslyLoadedEntityScript(const QUuid& entityItemID); QScriptValue getPreviouslyLoadedEntityScript(const EntityItemID& entityItemID);
QString loadScriptContents(const QString& scriptMaybeURLorText, bool& isURL, bool& isPending, QUrl& url); QString loadScriptContents(const QString& scriptMaybeURLorText, bool& isURL, bool& isPending, QUrl& url);
QScriptValueList createMouseEventArgs(const QUuid& entityID, QMouseEvent* event, unsigned int deviceID); QScriptValueList createMouseEventArgs(const EntityItemID& entityID, QMouseEvent* event, unsigned int deviceID);
QScriptValueList createMouseEventArgs(const QUuid& entityID, const MouseEvent& mouseEvent); QScriptValueList createMouseEventArgs(const EntityItemID& entityID, const MouseEvent& mouseEvent);
QHash<QUuid, EntityScriptDetails> _entityScripts; QHash<EntityItemID, EntityScriptDetails> _entityScripts;
void playEntityCollisionSound(const QUuid& myNodeID, EntityTree* entityTree, const QUuid& id, const Collision& collision); void playEntityCollisionSound(const QUuid& myNodeID, EntityTree* entityTree, const EntityItemID& id, const Collision& collision);
AbstractAudioInterface* _localAudioInterface; // So we can render collision sounds AbstractAudioInterface* _localAudioInterface; // So we can render collision sounds
bool _lastMouseEventValid; bool _lastMouseEventValid;
@ -170,7 +170,7 @@ private:
bool _shuttingDown = false; bool _shuttingDown = false;
QMultiMap<QUrl, QUuid> _waitingOnPreload; QMultiMap<QUrl, EntityItemID> _waitingOnPreload;
bool _hasPreviousZone = false; bool _hasPreviousZone = false;
const ZoneEntityItem* _bestZone; const ZoneEntityItem* _bestZone;

View file

@ -18,7 +18,7 @@
#include "RenderableBoxEntityItem.h" #include "RenderableBoxEntityItem.h"
EntityItem* RenderableBoxEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* RenderableBoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
return new RenderableBoxEntityItem(entityID, properties); return new RenderableBoxEntityItem(entityID, properties);
} }

View file

@ -17,9 +17,9 @@
class RenderableBoxEntityItem : public BoxEntityItem { class RenderableBoxEntityItem : public BoxEntityItem {
public: public:
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
RenderableBoxEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : RenderableBoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
BoxEntityItem(entityItemID, properties) BoxEntityItem(entityItemID, properties)
{ } { }

View file

@ -19,7 +19,7 @@
#include "RenderableLightEntityItem.h" #include "RenderableLightEntityItem.h"
EntityItem* RenderableLightEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* RenderableLightEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
return new RenderableLightEntityItem(entityID, properties); return new RenderableLightEntityItem(entityID, properties);
} }

View file

@ -16,9 +16,9 @@
class RenderableLightEntityItem : public LightEntityItem { class RenderableLightEntityItem : public LightEntityItem {
public: public:
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
RenderableLightEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : RenderableLightEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
LightEntityItem(entityItemID, properties) LightEntityItem(entityItemID, properties)
{ } { }

View file

@ -18,7 +18,7 @@
#include "RenderableLineEntityItem.h" #include "RenderableLineEntityItem.h"
EntityItem* RenderableLineEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* RenderableLineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
return new RenderableLineEntityItem(entityID, properties); return new RenderableLineEntityItem(entityID, properties);
} }

View file

@ -17,9 +17,9 @@
class RenderableLineEntityItem : public LineEntityItem { class RenderableLineEntityItem : public LineEntityItem {
public: public:
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
RenderableLineEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : RenderableLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
LineEntityItem(entityItemID, properties) { } LineEntityItem(entityItemID, properties) { }
virtual void render(RenderArgs* args); virtual void render(RenderArgs* args);

View file

@ -23,7 +23,7 @@
#include "EntitiesRendererLogging.h" #include "EntitiesRendererLogging.h"
#include "RenderableModelEntityItem.h" #include "RenderableModelEntityItem.h"
EntityItem* RenderableModelEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* RenderableModelEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
return new RenderableModelEntityItem(entityID, properties); return new RenderableModelEntityItem(entityID, properties);
} }

View file

@ -23,9 +23,9 @@ class EntityTreeRenderer;
class RenderableModelEntityItem : public ModelEntityItem { class RenderableModelEntityItem : public ModelEntityItem {
public: public:
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
RenderableModelEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : RenderableModelEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
ModelEntityItem(entityItemID, properties), ModelEntityItem(entityItemID, properties),
_model(NULL), _model(NULL),
_needsInitialSimulation(true), _needsInitialSimulation(true),

View file

@ -20,12 +20,11 @@
#include "RenderableParticleEffectEntityItem.h" #include "RenderableParticleEffectEntityItem.h"
EntityItem* RenderableParticleEffectEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* RenderableParticleEffectEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
return new RenderableParticleEffectEntityItem(entityID, properties); return new RenderableParticleEffectEntityItem(entityID, properties);
} }
RenderableParticleEffectEntityItem::RenderableParticleEffectEntityItem(const QUuid& entityItemID, RenderableParticleEffectEntityItem::RenderableParticleEffectEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
const EntityItemProperties& properties) :
ParticleEffectEntityItem(entityItemID, properties) { ParticleEffectEntityItem(entityItemID, properties) {
_cacheID = DependencyManager::get<GeometryCache>()->allocateID(); _cacheID = DependencyManager::get<GeometryCache>()->allocateID();
} }

View file

@ -16,8 +16,8 @@
class RenderableParticleEffectEntityItem : public ParticleEffectEntityItem { class RenderableParticleEffectEntityItem : public ParticleEffectEntityItem {
public: public:
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
RenderableParticleEffectEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); RenderableParticleEffectEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
virtual void render(RenderArgs* args); virtual void render(RenderArgs* args);
void renderUntexturedQuads(RenderArgs* args); void renderUntexturedQuads(RenderArgs* args);

View file

@ -19,7 +19,7 @@
#include "RenderableSphereEntityItem.h" #include "RenderableSphereEntityItem.h"
EntityItem* RenderableSphereEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* RenderableSphereEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
return new RenderableSphereEntityItem(entityID, properties); return new RenderableSphereEntityItem(entityID, properties);
} }

View file

@ -16,9 +16,9 @@
class RenderableSphereEntityItem : public SphereEntityItem { class RenderableSphereEntityItem : public SphereEntityItem {
public: public:
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
RenderableSphereEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : RenderableSphereEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
SphereEntityItem(entityItemID, properties) SphereEntityItem(entityItemID, properties)
{ } { }

View file

@ -23,7 +23,7 @@
const int FIXED_FONT_POINT_SIZE = 40; const int FIXED_FONT_POINT_SIZE = 40;
EntityItem* RenderableTextEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* RenderableTextEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
return new RenderableTextEntityItem(entityID, properties); return new RenderableTextEntityItem(entityID, properties);
} }
@ -37,7 +37,7 @@ void RenderableTextEntityItem::render(RenderArgs* args) {
float leftMargin = 0.1f; float leftMargin = 0.1f;
float topMargin = 0.1f; float topMargin = 0.1f;
//qCDebug(entitytree) << "RenderableTextEntityItem::render() id:" << getID() << "text:" << getText(); //qCDebug(entitytree) << "RenderableTextEntityItem::render() id:" << getEntityItemID() << "text:" << getText();
glPushMatrix(); glPushMatrix();
{ {

View file

@ -16,9 +16,9 @@
class RenderableTextEntityItem : public TextEntityItem { class RenderableTextEntityItem : public TextEntityItem {
public: public:
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
RenderableTextEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : RenderableTextEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
TextEntityItem(entityItemID, properties) TextEntityItem(entityItemID, properties)
{ } { }

View file

@ -29,11 +29,11 @@ const int FIXED_FONT_POINT_SIZE = 40;
const float DPI = 30.47; const float DPI = 30.47;
const float METERS_TO_INCHES = 39.3701; const float METERS_TO_INCHES = 39.3701;
EntityItem* RenderableWebEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* RenderableWebEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
return new RenderableWebEntityItem(entityID, properties); return new RenderableWebEntityItem(entityID, properties);
} }
RenderableWebEntityItem::RenderableWebEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : RenderableWebEntityItem::RenderableWebEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
WebEntityItem(entityItemID, properties) { WebEntityItem(entityItemID, properties) {
qDebug() << "Created web entity " << getID(); qDebug() << "Created web entity " << getID();
} }
@ -99,7 +99,7 @@ void RenderableWebEntityItem::render(RenderArgs* args) {
return; return;
} }
if (intersection.entityID == getID()) { if (intersection.entityID.id == getID()) {
if (event->button() == Qt::MouseButton::RightButton) { if (event->button() == Qt::MouseButton::RightButton) {
if (event->type() == QEvent::MouseButtonRelease) { if (event->type() == QEvent::MouseButtonRelease) {
AbstractViewStateInterface::instance()->postLambdaEvent([this] { AbstractViewStateInterface::instance()->postLambdaEvent([this] {

View file

@ -17,9 +17,9 @@ class OffscreenQmlSurface;
class RenderableWebEntityItem : public WebEntityItem { class RenderableWebEntityItem : public WebEntityItem {
public: public:
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
RenderableWebEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); RenderableWebEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
~RenderableWebEntityItem(); ~RenderableWebEntityItem();
virtual void render(RenderArgs* args); virtual void render(RenderArgs* args);

View file

@ -16,7 +16,7 @@
#include <GeometryCache.h> #include <GeometryCache.h>
#include <PerfStat.h> #include <PerfStat.h>
EntityItem* RenderableZoneEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* RenderableZoneEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
return new RenderableZoneEntityItem(entityID, properties); return new RenderableZoneEntityItem(entityID, properties);
} }

View file

@ -19,9 +19,9 @@ class NetworkGeometry;
class RenderableZoneEntityItem : public ZoneEntityItem { class RenderableZoneEntityItem : public ZoneEntityItem {
public: public:
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
RenderableZoneEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : RenderableZoneEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
ZoneEntityItem(entityItemID, properties), ZoneEntityItem(entityItemID, properties),
_model(NULL), _model(NULL),
_needsInitialSimulation(true) _needsInitialSimulation(true)

View file

@ -46,7 +46,7 @@ bool AddEntityOperator::preRecursion(OctreeElement* element) {
if (entityTreeElement->bestFitBounds(_newEntityBox)) { if (entityTreeElement->bestFitBounds(_newEntityBox)) {
entityTreeElement->addEntityItem(_newEntity); entityTreeElement->addEntityItem(_newEntity);
_tree->setContainingElement(_newEntity->getID(), entityTreeElement); _tree->setContainingElement(_newEntity->getEntityItemID(), entityTreeElement);
_foundNew = true; _foundNew = true;
keepSearching = false; keepSearching = false;

View file

@ -20,12 +20,12 @@
#include "EntityTreeElement.h" #include "EntityTreeElement.h"
EntityItem* BoxEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* BoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
EntityItem* result = new BoxEntityItem(entityID, properties); EntityItem* result = new BoxEntityItem(entityID, properties);
return result; return result;
} }
BoxEntityItem::BoxEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : BoxEntityItem::BoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
EntityItem(entityItemID) EntityItem(entityItemID)
{ {
_type = EntityTypes::Box; _type = EntityTypes::Box;
@ -99,7 +99,7 @@ void BoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitst
void BoxEntityItem::debugDump() const { void BoxEntityItem::debugDump() const {
quint64 now = usecTimestampNow(); quint64 now = usecTimestampNow();
qCDebug(entities) << " BOX EntityItem id:" << getID() << "---------------------------------------------"; qCDebug(entities) << " BOX EntityItem id:" << getEntityItemID() << "---------------------------------------------";
qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2];
qCDebug(entities) << " position:" << debugTreeVector(_position); qCDebug(entities) << " position:" << debugTreeVector(_position);
qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions);

View file

@ -16,9 +16,9 @@
class BoxEntityItem : public EntityItem { class BoxEntityItem : public EntityItem {
public: public:
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
BoxEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); BoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
ALLOW_INSTANTIATION // This class can be instantiated ALLOW_INSTANTIATION // This class can be instantiated

View file

@ -16,7 +16,7 @@
#include "EntitiesLogging.h" #include "EntitiesLogging.h"
#include "DeleteEntityOperator.h" #include "DeleteEntityOperator.h"
DeleteEntityOperator::DeleteEntityOperator(EntityTree* tree, const QUuid& searchEntityID) : DeleteEntityOperator::DeleteEntityOperator(EntityTree* tree, const EntityItemID& searchEntityID) :
_tree(tree), _tree(tree),
_changeTime(usecTimestampNow()), _changeTime(usecTimestampNow()),
_foundCount(0), _foundCount(0),
@ -36,7 +36,7 @@ DeleteEntityOperator::DeleteEntityOperator(EntityTree* tree) :
{ {
} }
void DeleteEntityOperator::addEntityIDToDeleteList(const QUuid& searchEntityID) { void DeleteEntityOperator::addEntityIDToDeleteList(const EntityItemID& searchEntityID) {
// check our tree, to determine if this entity is known // check our tree, to determine if this entity is known
EntityToDeleteDetails details; EntityToDeleteDetails details;
details.containingElement = _tree->getContainingElement(searchEntityID); details.containingElement = _tree->getContainingElement(searchEntityID);
@ -95,7 +95,7 @@ bool DeleteEntityOperator::preRecursion(OctreeElement* element) {
EntityItem* theEntity = details.entity; EntityItem* theEntity = details.entity;
bool entityDeleted = entityTreeElement->removeEntityItem(theEntity); // remove it from the element bool entityDeleted = entityTreeElement->removeEntityItem(theEntity); // remove it from the element
assert(entityDeleted); assert(entityDeleted);
_tree->setContainingElement(details.entity->getID(), NULL); // update or id to element lookup _tree->setContainingElement(details.entity->getEntityItemID(), NULL); // update or id to element lookup
_foundCount++; _foundCount++;
} }
} }

View file

@ -22,20 +22,20 @@ public:
typedef QSet<EntityToDeleteDetails> RemovedEntities; typedef QSet<EntityToDeleteDetails> RemovedEntities;
inline uint qHash(const EntityToDeleteDetails& a, uint seed) { inline uint qHash(const EntityToDeleteDetails& a, uint seed) {
return qHash(a.entity->getID(), seed); return qHash(a.entity->getEntityItemID(), seed);
} }
inline bool operator==(const EntityToDeleteDetails& a, const EntityToDeleteDetails& b) { inline bool operator==(const EntityToDeleteDetails& a, const EntityToDeleteDetails& b) {
return a.entity->getID() == b.entity->getID(); return a.entity->getEntityItemID() == b.entity->getEntityItemID();
} }
class DeleteEntityOperator : public RecurseOctreeOperator { class DeleteEntityOperator : public RecurseOctreeOperator {
public: public:
DeleteEntityOperator(EntityTree* tree); DeleteEntityOperator(EntityTree* tree);
DeleteEntityOperator(EntityTree* tree, const QUuid& searchEntityID); DeleteEntityOperator(EntityTree* tree, const EntityItemID& searchEntityID);
~DeleteEntityOperator(); ~DeleteEntityOperator();
void addEntityIDToDeleteList(const QUuid& searchEntityID); void addEntityIDToDeleteList(const EntityItemID& searchEntityID);
virtual bool preRecursion(OctreeElement* element); virtual bool preRecursion(OctreeElement* element);
virtual bool postRecursion(OctreeElement* element); virtual bool postRecursion(OctreeElement* element);

View file

@ -26,8 +26,8 @@ void EntityEditPacketSender::adjustEditPacketForClockSkew(PacketType type,
} }
} }
void EntityEditPacketSender::queueEditEntityMessage(PacketType type, QUuid modelID, void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemID modelID,
const EntityItemProperties& properties) { const EntityItemProperties& properties) {
if (!_shouldSend) { if (!_shouldSend) {
return; // bail early return; // bail early
} }
@ -46,7 +46,7 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, QUuid model
} }
} }
void EntityEditPacketSender::queueEraseEntityMessage(const QUuid& entityItemID) { void EntityEditPacketSender::queueEraseEntityMessage(const EntityItemID& entityItemID) {
if (!_shouldSend) { if (!_shouldSend) {
return; // bail early return; // bail early
} }

View file

@ -24,9 +24,9 @@ public:
/// which voxel-server node or nodes the packet should be sent to. Can be called even before voxel servers are known, in /// which voxel-server node or nodes the packet should be sent to. Can be called even before voxel servers are known, in
/// which case up to MaxPendingMessages will be buffered and processed when voxel servers are known. /// which case up to MaxPendingMessages will be buffered and processed when voxel servers are known.
/// NOTE: EntityItemProperties assumes that all distances are in meter units /// NOTE: EntityItemProperties assumes that all distances are in meter units
void queueEditEntityMessage(PacketType type, QUuid modelID, const EntityItemProperties& properties); void queueEditEntityMessage(PacketType type, EntityItemID modelID, const EntityItemProperties& properties);
void queueEraseEntityMessage(const QUuid& entityItemID); void queueEraseEntityMessage(const EntityItemID& entityItemID);
// My server type is the model server // My server type is the model server
virtual char getMyNodeType() const { return NodeType::EntityServer; } virtual char getMyNodeType() const { return NodeType::EntityServer; }

View file

@ -28,9 +28,9 @@
bool EntityItem::_sendPhysicsUpdates = true; bool EntityItem::_sendPhysicsUpdates = true;
EntityItem::EntityItem(const QUuid& entityItemID) : EntityItem::EntityItem(const EntityItemID& entityItemID) :
_type(EntityTypes::Unknown), _type(EntityTypes::Unknown),
_id(entityItemID), _id(entityItemID.id),
_lastSimulated(0), _lastSimulated(0),
_lastUpdated(0), _lastUpdated(0),
_lastEdited(0), _lastEdited(0),
@ -76,7 +76,7 @@ EntityItem::EntityItem(const QUuid& entityItemID) :
_lastUpdated = now; _lastUpdated = now;
} }
EntityItem::EntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID)
{ {
setProperties(properties); setProperties(properties);
} }
@ -156,8 +156,8 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet
// If we are being called for a subsequent pass at appendEntityData() that failed to completely encode this item, // If we are being called for a subsequent pass at appendEntityData() that failed to completely encode this item,
// then our entityTreeElementExtraEncodeData should include data about which properties we need to append. // then our entityTreeElementExtraEncodeData should include data about which properties we need to append.
if (entityTreeElementExtraEncodeData && entityTreeElementExtraEncodeData->entities.contains(getID())) { if (entityTreeElementExtraEncodeData && entityTreeElementExtraEncodeData->entities.contains(getEntityItemID())) {
requestedProperties = entityTreeElementExtraEncodeData->entities.value(getID()); requestedProperties = entityTreeElementExtraEncodeData->entities.value(getEntityItemID());
} }
LevelDetails entityLevel = packetData->startLevel(); LevelDetails entityLevel = packetData->startLevel();
@ -167,7 +167,7 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet
#ifdef WANT_DEBUG #ifdef WANT_DEBUG
float editedAgo = getEditedAgo(); float editedAgo = getEditedAgo();
QString agoAsString = formatSecondsElapsed(editedAgo); QString agoAsString = formatSecondsElapsed(editedAgo);
qCDebug(entities) << "Writing entity " << getID() << " to buffer, lastEdited =" << lastEdited qCDebug(entities) << "Writing entity " << getEntityItemID() << " to buffer, lastEdited =" << lastEdited
<< " ago=" << editedAgo << "seconds - " << agoAsString; << " ago=" << editedAgo << "seconds - " << agoAsString;
#endif #endif
@ -284,7 +284,7 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet
// If any part of the model items didn't fit, then the element is considered partial // If any part of the model items didn't fit, then the element is considered partial
if (appendState != OctreeElement::COMPLETED) { if (appendState != OctreeElement::COMPLETED) {
// add this item into our list for the next appendElementData() pass // add this item into our list for the next appendElementData() pass
entityTreeElementExtraEncodeData->entities.insert(getID(), propertiesDidntFit); entityTreeElementExtraEncodeData->entities.insert(getEntityItemID(), propertiesDidntFit);
} }
return appendState; return appendState;
@ -308,6 +308,16 @@ int EntityItem::expectedBytes() {
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) {
// NOTE: This shouldn't happen. The only versions of the bit stream that didn't support split mtu buffers should
// be handled by the model subclass and shouldn't call this routine.
qCDebug(entities) << "EntityItem::readEntityDataFromBuffer()... "
"ERROR CASE...args.bitstreamVersion < VERSION_ENTITIES_SUPPORT_SPLIT_MTU";
return 0;
}
// if this bitstream indicates that this node is the simulation owner, ignore any physics-related updates. // if this bitstream indicates that this node is the simulation owner, ignore any physics-related updates.
glm::vec3 savePosition = _position; glm::vec3 savePosition = _position;
glm::quat saveRotation = _rotation; glm::quat saveRotation = _rotation;
@ -375,7 +385,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
QString agoAsString = formatSecondsElapsed(editedAgo); QString agoAsString = formatSecondsElapsed(editedAgo);
QString ageAsString = formatSecondsElapsed(getAge()); QString ageAsString = formatSecondsElapsed(getAge());
qCDebug(entities) << "------------------------------------------"; qCDebug(entities) << "------------------------------------------";
qCDebug(entities) << "Loading entity " << getID() << " from buffer..."; qCDebug(entities) << "Loading entity " << getEntityItemID() << " from buffer...";
qCDebug(entities) << "------------------------------------------"; qCDebug(entities) << "------------------------------------------";
debugDump(); debugDump();
qCDebug(entities) << "------------------------------------------"; qCDebug(entities) << "------------------------------------------";
@ -402,7 +412,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
#ifdef WANT_DEBUG #ifdef WANT_DEBUG
qCDebug(entities) << "data from server **************** "; qCDebug(entities) << "data from server **************** ";
qCDebug(entities) << " entityItemID:" << getID(); qCDebug(entities) << " entityItemID:" << getEntityItemID();
qCDebug(entities) << " now:" << now; qCDebug(entities) << " now:" << now;
qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now);
qCDebug(entities) << " lastEditedFromBuffer:" << debugTime(lastEditedFromBuffer, now); qCDebug(entities) << " lastEditedFromBuffer:" << debugTime(lastEditedFromBuffer, now);
@ -492,7 +502,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
#ifdef WANT_DEBUG #ifdef WANT_DEBUG
if (overwriteLocalData) { if (overwriteLocalData) {
qCDebug(entities) << "EntityItem::readEntityDataFromBuffer()... changed entity:" << getID(); qCDebug(entities) << "EntityItem::readEntityDataFromBuffer()... changed entity:" << getEntityItemID();
qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now);
qCDebug(entities) << " getLastSimulated:" << debugTime(getLastSimulated(), now); qCDebug(entities) << " getLastSimulated:" << debugTime(getLastSimulated(), now);
qCDebug(entities) << " getLastUpdated:" << debugTime(getLastUpdated(), now); qCDebug(entities) << " getLastUpdated:" << debugTime(getLastUpdated(), now);
@ -626,7 +636,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
} }
void EntityItem::debugDump() const { void EntityItem::debugDump() const {
qCDebug(entities) << "EntityItem id:" << getID(); qCDebug(entities) << "EntityItem id:" << getEntityItemID();
qCDebug(entities, " edited ago:%f", getEditedAgo()); qCDebug(entities, " edited ago:%f", getEditedAgo());
qCDebug(entities, " position:%f,%f,%f", _position.x, _position.y, _position.z); qCDebug(entities, " position:%f,%f,%f", _position.x, _position.y, _position.z);
qCDebug(entities) << " dimensions:" << _dimensions; qCDebug(entities) << " dimensions:" << _dimensions;
@ -700,7 +710,7 @@ void EntityItem::simulate(const quint64& now) {
#ifdef WANT_DEBUG #ifdef WANT_DEBUG
qCDebug(entities) << "********** EntityItem::simulate()"; qCDebug(entities) << "********** EntityItem::simulate()";
qCDebug(entities) << " entity ID=" << getID(); qCDebug(entities) << " entity ID=" << getEntityItemID();
qCDebug(entities) << " simulator ID=" << getSimulatorID(); qCDebug(entities) << " simulator ID=" << getSimulatorID();
qCDebug(entities) << " now=" << now; qCDebug(entities) << " now=" << now;
qCDebug(entities) << " _lastSimulated=" << _lastSimulated; qCDebug(entities) << " _lastSimulated=" << _lastSimulated;

View file

@ -23,6 +23,7 @@
#include <OctreePacketData.h> #include <OctreePacketData.h>
#include <ShapeInfo.h> #include <ShapeInfo.h>
#include "EntityItemID.h"
#include "EntityItemProperties.h" #include "EntityItemProperties.h"
#include "EntityItemPropertiesDefaults.h" #include "EntityItemPropertiesDefaults.h"
#include "EntityTypes.h" #include "EntityTypes.h"
@ -88,13 +89,14 @@ public:
DONT_ALLOW_INSTANTIATION // This class can not be instantiated directly DONT_ALLOW_INSTANTIATION // This class can not be instantiated directly
EntityItem(const QUuid& entityItemID); EntityItem(const EntityItemID& entityItemID);
EntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); EntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
virtual ~EntityItem(); virtual ~EntityItem();
// ID and EntityItemID related methods // ID and EntityItemID related methods
const QUuid& getID() const { return _id; } const QUuid& getID() const { return _id; }
void setID(const QUuid& id) { _id = id; } void setID(const QUuid& id) { _id = id; }
EntityItemID getEntityItemID() const { return EntityItemID(_id); }
// methods for getting/setting all properties of an entity // methods for getting/setting all properties of an entity
virtual EntityItemProperties getProperties() const; virtual EntityItemProperties getProperties() const;
@ -138,8 +140,8 @@ public:
int& propertyCount, int& propertyCount,
OctreeElement::AppendState& appendState) const { /* do nothing*/ }; OctreeElement::AppendState& appendState) const { /* do nothing*/ };
static QUuid readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead, static EntityItemID readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead,
ReadBitstreamToTreeParams& args); ReadBitstreamToTreeParams& args);
virtual int readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args); virtual int readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args);

View file

@ -0,0 +1,57 @@
//
// EntityItemID.cpp
// libraries/entities/src
//
// Created by Brad Hefta-Gaub on 12/4/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QtCore/QObject>
#include <QDebug>
#include <PacketHeaders.h>
#include "RegisteredMetaTypes.h"
#include "EntityItemID.h"
EntityItemID::EntityItemID() :
id(UNKNOWN_ENTITY_ID)
{
}
EntityItemID::EntityItemID(const QUuid& id) :
id(id)
{
}
EntityItemID::EntityItemID(const EntityItemID& other) : id(other.id)
{
}
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);
}
return result;
}
QScriptValue EntityItemID::toScriptValue(QScriptEngine* engine) const {
return EntityItemIDtoScriptValue(engine, *this);
}
QScriptValue EntityItemIDtoScriptValue(QScriptEngine* engine, const EntityItemID& id) {
return quuidToScriptValue(engine, id.id);
}
void EntityItemIDfromScriptValue(const QScriptValue &object, EntityItemID& id) {
quuidFromScriptValue(object, id.id);
}

View file

@ -0,0 +1,71 @@
//
// EntityItemID.h
// libraries/entities/src
//
// Created by Brad Hefta-Gaub on 12/4/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_EntityItemID_h
#define hifi_EntityItemID_h
#include <stdint.h>
#include <QObject>
#include <QHash>
#include <QScriptEngine>
#include <QUuid>
// const uint32_t UNKNOWN_ENTITY_TOKEN = 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.
class EntityItemID {
public:
EntityItemID();
EntityItemID(const QUuid& id);
EntityItemID(const EntityItemID& other);
static EntityItemID readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead);
QScriptValue toScriptValue(QScriptEngine* engine) const;
bool isInvalidID() const { return id == UNKNOWN_ENTITY_ID; }
QUuid id;
};
inline bool operator<(const EntityItemID& a, const EntityItemID& b) {
return a.id == b.id;
}
inline bool operator==(const EntityItemID& a, const EntityItemID& b) {
return a.id == b.id;
}
inline bool operator!=(const EntityItemID& a, const EntityItemID& b) {
return !(a == b);
}
inline uint qHash(const EntityItemID& a, uint seed) {
return qHash(a.id, seed);
}
inline QDebug operator<<(QDebug debug, const EntityItemID& id) {
debug << "[entity-id:" << id.id << "]";
return debug;
}
Q_DECLARE_METATYPE(EntityItemID);
Q_DECLARE_METATYPE(QVector<EntityItemID>);
QScriptValue EntityItemIDtoScriptValue(QScriptEngine* engine, const EntityItemID& properties);
void EntityItemIDfromScriptValue(const QScriptValue &object, EntityItemID& properties);
#endif // hifi_EntityItemID_h

View file

@ -91,7 +91,7 @@ EntityItemProperties::EntityItemProperties() :
CONSTRUCT_PROPERTY(backgroundMode, BACKGROUND_MODE_INHERIT), CONSTRUCT_PROPERTY(backgroundMode, BACKGROUND_MODE_INHERIT),
CONSTRUCT_PROPERTY(sourceUrl, ""), CONSTRUCT_PROPERTY(sourceUrl, ""),
_id(QUuid()), _id(UNKNOWN_ENTITY_ID),
_idSet(false), _idSet(false),
_lastEdited(0), _lastEdited(0),
_created(UNKNOWN_CREATED_TIME), _created(UNKNOWN_CREATED_TIME),
@ -557,7 +557,7 @@ void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemP
// //
// TODO: Implement support for script and visible properties. // TODO: Implement support for script and visible properties.
// //
bool EntityItemProperties::encodeEntityEditPacket(PacketType command, QUuid id, const EntityItemProperties& properties, bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItemID id, const EntityItemProperties& properties,
unsigned char* bufferOut, int sizeIn, int& sizeOut) { unsigned char* bufferOut, int sizeIn, int& sizeOut) {
OctreePacketData ourDataPacket(false, sizeIn); // create a packetData object to add out packet details too. OctreePacketData ourDataPacket(false, sizeIn); // create a packetData object to add out packet details too.
OctreePacketData* packetData = &ourDataPacket; // we want a pointer to this so we can use our APPEND_ENTITY_PROPERTY macro OctreePacketData* packetData = &ourDataPacket; // we want a pointer to this so we can use our APPEND_ENTITY_PROPERTY macro
@ -586,7 +586,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, QUuid id,
// id // id
// encode our ID as a byte count coded byte stream // encode our ID as a byte count coded byte stream
QByteArray encodedID = id.toRfc4122(); // NUM_BYTES_RFC4122_UUID 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;
@ -818,7 +818,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, QUuid id,
// TODO: Implement support for script and visible properties. // TODO: Implement support for script and visible properties.
// //
bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int bytesToRead, int& processedBytes, bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int bytesToRead, int& processedBytes,
QUuid& entityID, EntityItemProperties& properties) { EntityItemID& entityID, EntityItemProperties& properties) {
bool valid = false; bool valid = false;
const unsigned char* dataAt = data; const unsigned char* dataAt = data;
@ -975,7 +975,7 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int
// NOTE: This version will only encode the portion of the edit message immediately following the // NOTE: This version will only encode the portion of the edit message immediately following the
// header it does not include the send times and sequence number because that is handled by the // header it does not include the send times and sequence number because that is handled by the
// edit packet sender... // edit packet sender...
bool EntityItemProperties::encodeEraseEntityMessage(const QUuid& entityItemID, bool EntityItemProperties::encodeEraseEntityMessage(const EntityItemID& entityItemID,
unsigned char* outputBuffer, size_t maxLength, size_t& outputLength) { unsigned char* outputBuffer, size_t maxLength, size_t& outputLength) {
unsigned char* copyAt = outputBuffer; unsigned char* copyAt = outputBuffer;
@ -990,7 +990,7 @@ bool EntityItemProperties::encodeEraseEntityMessage(const QUuid& entityItemID,
copyAt += sizeof(numberOfIds); copyAt += sizeof(numberOfIds);
outputLength = sizeof(numberOfIds); outputLength = sizeof(numberOfIds);
QUuid entityID = entityItemID; QUuid entityID = entityItemID.id;
QByteArray encodedEntityID = entityID.toRfc4122(); QByteArray encodedEntityID = entityID.toRfc4122();
memcpy(copyAt, encodedEntityID.constData(), NUM_BYTES_RFC4122_UUID); memcpy(copyAt, encodedEntityID.constData(), NUM_BYTES_RFC4122_UUID);

View file

@ -30,6 +30,7 @@
#include <ShapeInfo.h> #include <ShapeInfo.h>
#include "AtmospherePropertyGroup.h" #include "AtmospherePropertyGroup.h"
#include "EntityItemID.h"
#include "EntityItemPropertiesMacros.h" #include "EntityItemPropertiesMacros.h"
#include "EntityTypes.h" #include "EntityTypes.h"
#include "EntityPropertyFlags.h" #include "EntityPropertyFlags.h"
@ -162,20 +163,20 @@ public:
void setGlowLevel(float value) { _glowLevel = value; _glowLevelChanged = true; } void setGlowLevel(float value) { _glowLevel = value; _glowLevelChanged = true; }
void setLocalRenderAlpha(float value) { _localRenderAlpha = value; _localRenderAlphaChanged = true; } void setLocalRenderAlpha(float value) { _localRenderAlpha = value; _localRenderAlphaChanged = true; }
static bool encodeEntityEditPacket(PacketType command, QUuid id, const EntityItemProperties& properties, static bool encodeEntityEditPacket(PacketType command, EntityItemID id, const EntityItemProperties& properties,
unsigned char* bufferOut, int sizeIn, int& sizeOut); unsigned char* bufferOut, int sizeIn, int& sizeOut);
static bool encodeEraseEntityMessage(const QUuid& entityItemID, static bool encodeEraseEntityMessage(const EntityItemID& entityItemID,
unsigned char* outputBuffer, size_t maxLength, size_t& outputLength); unsigned char* outputBuffer, size_t maxLength, size_t& outputLength);
static bool decodeEntityEditPacket(const unsigned char* data, int bytesToRead, int& processedBytes, static bool decodeEntityEditPacket(const unsigned char* data, int bytesToRead, int& processedBytes,
QUuid& entityID, EntityItemProperties& properties); EntityItemID& entityID, EntityItemProperties& properties);
bool glowLevelChanged() const { return _glowLevelChanged; } bool glowLevelChanged() const { return _glowLevelChanged; }
bool localRenderAlphaChanged() const { return _localRenderAlphaChanged; } bool localRenderAlphaChanged() const { return _localRenderAlphaChanged; }
void clearID() { _id = QUuid(); _idSet = false; } void clearID() { _id = UNKNOWN_ENTITY_ID; _idSet = false; }
void markAllChanged(); void markAllChanged();
void setSittingPoints(const QVector<SittingPoint>& sittingPoints); void setSittingPoints(const QVector<SittingPoint>& sittingPoints);

View file

@ -28,7 +28,7 @@ EntityScriptingInterface::EntityScriptingInterface() :
} }
void EntityScriptingInterface::queueEntityMessage(PacketType packetType, void EntityScriptingInterface::queueEntityMessage(PacketType packetType,
QUuid entityID, const EntityItemProperties& properties) { EntityItemID entityID, const EntityItemProperties& properties) {
getEntityPacketSender()->queueEditEntityMessage(packetType, entityID, properties); getEntityPacketSender()->queueEditEntityMessage(packetType, entityID, properties);
} }
@ -46,7 +46,6 @@ void EntityScriptingInterface::setEntityTree(EntityTree* modelTree) {
if (_entityTree) { if (_entityTree) {
disconnect(_entityTree, &EntityTree::addingEntity, this, &EntityScriptingInterface::addingEntity); disconnect(_entityTree, &EntityTree::addingEntity, this, &EntityScriptingInterface::addingEntity);
disconnect(_entityTree, &EntityTree::deletingEntity, this, &EntityScriptingInterface::deletingEntity); disconnect(_entityTree, &EntityTree::deletingEntity, this, &EntityScriptingInterface::deletingEntity);
disconnect(_entityTree, &EntityTree::changingEntityID, this, &EntityScriptingInterface::changingEntityID);
disconnect(_entityTree, &EntityTree::clearingEntities, this, &EntityScriptingInterface::clearingEntities); disconnect(_entityTree, &EntityTree::clearingEntities, this, &EntityScriptingInterface::clearingEntities);
} }
@ -55,7 +54,6 @@ void EntityScriptingInterface::setEntityTree(EntityTree* modelTree) {
if (_entityTree) { if (_entityTree) {
connect(_entityTree, &EntityTree::addingEntity, this, &EntityScriptingInterface::addingEntity); connect(_entityTree, &EntityTree::addingEntity, this, &EntityScriptingInterface::addingEntity);
connect(_entityTree, &EntityTree::deletingEntity, this, &EntityScriptingInterface::deletingEntity); connect(_entityTree, &EntityTree::deletingEntity, this, &EntityScriptingInterface::deletingEntity);
connect(_entityTree, &EntityTree::changingEntityID, this, &EntityScriptingInterface::changingEntityID);
connect(_entityTree, &EntityTree::clearingEntities, this, &EntityScriptingInterface::clearingEntities); connect(_entityTree, &EntityTree::clearingEntities, this, &EntityScriptingInterface::clearingEntities);
} }
} }
@ -70,10 +68,11 @@ void bidForSimulationOwnership(EntityItemProperties& properties) {
QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties) { EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& properties) {
EntityItemProperties propertiesWithSimID = properties; EntityItemProperties propertiesWithSimID = properties;
QUuid id = QUuid::createUuid();
EntityItemID id = EntityItemID(QUuid::createUuid());
// If we have a local entity tree set, then also update it. // If we have a local entity tree set, then also update it.
bool success = true; bool success = true;
@ -99,11 +98,11 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
return id; return id;
} }
EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identity) { EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID identity) {
EntityItemProperties results; EntityItemProperties results;
if (_entityTree) { if (_entityTree) {
_entityTree->lockForRead(); _entityTree->lockForRead();
EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(identity)); EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(EntityItemID(identity)));
if (entity) { if (entity) {
results = entity->getProperties(); results = entity->getProperties();
@ -127,7 +126,8 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit
return results; return results;
} }
QUuid EntityScriptingInterface::editEntity(QUuid entityID, const EntityItemProperties& properties) { EntityItemID EntityScriptingInterface::editEntity(EntityItemID id, const EntityItemProperties& properties) {
EntityItemID entityID(id);
// If we have a local entity tree set, then also update it. // If we have a local entity tree set, then also update it.
if (_entityTree) { if (_entityTree) {
_entityTree->lockForWrite(); _entityTree->lockForWrite();
@ -145,16 +145,16 @@ QUuid EntityScriptingInterface::editEntity(QUuid entityID, const EntityItemPrope
modifiedProperties.setType(entity->getType()); modifiedProperties.setType(entity->getType());
bidForSimulationOwnership(modifiedProperties); bidForSimulationOwnership(modifiedProperties);
queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, modifiedProperties); queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, modifiedProperties);
return entityID; return id;
} }
} }
queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties);
return entityID; return id;
} }
void EntityScriptingInterface::deleteEntity(QUuid entityID) { void EntityScriptingInterface::deleteEntity(EntityItemID id) {
EntityItemID entityID(id);
bool shouldDelete = true; bool shouldDelete = true;
// If we have a local entity tree set, then also update it. // If we have a local entity tree set, then also update it.
@ -179,14 +179,14 @@ void EntityScriptingInterface::deleteEntity(QUuid entityID) {
} }
} }
QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const { EntityItemID EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const {
QUuid result; QUuid result;
if (_entityTree) { if (_entityTree) {
_entityTree->lockForRead(); _entityTree->lockForRead();
const EntityItem* closestEntity = _entityTree->findClosestEntity(center, radius); const EntityItem* closestEntity = _entityTree->findClosestEntity(center, radius);
_entityTree->unlock(); _entityTree->unlock();
if (closestEntity) { if (closestEntity) {
result = closestEntity->getID(); result = closestEntity->getEntityItemID().id;
} }
} }
return result; return result;
@ -201,8 +201,8 @@ void EntityScriptingInterface::dumpTree() const {
} }
} }
QVector<QUuid> EntityScriptingInterface::findEntities(const glm::vec3& center, float radius) const { QVector<EntityItemID> EntityScriptingInterface::findEntities(const glm::vec3& center, float radius) const {
QVector<QUuid> result; QVector<EntityItemID> result;
if (_entityTree) { if (_entityTree) {
_entityTree->lockForRead(); _entityTree->lockForRead();
QVector<const EntityItem*> entities; QVector<const EntityItem*> entities;
@ -210,14 +210,14 @@ QVector<QUuid> EntityScriptingInterface::findEntities(const glm::vec3& center, f
_entityTree->unlock(); _entityTree->unlock();
foreach (const EntityItem* entity, entities) { foreach (const EntityItem* entity, entities) {
result << entity->getID(); result << entity->getEntityItemID();
} }
} }
return result; return result;
} }
QVector<QUuid> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const { QVector<EntityItemID> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const {
QVector<QUuid> result; QVector<EntityItemID> result;
if (_entityTree) { if (_entityTree) {
_entityTree->lockForRead(); _entityTree->lockForRead();
AABox box(corner, dimensions); AABox box(corner, dimensions);
@ -226,7 +226,7 @@ QVector<QUuid> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corn
_entityTree->unlock(); _entityTree->unlock();
foreach (const EntityItem* entity, entities) { foreach (const EntityItem* entity, entities) {
result << entity->getID(); result << entity->getEntityItemID();
} }
} }
return result; return result;
@ -253,7 +253,7 @@ RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorke
(void**)&intersectedEntity, lockType, &result.accurate, (void**)&intersectedEntity, lockType, &result.accurate,
precisionPicking); precisionPicking);
if (result.intersects && intersectedEntity) { if (result.intersects && intersectedEntity) {
result.entityID = intersectedEntity->getID(); result.entityID = intersectedEntity->getEntityItemID().id;
result.properties = intersectedEntity->getProperties(); result.properties = intersectedEntity->getProperties();
result.intersection = ray.origin + (ray.direction * result.distance); result.intersection = ray.origin + (ray.direction * result.distance);
} }
@ -309,7 +309,7 @@ QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, c
QScriptValue obj = engine->newObject(); QScriptValue obj = engine->newObject();
obj.setProperty("intersects", value.intersects); obj.setProperty("intersects", value.intersects);
obj.setProperty("accurate", value.accurate); obj.setProperty("accurate", value.accurate);
QScriptValue entityItemValue = quuidToScriptValue(engine, value.entityID); QScriptValue entityItemValue = EntityItemIDtoScriptValue(engine, value.entityID);
obj.setProperty("entityID", entityItemValue); obj.setProperty("entityID", entityItemValue);
QScriptValue propertiesValue = EntityItemPropertiesToScriptValue(engine, value.properties); QScriptValue propertiesValue = EntityItemPropertiesToScriptValue(engine, value.properties);
@ -353,7 +353,7 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra
value.intersects = object.property("intersects").toVariant().toBool(); value.intersects = object.property("intersects").toVariant().toBool();
value.accurate = object.property("accurate").toVariant().toBool(); value.accurate = object.property("accurate").toVariant().toBool();
QScriptValue entityIDValue = object.property("entityID"); QScriptValue entityIDValue = object.property("entityID");
quuidFromScriptValue(entityIDValue, value.entityID); EntityItemIDfromScriptValue(entityIDValue, value.entityID);
QScriptValue entityPropertiesValue = object.property("properties"); QScriptValue entityPropertiesValue = object.property("properties");
if (entityPropertiesValue.isValid()) { if (entityPropertiesValue.isValid()) {
EntityItemPropertiesFromScriptValue(entityPropertiesValue, value.properties); EntityItemPropertiesFromScriptValue(entityPropertiesValue, value.properties);

View file

@ -34,7 +34,7 @@ public:
RayToEntityIntersectionResult(); RayToEntityIntersectionResult();
bool intersects; bool intersects;
bool accurate; bool accurate;
QUuid entityID; EntityItemID entityID;
EntityItemProperties properties; EntityItemProperties properties;
float distance; float distance;
BoxFace face; BoxFace face;
@ -70,31 +70,31 @@ public slots:
Q_INVOKABLE bool canRez(); Q_INVOKABLE bool canRez();
/// adds a model with the specific properties /// adds a model with the specific properties
Q_INVOKABLE QUuid addEntity(const EntityItemProperties& properties); Q_INVOKABLE EntityItemID addEntity(const EntityItemProperties& properties);
/// gets the current model properties for a specific model /// gets the current model properties for a specific model
/// this function will not find return results in script engine contexts which don't have access to models /// this function will not find return results in script engine contexts which don't have access to models
Q_INVOKABLE EntityItemProperties getEntityProperties(QUuid entityID); Q_INVOKABLE EntityItemProperties getEntityProperties(EntityItemID entityID);
/// edits a model updating only the included properties, will return the identified QUuid in case of /// edits a model updating only the included properties, will return the identified EntityItemID in case of
/// successful edit, if the input entityID is for an unknown model this function will have no effect /// successful edit, if the input entityID is for an unknown model this function will have no effect
Q_INVOKABLE QUuid editEntity(QUuid entityID, const EntityItemProperties& properties); Q_INVOKABLE EntityItemID editEntity(EntityItemID entityID, const EntityItemProperties& properties);
/// deletes a model /// deletes a model
Q_INVOKABLE void deleteEntity(QUuid entityID); Q_INVOKABLE void deleteEntity(EntityItemID entityID);
/// finds the closest model to the center point, within the radius /// finds the closest model to the center point, within the radius
/// will return a QUuid.isKnownID = false if no models are in the radius /// will return a EntityItemID.isKnownID = false if no models are in the radius
/// this function will not find any models in script engine contexts which don't have access to models /// this function will not find any models in script engine contexts which don't have access to models
Q_INVOKABLE QUuid findClosestEntity(const glm::vec3& center, float radius) const; Q_INVOKABLE EntityItemID findClosestEntity(const glm::vec3& center, float radius) const;
/// finds models within the search sphere specified by the center point and radius /// finds models within the search sphere specified by the center point and radius
/// this function will not find any models in script engine contexts which don't have access to models /// this function will not find any models in script engine contexts which don't have access to models
Q_INVOKABLE QVector<QUuid> findEntities(const glm::vec3& center, float radius) const; Q_INVOKABLE QVector<EntityItemID> findEntities(const glm::vec3& center, float radius) const;
/// finds models within the search sphere specified by the center point and radius /// finds models within the search sphere specified by the center point and radius
/// this function will not find any models in script engine contexts which don't have access to models /// this function will not find any models in script engine contexts which don't have access to models
Q_INVOKABLE QVector<QUuid> findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const; Q_INVOKABLE QVector<EntityItemID> findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const;
/// If the scripting context has visible entities, this will determine a ray intersection, the results /// If the scripting context has visible entities, this will determine a ray intersection, the results
/// may be inaccurate if the engine is unable to access the visible entities, in which case result.accurate /// may be inaccurate if the engine is unable to access the visible entities, in which case result.accurate
@ -120,33 +120,33 @@ public slots:
Q_INVOKABLE void dumpTree() const; Q_INVOKABLE void dumpTree() const;
signals: signals:
void entityCollisionWithEntity(const QUuid& idA, const QUuid& idB, const Collision& collision); void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
void canAdjustLocksChanged(bool canAdjustLocks); void canAdjustLocksChanged(bool canAdjustLocks);
void canRezChanged(bool canRez); void canRezChanged(bool canRez);
void mousePressOnEntity(const QUuid& entityItemID, const MouseEvent& event); void mousePressOnEntity(const EntityItemID& entityItemID, const MouseEvent& event);
void mouseMoveOnEntity(const QUuid& entityItemID, const MouseEvent& event); void mouseMoveOnEntity(const EntityItemID& entityItemID, const MouseEvent& event);
void mouseReleaseOnEntity(const QUuid& entityItemID, const MouseEvent& event); void mouseReleaseOnEntity(const EntityItemID& entityItemID, const MouseEvent& event);
void clickDownOnEntity(const QUuid& entityItemID, const MouseEvent& event); void clickDownOnEntity(const EntityItemID& entityItemID, const MouseEvent& event);
void holdingClickOnEntity(const QUuid& entityItemID, const MouseEvent& event); void holdingClickOnEntity(const EntityItemID& entityItemID, const MouseEvent& event);
void clickReleaseOnEntity(const QUuid& entityItemID, const MouseEvent& event); void clickReleaseOnEntity(const EntityItemID& entityItemID, const MouseEvent& event);
void hoverEnterEntity(const QUuid& entityItemID, const MouseEvent& event); void hoverEnterEntity(const EntityItemID& entityItemID, const MouseEvent& event);
void hoverOverEntity(const QUuid& entityItemID, const MouseEvent& event); void hoverOverEntity(const EntityItemID& entityItemID, const MouseEvent& event);
void hoverLeaveEntity(const QUuid& entityItemID, const MouseEvent& event); void hoverLeaveEntity(const EntityItemID& entityItemID, const MouseEvent& event);
void enterEntity(const QUuid& entityItemID); void enterEntity(const EntityItemID& entityItemID);
void leaveEntity(const QUuid& entityItemID); void leaveEntity(const EntityItemID& entityItemID);
void deletingEntity(const QUuid& entityID); void deletingEntity(const EntityItemID& entityID);
void addingEntity(const QUuid& entityID); void addingEntity(const EntityItemID& entityID);
void changingEntityID(const QUuid& oldEntityID, const QUuid& newEntityID); void changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID);
void clearingEntities(); void clearingEntities();
private: private:
void queueEntityMessage(PacketType packetType, QUuid entityID, const EntityItemProperties& properties); void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties);
/// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode /// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType,

View file

@ -121,7 +121,7 @@ void EntitySimulation::sortEntitiesThatMoved() {
// check to see if this movement has sent the entity outside of the domain. // check to see if this movement has sent the entity outside of the domain.
AACube newCube = entity->getMaximumAACube(); AACube newCube = entity->getMaximumAACube();
if (!domainBounds.touches(newCube)) { if (!domainBounds.touches(newCube)) {
qCDebug(entities) << "Entity " << entity->getID() << " moved out of domain bounds."; qCDebug(entities) << "Entity " << entity->getEntityItemID() << " moved out of domain bounds.";
_entitiesToDelete.insert(entity); _entitiesToDelete.insert(entity);
_mortalEntities.remove(entity); _mortalEntities.remove(entity);
_entitiesToUpdate.remove(entity); _entitiesToUpdate.remove(entity);
@ -198,7 +198,7 @@ void EntitySimulation::changeEntity(EntityItem* entity) {
AACube domainBounds(glm::vec3(0.0f,0.0f,0.0f), (float)TREE_SCALE); AACube domainBounds(glm::vec3(0.0f,0.0f,0.0f), (float)TREE_SCALE);
AACube newCube = entity->getMaximumAACube(); AACube newCube = entity->getMaximumAACube();
if (!domainBounds.touches(newCube)) { if (!domainBounds.touches(newCube)) {
qCDebug(entities) << "Entity " << entity->getID() << " moved out of domain bounds."; qCDebug(entities) << "Entity " << entity->getEntityItemID() << " moved out of domain bounds.";
_entitiesToDelete.insert(entity); _entitiesToDelete.insert(entity);
_mortalEntities.remove(entity); _mortalEntities.remove(entity);
_entitiesToUpdate.remove(entity); _entitiesToUpdate.remove(entity);

View file

@ -81,7 +81,7 @@ public:
void getEntitiesToDelete(VectorOfEntities& entitiesToDelete); void getEntitiesToDelete(VectorOfEntities& entitiesToDelete);
signals: signals:
void entityCollisionWithEntity(const QUuid& idA, const QUuid& idB, const Collision& collision); void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
protected: protected:

View file

@ -83,11 +83,10 @@ void EntityTree::postAddEntity(EntityItem* entity) {
_simulation->unlock(); _simulation->unlock();
} }
_isDirty = true; _isDirty = true;
emit addingEntity(entity->getID()); emit addingEntity(entity->getEntityItemID());
} }
bool EntityTree::updateEntity(const QUuid& entityID, const EntityItemProperties& properties, bool EntityTree::updateEntity(const EntityItemID& entityID, const EntityItemProperties& properties, const SharedNodePointer& senderNode) {
const SharedNodePointer& senderNode) {
EntityTreeElement* containingElement = getContainingElement(entityID); EntityTreeElement* containingElement = getContainingElement(entityID);
if (!containingElement) { if (!containingElement) {
qCDebug(entities) << "UNEXPECTED!!!! EntityTree::updateEntity() entityID doesn't exist!!! entityID=" << entityID; qCDebug(entities) << "UNEXPECTED!!!! EntityTree::updateEntity() entityID doesn't exist!!! entityID=" << entityID;
@ -104,10 +103,10 @@ bool EntityTree::updateEntity(const QUuid& entityID, const EntityItemProperties&
} }
bool EntityTree::updateEntity(EntityItem* entity, const EntityItemProperties& properties, const SharedNodePointer& senderNode) { bool EntityTree::updateEntity(EntityItem* entity, const EntityItemProperties& properties, const SharedNodePointer& senderNode) {
EntityTreeElement* containingElement = getContainingElement(entity->getID()); EntityTreeElement* containingElement = getContainingElement(entity->getEntityItemID());
if (!containingElement) { if (!containingElement) {
qCDebug(entities) << "UNEXPECTED!!!! EntityTree::updateEntity() entity-->element lookup failed!!! entityID=" qCDebug(entities) << "UNEXPECTED!!!! EntityTree::updateEntity() entity-->element lookup failed!!! entityID="
<< entity->getID(); << entity->getEntityItemID();
return false; return false;
} }
return updateEntityWithElement(entity, properties, containingElement, senderNode); return updateEntityWithElement(entity, properties, containingElement, senderNode);
@ -205,22 +204,22 @@ bool EntityTree::updateEntityWithElement(EntityItem* entity, const EntityItemPro
QString entityScriptAfter = entity->getScript(); QString entityScriptAfter = entity->getScript();
if (entityScriptBefore != entityScriptAfter) { if (entityScriptBefore != entityScriptAfter) {
emitEntityScriptChanging(entity->getID()); // the entity script has changed emitEntityScriptChanging(entity->getEntityItemID()); // the entity script has changed
} }
} }
// TODO: this final containingElement check should eventually be removed (or wrapped in an #ifdef DEBUG). // TODO: this final containingElement check should eventually be removed (or wrapped in an #ifdef DEBUG).
containingElement = getContainingElement(entity->getID()); containingElement = getContainingElement(entity->getEntityItemID());
if (!containingElement) { if (!containingElement) {
qCDebug(entities) << "UNEXPECTED!!!! after updateEntity() we no longer have a containing element??? entityID=" qCDebug(entities) << "UNEXPECTED!!!! after updateEntity() we no longer have a containing element??? entityID="
<< entity->getID(); << entity->getEntityItemID();
return false; return false;
} }
return true; return true;
} }
EntityItem* EntityTree::addEntity(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* EntityTree::addEntity(const EntityItemID& entityID, const EntityItemProperties& properties) {
EntityItem* result = NULL; EntityItem* result = NULL;
if (getIsClient()) { if (getIsClient()) {
@ -263,7 +262,7 @@ EntityItem* EntityTree::addEntity(const QUuid& entityID, const EntityItemPropert
return result; return result;
} }
void EntityTree::emitEntityScriptChanging(const QUuid& entityItemID) { void EntityTree::emitEntityScriptChanging(const EntityItemID& entityItemID) {
emit entityScriptChanging(entityItemID); emit entityScriptChanging(entityItemID);
} }
@ -282,7 +281,7 @@ void EntityTree::setSimulation(EntitySimulation* simulation) {
_simulation = simulation; _simulation = simulation;
} }
void EntityTree::deleteEntity(const QUuid& entityID, bool force, bool ignoreWarnings) { void EntityTree::deleteEntity(const EntityItemID& entityID, bool force, bool ignoreWarnings) {
EntityTreeElement* containingElement = getContainingElement(entityID); EntityTreeElement* containingElement = getContainingElement(entityID);
if (!containingElement) { if (!containingElement) {
if (!ignoreWarnings) { if (!ignoreWarnings) {
@ -316,10 +315,10 @@ void EntityTree::deleteEntity(const QUuid& entityID, bool force, bool ignoreWarn
_isDirty = true; _isDirty = true;
} }
void EntityTree::deleteEntities(QSet<QUuid> entityIDs, bool force, bool ignoreWarnings) { void EntityTree::deleteEntities(QSet<EntityItemID> entityIDs, bool force, bool ignoreWarnings) {
// NOTE: callers must lock the tree before using this method // NOTE: callers must lock the tree before using this method
DeleteEntityOperator theOperator(this); DeleteEntityOperator theOperator(this);
foreach(const QUuid& entityID, entityIDs) { foreach(const EntityItemID& entityID, entityIDs) {
EntityTreeElement* containingElement = getContainingElement(entityID); EntityTreeElement* containingElement = getContainingElement(entityID);
if (!containingElement) { if (!containingElement) {
if (!ignoreWarnings) { if (!ignoreWarnings) {
@ -368,7 +367,7 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator)
// set up the deleted entities ID // set up the deleted entities ID
quint64 deletedAt = usecTimestampNow(); quint64 deletedAt = usecTimestampNow();
_recentlyDeletedEntitiesLock.lockForWrite(); _recentlyDeletedEntitiesLock.lockForWrite();
_recentlyDeletedEntityItemIDs.insert(deletedAt, theEntity->getID()); _recentlyDeletedEntityItemIDs.insert(deletedAt, theEntity->getEntityItemID().id);
_recentlyDeletedEntitiesLock.unlock(); _recentlyDeletedEntitiesLock.unlock();
} }
@ -383,6 +382,7 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator)
} }
void EntityTree::handleAddEntityResponse(const QByteArray& packet) { void EntityTree::handleAddEntityResponse(const QByteArray& packet) {
if (!getIsClient()) { if (!getIsClient()) {
qCDebug(entities) << "UNEXPECTED!!! EntityTree::handleAddEntityResponse() with !getIsClient() ***"; qCDebug(entities) << "UNEXPECTED!!! EntityTree::handleAddEntityResponse() with !getIsClient() ***";
return; return;
@ -537,10 +537,11 @@ void EntityTree::findEntities(const AABox& box, QVector<EntityItem*>& foundEntit
} }
EntityItem* EntityTree::findEntityByID(const QUuid& id) { EntityItem* EntityTree::findEntityByID(const QUuid& id) {
return findEntityByEntityItemID(id); EntityItemID entityID(id);
return findEntityByEntityItemID(entityID);
} }
EntityItem* EntityTree::findEntityByEntityItemID(const QUuid& entityID) /*const*/ { EntityItem* EntityTree::findEntityByEntityItemID(const EntityItemID& entityID) /*const*/ {
EntityItem* foundEntity = NULL; EntityItem* foundEntity = NULL;
EntityTreeElement* containingElement = getContainingElement(entityID); EntityTreeElement* containingElement = getContainingElement(entityID);
if (containingElement) { if (containingElement) {
@ -567,32 +568,29 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char
} }
case PacketTypeEntityAddOrEdit: { case PacketTypeEntityAddOrEdit: {
QUuid entityItemID; EntityItemID entityItemID;
EntityItemProperties properties; EntityItemProperties properties;
bool validEditPacket = EntityItemProperties::decodeEntityEditPacket(editData, maxLength, bool validEditPacket = EntityItemProperties::decodeEntityEditPacket(editData, maxLength,
processedBytes, entityItemID, properties); processedBytes, entityItemID, properties);
// If we got a valid edit packet, then it could be a new entity or it could be an update to // If we got a valid edit packet, then it could be a new entity or it could be an update to
// an existing entity... handle appropriately // an existing entity... handle appropriately
if (validEditPacket) { if (validEditPacket) {
// search for the entity by EntityItemID // search for the entity by EntityItemID
EntityItem* existingEntity = findEntityByEntityItemID(entityItemID); EntityItem* existingEntity = findEntityByEntityItemID(entityItemID);
// If this is a knownID, then it should exist in our tree // If this is a knownID, then it should exist in our tree
if (existingEntity) { if (existingEntity) {
// if the EntityItem exists, then update it // if the EntityItem exists, then update it
if (existingEntity) { if (wantEditLogging()) {
if (wantEditLogging()) { qCDebug(entities) << "User [" << senderNode->getUUID() << "] editing entity. ID:" << entityItemID;
qCDebug(entities) << "User [" << senderNode->getUUID() << "] editing entity. ID:" << entityItemID; qCDebug(entities) << " properties:" << properties;
qCDebug(entities) << " properties:" << properties;
}
updateEntity(entityItemID, properties, senderNode);
existingEntity->markAsChangedOnServer();
} else {
qCDebug(entities) << "User attempted to edit an unknown entity. ID:" << entityItemID;
} }
updateEntity(entityItemID, properties, senderNode);
existingEntity->markAsChangedOnServer();
} else { } else {
if (senderNode->getCanRez()) { if (senderNode->getCanRez()) {
// this is a new entity... assign a new entityID
if (wantEditLogging()) { if (wantEditLogging()) {
qCDebug(entities) << "User [" << senderNode->getUUID() << "] adding entity."; qCDebug(entities) << "User [" << senderNode->getUUID() << "] adding entity.";
qCDebug(entities) << " properties:" << properties; qCDebug(entities) << " properties:" << properties;
@ -603,13 +601,13 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char
notifyNewlyCreatedEntity(*newEntity, senderNode); notifyNewlyCreatedEntity(*newEntity, senderNode);
if (wantEditLogging()) { if (wantEditLogging()) {
qCDebug(entities) << "User [" << senderNode->getUUID() << "] added entity. ID:" qCDebug(entities) << "User [" << senderNode->getUUID() << "] added entity. ID:"
<< newEntity->getID(); << newEntity->getEntityItemID();
qCDebug(entities) << " properties:" << properties; qCDebug(entities) << " properties:" << properties;
} }
} }
} else { } else {
qCDebug(entities) << "User without 'rez rights' [" qCDebug(entities) << "User without 'rez rights' [" << senderNode->getUUID() << "] attempted to add an entity.";
<< senderNode->getUUID() << "] attempted to add an entity.";
} }
} }
} }
@ -677,11 +675,11 @@ void EntityTree::update() {
if (pendingDeletes.size() > 0) { if (pendingDeletes.size() > 0) {
// translate into list of ID's // translate into list of ID's
QSet<QUuid> idsToDelete; QSet<EntityItemID> idsToDelete;
for (auto entityItr : pendingDeletes) { for (auto entityItr : pendingDeletes) {
EntityItem* entity = &(*entityItr); EntityItem* entity = &(*entityItr);
assert(!entity->getPhysicsInfo()); // TODO: Andrew to remove this after testing assert(!entity->getPhysicsInfo()); // TODO: Andrew to remove this after testing
idsToDelete.insert(entity->getID()); idsToDelete.insert(entity->getEntityItemID());
} }
// delete these things the roundabout way // delete these things the roundabout way
deleteEntities(idsToDelete, true); deleteEntities(idsToDelete, true);
@ -841,7 +839,7 @@ int EntityTree::processEraseMessage(const QByteArray& dataByteArray, const Share
processedBytes += sizeof(numberOfIds); processedBytes += sizeof(numberOfIds);
if (numberOfIds > 0) { if (numberOfIds > 0) {
QSet<QUuid> entityItemIDsToDelete; QSet<EntityItemID> entityItemIDsToDelete;
for (size_t i = 0; i < numberOfIds; i++) { for (size_t i = 0; i < numberOfIds; i++) {
@ -855,10 +853,11 @@ int EntityTree::processEraseMessage(const QByteArray& dataByteArray, const Share
dataAt += encodedID.size(); dataAt += encodedID.size();
processedBytes += encodedID.size(); processedBytes += encodedID.size();
entityItemIDsToDelete << entityID; EntityItemID entityItemID(entityID);
entityItemIDsToDelete << entityItemID;
if (wantEditLogging()) { if (wantEditLogging()) {
qCDebug(entities) << "User [" << sourceNode->getUUID() << "] deleting entity. ID:" << entityID; qCDebug(entities) << "User [" << sourceNode->getUUID() << "] deleting entity. ID:" << entityItemID;
} }
} }
@ -883,7 +882,7 @@ int EntityTree::processEraseMessageDetails(const QByteArray& dataByteArray, cons
processedBytes += sizeof(numberOfIds); processedBytes += sizeof(numberOfIds);
if (numberOfIds > 0) { if (numberOfIds > 0) {
QSet<QUuid> entityItemIDsToDelete; QSet<EntityItemID> entityItemIDsToDelete;
for (size_t i = 0; i < numberOfIds; i++) { for (size_t i = 0; i < numberOfIds; i++) {
@ -898,10 +897,11 @@ int EntityTree::processEraseMessageDetails(const QByteArray& dataByteArray, cons
dataAt += encodedID.size(); dataAt += encodedID.size();
processedBytes += encodedID.size(); processedBytes += encodedID.size();
entityItemIDsToDelete << entityID; EntityItemID entityItemID(entityID);
entityItemIDsToDelete << entityItemID;
if (wantEditLogging()) { if (wantEditLogging()) {
qCDebug(entities) << "User [" << sourceNode->getUUID() << "] deleting entity. ID:" << entityID; qCDebug(entities) << "User [" << sourceNode->getUUID() << "] deleting entity. ID:" << entityItemID;
} }
} }
@ -910,14 +910,13 @@ int EntityTree::processEraseMessageDetails(const QByteArray& dataByteArray, cons
return processedBytes; return processedBytes;
} }
EntityTreeElement* EntityTree::getContainingElement(const QUuid& entityItemID) /*const*/ { EntityTreeElement* EntityTree::getContainingElement(const EntityItemID& entityItemID) /*const*/ {
// TODO: do we need to make this thread safe? Or is it acceptable as is // TODO: do we need to make this thread safe? Or is it acceptable as is
EntityTreeElement* element = _entityToElementMap.value(entityItemID); EntityTreeElement* element = _entityToElementMap.value(entityItemID);
return element; return element;
} }
void EntityTree::setContainingElement(const EntityItemID& entityItemID, EntityTreeElement* element) {
void EntityTree::setContainingElement(const QUuid& entityItemID, EntityTreeElement* element) {
// TODO: do we need to make this thread safe? Or is it acceptable as is // TODO: do we need to make this thread safe? Or is it acceptable as is
if (element) { if (element) {
_entityToElementMap[entityItemID] = element; _entityToElementMap[entityItemID] = element;
@ -926,11 +925,9 @@ void EntityTree::setContainingElement(const QUuid& entityItemID, EntityTreeEleme
} }
} }
void EntityTree::debugDumpMap() { void EntityTree::debugDumpMap() {
qCDebug(entities) << "EntityTree::debugDumpMap() --------------------------"; qCDebug(entities) << "EntityTree::debugDumpMap() --------------------------";
QHashIterator<QUuid, EntityTreeElement*> i(_entityToElementMap); QHashIterator<EntityItemID, EntityTreeElement*> i(_entityToElementMap);
while (i.hasNext()) { while (i.hasNext()) {
i.next(); i.next();
qCDebug(entities) << i.key() << ": " << i.value(); qCDebug(entities) << i.key() << ": " << i.value();
@ -994,13 +991,12 @@ void EntityTree::pruneTree() {
recurseTreeWithOperator(&theOperator); recurseTreeWithOperator(&theOperator);
} }
QVector<QUuid> EntityTree::sendEntities(EntityEditPacketSender* packetSender, QVector<EntityItemID> EntityTree::sendEntities(EntityEditPacketSender* packetSender, EntityTree* localTree, float x, float y, float z) {
EntityTree* localTree, float x, float y, float z) {
SendEntitiesOperationArgs args; SendEntitiesOperationArgs args;
args.packetSender = packetSender; args.packetSender = packetSender;
args.localTree = localTree; args.localTree = localTree;
args.root = glm::vec3(x, y, z); args.root = glm::vec3(x, y, z);
QVector<QUuid> newEntityIDs; QVector<EntityItemID> newEntityIDs;
args.newEntityIDs = &newEntityIDs; args.newEntityIDs = &newEntityIDs;
recurseTreeWithOperation(sendEntitiesOperation, &args); recurseTreeWithOperation(sendEntitiesOperation, &args);
packetSender->releaseQueuedMessages(); packetSender->releaseQueuedMessages();
@ -1014,7 +1010,7 @@ bool EntityTree::sendEntitiesOperation(OctreeElement* element, void* extraData)
const QList<EntityItem*>& entities = entityTreeElement->getEntities(); const QList<EntityItem*>& entities = entityTreeElement->getEntities();
for (int i = 0; i < entities.size(); i++) { for (int i = 0; i < entities.size(); i++) {
QUuid newID = QUuid::createUuid(); EntityItemID newID(QUuid::createUuid());
args->newEntityIDs->append(newID); args->newEntityIDs->append(newID);
EntityItemProperties properties = entities[i]->getProperties(); EntityItemProperties properties = entities[i]->getProperties();
properties.setPosition(properties.getPosition() + args->root); properties.setPosition(properties.getPosition() + args->root);
@ -1057,11 +1053,11 @@ bool EntityTree::readFromMap(QVariantMap& map) {
EntityItemProperties properties; EntityItemProperties properties;
EntityItemPropertiesFromScriptValue(entityScriptValue, properties); EntityItemPropertiesFromScriptValue(entityScriptValue, properties);
QUuid entityItemID; EntityItemID entityItemID;
if (entityMap.contains("id")) { if (entityMap.contains("id")) {
entityItemID = QUuid(entityMap["id"].toString()); entityItemID = EntityItemID(QUuid(entityMap["id"].toString()));
} else { } else {
entityItemID = QUuid::createUuid(); entityItemID = EntityItemID(QUuid::createUuid());
} }
EntityItem* entity = addEntity(entityItemID, properties); EntityItem* entity = addEntity(entityItemID, properties);

View file

@ -41,7 +41,7 @@ public:
glm::vec3 root; glm::vec3 root;
EntityTree* localTree; EntityTree* localTree;
EntityEditPacketSender* packetSender; EntityEditPacketSender* packetSender;
QVector<QUuid>* newEntityIDs; QVector<EntityItemID>* newEntityIDs;
}; };
@ -85,25 +85,24 @@ public:
// The newer API... // The newer API...
void postAddEntity(EntityItem* entityItem); void postAddEntity(EntityItem* entityItem);
EntityItem* addEntity(const QUuid& entityID, const EntityItemProperties& properties); EntityItem* addEntity(const EntityItemID& entityID, const EntityItemProperties& properties);
// use this method if you only know the entityID // use this method if you only know the entityID
bool updateEntity(const QUuid& entityID, const EntityItemProperties& properties, bool updateEntity(const EntityItemID& entityID, const EntityItemProperties& properties, const SharedNodePointer& senderNode = SharedNodePointer(nullptr));
const SharedNodePointer& senderNode = SharedNodePointer(nullptr));
// use this method if you have a pointer to the entity (avoid an extra entity lookup) // use this method if you have a pointer to the entity (avoid an extra entity lookup)
bool updateEntity(EntityItem* entity, const EntityItemProperties& properties, const SharedNodePointer& senderNode = SharedNodePointer(nullptr)); bool updateEntity(EntityItem* entity, const EntityItemProperties& properties, const SharedNodePointer& senderNode = SharedNodePointer(nullptr));
void deleteEntity(const QUuid& entityID, bool force = false, bool ignoreWarnings = false); void deleteEntity(const EntityItemID& entityID, bool force = false, bool ignoreWarnings = false);
void deleteEntities(QSet<QUuid> entityIDs, bool force = false, bool ignoreWarnings = false); void deleteEntities(QSet<EntityItemID> entityIDs, bool force = false, bool ignoreWarnings = false);
/// \param position point of query in world-frame (meters) /// \param position point of query in world-frame (meters)
/// \param targetRadius radius of query (meters) /// \param targetRadius radius of query (meters)
const EntityItem* findClosestEntity(glm::vec3 position, float targetRadius); const EntityItem* findClosestEntity(glm::vec3 position, float targetRadius);
EntityItem* findEntityByID(const QUuid& id); EntityItem* findEntityByID(const QUuid& id);
EntityItem* findEntityByEntityItemID(const QUuid& entityID); EntityItem* findEntityByEntityItemID(const EntityItemID& entityID);
QUuid assignEntityID(const QUuid& entityItemID); /// Assigns a known ID for a creator token ID EntityItemID assignEntityID(const EntityItemID& entityItemID); /// Assigns a known ID for a creator token ID
/// finds all entities that touch a sphere /// finds all entities that touch a sphere
@ -147,17 +146,17 @@ public:
return _fbxService ? _fbxService->getModelForEntityItem(entityItem) : NULL; return _fbxService ? _fbxService->getModelForEntityItem(entityItem) : NULL;
} }
EntityTreeElement* getContainingElement(const QUuid& entityItemID) /*const*/; EntityTreeElement* getContainingElement(const EntityItemID& entityItemID) /*const*/;
void setContainingElement(const QUuid& entityItemID, EntityTreeElement* element); void setContainingElement(const EntityItemID& entityItemID, EntityTreeElement* element);
void debugDumpMap(); void debugDumpMap();
virtual void dumpTree(); virtual void dumpTree();
virtual void pruneTree(); virtual void pruneTree();
QVector<QUuid> sendEntities(EntityEditPacketSender* packetSender, EntityTree* localTree, float x, float y, float z); QVector<EntityItemID> sendEntities(EntityEditPacketSender* packetSender, EntityTree* localTree, float x, float y, float z);
void entityChanged(EntityItem* entity); void entityChanged(EntityItem* entity);
void emitEntityScriptChanging(const QUuid& entityItemID); void emitEntityScriptChanging(const EntityItemID& entityItemID);
void setSimulation(EntitySimulation* simulation); void setSimulation(EntitySimulation* simulation);
@ -170,10 +169,10 @@ public:
float getContentsLargestDimension(); float getContentsLargestDimension();
signals: signals:
void deletingEntity(const QUuid& entityID); void deletingEntity(const EntityItemID& entityID);
void addingEntity(const QUuid& entityID); void addingEntity(const EntityItemID& entityID);
void entityScriptChanging(const QUuid& entityItemID); void entityScriptChanging(const EntityItemID& entityItemID);
void changingEntityID(const QUuid& oldEntityID, const QUuid& newEntityID); void changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID);
void clearingEntities(); void clearingEntities();
private: private:
@ -197,7 +196,7 @@ private:
QMultiMap<quint64, QUuid> _recentlyDeletedEntityItemIDs; QMultiMap<quint64, QUuid> _recentlyDeletedEntityItemIDs;
EntityItemFBXService* _fbxService; EntityItemFBXService* _fbxService;
QHash<QUuid, EntityTreeElement*> _entityToElementMap; QHash<EntityItemID, EntityTreeElement*> _entityToElementMap;
EntitySimulation* _simulation; EntitySimulation* _simulation;

View file

@ -86,7 +86,7 @@ void EntityTreeElement::initializeExtraEncodeData(EncodeBitstreamParams& params)
} }
for (uint16_t i = 0; i < _entityItems->size(); i++) { for (uint16_t i = 0; i < _entityItems->size(); i++) {
EntityItem* entity = (*_entityItems)[i]; EntityItem* entity = (*_entityItems)[i];
entityTreeElementExtraEncodeData->entities.insert(entity->getID(), entity->getEntityProperties(params)); entityTreeElementExtraEncodeData->entities.insert(entity->getEntityItemID(), entity->getEntityProperties(params));
} }
// TODO: some of these inserts might be redundant!!! // TODO: some of these inserts might be redundant!!!
@ -258,14 +258,13 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData
if (child->hasEntities()) { if (child->hasEntities()) {
entityTreeElementExtraEncodeData->childCompleted[i] = false; entityTreeElementExtraEncodeData->childCompleted[i] = false;
} else { } else {
// if the child doesn't have enities, it is completed entityTreeElementExtraEncodeData->childCompleted[i] = true; // if the child doesn't have enities, it is completed
entityTreeElementExtraEncodeData->childCompleted[i] = true;
} }
} }
} }
for (uint16_t i = 0; i < _entityItems->size(); i++) { for (uint16_t i = 0; i < _entityItems->size(); i++) {
EntityItem* entity = (*_entityItems)[i]; EntityItem* entity = (*_entityItems)[i];
entityTreeElementExtraEncodeData->entities.insert(entity->getID(), entity->getEntityProperties(params)); entityTreeElementExtraEncodeData->entities.insert(entity->getEntityItemID(), entity->getEntityProperties(params));
} }
} }
@ -294,7 +293,7 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData
if (hadElementExtraData) { if (hadElementExtraData) {
includeThisEntity = includeThisEntity && includeThisEntity = includeThisEntity &&
entityTreeElementExtraEncodeData->entities.contains(entity->getID()); entityTreeElementExtraEncodeData->entities.contains(entity->getEntityItemID());
} }
if (includeThisEntity && params.viewFrustum) { if (includeThisEntity && params.viewFrustum) {
@ -339,7 +338,7 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData
// If the entity item got completely appended, then we can remove it from the extra encode data // If the entity item got completely appended, then we can remove it from the extra encode data
if (appendEntityState == OctreeElement::COMPLETED) { if (appendEntityState == OctreeElement::COMPLETED) {
entityTreeElementExtraEncodeData->entities.remove(entity->getID()); entityTreeElementExtraEncodeData->entities.remove(entity->getEntityItemID());
} }
// If any part of the entity items didn't fit, then the element is considered partial // If any part of the entity items didn't fit, then the element is considered partial
@ -612,11 +611,11 @@ void EntityTreeElement::getEntities(const AACube& box, QVector<EntityItem*>& fou
} }
} }
const EntityItem* EntityTreeElement::getEntityWithEntityItemID(const QUuid& id) const { const EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemID& id) const {
const EntityItem* foundEntity = NULL; const EntityItem* foundEntity = NULL;
uint16_t numberOfEntities = _entityItems->size(); uint16_t numberOfEntities = _entityItems->size();
for (uint16_t i = 0; i < numberOfEntities; i++) { for (uint16_t i = 0; i < numberOfEntities; i++) {
if ((*_entityItems)[i]->getID() == id) { if ((*_entityItems)[i]->getEntityItemID() == id) {
foundEntity = (*_entityItems)[i]; foundEntity = (*_entityItems)[i];
break; break;
} }
@ -624,11 +623,11 @@ const EntityItem* EntityTreeElement::getEntityWithEntityItemID(const QUuid& id)
return foundEntity; return foundEntity;
} }
EntityItem* EntityTreeElement::getEntityWithEntityItemID(const QUuid& id) { EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemID& id) {
EntityItem* foundEntity = NULL; EntityItem* foundEntity = NULL;
uint16_t numberOfEntities = _entityItems->size(); uint16_t numberOfEntities = _entityItems->size();
for (uint16_t i = 0; i < numberOfEntities; i++) { for (uint16_t i = 0; i < numberOfEntities; i++) {
if ((*_entityItems)[i]->getID() == id) { if ((*_entityItems)[i]->getEntityItemID() == id) {
foundEntity = (*_entityItems)[i]; foundEntity = (*_entityItems)[i];
break; break;
} }
@ -646,11 +645,11 @@ void EntityTreeElement::cleanupEntities() {
_entityItems->clear(); _entityItems->clear();
} }
bool EntityTreeElement::removeEntityWithEntityItemID(const QUuid& id) { bool EntityTreeElement::removeEntityWithEntityItemID(const EntityItemID& id) {
bool foundEntity = false; bool foundEntity = false;
uint16_t numberOfEntities = _entityItems->size(); uint16_t numberOfEntities = _entityItems->size();
for (uint16_t i = 0; i < numberOfEntities; i++) { for (uint16_t i = 0; i < numberOfEntities; i++) {
if ((*_entityItems)[i]->getID() == id) { if ((*_entityItems)[i]->getEntityItemID() == id) {
foundEntity = true; foundEntity = true;
(*_entityItems)[i]->_element = NULL; (*_entityItems)[i]->_element = NULL;
_entityItems->removeAt(i); _entityItems->removeAt(i);
@ -706,12 +705,16 @@ 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;
QUuid entityItemID; EntityItemID entityItemID;
EntityItem* entityItem = NULL; EntityItem* entityItem = NULL;
QByteArray encodedID((const char*)dataAt, NUM_BYTES_RFC4122_UUID); // Old model files don't have UUIDs in them. So we don't want to try to read those IDs from the stream.
entityItemID = QUuid::fromRfc4122(encodedID); // Since this can only happen on loading an old file, we can safely treat these as new entity cases,
entityItem = _myTree->findEntityByEntityItemID(entityItemID); // which will correctly handle the case of creating models and letting them parse the old format.
if (args.bitstreamVersion >= VERSION_ENTITIES_SUPPORT_SPLIT_MTU) {
entityItemID = EntityItemID::readEntityItemIDFromBuffer(dataAt, bytesLeftToRead);
entityItem = _myTree->findEntityByEntityItemID(entityItemID);
}
// If the item already exists in our tree, we want do the following... // If the item already exists in our tree, we want do the following...
// 1) allow the existing item to read from the databuffer // 1) allow the existing item to read from the databuffer
@ -752,7 +755,7 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
if (entityItem) { if (entityItem) {
bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args); bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args);
addEntityItem(entityItem); // add this new entity to this elements entities addEntityItem(entityItem); // add this new entity to this elements entities
entityItemID = entityItem->getID(); entityItemID = entityItem->getEntityItemID();
_myTree->setContainingElement(entityItemID, this); _myTree->setContainingElement(entityItemID, this);
_myTree->postAddEntity(entityItem); _myTree->postAddEntity(entityItem);
} }

View file

@ -47,7 +47,7 @@ public:
bool elementCompleted; bool elementCompleted;
bool subtreeCompleted; bool subtreeCompleted;
bool childCompleted[NUMBER_OF_CHILDREN]; bool childCompleted[NUMBER_OF_CHILDREN];
QMap<QUuid, EntityPropertyFlags> entities; QMap<EntityItemID, EntityPropertyFlags> entities;
}; };
inline QDebug operator<<(QDebug debug, const EntityTreeElementExtraEncodeData* data) { inline QDebug operator<<(QDebug debug, const EntityTreeElementExtraEncodeData* data) {
@ -165,13 +165,13 @@ public:
void getEntities(const AACube& box, QVector<EntityItem*>& foundEntities); void getEntities(const AACube& box, QVector<EntityItem*>& foundEntities);
const EntityItem* getEntityWithID(uint32_t id) const; const EntityItem* getEntityWithID(uint32_t id) const;
const EntityItem* getEntityWithEntityItemID(const QUuid& id) const; const EntityItem* getEntityWithEntityItemID(const EntityItemID& id) const;
void getEntitiesInside(const AACube& box, QVector<EntityItem*>& foundEntities); void getEntitiesInside(const AACube& box, QVector<EntityItem*>& foundEntities);
EntityItem* getEntityWithEntityItemID(const QUuid& id); EntityItem* getEntityWithEntityItemID(const EntityItemID& id);
void cleanupEntities(); /// called by EntityTree on cleanup this will free all entities void cleanupEntities(); /// called by EntityTree on cleanup this will free all entities
bool removeEntityWithEntityItemID(const QUuid& id); bool removeEntityWithEntityItemID(const EntityItemID& id);
bool removeEntityItem(EntityItem* entity); bool removeEntityItem(EntityItem* entity);
bool containsEntityBounds(const EntityItem* entity) const; bool containsEntityBounds(const EntityItem* entity) const;

View file

@ -76,8 +76,8 @@ bool EntityTypes::registerEntityType(EntityType entityType, const char* name, En
return false; return false;
} }
EntityItem* EntityTypes::constructEntityItem(EntityType entityType, const QUuid& entityID, EntityItem* EntityTypes::constructEntityItem(EntityType entityType, const EntityItemID& entityID,
const EntityItemProperties& properties) { const EntityItemProperties& properties) {
EntityItem* newEntityItem = NULL; EntityItem* newEntityItem = NULL;
EntityTypeFactory factory = NULL; EntityTypeFactory factory = NULL;
if (entityType >= 0 && entityType <= LAST) { if (entityType >= 0 && entityType <= LAST) {
@ -91,7 +91,15 @@ EntityItem* EntityTypes::constructEntityItem(EntityType entityType, const QUuid&
return newEntityItem; return newEntityItem;
} }
EntityItem* EntityTypes::constructEntityItem(const unsigned char* data, int bytesToRead, ReadBitstreamToTreeParams& args) { EntityItem* EntityTypes::constructEntityItem(const unsigned char* data, int bytesToRead,
ReadBitstreamToTreeParams& args) {
if (args.bitstreamVersion < VERSION_ENTITIES_SUPPORT_SPLIT_MTU) {
EntityItemID tempEntityID;
EntityItemProperties tempProperties;
return constructEntityItem(Model, tempEntityID, tempProperties);
}
// Header bytes // Header bytes
// object ID [16 bytes] // object ID [16 bytes]
// ByteCountCoded(type code) [~1 byte] // ByteCountCoded(type code) [~1 byte]
@ -119,8 +127,9 @@ EntityItem* EntityTypes::constructEntityItem(const unsigned char* data, int byte
quint32 type = typeCoder; quint32 type = typeCoder;
EntityTypes::EntityType entityType = (EntityTypes::EntityType)type; EntityTypes::EntityType entityType = (EntityTypes::EntityType)type;
EntityItemID tempEntityID(actualID);
EntityItemProperties tempProperties; EntityItemProperties tempProperties;
return constructEntityItem(entityType, actualID, tempProperties); return constructEntityItem(entityType, tempEntityID, tempProperties);
} }
return NULL; return NULL;

View file

@ -14,17 +14,17 @@
#include <stdint.h> #include <stdint.h>
#include <QUuid>
#include <QHash> #include <QHash>
#include <QString> #include <QString>
#include <OctreeRenderer.h> // for RenderArgs #include <OctreeRenderer.h> // for RenderArgs
class EntityItem; class EntityItem;
class EntityItemID;
class EntityItemProperties; class EntityItemProperties;
class ReadBitstreamToTreeParams; class ReadBitstreamToTreeParams;
typedef EntityItem* (*EntityTypeFactory)(const QUuid& entityID, const EntityItemProperties& properties); typedef EntityItem* (*EntityTypeFactory)(const EntityItemID& entityID, const EntityItemProperties& properties);
class EntityTypes { class EntityTypes {
public: public:
@ -45,8 +45,7 @@ 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 EntityItem* constructEntityItem(EntityType entityType, static EntityItem* constructEntityItem(EntityType entityType, const EntityItemID& entityID, const EntityItemProperties& properties);
const QUuid& entityID, const EntityItemProperties& properties);
static EntityItem* constructEntityItem(const unsigned char* data, int bytesToRead, ReadBitstreamToTreeParams& args); static EntityItem* constructEntityItem(const unsigned char* data, int bytesToRead, ReadBitstreamToTreeParams& args);
private: private:
@ -60,7 +59,7 @@ private:
/// Macro for registering entity types. Make sure to add an element to the EntityType enum with your name, and your class should be /// Macro for registering entity types. Make sure to add an element to the EntityType enum with your name, and your class should be
/// named NameEntityItem and must of a static method called factory that takes an EnityItemID, and EntityItemProperties and return a newly /// named NameEntityItem and must of a static method called factory that takes an EnityItemID, and EntityItemProperties and return a newly
/// constructed (heap allocated) instance of your type. e.g. The following prototype: /// constructed (heap allocated) instance of your type. e.g. The following prototype:
// static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); // static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
#define REGISTER_ENTITY_TYPE(x) static bool x##Registration = \ #define REGISTER_ENTITY_TYPE(x) static bool x##Registration = \
EntityTypes::registerEntityType(EntityTypes::x, #x, x##EntityItem::factory); EntityTypes::registerEntityType(EntityTypes::x, #x, x##EntityItem::factory);
@ -68,7 +67,7 @@ private:
/// an element to the EntityType enum with your name. But unlike REGISTER_ENTITY_TYPE, your class can be named anything /// an element to the EntityType enum with your name. But unlike REGISTER_ENTITY_TYPE, your class can be named anything
/// so long as you provide a static method passed to the macro, that takes an EnityItemID, and EntityItemProperties and /// so long as you provide a static method passed to the macro, that takes an EnityItemID, and EntityItemProperties and
/// returns a newly constructed (heap allocated) instance of your type. e.g. The following prototype: /// returns a newly constructed (heap allocated) instance of your type. e.g. The following prototype:
// static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); // static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
#define REGISTER_ENTITY_TYPE_WITH_FACTORY(x,y) static bool x##Registration = \ #define REGISTER_ENTITY_TYPE_WITH_FACTORY(x,y) static bool x##Registration = \
EntityTypes::registerEntityType(EntityTypes::x, #x, y); \ EntityTypes::registerEntityType(EntityTypes::x, #x, y); \
if (!x##Registration) { \ if (!x##Registration) { \

View file

@ -14,6 +14,7 @@
#include <ByteCountCoding.h> #include <ByteCountCoding.h>
#include "EntityItemID.h"
#include "EntityTree.h" #include "EntityTree.h"
#include "EntityTreeElement.h" #include "EntityTreeElement.h"
#include "EntitiesLogging.h" #include "EntitiesLogging.h"
@ -21,12 +22,12 @@
bool LightEntityItem::_lightsArePickable = false; bool LightEntityItem::_lightsArePickable = false;
EntityItem* LightEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* LightEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
return new LightEntityItem(entityID, properties); return new LightEntityItem(entityID, properties);
} }
// our non-pure virtual subclass for now... // our non-pure virtual subclass for now...
LightEntityItem::LightEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : LightEntityItem::LightEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
EntityItem(entityItemID, properties) EntityItem(entityItemID, properties)
{ {
_type = EntityTypes::Light; _type = EntityTypes::Light;

View file

@ -16,9 +16,9 @@
class LightEntityItem : public EntityItem { class LightEntityItem : public EntityItem {
public: public:
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
LightEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); LightEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
ALLOW_INSTANTIATION // This class can be instantiated ALLOW_INSTANTIATION // This class can be instantiated

View file

@ -20,12 +20,12 @@
#include "EntityTreeElement.h" #include "EntityTreeElement.h"
EntityItem* LineEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* LineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
EntityItem* result = new LineEntityItem(entityID, properties); EntityItem* result = new LineEntityItem(entityID, properties);
return result; return result;
} }
LineEntityItem::LineEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : LineEntityItem::LineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
EntityItem(entityItemID) EntityItem(entityItemID)
{ {
_type = EntityTypes::Line; _type = EntityTypes::Line;
@ -99,7 +99,7 @@ void LineEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits
void LineEntityItem::debugDump() const { void LineEntityItem::debugDump() const {
quint64 now = usecTimestampNow(); quint64 now = usecTimestampNow();
qCDebug(entities) << " LINE EntityItem id:" << getID() << "---------------------------------------------"; qCDebug(entities) << " LINE EntityItem id:" << getEntityItemID() << "---------------------------------------------";
qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2];
qCDebug(entities) << " position:" << debugTreeVector(_position); qCDebug(entities) << " position:" << debugTreeVector(_position);
qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions);

View file

@ -16,9 +16,9 @@
class LineEntityItem : public EntityItem { class LineEntityItem : public EntityItem {
public: public:
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
LineEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); LineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
ALLOW_INSTANTIATION // This class can be instantiated ALLOW_INSTANTIATION // This class can be instantiated

View file

@ -28,11 +28,11 @@ const bool ModelEntityItem::DEFAULT_ANIMATION_IS_PLAYING = false;
const float ModelEntityItem::DEFAULT_ANIMATION_FPS = 30.0f; const float ModelEntityItem::DEFAULT_ANIMATION_FPS = 30.0f;
EntityItem* ModelEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* ModelEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
return new ModelEntityItem(entityID, properties); return new ModelEntityItem(entityID, properties);
} }
ModelEntityItem::ModelEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
EntityItem(entityItemID, properties) EntityItem(entityItemID, properties)
{ {
_type = EntityTypes::Model; _type = EntityTypes::Model;
@ -267,7 +267,7 @@ void ModelEntityItem::update(const quint64& now) {
} }
void ModelEntityItem::debugDump() const { void ModelEntityItem::debugDump() const {
qCDebug(entities) << "ModelEntityItem id:" << getID(); qCDebug(entities) << "ModelEntityItem id:" << getEntityItemID();
qCDebug(entities) << " edited ago:" << getEditedAgo(); qCDebug(entities) << " edited ago:" << getEditedAgo();
qCDebug(entities) << " position:" << getPosition(); qCDebug(entities) << " position:" << getPosition();
qCDebug(entities) << " dimensions:" << getDimensions(); qCDebug(entities) << " dimensions:" << getDimensions();

View file

@ -18,9 +18,9 @@
class ModelEntityItem : public EntityItem { class ModelEntityItem : public EntityItem {
public: public:
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
ModelEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); ModelEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
ALLOW_INSTANTIATION // This class can be instantiated ALLOW_INSTANTIATION // This class can be instantiated

View file

@ -25,11 +25,11 @@ public:
}; };
inline uint qHash(const EntityToMoveDetails& a, uint seed) { inline uint qHash(const EntityToMoveDetails& a, uint seed) {
return qHash(a.entity->getID(), seed); return qHash(a.entity, seed);
} }
inline bool operator==(const EntityToMoveDetails& a, const EntityToMoveDetails& b) { inline bool operator==(const EntityToMoveDetails& a, const EntityToMoveDetails& b) {
return a.entity->getID() == b.entity->getID(); return a.entity == b.entity;
} }
class MovingEntitiesOperator : public RecurseOctreeOperator { class MovingEntitiesOperator : public RecurseOctreeOperator {

View file

@ -55,12 +55,12 @@ const float ParticleEffectEntityItem::DEFAULT_PARTICLE_RADIUS = 0.025f;
const QString ParticleEffectEntityItem::DEFAULT_TEXTURES = ""; const QString ParticleEffectEntityItem::DEFAULT_TEXTURES = "";
EntityItem* ParticleEffectEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* ParticleEffectEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
return new ParticleEffectEntityItem(entityID, properties); return new ParticleEffectEntityItem(entityID, properties);
} }
// our non-pure virtual subclass for now... // our non-pure virtual subclass for now...
ParticleEffectEntityItem::ParticleEffectEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : ParticleEffectEntityItem::ParticleEffectEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
EntityItem(entityItemID, properties), EntityItem(entityItemID, properties),
_maxParticles(DEFAULT_MAX_PARTICLES), _maxParticles(DEFAULT_MAX_PARTICLES),
_lifespan(DEFAULT_LIFESPAN), _lifespan(DEFAULT_LIFESPAN),
@ -274,7 +274,7 @@ void ParticleEffectEntityItem::update(const quint64& now) {
void ParticleEffectEntityItem::debugDump() const { void ParticleEffectEntityItem::debugDump() const {
quint64 now = usecTimestampNow(); quint64 now = usecTimestampNow();
qCDebug(entities) << "PA EFFECT EntityItem id:" << getID() << "---------------------------------------------"; qCDebug(entities) << "PA EFFECT EntityItem id:" << getEntityItemID() << "---------------------------------------------";
qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2];
qCDebug(entities) << " position:" << debugTreeVector(_position); qCDebug(entities) << " position:" << debugTreeVector(_position);
qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions);

View file

@ -17,9 +17,9 @@
class ParticleEffectEntityItem : public EntityItem { class ParticleEffectEntityItem : public EntityItem {
public: public:
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
ParticleEffectEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); ParticleEffectEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
virtual ~ParticleEffectEntityItem(); virtual ~ParticleEffectEntityItem();
ALLOW_INSTANTIATION // This class can be instantiated ALLOW_INSTANTIATION // This class can be instantiated

View file

@ -23,12 +23,12 @@
#include "SphereEntityItem.h" #include "SphereEntityItem.h"
EntityItem* SphereEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* SphereEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
return new SphereEntityItem(entityID, properties); return new SphereEntityItem(entityID, properties);
} }
// our non-pure virtual subclass for now... // our non-pure virtual subclass for now...
SphereEntityItem::SphereEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : SphereEntityItem::SphereEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
EntityItem(entityItemID, properties) EntityItem(entityItemID, properties)
{ {
_type = EntityTypes::Sphere; _type = EntityTypes::Sphere;
@ -117,7 +117,7 @@ bool SphereEntityItem::findDetailedRayIntersection(const glm::vec3& origin, cons
void SphereEntityItem::debugDump() const { void SphereEntityItem::debugDump() const {
quint64 now = usecTimestampNow(); quint64 now = usecTimestampNow();
qCDebug(entities) << "SHPERE EntityItem id:" << getID() << "---------------------------------------------"; qCDebug(entities) << "SHPERE EntityItem id:" << getEntityItemID() << "---------------------------------------------";
qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2];
qCDebug(entities) << " position:" << debugTreeVector(_position); qCDebug(entities) << " position:" << debugTreeVector(_position);
qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions);

View file

@ -16,9 +16,9 @@
class SphereEntityItem : public EntityItem { class SphereEntityItem : public EntityItem {
public: public:
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
SphereEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); SphereEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
ALLOW_INSTANTIATION // This class can be instantiated ALLOW_INSTANTIATION // This class can be instantiated

View file

@ -28,12 +28,12 @@ const float TextEntityItem::DEFAULT_LINE_HEIGHT = 0.1f;
const xColor TextEntityItem::DEFAULT_TEXT_COLOR = { 255, 255, 255 }; const xColor TextEntityItem::DEFAULT_TEXT_COLOR = { 255, 255, 255 };
const xColor TextEntityItem::DEFAULT_BACKGROUND_COLOR = { 0, 0, 0}; const xColor TextEntityItem::DEFAULT_BACKGROUND_COLOR = { 0, 0, 0};
EntityItem* TextEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* TextEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
EntityItem* result = new TextEntityItem(entityID, properties); EntityItem* result = new TextEntityItem(entityID, properties);
return result; return result;
} }
TextEntityItem::TextEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : TextEntityItem::TextEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
EntityItem(entityItemID) EntityItem(entityItemID)
{ {
_type = EntityTypes::Text; _type = EntityTypes::Text;

View file

@ -16,9 +16,9 @@
class TextEntityItem : public EntityItem { class TextEntityItem : public EntityItem {
public: public:
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
TextEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); TextEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
ALLOW_INSTANTIATION // This class can be instantiated ALLOW_INSTANTIATION // This class can be instantiated

View file

@ -25,7 +25,7 @@ UpdateEntityOperator::UpdateEntityOperator(EntityTree* tree,
_containingElement(containingElement), _containingElement(containingElement),
_containingElementCube(containingElement->getAACube()), _containingElementCube(containingElement->getAACube()),
_properties(properties), _properties(properties),
_entityItemID(existingEntity->getID()), _entityItemID(existingEntity->getEntityItemID()),
_foundOld(false), _foundOld(false),
_foundNew(false), _foundNew(false),
_removeOld(false), _removeOld(false),

View file

@ -15,7 +15,7 @@
class UpdateEntityOperator : public RecurseOctreeOperator { class UpdateEntityOperator : public RecurseOctreeOperator {
public: public:
UpdateEntityOperator(EntityTree* tree, EntityTreeElement* containingElement, UpdateEntityOperator(EntityTree* tree, EntityTreeElement* containingElement,
EntityItem* existingEntity, const EntityItemProperties& properties); EntityItem* existingEntity, const EntityItemProperties& properties);
~UpdateEntityOperator(); ~UpdateEntityOperator();
virtual bool preRecursion(OctreeElement* element); virtual bool preRecursion(OctreeElement* element);
@ -27,7 +27,7 @@ private:
EntityTreeElement* _containingElement; EntityTreeElement* _containingElement;
AACube _containingElementCube; // we temporarily store our cube here in case we need to delete the containing element AACube _containingElementCube; // we temporarily store our cube here in case we need to delete the containing element
EntityItemProperties _properties; EntityItemProperties _properties;
QUuid _entityItemID; EntityItemID _entityItemID;
bool _foundOld; bool _foundOld;
bool _foundNew; bool _foundNew;
bool _removeOld; bool _removeOld;

View file

@ -22,12 +22,12 @@
const QString WebEntityItem::DEFAULT_SOURCE_URL("http://www.google.com"); const QString WebEntityItem::DEFAULT_SOURCE_URL("http://www.google.com");
EntityItem* WebEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* WebEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
EntityItem* result = new WebEntityItem(entityID, properties); EntityItem* result = new WebEntityItem(entityID, properties);
return result; return result;
} }
WebEntityItem::WebEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : WebEntityItem::WebEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
EntityItem(entityItemID) EntityItem(entityItemID)
{ {
_type = EntityTypes::Web; _type = EntityTypes::Web;
@ -150,4 +150,4 @@ void WebEntityItem::setSourceUrl(const QString& value) {
} }
} }
const QString& WebEntityItem::getSourceUrl() const { return _sourceUrl; } const QString& WebEntityItem::getSourceUrl() const { return _sourceUrl; }

View file

@ -15,9 +15,9 @@ class WebEntityItem : public EntityItem {
public: public:
static const QString DEFAULT_SOURCE_URL; static const QString DEFAULT_SOURCE_URL;
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
WebEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); WebEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
ALLOW_INSTANTIATION // This class can be instantiated ALLOW_INSTANTIATION // This class can be instantiated

View file

@ -29,12 +29,12 @@ const glm::vec3 ZoneEntityItem::DEFAULT_KEYLIGHT_DIRECTION = { 0.0f, -1.0f, 0.0f
const ShapeType ZoneEntityItem::DEFAULT_SHAPE_TYPE = SHAPE_TYPE_BOX; const ShapeType ZoneEntityItem::DEFAULT_SHAPE_TYPE = SHAPE_TYPE_BOX;
const QString ZoneEntityItem::DEFAULT_COMPOUND_SHAPE_URL = ""; const QString ZoneEntityItem::DEFAULT_COMPOUND_SHAPE_URL = "";
EntityItem* ZoneEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* ZoneEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
EntityItem* result = new ZoneEntityItem(entityID, properties); EntityItem* result = new ZoneEntityItem(entityID, properties);
return result; return result;
} }
ZoneEntityItem::ZoneEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : ZoneEntityItem::ZoneEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
EntityItem(entityItemID) EntityItem(entityItemID)
{ {
_type = EntityTypes::Zone; _type = EntityTypes::Zone;
@ -216,9 +216,8 @@ void ZoneEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits
void ZoneEntityItem::debugDump() const { void ZoneEntityItem::debugDump() const {
quint64 now = usecTimestampNow(); quint64 now = usecTimestampNow();
qCDebug(entities) << " ZoneEntityItem id:" << getID() << "---------------------------------------------"; qCDebug(entities) << " ZoneEntityItem id:" << getEntityItemID() << "---------------------------------------------";
qCDebug(entities) << " keyLightColor:" << _keyLightColor[0] << "," qCDebug(entities) << " keyLightColor:" << _keyLightColor[0] << "," << _keyLightColor[1] << "," << _keyLightColor[2];
<< _keyLightColor[1] << "," << _keyLightColor[2];
qCDebug(entities) << " position:" << debugTreeVector(_position); qCDebug(entities) << " position:" << debugTreeVector(_position);
qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions);
qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now);

View file

@ -19,9 +19,9 @@
class ZoneEntityItem : public EntityItem { class ZoneEntityItem : public EntityItem {
public: public:
static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties);
ZoneEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); ZoneEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
ALLOW_INSTANTIATION // This class can be instantiated ALLOW_INSTANTIATION // This class can be instantiated

View file

@ -427,7 +427,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q
} }
if (EntityItem::getSendPhysicsUpdates()) { if (EntityItem::getSendPhysicsUpdates()) {
QUuid id(_entity->getID()); EntityItemID id(_entity->getID());
EntityEditPacketSender* entityPacketSender = static_cast<EntityEditPacketSender*>(packetSender); EntityEditPacketSender* entityPacketSender = static_cast<EntityEditPacketSender*>(packetSender);
#ifdef WANT_DEBUG #ifdef WANT_DEBUG
qCDebug(physics) << "EntityMotionState::sendUpdate()... calling queueEditEntityMessage()..."; qCDebug(physics) << "EntityMotionState::sendUpdate()... calling queueEditEntityMessage()...";

View file

@ -40,7 +40,8 @@ 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;
QUuid entityID = QUuid::createUuid(); QUuid id = QUuid::createUuid();
EntityItemID entityID(id);
EntityItemProperties properties; EntityItemProperties properties;
float oneMeter = 1.0f; float oneMeter = 1.0f;
float halfOfDomain = TREE_SCALE * 0.5f; float halfOfDomain = TREE_SCALE * 0.5f;
@ -247,7 +248,8 @@ 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++) {
QUuid entityID = QUuid::createUuid();// 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);
float randomX = randFloatInRange(1.0f ,(float)TREE_SCALE - 1.0f); float randomX = randFloatInRange(1.0f ,(float)TREE_SCALE - 1.0f);
float randomY = randFloatInRange(1.0f ,(float)TREE_SCALE - 1.0f); float randomY = randFloatInRange(1.0f ,(float)TREE_SCALE - 1.0f);
@ -349,7 +351,8 @@ 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++) {
QUuid entityID = QUuid::createUuid();// 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);
if (extraVerbose) { if (extraVerbose) {
qDebug() << "before:" << i << "getOctreeElementsCount()=" << tree.getOctreeElementsCount(); qDebug() << "before:" << i << "getOctreeElementsCount()=" << tree.getOctreeElementsCount();
@ -428,9 +431,11 @@ void EntityTests::entityTreeTests(bool verbose) {
quint64 totalElapsedFind = 0; quint64 totalElapsedFind = 0;
for (int i = 0; i < TEST_ITERATIONS; i++) { for (int i = 0; i < TEST_ITERATIONS; i++) {
QSet<QUuid> 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);
entitiesToDelete << entityID; entitiesToDelete << entityID;
} }
@ -450,7 +455,8 @@ 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 entityID = QUuid::createUuid();// 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);
const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID); const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
EntityTreeElement* containingElement = tree.getContainingElement(entityID); EntityTreeElement* containingElement = tree.getContainingElement(entityID);