From f9d46b0cb5af090a4f668c473049ed4e5eb57c17 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 19 May 2015 14:25:23 -0700 Subject: [PATCH 1/8] interface decides on entityIDs rather than bouncing a temporary id through the entity server --- assignment-client/src/Agent.cpp | 3 - .../src/entities/EntityServer.cpp | 6 - examples/controllers/hydra/frisbee.js | 4 +- examples/controllers/hydra/gun.js | 7 - examples/controllers/hydra/paddleBall.js | 8 +- examples/controllers/hydra/toyball.js | 9 +- examples/edit.js | 39 +-- examples/entityScripts/chessPiece.js | 19 +- examples/entityScripts/inspect.js | 4 +- examples/entityScripts/lightController.js | 8 +- examples/entityScripts/movable.js | 4 +- examples/entityScripts/playSoundOnClick.js | 2 +- .../entityScripts/playSoundOnEnterOrLeave.js | 6 +- examples/entityScripts/sitOnEntity.js | 6 +- .../example/entities/animatedModelExample.js | 5 +- examples/example/entities/butterflies.js | 2 +- .../example/entities/editEntityExample.js | 2 - examples/example/entities/editModelExample.js | 2 - .../example/entities/findEntitiesExample.js | 20 -- examples/example/entities/flockingBirds.js | 23 +- .../entities/rideAlongWithAnEntityExample.js | 4 - examples/example/games/billiards.js | 21 +- examples/example/games/playChess.js | 8 +- .../example/games/spaceInvadersExample.js | 38 +-- examples/harmonicOscillator.js | 3 - examples/html/entityList.html | 5 +- examples/html/entityProperties.html | 2 +- examples/libraries/entityList.js | 12 +- examples/libraries/entitySelectionTool.js | 74 +---- examples/libraries/lightOverlayManager.js | 27 +- examples/sit.js | 4 +- interface/src/Application.cpp | 8 +- interface/src/Application.h | 4 +- interface/src/DatagramProcessor.cpp | 2 - .../scripting/ClipboardScriptingInterface.cpp | 4 +- .../scripting/ClipboardScriptingInterface.h | 4 +- .../src/EntityTreeRenderer.cpp | 83 +++--- .../src/EntityTreeRenderer.h | 52 ++-- .../src/RenderableBoxEntityItem.cpp | 2 +- .../src/RenderableBoxEntityItem.h | 4 +- .../src/RenderableLightEntityItem.cpp | 2 +- .../src/RenderableLightEntityItem.h | 4 +- .../src/RenderableLineEntityItem.cpp | 2 +- .../src/RenderableLineEntityItem.h | 4 +- .../src/RenderableModelEntityItem.cpp | 2 +- .../src/RenderableModelEntityItem.h | 4 +- .../RenderableParticleEffectEntityItem.cpp | 5 +- .../src/RenderableParticleEffectEntityItem.h | 4 +- .../src/RenderableSphereEntityItem.cpp | 2 +- .../src/RenderableSphereEntityItem.h | 4 +- .../src/RenderableTextEntityItem.cpp | 4 +- .../src/RenderableTextEntityItem.h | 4 +- .../src/RenderableWebEntityItem.cpp | 6 +- .../src/RenderableWebEntityItem.h | 4 +- .../src/RenderableZoneEntityItem.cpp | 2 +- .../src/RenderableZoneEntityItem.h | 4 +- libraries/entities/src/AddEntityOperator.cpp | 2 +- libraries/entities/src/BoxEntityItem.cpp | 6 +- libraries/entities/src/BoxEntityItem.h | 4 +- .../entities/src/DeleteEntityOperator.cpp | 6 +- libraries/entities/src/DeleteEntityOperator.h | 8 +- .../entities/src/EntityEditPacketSender.cpp | 6 +- .../entities/src/EntityEditPacketSender.h | 4 +- libraries/entities/src/EntityItem.cpp | 38 +-- libraries/entities/src/EntityItem.h | 16 +- libraries/entities/src/EntityItemID.cpp | 143 ---------- libraries/entities/src/EntityItemID.h | 112 -------- .../entities/src/EntityItemProperties.cpp | 61 +--- libraries/entities/src/EntityItemProperties.h | 14 +- .../entities/src/EntityScriptingInterface.cpp | 120 +++----- .../entities/src/EntityScriptingInterface.h | 56 ++-- libraries/entities/src/EntitySimulation.cpp | 4 +- libraries/entities/src/EntitySimulation.h | 2 +- libraries/entities/src/EntityTree.cpp | 262 ++++-------------- libraries/entities/src/EntityTree.h | 35 ++- libraries/entities/src/EntityTreeElement.cpp | 50 ++-- libraries/entities/src/EntityTreeElement.h | 11 +- libraries/entities/src/EntityTypes.cpp | 17 +- libraries/entities/src/EntityTypes.h | 11 +- libraries/entities/src/LightEntityItem.cpp | 5 +- libraries/entities/src/LightEntityItem.h | 4 +- libraries/entities/src/LineEntityItem.cpp | 6 +- libraries/entities/src/LineEntityItem.h | 4 +- libraries/entities/src/ModelEntityItem.cpp | 6 +- libraries/entities/src/ModelEntityItem.h | 4 +- .../entities/src/MovingEntitiesOperator.cpp | 12 +- .../entities/src/MovingEntitiesOperator.h | 4 +- .../entities/src/ParticleEffectEntityItem.cpp | 6 +- .../entities/src/ParticleEffectEntityItem.h | 4 +- libraries/entities/src/SphereEntityItem.cpp | 6 +- libraries/entities/src/SphereEntityItem.h | 4 +- libraries/entities/src/TextEntityItem.cpp | 4 +- libraries/entities/src/TextEntityItem.h | 4 +- .../entities/src/UpdateEntityOperator.cpp | 2 +- libraries/entities/src/UpdateEntityOperator.h | 4 +- libraries/entities/src/WebEntityItem.cpp | 6 +- libraries/entities/src/WebEntityItem.h | 4 +- libraries/entities/src/ZoneEntityItem.cpp | 9 +- libraries/entities/src/ZoneEntityItem.h | 4 +- libraries/physics/src/EntityMotionState.cpp | 3 +- .../physics/src/PhysicalEntitySimulation.cpp | 2 +- libraries/script-engine/src/ScriptEngine.cpp | 3 +- libraries/shared/src/RegisteredMetaTypes.cpp | 7 + tests/octree/src/ModelTests.cpp | 21 +- 104 files changed, 489 insertions(+), 1234 deletions(-) delete mode 100644 libraries/entities/src/EntityItemID.cpp delete mode 100644 libraries/entities/src/EntityItemID.h diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 3c99f0a209..3030f82cf1 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -74,9 +74,6 @@ void Agent::readPendingDatagrams() { } } else if (datagramPacketType == PacketTypeEntityAddResponse) { - // this will keep creatorTokenIDs to IDs mapped correctly - EntityItemID::handleAddEntityResponse(receivedPacket); - // also give our local entity tree a chance to remap any internal locally created entities _entityViewer.getTree()->handleAddEntityResponse(receivedPacket); diff --git a/assignment-client/src/entities/EntityServer.cpp b/assignment-client/src/entities/EntityServer.cpp index 0f5332192a..9c57f6c757 100644 --- a/assignment-client/src/entities/EntityServer.cpp +++ b/assignment-client/src/entities/EntityServer.cpp @@ -70,12 +70,6 @@ void EntityServer::entityCreated(const EntityItem& newEntity, const SharedNodePo int packetLength = numBytesPacketHeader; copyAt += numBytesPacketHeader; - // encode the creatorTokenID - uint32_t creatorTokenID = newEntity.getCreatorTokenID(); - memcpy(copyAt, &creatorTokenID, sizeof(creatorTokenID)); - copyAt += sizeof(creatorTokenID); - packetLength += sizeof(creatorTokenID); - // encode the entity ID QUuid entityID = newEntity.getID(); QByteArray encodedID = entityID.toRfc4122(); diff --git a/examples/controllers/hydra/frisbee.js b/examples/controllers/hydra/frisbee.js index 461f4691da..78d8e77a90 100644 --- a/examples/controllers/hydra/frisbee.js +++ b/examples/controllers/hydra/frisbee.js @@ -198,7 +198,7 @@ function checkControllerSide(hand) { var closestEntity = Entities.findClosestEntity(hand.palmPosition(), CATCH_RADIUS); var modelUrl = Entities.getEntityProperties(closestEntity).modelURL; print("lol2"+closestEntity.isKnownID); - if (closestEntity.isKnownID && validFrisbeeURL(Entities.getEntityProperties(closestEntity).modelURL)) { + if (closestEntity && validFrisbeeURL(Entities.getEntityProperties(closestEntity).modelURL)) { print("lol"); Entities.editEntity(closestEntity, {modelScale: 1, inHand: true, position: hand.holdPosition(), shouldDie: true}); Entities.deleteEntity(closestEntity); @@ -448,4 +448,4 @@ Controller.mouseReleaseEvent.connect(mouseReleaseEvent); Menu.menuItemEvent.connect(menuItemEvent); Script.scriptEnding.connect(scriptEnding); Script.update.connect(checkController); -Script.update.connect(controlFrisbees); \ No newline at end of file +Script.update.connect(controlFrisbees); diff --git a/examples/controllers/hydra/gun.js b/examples/controllers/hydra/gun.js index f2ed50733d..7dd2b5974f 100644 --- a/examples/controllers/hydra/gun.js +++ b/examples/controllers/hydra/gun.js @@ -386,13 +386,6 @@ MyAvatar.attach(gunModel, "LeftHand", {x:-0.04, y: 0.22, z: 0.02}, Quat.fromPitc Script.setTimeout(playLoadSound, 2000); function update(deltaTime) { - if (bulletID && !bulletID.isKnownID) { - bulletID = Entities.identifyEntity(bulletID); - } - if (targetID && !targetID.isKnownID) { - targetID = Entities.identifyEntity(targetID); - } - if (activeControllers == 0) { if (Controller.getNumberOfSpatialControls() > 0) { activeControllers = Controller.getNumberOfSpatialControls(); diff --git a/examples/controllers/hydra/paddleBall.js b/examples/controllers/hydra/paddleBall.js index fb312739f4..ef4fe92544 100644 --- a/examples/controllers/hydra/paddleBall.js +++ b/examples/controllers/hydra/paddleBall.js @@ -132,12 +132,6 @@ function update(deltaTime) { return; } - if (!paddle.isKnownID) { - paddle = Entities.identifyEntity(paddle); - } - if (!ball.isKnownID) { - ball = Entities.identifyEntity(ball); - } else { var paddleOrientation = leftHanded ? PADDLE_ORIENTATION : Quat.multiply(PADDLE_ORIENTATION, Quat.fromPitchYawRollDegrees(0, 180, 0)); var paddleWorldOrientation = Quat.multiply(Quat.multiply(MyAvatar.orientation, Controller.getSpatialControlRawRotation(controllerID)), paddleOrientation); var holdPosition = Vec3.sum(leftHanded ? MyAvatar.getLeftPalmPosition() : MyAvatar.getRightPalmPosition(), @@ -157,7 +151,7 @@ function update(deltaTime) { Entities.editEntity(paddleModel, { position: Vec3.sum(holdPosition, Vec3.multiplyQbyV(paddleWorldOrientation, PADDLE_BOX_OFFSET)), velocity: Controller.getSpatialControlVelocity(controllerID), rotation: paddleWorldOrientation }); - } + } function entityCollisionWithEntity(entity1, entity2, collision) { diff --git a/examples/controllers/hydra/toyball.js b/examples/controllers/hydra/toyball.js index 83dcf2937d..18a4341ca6 100644 --- a/examples/controllers/hydra/toyball.js +++ b/examples/controllers/hydra/toyball.js @@ -109,17 +109,10 @@ function checkControllerSide(whichSide) { var grabButtonPressed = (Controller.isButtonPressed(BUTTON_FWD) || Controller.isButtonPressed(BUTTON_3) || (Controller.getTriggerValue(TRIGGER) > 0.5)); // If I don't currently have a ball in my hand, then try to catch closest one - if (leftHandEntity && !leftHandEntity.isKnownID) { - leftHandEntity = Entities.identifyEntity(leftHandEntity); - } - if (rightHandEntity && !rightHandEntity.isKnownID) { - rightHandEntity = Entities.identifyEntity(rightHandEntity); - } - if (!ballAlreadyInHand && grabButtonPressed) { var closestEntity = Entities.findClosestEntity(palmPosition, targetRadius); - if (closestEntity.isKnownID) { + if (closestEntity) { var foundProperties = Entities.getEntityProperties(closestEntity); if (Vec3.length(foundProperties.velocity) > 0.0) { diff --git a/examples/edit.js b/examples/edit.js index 085cfb28ba..95c4df50c4 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -579,16 +579,6 @@ function findClickedEntity(event) { } var foundEntity = result.entityID; - - if (!foundEntity.isKnownID) { - var identify = Entities.identifyEntity(foundEntity); - if (!identify.isKnownID) { - print("Unknown ID " + identify.id + " (update loop " + foundEntity.id + ")"); - return null; - } - foundEntity = identify; - } - return { pickRay: pickRay, entityID: foundEntity }; } @@ -610,7 +600,7 @@ function mousePressEvent(event) { } } -var highlightedEntityID = { isKnownID: false }; +var highlightedEntityID = null; var mouseCapturedByTool = false; var lastMousePosition = null; var idleMouseTimerId = null; @@ -625,9 +615,6 @@ function mouseMove(event) { mouseHasMovedSincePress = true; if (placingEntityID) { - if (!placingEntityID.isKnownID) { - placingEntityID = Entities.identifyEntity(placingEntityID); - } var pickRay = Camera.computePickRay(event.x, event.y); var distance = cameraManager.enabled ? cameraManager.zoomDistance : DEFAULT_ENTITY_DRAG_DROP_DISTANCE; var offset = Vec3.multiply(distance, pickRay.direction); @@ -664,9 +651,9 @@ function highlightEntityUnderCursor(position, accurateRay) { var pickRay = Camera.computePickRay(position.x, position.y); var entityIntersection = Entities.findRayIntersection(pickRay, accurateRay); if (entityIntersection.accurate) { - if(highlightedEntityID.isKnownID && highlightedEntityID.id != entityIntersection.entityID.id) { + if(highlightedEntityID && highlightedEntityID != entityIntersection.entityID) { selectionDisplay.unhighlightSelectable(highlightedEntityID); - highlightedEntityID = { id: -1, isKnownID: false }; + highlightedEntityID = { id: -1 }; } var halfDiagonal = Vec3.length(entityIntersection.properties.dimensions) / 2.0; @@ -677,7 +664,7 @@ function highlightEntityUnderCursor(position, accurateRay) { var sizeOK = (allowLargeModels || angularSize < MAX_ANGULAR_SIZE) && (allowSmallModels || angularSize > MIN_ANGULAR_SIZE); - if (entityIntersection.entityID.isKnownID && sizeOK) { + if (entityIntersection.entityID && sizeOK) { if (wantEntityGlow) { Entities.editEntity(entityIntersection.entityID, { glowLevel: 0.25 }); } @@ -736,7 +723,7 @@ function mouseClickEvent(event) { } else { var halfDiagonal = Vec3.length(properties.dimensions) / 2.0; - print("Checking properties: " + properties.id + " " + properties.isKnownID + " - Half Diagonal:" + halfDiagonal); + print("Checking properties: " + properties.id + " " + " - Half Diagonal:" + halfDiagonal); // P P - Model // /| A - Palm // / | d B - unit vector toward tip @@ -967,8 +954,8 @@ function deleteSelectedEntities() { var savedProperties = []; for (var i = 0; i < selectionManager.selections.length; i++) { var entityID = SelectionManager.selections[i]; - var initialProperties = SelectionManager.savedProperties[entityID.id]; - SelectionManager.savedProperties[entityID.id]; + var initialProperties = SelectionManager.savedProperties[entityID]; + SelectionManager.savedProperties[entityID]; savedProperties.push({ entityID: entityID, properties: initialProperties @@ -1127,8 +1114,8 @@ function applyEntityProperties(data) { var selectedEntityIDs = []; for (var i = 0; i < properties.length; i++) { var entityID = properties[i].entityID; - if (DELETED_ENTITY_MAP[entityID.id] !== undefined) { - entityID = DELETED_ENTITY_MAP[entityID.id]; + if (DELETED_ENTITY_MAP[entityID] !== undefined) { + entityID = DELETED_ENTITY_MAP[entityID]; } Entities.editEntity(entityID, properties[i].properties); selectedEntityIDs.push(entityID); @@ -1137,15 +1124,15 @@ function applyEntityProperties(data) { var entityID = data.createEntities[i].entityID; var properties = data.createEntities[i].properties; var newEntityID = Entities.addEntity(properties); - DELETED_ENTITY_MAP[entityID.id] = newEntityID; + DELETED_ENTITY_MAP[entityID] = newEntityID; if (data.selectCreated) { selectedEntityIDs.push(newEntityID); } } for (var i = 0; i < data.deleteEntities.length; i++) { var entityID = data.deleteEntities[i].entityID; - if (DELETED_ENTITY_MAP[entityID.id] !== undefined) { - entityID = DELETED_ENTITY_MAP[entityID.id]; + if (DELETED_ENTITY_MAP[entityID] !== undefined) { + entityID = DELETED_ENTITY_MAP[entityID]; } Entities.deleteEntity(entityID); } @@ -1170,7 +1157,7 @@ function pushCommandForSelections(createdEntityData, deletedEntityData) { }; for (var i = 0; i < SelectionManager.selections.length; i++) { var entityID = SelectionManager.selections[i]; - var initialProperties = SelectionManager.savedProperties[entityID.id]; + var initialProperties = SelectionManager.savedProperties[entityID]; var currentProperties = Entities.getEntityProperties(entityID); undoData.setProperties.push({ entityID: entityID, diff --git a/examples/entityScripts/chessPiece.js b/examples/entityScripts/chessPiece.js index 4d3fc5cc3d..b6dfca9efd 100644 --- a/examples/entityScripts/chessPiece.js +++ b/examples/entityScripts/chessPiece.js @@ -17,8 +17,8 @@ // All callbacks start by updating the properties this.updateProperties = function(entityID) { // Piece ID - if (this.entityID === null || !this.entityID.isKnownID) { - this.entityID = Entities.identifyEntity(entityID); + if (this.entityID === null) { + this.entityID = entityID; } // Piece Properties this.properties = Entities.getEntityProperties(this.entityID); @@ -27,12 +27,7 @@ if (this.boardID === null) { // Read user data string and update boardID var userData = JSON.parse(this.properties.userData); - var boardID = Entities.identifyEntity(userData.boardID); - if (boardID.isKnownID) { - this.boardID = boardID; - } else { - return; - } + this.boardID = userData.boardID; } // Board User Data @@ -52,13 +47,13 @@ // Updates user data related objects this.updateUserData = function() { // Get board's user data - if (this.boardID !== null && this.boardID.isKnownID) { + if (this.boardID !== null) { this.boardUserData = this.getEntityUserData(this.boardID); if (!(this.boardUserData && this.boardUserData.firstTile && this.boardUserData.tileSize)) { - print("Incomplete boardUserData " + this.boardID.id); + print("Incomplete boardUserData " + this.boardID); } else { this.FIRST_TILE = this.boardUserData.firstTile; this.TILE_SIZE = this.boardUserData.tileSize; @@ -137,7 +132,7 @@ for (var i = 0; i < others.length; i++) { var piece = others[i]; - if (piece.id != this.entityID.id) { + if (piece.id != this.entityID) { var properties = Entities.getEntityProperties(piece); var isWhite = properties.modelURL.search("White") !== -1; @@ -198,4 +193,4 @@ this.updateProperties(entityID); // All callbacks start by updating the properties this.release(mouseEvent); }; -}) \ No newline at end of file +}) diff --git a/examples/entityScripts/inspect.js b/examples/entityScripts/inspect.js index abfb445a17..c56892c4fe 100644 --- a/examples/entityScripts/inspect.js +++ b/examples/entityScripts/inspect.js @@ -35,8 +35,8 @@ } // All callbacks start by updating the properties this.updateProperties = function(entityID) { - if (this.entityID === null || !this.entityID.isKnownID) { - this.entityID = Entities.identifyEntity(entityID); + if (this.entityID === null) { + this.entityID = entityID; } this.properties = Entities.getEntityProperties(this.entityID); }; diff --git a/examples/entityScripts/lightController.js b/examples/entityScripts/lightController.js index 6d6c0a59bd..ab901f567a 100644 --- a/examples/entityScripts/lightController.js +++ b/examples/entityScripts/lightController.js @@ -32,14 +32,14 @@ return JSON.parse(JSON.stringify(object)); } function didEntityExist(entityID) { - return entityID && entityID.isKnownID; + return entityID; } function doesEntityExistNow(entityID) { - return entityID && getTrueID(entityID).isKnownID; + return entityID; } function getTrueID(entityID) { var properties = Entities.getEntityProperties(entityID); - return { id: properties.id, creatorTokenID: properties.creatorTokenID, isKnownID: properties.isKnownID }; + return { id: properties.id }; } function getUserData(entityID) { var properties = Entities.getEntityProperties(entityID); @@ -225,4 +225,4 @@ this.updateRelativeLightPosition(); } }; -}) \ No newline at end of file +}) diff --git a/examples/entityScripts/movable.js b/examples/entityScripts/movable.js index 066f258f2e..b7ecfbbc8e 100644 --- a/examples/entityScripts/movable.js +++ b/examples/entityScripts/movable.js @@ -251,8 +251,8 @@ }; // All callbacks start by updating the properties this.updateProperties = function(entityID) { - if (this.entityID === null || !this.entityID.isKnownID) { - this.entityID = Entities.identifyEntity(entityID); + if (this.entityID === null) { + this.entityID = entityID; } this.properties = Entities.getEntityProperties(this.entityID); }; diff --git a/examples/entityScripts/playSoundOnClick.js b/examples/entityScripts/playSoundOnClick.js index 6c1279774b..de1e57e062 100644 --- a/examples/entityScripts/playSoundOnClick.js +++ b/examples/entityScripts/playSoundOnClick.js @@ -15,7 +15,7 @@ var bird; this.preload = function(entityID) { - print("preload("+entityID.id+")"); + print("preload("+entityID+")"); bird = SoundCache.getSound("http://s3.amazonaws.com/hifi-public/sounds/Animals/bushtit_1.raw"); }; diff --git a/examples/entityScripts/playSoundOnEnterOrLeave.js b/examples/entityScripts/playSoundOnEnterOrLeave.js index b95e35ab1d..6ef8d8ea77 100644 --- a/examples/entityScripts/playSoundOnEnterOrLeave.js +++ b/examples/entityScripts/playSoundOnEnterOrLeave.js @@ -22,17 +22,17 @@ } this.preload = function(entityID) { - print("preload("+entityID.id+")"); + print("preload("+entityID+")"); bird = SoundCache.getSound("http://s3.amazonaws.com/hifi-public/sounds/Animals/bushtit_1.raw"); }; this.enterEntity = function(entityID) { - print("enterEntity("+entityID.id+")"); + print("enterEntity("+entityID+")"); playSound(); }; this.leaveEntity = function(entityID) { - print("leaveEntity("+entityID.id+")"); + print("leaveEntity("+entityID+")"); playSound(); }; }) diff --git a/examples/entityScripts/sitOnEntity.js b/examples/entityScripts/sitOnEntity.js index d5c4fa9c52..0ba2c959a2 100644 --- a/examples/entityScripts/sitOnEntity.js +++ b/examples/entityScripts/sitOnEntity.js @@ -333,8 +333,8 @@ // All callbacks start by updating the properties this.updateProperties = function(entityID) { - if (this.entityID === null || !this.entityID.isKnownID) { - this.entityID = Entities.identifyEntity(entityID); + if (this.entityID === null) { + this.entityID = entityID; } this.properties = Entities.getEntityProperties(this.entityID); }; @@ -369,4 +369,4 @@ this.updateProperties(entityID); // All callbacks start by updating the properties }; -}) \ No newline at end of file +}) diff --git a/examples/example/entities/animatedModelExample.js b/examples/example/entities/animatedModelExample.js index 00790fecc8..af2fab05a0 100644 --- a/examples/example/entities/animatedModelExample.js +++ b/examples/example/entities/animatedModelExample.js @@ -42,7 +42,6 @@ var originalProperties = { }; var modelID = Entities.addEntity(originalProperties); -print("Entities.addEntity()... modelID.creatorTokenID = " + modelID.creatorTokenID); var isPlaying = true; var playPauseEveryWhile = 360; @@ -98,8 +97,6 @@ function moveModel(deltaTime) { count++; - //print("modelID.creatorTokenID = " + modelID.creatorTokenID); - if (somethingChanged) { var newProperties = { animationIsPlaying: isPlaying, @@ -123,7 +120,7 @@ Script.update.connect(moveModel); Script.scriptEnding.connect(function () { print("cleaning up..."); - print("modelID="+ modelID.creatorTokenID + ", id:" + modelID.id); + print("modelID=" + modelID); Models.deleteModel(modelID); }); diff --git a/examples/example/entities/butterflies.js b/examples/example/entities/butterflies.js index 9cbe8f966c..7c8cd18376 100644 --- a/examples/example/entities/butterflies.js +++ b/examples/example/entities/butterflies.js @@ -106,7 +106,7 @@ function updateButterflies(deltaTime) { var CHANCE_OF_IMPULSE = 0.04; for (var i = 0; i < numButterflies; i++) { if (Math.random() < CHANCE_OF_IMPULSE) { - if (!butterflies[i].isKnownID) { + if (!butterflies[i]) { butterflies[i] = Entities.identifyEntity(butterflies[i]); } var properties = Entities.getEntityProperties(butterflies[i]); diff --git a/examples/example/entities/editEntityExample.js b/examples/example/entities/editEntityExample.js index 96132ad471..78279cf993 100644 --- a/examples/example/entities/editEntityExample.js +++ b/examples/example/entities/editEntityExample.js @@ -71,8 +71,6 @@ function moveEntity(deltaTime) { print("count =" + count); count++; - print("entityID.creatorTokenID = " + entityID.creatorTokenID); - var newProperties = { position: { x: originalProperties.position.x + (count * positionDelta.x), diff --git a/examples/example/entities/editModelExample.js b/examples/example/entities/editModelExample.js index 2a58028521..cb8d5b39ae 100644 --- a/examples/example/entities/editModelExample.js +++ b/examples/example/entities/editModelExample.js @@ -70,8 +70,6 @@ function moveEntity(deltaTime) { print("count =" + count); count++; - print("entityID.creatorTokenID = " + entityID.creatorTokenID); - var newProperties = { position: { x: originalProperties.position.x + (count * positionDelta.x), diff --git a/examples/example/entities/findEntitiesExample.js b/examples/example/entities/findEntitiesExample.js index 01e77e1b2e..aee26fea61 100644 --- a/examples/example/entities/findEntitiesExample.js +++ b/examples/example/entities/findEntitiesExample.js @@ -38,10 +38,6 @@ var moveSearch = { x: 0.1, y: 0, z: 0.1}; var searchRadius = 1; var searchRadiusChange = 0; -print("entityA.creatorTokenID = " + entityA.creatorTokenID); -print("entityB.creatorTokenID = " + entityB.creatorTokenID); - - function scriptEnding() { print("calling Entities.deleteEntity()"); Entities.deleteEntity(entityA); @@ -77,22 +73,6 @@ function findEntities(deltaTime) { print("--------------------------"); print("iteration =" + iteration); iteration++; - - // Check to see if we've been notified of the actual identity of the entities we created - if (!entityA.isKnownID) { - var identifyA = Entities.identifyEntity(entityA); - if (identifyA.isKnownID) { - entityA = identifyA; - print(">>>> identified entityA.id = " + entityA.id); - } - } - if (!entityB.isKnownID) { - var identifyB = Entities.identifyEntity(entityB); - if (identifyB.isKnownID) { - entityB = identifyB; - print(">>>> identified entityB.id = " + entityB.id); - } - } // also check to see if we can "find" entities... print("searching for entities at:" + searchAt.x + ", " + searchAt.y + ", " + searchAt.z + " radius:" + searchRadius); diff --git a/examples/example/entities/flockingBirds.js b/examples/example/entities/flockingBirds.js index b07e7cf4bd..9bbabeaabe 100644 --- a/examples/example/entities/flockingBirds.js +++ b/examples/example/entities/flockingBirds.js @@ -177,18 +177,11 @@ function updateBirds(deltaTime) { var averagePosition = { x: 0, y: 0, z: 0}; var knownBirds = 0; for(var i =0; i < birdsInFlock; i++) { - // identifyParticle() will check to see that the particle handle we have is in sync with the domain/server - // context. If the handle is for a created particle that now has a known ID it will be updated to be a - // handle with a known ID. - birds[i].particle = Entities.identifyEntity(birds[i].particle); - - if (birds[i].particle.isKnownID) { - birds[i].properties = Entities.getEntityProperties(birds[i].particle); - if (birds[i].properties.isKnownID) { - knownBirds++; - averageVelocity = Vec3.sum(averageVelocity, birds[i].properties.velocity); - averagePosition = Vec3.sum(averagePosition, birds[i].properties.position); - } + birds[i].properties = Entities.getEntityProperties(birds[i].particle); + if (birds[i].properties) { + knownBirds++; + averageVelocity = Vec3.sum(averageVelocity, birds[i].properties.velocity); + averagePosition = Vec3.sum(averagePosition, birds[i].properties.position); } } @@ -220,7 +213,7 @@ function updateBirds(deltaTime) { birds[i].thrust = { x: 0, y: 0, z: 0 }; // assume no thrust... - if (birds[i].particle.isKnownID) { + if (birds[i].particle) { if (enableFlyTowardPoints) { // if we're flying toward clusters, and the cluster changed, and this bird is flyingToward @@ -400,7 +393,7 @@ function updateBirds(deltaTime) { for(var j =0; j < birdsInFlock; j++) { // if this is not me, and a known bird, then check our position - if (birds[i].properties.isKnownID && j != i) { + if (birds[i].properties && j != i) { var positionMe = birds[i].properties.position; var positionYou = birds[j].properties.position; var awayFromYou = Vec3.subtract(positionMe, positionYou); // vector pointing away from "you" @@ -428,7 +421,7 @@ function updateBirds(deltaTime) { // iterate all birds again, apply their thrust for(var i =0; i < birdsInFlock; i++) { - if (birds[i].particle.isKnownID) { + if (birds[i].particle) { var color; if (birds[i].gliding) { diff --git a/examples/example/entities/rideAlongWithAnEntityExample.js b/examples/example/entities/rideAlongWithAnEntityExample.js index ce09b296a3..169a85e051 100644 --- a/examples/example/entities/rideAlongWithAnEntityExample.js +++ b/examples/example/entities/rideAlongWithAnEntityExample.js @@ -29,10 +29,6 @@ function rideWithEntity(deltaTime) { if (iteration <= lengthOfRide) { // Check to see if we've been notified of the actual identity of the entities we created - if (!entityA.isKnownID) { - entityA = Entities.identifyEntity(entityA); - } - var propertiesA = Entities.getEntityProperties(entityA); var newPosition = propertiesA.position; MyAvatar.position = { x: propertiesA.position.x - 1, diff --git a/examples/example/games/billiards.js b/examples/example/games/billiards.js index 8e890515c0..5e08322c77 100644 --- a/examples/example/games/billiards.js +++ b/examples/example/games/billiards.js @@ -206,15 +206,9 @@ function keyPressEvent(event) { function cleanup() { for (var i = 0; i < tableParts.length; i++) { - if (!tableParts[i].isKnownID) { - tableParts[i] = Entities.identifyEntity(tableParts[i]); - } Entities.deleteEntity(tableParts[i]); } for (var i = 0; i < balls.length; i++) { - if (!balls[i].isKnownID) { - balls[i] = Entities.identifyEntity(balls[i]); - } Entities.deleteEntity(balls[i]); } Overlays.deleteOverlay(reticle); @@ -222,18 +216,13 @@ function cleanup() { } function update(deltaTime) { - if (!cueBall.isKnownID) { - cueBall = Entities.identifyEntity(cueBall); - } else { - // Check if cue ball has fallen off table, re-drop if so - var cueProperties = Entities.getEntityProperties(cueBall); - if (cueProperties.position.y < tableCenter.y) { - // Replace the cueball - Entities.editEntity(cueBall, { position: cuePosition } ); + // Check if cue ball has fallen off table, re-drop if so + var cueProperties = Entities.getEntityProperties(cueBall); + if (cueProperties.position.y < tableCenter.y) { + // Replace the cueball + Entities.editEntity(cueBall, { position: cuePosition } ); - } } - } function entityCollisionWithEntity(entity1, entity2, collision) { diff --git a/examples/example/games/playChess.js b/examples/example/games/playChess.js index faa32f6cda..9848c91b1f 100644 --- a/examples/example/games/playChess.js +++ b/examples/example/games/playChess.js @@ -157,7 +157,7 @@ ChessGame.Piece = (function(position, dimensions, url, rotation) { }); // Build the user data string ChessGame.Piece.prototype.buildUserDataString = function() { - if (!(ChessGame.board !== null || ChessGame.board.entity.isKnownID)) { + if (!ChessGame.board) { print("ChessGame.Piece.prototype.buildUserDataString(): Called before proper initialization, bailing."); return null; } @@ -200,9 +200,7 @@ ChessGame.scriptStarting = function() { } ChessGame.update = function() { - ChessGame.board.entity = Entities.identifyEntity(ChessGame.board.entity); - - if (ChessGame.board.entity.isKnownID && ChessGame.pieces.length == 0) { + if (ChessGame.board.entity && ChessGame.pieces.length == 0) { // Setup white pieces var isWhite = true; var row = 1; @@ -260,4 +258,4 @@ ChessGame.scriptEnding = function() { Script.scriptEnding.connect(ChessGame.scriptEnding); Script.update.connect(ChessGame.update); -ChessGame.scriptStarting(); \ No newline at end of file +ChessGame.scriptStarting(); diff --git a/examples/example/games/spaceInvadersExample.js b/examples/example/games/spaceInvadersExample.js index 80b03354ff..819cf6b774 100644 --- a/examples/example/games/spaceInvadersExample.js +++ b/examples/example/games/spaceInvadersExample.js @@ -183,8 +183,6 @@ function initializeInvaders() { modelURL: invaderModels[row].modelURL, lifetime: itemLifetimes }); - - print("invaders[row][column].creatorTokenID=" + invaders[row][column].creatorTokenID); } } } @@ -193,7 +191,7 @@ function moveInvaders() { for (var row = 0; row < numberOfRows; row++) { for (var column = 0; column < invadersPerRow; column++) { props = Entities.getEntityProperties(invaders[row][column]); - if (props.isKnownID) { + if (props.id) { invaderPosition = getInvaderPosition(row, column); Entities.editEntity(invaders[row][column], { @@ -292,7 +290,6 @@ function endGame() { } function moveShipTo(position) { - myShip = Entities.identifyEntity(myShip); Entities.editEntity(myShip, { position: position }); } @@ -303,9 +300,8 @@ function fireMissile() { // If we've fired a missile, then check to see if it's still alive if (missileFired) { var missileProperties = Entities.getEntityProperties(myMissile); - print("missileProperties.isKnownID=" + missileProperties.isKnownID); - if (!missileProperties.isKnownID) { + if (!missileProperties) { print("canFire = true"); canFire = true; } @@ -374,24 +370,21 @@ Controller.captureKeyEvents({text: " "}); function deleteIfInvader(possibleInvaderEntity) { for (var row = 0; row < numberOfRows; row++) { for (var column = 0; column < invadersPerRow; column++) { - invaders[row][column] = Entities.identifyEntity(invaders[row][column]); - if (invaders[row][column].isKnownID) { - if (invaders[row][column].id == possibleInvaderEntity.id) { - Entities.deleteEntity(possibleInvaderEntity); - Entities.deleteEntity(myMissile); + if (invaders[row][column].id && invaders[row][column].id == possibleInvaderEntity.id) { + Entities.deleteEntity(possibleInvaderEntity); + Entities.deleteEntity(myMissile); - // play the hit sound - var options = {}; - if (soundInMyHead) { - options.position = { x: MyAvatar.position.x + 0.0, - y: MyAvatar.position.y + 0.1, - z: MyAvatar.position.z + 0.0 }; - } else { - options.position = getInvaderPosition(row, column); - } - - Audio.playSound(hitSound, options); + // play the hit sound + var options = {}; + if (soundInMyHead) { + options.position = { x: MyAvatar.position.x + 0.0, + y: MyAvatar.position.y + 0.1, + z: MyAvatar.position.z + 0.0 }; + } else { + options.position = getInvaderPosition(row, column); } + + Audio.playSound(hitSound, options); } } } @@ -402,7 +395,6 @@ function entityCollisionWithEntity(entityA, entityB, collision) { Vec3.print('entityCollisionWithEntity() penetration=', collision.penetration); Vec3.print('entityCollisionWithEntity() contactPoint=', collision.contactPoint); if (missileFired) { - myMissile = Entities.identifyEntity(myMissile); if (myMissile.id == entityA.id) { deleteIfInvader(entityB); } else if (myMissile.id == entityB.id) { diff --git a/examples/harmonicOscillator.js b/examples/harmonicOscillator.js index 653c2db939..c3e0221a13 100644 --- a/examples/harmonicOscillator.js +++ b/examples/harmonicOscillator.js @@ -42,9 +42,6 @@ function randomColor() { function update(deltaTime) { time += deltaTime; - if (!ball.isKnownID) { - ball = Entities.identifyEntity(ball); - } rotation = Quat.angleAxis(time * omega /Math.PI * 180.0, { x: 0, y: 1, z: 0 }); Entities.editEntity(ball, { diff --git a/examples/html/entityList.html b/examples/html/entityList.html index 5795cc2acb..9a46efe7b5 100644 --- a/examples/html/entityList.html +++ b/examples/html/entityList.html @@ -34,7 +34,6 @@ function onRowClicked(e) { var id = this.dataset.entityId; - var selection = [this.dataset.entityId]; if (e.shiftKey) { selection = selection.concat(selectedEntities); @@ -66,7 +65,7 @@ entityList.add([{ id: id, name: name, type: type, url: filename }], function(items) { var el = items[0].elm; - var id = items[0]._values.id; + var id = items[0]._values.id; // ? entities[id] = { id: id, name: name, @@ -170,7 +169,7 @@ elEntityTable.style.display = "table"; elNoEntitiesMessage.style.display = "none"; for (var i = 0; i < newEntities.length; i++) { - var id = newEntities[i].id; + var id = newEntities[i].id; // ? addEntity(id, newEntities[i].name, newEntities[i].type, newEntities[i].url); } updateSelectedEntities(data.selectedIDs); diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index 0e3494bff8..0879e0d01b 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -358,7 +358,7 @@ var types = {}; for (var i = 0; i < selections.length; i++) { - ids.push(selections[i].id); + ids.push(selections[i].id); // ? var type = selections[i].properties.type; if (types[type] === undefined) { types[type] = 0; diff --git a/examples/libraries/entityList.js b/examples/libraries/entityList.js index e10aed4051..241ffb2766 100644 --- a/examples/libraries/entityList.js +++ b/examples/libraries/entityList.js @@ -21,7 +21,7 @@ EntityListTool = function(opts) { var selectedIDs = []; for (var i = 0; i < selectionManager.selections.length; i++) { - selectedIDs.push(selectionManager.selections[i].id); + selectedIDs.push(selectionManager.selections[i]); } data = { @@ -38,7 +38,7 @@ EntityListTool = function(opts) { var id = ids[i]; var properties = Entities.getEntityProperties(id); entities.push({ - id: id.id, + id: id, name: properties.name, type: properties.type, url: properties.type == "Model" ? properties.modelURL : "", @@ -47,7 +47,7 @@ EntityListTool = function(opts) { var selectedIDs = []; for (var i = 0; i < selectionManager.selections.length; i++) { - selectedIDs.push(selectionManager.selections[i].id); + selectedIDs.push(selectionManager.selections[i].id); // ? } var data = { @@ -64,11 +64,7 @@ EntityListTool = function(opts) { var ids = data.entityIds; var entityIDs = []; for (var i = 0; i < ids.length; i++) { - entityIDs.push({ - id: ids[i], - isKnownID: true, - creatorTokenID: 0, - }); + entityIDs.push(ids[i]); } selectionManager.setSelections(entityIDs); if (data.focus) { diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index f3ea18aef3..1cf9bf0e8f 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -19,15 +19,8 @@ SPACE_WORLD = "world"; SelectionManager = (function() { var that = {}; - var PENDING_SELECTION_CHECK_INTERVAL = 50; - that.savedProperties = {}; - that.selections = []; - // These are selections that don't have a known ID yet - that.pendingSelections = []; - var pendingSelectionTimer = null; - var listeners = []; that.localRotation = Quat.fromPitchYawRollDegrees(0, 0, 0); @@ -45,7 +38,7 @@ SelectionManager = (function() { that.savedProperties = {}; for (var i = 0; i < that.selections.length; i++) { var entityID = that.selections[i]; - that.savedProperties[entityID.id] = Entities.getEntityProperties(entityID); + that.savedProperties[entityID] = Entities.getEntityProperties(entityID); } }; @@ -61,41 +54,17 @@ SelectionManager = (function() { that.selections = []; for (var i = 0; i < entityIDs.length; i++) { var entityID = entityIDs[i]; - if (entityID.isKnownID) { - that.selections.push(entityID); - } else { - that.pendingSelections.push(entityID); - if (pendingSelectionTimer == null) { - pendingSelectionTimer = Script.setInterval(that._checkPendingSelections, PENDING_SELECTION_CHECK_INTERVAL); - } - } + that.selections.push(entityID); } that._update(); }; - that._checkPendingSelections = function() { - for (var i = 0; i < that.pendingSelections.length; i++) { - var entityID = that.pendingSelections[i]; - var newEntityID = Entities.identifyEntity(entityID); - if (newEntityID.isKnownID) { - that.pendingSelections.splice(i, 1); - that.addEntity(newEntityID); - i--; - } - } - - if (that.pendingSelections.length == 0) { - Script.clearInterval(pendingSelectionTimer); - pendingSelectionTimer = null; - } - } - that.addEntity = function(entityID, toggleSelection) { - if (entityID.isKnownID) { + if (entityID) { var idx = -1; for (var i = 0; i < that.selections.length; i++) { - if (entityID.id == that.selections[i].id) { + if (entityID == that.selections[i]) { idx = i; break; } @@ -105,14 +74,6 @@ SelectionManager = (function() { } else if (toggleSelection) { that.selections.splice(idx, 1); } - } else { - var idx = that.pendingSelections.indexOf(entityID); - if (idx == -1) { - that.pendingSelections.push(entityID); - if (pendingSelectionTimer == null) { - pendingSelectionTimer = Script.setInterval(that._checkPendingSelections, PENDING_SELECTION_CHECK_INTERVAL); - } - } } that._update(); @@ -123,24 +84,11 @@ SelectionManager = (function() { if (idx >= 0) { that.selections.splice(idx, 1); } - - var idx = that.pendingSelections.indexOf(entityID); - if (idx >= 0) { - that.pendingSelections.splice(idx, 1); - } - that._update(); }; that.clearSelections = function() { that.selections = []; - that.pendingSelections = []; - - if (pendingSelectionTimer !== null) { - Script.clearInterval(pendingSelectionTimer); - pendingSelectionTimer = null; - } - that._update(); }; @@ -1563,7 +1511,7 @@ SelectionDisplay = (function () { var wantDebug = false; for (var i = 0; i < SelectionManager.selections.length; i++) { - var properties = SelectionManager.savedProperties[SelectionManager.selections[i].id]; + var properties = SelectionManager.savedProperties[SelectionManager.selections[i]]; var newPosition = Vec3.sum(properties.position, { x: vector.x, y: 0, z: vector.z }); Entities.editEntity(SelectionManager.selections[i], { position: newPosition, @@ -1641,7 +1589,7 @@ SelectionDisplay = (function () { } for (var i = 0; i < SelectionManager.selections.length; i++) { var id = SelectionManager.selections[i]; - var properties = selectionManager.savedProperties[id.id]; + var properties = selectionManager.savedProperties[id]; var original = properties.position; var newPosition = Vec3.sum(properties.position, vector); @@ -1900,7 +1848,7 @@ SelectionDisplay = (function () { vector = change; Vec3.print("Radius stretch: ", vector); var length = vector.x + vector.y + vector.z; - var props = selectionManager.savedProperties[selectionManager.selections[0].id]; + var props = selectionManager.savedProperties[selectionManager.selections[0]]; var radius = props.dimensions.z / 2; var originalCutoff = props.cutoff; @@ -1917,7 +1865,7 @@ SelectionDisplay = (function () { }; function radiusStretchFunc(vector, change) { - var props = selectionManager.savedProperties[selectionManager.selections[0].id]; + var props = selectionManager.savedProperties[selectionManager.selections[0]]; // Find the axis being adjusted var size; @@ -2084,7 +2032,7 @@ SelectionDisplay = (function () { for (var i = 0; i < SelectionManager.selections.length; i++) { var entityID = SelectionManager.selections[i]; var properties = Entities.getEntityProperties(entityID); - var initialProperties = SelectionManager.savedProperties[entityID.id]; + var initialProperties = SelectionManager.savedProperties[entityID]; var newProperties = { rotation: Quat.multiply(yawChange, initialProperties.rotation), @@ -2211,7 +2159,7 @@ SelectionDisplay = (function () { for (var i = 0; i < SelectionManager.selections.length; i++) { var entityID = SelectionManager.selections[i]; var properties = Entities.getEntityProperties(entityID); - var initialProperties = SelectionManager.savedProperties[entityID.id]; + var initialProperties = SelectionManager.savedProperties[entityID]; var dPos = Vec3.subtract(initialProperties.position, initialPosition); dPos = Vec3.multiplyQbyV(pitchChange, dPos); @@ -2331,7 +2279,7 @@ SelectionDisplay = (function () { for (var i = 0; i < SelectionManager.selections.length; i++) { var entityID = SelectionManager.selections[i]; var properties = Entities.getEntityProperties(entityID); - var initialProperties = SelectionManager.savedProperties[entityID.id]; + var initialProperties = SelectionManager.savedProperties[entityID]; var dPos = Vec3.subtract(initialProperties.position, initialPosition); dPos = Vec3.multiplyQbyV(rollChange, dPos); diff --git a/examples/libraries/lightOverlayManager.js b/examples/libraries/lightOverlayManager.js index a140461a27..9b26cae837 100644 --- a/examples/libraries/lightOverlayManager.js +++ b/examples/libraries/lightOverlayManager.js @@ -12,17 +12,17 @@ LightOverlayManager = function() { // List of overlays not currently being used var unusedOverlays = []; - // Map from EntityItemID.id to overlay id + // Map from EntityItemID to overlay id var entityOverlays = {}; - // Map from EntityItemID.id to EntityItemID object + // Map from EntityItemID to EntityItemID object var entityIDs = {}; this.updatePositions = function(ids) { for (var id in entityIDs) { var entityID = entityIDs[id]; var properties = Entities.getEntityProperties(entityID); - Overlays.editOverlay(entityOverlays[entityID.id], { + Overlays.editOverlay(entityOverlays[entityID], { position: properties.position }); } @@ -77,10 +77,10 @@ LightOverlayManager = function() { function addEntity(entityID) { var properties = Entities.getEntityProperties(entityID); - if (properties.type == "Light" && !(entityID.id in entityOverlays)) { + if (properties.type == "Light" && !(entityID in entityOverlays)) { var overlay = getOverlay(); - entityOverlays[entityID.id] = overlay; - entityIDs[entityID.id] = entityID; + entityOverlays[entityID] = overlay; + entityIDs[entityID] = entityID; Overlays.editOverlay(overlay, { position: properties.position, url: properties.isSpotlight ? SPOT_LIGHT_URL : POINT_LIGHT_URL, @@ -94,20 +94,12 @@ LightOverlayManager = function() { } function deleteEntity(entityID) { - if (entityID.id in entityOverlays) { - releaseOverlay(entityOverlays[entityID.id]); - delete entityOverlays[entityID.id]; + if (entityID in entityOverlays) { + releaseOverlay(entityOverlays[entityID]); + delete entityOverlays[entityID]; } } - function changeEntityID(oldEntityID, newEntityID) { - entityOverlays[newEntityID.id] = entityOverlays[oldEntityID.id]; - entityIDs[newEntityID.id] = newEntityID; - - delete entityOverlays[oldEntityID.id]; - delete entityIDs[oldEntityID.id]; - } - function clearEntities() { for (var id in entityOverlays) { releaseOverlay(entityOverlays[id]); @@ -117,7 +109,6 @@ LightOverlayManager = function() { } Entities.addingEntity.connect(addEntity); - Entities.changingEntityID.connect(changeEntityID); Entities.deletingEntity.connect(deleteEntity); Entities.clearingEntities.connect(clearEntities); diff --git a/examples/sit.js b/examples/sit.js index 196a1a1972..da499b3b21 100644 --- a/examples/sit.js +++ b/examples/sit.js @@ -316,7 +316,7 @@ function addIndicators(modelID) { modelID.properties.sittingPoints[i].indicator = new SeatIndicator(modelID.properties, i); } - models[modelID.id] = modelID; + models[modelID] = modelID; } else { Entities.editEntity(modelID, { glowLevel: 0.0 }); } @@ -326,7 +326,7 @@ function removeIndicators(modelID) { for (var i = 0; i < modelID.properties.sittingPoints.length; ++i) { modelID.properties.sittingPoints[i].indicator.cleanup(); } - delete models[modelID.id]; + delete models[modelID]; } function showIndicators(doShow) { diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 37ee116f40..f91fbd46b9 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1975,7 +1975,7 @@ void Application::toggleFaceTrackerMute() { } } -bool Application::exportEntities(const QString& filename, const QVector& entityIDs) { +bool Application::exportEntities(const QString& filename, const QVector& entityIDs) { QVector entities; auto entityTree = _entities.getTree(); @@ -2006,7 +2006,7 @@ bool Application::exportEntities(const QString& filename, const QVectorgetProperties(); properties.setPosition(properties.getPosition() - root); - exportTree.addEntity(entityItem->getEntityItemID(), properties); + exportTree.addEntity(entityItem->getID(), properties); } 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++) { EntityItemProperties properties = entities.at(i)->getProperties(); - EntityItemID id = entities.at(i)->getEntityItemID(); + QUuid id = entities.at(i)->getID(); properties.setPosition(properties.getPosition() - root); exportTree.addEntity(id, properties); } @@ -2075,7 +2075,7 @@ bool Application::importEntities(const QString& urlOrFilename) { return success; } -QVector Application::pasteEntities(float x, float y, float z) { +QVector Application::pasteEntities(float x, float y, float z) { return _entityClipboard.sendEntities(&_entityEditSender, _entities.getTree(), x, y, z); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 83fc74aed4..8676be5a6e 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -383,8 +383,8 @@ public slots: void nodeKilled(SharedNodePointer node); void packetSent(quint64 length); - QVector pasteEntities(float x, float y, float z); - bool exportEntities(const QString& filename, const QVector& entityIDs); + QVector pasteEntities(float x, float y, float z); + bool exportEntities(const QString& filename, const QVector& entityIDs); bool exportEntities(const QString& filename, float x, float y, float z, float scale); bool importEntities(const QString& url); diff --git a/interface/src/DatagramProcessor.cpp b/interface/src/DatagramProcessor.cpp index 51adb7ba1a..474aaf24b5 100644 --- a/interface/src/DatagramProcessor.cpp +++ b/interface/src/DatagramProcessor.cpp @@ -83,8 +83,6 @@ void DatagramProcessor::processDatagrams() { break; } case PacketTypeEntityAddResponse: - // this will keep creatorTokenIDs to IDs mapped correctly - EntityItemID::handleAddEntityResponse(incomingPacket); application->getEntities()->getTree()->handleAddEntityResponse(incomingPacket); break; case PacketTypeEntityData: diff --git a/interface/src/scripting/ClipboardScriptingInterface.cpp b/interface/src/scripting/ClipboardScriptingInterface.cpp index f833ad43cc..adeeae74d1 100644 --- a/interface/src/scripting/ClipboardScriptingInterface.cpp +++ b/interface/src/scripting/ClipboardScriptingInterface.cpp @@ -18,7 +18,7 @@ float ClipboardScriptingInterface::getClipboardContentsLargestDimension() { return Application::getInstance()->getEntityClipboard()->getContentsLargestDimension(); } -bool ClipboardScriptingInterface::exportEntities(const QString& filename, const QVector& entityIDs) { +bool ClipboardScriptingInterface::exportEntities(const QString& filename, const QVector& entityIDs) { return Application::getInstance()->exportEntities(filename, entityIDs); } @@ -30,6 +30,6 @@ bool ClipboardScriptingInterface::importEntities(const QString& filename) { return Application::getInstance()->importEntities(filename); } -QVector ClipboardScriptingInterface::pasteEntities(glm::vec3 position) { +QVector ClipboardScriptingInterface::pasteEntities(glm::vec3 position) { return Application::getInstance()->pasteEntities(position.x, position.y, position.z); } diff --git a/interface/src/scripting/ClipboardScriptingInterface.h b/interface/src/scripting/ClipboardScriptingInterface.h index 73bebd4836..5a5fd55711 100644 --- a/interface/src/scripting/ClipboardScriptingInterface.h +++ b/interface/src/scripting/ClipboardScriptingInterface.h @@ -24,9 +24,9 @@ signals: public slots: float getClipboardContentsLargestDimension(); /// returns the largest dimension of everything on the clipboard bool importEntities(const QString& filename); - bool exportEntities(const QString& filename, const QVector& entityIDs); + bool exportEntities(const QString& filename, const QVector& entityIDs); bool exportEntities(const QString& filename, float x, float y, float z, float s); - QVector pasteEntities(glm::vec3 position); + QVector pasteEntities(glm::vec3 position); }; #endif // hifi_ClipboardScriptingInterface_h diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index bacd6eb56e..2d58307823 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -66,8 +66,8 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterf REGISTER_ENTITY_TYPE_WITH_FACTORY(Zone, RenderableZoneEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(Line, RenderableLineEntityItem::factory) - _currentHoverOverEntityID = EntityItemID::createInvalidEntityID(); // makes it the unknown ID - _currentClickingOnEntityID = EntityItemID::createInvalidEntityID(); // makes it the unknown ID + _currentHoverOverEntityID = QUuid(); // makes it the unknown ID + _currentClickingOnEntityID = QUuid(); // makes it the unknown ID } EntityTreeRenderer::~EntityTreeRenderer() { @@ -86,7 +86,7 @@ EntityTreeRenderer::~EntityTreeRenderer() { void EntityTreeRenderer::clear() { leaveAllEntities(); - foreach (const EntityItemID& entityID, _entityScripts.keys()) { + foreach (const QUuid& entityID, _entityScripts.keys()) { checkAndCallUnload(entityID); } OctreeRenderer::clear(); @@ -123,9 +123,9 @@ void EntityTreeRenderer::shutdown() { void EntityTreeRenderer::scriptContentsAvailable(const QUrl& url, const QString& scriptContents) { if (_waitingOnPreload.contains(url)) { - QList entityIDs = _waitingOnPreload.values(url); + QList entityIDs = _waitingOnPreload.values(url); _waitingOnPreload.remove(url); - foreach(EntityItemID entityID, entityIDs) { + foreach(QUuid entityID, entityIDs) { checkAndCallPreload(entityID); } } @@ -137,7 +137,7 @@ void EntityTreeRenderer::errorInLoadingScript(const QUrl& url) { } } -QScriptValue EntityTreeRenderer::loadEntityScript(const EntityItemID& entityItemID, bool isPreload) { +QScriptValue EntityTreeRenderer::loadEntityScript(const QUuid& entityItemID, bool isPreload) { EntityItem* entity = static_cast(_tree)->findEntityByEntityItemID(entityItemID); 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 // 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. - EntityItemID entityID = entity->getEntityItemID(); + QUuid entityID = entity->getID(); QString entityScript = entity->getScript(); if (_entityScripts.contains(entityID)) { @@ -282,7 +282,7 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity, bool isPre return entityScriptObject; // newly constructed } -QScriptValue EntityTreeRenderer::getPreviouslyLoadedEntityScript(const EntityItemID& entityID) { +QScriptValue EntityTreeRenderer::getPreviouslyLoadedEntityScript(const QUuid& entityID) { if (_entityScripts.contains(entityID)) { EntityScriptDetails details = _entityScripts[entityID]; 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 // 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 - if (_lastMouseEventValid && !_currentClickingOnEntityID.isInvalidID()) { + if (_lastMouseEventValid && !_currentClickingOnEntityID.isNull()) { emit holdingClickOnEntity(_currentClickingOnEntityID, _lastMouseEvent); QScriptValueList currentClickingEntityArgs = createMouseEventArgs(_currentClickingOnEntityID, _lastMouseEvent); QScriptValue currentClickingEntity = loadEntityScript(_currentClickingOnEntityID); @@ -325,7 +325,7 @@ void EntityTreeRenderer::checkEnterLeaveEntities() { if (avatarPosition != _lastAvatarPosition) { float radius = 1.0f; // for now, assume 1 meter radius QVector foundEntities; - QVector entitiesContainingAvatar; + QVector entitiesContainingAvatar; // find the entities near us _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 foreach(const EntityItem* entity, foundEntities) { if (entity->contains(avatarPosition)) { - entitiesContainingAvatar << entity->getEntityItemID(); + entitiesContainingAvatar << entity->getID(); } } _tree->unlock(); @@ -344,7 +344,7 @@ void EntityTreeRenderer::checkEnterLeaveEntities() { // 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 - foreach(const EntityItemID& entityID, _currentEntitiesInside) { + foreach(const QUuid& entityID, _currentEntitiesInside) { if (!entitiesContainingAvatar.contains(entityID)) { emit leaveEntity(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 - foreach(const EntityItemID& entityID, entitiesContainingAvatar) { + foreach(const QUuid& entityID, entitiesContainingAvatar) { if (!_currentEntitiesInside.contains(entityID)) { emit enterEntity(entityID); QScriptValueList entityArgs = createEntityArgs(entityID); @@ -377,7 +377,7 @@ void EntityTreeRenderer::leaveAllEntities() { if (_tree && !_shuttingDown) { // for all of our previous containing entities, if they are no longer containing then send them a leave event - foreach(const EntityItemID& entityID, _currentEntitiesInside) { + foreach(const QUuid& entityID, _currentEntitiesInside) { emit leaveEntity(entityID); QScriptValueList entityArgs = createEntityArgs(entityID); QScriptValue entityScript = loadEntityScript(entityID); @@ -704,7 +704,7 @@ void EntityTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) } else { // in the case of the volume being equal, we will use the // EntityItemID to deterministically pick one entity over the other - if (entityItem->getEntityItemID() < _bestZone->getEntityItemID()) { + if (entityItem->getID() < _bestZone->getID()) { _bestZoneVolume = entityVolumeEstimate; _bestZone = dynamic_cast(entityItem); } @@ -840,7 +840,7 @@ RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(cons (void**)&intersectedEntity, lockType, &result.accurate, precisionPicking); if (result.intersects && intersectedEntity) { - result.entityID = intersectedEntity->getEntityItemID(); + result.entityID = intersectedEntity->getID(); result.properties = intersectedEntity->getProperties(); result.intersection = ray.origin + (ray.direction * result.distance); result.entity = intersectedEntity; @@ -875,24 +875,24 @@ void EntityTreeRenderer::connectSignalsToSlots(EntityScriptingInterface* entityS connect(this, &EntityTreeRenderer::leaveEntity, entityScriptingInterface, &EntityScriptingInterface::leaveEntity); } -QScriptValueList EntityTreeRenderer::createMouseEventArgs(const EntityItemID& entityID, QMouseEvent* event, unsigned int deviceID) { +QScriptValueList EntityTreeRenderer::createMouseEventArgs(const QUuid& entityID, QMouseEvent* event, unsigned int deviceID) { QScriptValueList args; - args << entityID.toScriptValue(_entitiesScriptEngine); + args << quuidToScriptValue(_entitiesScriptEngine, entityID); args << MouseEvent(*event, deviceID).toScriptValue(_entitiesScriptEngine); return args; } -QScriptValueList EntityTreeRenderer::createMouseEventArgs(const EntityItemID& entityID, const MouseEvent& mouseEvent) { +QScriptValueList EntityTreeRenderer::createMouseEventArgs(const QUuid& entityID, const MouseEvent& mouseEvent) { QScriptValueList args; - args << entityID.toScriptValue(_entitiesScriptEngine); + args << quuidToScriptValue(_entitiesScriptEngine, entityID); args << mouseEvent.toScriptValue(_entitiesScriptEngine); return args; } -QScriptValueList EntityTreeRenderer::createEntityArgs(const EntityItemID& entityID) { +QScriptValueList EntityTreeRenderer::createEntityArgs(const QUuid& entityID) { QScriptValueList args; - args << entityID.toScriptValue(_entitiesScriptEngine); + args << quuidToScriptValue(_entitiesScriptEngine, entityID); 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 // we're releasing the button, then this is considered a clickOn event - if (!_currentClickingOnEntityID.isInvalidID()) { + if (!_currentClickingOnEntityID.isNull()) { emit clickReleaseOnEntity(_currentClickingOnEntityID, MouseEvent(*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 - _currentClickingOnEntityID = EntityItemID::createInvalidEntityID(); + _currentClickingOnEntityID = QUuid(); _lastMouseEvent = MouseEvent(*event, deviceID); _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 // then we need to send the hover leave. - if (!_currentHoverOverEntityID.isInvalidID() && rayPickResult.entityID != _currentHoverOverEntityID) { + if (!_currentHoverOverEntityID.isNull() && rayPickResult.entityID != _currentHoverOverEntityID) { emit hoverLeaveEntity(_currentHoverOverEntityID, MouseEvent(*event, deviceID)); QScriptValueList currentHoverEntityArgs = createMouseEventArgs(_currentHoverOverEntityID, event, deviceID); @@ -1031,7 +1031,7 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI // 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 // send the hover leave for our previous entity - if (!_currentHoverOverEntityID.isInvalidID()) { + if (!_currentHoverOverEntityID.isNull()) { emit hoverLeaveEntity(_currentHoverOverEntityID, MouseEvent(*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); } - _currentHoverOverEntityID = EntityItemID::createInvalidEntityID(); // makes it the unknown ID + _currentHoverOverEntityID = QUuid(); // 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 // not yet released the hold then this is still considered a holdingClickOnEntity event - if (!_currentClickingOnEntityID.isInvalidID()) { + if (!_currentClickingOnEntityID.isNull()) { emit holdingClickOnEntity(_currentClickingOnEntityID, MouseEvent(*event, deviceID)); QScriptValueList currentClickingEntityArgs = createMouseEventArgs(_currentClickingOnEntityID, event, deviceID); @@ -1061,25 +1061,25 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI _lastMouseEventValid = true; } -void EntityTreeRenderer::deletingEntity(const EntityItemID& entityID) { +void EntityTreeRenderer::deletingEntity(const QUuid& entityID) { if (_tree && !_shuttingDown) { checkAndCallUnload(entityID); } _entityScripts.remove(entityID); } -void EntityTreeRenderer::addingEntity(const EntityItemID& entityID) { +void EntityTreeRenderer::addingEntity(const QUuid& entityID) { checkAndCallPreload(entityID); } -void EntityTreeRenderer::entitySciptChanging(const EntityItemID& entityID) { +void EntityTreeRenderer::entitySciptChanging(const QUuid& entityID) { if (_tree && !_shuttingDown) { checkAndCallUnload(entityID); checkAndCallPreload(entityID); } } -void EntityTreeRenderer::checkAndCallPreload(const EntityItemID& entityID) { +void EntityTreeRenderer::checkAndCallPreload(const QUuid& entityID) { if (_tree && !_shuttingDown) { // load the entity script if needed... QScriptValue entityScript = loadEntityScript(entityID, true); // is preload! @@ -1090,7 +1090,7 @@ void EntityTreeRenderer::checkAndCallPreload(const EntityItemID& entityID) { } } -void EntityTreeRenderer::checkAndCallUnload(const EntityItemID& entityID) { +void EntityTreeRenderer::checkAndCallUnload(const QUuid& entityID) { if (_tree && !_shuttingDown) { QScriptValue entityScript = getPreviouslyLoadedEntityScript(entityID); if (entityScript.property("unload").isValid()) { @@ -1101,7 +1101,7 @@ void EntityTreeRenderer::checkAndCallUnload(const EntityItemID& entityID) { } -void EntityTreeRenderer::changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID) { +void EntityTreeRenderer::changingEntityID(const QUuid& oldEntityID, const QUuid& newEntityID) { if (_entityScripts.contains(oldEntityID)) { EntityScriptDetails details = _entityScripts[oldEntityID]; _entityScripts.remove(oldEntityID); @@ -1109,7 +1109,8 @@ void EntityTreeRenderer::changingEntityID(const EntityItemID& oldEntityID, const } } -void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityTree* entityTree, const EntityItemID& id, const Collision& collision) { +void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityTree* entityTree, + const QUuid& id, const Collision& collision) { EntityItem* entity = entityTree->findEntityByEntityItemID(id); if (!entity) { return; @@ -1167,8 +1168,8 @@ void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityT injectorThread->start(); } -void EntityTreeRenderer::entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, - const Collision& collision) { +void EntityTreeRenderer::entityCollisionWithEntity(const QUuid& idA, const QUuid& idB, + const Collision& collision) { // If we don't have a tree, or we're in the process of shutting down, then don't // process these events. if (!_tree || _shuttingDown) { @@ -1198,8 +1199,8 @@ void EntityTreeRenderer::entityCollisionWithEntity(const EntityItemID& idA, cons QScriptValue entityScriptA = loadEntityScript(idA); if (entityScriptA.property("collisionWithEntity").isValid()) { QScriptValueList args; - args << idA.toScriptValue(_entitiesScriptEngine); - args << idB.toScriptValue(_entitiesScriptEngine); + args << quuidToScriptValue(_entitiesScriptEngine, idA); + args << quuidToScriptValue(_entitiesScriptEngine, idB); args << collisionToScriptValue(_entitiesScriptEngine, collision); entityScriptA.property("collisionWithEntity").call(entityScriptA, args); } @@ -1207,8 +1208,8 @@ void EntityTreeRenderer::entityCollisionWithEntity(const EntityItemID& idA, cons QScriptValue entityScriptB = loadEntityScript(idB); if (entityScriptB.property("collisionWithEntity").isValid()) { QScriptValueList args; - args << idB.toScriptValue(_entitiesScriptEngine); - args << idA.toScriptValue(_entitiesScriptEngine); + args << quuidToScriptValue(_entitiesScriptEngine, idA); + args << quuidToScriptValue(_entitiesScriptEngine, idB); args << collisionToScriptValue(_entitiesScriptEngine, collision); entityScriptB.property("collisionWithEntity").call(entityScriptA, args); } diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index 9768d4a20a..8ca7fff2dd 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -97,23 +97,23 @@ signals: void mouseMoveOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId); void mouseReleaseOnEntity(const RayToEntityIntersectionResult& entityItemID, const QMouseEvent* event, unsigned int deviceId); - void clickDownOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); - void holdingClickOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); - void clickReleaseOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); + void clickDownOnEntity(const QUuid& entityItemID, const MouseEvent& event); + void holdingClickOnEntity(const QUuid& entityItemID, const MouseEvent& event); + void clickReleaseOnEntity(const QUuid& entityItemID, const MouseEvent& event); - void hoverEnterEntity(const EntityItemID& entityItemID, const MouseEvent& event); - void hoverOverEntity(const EntityItemID& entityItemID, const MouseEvent& event); - void hoverLeaveEntity(const EntityItemID& entityItemID, const MouseEvent& event); + void hoverEnterEntity(const QUuid& entityItemID, const MouseEvent& event); + void hoverOverEntity(const QUuid& entityItemID, const MouseEvent& event); + void hoverLeaveEntity(const QUuid& entityItemID, const MouseEvent& event); - void enterEntity(const EntityItemID& entityItemID); - void leaveEntity(const EntityItemID& entityItemID); + void enterEntity(const QUuid& entityItemID); + void leaveEntity(const QUuid& entityItemID); public slots: - void addingEntity(const EntityItemID& entityID); - void deletingEntity(const EntityItemID& entityID); - void changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID); - void entitySciptChanging(const EntityItemID& entityID); - void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); + void addingEntity(const QUuid& entityID); + void deletingEntity(const QUuid& entityID); + void changingEntityID(const QUuid& oldEntityID, const QUuid& newEntityID); + void entitySciptChanging(const QUuid& entityID); + void entityCollisionWithEntity(const QUuid& idA, const QUuid& idB, const Collision& collision); // optional slots that can be wired to menu items void setDisplayElementChildProxies(bool value) { _displayElementChildProxies = value; } @@ -126,37 +126,37 @@ protected: private: void renderElementProxy(EntityTreeElement* entityTreeElement); - void checkAndCallPreload(const EntityItemID& entityID); - void checkAndCallUnload(const EntityItemID& entityID); + void checkAndCallPreload(const QUuid& entityID); + void checkAndCallUnload(const QUuid& entityID); QList _releasedModels; void renderProxies(const EntityItem* entity, RenderArgs* args); RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, bool precisionPicking); - EntityItemID _currentHoverOverEntityID; - EntityItemID _currentClickingOnEntityID; + QUuid _currentHoverOverEntityID; + QUuid _currentClickingOnEntityID; - QScriptValueList createEntityArgs(const EntityItemID& entityID); + QScriptValueList createEntityArgs(const QUuid& entityID); void checkEnterLeaveEntities(); void leaveAllEntities(); glm::vec3 _lastAvatarPosition; - QVector _currentEntitiesInside; + QVector _currentEntitiesInside; bool _wantScripts; ScriptEngine* _entitiesScriptEngine; ScriptEngine* _sandboxScriptEngine; QScriptValue loadEntityScript(EntityItem* entity, bool isPreload = false); - QScriptValue loadEntityScript(const EntityItemID& entityItemID, bool isPreload = false); - QScriptValue getPreviouslyLoadedEntityScript(const EntityItemID& entityItemID); + QScriptValue loadEntityScript(const QUuid& entityItemID, bool isPreload = false); + QScriptValue getPreviouslyLoadedEntityScript(const QUuid& entityItemID); QString loadScriptContents(const QString& scriptMaybeURLorText, bool& isURL, bool& isPending, QUrl& url); - QScriptValueList createMouseEventArgs(const EntityItemID& entityID, QMouseEvent* event, unsigned int deviceID); - QScriptValueList createMouseEventArgs(const EntityItemID& entityID, const MouseEvent& mouseEvent); + QScriptValueList createMouseEventArgs(const QUuid& entityID, QMouseEvent* event, unsigned int deviceID); + QScriptValueList createMouseEventArgs(const QUuid& entityID, const MouseEvent& mouseEvent); - QHash _entityScripts; + QHash _entityScripts; - void playEntityCollisionSound(const QUuid& myNodeID, EntityTree* entityTree, const EntityItemID& id, const Collision& collision); + void playEntityCollisionSound(const QUuid& myNodeID, EntityTree* entityTree, const QUuid& id, const Collision& collision); AbstractAudioInterface* _localAudioInterface; // So we can render collision sounds bool _lastMouseEventValid; @@ -170,7 +170,7 @@ private: bool _shuttingDown = false; - QMultiMap _waitingOnPreload; + QMultiMap _waitingOnPreload; bool _hasPreviousZone = false; const ZoneEntityItem* _bestZone; diff --git a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp index 13df04e2e7..063249c775 100644 --- a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp @@ -18,7 +18,7 @@ #include "RenderableBoxEntityItem.h" -EntityItem* RenderableBoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* RenderableBoxEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { return new RenderableBoxEntityItem(entityID, properties); } diff --git a/libraries/entities-renderer/src/RenderableBoxEntityItem.h b/libraries/entities-renderer/src/RenderableBoxEntityItem.h index cda725056c..7bdf9ab6f2 100644 --- a/libraries/entities-renderer/src/RenderableBoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderableBoxEntityItem.h @@ -17,9 +17,9 @@ class RenderableBoxEntityItem : public BoxEntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - RenderableBoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : + RenderableBoxEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : BoxEntityItem(entityItemID, properties) { } diff --git a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp index 838c9fd8c4..1874ceecc1 100644 --- a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp @@ -19,7 +19,7 @@ #include "RenderableLightEntityItem.h" -EntityItem* RenderableLightEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* RenderableLightEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { return new RenderableLightEntityItem(entityID, properties); } diff --git a/libraries/entities-renderer/src/RenderableLightEntityItem.h b/libraries/entities-renderer/src/RenderableLightEntityItem.h index cfafb85983..53c3b61c6d 100644 --- a/libraries/entities-renderer/src/RenderableLightEntityItem.h +++ b/libraries/entities-renderer/src/RenderableLightEntityItem.h @@ -16,9 +16,9 @@ class RenderableLightEntityItem : public LightEntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - RenderableLightEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : + RenderableLightEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : LightEntityItem(entityItemID, properties) { } diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 14628d0a7a..e03e91182b 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -18,7 +18,7 @@ #include "RenderableLineEntityItem.h" -EntityItem* RenderableLineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* RenderableLineEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { return new RenderableLineEntityItem(entityID, properties); } diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.h b/libraries/entities-renderer/src/RenderableLineEntityItem.h index 0de7cd43ae..f77954800a 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.h +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.h @@ -17,9 +17,9 @@ class RenderableLineEntityItem : public LineEntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - RenderableLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : + RenderableLineEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : LineEntityItem(entityItemID, properties) { } virtual void render(RenderArgs* args); diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 43112d7d73..175b5847e0 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -23,7 +23,7 @@ #include "EntitiesRendererLogging.h" #include "RenderableModelEntityItem.h" -EntityItem* RenderableModelEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* RenderableModelEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { return new RenderableModelEntityItem(entityID, properties); } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index efd60faedc..ff26451fe8 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -23,9 +23,9 @@ class EntityTreeRenderer; class RenderableModelEntityItem : public ModelEntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - RenderableModelEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : + RenderableModelEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : ModelEntityItem(entityItemID, properties), _model(NULL), _needsInitialSimulation(true), diff --git a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp index 009d26481a..3848542d25 100644 --- a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp @@ -20,11 +20,12 @@ #include "RenderableParticleEffectEntityItem.h" -EntityItem* RenderableParticleEffectEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* RenderableParticleEffectEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { return new RenderableParticleEffectEntityItem(entityID, properties); } -RenderableParticleEffectEntityItem::RenderableParticleEffectEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : +RenderableParticleEffectEntityItem::RenderableParticleEffectEntityItem(const QUuid& entityItemID, + const EntityItemProperties& properties) : ParticleEffectEntityItem(entityItemID, properties) { _cacheID = DependencyManager::get()->allocateID(); } diff --git a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h index 25bbe5c147..61bc2e1578 100644 --- a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h +++ b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h @@ -16,8 +16,8 @@ class RenderableParticleEffectEntityItem : public ParticleEffectEntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); - RenderableParticleEffectEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); + RenderableParticleEffectEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); virtual void render(RenderArgs* args); void renderUntexturedQuads(RenderArgs* args); diff --git a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp index 083a34c02f..9e36278fb1 100644 --- a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp @@ -19,7 +19,7 @@ #include "RenderableSphereEntityItem.h" -EntityItem* RenderableSphereEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* RenderableSphereEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { return new RenderableSphereEntityItem(entityID, properties); } diff --git a/libraries/entities-renderer/src/RenderableSphereEntityItem.h b/libraries/entities-renderer/src/RenderableSphereEntityItem.h index 3ed651b0ae..adb3e706a7 100644 --- a/libraries/entities-renderer/src/RenderableSphereEntityItem.h +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.h @@ -16,9 +16,9 @@ class RenderableSphereEntityItem : public SphereEntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - RenderableSphereEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : + RenderableSphereEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : SphereEntityItem(entityItemID, properties) { } diff --git a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp index 895b2f9b54..ea3f6a7d8f 100644 --- a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp @@ -23,7 +23,7 @@ const int FIXED_FONT_POINT_SIZE = 40; -EntityItem* RenderableTextEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* RenderableTextEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { return new RenderableTextEntityItem(entityID, properties); } @@ -37,7 +37,7 @@ void RenderableTextEntityItem::render(RenderArgs* args) { float leftMargin = 0.1f; float topMargin = 0.1f; - //qCDebug(entitytree) << "RenderableTextEntityItem::render() id:" << getEntityItemID() << "text:" << getText(); + //qCDebug(entitytree) << "RenderableTextEntityItem::render() id:" << getID() << "text:" << getText(); glPushMatrix(); { diff --git a/libraries/entities-renderer/src/RenderableTextEntityItem.h b/libraries/entities-renderer/src/RenderableTextEntityItem.h index e57ab0538a..2f7115b83f 100644 --- a/libraries/entities-renderer/src/RenderableTextEntityItem.h +++ b/libraries/entities-renderer/src/RenderableTextEntityItem.h @@ -16,9 +16,9 @@ class RenderableTextEntityItem : public TextEntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - RenderableTextEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : + RenderableTextEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : TextEntityItem(entityItemID, properties) { } diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index 3afd930ab0..1a673c3dba 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -29,11 +29,11 @@ const int FIXED_FONT_POINT_SIZE = 40; const float DPI = 30.47; const float METERS_TO_INCHES = 39.3701; -EntityItem* RenderableWebEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* RenderableWebEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { return new RenderableWebEntityItem(entityID, properties); } -RenderableWebEntityItem::RenderableWebEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : +RenderableWebEntityItem::RenderableWebEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : WebEntityItem(entityItemID, properties) { qDebug() << "Created web entity " << getID(); } @@ -99,7 +99,7 @@ void RenderableWebEntityItem::render(RenderArgs* args) { return; } - if (intersection.entityID.id == getID()) { + if (intersection.entityID == getID()) { if (event->button() == Qt::MouseButton::RightButton) { if (event->type() == QEvent::MouseButtonRelease) { AbstractViewStateInterface::instance()->postLambdaEvent([this] { diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.h b/libraries/entities-renderer/src/RenderableWebEntityItem.h index cf63d7915e..fa8d4d5bfd 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.h +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.h @@ -17,9 +17,9 @@ class OffscreenQmlSurface; class RenderableWebEntityItem : public WebEntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - RenderableWebEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); + RenderableWebEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); ~RenderableWebEntityItem(); virtual void render(RenderArgs* args); diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index d9bc0f0b4a..c46f7c63ae 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -16,7 +16,7 @@ #include #include -EntityItem* RenderableZoneEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* RenderableZoneEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { return new RenderableZoneEntityItem(entityID, properties); } diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h index 90a16a8a9f..ea444faeae 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.h +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.h @@ -19,9 +19,9 @@ class NetworkGeometry; class RenderableZoneEntityItem : public ZoneEntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - RenderableZoneEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : + RenderableZoneEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : ZoneEntityItem(entityItemID, properties), _model(NULL), _needsInitialSimulation(true) diff --git a/libraries/entities/src/AddEntityOperator.cpp b/libraries/entities/src/AddEntityOperator.cpp index 09aa6af0cb..264babe725 100644 --- a/libraries/entities/src/AddEntityOperator.cpp +++ b/libraries/entities/src/AddEntityOperator.cpp @@ -46,7 +46,7 @@ bool AddEntityOperator::preRecursion(OctreeElement* element) { if (entityTreeElement->bestFitBounds(_newEntityBox)) { entityTreeElement->addEntityItem(_newEntity); - _tree->setContainingElement(_newEntity->getEntityItemID(), entityTreeElement); + _tree->setContainingElement(_newEntity->getID(), entityTreeElement); _foundNew = true; keepSearching = false; diff --git a/libraries/entities/src/BoxEntityItem.cpp b/libraries/entities/src/BoxEntityItem.cpp index fab48ae777..b6cb2f97d7 100644 --- a/libraries/entities/src/BoxEntityItem.cpp +++ b/libraries/entities/src/BoxEntityItem.cpp @@ -20,12 +20,12 @@ #include "EntityTreeElement.h" -EntityItem* BoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* BoxEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* result = new BoxEntityItem(entityID, properties); return result; } -BoxEntityItem::BoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : +BoxEntityItem::BoxEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) { _type = EntityTypes::Box; @@ -99,7 +99,7 @@ void BoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitst void BoxEntityItem::debugDump() const { quint64 now = usecTimestampNow(); - qCDebug(entities) << " BOX EntityItem id:" << getEntityItemID() << "---------------------------------------------"; + qCDebug(entities) << " BOX EntityItem id:" << getID() << "---------------------------------------------"; qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; qCDebug(entities) << " position:" << debugTreeVector(_position); qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); diff --git a/libraries/entities/src/BoxEntityItem.h b/libraries/entities/src/BoxEntityItem.h index e8459e7dbb..8b9f222bcb 100644 --- a/libraries/entities/src/BoxEntityItem.h +++ b/libraries/entities/src/BoxEntityItem.h @@ -16,9 +16,9 @@ class BoxEntityItem : public EntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - BoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); + BoxEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); ALLOW_INSTANTIATION // This class can be instantiated diff --git a/libraries/entities/src/DeleteEntityOperator.cpp b/libraries/entities/src/DeleteEntityOperator.cpp index 1d1be55a9b..d173222c72 100644 --- a/libraries/entities/src/DeleteEntityOperator.cpp +++ b/libraries/entities/src/DeleteEntityOperator.cpp @@ -16,7 +16,7 @@ #include "EntitiesLogging.h" #include "DeleteEntityOperator.h" -DeleteEntityOperator::DeleteEntityOperator(EntityTree* tree, const EntityItemID& searchEntityID) : +DeleteEntityOperator::DeleteEntityOperator(EntityTree* tree, const QUuid& searchEntityID) : _tree(tree), _changeTime(usecTimestampNow()), _foundCount(0), @@ -36,7 +36,7 @@ DeleteEntityOperator::DeleteEntityOperator(EntityTree* tree) : { } -void DeleteEntityOperator::addEntityIDToDeleteList(const EntityItemID& searchEntityID) { +void DeleteEntityOperator::addEntityIDToDeleteList(const QUuid& searchEntityID) { // check our tree, to determine if this entity is known EntityToDeleteDetails details; details.containingElement = _tree->getContainingElement(searchEntityID); @@ -95,7 +95,7 @@ bool DeleteEntityOperator::preRecursion(OctreeElement* element) { EntityItem* theEntity = details.entity; bool entityDeleted = entityTreeElement->removeEntityItem(theEntity); // remove it from the element assert(entityDeleted); - _tree->setContainingElement(details.entity->getEntityItemID(), NULL); // update or id to element lookup + _tree->setContainingElement(details.entity->getID(), NULL); // update or id to element lookup _foundCount++; } } diff --git a/libraries/entities/src/DeleteEntityOperator.h b/libraries/entities/src/DeleteEntityOperator.h index b6e6f9e2ff..a78749ac99 100644 --- a/libraries/entities/src/DeleteEntityOperator.h +++ b/libraries/entities/src/DeleteEntityOperator.h @@ -22,20 +22,20 @@ public: typedef QSet RemovedEntities; inline uint qHash(const EntityToDeleteDetails& a, uint seed) { - return qHash(a.entity->getEntityItemID(), seed); + return qHash(a.entity->getID(), seed); } inline bool operator==(const EntityToDeleteDetails& a, const EntityToDeleteDetails& b) { - return a.entity->getEntityItemID() == b.entity->getEntityItemID(); + return a.entity->getID() == b.entity->getID(); } class DeleteEntityOperator : public RecurseOctreeOperator { public: DeleteEntityOperator(EntityTree* tree); - DeleteEntityOperator(EntityTree* tree, const EntityItemID& searchEntityID); + DeleteEntityOperator(EntityTree* tree, const QUuid& searchEntityID); ~DeleteEntityOperator(); - void addEntityIDToDeleteList(const EntityItemID& searchEntityID); + void addEntityIDToDeleteList(const QUuid& searchEntityID); virtual bool preRecursion(OctreeElement* element); virtual bool postRecursion(OctreeElement* element); diff --git a/libraries/entities/src/EntityEditPacketSender.cpp b/libraries/entities/src/EntityEditPacketSender.cpp index e94725782d..c95e533410 100644 --- a/libraries/entities/src/EntityEditPacketSender.cpp +++ b/libraries/entities/src/EntityEditPacketSender.cpp @@ -26,8 +26,8 @@ void EntityEditPacketSender::adjustEditPacketForClockSkew(PacketType type, } } -void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemID modelID, - const EntityItemProperties& properties) { +void EntityEditPacketSender::queueEditEntityMessage(PacketType type, QUuid modelID, + const EntityItemProperties& properties) { if (!_shouldSend) { return; // bail early } @@ -46,7 +46,7 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemI } } -void EntityEditPacketSender::queueEraseEntityMessage(const EntityItemID& entityItemID) { +void EntityEditPacketSender::queueEraseEntityMessage(const QUuid& entityItemID) { if (!_shouldSend) { return; // bail early } diff --git a/libraries/entities/src/EntityEditPacketSender.h b/libraries/entities/src/EntityEditPacketSender.h index 69171ae16b..8391a7e344 100644 --- a/libraries/entities/src/EntityEditPacketSender.h +++ b/libraries/entities/src/EntityEditPacketSender.h @@ -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 case up to MaxPendingMessages will be buffered and processed when voxel servers are known. /// NOTE: EntityItemProperties assumes that all distances are in meter units - void queueEditEntityMessage(PacketType type, EntityItemID modelID, const EntityItemProperties& properties); + void queueEditEntityMessage(PacketType type, QUuid modelID, const EntityItemProperties& properties); - void queueEraseEntityMessage(const EntityItemID& entityItemID); + void queueEraseEntityMessage(const QUuid& entityItemID); // My server type is the model server virtual char getMyNodeType() const { return NodeType::EntityServer; } diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 874dc079ca..820f498269 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -28,11 +28,9 @@ bool EntityItem::_sendPhysicsUpdates = true; -EntityItem::EntityItem(const EntityItemID& entityItemID) : +EntityItem::EntityItem(const QUuid& entityItemID) : _type(EntityTypes::Unknown), - _id(entityItemID.id), - _creatorTokenID(entityItemID.creatorTokenID), - _newlyCreated(false), + _id(entityItemID), _lastSimulated(0), _lastUpdated(0), _lastEdited(0), @@ -78,7 +76,7 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) : _lastUpdated = now; } -EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) +EntityItem::EntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) { setProperties(properties); } @@ -158,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, // then our entityTreeElementExtraEncodeData should include data about which properties we need to append. - if (entityTreeElementExtraEncodeData && entityTreeElementExtraEncodeData->entities.contains(getEntityItemID())) { - requestedProperties = entityTreeElementExtraEncodeData->entities.value(getEntityItemID()); + if (entityTreeElementExtraEncodeData && entityTreeElementExtraEncodeData->entities.contains(getID())) { + requestedProperties = entityTreeElementExtraEncodeData->entities.value(getID()); } LevelDetails entityLevel = packetData->startLevel(); @@ -169,7 +167,7 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet #ifdef WANT_DEBUG float editedAgo = getEditedAgo(); QString agoAsString = formatSecondsElapsed(editedAgo); - qCDebug(entities) << "Writing entity " << getEntityItemID() << " to buffer, lastEdited =" << lastEdited + qCDebug(entities) << "Writing entity " << getID() << " to buffer, lastEdited =" << lastEdited << " ago=" << editedAgo << "seconds - " << agoAsString; #endif @@ -286,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 (appendState != OctreeElement::COMPLETED) { // add this item into our list for the next appendElementData() pass - entityTreeElementExtraEncodeData->entities.insert(getEntityItemID(), propertiesDidntFit); + entityTreeElementExtraEncodeData->entities.insert(getID(), propertiesDidntFit); } return appendState; @@ -310,16 +308,6 @@ int EntityItem::expectedBytes() { 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. glm::vec3 savePosition = _position; glm::quat saveRotation = _rotation; @@ -351,8 +339,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // id QByteArray encodedID = originalDataBuffer.mid(bytesRead, NUM_BYTES_RFC4122_UUID); // maximum possible size _id = QUuid::fromRfc4122(encodedID); - _creatorTokenID = UNKNOWN_ENTITY_TOKEN; // if we know the id, then we don't care about the creator token - _newlyCreated = false; dataAt += encodedID.size(); bytesRead += encodedID.size(); @@ -389,7 +375,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef QString agoAsString = formatSecondsElapsed(editedAgo); QString ageAsString = formatSecondsElapsed(getAge()); qCDebug(entities) << "------------------------------------------"; - qCDebug(entities) << "Loading entity " << getEntityItemID() << " from buffer..."; + qCDebug(entities) << "Loading entity " << getID() << " from buffer..."; qCDebug(entities) << "------------------------------------------"; debugDump(); qCDebug(entities) << "------------------------------------------"; @@ -416,7 +402,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef #ifdef WANT_DEBUG qCDebug(entities) << "data from server **************** "; - qCDebug(entities) << " entityItemID:" << getEntityItemID(); + qCDebug(entities) << " entityItemID:" << getID(); qCDebug(entities) << " now:" << now; qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); qCDebug(entities) << " lastEditedFromBuffer:" << debugTime(lastEditedFromBuffer, now); @@ -506,7 +492,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef #ifdef WANT_DEBUG if (overwriteLocalData) { - qCDebug(entities) << "EntityItem::readEntityDataFromBuffer()... changed entity:" << getEntityItemID(); + qCDebug(entities) << "EntityItem::readEntityDataFromBuffer()... changed entity:" << getID(); qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); qCDebug(entities) << " getLastSimulated:" << debugTime(getLastSimulated(), now); qCDebug(entities) << " getLastUpdated:" << debugTime(getLastUpdated(), now); @@ -640,7 +626,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef } void EntityItem::debugDump() const { - qCDebug(entities) << "EntityItem id:" << getEntityItemID(); + qCDebug(entities) << "EntityItem id:" << getID(); qCDebug(entities, " edited ago:%f", getEditedAgo()); qCDebug(entities, " position:%f,%f,%f", _position.x, _position.y, _position.z); qCDebug(entities) << " dimensions:" << _dimensions; @@ -714,7 +700,7 @@ void EntityItem::simulate(const quint64& now) { #ifdef WANT_DEBUG qCDebug(entities) << "********** EntityItem::simulate()"; - qCDebug(entities) << " entity ID=" << getEntityItemID(); + qCDebug(entities) << " entity ID=" << getID(); qCDebug(entities) << " simulator ID=" << getSimulatorID(); qCDebug(entities) << " now=" << now; qCDebug(entities) << " _lastSimulated=" << _lastSimulated; diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index e49efb1329..18723af8b1 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -23,7 +23,6 @@ #include #include -#include "EntityItemID.h" #include "EntityItemProperties.h" #include "EntityItemPropertiesDefaults.h" #include "EntityTypes.h" @@ -89,18 +88,13 @@ public: DONT_ALLOW_INSTANTIATION // This class can not be instantiated directly - EntityItem(const EntityItemID& entityItemID); - EntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); + EntityItem(const QUuid& entityItemID); + EntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); virtual ~EntityItem(); // ID and EntityItemID related methods const QUuid& getID() const { return _id; } void setID(const QUuid& id) { _id = id; } - uint32_t getCreatorTokenID() const { return _creatorTokenID; } - void setCreatorTokenID(uint32_t creatorTokenID) { _creatorTokenID = creatorTokenID; } - bool isNewlyCreated() const { return _newlyCreated; } - bool isKnownID() const { return getID() != UNKNOWN_ENTITY_ID; } - EntityItemID getEntityItemID() const { return EntityItemID(getID(), getCreatorTokenID(), getID() != UNKNOWN_ENTITY_ID); } // methods for getting/setting all properties of an entity virtual EntityItemProperties getProperties() const; @@ -144,8 +138,8 @@ public: int& propertyCount, OctreeElement::AppendState& appendState) const { /* do nothing*/ }; - static EntityItemID readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead, - ReadBitstreamToTreeParams& args); + static QUuid readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead, + ReadBitstreamToTreeParams& args); virtual int readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args); @@ -356,8 +350,6 @@ protected: static bool _sendPhysicsUpdates; EntityTypes::EntityType _type; QUuid _id; - uint32_t _creatorTokenID; - bool _newlyCreated; quint64 _lastSimulated; // last time this entity called simulate(), this includes velocity, angular velocity, and physics changes quint64 _lastUpdated; // last time this entity called update(), this includes animations and non-physics changes quint64 _lastEdited; // last official local or remote edit time diff --git a/libraries/entities/src/EntityItemID.cpp b/libraries/entities/src/EntityItemID.cpp deleted file mode 100644 index cd2202eead..0000000000 --- a/libraries/entities/src/EntityItemID.cpp +++ /dev/null @@ -1,143 +0,0 @@ -// -// 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 -#include - -#include - -#include "EntityItemID.h" - -// for locally created models -QHash EntityItemID::_tokenIDsToIDs; -uint32_t EntityItemID::_nextCreatorTokenID = 0; - -EntityItemID::EntityItemID() : - id(NEW_ENTITY), - creatorTokenID(UNKNOWN_ENTITY_TOKEN), - isKnownID(false) -{ -} - -EntityItemID::EntityItemID(const EntityItemID& other) : - id(other.id), - creatorTokenID(other.creatorTokenID), - isKnownID(other.isKnownID) -{ -} - - -EntityItemID::EntityItemID(const QUuid& id, uint32_t creatorTokenID, bool isKnownID) : - id(id), - creatorTokenID(creatorTokenID), - isKnownID(isKnownID) -{ -}; - -EntityItemID::EntityItemID(const QUuid& id) : - id(id), - creatorTokenID(UNKNOWN_ENTITY_TOKEN), - isKnownID(true) -{ -}; - -EntityItemID EntityItemID::getIDfromCreatorTokenID(uint32_t creatorTokenID) { - if (_tokenIDsToIDs.find(creatorTokenID) != _tokenIDsToIDs.end()) { - return EntityItemID(_tokenIDsToIDs[creatorTokenID], creatorTokenID, true); - } - return EntityItemID(UNKNOWN_ENTITY_ID); -} - -uint32_t EntityItemID::getNextCreatorTokenID() { - uint32_t creatorTokenID = _nextCreatorTokenID; - _nextCreatorTokenID++; - return creatorTokenID; -} - -EntityItemID EntityItemID::assignActualIDForToken() const { - EntityItemID newlyAssignedEntityID; - - newlyAssignedEntityID.creatorTokenID = creatorTokenID; - newlyAssignedEntityID.isKnownID = true; - newlyAssignedEntityID.id = QUuid::createUuid(); - - return newlyAssignedEntityID; -} - -EntityItemID EntityItemID::convertToKnownIDVersion() const { - EntityItemID knownIDVersionEntityID; - - knownIDVersionEntityID.creatorTokenID = UNKNOWN_ENTITY_TOKEN; - knownIDVersionEntityID.isKnownID = true; - knownIDVersionEntityID.id = id; - - return knownIDVersionEntityID; -} - -EntityItemID EntityItemID::convertToCreatorTokenVersion() const { - EntityItemID knownIDVersionEntityID; - - knownIDVersionEntityID.creatorTokenID = creatorTokenID; - knownIDVersionEntityID.isKnownID = false; - knownIDVersionEntityID.id = UNKNOWN_ENTITY_ID; - - return knownIDVersionEntityID; -} - -EntityItemID EntityItemID::readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead) { - EntityItemID result; - - if (bytesLeftToRead >= NUM_BYTES_RFC4122_UUID) { - // id - QByteArray encodedID((const char*)data, NUM_BYTES_RFC4122_UUID); - result.id = QUuid::fromRfc4122(encodedID); - result.isKnownID = true; - result.creatorTokenID = UNKNOWN_ENTITY_TOKEN; - } - return result; -} - - -void EntityItemID::handleAddEntityResponse(const QByteArray& packet) { - const unsigned char* dataAt = reinterpret_cast(packet.data()); - int numBytesPacketHeader = numBytesForPacketHeader(packet); - int bytesRead = numBytesPacketHeader; - dataAt += numBytesPacketHeader; - - uint32_t creatorTokenID; - memcpy(&creatorTokenID, dataAt, sizeof(creatorTokenID)); - dataAt += sizeof(creatorTokenID); - bytesRead += sizeof(creatorTokenID); - - QUuid entityID = QUuid::fromRfc4122(packet.mid(bytesRead, NUM_BYTES_RFC4122_UUID)); - dataAt += NUM_BYTES_RFC4122_UUID; - - // add our token to id mapping - _tokenIDsToIDs[creatorTokenID] = entityID; -} - -QScriptValue EntityItemID::toScriptValue(QScriptEngine* engine) const { - return EntityItemIDtoScriptValue(engine, *this); -} - -QScriptValue EntityItemIDtoScriptValue(QScriptEngine* engine, const EntityItemID& id) { - QScriptValue obj = engine->newObject(); - obj.setProperty("id", id.id.toString()); - obj.setProperty("creatorTokenID", id.creatorTokenID); - obj.setProperty("isKnownID", id.isKnownID); - return obj; -} - -void EntityItemIDfromScriptValue(const QScriptValue &object, EntityItemID& id) { - id.id = QUuid(object.property("id").toVariant().toString()); - id.creatorTokenID = object.property("creatorTokenID").toVariant().toUInt(); - id.isKnownID = object.property("isKnownID").toVariant().toBool(); -} diff --git a/libraries/entities/src/EntityItemID.h b/libraries/entities/src/EntityItemID.h deleted file mode 100644 index 1ac8a67fcd..0000000000 --- a/libraries/entities/src/EntityItemID.h +++ /dev/null @@ -1,112 +0,0 @@ -// -// 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 - - -#include -#include -#include -#include - -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 - When models are created in the JS api, they are given a -/// local creatorTokenID, the actual id for the model is not known until the server responds to the creator with the -/// correct mapping. This class works with the scripting API an allows the developer to edit models they created. -class EntityItemID { -public: - EntityItemID(); - EntityItemID(const EntityItemID& other); - EntityItemID(const QUuid& id, uint32_t creatorTokenID, bool isKnownID); - EntityItemID(const QUuid& id); - - //uint32_t id; - QUuid id; - - uint32_t creatorTokenID; - bool isKnownID; - - // these methods will reduce the ID down to half the IDs data to allow for comparisons and searches of known values - EntityItemID convertToKnownIDVersion() const; - EntityItemID convertToCreatorTokenVersion() const; - - bool isInvalidID() const { return id == UNKNOWN_ENTITY_ID && creatorTokenID == UNKNOWN_ENTITY_TOKEN && isKnownID == false; } - - // these methods allow you to create models, and later edit them. - static EntityItemID createInvalidEntityID() { return EntityItemID(UNKNOWN_ENTITY_ID, UNKNOWN_ENTITY_TOKEN, false); } - static EntityItemID getIDfromCreatorTokenID(uint32_t creatorTokenID); - static uint32_t getNextCreatorTokenID(); - static void handleAddEntityResponse(const QByteArray& packet); - static EntityItemID readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead); - - QScriptValue toScriptValue(QScriptEngine* engine) const; - -private: - friend class EntityTree; - EntityItemID assignActualIDForToken() const; // only called by EntityTree - - static uint32_t _nextCreatorTokenID; /// used by the static interfaces for creator token ids - static QHash _tokenIDsToIDs; -}; - -inline bool operator<(const EntityItemID& a, const EntityItemID& b) { - return (a.id == b.id) ? (a.creatorTokenID < b.creatorTokenID) : (a.id < b.id); -} - -inline bool operator==(const EntityItemID& a, const EntityItemID& b) { - if (a.isInvalidID() && b.isInvalidID()) { - return true; - } - if (a.isInvalidID() != b.isInvalidID()) { - return false; - } - if (a.id == UNKNOWN_ENTITY_ID || b.id == UNKNOWN_ENTITY_ID) { - return a.creatorTokenID == b.creatorTokenID; - } - 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) { - QUuid temp; - if (a.id == UNKNOWN_ENTITY_ID) { - temp = QUuid(a.creatorTokenID,0,0,0,0,0,0,0,0,0,0); - } else { - temp = a.id; - } - return qHash(temp, seed); -} - -inline QDebug operator<<(QDebug debug, const EntityItemID& id) { - debug << "[ id:" << id.id << ", creatorTokenID:" << id.creatorTokenID << ", isKnownID:" << id.isKnownID << "]"; - return debug; -} - -Q_DECLARE_METATYPE(EntityItemID); -Q_DECLARE_METATYPE(QVector); -QScriptValue EntityItemIDtoScriptValue(QScriptEngine* engine, const EntityItemID& properties); -void EntityItemIDfromScriptValue(const QScriptValue &object, EntityItemID& properties); - -#endif // hifi_EntityItemID_h diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index fd3d0e9361..fd9dc1e377 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -91,7 +91,7 @@ EntityItemProperties::EntityItemProperties() : CONSTRUCT_PROPERTY(backgroundMode, BACKGROUND_MODE_INHERIT), CONSTRUCT_PROPERTY(sourceUrl, ""), - _id(UNKNOWN_ENTITY_ID), + _id(QUuid()), _idSet(false), _lastEdited(0), _created(UNKNOWN_CREATED_TIME), @@ -350,9 +350,6 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool if (_idSet) { COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(id, _id.toString()); - COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(isKnownID, (_id != UNKNOWN_ENTITY_ID)); - } else { - COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(isKnownID, false); } COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(type, EntityTypes::getEntityTypeName(_type)); @@ -560,8 +557,8 @@ void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemP // // TODO: Implement support for script and visible properties. // -bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItemID id, const EntityItemProperties& properties, - unsigned char* bufferOut, int sizeIn, int& sizeOut) { +bool EntityItemProperties::encodeEntityEditPacket(PacketType command, QUuid id, const EntityItemProperties& properties, + unsigned char* bufferOut, int sizeIn, int& sizeOut) { 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 @@ -586,23 +583,15 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem if (success) { // Now add our edit content details... - bool isNewEntityItem = (id.id == NEW_ENTITY); // id // encode our ID as a byte count coded byte stream - QByteArray encodedID = id.id.toRfc4122(); // NUM_BYTES_RFC4122_UUID + QByteArray encodedID = id.toRfc4122(); // NUM_BYTES_RFC4122_UUID // encode our ID as a byte count coded byte stream ByteCountCoded tokenCoder; QByteArray encodedToken; - // special case for handling "new" modelItems - if (isNewEntityItem) { - // encode our creator token as a byte count coded byte stream - tokenCoder = id.creatorTokenID; - encodedToken = tokenCoder; - } - // encode our type as a byte count coded byte stream ByteCountCoded typeCoder = (quint32)properties.getType(); QByteArray encodedType = typeCoder; @@ -631,7 +620,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem bool successLastEditedFits = packetData->appendValue(lastEdited); bool successIDFits = packetData->appendValue(encodedID); - if (isNewEntityItem && successIDFits) { + if (successIDFits) { successIDFits = packetData->appendValue(encodedToken); } bool successTypeFits = packetData->appendValue(encodedType); @@ -829,7 +818,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem // TODO: Implement support for script and visible properties. // bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int bytesToRead, int& processedBytes, - EntityItemID& entityID, EntityItemProperties& properties) { + QUuid& entityID, EntityItemProperties& properties) { bool valid = false; const unsigned char* dataAt = data; @@ -863,36 +852,8 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int dataAt += encodedID.size(); processedBytes += encodedID.size(); - bool isNewEntityItem = (editID == NEW_ENTITY); - - if (isNewEntityItem) { - // If this is a NEW_ENTITY, then we assume that there's an additional uint32_t creatorToken, that - // we want to send back to the creator as an map to the actual id - - QByteArray encodedToken((const char*)dataAt, (bytesToRead - processedBytes)); - ByteCountCoded tokenCoder = encodedToken; - quint32 creatorTokenID = tokenCoder; - encodedToken = tokenCoder; // determine true bytesToRead - dataAt += encodedToken.size(); - processedBytes += encodedToken.size(); - - //newEntityItem.setCreatorTokenID(creatorTokenID); - //newEntityItem._newlyCreated = true; - - entityID.id = NEW_ENTITY; - entityID.creatorTokenID = creatorTokenID; - entityID.isKnownID = false; - - valid = true; - - // created time is lastEdited time - properties.setCreated(lastEdited); - } else { - entityID.id = editID; - entityID.creatorTokenID = UNKNOWN_ENTITY_TOKEN; - entityID.isKnownID = true; - valid = true; - } + entityID = editID; + valid = true; // Entity Type... QByteArray encodedType((const char*)dataAt, (bytesToRead - processedBytes)); @@ -1014,8 +975,8 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int // 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 // edit packet sender... -bool EntityItemProperties::encodeEraseEntityMessage(const EntityItemID& entityItemID, - unsigned char* outputBuffer, size_t maxLength, size_t& outputLength) { +bool EntityItemProperties::encodeEraseEntityMessage(const QUuid& entityItemID, + unsigned char* outputBuffer, size_t maxLength, size_t& outputLength) { unsigned char* copyAt = outputBuffer; uint16_t numberOfIds = 1; // only one entity ID in this message @@ -1029,7 +990,7 @@ bool EntityItemProperties::encodeEraseEntityMessage(const EntityItemID& entityIt copyAt += sizeof(numberOfIds); outputLength = sizeof(numberOfIds); - QUuid entityID = entityItemID.id; + QUuid entityID = entityItemID; QByteArray encodedEntityID = entityID.toRfc4122(); memcpy(copyAt, encodedEntityID.constData(), NUM_BYTES_RFC4122_UUID); diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 530013bbb6..742411dc13 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -30,7 +30,6 @@ #include #include "AtmospherePropertyGroup.h" -#include "EntityItemID.h" #include "EntityItemPropertiesMacros.h" #include "EntityTypes.h" #include "EntityPropertyFlags.h" @@ -70,9 +69,6 @@ public: { return (float)(usecTimestampNow() - getLastEdited()) / (float)USECS_PER_SECOND; } EntityPropertyFlags getChangedProperties() const; - /// used by EntityScriptingInterface to return EntityItemProperties for unknown models - void setIsUnknownID() { _id = UNKNOWN_ENTITY_ID; _idSet = true; } - AACube getMaximumAACube() const; AABox getAABox() const; @@ -166,20 +162,20 @@ public: void setGlowLevel(float value) { _glowLevel = value; _glowLevelChanged = true; } void setLocalRenderAlpha(float value) { _localRenderAlpha = value; _localRenderAlphaChanged = true; } - static bool encodeEntityEditPacket(PacketType command, EntityItemID id, const EntityItemProperties& properties, - unsigned char* bufferOut, int sizeIn, int& sizeOut); + static bool encodeEntityEditPacket(PacketType command, QUuid id, const EntityItemProperties& properties, + unsigned char* bufferOut, int sizeIn, int& sizeOut); - static bool encodeEraseEntityMessage(const EntityItemID& entityItemID, + static bool encodeEraseEntityMessage(const QUuid& entityItemID, unsigned char* outputBuffer, size_t maxLength, size_t& outputLength); static bool decodeEntityEditPacket(const unsigned char* data, int bytesToRead, int& processedBytes, - EntityItemID& entityID, EntityItemProperties& properties); + QUuid& entityID, EntityItemProperties& properties); bool glowLevelChanged() const { return _glowLevelChanged; } bool localRenderAlphaChanged() const { return _localRenderAlphaChanged; } - void clearID() { _id = UNKNOWN_ENTITY_ID; _idSet = false; } + void clearID() { _id = QUuid(); _idSet = false; } void markAllChanged(); void setSittingPoints(const QVector& sittingPoints); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index e076507b76..bb288eb702 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -20,7 +20,6 @@ EntityScriptingInterface::EntityScriptingInterface() : - _nextCreatorTokenID(0), _entityTree(NULL) { auto nodeList = DependencyManager::get(); @@ -29,7 +28,7 @@ EntityScriptingInterface::EntityScriptingInterface() : } void EntityScriptingInterface::queueEntityMessage(PacketType packetType, - EntityItemID entityID, const EntityItemProperties& properties) { + QUuid entityID, const EntityItemProperties& properties) { getEntityPacketSender()->queueEditEntityMessage(packetType, entityID, properties); } @@ -71,14 +70,10 @@ void bidForSimulationOwnership(EntityItemProperties& properties) { -EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& properties) { - - // The application will keep track of creatorTokenID - uint32_t creatorTokenID = EntityItemID::getNextCreatorTokenID(); +QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties) { EntityItemProperties propertiesWithSimID = properties; - - EntityItemID id(NEW_ENTITY, creatorTokenID, false); + QUuid id = QUuid::createUuid(); // If we have a local entity tree set, then also update it. bool success = true; @@ -104,25 +99,8 @@ EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& pro return id; } -EntityItemID EntityScriptingInterface::identifyEntity(EntityItemID entityID) { - EntityItemID actualID = entityID; - - if (!entityID.isKnownID) { - actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID); - if (actualID == UNKNOWN_ENTITY_ID) { - return entityID; // bailing early - } - - // found it! - entityID.id = actualID.id; - entityID.isKnownID = true; - } - return entityID; -} - -EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID entityID) { +EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identity) { EntityItemProperties results; - EntityItemID identity = identifyEntity(entityID); if (_entityTree) { _entityTree->lockForRead(); EntityItem* entity = const_cast(_entityTree->findEntityByEntityItemID(identity)); @@ -142,8 +120,6 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID } } - } else { - results.setIsUnknownID(); } _entityTree->unlock(); } @@ -151,59 +127,33 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID return results; } -EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const EntityItemProperties& properties) { - EntityItemID actualID = entityID; - // if the entity is unknown, attempt to look it up - if (!entityID.isKnownID) { - actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID); - if (actualID.id != UNKNOWN_ENTITY_ID) { - entityID.id = actualID.id; - entityID.isKnownID = true; - } - } - - // If we have a local entity tree set, then also update it. We can do this even if we don't know - // the actual id, because we can edit out local entities just with creatorTokenID +QUuid EntityScriptingInterface::editEntity(QUuid entityID, const EntityItemProperties& properties) { + // If we have a local entity tree set, then also update it. if (_entityTree) { _entityTree->lockForWrite(); _entityTree->updateEntity(entityID, properties); _entityTree->unlock(); } - // if at this point, we know the id, send the update to the entity server - if (entityID.isKnownID) { - // make sure the properties has a type, so that the encode can know which properties to include - if (properties.getType() == EntityTypes::Unknown) { - EntityItem* entity = _entityTree->findEntityByEntityItemID(entityID); - if (entity) { - // we need to change the outgoing properties, so we make a copy, modify, and send. - EntityItemProperties modifiedProperties = properties; - entity->setLastBroadcast(usecTimestampNow()); - modifiedProperties.setType(entity->getType()); - bidForSimulationOwnership(modifiedProperties); - queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, modifiedProperties); - return entityID; - } + // make sure the properties has a type, so that the encode can know which properties to include + if (properties.getType() == EntityTypes::Unknown) { + EntityItem* entity = _entityTree->findEntityByEntityItemID(entityID); + if (entity) { + // we need to change the outgoing properties, so we make a copy, modify, and send. + EntityItemProperties modifiedProperties = properties; + entity->setLastBroadcast(usecTimestampNow()); + modifiedProperties.setType(entity->getType()); + bidForSimulationOwnership(modifiedProperties); + queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, modifiedProperties); + return entityID; } - - queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); } - + + queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); return entityID; } -void EntityScriptingInterface::deleteEntity(EntityItemID entityID) { - - EntityItemID actualID = entityID; - - // if the entity is unknown, attempt to look it up - if (!entityID.isKnownID) { - actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID); - if (actualID.id != UNKNOWN_ENTITY_ID) { - entityID.id = actualID.id; - entityID.isKnownID = true; - } - } +void EntityScriptingInterface::deleteEntity(QUuid entityID) { bool shouldDelete = true; @@ -211,7 +161,7 @@ void EntityScriptingInterface::deleteEntity(EntityItemID entityID) { if (_entityTree) { _entityTree->lockForWrite(); - EntityItem* entity = const_cast(_entityTree->findEntityByEntityItemID(actualID)); + EntityItem* entity = const_cast(_entityTree->findEntityByEntityItemID(entityID)); if (entity) { if (entity->getLocked()) { shouldDelete = false; @@ -224,19 +174,19 @@ void EntityScriptingInterface::deleteEntity(EntityItemID entityID) { } // if at this point, we know the id, and we should still delete the entity, send the update to the entity server - if (shouldDelete && entityID.isKnownID) { + if (shouldDelete) { getEntityPacketSender()->queueEraseEntityMessage(entityID); } } -EntityItemID EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const { - EntityItemID result(UNKNOWN_ENTITY_ID, UNKNOWN_ENTITY_TOKEN, false); +QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const { + QUuid result; if (_entityTree) { _entityTree->lockForRead(); const EntityItem* closestEntity = _entityTree->findClosestEntity(center, radius); _entityTree->unlock(); if (closestEntity) { - result = closestEntity->getEntityItemID(); + result = closestEntity->getID(); } } return result; @@ -251,8 +201,8 @@ void EntityScriptingInterface::dumpTree() const { } } -QVector EntityScriptingInterface::findEntities(const glm::vec3& center, float radius) const { - QVector result; +QVector EntityScriptingInterface::findEntities(const glm::vec3& center, float radius) const { + QVector result; if (_entityTree) { _entityTree->lockForRead(); QVector entities; @@ -260,14 +210,14 @@ QVector EntityScriptingInterface::findEntities(const glm::vec3& ce _entityTree->unlock(); foreach (const EntityItem* entity, entities) { - result << entity->getEntityItemID(); + result << entity->getID(); } } return result; } -QVector EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const { - QVector result; +QVector EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const { + QVector result; if (_entityTree) { _entityTree->lockForRead(); AABox box(corner, dimensions); @@ -276,7 +226,7 @@ QVector EntityScriptingInterface::findEntitiesInBox(const glm::vec _entityTree->unlock(); foreach (const EntityItem* entity, entities) { - result << entity->getEntityItemID(); + result << entity->getID(); } } return result; @@ -303,7 +253,7 @@ RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorke (void**)&intersectedEntity, lockType, &result.accurate, precisionPicking); if (result.intersects && intersectedEntity) { - result.entityID = intersectedEntity->getEntityItemID(); + result.entityID = intersectedEntity->getID(); result.properties = intersectedEntity->getProperties(); result.intersection = ray.origin + (ray.direction * result.distance); } @@ -359,7 +309,7 @@ QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, c QScriptValue obj = engine->newObject(); obj.setProperty("intersects", value.intersects); obj.setProperty("accurate", value.accurate); - QScriptValue entityItemValue = EntityItemIDtoScriptValue(engine, value.entityID); + QScriptValue entityItemValue = quuidToScriptValue(engine, value.entityID); obj.setProperty("entityID", entityItemValue); QScriptValue propertiesValue = EntityItemPropertiesToScriptValue(engine, value.properties); @@ -403,9 +353,7 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra value.intersects = object.property("intersects").toVariant().toBool(); value.accurate = object.property("accurate").toVariant().toBool(); QScriptValue entityIDValue = object.property("entityID"); - if (entityIDValue.isValid()) { - EntityItemIDfromScriptValue(entityIDValue, value.entityID); - } + quuidFromScriptValue(entityIDValue, value.entityID); QScriptValue entityPropertiesValue = object.property("properties"); if (entityPropertiesValue.isValid()) { EntityItemPropertiesFromScriptValue(entityPropertiesValue, value.properties); diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index bde369eaf2..de052d12a9 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -34,7 +34,7 @@ public: RayToEntityIntersectionResult(); bool intersects; bool accurate; - EntityItemID entityID; + QUuid entityID; EntityItemProperties properties; float distance; BoxFace face; @@ -70,34 +70,31 @@ public slots: Q_INVOKABLE bool canRez(); /// adds a model with the specific properties - Q_INVOKABLE EntityItemID addEntity(const EntityItemProperties& properties); - - /// identify a recently created model to determine its true ID - Q_INVOKABLE EntityItemID identifyEntity(EntityItemID entityID); + Q_INVOKABLE QUuid addEntity(const EntityItemProperties& properties); /// 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 - Q_INVOKABLE EntityItemProperties getEntityProperties(EntityItemID entityID); + Q_INVOKABLE EntityItemProperties getEntityProperties(QUuid entityID); - /// edits a model updating only the included properties, will return the identified EntityItemID in case of + /// edits a model updating only the included properties, will return the identified QUuid in case of /// successful edit, if the input entityID is for an unknown model this function will have no effect - Q_INVOKABLE EntityItemID editEntity(EntityItemID entityID, const EntityItemProperties& properties); + Q_INVOKABLE QUuid editEntity(QUuid entityID, const EntityItemProperties& properties); /// deletes a model - Q_INVOKABLE void deleteEntity(EntityItemID entityID); + Q_INVOKABLE void deleteEntity(QUuid entityID); /// finds the closest model to the center point, within the radius - /// will return a EntityItemID.isKnownID = false if no models are in the radius + /// will return a QUuid.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 - Q_INVOKABLE EntityItemID findClosestEntity(const glm::vec3& center, float radius) const; + Q_INVOKABLE QUuid findClosestEntity(const glm::vec3& center, float radius) const; /// 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 - Q_INVOKABLE QVector findEntities(const glm::vec3& center, float radius) const; + Q_INVOKABLE QVector findEntities(const glm::vec3& center, float radius) const; /// 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 - Q_INVOKABLE QVector findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const; + Q_INVOKABLE QVector 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 /// may be inaccurate if the engine is unable to access the visible entities, in which case result.accurate @@ -123,39 +120,38 @@ public slots: Q_INVOKABLE void dumpTree() const; signals: - void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); + void entityCollisionWithEntity(const QUuid& idA, const QUuid& idB, const Collision& collision); void canAdjustLocksChanged(bool canAdjustLocks); void canRezChanged(bool canRez); - void mousePressOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); - void mouseMoveOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); - void mouseReleaseOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); + void mousePressOnEntity(const QUuid& entityItemID, const MouseEvent& event); + void mouseMoveOnEntity(const QUuid& entityItemID, const MouseEvent& event); + void mouseReleaseOnEntity(const QUuid& entityItemID, const MouseEvent& event); - void clickDownOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); - void holdingClickOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); - void clickReleaseOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); + void clickDownOnEntity(const QUuid& entityItemID, const MouseEvent& event); + void holdingClickOnEntity(const QUuid& entityItemID, const MouseEvent& event); + void clickReleaseOnEntity(const QUuid& entityItemID, const MouseEvent& event); - void hoverEnterEntity(const EntityItemID& entityItemID, const MouseEvent& event); - void hoverOverEntity(const EntityItemID& entityItemID, const MouseEvent& event); - void hoverLeaveEntity(const EntityItemID& entityItemID, const MouseEvent& event); + void hoverEnterEntity(const QUuid& entityItemID, const MouseEvent& event); + void hoverOverEntity(const QUuid& entityItemID, const MouseEvent& event); + void hoverLeaveEntity(const QUuid& entityItemID, const MouseEvent& event); - void enterEntity(const EntityItemID& entityItemID); - void leaveEntity(const EntityItemID& entityItemID); + void enterEntity(const QUuid& entityItemID); + void leaveEntity(const QUuid& entityItemID); - void deletingEntity(const EntityItemID& entityID); - void addingEntity(const EntityItemID& entityID); - void changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID); + void deletingEntity(const QUuid& entityID); + void addingEntity(const QUuid& entityID); + void changingEntityID(const QUuid& oldEntityID, const QUuid& newEntityID); void clearingEntities(); private: - void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties); + void queueEntityMessage(PacketType packetType, QUuid entityID, const EntityItemProperties& properties); /// 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, bool precisionPicking); - uint32_t _nextCreatorTokenID; EntityTree* _entityTree; }; diff --git a/libraries/entities/src/EntitySimulation.cpp b/libraries/entities/src/EntitySimulation.cpp index d28e139205..75e32cd548 100644 --- a/libraries/entities/src/EntitySimulation.cpp +++ b/libraries/entities/src/EntitySimulation.cpp @@ -121,7 +121,7 @@ void EntitySimulation::sortEntitiesThatMoved() { // check to see if this movement has sent the entity outside of the domain. AACube newCube = entity->getMaximumAACube(); if (!domainBounds.touches(newCube)) { - qCDebug(entities) << "Entity " << entity->getEntityItemID() << " moved out of domain bounds."; + qCDebug(entities) << "Entity " << entity->getID() << " moved out of domain bounds."; _entitiesToDelete.insert(entity); _mortalEntities.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 newCube = entity->getMaximumAACube(); if (!domainBounds.touches(newCube)) { - qCDebug(entities) << "Entity " << entity->getEntityItemID() << " moved out of domain bounds."; + qCDebug(entities) << "Entity " << entity->getID() << " moved out of domain bounds."; _entitiesToDelete.insert(entity); _mortalEntities.remove(entity); _entitiesToUpdate.remove(entity); diff --git a/libraries/entities/src/EntitySimulation.h b/libraries/entities/src/EntitySimulation.h index f5a100eba0..a37a4ecb4f 100644 --- a/libraries/entities/src/EntitySimulation.h +++ b/libraries/entities/src/EntitySimulation.h @@ -81,7 +81,7 @@ public: void getEntitiesToDelete(VectorOfEntities& entitiesToDelete); signals: - void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); + void entityCollisionWithEntity(const QUuid& idA, const QUuid& idB, const Collision& collision); protected: diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index e90a01383b..9e4e598e05 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -83,10 +83,11 @@ void EntityTree::postAddEntity(EntityItem* entity) { _simulation->unlock(); } _isDirty = true; - emit addingEntity(entity->getEntityItemID()); + emit addingEntity(entity->getID()); } -bool EntityTree::updateEntity(const EntityItemID& entityID, const EntityItemProperties& properties, const SharedNodePointer& senderNode) { +bool EntityTree::updateEntity(const QUuid& entityID, const EntityItemProperties& properties, + const SharedNodePointer& senderNode) { EntityTreeElement* containingElement = getContainingElement(entityID); if (!containingElement) { qCDebug(entities) << "UNEXPECTED!!!! EntityTree::updateEntity() entityID doesn't exist!!! entityID=" << entityID; @@ -103,10 +104,10 @@ bool EntityTree::updateEntity(const EntityItemID& entityID, const EntityItemProp } bool EntityTree::updateEntity(EntityItem* entity, const EntityItemProperties& properties, const SharedNodePointer& senderNode) { - EntityTreeElement* containingElement = getContainingElement(entity->getEntityItemID()); + EntityTreeElement* containingElement = getContainingElement(entity->getID()); if (!containingElement) { qCDebug(entities) << "UNEXPECTED!!!! EntityTree::updateEntity() entity-->element lookup failed!!! entityID=" - << entity->getEntityItemID(); + << entity->getID(); return false; } return updateEntityWithElement(entity, properties, containingElement, senderNode); @@ -204,22 +205,22 @@ bool EntityTree::updateEntityWithElement(EntityItem* entity, const EntityItemPro QString entityScriptAfter = entity->getScript(); if (entityScriptBefore != entityScriptAfter) { - emitEntityScriptChanging(entity->getEntityItemID()); // the entity script has changed + emitEntityScriptChanging(entity->getID()); // the entity script has changed } } // TODO: this final containingElement check should eventually be removed (or wrapped in an #ifdef DEBUG). - containingElement = getContainingElement(entity->getEntityItemID()); + containingElement = getContainingElement(entity->getID()); if (!containingElement) { qCDebug(entities) << "UNEXPECTED!!!! after updateEntity() we no longer have a containing element??? entityID=" - << entity->getEntityItemID(); + << entity->getID(); return false; } return true; } -EntityItem* EntityTree::addEntity(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* EntityTree::addEntity(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* result = NULL; if (getIsClient()) { @@ -230,19 +231,11 @@ EntityItem* EntityTree::addEntity(const EntityItemID& entityID, const EntityItem } } - // NOTE: This method is used in the client and the server tree. In the client, it's possible to create EntityItems - // that do not yet have known IDs. In the server tree however we don't want to have entities without known IDs. bool recordCreationTime = false; - if (!entityID.isKnownID) { - if (getIsServer()) { - qCDebug(entities) << "UNEXPECTED!!! ----- EntityTree::addEntity()... (getIsSever() && !entityID.isKnownID)"; - return result; - } - if (properties.getCreated() == UNKNOWN_CREATED_TIME) { - // the entity's creation time was not specified in properties, which means this is a NEW entity - // and we must record its creation time - recordCreationTime = true; - } + if (properties.getCreated() == UNKNOWN_CREATED_TIME) { + // the entity's creation time was not specified in properties, which means this is a NEW entity + // and we must record its creation time + recordCreationTime = true; } // You should not call this on existing entities that are already part of the tree! Call updateEntity() @@ -270,7 +263,7 @@ EntityItem* EntityTree::addEntity(const EntityItemID& entityID, const EntityItem return result; } -void EntityTree::emitEntityScriptChanging(const EntityItemID& entityItemID) { +void EntityTree::emitEntityScriptChanging(const QUuid& entityItemID) { emit entityScriptChanging(entityItemID); } @@ -289,7 +282,7 @@ void EntityTree::setSimulation(EntitySimulation* simulation) { _simulation = simulation; } -void EntityTree::deleteEntity(const EntityItemID& entityID, bool force, bool ignoreWarnings) { +void EntityTree::deleteEntity(const QUuid& entityID, bool force, bool ignoreWarnings) { EntityTreeElement* containingElement = getContainingElement(entityID); if (!containingElement) { if (!ignoreWarnings) { @@ -323,10 +316,10 @@ void EntityTree::deleteEntity(const EntityItemID& entityID, bool force, bool ign _isDirty = true; } -void EntityTree::deleteEntities(QSet entityIDs, bool force, bool ignoreWarnings) { +void EntityTree::deleteEntities(QSet entityIDs, bool force, bool ignoreWarnings) { // NOTE: callers must lock the tree before using this method DeleteEntityOperator theOperator(this); - foreach(const EntityItemID& entityID, entityIDs) { + foreach(const QUuid& entityID, entityIDs) { EntityTreeElement* containingElement = getContainingElement(entityID); if (!containingElement) { if (!ignoreWarnings) { @@ -375,7 +368,7 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator) // set up the deleted entities ID quint64 deletedAt = usecTimestampNow(); _recentlyDeletedEntitiesLock.lockForWrite(); - _recentlyDeletedEntityItemIDs.insert(deletedAt, theEntity->getEntityItemID().id); + _recentlyDeletedEntityItemIDs.insert(deletedAt, theEntity->getID()); _recentlyDeletedEntitiesLock.unlock(); } @@ -389,93 +382,11 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator) } } -/// This method is used to find and fix entity IDs that are shifting from creator token based to known ID based entity IDs. -/// This should only be used on a client side (viewing) tree. The typical usage is that a local editor has been creating -/// entities in the local tree, those entities have creatorToken based entity IDs. But those entity edits are also sent up to -/// the server, and the server eventually sends back to the client two messages that can come in varying order. The first -/// message would be a typical query/viewing data message conversation in which the viewer "sees" the newly created entity. -/// Those entities that have been seen, will have the authoritative "known ID". Therefore there is a potential that there can -/// be two copies of the same entity in the tree: the "local only" "creator token" version of the entity and the "seen" -/// "knownID" version of the entity. The server also sends an "entityAdded" message to the client which contains the mapping -/// of the creator token to the known ID. These messages can come in any order, so we need to handle the follow cases: -/// -/// Case A: The local edit occurs, the addEntity message arrives, the "viewed data" has not yet arrived. -/// In this case, we can expect that our local tree has only one copy of the entity (the creator token), -/// and we only really need to fix up that entity with a new version of the ID that includes the knownID -/// -/// Case B: The local edit occurs, the "viewed data" for the new entity arrives, then the addEntity message arrives. -/// In this case, we can expect that our local tree has two copies of the entity (the creator token, and the -/// known ID version). We end up with two version of the entity because the server sends viewers only the -/// known ID version without a creator token. And we don't yet know the mapping until we get the mapping message. -/// In this case we need to fix up that entity with a new version of the ID that includes the knownID and -/// we need to delete the extra copy of the entity. -/// -/// This method handles both of these cases. -/// -/// NOTE: unlike some operations on the tree, this process does not mark the tree as being changed. This is because -/// we're not changing the content of the tree, we're only changing the internal IDs that map entities from creator -/// based to known IDs. This means we don't have to recurse the tree to mark the changed path as dirty. void EntityTree::handleAddEntityResponse(const QByteArray& packet) { - if (!getIsClient()) { qCDebug(entities) << "UNEXPECTED!!! EntityTree::handleAddEntityResponse() with !getIsClient() ***"; return; } - - const unsigned char* dataAt = reinterpret_cast(packet.data()); - int numBytesPacketHeader = numBytesForPacketHeader(packet); - int bytesRead = numBytesPacketHeader; - dataAt += numBytesPacketHeader; - - uint32_t creatorTokenID; - memcpy(&creatorTokenID, dataAt, sizeof(creatorTokenID)); - dataAt += sizeof(creatorTokenID); - bytesRead += sizeof(creatorTokenID); - - QUuid entityID = QUuid::fromRfc4122(packet.mid(bytesRead, NUM_BYTES_RFC4122_UUID)); - dataAt += NUM_BYTES_RFC4122_UUID; - - // First, look for the existing entity in the tree.. - EntityItemID searchEntityID; - searchEntityID.id = entityID; - searchEntityID.creatorTokenID = creatorTokenID; - - lockForWrite(); - - // find the creator token version, it's containing element, and the entity itself - EntityItem* foundEntity = NULL; - EntityItemID creatorTokenVersion = searchEntityID.convertToCreatorTokenVersion(); - EntityItemID knownIDVersion = searchEntityID.convertToKnownIDVersion(); - - _changedEntityIDs[creatorTokenVersion] = knownIDVersion; - - // First look for and find the "viewed version" of this entity... it's possible we got - // the known ID version sent to us between us creating our local version, and getting this - // remapping message. If this happened, we actually want to find and delete that version of - // the entity. - EntityTreeElement* knownIDVersionContainingElement = getContainingElement(knownIDVersion); - if (knownIDVersionContainingElement) { - foundEntity = knownIDVersionContainingElement->getEntityWithEntityItemID(knownIDVersion); - if (foundEntity) { - knownIDVersionContainingElement->removeEntityWithEntityItemID(knownIDVersion); - setContainingElement(knownIDVersion, NULL); - } - } - - EntityTreeElement* creatorTokenContainingElement = getContainingElement(creatorTokenVersion); - if (creatorTokenContainingElement) { - foundEntity = creatorTokenContainingElement->getEntityWithEntityItemID(creatorTokenVersion); - if (foundEntity) { - creatorTokenContainingElement->updateEntityItemID(creatorTokenVersion, knownIDVersion); - setContainingElement(creatorTokenVersion, NULL); - setContainingElement(knownIDVersion, creatorTokenContainingElement); - - // because the ID of the entity is switching, we need to emit these signals for any - // listeners who care about the changing of IDs - emit changingEntityID(creatorTokenVersion, knownIDVersion); - } - } - unlock(); } @@ -626,39 +537,20 @@ void EntityTree::findEntities(const AABox& box, QVector& foundEntit } EntityItem* EntityTree::findEntityByID(const QUuid& id) { - EntityItemID entityID(id); - return findEntityByEntityItemID(entityID); + return findEntityByEntityItemID(id); } -EntityItem* EntityTree::findEntityByEntityItemID(const EntityItemID& entityID) /*const*/ { +EntityItem* EntityTree::findEntityByEntityItemID(const QUuid& entityID) /*const*/ { EntityItem* foundEntity = NULL; EntityTreeElement* containingElement = getContainingElement(entityID); if (containingElement) { foundEntity = containingElement->getEntityWithEntityItemID(entityID); - if (!foundEntity && _changedEntityIDs.contains(entityID)) { - foundEntity = containingElement->getEntityWithEntityItemID(_changedEntityIDs[entityID]); - } } return foundEntity; } -EntityItemID EntityTree::assignEntityID(const EntityItemID& entityItemID) { - if (!getIsServer()) { - qCDebug(entities) << "UNEXPECTED!!! assignEntityID should only be called on a server tree. entityItemID:" << entityItemID; - return entityItemID; - } - - if (getContainingElement(entityItemID)) { - qCDebug(entities) << "UNEXPECTED!!! don't call assignEntityID() for existing entityIDs. entityItemID:" << entityItemID; - return entityItemID; - } - - // The EntityItemID is responsible for assigning actual IDs and keeping track of them. - return entityItemID.assignActualIDForToken(); -} - int EntityTree::processEditPacketData(PacketType packetType, const unsigned char* packetData, int packetLength, - const unsigned char* editData, int maxLength, const SharedNodePointer& senderNode) { + const unsigned char* editData, int maxLength, const SharedNodePointer& senderNode) { if (!getIsServer()) { qCDebug(entities) << "UNEXPECTED!!! processEditPacketData() should only be called on a server tree."; @@ -675,20 +567,19 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char } case PacketTypeEntityAddOrEdit: { - EntityItemID entityItemID; + QUuid entityItemID; EntityItemProperties properties; 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 // an existing entity... handle appropriately if (validEditPacket) { + // search for the entity by EntityItemID + EntityItem* existingEntity = findEntityByEntityItemID(entityItemID); // If this is a knownID, then it should exist in our tree - if (entityItemID.isKnownID) { - // search for the entity by EntityItemID - EntityItem* existingEntity = findEntityByEntityItemID(entityItemID); - + if (existingEntity) { // if the EntityItem exists, then update it if (existingEntity) { if (wantEditLogging()) { @@ -702,8 +593,6 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char } } else { if (senderNode->getCanRez()) { - // this is a new entity... assign a new entityID - entityItemID = assignEntityID(entityItemID); if (wantEditLogging()) { qCDebug(entities) << "User [" << senderNode->getUUID() << "] adding entity."; qCDebug(entities) << " properties:" << properties; @@ -714,13 +603,13 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char notifyNewlyCreatedEntity(*newEntity, senderNode); if (wantEditLogging()) { qCDebug(entities) << "User [" << senderNode->getUUID() << "] added entity. ID:" - << newEntity->getEntityItemID(); + << newEntity->getID(); qCDebug(entities) << " properties:" << properties; } - } } else { - qCDebug(entities) << "User without 'rez rights' [" << senderNode->getUUID() << "] attempted to add an entity."; + qCDebug(entities) << "User without 'rez rights' [" + << senderNode->getUUID() << "] attempted to add an entity."; } } } @@ -788,11 +677,11 @@ void EntityTree::update() { if (pendingDeletes.size() > 0) { // translate into list of ID's - QSet idsToDelete; + QSet idsToDelete; for (auto entityItr : pendingDeletes) { EntityItem* entity = &(*entityItr); assert(!entity->getPhysicsInfo()); // TODO: Andrew to remove this after testing - idsToDelete.insert(entity->getEntityItemID()); + idsToDelete.insert(entity->getID()); } // delete these things the roundabout way deleteEntities(idsToDelete, true); @@ -952,7 +841,7 @@ int EntityTree::processEraseMessage(const QByteArray& dataByteArray, const Share processedBytes += sizeof(numberOfIds); if (numberOfIds > 0) { - QSet entityItemIDsToDelete; + QSet entityItemIDsToDelete; for (size_t i = 0; i < numberOfIds; i++) { @@ -966,11 +855,10 @@ int EntityTree::processEraseMessage(const QByteArray& dataByteArray, const Share dataAt += encodedID.size(); processedBytes += encodedID.size(); - EntityItemID entityItemID(entityID); - entityItemIDsToDelete << entityItemID; + entityItemIDsToDelete << entityID; if (wantEditLogging()) { - qCDebug(entities) << "User [" << sourceNode->getUUID() << "] deleting entity. ID:" << entityItemID; + qCDebug(entities) << "User [" << sourceNode->getUUID() << "] deleting entity. ID:" << entityID; } } @@ -995,7 +883,7 @@ int EntityTree::processEraseMessageDetails(const QByteArray& dataByteArray, cons processedBytes += sizeof(numberOfIds); if (numberOfIds > 0) { - QSet entityItemIDsToDelete; + QSet entityItemIDsToDelete; for (size_t i = 0; i < numberOfIds; i++) { @@ -1010,11 +898,10 @@ int EntityTree::processEraseMessageDetails(const QByteArray& dataByteArray, cons dataAt += encodedID.size(); processedBytes += encodedID.size(); - EntityItemID entityItemID(entityID); - entityItemIDsToDelete << entityItemID; + entityItemIDsToDelete << entityID; if (wantEditLogging()) { - qCDebug(entities) << "User [" << sourceNode->getUUID() << "] deleting entity. ID:" << entityItemID; + qCDebug(entities) << "User [" << sourceNode->getUUID() << "] deleting entity. ID:" << entityID; } } @@ -1023,75 +910,27 @@ int EntityTree::processEraseMessageDetails(const QByteArray& dataByteArray, cons return processedBytes; } -EntityTreeElement* EntityTree::getContainingElement(const EntityItemID& entityItemID) /*const*/ { +EntityTreeElement* EntityTree::getContainingElement(const QUuid& entityItemID) /*const*/ { // TODO: do we need to make this thread safe? Or is it acceptable as is EntityTreeElement* element = _entityToElementMap.value(entityItemID); - if (!element && entityItemID.creatorTokenID != UNKNOWN_ENTITY_TOKEN){ - // check the creator token version too... - EntityItemID creatorTokenOnly; - creatorTokenOnly.id = UNKNOWN_ENTITY_ID; - creatorTokenOnly.creatorTokenID = entityItemID.creatorTokenID; - creatorTokenOnly.isKnownID = false; - element = _entityToElementMap.value(creatorTokenOnly); - } - - // If we still didn't find the entity, but the ID was in our changed entityIDs, search for the new ID version - if (!element && _changedEntityIDs.contains(entityItemID)) { - element = getContainingElement(_changedEntityIDs[entityItemID]); - } - return element; } -// TODO: do we need to make this thread safe? Or is it acceptable as is -void EntityTree::resetContainingElement(const EntityItemID& entityItemID, EntityTreeElement* element) { - if (entityItemID.id == UNKNOWN_ENTITY_ID) { - //assert(entityItemID.id != UNKNOWN_ENTITY_ID); - qCDebug(entities) << "UNEXPECTED! resetContainingElement() called with UNKNOWN_ENTITY_ID. entityItemID:" << entityItemID; - return; - } - if (entityItemID.creatorTokenID == UNKNOWN_ENTITY_TOKEN) { - //assert(entityItemID.creatorTokenID != UNKNOWN_ENTITY_TOKEN); - qCDebug(entities) << "UNEXPECTED! resetContainingElement() called with UNKNOWN_ENTITY_TOKEN. entityItemID:" << entityItemID; - return; - } - if (!element) { - //assert(element); - qCDebug(entities) << "UNEXPECTED! resetContainingElement() called with NULL element. entityItemID:" << entityItemID; - return; - } - - // remove the old version with the creatorTokenID - EntityItemID creatorTokenVersion; - creatorTokenVersion.id = UNKNOWN_ENTITY_ID; - creatorTokenVersion.isKnownID = false; - creatorTokenVersion.creatorTokenID = entityItemID.creatorTokenID; - _entityToElementMap.remove(creatorTokenVersion); - // set the new version with both creator token and real ID - _entityToElementMap[entityItemID] = 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 - - // If we're a sever side tree, we always remove the creator tokens from our map items - EntityItemID storedEntityItemID = entityItemID; - - if (getIsServer()) { - storedEntityItemID.creatorTokenID = UNKNOWN_ENTITY_TOKEN; - } - if (element) { - _entityToElementMap[storedEntityItemID] = element; + _entityToElementMap[entityItemID] = element; } else { - _entityToElementMap.remove(storedEntityItemID); + _entityToElementMap.remove(entityItemID); } } + + void EntityTree::debugDumpMap() { qCDebug(entities) << "EntityTree::debugDumpMap() --------------------------"; - QHashIterator i(_entityToElementMap); + QHashIterator i(_entityToElementMap); while (i.hasNext()) { i.next(); qCDebug(entities) << i.key() << ": " << i.value(); @@ -1155,12 +994,13 @@ void EntityTree::pruneTree() { recurseTreeWithOperator(&theOperator); } -QVector EntityTree::sendEntities(EntityEditPacketSender* packetSender, EntityTree* localTree, float x, float y, float z) { +QVector EntityTree::sendEntities(EntityEditPacketSender* packetSender, + EntityTree* localTree, float x, float y, float z) { SendEntitiesOperationArgs args; args.packetSender = packetSender; args.localTree = localTree; args.root = glm::vec3(x, y, z); - QVector newEntityIDs; + QVector newEntityIDs; args.newEntityIDs = &newEntityIDs; recurseTreeWithOperation(sendEntitiesOperation, &args); packetSender->releaseQueuedMessages(); @@ -1174,7 +1014,7 @@ bool EntityTree::sendEntitiesOperation(OctreeElement* element, void* extraData) const QList& entities = entityTreeElement->getEntities(); for (int i = 0; i < entities.size(); i++) { - EntityItemID newID(NEW_ENTITY, EntityItemID::getNextCreatorTokenID(), false); + QUuid newID = QUuid::createUuid(); args->newEntityIDs->append(newID); EntityItemProperties properties = entities[i]->getProperties(); properties.setPosition(properties.getPosition() + args->root); @@ -1217,11 +1057,11 @@ bool EntityTree::readFromMap(QVariantMap& map) { EntityItemProperties properties; EntityItemPropertiesFromScriptValue(entityScriptValue, properties); - EntityItemID entityItemID; + QUuid entityItemID; if (entityMap.contains("id")) { - entityItemID = EntityItemID(QUuid(entityMap["id"].toString())); + entityItemID = QUuid(entityMap["id"].toString()); } else { - entityItemID = EntityItemID(QUuid::createUuid()); + entityItemID = QUuid::createUuid(); } EntityItem* entity = addEntity(entityItemID, properties); diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index fb6e0f26eb..a7e9ce6842 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -41,7 +41,7 @@ public: glm::vec3 root; EntityTree* localTree; EntityEditPacketSender* packetSender; - QVector* newEntityIDs; + QVector* newEntityIDs; }; @@ -85,24 +85,25 @@ public: // The newer API... void postAddEntity(EntityItem* entityItem); - EntityItem* addEntity(const EntityItemID& entityID, const EntityItemProperties& properties); + EntityItem* addEntity(const QUuid& entityID, const EntityItemProperties& properties); // use this method if you only know the entityID - bool updateEntity(const EntityItemID& entityID, const EntityItemProperties& properties, const SharedNodePointer& senderNode = SharedNodePointer(nullptr)); + bool updateEntity(const QUuid& entityID, const EntityItemProperties& properties, + const SharedNodePointer& senderNode = SharedNodePointer(nullptr)); // 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)); - void deleteEntity(const EntityItemID& entityID, bool force = false, bool ignoreWarnings = false); - void deleteEntities(QSet entityIDs, bool force = false, bool ignoreWarnings = false); + void deleteEntity(const QUuid& entityID, bool force = false, bool ignoreWarnings = false); + void deleteEntities(QSet entityIDs, bool force = false, bool ignoreWarnings = false); /// \param position point of query in world-frame (meters) /// \param targetRadius radius of query (meters) const EntityItem* findClosestEntity(glm::vec3 position, float targetRadius); EntityItem* findEntityByID(const QUuid& id); - EntityItem* findEntityByEntityItemID(const EntityItemID& entityID); + EntityItem* findEntityByEntityItemID(const QUuid& entityID); - EntityItemID assignEntityID(const EntityItemID& entityItemID); /// Assigns a known ID for a creator token ID + QUuid assignEntityID(const QUuid& entityItemID); /// Assigns a known ID for a creator token ID /// finds all entities that touch a sphere @@ -146,18 +147,17 @@ public: return _fbxService ? _fbxService->getModelForEntityItem(entityItem) : NULL; } - EntityTreeElement* getContainingElement(const EntityItemID& entityItemID) /*const*/; - void setContainingElement(const EntityItemID& entityItemID, EntityTreeElement* element); - void resetContainingElement(const EntityItemID& entityItemID, EntityTreeElement* element); + EntityTreeElement* getContainingElement(const QUuid& entityItemID) /*const*/; + void setContainingElement(const QUuid& entityItemID, EntityTreeElement* element); void debugDumpMap(); virtual void dumpTree(); virtual void pruneTree(); - QVector sendEntities(EntityEditPacketSender* packetSender, EntityTree* localTree, float x, float y, float z); + QVector sendEntities(EntityEditPacketSender* packetSender, EntityTree* localTree, float x, float y, float z); void entityChanged(EntityItem* entity); - void emitEntityScriptChanging(const EntityItemID& entityItemID); + void emitEntityScriptChanging(const QUuid& entityItemID); void setSimulation(EntitySimulation* simulation); @@ -170,10 +170,10 @@ public: float getContentsLargestDimension(); signals: - void deletingEntity(const EntityItemID& entityID); - void addingEntity(const EntityItemID& entityID); - void entityScriptChanging(const EntityItemID& entityItemID); - void changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID); + void deletingEntity(const QUuid& entityID); + void addingEntity(const QUuid& entityID); + void entityScriptChanging(const QUuid& entityItemID); + void changingEntityID(const QUuid& oldEntityID, const QUuid& newEntityID); void clearingEntities(); private: @@ -197,8 +197,7 @@ private: QMultiMap _recentlyDeletedEntityItemIDs; EntityItemFBXService* _fbxService; - QHash _entityToElementMap; - QHash _changedEntityIDs; + QHash _entityToElementMap; EntitySimulation* _simulation; diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index 3acc5fbcef..61f54c6f54 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -86,7 +86,7 @@ void EntityTreeElement::initializeExtraEncodeData(EncodeBitstreamParams& params) } for (uint16_t i = 0; i < _entityItems->size(); i++) { EntityItem* entity = (*_entityItems)[i]; - entityTreeElementExtraEncodeData->entities.insert(entity->getEntityItemID(), entity->getEntityProperties(params)); + entityTreeElementExtraEncodeData->entities.insert(entity->getID(), entity->getEntityProperties(params)); } // TODO: some of these inserts might be redundant!!! @@ -258,13 +258,14 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData if (child->hasEntities()) { entityTreeElementExtraEncodeData->childCompleted[i] = false; } else { - entityTreeElementExtraEncodeData->childCompleted[i] = true; // if the child doesn't have enities, it is completed + // if the child doesn't have enities, it is completed + entityTreeElementExtraEncodeData->childCompleted[i] = true; } } } for (uint16_t i = 0; i < _entityItems->size(); i++) { EntityItem* entity = (*_entityItems)[i]; - entityTreeElementExtraEncodeData->entities.insert(entity->getEntityItemID(), entity->getEntityProperties(params)); + entityTreeElementExtraEncodeData->entities.insert(entity->getID(), entity->getEntityProperties(params)); } } @@ -293,7 +294,7 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData if (hadElementExtraData) { includeThisEntity = includeThisEntity && - entityTreeElementExtraEncodeData->entities.contains(entity->getEntityItemID()); + entityTreeElementExtraEncodeData->entities.contains(entity->getID()); } if (includeThisEntity && params.viewFrustum) { @@ -338,7 +339,7 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData // If the entity item got completely appended, then we can remove it from the extra encode data if (appendEntityState == OctreeElement::COMPLETED) { - entityTreeElementExtraEncodeData->entities.remove(entity->getEntityItemID()); + entityTreeElementExtraEncodeData->entities.remove(entity->getID()); } // If any part of the entity items didn't fit, then the element is considered partial @@ -567,19 +568,6 @@ bool EntityTreeElement::findSpherePenetration(const glm::vec3& center, float rad return false; } -void EntityTreeElement::updateEntityItemID(const EntityItemID& creatorTokenEntityID, const EntityItemID& knownIDEntityID) { - uint16_t numberOfEntities = _entityItems->size(); - for (uint16_t i = 0; i < numberOfEntities; i++) { - EntityItem* thisEntity = (*_entityItems)[i]; - - EntityItemID thisEntityID = thisEntity->getEntityItemID(); - - if (thisEntityID == creatorTokenEntityID) { - thisEntity->setID(knownIDEntityID.id); - } - } -} - const EntityItem* EntityTreeElement::getClosestEntity(glm::vec3 position) const { const EntityItem* closestEntity = NULL; float closestEntityDistance = FLT_MAX; @@ -624,11 +612,11 @@ void EntityTreeElement::getEntities(const AACube& box, QVector& fou } } -const EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemID& id) const { +const EntityItem* EntityTreeElement::getEntityWithEntityItemID(const QUuid& id) const { const EntityItem* foundEntity = NULL; uint16_t numberOfEntities = _entityItems->size(); for (uint16_t i = 0; i < numberOfEntities; i++) { - if ((*_entityItems)[i]->getEntityItemID() == id) { + if ((*_entityItems)[i]->getID() == id) { foundEntity = (*_entityItems)[i]; break; } @@ -636,11 +624,11 @@ const EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemI return foundEntity; } -EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemID& id) { +EntityItem* EntityTreeElement::getEntityWithEntityItemID(const QUuid& id) { EntityItem* foundEntity = NULL; uint16_t numberOfEntities = _entityItems->size(); for (uint16_t i = 0; i < numberOfEntities; i++) { - if ((*_entityItems)[i]->getEntityItemID() == id) { + if ((*_entityItems)[i]->getID() == id) { foundEntity = (*_entityItems)[i]; break; } @@ -658,11 +646,11 @@ void EntityTreeElement::cleanupEntities() { _entityItems->clear(); } -bool EntityTreeElement::removeEntityWithEntityItemID(const EntityItemID& id) { +bool EntityTreeElement::removeEntityWithEntityItemID(const QUuid& id) { bool foundEntity = false; uint16_t numberOfEntities = _entityItems->size(); for (uint16_t i = 0; i < numberOfEntities; i++) { - if ((*_entityItems)[i]->getEntityItemID() == id) { + if ((*_entityItems)[i]->getID() == id) { foundEntity = true; (*_entityItems)[i]->_element = NULL; _entityItems->removeAt(i); @@ -718,16 +706,12 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int if (bytesLeftToRead >= (int)(numberOfEntities * expectedBytesPerEntity)) { for (uint16_t i = 0; i < numberOfEntities; i++) { int bytesForThisEntity = 0; - EntityItemID entityItemID; + QUuid entityItemID; EntityItem* entityItem = NULL; - // Old model files don't have UUIDs in them. So we don't want to try to read those IDs from the stream. - // Since this can only happen on loading an old file, we can safely treat these as new entity cases, - // 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); - } + QByteArray encodedID((const char*)dataAt, NUM_BYTES_RFC4122_UUID); + entityItemID = QUuid::fromRfc4122(encodedID); + entityItem = _myTree->findEntityByEntityItemID(entityItemID); // If the item already exists in our tree, we want do the following... // 1) allow the existing item to read from the databuffer @@ -768,7 +752,7 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int if (entityItem) { bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args); addEntityItem(entityItem); // add this new entity to this elements entities - entityItemID = entityItem->getEntityItemID(); + entityItemID = entityItem->getID(); _myTree->setContainingElement(entityItemID, this); _myTree->postAddEntity(entityItem); } diff --git a/libraries/entities/src/EntityTreeElement.h b/libraries/entities/src/EntityTreeElement.h index 658dfeab92..538772a9f8 100644 --- a/libraries/entities/src/EntityTreeElement.h +++ b/libraries/entities/src/EntityTreeElement.h @@ -47,7 +47,7 @@ public: bool elementCompleted; bool subtreeCompleted; bool childCompleted[NUMBER_OF_CHILDREN]; - QMap entities; + QMap entities; }; inline QDebug operator<<(QDebug debug, const EntityTreeElementExtraEncodeData* data) { @@ -151,9 +151,6 @@ public: bool updateEntity(const EntityItem& entity); void addEntityItem(EntityItem* entity); - - void updateEntityItemID(const EntityItemID& creatorTokenEntityID, const EntityItemID& knownIDEntityID); - const EntityItem* getClosestEntity(glm::vec3 position) const; /// finds all entities that touch a sphere @@ -168,13 +165,13 @@ public: void getEntities(const AACube& box, QVector& foundEntities); const EntityItem* getEntityWithID(uint32_t id) const; - const EntityItem* getEntityWithEntityItemID(const EntityItemID& id) const; + const EntityItem* getEntityWithEntityItemID(const QUuid& id) const; void getEntitiesInside(const AACube& box, QVector& foundEntities); - EntityItem* getEntityWithEntityItemID(const EntityItemID& id); + EntityItem* getEntityWithEntityItemID(const QUuid& id); void cleanupEntities(); /// called by EntityTree on cleanup this will free all entities - bool removeEntityWithEntityItemID(const EntityItemID& id); + bool removeEntityWithEntityItemID(const QUuid& id); bool removeEntityItem(EntityItem* entity); bool containsEntityBounds(const EntityItem* entity) const; diff --git a/libraries/entities/src/EntityTypes.cpp b/libraries/entities/src/EntityTypes.cpp index 794a77b194..fcd34a1d01 100644 --- a/libraries/entities/src/EntityTypes.cpp +++ b/libraries/entities/src/EntityTypes.cpp @@ -76,8 +76,8 @@ bool EntityTypes::registerEntityType(EntityType entityType, const char* name, En return false; } -EntityItem* EntityTypes::constructEntityItem(EntityType entityType, const EntityItemID& entityID, - const EntityItemProperties& properties) { +EntityItem* EntityTypes::constructEntityItem(EntityType entityType, const QUuid& entityID, + const EntityItemProperties& properties) { EntityItem* newEntityItem = NULL; EntityTypeFactory factory = NULL; if (entityType >= 0 && entityType <= LAST) { @@ -91,15 +91,7 @@ EntityItem* EntityTypes::constructEntityItem(EntityType entityType, const Entity return newEntityItem; } -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); - } - +EntityItem* EntityTypes::constructEntityItem(const unsigned char* data, int bytesToRead, ReadBitstreamToTreeParams& args) { // Header bytes // object ID [16 bytes] // ByteCountCoded(type code) [~1 byte] @@ -127,9 +119,8 @@ EntityItem* EntityTypes::constructEntityItem(const unsigned char* data, int byte quint32 type = typeCoder; EntityTypes::EntityType entityType = (EntityTypes::EntityType)type; - EntityItemID tempEntityID(actualID); EntityItemProperties tempProperties; - return constructEntityItem(entityType, tempEntityID, tempProperties); + return constructEntityItem(entityType, actualID, tempProperties); } return NULL; diff --git a/libraries/entities/src/EntityTypes.h b/libraries/entities/src/EntityTypes.h index b3de3dfc8e..1a8a38df32 100644 --- a/libraries/entities/src/EntityTypes.h +++ b/libraries/entities/src/EntityTypes.h @@ -14,17 +14,17 @@ #include +#include #include #include #include // for RenderArgs class EntityItem; -class EntityItemID; class EntityItemProperties; class ReadBitstreamToTreeParams; -typedef EntityItem* (*EntityTypeFactory)(const EntityItemID& entityID, const EntityItemProperties& properties); +typedef EntityItem* (*EntityTypeFactory)(const QUuid& entityID, const EntityItemProperties& properties); class EntityTypes { public: @@ -45,7 +45,8 @@ public: static const QString& getEntityTypeName(EntityType entityType); static EntityTypes::EntityType getEntityTypeFromName(const QString& name); static bool registerEntityType(EntityType entityType, const char* name, EntityTypeFactory factoryMethod); - static EntityItem* constructEntityItem(EntityType entityType, const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* constructEntityItem(EntityType entityType, + const QUuid& entityID, const EntityItemProperties& properties); static EntityItem* constructEntityItem(const unsigned char* data, int bytesToRead, ReadBitstreamToTreeParams& args); private: @@ -59,7 +60,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 /// 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: -// static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); +// static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); #define REGISTER_ENTITY_TYPE(x) static bool x##Registration = \ EntityTypes::registerEntityType(EntityTypes::x, #x, x##EntityItem::factory); @@ -67,7 +68,7 @@ private: /// 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 /// returns a newly constructed (heap allocated) instance of your type. e.g. The following prototype: -// static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); +// static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); #define REGISTER_ENTITY_TYPE_WITH_FACTORY(x,y) static bool x##Registration = \ EntityTypes::registerEntityType(EntityTypes::x, #x, y); \ if (!x##Registration) { \ diff --git a/libraries/entities/src/LightEntityItem.cpp b/libraries/entities/src/LightEntityItem.cpp index a66cb56bd2..a6d3c2fdcd 100644 --- a/libraries/entities/src/LightEntityItem.cpp +++ b/libraries/entities/src/LightEntityItem.cpp @@ -14,7 +14,6 @@ #include -#include "EntityItemID.h" #include "EntityTree.h" #include "EntityTreeElement.h" #include "EntitiesLogging.h" @@ -22,12 +21,12 @@ bool LightEntityItem::_lightsArePickable = false; -EntityItem* LightEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* LightEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { return new LightEntityItem(entityID, properties); } // our non-pure virtual subclass for now... -LightEntityItem::LightEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : +LightEntityItem::LightEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID, properties) { _type = EntityTypes::Light; diff --git a/libraries/entities/src/LightEntityItem.h b/libraries/entities/src/LightEntityItem.h index 162b40f56d..4816c921f3 100644 --- a/libraries/entities/src/LightEntityItem.h +++ b/libraries/entities/src/LightEntityItem.h @@ -16,9 +16,9 @@ class LightEntityItem : public EntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - LightEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); + LightEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); ALLOW_INSTANTIATION // This class can be instantiated diff --git a/libraries/entities/src/LineEntityItem.cpp b/libraries/entities/src/LineEntityItem.cpp index 6686f9e46a..0a07e47bad 100644 --- a/libraries/entities/src/LineEntityItem.cpp +++ b/libraries/entities/src/LineEntityItem.cpp @@ -20,12 +20,12 @@ #include "EntityTreeElement.h" -EntityItem* LineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* LineEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* result = new LineEntityItem(entityID, properties); return result; } -LineEntityItem::LineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : +LineEntityItem::LineEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) { _type = EntityTypes::Line; @@ -99,7 +99,7 @@ void LineEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits void LineEntityItem::debugDump() const { quint64 now = usecTimestampNow(); - qCDebug(entities) << " LINE EntityItem id:" << getEntityItemID() << "---------------------------------------------"; + qCDebug(entities) << " LINE EntityItem id:" << getID() << "---------------------------------------------"; qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; qCDebug(entities) << " position:" << debugTreeVector(_position); qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); diff --git a/libraries/entities/src/LineEntityItem.h b/libraries/entities/src/LineEntityItem.h index a8bc867bdd..bf1cceb51b 100644 --- a/libraries/entities/src/LineEntityItem.h +++ b/libraries/entities/src/LineEntityItem.h @@ -16,9 +16,9 @@ class LineEntityItem : public EntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - LineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); + LineEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); ALLOW_INSTANTIATION // This class can be instantiated diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index f7da57da0d..9a0ebbddde 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -28,11 +28,11 @@ const bool ModelEntityItem::DEFAULT_ANIMATION_IS_PLAYING = false; const float ModelEntityItem::DEFAULT_ANIMATION_FPS = 30.0f; -EntityItem* ModelEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* ModelEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { return new ModelEntityItem(entityID, properties); } -ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : +ModelEntityItem::ModelEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID, properties) { _type = EntityTypes::Model; @@ -267,7 +267,7 @@ void ModelEntityItem::update(const quint64& now) { } void ModelEntityItem::debugDump() const { - qCDebug(entities) << "ModelEntityItem id:" << getEntityItemID(); + qCDebug(entities) << "ModelEntityItem id:" << getID(); qCDebug(entities) << " edited ago:" << getEditedAgo(); qCDebug(entities) << " position:" << getPosition(); qCDebug(entities) << " dimensions:" << getDimensions(); diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index d4a4efda04..d52c2b1cc0 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -18,9 +18,9 @@ class ModelEntityItem : public EntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - ModelEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); + ModelEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); ALLOW_INSTANTIATION // This class can be instantiated diff --git a/libraries/entities/src/MovingEntitiesOperator.cpp b/libraries/entities/src/MovingEntitiesOperator.cpp index 1418f107bb..32dc01b950 100644 --- a/libraries/entities/src/MovingEntitiesOperator.cpp +++ b/libraries/entities/src/MovingEntitiesOperator.cpp @@ -51,7 +51,7 @@ MovingEntitiesOperator::~MovingEntitiesOperator() { void MovingEntitiesOperator::addEntityToMoveList(EntityItem* entity, const AACube& newCube) { - EntityTreeElement* oldContainingElement = _tree->getContainingElement(entity->getEntityItemID()); + EntityTreeElement* oldContainingElement = _tree->getContainingElement(entity->getID()); AABox newCubeClamped = newCube.clamp(0.0f, (float)TREE_SCALE); if (_wantDebug) { @@ -68,7 +68,7 @@ void MovingEntitiesOperator::addEntityToMoveList(EntityItem* entity, const AACub } if (!oldContainingElement) { - qCDebug(entities) << "UNEXPECTED!!!! attempting to move entity "<< entity->getEntityItemID() + qCDebug(entities) << "UNEXPECTED!!!! attempting to move entity "<< entity->getID() << "that has no containing element. "; return; // bail without adding. } @@ -90,7 +90,7 @@ void MovingEntitiesOperator::addEntityToMoveList(EntityItem* entity, const AACub if (_wantDebug) { qCDebug(entities) << "MovingEntitiesOperator::addEntityToMoveList() -----------------------------"; - qCDebug(entities) << " details.entity:" << details.entity->getEntityItemID(); + qCDebug(entities) << " details.entity:" << details.entity->getID(); qCDebug(entities) << " details.oldContainingElementCube:" << details.oldContainingElementCube; qCDebug(entities) << " details.newCube:" << details.newCube; qCDebug(entities) << " details.newCubeClamped:" << details.newCubeClamped; @@ -122,7 +122,7 @@ bool MovingEntitiesOperator::shouldRecurseSubTree(OctreeElement* element) { if (_wantDebug) { qCDebug(entities) << "MovingEntitiesOperator::shouldRecurseSubTree() details["<< detailIndex <<"]-----------------------------"; qCDebug(entities) << " element:" << element->getAACube(); - qCDebug(entities) << " details.entity:" << details.entity->getEntityItemID(); + qCDebug(entities) << " details.entity:" << details.entity->getID(); qCDebug(entities) << " details.oldContainingElementCube:" << details.oldContainingElementCube; qCDebug(entities) << " details.newCube:" << details.newCube; qCDebug(entities) << " details.newCubeClamped:" << details.newCubeClamped; @@ -167,7 +167,7 @@ bool MovingEntitiesOperator::preRecursion(OctreeElement* element) { qCDebug(entities) << "MovingEntitiesOperator::preRecursion() details["<< detailIndex <<"]-----------------------------"; qCDebug(entities) << " entityTreeElement:" << entityTreeElement->getAACube(); qCDebug(entities) << " entityTreeElement->bestFitBounds(details.newCube):" << entityTreeElement->bestFitBounds(details.newCube); - qCDebug(entities) << " details.entity:" << details.entity->getEntityItemID(); + qCDebug(entities) << " details.entity:" << details.entity->getID(); qCDebug(entities) << " details.oldContainingElementCube:" << details.oldContainingElementCube; qCDebug(entities) << " entityTreeElement:" << entityTreeElement; qCDebug(entities) << " details.newCube:" << details.newCube; @@ -193,7 +193,7 @@ bool MovingEntitiesOperator::preRecursion(OctreeElement* element) { // If this element is the best fit for the new bounds of this entity then add the entity to the element if (!details.newFound && entityTreeElement->bestFitBounds(details.newCube)) { - EntityItemID entityItemID = details.entity->getEntityItemID(); + QUuid entityItemID = details.entity->getID(); // remove from the old before adding EntityTreeElement* oldElement = details.entity->getElement(); if (oldElement != entityTreeElement) { diff --git a/libraries/entities/src/MovingEntitiesOperator.h b/libraries/entities/src/MovingEntitiesOperator.h index 760b001081..31f0cb5248 100644 --- a/libraries/entities/src/MovingEntitiesOperator.h +++ b/libraries/entities/src/MovingEntitiesOperator.h @@ -25,11 +25,11 @@ public: }; inline uint qHash(const EntityToMoveDetails& a, uint seed) { - return qHash(a.entity->getEntityItemID(), seed); + return qHash(a.entity->getID(), seed); } inline bool operator==(const EntityToMoveDetails& a, const EntityToMoveDetails& b) { - return a.entity->getEntityItemID() == b.entity->getEntityItemID(); + return a.entity->getID() == b.entity->getID(); } class MovingEntitiesOperator : public RecurseOctreeOperator { diff --git a/libraries/entities/src/ParticleEffectEntityItem.cpp b/libraries/entities/src/ParticleEffectEntityItem.cpp index 0879e49f03..2e13bfe834 100644 --- a/libraries/entities/src/ParticleEffectEntityItem.cpp +++ b/libraries/entities/src/ParticleEffectEntityItem.cpp @@ -55,12 +55,12 @@ const float ParticleEffectEntityItem::DEFAULT_PARTICLE_RADIUS = 0.025f; const QString ParticleEffectEntityItem::DEFAULT_TEXTURES = ""; -EntityItem* ParticleEffectEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* ParticleEffectEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { return new ParticleEffectEntityItem(entityID, properties); } // our non-pure virtual subclass for now... -ParticleEffectEntityItem::ParticleEffectEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : +ParticleEffectEntityItem::ParticleEffectEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID, properties), _maxParticles(DEFAULT_MAX_PARTICLES), _lifespan(DEFAULT_LIFESPAN), @@ -274,7 +274,7 @@ void ParticleEffectEntityItem::update(const quint64& now) { void ParticleEffectEntityItem::debugDump() const { quint64 now = usecTimestampNow(); - qCDebug(entities) << "PA EFFECT EntityItem id:" << getEntityItemID() << "---------------------------------------------"; + qCDebug(entities) << "PA EFFECT EntityItem id:" << getID() << "---------------------------------------------"; qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; qCDebug(entities) << " position:" << debugTreeVector(_position); qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); diff --git a/libraries/entities/src/ParticleEffectEntityItem.h b/libraries/entities/src/ParticleEffectEntityItem.h index 6d1ef601f6..532c7a700b 100644 --- a/libraries/entities/src/ParticleEffectEntityItem.h +++ b/libraries/entities/src/ParticleEffectEntityItem.h @@ -17,9 +17,9 @@ class ParticleEffectEntityItem : public EntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - ParticleEffectEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); + ParticleEffectEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); virtual ~ParticleEffectEntityItem(); ALLOW_INSTANTIATION // This class can be instantiated diff --git a/libraries/entities/src/SphereEntityItem.cpp b/libraries/entities/src/SphereEntityItem.cpp index c3bc78a2f0..1272a0c283 100644 --- a/libraries/entities/src/SphereEntityItem.cpp +++ b/libraries/entities/src/SphereEntityItem.cpp @@ -23,12 +23,12 @@ #include "SphereEntityItem.h" -EntityItem* SphereEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* SphereEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { return new SphereEntityItem(entityID, properties); } // our non-pure virtual subclass for now... -SphereEntityItem::SphereEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : +SphereEntityItem::SphereEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID, properties) { _type = EntityTypes::Sphere; @@ -117,7 +117,7 @@ bool SphereEntityItem::findDetailedRayIntersection(const glm::vec3& origin, cons void SphereEntityItem::debugDump() const { quint64 now = usecTimestampNow(); - qCDebug(entities) << "SHPERE EntityItem id:" << getEntityItemID() << "---------------------------------------------"; + qCDebug(entities) << "SHPERE EntityItem id:" << getID() << "---------------------------------------------"; qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; qCDebug(entities) << " position:" << debugTreeVector(_position); qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); diff --git a/libraries/entities/src/SphereEntityItem.h b/libraries/entities/src/SphereEntityItem.h index b6516b714f..fb3843a39d 100644 --- a/libraries/entities/src/SphereEntityItem.h +++ b/libraries/entities/src/SphereEntityItem.h @@ -16,9 +16,9 @@ class SphereEntityItem : public EntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - SphereEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); + SphereEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); ALLOW_INSTANTIATION // This class can be instantiated diff --git a/libraries/entities/src/TextEntityItem.cpp b/libraries/entities/src/TextEntityItem.cpp index 1a117dd79e..f4cbcc6199 100644 --- a/libraries/entities/src/TextEntityItem.cpp +++ b/libraries/entities/src/TextEntityItem.cpp @@ -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_BACKGROUND_COLOR = { 0, 0, 0}; -EntityItem* TextEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* TextEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* result = new TextEntityItem(entityID, properties); return result; } -TextEntityItem::TextEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : +TextEntityItem::TextEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) { _type = EntityTypes::Text; diff --git a/libraries/entities/src/TextEntityItem.h b/libraries/entities/src/TextEntityItem.h index d57b5442d6..7e26a6469f 100644 --- a/libraries/entities/src/TextEntityItem.h +++ b/libraries/entities/src/TextEntityItem.h @@ -16,9 +16,9 @@ class TextEntityItem : public EntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - TextEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); + TextEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); ALLOW_INSTANTIATION // This class can be instantiated diff --git a/libraries/entities/src/UpdateEntityOperator.cpp b/libraries/entities/src/UpdateEntityOperator.cpp index 6c1fac1ffc..6fcc1c11ef 100644 --- a/libraries/entities/src/UpdateEntityOperator.cpp +++ b/libraries/entities/src/UpdateEntityOperator.cpp @@ -25,7 +25,7 @@ UpdateEntityOperator::UpdateEntityOperator(EntityTree* tree, _containingElement(containingElement), _containingElementCube(containingElement->getAACube()), _properties(properties), - _entityItemID(existingEntity->getEntityItemID()), + _entityItemID(existingEntity->getID()), _foundOld(false), _foundNew(false), _removeOld(false), diff --git a/libraries/entities/src/UpdateEntityOperator.h b/libraries/entities/src/UpdateEntityOperator.h index 8d40ddfd57..54d6c36e99 100644 --- a/libraries/entities/src/UpdateEntityOperator.h +++ b/libraries/entities/src/UpdateEntityOperator.h @@ -15,7 +15,7 @@ class UpdateEntityOperator : public RecurseOctreeOperator { public: UpdateEntityOperator(EntityTree* tree, EntityTreeElement* containingElement, - EntityItem* existingEntity, const EntityItemProperties& properties); + EntityItem* existingEntity, const EntityItemProperties& properties); ~UpdateEntityOperator(); virtual bool preRecursion(OctreeElement* element); @@ -27,7 +27,7 @@ private: EntityTreeElement* _containingElement; AACube _containingElementCube; // we temporarily store our cube here in case we need to delete the containing element EntityItemProperties _properties; - EntityItemID _entityItemID; + QUuid _entityItemID; bool _foundOld; bool _foundNew; bool _removeOld; diff --git a/libraries/entities/src/WebEntityItem.cpp b/libraries/entities/src/WebEntityItem.cpp index 48b03a48f6..d4ed10a01a 100644 --- a/libraries/entities/src/WebEntityItem.cpp +++ b/libraries/entities/src/WebEntityItem.cpp @@ -22,12 +22,12 @@ const QString WebEntityItem::DEFAULT_SOURCE_URL("http://www.google.com"); -EntityItem* WebEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* WebEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* result = new WebEntityItem(entityID, properties); return result; } -WebEntityItem::WebEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : +WebEntityItem::WebEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) { _type = EntityTypes::Web; @@ -150,4 +150,4 @@ void WebEntityItem::setSourceUrl(const QString& value) { } } -const QString& WebEntityItem::getSourceUrl() const { return _sourceUrl; } \ No newline at end of file +const QString& WebEntityItem::getSourceUrl() const { return _sourceUrl; } diff --git a/libraries/entities/src/WebEntityItem.h b/libraries/entities/src/WebEntityItem.h index 35e98b2092..33dbd716f4 100644 --- a/libraries/entities/src/WebEntityItem.h +++ b/libraries/entities/src/WebEntityItem.h @@ -15,9 +15,9 @@ class WebEntityItem : public EntityItem { public: static const QString DEFAULT_SOURCE_URL; - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - WebEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); + WebEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); ALLOW_INSTANTIATION // This class can be instantiated diff --git a/libraries/entities/src/ZoneEntityItem.cpp b/libraries/entities/src/ZoneEntityItem.cpp index 1846d16e25..e7024701db 100644 --- a/libraries/entities/src/ZoneEntityItem.cpp +++ b/libraries/entities/src/ZoneEntityItem.cpp @@ -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 QString ZoneEntityItem::DEFAULT_COMPOUND_SHAPE_URL = ""; -EntityItem* ZoneEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItem* ZoneEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { EntityItem* result = new ZoneEntityItem(entityID, properties); return result; } -ZoneEntityItem::ZoneEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : +ZoneEntityItem::ZoneEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) { _type = EntityTypes::Zone; @@ -216,8 +216,9 @@ void ZoneEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits void ZoneEntityItem::debugDump() const { quint64 now = usecTimestampNow(); - qCDebug(entities) << " ZoneEntityItem id:" << getEntityItemID() << "---------------------------------------------"; - qCDebug(entities) << " keyLightColor:" << _keyLightColor[0] << "," << _keyLightColor[1] << "," << _keyLightColor[2]; + qCDebug(entities) << " ZoneEntityItem id:" << getID() << "---------------------------------------------"; + qCDebug(entities) << " keyLightColor:" << _keyLightColor[0] << "," + << _keyLightColor[1] << "," << _keyLightColor[2]; qCDebug(entities) << " position:" << debugTreeVector(_position); qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); diff --git a/libraries/entities/src/ZoneEntityItem.h b/libraries/entities/src/ZoneEntityItem.h index f1d88f986c..2077fd364f 100644 --- a/libraries/entities/src/ZoneEntityItem.h +++ b/libraries/entities/src/ZoneEntityItem.h @@ -19,9 +19,9 @@ class ZoneEntityItem : public EntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - ZoneEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); + ZoneEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); ALLOW_INSTANTIATION // This class can be instantiated diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 3986762f6f..168c0ef0c2 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -334,7 +334,6 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep, const QUuid& s void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const QUuid& sessionID, uint32_t step) { assert(_entity); - assert(_entity->isKnownID()); bool active = _body->isActive(); if (!active) { @@ -428,7 +427,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q } if (EntityItem::getSendPhysicsUpdates()) { - EntityItemID id(_entity->getID()); + QUuid id(_entity->getID()); EntityEditPacketSender* entityPacketSender = static_cast(packetSender); #ifdef WANT_DEBUG qCDebug(physics) << "EntityMotionState::sendUpdate()... calling queueEditEntityMessage()..."; diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index 3e43ab7454..06fbdce6be 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -196,7 +196,7 @@ void PhysicalEntitySimulation::handleOutgoingChanges(VectorOfMotionStates& motio EntityMotionState* entityState = static_cast(state); EntityItem* entity = entityState->getEntity(); if (entity) { - if (entity->isKnownID() && entityState->isCandidateForOwnership(sessionID)) { + if (entityState->isCandidateForOwnership(sessionID)) { _outgoingChanges.insert(entityState); } _entitiesToSort.insert(entityState->getEntity()); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index f02ef3a549..8668fb02d3 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -319,9 +319,8 @@ void ScriptEngine::init() { registerAudioMetaTypes(this); qScriptRegisterMetaType(this, EntityItemPropertiesToScriptValue, EntityItemPropertiesFromScriptValue); - qScriptRegisterMetaType(this, EntityItemIDtoScriptValue, EntityItemIDfromScriptValue); qScriptRegisterMetaType(this, RayToEntityIntersectionResultToScriptValue, RayToEntityIntersectionResultFromScriptValue); - qScriptRegisterSequenceMetaType >(this); + qScriptRegisterSequenceMetaType >(this); qScriptRegisterSequenceMetaType >(this); qScriptRegisterSequenceMetaType >(this); diff --git a/libraries/shared/src/RegisteredMetaTypes.cpp b/libraries/shared/src/RegisteredMetaTypes.cpp index 8c9d0c27bd..eb60e1c31d 100644 --- a/libraries/shared/src/RegisteredMetaTypes.cpp +++ b/libraries/shared/src/RegisteredMetaTypes.cpp @@ -200,11 +200,18 @@ void collisionFromScriptValue(const QScriptValue &object, Collision& collision) } QScriptValue quuidToScriptValue(QScriptEngine* engine, const QUuid& uuid) { + if (uuid.isNull()) { + return QScriptValue::NullValue; + } QScriptValue obj(uuid.toString()); return obj; } void quuidFromScriptValue(const QScriptValue& object, QUuid& uuid) { + if (object.isNull()) { + uuid = QUuid(); + return; + } QString uuidAsString = object.toVariant().toString(); QUuid fromString(uuidAsString); uuid = fromString; diff --git a/tests/octree/src/ModelTests.cpp b/tests/octree/src/ModelTests.cpp index 2e2b873115..acd4d4dc18 100644 --- a/tests/octree/src/ModelTests.cpp +++ b/tests/octree/src/ModelTests.cpp @@ -40,9 +40,7 @@ void EntityTests::entityTreeTests(bool verbose) { // Tree, id, and entity properties used in many tests below... EntityTree tree; - QUuid id = QUuid::createUuid(); - EntityItemID entityID(id); - entityID.isKnownID = false; // this is a temporary workaround to allow local tree entities to be added with known IDs + QUuid entityID = QUuid::createUuid(); EntityItemProperties properties; float oneMeter = 1.0f; float halfOfDomain = TREE_SCALE * 0.5f; @@ -90,8 +88,6 @@ void EntityTests::entityTreeTests(bool verbose) { } } - entityID.isKnownID = true; // this is a temporary workaround to allow local tree entities to be added with known IDs - { testsTaken++; QString testName = "change position of entity in tree"; @@ -251,9 +247,7 @@ void EntityTests::entityTreeTests(bool verbose) { quint64 totalElapsedAdd = 0; quint64 totalElapsedFind = 0; for (int i = 0; i < TEST_ITERATIONS; i++) { - QUuid id = QUuid::createUuid();// make sure it doesn't collide with previous entity ids - EntityItemID entityID(id); - entityID.isKnownID = false; // this is a temporary workaround to allow local tree entities to be added with known IDs + QUuid entityID = QUuid::createUuid();// make sure it doesn't collide with previous entity ids float randomX = randFloatInRange(1.0f ,(float)TREE_SCALE - 1.0f); float randomY = randFloatInRange(1.0f ,(float)TREE_SCALE - 1.0f); @@ -355,9 +349,7 @@ void EntityTests::entityTreeTests(bool verbose) { quint64 totalElapsedDelete = 0; quint64 totalElapsedFind = 0; for (int i = 0; i < TEST_ITERATIONS; i++) { - QUuid id = QUuid::createUuid();// make sure it doesn't collide with previous entity ids - EntityItemID entityID(id); - entityID.isKnownID = true; // this is a temporary workaround to allow local tree entities to be added with known IDs + QUuid entityID = QUuid::createUuid();// make sure it doesn't collide with previous entity ids if (extraVerbose) { qDebug() << "before:" << i << "getOctreeElementsCount()=" << tree.getOctreeElementsCount(); @@ -436,11 +428,9 @@ void EntityTests::entityTreeTests(bool verbose) { quint64 totalElapsedFind = 0; for (int i = 0; i < TEST_ITERATIONS; i++) { - QSet entitiesToDelete; + QSet entitiesToDelete; for (int j = 0; j < ENTITIES_PER_ITERATION; j++) { //uint32_t id = 2 + (i * ENTITIES_PER_ITERATION) + j; // These are the entities we added above - QUuid id = QUuid::createUuid();// make sure it doesn't collide with previous entity ids - EntityItemID entityID(id); entitiesToDelete << entityID; } @@ -460,8 +450,7 @@ void EntityTests::entityTreeTests(bool verbose) { quint64 startFind = usecTimestampNow(); for (int j = 0; j < ENTITIES_PER_ITERATION; j++) { //uint32_t id = 2 + (i * ENTITIES_PER_ITERATION) + j; // These are the entities we added above - QUuid id = QUuid::createUuid();// make sure it doesn't collide with previous entity ids - EntityItemID entityID(id); + QUuid entityID = QUuid::createUuid();// make sure it doesn't collide with previous entity ids const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID); EntityTreeElement* containingElement = tree.getContainingElement(entityID); From b32e069f1da043662db984a0ace737bdc54ea640 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 19 May 2015 14:45:01 -0700 Subject: [PATCH 2/8] bump protocol version --- libraries/networking/src/PacketHeaders.cpp | 2 +- libraries/networking/src/PacketHeaders.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/networking/src/PacketHeaders.cpp b/libraries/networking/src/PacketHeaders.cpp index 689c958cbb..262d1175b6 100644 --- a/libraries/networking/src/PacketHeaders.cpp +++ b/libraries/networking/src/PacketHeaders.cpp @@ -72,7 +72,7 @@ PacketVersion versionForPacketType(PacketType packetType) { return 1; case PacketTypeEntityAddOrEdit: case PacketTypeEntityData: - return VERSION_ENTITIES_HAVE_FRICTION; + return VERSION_NO_ENTITY_ID_SWAP; case PacketTypeEntityErase: return 2; case PacketTypeAudioStreamStats: diff --git a/libraries/networking/src/PacketHeaders.h b/libraries/networking/src/PacketHeaders.h index b4e630c677..af4f0bf683 100644 --- a/libraries/networking/src/PacketHeaders.h +++ b/libraries/networking/src/PacketHeaders.h @@ -178,5 +178,6 @@ const PacketVersion VERSION_ENTITIES_PARTICLE_ENTITIES_HAVE_TEXTURES = 23; const PacketVersion VERSION_ENTITIES_HAVE_LINE_TYPE = 24; const PacketVersion VERSION_ENTITIES_HAVE_COLLISION_SOUND_URL = 25; const PacketVersion VERSION_ENTITIES_HAVE_FRICTION = 26; +const PacketVersion VERSION_NO_ENTITY_ID_SWAP = 27; #endif // hifi_PacketHeaders_h From a769cfdaf2353462770f0be06092fcd9f7c3daf6 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 20 May 2015 10:42:19 -0700 Subject: [PATCH 3/8] client decides on new entity-ids, keep EntityItemID class --- interface/src/Application.cpp | 8 +- interface/src/Application.h | 4 +- .../scripting/ClipboardScriptingInterface.cpp | 4 +- .../scripting/ClipboardScriptingInterface.h | 4 +- .../src/EntityTreeRenderer.cpp | 83 +++++++-------- .../src/EntityTreeRenderer.h | 52 ++++----- .../src/RenderableBoxEntityItem.cpp | 2 +- .../src/RenderableBoxEntityItem.h | 4 +- .../src/RenderableLightEntityItem.cpp | 2 +- .../src/RenderableLightEntityItem.h | 4 +- .../src/RenderableLineEntityItem.cpp | 2 +- .../src/RenderableLineEntityItem.h | 4 +- .../src/RenderableModelEntityItem.cpp | 2 +- .../src/RenderableModelEntityItem.h | 4 +- .../RenderableParticleEffectEntityItem.cpp | 5 +- .../src/RenderableParticleEffectEntityItem.h | 4 +- .../src/RenderableSphereEntityItem.cpp | 2 +- .../src/RenderableSphereEntityItem.h | 4 +- .../src/RenderableTextEntityItem.cpp | 4 +- .../src/RenderableTextEntityItem.h | 4 +- .../src/RenderableWebEntityItem.cpp | 6 +- .../src/RenderableWebEntityItem.h | 4 +- .../src/RenderableZoneEntityItem.cpp | 2 +- .../src/RenderableZoneEntityItem.h | 4 +- libraries/entities/src/AddEntityOperator.cpp | 2 +- libraries/entities/src/BoxEntityItem.cpp | 6 +- libraries/entities/src/BoxEntityItem.h | 4 +- .../entities/src/DeleteEntityOperator.cpp | 6 +- libraries/entities/src/DeleteEntityOperator.h | 8 +- .../entities/src/EntityEditPacketSender.cpp | 6 +- .../entities/src/EntityEditPacketSender.h | 4 +- libraries/entities/src/EntityItem.cpp | 34 +++--- libraries/entities/src/EntityItem.h | 10 +- libraries/entities/src/EntityItemID.cpp | 57 ++++++++++ libraries/entities/src/EntityItemID.h | 71 +++++++++++++ .../entities/src/EntityItemProperties.cpp | 12 +-- libraries/entities/src/EntityItemProperties.h | 11 +- .../entities/src/EntityScriptingInterface.cpp | 46 ++++---- .../entities/src/EntityScriptingInterface.h | 52 ++++----- libraries/entities/src/EntitySimulation.cpp | 4 +- libraries/entities/src/EntitySimulation.h | 2 +- libraries/entities/src/EntityTree.cpp | 100 +++++++++--------- libraries/entities/src/EntityTree.h | 33 +++--- libraries/entities/src/EntityTreeElement.cpp | 37 ++++--- libraries/entities/src/EntityTreeElement.h | 8 +- libraries/entities/src/EntityTypes.cpp | 17 ++- libraries/entities/src/EntityTypes.h | 11 +- libraries/entities/src/LightEntityItem.cpp | 5 +- libraries/entities/src/LightEntityItem.h | 4 +- libraries/entities/src/LineEntityItem.cpp | 6 +- libraries/entities/src/LineEntityItem.h | 4 +- libraries/entities/src/ModelEntityItem.cpp | 6 +- libraries/entities/src/ModelEntityItem.h | 4 +- .../entities/src/MovingEntitiesOperator.h | 4 +- .../entities/src/ParticleEffectEntityItem.cpp | 6 +- .../entities/src/ParticleEffectEntityItem.h | 4 +- libraries/entities/src/SphereEntityItem.cpp | 6 +- libraries/entities/src/SphereEntityItem.h | 4 +- libraries/entities/src/TextEntityItem.cpp | 4 +- libraries/entities/src/TextEntityItem.h | 4 +- .../entities/src/UpdateEntityOperator.cpp | 2 +- libraries/entities/src/UpdateEntityOperator.h | 4 +- libraries/entities/src/WebEntityItem.cpp | 6 +- libraries/entities/src/WebEntityItem.h | 4 +- libraries/entities/src/ZoneEntityItem.cpp | 9 +- libraries/entities/src/ZoneEntityItem.h | 4 +- libraries/physics/src/EntityMotionState.cpp | 2 +- tests/octree/src/ModelTests.cpp | 16 ++- 68 files changed, 509 insertions(+), 358 deletions(-) create mode 100644 libraries/entities/src/EntityItemID.cpp create mode 100644 libraries/entities/src/EntityItemID.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f91fbd46b9..37ee116f40 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1975,7 +1975,7 @@ void Application::toggleFaceTrackerMute() { } } -bool Application::exportEntities(const QString& filename, const QVector& entityIDs) { +bool Application::exportEntities(const QString& filename, const QVector& entityIDs) { QVector entities; auto entityTree = _entities.getTree(); @@ -2006,7 +2006,7 @@ bool Application::exportEntities(const QString& filename, const QVector& auto properties = entityItem->getProperties(); properties.setPosition(properties.getPosition() - root); - exportTree.addEntity(entityItem->getID(), properties); + exportTree.addEntity(entityItem->getEntityItemID(), properties); } 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++) { EntityItemProperties properties = entities.at(i)->getProperties(); - QUuid id = entities.at(i)->getID(); + EntityItemID id = entities.at(i)->getEntityItemID(); properties.setPosition(properties.getPosition() - root); exportTree.addEntity(id, properties); } @@ -2075,7 +2075,7 @@ bool Application::importEntities(const QString& urlOrFilename) { return success; } -QVector Application::pasteEntities(float x, float y, float z) { +QVector Application::pasteEntities(float x, float y, float z) { return _entityClipboard.sendEntities(&_entityEditSender, _entities.getTree(), x, y, z); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 8676be5a6e..83fc74aed4 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -383,8 +383,8 @@ public slots: void nodeKilled(SharedNodePointer node); void packetSent(quint64 length); - QVector pasteEntities(float x, float y, float z); - bool exportEntities(const QString& filename, const QVector& entityIDs); + QVector pasteEntities(float x, float y, float z); + bool exportEntities(const QString& filename, const QVector& entityIDs); bool exportEntities(const QString& filename, float x, float y, float z, float scale); bool importEntities(const QString& url); diff --git a/interface/src/scripting/ClipboardScriptingInterface.cpp b/interface/src/scripting/ClipboardScriptingInterface.cpp index adeeae74d1..f833ad43cc 100644 --- a/interface/src/scripting/ClipboardScriptingInterface.cpp +++ b/interface/src/scripting/ClipboardScriptingInterface.cpp @@ -18,7 +18,7 @@ float ClipboardScriptingInterface::getClipboardContentsLargestDimension() { return Application::getInstance()->getEntityClipboard()->getContentsLargestDimension(); } -bool ClipboardScriptingInterface::exportEntities(const QString& filename, const QVector& entityIDs) { +bool ClipboardScriptingInterface::exportEntities(const QString& filename, const QVector& entityIDs) { return Application::getInstance()->exportEntities(filename, entityIDs); } @@ -30,6 +30,6 @@ bool ClipboardScriptingInterface::importEntities(const QString& filename) { return Application::getInstance()->importEntities(filename); } -QVector ClipboardScriptingInterface::pasteEntities(glm::vec3 position) { +QVector ClipboardScriptingInterface::pasteEntities(glm::vec3 position) { return Application::getInstance()->pasteEntities(position.x, position.y, position.z); } diff --git a/interface/src/scripting/ClipboardScriptingInterface.h b/interface/src/scripting/ClipboardScriptingInterface.h index 5a5fd55711..73bebd4836 100644 --- a/interface/src/scripting/ClipboardScriptingInterface.h +++ b/interface/src/scripting/ClipboardScriptingInterface.h @@ -24,9 +24,9 @@ signals: public slots: float getClipboardContentsLargestDimension(); /// returns the largest dimension of everything on the clipboard bool importEntities(const QString& filename); - bool exportEntities(const QString& filename, const QVector& entityIDs); + bool exportEntities(const QString& filename, const QVector& entityIDs); bool exportEntities(const QString& filename, float x, float y, float z, float s); - QVector pasteEntities(glm::vec3 position); + QVector pasteEntities(glm::vec3 position); }; #endif // hifi_ClipboardScriptingInterface_h diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 2d58307823..c8b20e92e1 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -66,8 +66,8 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterf REGISTER_ENTITY_TYPE_WITH_FACTORY(Zone, RenderableZoneEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(Line, RenderableLineEntityItem::factory) - _currentHoverOverEntityID = QUuid(); // makes it the unknown ID - _currentClickingOnEntityID = QUuid(); // makes it the unknown ID + _currentHoverOverEntityID = UNKNOWN_ENTITY_ID; + _currentClickingOnEntityID = UNKNOWN_ENTITY_ID; } EntityTreeRenderer::~EntityTreeRenderer() { @@ -86,7 +86,7 @@ EntityTreeRenderer::~EntityTreeRenderer() { void EntityTreeRenderer::clear() { leaveAllEntities(); - foreach (const QUuid& entityID, _entityScripts.keys()) { + foreach (const EntityItemID& entityID, _entityScripts.keys()) { checkAndCallUnload(entityID); } OctreeRenderer::clear(); @@ -123,9 +123,9 @@ void EntityTreeRenderer::shutdown() { void EntityTreeRenderer::scriptContentsAvailable(const QUrl& url, const QString& scriptContents) { if (_waitingOnPreload.contains(url)) { - QList entityIDs = _waitingOnPreload.values(url); + QList entityIDs = _waitingOnPreload.values(url); _waitingOnPreload.remove(url); - foreach(QUuid entityID, entityIDs) { + foreach(EntityItemID entityID, entityIDs) { 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(_tree)->findEntityByEntityItemID(entityItemID); 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 // 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. - QUuid entityID = entity->getID(); + EntityItemID entityID = entity->getEntityItemID(); QString entityScript = entity->getScript(); if (_entityScripts.contains(entityID)) { @@ -282,7 +282,7 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity, bool isPre return entityScriptObject; // newly constructed } -QScriptValue EntityTreeRenderer::getPreviouslyLoadedEntityScript(const QUuid& entityID) { +QScriptValue EntityTreeRenderer::getPreviouslyLoadedEntityScript(const EntityItemID& entityID) { if (_entityScripts.contains(entityID)) { EntityScriptDetails details = _entityScripts[entityID]; 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 // 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 - if (_lastMouseEventValid && !_currentClickingOnEntityID.isNull()) { + if (_lastMouseEventValid && !_currentClickingOnEntityID.isInvalidID()) { emit holdingClickOnEntity(_currentClickingOnEntityID, _lastMouseEvent); QScriptValueList currentClickingEntityArgs = createMouseEventArgs(_currentClickingOnEntityID, _lastMouseEvent); QScriptValue currentClickingEntity = loadEntityScript(_currentClickingOnEntityID); @@ -325,7 +325,7 @@ void EntityTreeRenderer::checkEnterLeaveEntities() { if (avatarPosition != _lastAvatarPosition) { float radius = 1.0f; // for now, assume 1 meter radius QVector foundEntities; - QVector entitiesContainingAvatar; + QVector entitiesContainingAvatar; // find the entities near us _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 foreach(const EntityItem* entity, foundEntities) { if (entity->contains(avatarPosition)) { - entitiesContainingAvatar << entity->getID(); + entitiesContainingAvatar << entity->getEntityItemID(); } } _tree->unlock(); @@ -344,7 +344,7 @@ void EntityTreeRenderer::checkEnterLeaveEntities() { // 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 - foreach(const QUuid& entityID, _currentEntitiesInside) { + foreach(const EntityItemID& entityID, _currentEntitiesInside) { if (!entitiesContainingAvatar.contains(entityID)) { emit leaveEntity(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 - foreach(const QUuid& entityID, entitiesContainingAvatar) { + foreach(const EntityItemID& entityID, entitiesContainingAvatar) { if (!_currentEntitiesInside.contains(entityID)) { emit enterEntity(entityID); QScriptValueList entityArgs = createEntityArgs(entityID); @@ -377,7 +377,7 @@ void EntityTreeRenderer::leaveAllEntities() { if (_tree && !_shuttingDown) { // 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); QScriptValueList entityArgs = createEntityArgs(entityID); QScriptValue entityScript = loadEntityScript(entityID); @@ -704,7 +704,7 @@ void EntityTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) } else { // in the case of the volume being equal, we will use the // EntityItemID to deterministically pick one entity over the other - if (entityItem->getID() < _bestZone->getID()) { + if (entityItem->getEntityItemID() < _bestZone->getEntityItemID()) { _bestZoneVolume = entityVolumeEstimate; _bestZone = dynamic_cast(entityItem); } @@ -840,7 +840,7 @@ RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(cons (void**)&intersectedEntity, lockType, &result.accurate, precisionPicking); if (result.intersects && intersectedEntity) { - result.entityID = intersectedEntity->getID(); + result.entityID = intersectedEntity->getEntityItemID(); result.properties = intersectedEntity->getProperties(); result.intersection = ray.origin + (ray.direction * result.distance); result.entity = intersectedEntity; @@ -875,24 +875,24 @@ void EntityTreeRenderer::connectSignalsToSlots(EntityScriptingInterface* entityS 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; - args << quuidToScriptValue(_entitiesScriptEngine, entityID); + args << entityID.toScriptValue(_entitiesScriptEngine); args << MouseEvent(*event, deviceID).toScriptValue(_entitiesScriptEngine); return args; } -QScriptValueList EntityTreeRenderer::createMouseEventArgs(const QUuid& entityID, const MouseEvent& mouseEvent) { +QScriptValueList EntityTreeRenderer::createMouseEventArgs(const EntityItemID& entityID, const MouseEvent& mouseEvent) { QScriptValueList args; - args << quuidToScriptValue(_entitiesScriptEngine, entityID); + args << entityID.toScriptValue(_entitiesScriptEngine); args << mouseEvent.toScriptValue(_entitiesScriptEngine); return args; } -QScriptValueList EntityTreeRenderer::createEntityArgs(const QUuid& entityID) { +QScriptValueList EntityTreeRenderer::createEntityArgs(const EntityItemID& entityID) { QScriptValueList args; - args << quuidToScriptValue(_entitiesScriptEngine, entityID); + args << entityID.toScriptValue(_entitiesScriptEngine); 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 // we're releasing the button, then this is considered a clickOn event - if (!_currentClickingOnEntityID.isNull()) { + if (!_currentClickingOnEntityID.isInvalidID()) { emit clickReleaseOnEntity(_currentClickingOnEntityID, MouseEvent(*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 - _currentClickingOnEntityID = QUuid(); + _currentClickingOnEntityID = UNKNOWN_ENTITY_ID; _lastMouseEvent = MouseEvent(*event, deviceID); _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 // 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)); QScriptValueList currentHoverEntityArgs = createMouseEventArgs(_currentHoverOverEntityID, event, deviceID); @@ -1031,7 +1031,7 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI // 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 // send the hover leave for our previous entity - if (!_currentHoverOverEntityID.isNull()) { + if (!_currentHoverOverEntityID.isInvalidID()) { emit hoverLeaveEntity(_currentHoverOverEntityID, MouseEvent(*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); } - _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 // 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)); QScriptValueList currentClickingEntityArgs = createMouseEventArgs(_currentClickingOnEntityID, event, deviceID); @@ -1061,25 +1061,25 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI _lastMouseEventValid = true; } -void EntityTreeRenderer::deletingEntity(const QUuid& entityID) { +void EntityTreeRenderer::deletingEntity(const EntityItemID& entityID) { if (_tree && !_shuttingDown) { checkAndCallUnload(entityID); } _entityScripts.remove(entityID); } -void EntityTreeRenderer::addingEntity(const QUuid& entityID) { +void EntityTreeRenderer::addingEntity(const EntityItemID& entityID) { checkAndCallPreload(entityID); } -void EntityTreeRenderer::entitySciptChanging(const QUuid& entityID) { +void EntityTreeRenderer::entitySciptChanging(const EntityItemID& entityID) { if (_tree && !_shuttingDown) { checkAndCallUnload(entityID); checkAndCallPreload(entityID); } } -void EntityTreeRenderer::checkAndCallPreload(const QUuid& entityID) { +void EntityTreeRenderer::checkAndCallPreload(const EntityItemID& entityID) { if (_tree && !_shuttingDown) { // load the entity script if needed... 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) { QScriptValue entityScript = getPreviouslyLoadedEntityScript(entityID); 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)) { EntityScriptDetails details = _entityScripts[oldEntityID]; _entityScripts.remove(oldEntityID); @@ -1109,8 +1109,7 @@ void EntityTreeRenderer::changingEntityID(const QUuid& oldEntityID, const QUuid& } } -void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityTree* entityTree, - const QUuid& id, const Collision& collision) { +void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityTree* entityTree, const EntityItemID& id, const Collision& collision) { EntityItem* entity = entityTree->findEntityByEntityItemID(id); if (!entity) { return; @@ -1168,8 +1167,8 @@ void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityT injectorThread->start(); } -void EntityTreeRenderer::entityCollisionWithEntity(const QUuid& idA, const QUuid& idB, - const Collision& collision) { +void EntityTreeRenderer::entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, + const Collision& collision) { // If we don't have a tree, or we're in the process of shutting down, then don't // process these events. if (!_tree || _shuttingDown) { @@ -1199,8 +1198,8 @@ void EntityTreeRenderer::entityCollisionWithEntity(const QUuid& idA, const QUuid QScriptValue entityScriptA = loadEntityScript(idA); if (entityScriptA.property("collisionWithEntity").isValid()) { QScriptValueList args; - args << quuidToScriptValue(_entitiesScriptEngine, idA); - args << quuidToScriptValue(_entitiesScriptEngine, idB); + args << idA.toScriptValue(_entitiesScriptEngine); + args << idB.toScriptValue(_entitiesScriptEngine); args << collisionToScriptValue(_entitiesScriptEngine, collision); entityScriptA.property("collisionWithEntity").call(entityScriptA, args); } @@ -1208,8 +1207,8 @@ void EntityTreeRenderer::entityCollisionWithEntity(const QUuid& idA, const QUuid QScriptValue entityScriptB = loadEntityScript(idB); if (entityScriptB.property("collisionWithEntity").isValid()) { QScriptValueList args; - args << quuidToScriptValue(_entitiesScriptEngine, idA); - args << quuidToScriptValue(_entitiesScriptEngine, idB); + args << idB.toScriptValue(_entitiesScriptEngine); + args << idA.toScriptValue(_entitiesScriptEngine); args << collisionToScriptValue(_entitiesScriptEngine, collision); entityScriptB.property("collisionWithEntity").call(entityScriptA, args); } diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index 8ca7fff2dd..9768d4a20a 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -97,23 +97,23 @@ signals: void mouseMoveOnEntity(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 holdingClickOnEntity(const QUuid& entityItemID, const MouseEvent& event); - void clickReleaseOnEntity(const QUuid& entityItemID, const MouseEvent& event); + void clickDownOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); + void holdingClickOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); + void clickReleaseOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); - void hoverEnterEntity(const QUuid& entityItemID, const MouseEvent& event); - void hoverOverEntity(const QUuid& entityItemID, const MouseEvent& event); - void hoverLeaveEntity(const QUuid& entityItemID, const MouseEvent& event); + void hoverEnterEntity(const EntityItemID& entityItemID, const MouseEvent& event); + void hoverOverEntity(const EntityItemID& entityItemID, const MouseEvent& event); + void hoverLeaveEntity(const EntityItemID& entityItemID, const MouseEvent& event); - void enterEntity(const QUuid& entityItemID); - void leaveEntity(const QUuid& entityItemID); + void enterEntity(const EntityItemID& entityItemID); + void leaveEntity(const EntityItemID& entityItemID); public slots: - void addingEntity(const QUuid& entityID); - void deletingEntity(const QUuid& entityID); - void changingEntityID(const QUuid& oldEntityID, const QUuid& newEntityID); - void entitySciptChanging(const QUuid& entityID); - void entityCollisionWithEntity(const QUuid& idA, const QUuid& idB, const Collision& collision); + void addingEntity(const EntityItemID& entityID); + void deletingEntity(const EntityItemID& entityID); + void changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID); + void entitySciptChanging(const EntityItemID& entityID); + void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); // optional slots that can be wired to menu items void setDisplayElementChildProxies(bool value) { _displayElementChildProxies = value; } @@ -126,37 +126,37 @@ protected: private: void renderElementProxy(EntityTreeElement* entityTreeElement); - void checkAndCallPreload(const QUuid& entityID); - void checkAndCallUnload(const QUuid& entityID); + void checkAndCallPreload(const EntityItemID& entityID); + void checkAndCallUnload(const EntityItemID& entityID); QList _releasedModels; void renderProxies(const EntityItem* entity, RenderArgs* args); RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, bool precisionPicking); - QUuid _currentHoverOverEntityID; - QUuid _currentClickingOnEntityID; + EntityItemID _currentHoverOverEntityID; + EntityItemID _currentClickingOnEntityID; - QScriptValueList createEntityArgs(const QUuid& entityID); + QScriptValueList createEntityArgs(const EntityItemID& entityID); void checkEnterLeaveEntities(); void leaveAllEntities(); glm::vec3 _lastAvatarPosition; - QVector _currentEntitiesInside; + QVector _currentEntitiesInside; bool _wantScripts; ScriptEngine* _entitiesScriptEngine; ScriptEngine* _sandboxScriptEngine; QScriptValue loadEntityScript(EntityItem* entity, bool isPreload = false); - QScriptValue loadEntityScript(const QUuid& entityItemID, bool isPreload = false); - QScriptValue getPreviouslyLoadedEntityScript(const QUuid& entityItemID); + QScriptValue loadEntityScript(const EntityItemID& entityItemID, bool isPreload = false); + QScriptValue getPreviouslyLoadedEntityScript(const EntityItemID& entityItemID); QString loadScriptContents(const QString& scriptMaybeURLorText, bool& isURL, bool& isPending, QUrl& url); - QScriptValueList createMouseEventArgs(const QUuid& entityID, QMouseEvent* event, unsigned int deviceID); - QScriptValueList createMouseEventArgs(const QUuid& entityID, const MouseEvent& mouseEvent); + QScriptValueList createMouseEventArgs(const EntityItemID& entityID, QMouseEvent* event, unsigned int deviceID); + QScriptValueList createMouseEventArgs(const EntityItemID& entityID, const MouseEvent& mouseEvent); - QHash _entityScripts; + QHash _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 bool _lastMouseEventValid; @@ -170,7 +170,7 @@ private: bool _shuttingDown = false; - QMultiMap _waitingOnPreload; + QMultiMap _waitingOnPreload; bool _hasPreviousZone = false; const ZoneEntityItem* _bestZone; diff --git a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp index 063249c775..13df04e2e7 100644 --- a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp @@ -18,7 +18,7 @@ #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); } diff --git a/libraries/entities-renderer/src/RenderableBoxEntityItem.h b/libraries/entities-renderer/src/RenderableBoxEntityItem.h index 7bdf9ab6f2..cda725056c 100644 --- a/libraries/entities-renderer/src/RenderableBoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderableBoxEntityItem.h @@ -17,9 +17,9 @@ class RenderableBoxEntityItem : public BoxEntityItem { 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) { } diff --git a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp index 1874ceecc1..838c9fd8c4 100644 --- a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp @@ -19,7 +19,7 @@ #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); } diff --git a/libraries/entities-renderer/src/RenderableLightEntityItem.h b/libraries/entities-renderer/src/RenderableLightEntityItem.h index 53c3b61c6d..cfafb85983 100644 --- a/libraries/entities-renderer/src/RenderableLightEntityItem.h +++ b/libraries/entities-renderer/src/RenderableLightEntityItem.h @@ -16,9 +16,9 @@ class RenderableLightEntityItem : public LightEntityItem { 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) { } diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index e03e91182b..14628d0a7a 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -18,7 +18,7 @@ #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); } diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.h b/libraries/entities-renderer/src/RenderableLineEntityItem.h index f77954800a..0de7cd43ae 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.h +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.h @@ -17,9 +17,9 @@ class RenderableLineEntityItem : public LineEntityItem { 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) { } virtual void render(RenderArgs* args); diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 175b5847e0..43112d7d73 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -23,7 +23,7 @@ #include "EntitiesRendererLogging.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); } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index ff26451fe8..efd60faedc 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -23,9 +23,9 @@ class EntityTreeRenderer; class RenderableModelEntityItem : public ModelEntityItem { 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), _model(NULL), _needsInitialSimulation(true), diff --git a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp index 3848542d25..009d26481a 100644 --- a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp @@ -20,12 +20,11 @@ #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); } -RenderableParticleEffectEntityItem::RenderableParticleEffectEntityItem(const QUuid& entityItemID, - const EntityItemProperties& properties) : +RenderableParticleEffectEntityItem::RenderableParticleEffectEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : ParticleEffectEntityItem(entityItemID, properties) { _cacheID = DependencyManager::get()->allocateID(); } diff --git a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h index 61bc2e1578..25bbe5c147 100644 --- a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h +++ b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h @@ -16,8 +16,8 @@ class RenderableParticleEffectEntityItem : public ParticleEffectEntityItem { public: - static EntityItem* factory(const QUuid& entityID, const EntityItemProperties& properties); - RenderableParticleEffectEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); + static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + RenderableParticleEffectEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); virtual void render(RenderArgs* args); void renderUntexturedQuads(RenderArgs* args); diff --git a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp index 9e36278fb1..083a34c02f 100644 --- a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp @@ -19,7 +19,7 @@ #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); } diff --git a/libraries/entities-renderer/src/RenderableSphereEntityItem.h b/libraries/entities-renderer/src/RenderableSphereEntityItem.h index adb3e706a7..3ed651b0ae 100644 --- a/libraries/entities-renderer/src/RenderableSphereEntityItem.h +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.h @@ -16,9 +16,9 @@ class RenderableSphereEntityItem : public SphereEntityItem { 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) { } diff --git a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp index ea3f6a7d8f..895b2f9b54 100644 --- a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp @@ -23,7 +23,7 @@ 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); } @@ -37,7 +37,7 @@ void RenderableTextEntityItem::render(RenderArgs* args) { float leftMargin = 0.1f; float topMargin = 0.1f; - //qCDebug(entitytree) << "RenderableTextEntityItem::render() id:" << getID() << "text:" << getText(); + //qCDebug(entitytree) << "RenderableTextEntityItem::render() id:" << getEntityItemID() << "text:" << getText(); glPushMatrix(); { diff --git a/libraries/entities-renderer/src/RenderableTextEntityItem.h b/libraries/entities-renderer/src/RenderableTextEntityItem.h index 2f7115b83f..e57ab0538a 100644 --- a/libraries/entities-renderer/src/RenderableTextEntityItem.h +++ b/libraries/entities-renderer/src/RenderableTextEntityItem.h @@ -16,9 +16,9 @@ class RenderableTextEntityItem : public TextEntityItem { 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) { } diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index 1a673c3dba..3afd930ab0 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -29,11 +29,11 @@ const int FIXED_FONT_POINT_SIZE = 40; const float DPI = 30.47; 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); } -RenderableWebEntityItem::RenderableWebEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : +RenderableWebEntityItem::RenderableWebEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : WebEntityItem(entityItemID, properties) { qDebug() << "Created web entity " << getID(); } @@ -99,7 +99,7 @@ void RenderableWebEntityItem::render(RenderArgs* args) { return; } - if (intersection.entityID == getID()) { + if (intersection.entityID.id == getID()) { if (event->button() == Qt::MouseButton::RightButton) { if (event->type() == QEvent::MouseButtonRelease) { AbstractViewStateInterface::instance()->postLambdaEvent([this] { diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.h b/libraries/entities-renderer/src/RenderableWebEntityItem.h index fa8d4d5bfd..cf63d7915e 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.h +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.h @@ -17,9 +17,9 @@ class OffscreenQmlSurface; class RenderableWebEntityItem : public WebEntityItem { 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(); virtual void render(RenderArgs* args); diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index c46f7c63ae..d9bc0f0b4a 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -16,7 +16,7 @@ #include #include -EntityItem* RenderableZoneEntityItem::factory(const QUuid& entityID, const EntityItemProperties& properties) { +EntityItem* RenderableZoneEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { return new RenderableZoneEntityItem(entityID, properties); } diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h index ea444faeae..90a16a8a9f 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.h +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.h @@ -19,9 +19,9 @@ class NetworkGeometry; class RenderableZoneEntityItem : public ZoneEntityItem { 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), _model(NULL), _needsInitialSimulation(true) diff --git a/libraries/entities/src/AddEntityOperator.cpp b/libraries/entities/src/AddEntityOperator.cpp index 264babe725..09aa6af0cb 100644 --- a/libraries/entities/src/AddEntityOperator.cpp +++ b/libraries/entities/src/AddEntityOperator.cpp @@ -46,7 +46,7 @@ bool AddEntityOperator::preRecursion(OctreeElement* element) { if (entityTreeElement->bestFitBounds(_newEntityBox)) { entityTreeElement->addEntityItem(_newEntity); - _tree->setContainingElement(_newEntity->getID(), entityTreeElement); + _tree->setContainingElement(_newEntity->getEntityItemID(), entityTreeElement); _foundNew = true; keepSearching = false; diff --git a/libraries/entities/src/BoxEntityItem.cpp b/libraries/entities/src/BoxEntityItem.cpp index b6cb2f97d7..fab48ae777 100644 --- a/libraries/entities/src/BoxEntityItem.cpp +++ b/libraries/entities/src/BoxEntityItem.cpp @@ -20,12 +20,12 @@ #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); return result; } -BoxEntityItem::BoxEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : +BoxEntityItem::BoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) { _type = EntityTypes::Box; @@ -99,7 +99,7 @@ void BoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitst void BoxEntityItem::debugDump() const { 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) << " position:" << debugTreeVector(_position); qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); diff --git a/libraries/entities/src/BoxEntityItem.h b/libraries/entities/src/BoxEntityItem.h index 8b9f222bcb..e8459e7dbb 100644 --- a/libraries/entities/src/BoxEntityItem.h +++ b/libraries/entities/src/BoxEntityItem.h @@ -16,9 +16,9 @@ class BoxEntityItem : public EntityItem { 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 diff --git a/libraries/entities/src/DeleteEntityOperator.cpp b/libraries/entities/src/DeleteEntityOperator.cpp index d173222c72..1d1be55a9b 100644 --- a/libraries/entities/src/DeleteEntityOperator.cpp +++ b/libraries/entities/src/DeleteEntityOperator.cpp @@ -16,7 +16,7 @@ #include "EntitiesLogging.h" #include "DeleteEntityOperator.h" -DeleteEntityOperator::DeleteEntityOperator(EntityTree* tree, const QUuid& searchEntityID) : +DeleteEntityOperator::DeleteEntityOperator(EntityTree* tree, const EntityItemID& searchEntityID) : _tree(tree), _changeTime(usecTimestampNow()), _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 EntityToDeleteDetails details; details.containingElement = _tree->getContainingElement(searchEntityID); @@ -95,7 +95,7 @@ bool DeleteEntityOperator::preRecursion(OctreeElement* element) { EntityItem* theEntity = details.entity; bool entityDeleted = entityTreeElement->removeEntityItem(theEntity); // remove it from the element 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++; } } diff --git a/libraries/entities/src/DeleteEntityOperator.h b/libraries/entities/src/DeleteEntityOperator.h index a78749ac99..b6e6f9e2ff 100644 --- a/libraries/entities/src/DeleteEntityOperator.h +++ b/libraries/entities/src/DeleteEntityOperator.h @@ -22,20 +22,20 @@ public: typedef QSet RemovedEntities; 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) { - return a.entity->getID() == b.entity->getID(); + return a.entity->getEntityItemID() == b.entity->getEntityItemID(); } class DeleteEntityOperator : public RecurseOctreeOperator { public: DeleteEntityOperator(EntityTree* tree); - DeleteEntityOperator(EntityTree* tree, const QUuid& searchEntityID); + DeleteEntityOperator(EntityTree* tree, const EntityItemID& searchEntityID); ~DeleteEntityOperator(); - void addEntityIDToDeleteList(const QUuid& searchEntityID); + void addEntityIDToDeleteList(const EntityItemID& searchEntityID); virtual bool preRecursion(OctreeElement* element); virtual bool postRecursion(OctreeElement* element); diff --git a/libraries/entities/src/EntityEditPacketSender.cpp b/libraries/entities/src/EntityEditPacketSender.cpp index c95e533410..e94725782d 100644 --- a/libraries/entities/src/EntityEditPacketSender.cpp +++ b/libraries/entities/src/EntityEditPacketSender.cpp @@ -26,8 +26,8 @@ void EntityEditPacketSender::adjustEditPacketForClockSkew(PacketType type, } } -void EntityEditPacketSender::queueEditEntityMessage(PacketType type, QUuid modelID, - const EntityItemProperties& properties) { +void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemID modelID, + const EntityItemProperties& properties) { if (!_shouldSend) { 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) { return; // bail early } diff --git a/libraries/entities/src/EntityEditPacketSender.h b/libraries/entities/src/EntityEditPacketSender.h index 8391a7e344..69171ae16b 100644 --- a/libraries/entities/src/EntityEditPacketSender.h +++ b/libraries/entities/src/EntityEditPacketSender.h @@ -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 case up to MaxPendingMessages will be buffered and processed when voxel servers are known. /// 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 virtual char getMyNodeType() const { return NodeType::EntityServer; } diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 820f498269..4940095e3e 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -28,9 +28,9 @@ bool EntityItem::_sendPhysicsUpdates = true; -EntityItem::EntityItem(const QUuid& entityItemID) : +EntityItem::EntityItem(const EntityItemID& entityItemID) : _type(EntityTypes::Unknown), - _id(entityItemID), + _id(entityItemID.id), _lastSimulated(0), _lastUpdated(0), _lastEdited(0), @@ -76,7 +76,7 @@ EntityItem::EntityItem(const QUuid& entityItemID) : _lastUpdated = now; } -EntityItem::EntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) +EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) { 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, // then our entityTreeElementExtraEncodeData should include data about which properties we need to append. - if (entityTreeElementExtraEncodeData && entityTreeElementExtraEncodeData->entities.contains(getID())) { - requestedProperties = entityTreeElementExtraEncodeData->entities.value(getID()); + if (entityTreeElementExtraEncodeData && entityTreeElementExtraEncodeData->entities.contains(getEntityItemID())) { + requestedProperties = entityTreeElementExtraEncodeData->entities.value(getEntityItemID()); } LevelDetails entityLevel = packetData->startLevel(); @@ -167,7 +167,7 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet #ifdef WANT_DEBUG float editedAgo = getEditedAgo(); 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; #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 (appendState != OctreeElement::COMPLETED) { // add this item into our list for the next appendElementData() pass - entityTreeElementExtraEncodeData->entities.insert(getID(), propertiesDidntFit); + entityTreeElementExtraEncodeData->entities.insert(getEntityItemID(), propertiesDidntFit); } return appendState; @@ -308,6 +308,16 @@ int EntityItem::expectedBytes() { 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. glm::vec3 savePosition = _position; glm::quat saveRotation = _rotation; @@ -375,7 +385,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef QString agoAsString = formatSecondsElapsed(editedAgo); QString ageAsString = formatSecondsElapsed(getAge()); qCDebug(entities) << "------------------------------------------"; - qCDebug(entities) << "Loading entity " << getID() << " from buffer..."; + qCDebug(entities) << "Loading entity " << getEntityItemID() << " from buffer..."; qCDebug(entities) << "------------------------------------------"; debugDump(); qCDebug(entities) << "------------------------------------------"; @@ -402,7 +412,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef #ifdef WANT_DEBUG qCDebug(entities) << "data from server **************** "; - qCDebug(entities) << " entityItemID:" << getID(); + qCDebug(entities) << " entityItemID:" << getEntityItemID(); qCDebug(entities) << " now:" << now; qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); qCDebug(entities) << " lastEditedFromBuffer:" << debugTime(lastEditedFromBuffer, now); @@ -492,7 +502,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef #ifdef WANT_DEBUG if (overwriteLocalData) { - qCDebug(entities) << "EntityItem::readEntityDataFromBuffer()... changed entity:" << getID(); + qCDebug(entities) << "EntityItem::readEntityDataFromBuffer()... changed entity:" << getEntityItemID(); qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); qCDebug(entities) << " getLastSimulated:" << debugTime(getLastSimulated(), now); qCDebug(entities) << " getLastUpdated:" << debugTime(getLastUpdated(), now); @@ -626,7 +636,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef } void EntityItem::debugDump() const { - qCDebug(entities) << "EntityItem id:" << getID(); + qCDebug(entities) << "EntityItem id:" << getEntityItemID(); qCDebug(entities, " edited ago:%f", getEditedAgo()); qCDebug(entities, " position:%f,%f,%f", _position.x, _position.y, _position.z); qCDebug(entities) << " dimensions:" << _dimensions; @@ -700,7 +710,7 @@ void EntityItem::simulate(const quint64& now) { #ifdef WANT_DEBUG qCDebug(entities) << "********** EntityItem::simulate()"; - qCDebug(entities) << " entity ID=" << getID(); + qCDebug(entities) << " entity ID=" << getEntityItemID(); qCDebug(entities) << " simulator ID=" << getSimulatorID(); qCDebug(entities) << " now=" << now; qCDebug(entities) << " _lastSimulated=" << _lastSimulated; diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 18723af8b1..4f2132bef4 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -23,6 +23,7 @@ #include #include +#include "EntityItemID.h" #include "EntityItemProperties.h" #include "EntityItemPropertiesDefaults.h" #include "EntityTypes.h" @@ -88,13 +89,14 @@ public: DONT_ALLOW_INSTANTIATION // This class can not be instantiated directly - EntityItem(const QUuid& entityItemID); - EntityItem(const QUuid& entityItemID, const EntityItemProperties& properties); + EntityItem(const EntityItemID& entityItemID); + EntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); virtual ~EntityItem(); // ID and EntityItemID related methods const QUuid& getID() const { return _id; } void setID(const QUuid& id) { _id = id; } + EntityItemID getEntityItemID() const { return EntityItemID(_id); } // methods for getting/setting all properties of an entity virtual EntityItemProperties getProperties() const; @@ -138,8 +140,8 @@ public: int& propertyCount, OctreeElement::AppendState& appendState) const { /* do nothing*/ }; - static QUuid readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead, - ReadBitstreamToTreeParams& args); + static EntityItemID readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead, + ReadBitstreamToTreeParams& args); virtual int readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args); diff --git a/libraries/entities/src/EntityItemID.cpp b/libraries/entities/src/EntityItemID.cpp new file mode 100644 index 0000000000..696924403e --- /dev/null +++ b/libraries/entities/src/EntityItemID.cpp @@ -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 +#include + +#include + +#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); +} diff --git a/libraries/entities/src/EntityItemID.h b/libraries/entities/src/EntityItemID.h new file mode 100644 index 0000000000..9f2c499c28 --- /dev/null +++ b/libraries/entities/src/EntityItemID.h @@ -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 + + +#include +#include +#include +#include + +// 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); +QScriptValue EntityItemIDtoScriptValue(QScriptEngine* engine, const EntityItemID& properties); +void EntityItemIDfromScriptValue(const QScriptValue &object, EntityItemID& properties); + +#endif // hifi_EntityItemID_h diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index fd9dc1e377..cf3d3adaa3 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -91,7 +91,7 @@ EntityItemProperties::EntityItemProperties() : CONSTRUCT_PROPERTY(backgroundMode, BACKGROUND_MODE_INHERIT), CONSTRUCT_PROPERTY(sourceUrl, ""), - _id(QUuid()), + _id(UNKNOWN_ENTITY_ID), _idSet(false), _lastEdited(0), _created(UNKNOWN_CREATED_TIME), @@ -557,7 +557,7 @@ void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemP // // 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) { 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 @@ -586,7 +586,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, QUuid id, // id // 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 ByteCountCoded tokenCoder; @@ -818,7 +818,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, QUuid id, // TODO: Implement support for script and visible properties. // bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int bytesToRead, int& processedBytes, - QUuid& entityID, EntityItemProperties& properties) { + EntityItemID& entityID, EntityItemProperties& properties) { bool valid = false; 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 // header it does not include the send times and sequence number because that is handled by the // 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* copyAt = outputBuffer; @@ -990,7 +990,7 @@ bool EntityItemProperties::encodeEraseEntityMessage(const QUuid& entityItemID, copyAt += sizeof(numberOfIds); outputLength = sizeof(numberOfIds); - QUuid entityID = entityItemID; + QUuid entityID = entityItemID.id; QByteArray encodedEntityID = entityID.toRfc4122(); memcpy(copyAt, encodedEntityID.constData(), NUM_BYTES_RFC4122_UUID); diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 742411dc13..2c052d0a53 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -30,6 +30,7 @@ #include #include "AtmospherePropertyGroup.h" +#include "EntityItemID.h" #include "EntityItemPropertiesMacros.h" #include "EntityTypes.h" #include "EntityPropertyFlags.h" @@ -162,20 +163,20 @@ public: void setGlowLevel(float value) { _glowLevel = value; _glowLevelChanged = true; } void setLocalRenderAlpha(float value) { _localRenderAlpha = value; _localRenderAlphaChanged = true; } - static bool encodeEntityEditPacket(PacketType command, QUuid id, const EntityItemProperties& properties, - unsigned char* bufferOut, int sizeIn, int& sizeOut); + static bool encodeEntityEditPacket(PacketType command, EntityItemID id, const EntityItemProperties& properties, + 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); 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 localRenderAlphaChanged() const { return _localRenderAlphaChanged; } - void clearID() { _id = QUuid(); _idSet = false; } + void clearID() { _id = UNKNOWN_ENTITY_ID; _idSet = false; } void markAllChanged(); void setSittingPoints(const QVector& sittingPoints); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index bb288eb702..4e56405bef 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -28,7 +28,7 @@ EntityScriptingInterface::EntityScriptingInterface() : } void EntityScriptingInterface::queueEntityMessage(PacketType packetType, - QUuid entityID, const EntityItemProperties& properties) { + EntityItemID entityID, const EntityItemProperties& properties) { getEntityPacketSender()->queueEditEntityMessage(packetType, entityID, properties); } @@ -46,7 +46,6 @@ void EntityScriptingInterface::setEntityTree(EntityTree* modelTree) { if (_entityTree) { disconnect(_entityTree, &EntityTree::addingEntity, this, &EntityScriptingInterface::addingEntity); disconnect(_entityTree, &EntityTree::deletingEntity, this, &EntityScriptingInterface::deletingEntity); - disconnect(_entityTree, &EntityTree::changingEntityID, this, &EntityScriptingInterface::changingEntityID); disconnect(_entityTree, &EntityTree::clearingEntities, this, &EntityScriptingInterface::clearingEntities); } @@ -55,7 +54,6 @@ void EntityScriptingInterface::setEntityTree(EntityTree* modelTree) { if (_entityTree) { connect(_entityTree, &EntityTree::addingEntity, this, &EntityScriptingInterface::addingEntity); connect(_entityTree, &EntityTree::deletingEntity, this, &EntityScriptingInterface::deletingEntity); - connect(_entityTree, &EntityTree::changingEntityID, this, &EntityScriptingInterface::changingEntityID); 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; - QUuid id = QUuid::createUuid(); + + EntityItemID id = EntityItemID(QUuid::createUuid()); // If we have a local entity tree set, then also update it. bool success = true; @@ -99,11 +98,11 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties return id; } -EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identity) { +EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID identity) { EntityItemProperties results; if (_entityTree) { _entityTree->lockForRead(); - EntityItem* entity = const_cast(_entityTree->findEntityByEntityItemID(identity)); + EntityItem* entity = const_cast(_entityTree->findEntityByEntityItemID(EntityItemID(identity))); if (entity) { results = entity->getProperties(); @@ -127,7 +126,8 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit 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 (_entityTree) { _entityTree->lockForWrite(); @@ -145,16 +145,16 @@ QUuid EntityScriptingInterface::editEntity(QUuid entityID, const EntityItemPrope modifiedProperties.setType(entity->getType()); bidForSimulationOwnership(modifiedProperties); queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, modifiedProperties); - return entityID; + return id; } } queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); - return entityID; + return id; } -void EntityScriptingInterface::deleteEntity(QUuid entityID) { - +void EntityScriptingInterface::deleteEntity(EntityItemID id) { + EntityItemID entityID(id); bool shouldDelete = true; // 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; if (_entityTree) { _entityTree->lockForRead(); const EntityItem* closestEntity = _entityTree->findClosestEntity(center, radius); _entityTree->unlock(); if (closestEntity) { - result = closestEntity->getID(); + result = closestEntity->getEntityItemID().id; } } return result; @@ -201,8 +201,8 @@ void EntityScriptingInterface::dumpTree() const { } } -QVector EntityScriptingInterface::findEntities(const glm::vec3& center, float radius) const { - QVector result; +QVector EntityScriptingInterface::findEntities(const glm::vec3& center, float radius) const { + QVector result; if (_entityTree) { _entityTree->lockForRead(); QVector entities; @@ -210,14 +210,14 @@ QVector EntityScriptingInterface::findEntities(const glm::vec3& center, f _entityTree->unlock(); foreach (const EntityItem* entity, entities) { - result << entity->getID(); + result << entity->getEntityItemID(); } } return result; } -QVector EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const { - QVector result; +QVector EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const { + QVector result; if (_entityTree) { _entityTree->lockForRead(); AABox box(corner, dimensions); @@ -226,7 +226,7 @@ QVector EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corn _entityTree->unlock(); foreach (const EntityItem* entity, entities) { - result << entity->getID(); + result << entity->getEntityItemID(); } } return result; @@ -253,7 +253,7 @@ RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorke (void**)&intersectedEntity, lockType, &result.accurate, precisionPicking); if (result.intersects && intersectedEntity) { - result.entityID = intersectedEntity->getID(); + result.entityID = intersectedEntity->getEntityItemID().id; result.properties = intersectedEntity->getProperties(); result.intersection = ray.origin + (ray.direction * result.distance); } @@ -309,7 +309,7 @@ QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, c QScriptValue obj = engine->newObject(); obj.setProperty("intersects", value.intersects); obj.setProperty("accurate", value.accurate); - QScriptValue entityItemValue = quuidToScriptValue(engine, value.entityID); + QScriptValue entityItemValue = EntityItemIDtoScriptValue(engine, value.entityID); obj.setProperty("entityID", entityItemValue); QScriptValue propertiesValue = EntityItemPropertiesToScriptValue(engine, value.properties); @@ -353,7 +353,7 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra value.intersects = object.property("intersects").toVariant().toBool(); value.accurate = object.property("accurate").toVariant().toBool(); QScriptValue entityIDValue = object.property("entityID"); - quuidFromScriptValue(entityIDValue, value.entityID); + EntityItemIDfromScriptValue(entityIDValue, value.entityID); QScriptValue entityPropertiesValue = object.property("properties"); if (entityPropertiesValue.isValid()) { EntityItemPropertiesFromScriptValue(entityPropertiesValue, value.properties); diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index de052d12a9..5d176c5186 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -34,7 +34,7 @@ public: RayToEntityIntersectionResult(); bool intersects; bool accurate; - QUuid entityID; + EntityItemID entityID; EntityItemProperties properties; float distance; BoxFace face; @@ -70,31 +70,31 @@ public slots: Q_INVOKABLE bool canRez(); /// 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 /// 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 - Q_INVOKABLE QUuid editEntity(QUuid entityID, const EntityItemProperties& properties); + Q_INVOKABLE EntityItemID editEntity(EntityItemID entityID, const EntityItemProperties& properties); /// 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 - /// 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 - 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 /// this function will not find any models in script engine contexts which don't have access to models - Q_INVOKABLE QVector findEntities(const glm::vec3& center, float radius) const; + Q_INVOKABLE QVector findEntities(const glm::vec3& center, float radius) const; /// 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 - Q_INVOKABLE QVector findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const; + Q_INVOKABLE QVector 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 /// 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; 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 canRezChanged(bool canRez); - void mousePressOnEntity(const QUuid& entityItemID, const MouseEvent& event); - void mouseMoveOnEntity(const QUuid& entityItemID, const MouseEvent& event); - void mouseReleaseOnEntity(const QUuid& entityItemID, const MouseEvent& event); + void mousePressOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); + void mouseMoveOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); + void mouseReleaseOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); - void clickDownOnEntity(const QUuid& entityItemID, const MouseEvent& event); - void holdingClickOnEntity(const QUuid& entityItemID, const MouseEvent& event); - void clickReleaseOnEntity(const QUuid& entityItemID, const MouseEvent& event); + void clickDownOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); + void holdingClickOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); + void clickReleaseOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); - void hoverEnterEntity(const QUuid& entityItemID, const MouseEvent& event); - void hoverOverEntity(const QUuid& entityItemID, const MouseEvent& event); - void hoverLeaveEntity(const QUuid& entityItemID, const MouseEvent& event); + void hoverEnterEntity(const EntityItemID& entityItemID, const MouseEvent& event); + void hoverOverEntity(const EntityItemID& entityItemID, const MouseEvent& event); + void hoverLeaveEntity(const EntityItemID& entityItemID, const MouseEvent& event); - void enterEntity(const QUuid& entityItemID); - void leaveEntity(const QUuid& entityItemID); + void enterEntity(const EntityItemID& entityItemID); + void leaveEntity(const EntityItemID& entityItemID); - void deletingEntity(const QUuid& entityID); - void addingEntity(const QUuid& entityID); - void changingEntityID(const QUuid& oldEntityID, const QUuid& newEntityID); + void deletingEntity(const EntityItemID& entityID); + void addingEntity(const EntityItemID& entityID); + void changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID); void clearingEntities(); 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 RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, diff --git a/libraries/entities/src/EntitySimulation.cpp b/libraries/entities/src/EntitySimulation.cpp index 75e32cd548..d28e139205 100644 --- a/libraries/entities/src/EntitySimulation.cpp +++ b/libraries/entities/src/EntitySimulation.cpp @@ -121,7 +121,7 @@ void EntitySimulation::sortEntitiesThatMoved() { // check to see if this movement has sent the entity outside of the domain. AACube newCube = entity->getMaximumAACube(); 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); _mortalEntities.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 newCube = entity->getMaximumAACube(); 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); _mortalEntities.remove(entity); _entitiesToUpdate.remove(entity); diff --git a/libraries/entities/src/EntitySimulation.h b/libraries/entities/src/EntitySimulation.h index a37a4ecb4f..f5a100eba0 100644 --- a/libraries/entities/src/EntitySimulation.h +++ b/libraries/entities/src/EntitySimulation.h @@ -81,7 +81,7 @@ public: void getEntitiesToDelete(VectorOfEntities& entitiesToDelete); signals: - void entityCollisionWithEntity(const QUuid& idA, const QUuid& idB, const Collision& collision); + void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); protected: diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 9e4e598e05..48d99a2cbf 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -83,11 +83,10 @@ void EntityTree::postAddEntity(EntityItem* entity) { _simulation->unlock(); } _isDirty = true; - emit addingEntity(entity->getID()); + emit addingEntity(entity->getEntityItemID()); } -bool EntityTree::updateEntity(const QUuid& entityID, const EntityItemProperties& properties, - const SharedNodePointer& senderNode) { +bool EntityTree::updateEntity(const EntityItemID& entityID, const EntityItemProperties& properties, const SharedNodePointer& senderNode) { EntityTreeElement* containingElement = getContainingElement(entityID); if (!containingElement) { 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) { - EntityTreeElement* containingElement = getContainingElement(entity->getID()); + EntityTreeElement* containingElement = getContainingElement(entity->getEntityItemID()); if (!containingElement) { qCDebug(entities) << "UNEXPECTED!!!! EntityTree::updateEntity() entity-->element lookup failed!!! entityID=" - << entity->getID(); + << entity->getEntityItemID(); return false; } return updateEntityWithElement(entity, properties, containingElement, senderNode); @@ -205,22 +204,22 @@ bool EntityTree::updateEntityWithElement(EntityItem* entity, const EntityItemPro QString entityScriptAfter = entity->getScript(); 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). - containingElement = getContainingElement(entity->getID()); + containingElement = getContainingElement(entity->getEntityItemID()); if (!containingElement) { qCDebug(entities) << "UNEXPECTED!!!! after updateEntity() we no longer have a containing element??? entityID=" - << entity->getID(); + << entity->getEntityItemID(); return false; } return true; } -EntityItem* EntityTree::addEntity(const QUuid& entityID, const EntityItemProperties& properties) { +EntityItem* EntityTree::addEntity(const EntityItemID& entityID, const EntityItemProperties& properties) { EntityItem* result = NULL; if (getIsClient()) { @@ -263,7 +262,7 @@ EntityItem* EntityTree::addEntity(const QUuid& entityID, const EntityItemPropert return result; } -void EntityTree::emitEntityScriptChanging(const QUuid& entityItemID) { +void EntityTree::emitEntityScriptChanging(const EntityItemID& entityItemID) { emit entityScriptChanging(entityItemID); } @@ -282,7 +281,7 @@ void EntityTree::setSimulation(EntitySimulation* 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); if (!containingElement) { if (!ignoreWarnings) { @@ -316,10 +315,10 @@ void EntityTree::deleteEntity(const QUuid& entityID, bool force, bool ignoreWarn _isDirty = true; } -void EntityTree::deleteEntities(QSet entityIDs, bool force, bool ignoreWarnings) { +void EntityTree::deleteEntities(QSet entityIDs, bool force, bool ignoreWarnings) { // NOTE: callers must lock the tree before using this method DeleteEntityOperator theOperator(this); - foreach(const QUuid& entityID, entityIDs) { + foreach(const EntityItemID& entityID, entityIDs) { EntityTreeElement* containingElement = getContainingElement(entityID); if (!containingElement) { if (!ignoreWarnings) { @@ -368,7 +367,7 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator) // set up the deleted entities ID quint64 deletedAt = usecTimestampNow(); _recentlyDeletedEntitiesLock.lockForWrite(); - _recentlyDeletedEntityItemIDs.insert(deletedAt, theEntity->getID()); + _recentlyDeletedEntityItemIDs.insert(deletedAt, theEntity->getEntityItemID().id); _recentlyDeletedEntitiesLock.unlock(); } @@ -383,6 +382,7 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator) } void EntityTree::handleAddEntityResponse(const QByteArray& packet) { + if (!getIsClient()) { qCDebug(entities) << "UNEXPECTED!!! EntityTree::handleAddEntityResponse() with !getIsClient() ***"; return; @@ -537,10 +537,11 @@ void EntityTree::findEntities(const AABox& box, QVector& foundEntit } 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; EntityTreeElement* containingElement = getContainingElement(entityID); if (containingElement) { @@ -567,32 +568,29 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char } case PacketTypeEntityAddOrEdit: { - QUuid entityItemID; + EntityItemID entityItemID; EntityItemProperties properties; 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 // an existing entity... handle appropriately if (validEditPacket) { // search for the entity by EntityItemID EntityItem* existingEntity = findEntityByEntityItemID(entityItemID); - + // If this is a knownID, then it should exist in our tree if (existingEntity) { // if the EntityItem exists, then update it - if (existingEntity) { - if (wantEditLogging()) { - qCDebug(entities) << "User [" << senderNode->getUUID() << "] editing entity. ID:" << entityItemID; - qCDebug(entities) << " properties:" << properties; - } - updateEntity(entityItemID, properties, senderNode); - existingEntity->markAsChangedOnServer(); - } else { - qCDebug(entities) << "User attempted to edit an unknown entity. ID:" << entityItemID; + if (wantEditLogging()) { + qCDebug(entities) << "User [" << senderNode->getUUID() << "] editing entity. ID:" << entityItemID; + qCDebug(entities) << " properties:" << properties; } + updateEntity(entityItemID, properties, senderNode); + existingEntity->markAsChangedOnServer(); } else { if (senderNode->getCanRez()) { + // this is a new entity... assign a new entityID if (wantEditLogging()) { qCDebug(entities) << "User [" << senderNode->getUUID() << "] adding entity."; qCDebug(entities) << " properties:" << properties; @@ -603,13 +601,13 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char notifyNewlyCreatedEntity(*newEntity, senderNode); if (wantEditLogging()) { qCDebug(entities) << "User [" << senderNode->getUUID() << "] added entity. ID:" - << newEntity->getID(); + << newEntity->getEntityItemID(); qCDebug(entities) << " properties:" << properties; } + } } else { - qCDebug(entities) << "User without 'rez rights' [" - << senderNode->getUUID() << "] attempted to add an entity."; + qCDebug(entities) << "User without 'rez rights' [" << senderNode->getUUID() << "] attempted to add an entity."; } } } @@ -677,11 +675,11 @@ void EntityTree::update() { if (pendingDeletes.size() > 0) { // translate into list of ID's - QSet idsToDelete; + QSet idsToDelete; for (auto entityItr : pendingDeletes) { EntityItem* entity = &(*entityItr); assert(!entity->getPhysicsInfo()); // TODO: Andrew to remove this after testing - idsToDelete.insert(entity->getID()); + idsToDelete.insert(entity->getEntityItemID()); } // delete these things the roundabout way deleteEntities(idsToDelete, true); @@ -841,7 +839,7 @@ int EntityTree::processEraseMessage(const QByteArray& dataByteArray, const Share processedBytes += sizeof(numberOfIds); if (numberOfIds > 0) { - QSet entityItemIDsToDelete; + QSet entityItemIDsToDelete; for (size_t i = 0; i < numberOfIds; i++) { @@ -855,10 +853,11 @@ int EntityTree::processEraseMessage(const QByteArray& dataByteArray, const Share dataAt += encodedID.size(); processedBytes += encodedID.size(); - entityItemIDsToDelete << entityID; + EntityItemID entityItemID(entityID); + entityItemIDsToDelete << entityItemID; 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); if (numberOfIds > 0) { - QSet entityItemIDsToDelete; + QSet entityItemIDsToDelete; for (size_t i = 0; i < numberOfIds; i++) { @@ -898,10 +897,11 @@ int EntityTree::processEraseMessageDetails(const QByteArray& dataByteArray, cons dataAt += encodedID.size(); processedBytes += encodedID.size(); - entityItemIDsToDelete << entityID; + EntityItemID entityItemID(entityID); + entityItemIDsToDelete << entityItemID; 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; } -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 EntityTreeElement* element = _entityToElementMap.value(entityItemID); return element; } - -void EntityTree::setContainingElement(const QUuid& entityItemID, EntityTreeElement* element) { +void EntityTree::setContainingElement(const EntityItemID& entityItemID, EntityTreeElement* element) { // TODO: do we need to make this thread safe? Or is it acceptable as is if (element) { _entityToElementMap[entityItemID] = element; @@ -926,11 +925,9 @@ void EntityTree::setContainingElement(const QUuid& entityItemID, EntityTreeEleme } } - - void EntityTree::debugDumpMap() { qCDebug(entities) << "EntityTree::debugDumpMap() --------------------------"; - QHashIterator i(_entityToElementMap); + QHashIterator i(_entityToElementMap); while (i.hasNext()) { i.next(); qCDebug(entities) << i.key() << ": " << i.value(); @@ -994,13 +991,12 @@ void EntityTree::pruneTree() { recurseTreeWithOperator(&theOperator); } -QVector EntityTree::sendEntities(EntityEditPacketSender* packetSender, - EntityTree* localTree, float x, float y, float z) { +QVector EntityTree::sendEntities(EntityEditPacketSender* packetSender, EntityTree* localTree, float x, float y, float z) { SendEntitiesOperationArgs args; args.packetSender = packetSender; args.localTree = localTree; args.root = glm::vec3(x, y, z); - QVector newEntityIDs; + QVector newEntityIDs; args.newEntityIDs = &newEntityIDs; recurseTreeWithOperation(sendEntitiesOperation, &args); packetSender->releaseQueuedMessages(); @@ -1014,7 +1010,7 @@ bool EntityTree::sendEntitiesOperation(OctreeElement* element, void* extraData) const QList& entities = entityTreeElement->getEntities(); for (int i = 0; i < entities.size(); i++) { - QUuid newID = QUuid::createUuid(); + EntityItemID newID(QUuid::createUuid()); args->newEntityIDs->append(newID); EntityItemProperties properties = entities[i]->getProperties(); properties.setPosition(properties.getPosition() + args->root); @@ -1057,11 +1053,11 @@ bool EntityTree::readFromMap(QVariantMap& map) { EntityItemProperties properties; EntityItemPropertiesFromScriptValue(entityScriptValue, properties); - QUuid entityItemID; + EntityItemID entityItemID; if (entityMap.contains("id")) { - entityItemID = QUuid(entityMap["id"].toString()); + entityItemID = EntityItemID(QUuid(entityMap["id"].toString())); } else { - entityItemID = QUuid::createUuid(); + entityItemID = EntityItemID(QUuid::createUuid()); } EntityItem* entity = addEntity(entityItemID, properties); diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index a7e9ce6842..a7fa438984 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -41,7 +41,7 @@ public: glm::vec3 root; EntityTree* localTree; EntityEditPacketSender* packetSender; - QVector* newEntityIDs; + QVector* newEntityIDs; }; @@ -85,25 +85,24 @@ public: // The newer API... 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 - bool updateEntity(const QUuid& entityID, const EntityItemProperties& properties, - const SharedNodePointer& senderNode = SharedNodePointer(nullptr)); + bool updateEntity(const EntityItemID& entityID, const EntityItemProperties& properties, const SharedNodePointer& senderNode = SharedNodePointer(nullptr)); // 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)); - void deleteEntity(const QUuid& entityID, bool force = false, bool ignoreWarnings = false); - void deleteEntities(QSet entityIDs, bool force = false, bool ignoreWarnings = false); + void deleteEntity(const EntityItemID& entityID, bool force = false, bool ignoreWarnings = false); + void deleteEntities(QSet entityIDs, bool force = false, bool ignoreWarnings = false); /// \param position point of query in world-frame (meters) /// \param targetRadius radius of query (meters) const EntityItem* findClosestEntity(glm::vec3 position, float targetRadius); 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 @@ -147,17 +146,17 @@ public: return _fbxService ? _fbxService->getModelForEntityItem(entityItem) : NULL; } - EntityTreeElement* getContainingElement(const QUuid& entityItemID) /*const*/; - void setContainingElement(const QUuid& entityItemID, EntityTreeElement* element); + EntityTreeElement* getContainingElement(const EntityItemID& entityItemID) /*const*/; + void setContainingElement(const EntityItemID& entityItemID, EntityTreeElement* element); void debugDumpMap(); virtual void dumpTree(); virtual void pruneTree(); - QVector sendEntities(EntityEditPacketSender* packetSender, EntityTree* localTree, float x, float y, float z); + QVector sendEntities(EntityEditPacketSender* packetSender, EntityTree* localTree, float x, float y, float z); void entityChanged(EntityItem* entity); - void emitEntityScriptChanging(const QUuid& entityItemID); + void emitEntityScriptChanging(const EntityItemID& entityItemID); void setSimulation(EntitySimulation* simulation); @@ -170,10 +169,10 @@ public: float getContentsLargestDimension(); signals: - void deletingEntity(const QUuid& entityID); - void addingEntity(const QUuid& entityID); - void entityScriptChanging(const QUuid& entityItemID); - void changingEntityID(const QUuid& oldEntityID, const QUuid& newEntityID); + void deletingEntity(const EntityItemID& entityID); + void addingEntity(const EntityItemID& entityID); + void entityScriptChanging(const EntityItemID& entityItemID); + void changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID); void clearingEntities(); private: @@ -197,7 +196,7 @@ private: QMultiMap _recentlyDeletedEntityItemIDs; EntityItemFBXService* _fbxService; - QHash _entityToElementMap; + QHash _entityToElementMap; EntitySimulation* _simulation; diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index 61f54c6f54..8ca817adb5 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -86,7 +86,7 @@ void EntityTreeElement::initializeExtraEncodeData(EncodeBitstreamParams& params) } for (uint16_t i = 0; i < _entityItems->size(); 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!!! @@ -258,14 +258,13 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData if (child->hasEntities()) { entityTreeElementExtraEncodeData->childCompleted[i] = false; } else { - // if the child doesn't have enities, it is completed - entityTreeElementExtraEncodeData->childCompleted[i] = true; + entityTreeElementExtraEncodeData->childCompleted[i] = true; // if the child doesn't have enities, it is completed } } } for (uint16_t i = 0; i < _entityItems->size(); 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) { includeThisEntity = includeThisEntity && - entityTreeElementExtraEncodeData->entities.contains(entity->getID()); + entityTreeElementExtraEncodeData->entities.contains(entity->getEntityItemID()); } 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 (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 @@ -612,11 +611,11 @@ void EntityTreeElement::getEntities(const AACube& box, QVector& fou } } -const EntityItem* EntityTreeElement::getEntityWithEntityItemID(const QUuid& id) const { +const EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemID& id) const { const EntityItem* foundEntity = NULL; uint16_t numberOfEntities = _entityItems->size(); for (uint16_t i = 0; i < numberOfEntities; i++) { - if ((*_entityItems)[i]->getID() == id) { + if ((*_entityItems)[i]->getEntityItemID() == id) { foundEntity = (*_entityItems)[i]; break; } @@ -624,11 +623,11 @@ const EntityItem* EntityTreeElement::getEntityWithEntityItemID(const QUuid& id) return foundEntity; } -EntityItem* EntityTreeElement::getEntityWithEntityItemID(const QUuid& id) { +EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemID& id) { EntityItem* foundEntity = NULL; uint16_t numberOfEntities = _entityItems->size(); for (uint16_t i = 0; i < numberOfEntities; i++) { - if ((*_entityItems)[i]->getID() == id) { + if ((*_entityItems)[i]->getEntityItemID() == id) { foundEntity = (*_entityItems)[i]; break; } @@ -646,11 +645,11 @@ void EntityTreeElement::cleanupEntities() { _entityItems->clear(); } -bool EntityTreeElement::removeEntityWithEntityItemID(const QUuid& id) { +bool EntityTreeElement::removeEntityWithEntityItemID(const EntityItemID& id) { bool foundEntity = false; uint16_t numberOfEntities = _entityItems->size(); for (uint16_t i = 0; i < numberOfEntities; i++) { - if ((*_entityItems)[i]->getID() == id) { + if ((*_entityItems)[i]->getEntityItemID() == id) { foundEntity = true; (*_entityItems)[i]->_element = NULL; _entityItems->removeAt(i); @@ -706,12 +705,16 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int if (bytesLeftToRead >= (int)(numberOfEntities * expectedBytesPerEntity)) { for (uint16_t i = 0; i < numberOfEntities; i++) { int bytesForThisEntity = 0; - QUuid entityItemID; + EntityItemID entityItemID; EntityItem* entityItem = NULL; - QByteArray encodedID((const char*)dataAt, NUM_BYTES_RFC4122_UUID); - entityItemID = QUuid::fromRfc4122(encodedID); - entityItem = _myTree->findEntityByEntityItemID(entityItemID); + // Old model files don't have UUIDs in them. So we don't want to try to read those IDs from the stream. + // Since this can only happen on loading an old file, we can safely treat these as new entity cases, + // 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... // 1) allow the existing item to read from the databuffer @@ -752,7 +755,7 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int if (entityItem) { bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args); addEntityItem(entityItem); // add this new entity to this elements entities - entityItemID = entityItem->getID(); + entityItemID = entityItem->getEntityItemID(); _myTree->setContainingElement(entityItemID, this); _myTree->postAddEntity(entityItem); } diff --git a/libraries/entities/src/EntityTreeElement.h b/libraries/entities/src/EntityTreeElement.h index 538772a9f8..51517a2071 100644 --- a/libraries/entities/src/EntityTreeElement.h +++ b/libraries/entities/src/EntityTreeElement.h @@ -47,7 +47,7 @@ public: bool elementCompleted; bool subtreeCompleted; bool childCompleted[NUMBER_OF_CHILDREN]; - QMap entities; + QMap entities; }; inline QDebug operator<<(QDebug debug, const EntityTreeElementExtraEncodeData* data) { @@ -165,13 +165,13 @@ public: void getEntities(const AACube& box, QVector& foundEntities); 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& foundEntities); - EntityItem* getEntityWithEntityItemID(const QUuid& id); + EntityItem* getEntityWithEntityItemID(const EntityItemID& id); 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 containsEntityBounds(const EntityItem* entity) const; diff --git a/libraries/entities/src/EntityTypes.cpp b/libraries/entities/src/EntityTypes.cpp index fcd34a1d01..794a77b194 100644 --- a/libraries/entities/src/EntityTypes.cpp +++ b/libraries/entities/src/EntityTypes.cpp @@ -76,8 +76,8 @@ bool EntityTypes::registerEntityType(EntityType entityType, const char* name, En return false; } -EntityItem* EntityTypes::constructEntityItem(EntityType entityType, const QUuid& entityID, - const EntityItemProperties& properties) { +EntityItem* EntityTypes::constructEntityItem(EntityType entityType, const EntityItemID& entityID, + const EntityItemProperties& properties) { EntityItem* newEntityItem = NULL; EntityTypeFactory factory = NULL; if (entityType >= 0 && entityType <= LAST) { @@ -91,7 +91,15 @@ EntityItem* EntityTypes::constructEntityItem(EntityType entityType, const QUuid& 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 // object ID [16 bytes] // ByteCountCoded(type code) [~1 byte] @@ -119,8 +127,9 @@ EntityItem* EntityTypes::constructEntityItem(const unsigned char* data, int byte quint32 type = typeCoder; EntityTypes::EntityType entityType = (EntityTypes::EntityType)type; + EntityItemID tempEntityID(actualID); EntityItemProperties tempProperties; - return constructEntityItem(entityType, actualID, tempProperties); + return constructEntityItem(entityType, tempEntityID, tempProperties); } return NULL; diff --git a/libraries/entities/src/EntityTypes.h b/libraries/entities/src/EntityTypes.h index 1a8a38df32..b3de3dfc8e 100644 --- a/libraries/entities/src/EntityTypes.h +++ b/libraries/entities/src/EntityTypes.h @@ -14,17 +14,17 @@ #include -#include #include #include #include // for RenderArgs class EntityItem; +class EntityItemID; class EntityItemProperties; class ReadBitstreamToTreeParams; -typedef EntityItem* (*EntityTypeFactory)(const QUuid& entityID, const EntityItemProperties& properties); +typedef EntityItem* (*EntityTypeFactory)(const EntityItemID& entityID, const EntityItemProperties& properties); class EntityTypes { public: @@ -45,8 +45,7 @@ public: static const QString& getEntityTypeName(EntityType entityType); static EntityTypes::EntityType getEntityTypeFromName(const QString& name); static bool registerEntityType(EntityType entityType, const char* name, EntityTypeFactory factoryMethod); - static EntityItem* constructEntityItem(EntityType entityType, - const QUuid& entityID, const EntityItemProperties& properties); + static EntityItem* constructEntityItem(EntityType entityType, const EntityItemID& entityID, const EntityItemProperties& properties); static EntityItem* constructEntityItem(const unsigned char* data, int bytesToRead, ReadBitstreamToTreeParams& args); 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 /// 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: -// 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 = \ 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 /// 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: -// 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 = \ EntityTypes::registerEntityType(EntityTypes::x, #x, y); \ if (!x##Registration) { \ diff --git a/libraries/entities/src/LightEntityItem.cpp b/libraries/entities/src/LightEntityItem.cpp index a6d3c2fdcd..a66cb56bd2 100644 --- a/libraries/entities/src/LightEntityItem.cpp +++ b/libraries/entities/src/LightEntityItem.cpp @@ -14,6 +14,7 @@ #include +#include "EntityItemID.h" #include "EntityTree.h" #include "EntityTreeElement.h" #include "EntitiesLogging.h" @@ -21,12 +22,12 @@ 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); } // 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) { _type = EntityTypes::Light; diff --git a/libraries/entities/src/LightEntityItem.h b/libraries/entities/src/LightEntityItem.h index 4816c921f3..162b40f56d 100644 --- a/libraries/entities/src/LightEntityItem.h +++ b/libraries/entities/src/LightEntityItem.h @@ -16,9 +16,9 @@ class LightEntityItem : public EntityItem { 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 diff --git a/libraries/entities/src/LineEntityItem.cpp b/libraries/entities/src/LineEntityItem.cpp index 0a07e47bad..6686f9e46a 100644 --- a/libraries/entities/src/LineEntityItem.cpp +++ b/libraries/entities/src/LineEntityItem.cpp @@ -20,12 +20,12 @@ #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); return result; } -LineEntityItem::LineEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : +LineEntityItem::LineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) { _type = EntityTypes::Line; @@ -99,7 +99,7 @@ void LineEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits void LineEntityItem::debugDump() const { 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) << " position:" << debugTreeVector(_position); qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); diff --git a/libraries/entities/src/LineEntityItem.h b/libraries/entities/src/LineEntityItem.h index bf1cceb51b..a8bc867bdd 100644 --- a/libraries/entities/src/LineEntityItem.h +++ b/libraries/entities/src/LineEntityItem.h @@ -16,9 +16,9 @@ class LineEntityItem : public EntityItem { 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 diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 9a0ebbddde..f7da57da0d 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -28,11 +28,11 @@ const bool ModelEntityItem::DEFAULT_ANIMATION_IS_PLAYING = false; 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); } -ModelEntityItem::ModelEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : +ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID, properties) { _type = EntityTypes::Model; @@ -267,7 +267,7 @@ void ModelEntityItem::update(const quint64& now) { } void ModelEntityItem::debugDump() const { - qCDebug(entities) << "ModelEntityItem id:" << getID(); + qCDebug(entities) << "ModelEntityItem id:" << getEntityItemID(); qCDebug(entities) << " edited ago:" << getEditedAgo(); qCDebug(entities) << " position:" << getPosition(); qCDebug(entities) << " dimensions:" << getDimensions(); diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index d52c2b1cc0..d4a4efda04 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -18,9 +18,9 @@ class ModelEntityItem : public EntityItem { 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 diff --git a/libraries/entities/src/MovingEntitiesOperator.h b/libraries/entities/src/MovingEntitiesOperator.h index 31f0cb5248..51eef0d0e3 100644 --- a/libraries/entities/src/MovingEntitiesOperator.h +++ b/libraries/entities/src/MovingEntitiesOperator.h @@ -25,11 +25,11 @@ public: }; 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) { - return a.entity->getID() == b.entity->getID(); + return a.entity == b.entity; } class MovingEntitiesOperator : public RecurseOctreeOperator { diff --git a/libraries/entities/src/ParticleEffectEntityItem.cpp b/libraries/entities/src/ParticleEffectEntityItem.cpp index 2e13bfe834..0879e49f03 100644 --- a/libraries/entities/src/ParticleEffectEntityItem.cpp +++ b/libraries/entities/src/ParticleEffectEntityItem.cpp @@ -55,12 +55,12 @@ const float ParticleEffectEntityItem::DEFAULT_PARTICLE_RADIUS = 0.025f; 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); } // 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), _maxParticles(DEFAULT_MAX_PARTICLES), _lifespan(DEFAULT_LIFESPAN), @@ -274,7 +274,7 @@ void ParticleEffectEntityItem::update(const quint64& now) { void ParticleEffectEntityItem::debugDump() const { 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) << " position:" << debugTreeVector(_position); qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); diff --git a/libraries/entities/src/ParticleEffectEntityItem.h b/libraries/entities/src/ParticleEffectEntityItem.h index 532c7a700b..6d1ef601f6 100644 --- a/libraries/entities/src/ParticleEffectEntityItem.h +++ b/libraries/entities/src/ParticleEffectEntityItem.h @@ -17,9 +17,9 @@ class ParticleEffectEntityItem : public EntityItem { 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(); ALLOW_INSTANTIATION // This class can be instantiated diff --git a/libraries/entities/src/SphereEntityItem.cpp b/libraries/entities/src/SphereEntityItem.cpp index 1272a0c283..c3bc78a2f0 100644 --- a/libraries/entities/src/SphereEntityItem.cpp +++ b/libraries/entities/src/SphereEntityItem.cpp @@ -23,12 +23,12 @@ #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); } // 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) { _type = EntityTypes::Sphere; @@ -117,7 +117,7 @@ bool SphereEntityItem::findDetailedRayIntersection(const glm::vec3& origin, cons void SphereEntityItem::debugDump() const { 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) << " position:" << debugTreeVector(_position); qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); diff --git a/libraries/entities/src/SphereEntityItem.h b/libraries/entities/src/SphereEntityItem.h index fb3843a39d..b6516b714f 100644 --- a/libraries/entities/src/SphereEntityItem.h +++ b/libraries/entities/src/SphereEntityItem.h @@ -16,9 +16,9 @@ class SphereEntityItem : public EntityItem { 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 diff --git a/libraries/entities/src/TextEntityItem.cpp b/libraries/entities/src/TextEntityItem.cpp index f4cbcc6199..1a117dd79e 100644 --- a/libraries/entities/src/TextEntityItem.cpp +++ b/libraries/entities/src/TextEntityItem.cpp @@ -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_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); return result; } -TextEntityItem::TextEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : +TextEntityItem::TextEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) { _type = EntityTypes::Text; diff --git a/libraries/entities/src/TextEntityItem.h b/libraries/entities/src/TextEntityItem.h index 7e26a6469f..d57b5442d6 100644 --- a/libraries/entities/src/TextEntityItem.h +++ b/libraries/entities/src/TextEntityItem.h @@ -16,9 +16,9 @@ class TextEntityItem : public EntityItem { 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 diff --git a/libraries/entities/src/UpdateEntityOperator.cpp b/libraries/entities/src/UpdateEntityOperator.cpp index 6fcc1c11ef..6c1fac1ffc 100644 --- a/libraries/entities/src/UpdateEntityOperator.cpp +++ b/libraries/entities/src/UpdateEntityOperator.cpp @@ -25,7 +25,7 @@ UpdateEntityOperator::UpdateEntityOperator(EntityTree* tree, _containingElement(containingElement), _containingElementCube(containingElement->getAACube()), _properties(properties), - _entityItemID(existingEntity->getID()), + _entityItemID(existingEntity->getEntityItemID()), _foundOld(false), _foundNew(false), _removeOld(false), diff --git a/libraries/entities/src/UpdateEntityOperator.h b/libraries/entities/src/UpdateEntityOperator.h index 54d6c36e99..8d40ddfd57 100644 --- a/libraries/entities/src/UpdateEntityOperator.h +++ b/libraries/entities/src/UpdateEntityOperator.h @@ -15,7 +15,7 @@ class UpdateEntityOperator : public RecurseOctreeOperator { public: UpdateEntityOperator(EntityTree* tree, EntityTreeElement* containingElement, - EntityItem* existingEntity, const EntityItemProperties& properties); + EntityItem* existingEntity, const EntityItemProperties& properties); ~UpdateEntityOperator(); virtual bool preRecursion(OctreeElement* element); @@ -27,7 +27,7 @@ private: EntityTreeElement* _containingElement; AACube _containingElementCube; // we temporarily store our cube here in case we need to delete the containing element EntityItemProperties _properties; - QUuid _entityItemID; + EntityItemID _entityItemID; bool _foundOld; bool _foundNew; bool _removeOld; diff --git a/libraries/entities/src/WebEntityItem.cpp b/libraries/entities/src/WebEntityItem.cpp index d4ed10a01a..48b03a48f6 100644 --- a/libraries/entities/src/WebEntityItem.cpp +++ b/libraries/entities/src/WebEntityItem.cpp @@ -22,12 +22,12 @@ 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); return result; } -WebEntityItem::WebEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : +WebEntityItem::WebEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) { _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; } \ No newline at end of file diff --git a/libraries/entities/src/WebEntityItem.h b/libraries/entities/src/WebEntityItem.h index 33dbd716f4..35e98b2092 100644 --- a/libraries/entities/src/WebEntityItem.h +++ b/libraries/entities/src/WebEntityItem.h @@ -15,9 +15,9 @@ class WebEntityItem : public EntityItem { public: 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 diff --git a/libraries/entities/src/ZoneEntityItem.cpp b/libraries/entities/src/ZoneEntityItem.cpp index e7024701db..1846d16e25 100644 --- a/libraries/entities/src/ZoneEntityItem.cpp +++ b/libraries/entities/src/ZoneEntityItem.cpp @@ -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 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); return result; } -ZoneEntityItem::ZoneEntityItem(const QUuid& entityItemID, const EntityItemProperties& properties) : +ZoneEntityItem::ZoneEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) { _type = EntityTypes::Zone; @@ -216,9 +216,8 @@ void ZoneEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits void ZoneEntityItem::debugDump() const { quint64 now = usecTimestampNow(); - qCDebug(entities) << " ZoneEntityItem id:" << getID() << "---------------------------------------------"; - qCDebug(entities) << " keyLightColor:" << _keyLightColor[0] << "," - << _keyLightColor[1] << "," << _keyLightColor[2]; + qCDebug(entities) << " ZoneEntityItem id:" << getEntityItemID() << "---------------------------------------------"; + qCDebug(entities) << " keyLightColor:" << _keyLightColor[0] << "," << _keyLightColor[1] << "," << _keyLightColor[2]; qCDebug(entities) << " position:" << debugTreeVector(_position); qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); diff --git a/libraries/entities/src/ZoneEntityItem.h b/libraries/entities/src/ZoneEntityItem.h index 2077fd364f..f1d88f986c 100644 --- a/libraries/entities/src/ZoneEntityItem.h +++ b/libraries/entities/src/ZoneEntityItem.h @@ -19,9 +19,9 @@ class ZoneEntityItem : public EntityItem { 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 diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 168c0ef0c2..9bba80054f 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -427,7 +427,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q } if (EntityItem::getSendPhysicsUpdates()) { - QUuid id(_entity->getID()); + EntityItemID id(_entity->getID()); EntityEditPacketSender* entityPacketSender = static_cast(packetSender); #ifdef WANT_DEBUG qCDebug(physics) << "EntityMotionState::sendUpdate()... calling queueEditEntityMessage()..."; diff --git a/tests/octree/src/ModelTests.cpp b/tests/octree/src/ModelTests.cpp index acd4d4dc18..97258d8c34 100644 --- a/tests/octree/src/ModelTests.cpp +++ b/tests/octree/src/ModelTests.cpp @@ -40,7 +40,8 @@ void EntityTests::entityTreeTests(bool verbose) { // Tree, id, and entity properties used in many tests below... EntityTree tree; - QUuid entityID = QUuid::createUuid(); + QUuid id = QUuid::createUuid(); + EntityItemID entityID(id); EntityItemProperties properties; float oneMeter = 1.0f; float halfOfDomain = TREE_SCALE * 0.5f; @@ -247,7 +248,8 @@ void EntityTests::entityTreeTests(bool verbose) { quint64 totalElapsedAdd = 0; quint64 totalElapsedFind = 0; 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 randomY = randFloatInRange(1.0f ,(float)TREE_SCALE - 1.0f); @@ -349,7 +351,8 @@ void EntityTests::entityTreeTests(bool verbose) { quint64 totalElapsedDelete = 0; quint64 totalElapsedFind = 0; 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) { qDebug() << "before:" << i << "getOctreeElementsCount()=" << tree.getOctreeElementsCount(); @@ -428,9 +431,11 @@ void EntityTests::entityTreeTests(bool verbose) { quint64 totalElapsedFind = 0; for (int i = 0; i < TEST_ITERATIONS; i++) { - QSet entitiesToDelete; + QSet entitiesToDelete; for (int j = 0; j < ENTITIES_PER_ITERATION; j++) { //uint32_t id = 2 + (i * ENTITIES_PER_ITERATION) + j; // These are the entities we added above + QUuid id = QUuid::createUuid();// make sure it doesn't collide with previous entity ids + EntityItemID entityID(id); entitiesToDelete << entityID; } @@ -450,7 +455,8 @@ void EntityTests::entityTreeTests(bool verbose) { quint64 startFind = usecTimestampNow(); for (int j = 0; j < ENTITIES_PER_ITERATION; j++) { //uint32_t id = 2 + (i * ENTITIES_PER_ITERATION) + j; // These are the entities we added above - 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); EntityTreeElement* containingElement = tree.getContainingElement(entityID); From f522334c99beeadb6c8a7a123d0c51e0a0368529 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 20 May 2015 12:30:06 -0700 Subject: [PATCH 4/8] sort out script interface changes --- .../src/EntityTreeRenderer.cpp | 2 +- .../src/RenderableWebEntityItem.cpp | 2 +- libraries/entities/src/EntityItemID.h | 10 ++---- .../entities/src/EntityScriptingInterface.cpp | 35 ++++++++++--------- .../entities/src/EntityScriptingInterface.h | 17 +++++---- libraries/entities/src/EntityTree.cpp | 2 +- .../entities/src/MovingEntitiesOperator.cpp | 12 +++---- 7 files changed, 37 insertions(+), 43 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index c8b20e92e1..98040ce713 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -840,7 +840,7 @@ RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(cons (void**)&intersectedEntity, lockType, &result.accurate, precisionPicking); if (result.intersects && intersectedEntity) { - result.entityID = intersectedEntity->getEntityItemID(); + result.entityID = intersectedEntity->getEntityItemID().id; result.properties = intersectedEntity->getProperties(); result.intersection = ray.origin + (ray.direction * result.distance); result.entity = intersectedEntity; diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index 3afd930ab0..9d8a5ab6d2 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -99,7 +99,7 @@ void RenderableWebEntityItem::render(RenderArgs* args) { return; } - if (intersection.entityID.id == getID()) { + if (intersection.entityID == getID()) { if (event->button() == Qt::MouseButton::RightButton) { if (event->type() == QEvent::MouseButtonRelease) { AbstractViewStateInterface::instance()->postLambdaEvent([this] { diff --git a/libraries/entities/src/EntityItemID.h b/libraries/entities/src/EntityItemID.h index 9f2c499c28..a8415d4e19 100644 --- a/libraries/entities/src/EntityItemID.h +++ b/libraries/entities/src/EntityItemID.h @@ -20,13 +20,7 @@ #include #include -// 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; - +const QUuid UNKNOWN_ENTITY_ID; // null uuid /// Abstract ID for editing model items. Used in EntityItem JS API. class EntityItemID { @@ -43,7 +37,7 @@ public: }; inline bool operator<(const EntityItemID& a, const EntityItemID& b) { - return a.id == b.id; + return a.id < b.id; } inline bool operator==(const EntityItemID& a, const EntityItemID& b) { diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 4e56405bef..2734eddde8 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -68,11 +68,11 @@ void bidForSimulationOwnership(EntityItemProperties& properties) { -EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& properties) { +QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties) { EntityItemProperties propertiesWithSimID = properties; - EntityItemID id = EntityItemID(QUuid::createUuid()); + EntityItemID id = EntityItemID(UNKNOWN_ENTITY_ID); // If we have a local entity tree set, then also update it. bool success = true; @@ -95,10 +95,10 @@ EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& pro queueEntityMessage(PacketTypeEntityAddOrEdit, id, propertiesWithSimID); } - return id; + return id.id; } -EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID identity) { +EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identity) { EntityItemProperties results; if (_entityTree) { _entityTree->lockForRead(); @@ -126,7 +126,7 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID return results; } -EntityItemID EntityScriptingInterface::editEntity(EntityItemID id, const EntityItemProperties& properties) { +QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& properties) { EntityItemID entityID(id); // If we have a local entity tree set, then also update it. if (_entityTree) { @@ -153,7 +153,7 @@ EntityItemID EntityScriptingInterface::editEntity(EntityItemID id, const EntityI return id; } -void EntityScriptingInterface::deleteEntity(EntityItemID id) { +void EntityScriptingInterface::deleteEntity(QUuid id) { EntityItemID entityID(id); bool shouldDelete = true; @@ -179,17 +179,17 @@ void EntityScriptingInterface::deleteEntity(EntityItemID id) { } } -EntityItemID EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const { - QUuid result; +QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const { + EntityItemID result; if (_entityTree) { _entityTree->lockForRead(); const EntityItem* closestEntity = _entityTree->findClosestEntity(center, radius); _entityTree->unlock(); if (closestEntity) { - result = closestEntity->getEntityItemID().id; + result = closestEntity->getEntityItemID(); } } - return result; + return result.id; } @@ -201,8 +201,8 @@ void EntityScriptingInterface::dumpTree() const { } } -QVector EntityScriptingInterface::findEntities(const glm::vec3& center, float radius) const { - QVector result; +QVector EntityScriptingInterface::findEntities(const glm::vec3& center, float radius) const { + QVector result; if (_entityTree) { _entityTree->lockForRead(); QVector entities; @@ -210,14 +210,14 @@ QVector EntityScriptingInterface::findEntities(const glm::vec3& ce _entityTree->unlock(); foreach (const EntityItem* entity, entities) { - result << entity->getEntityItemID(); + result << entity->getEntityItemID().id; } } return result; } -QVector EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const { - QVector result; +QVector EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const { + QVector result; if (_entityTree) { _entityTree->lockForRead(); AABox box(corner, dimensions); @@ -226,7 +226,7 @@ QVector EntityScriptingInterface::findEntitiesInBox(const glm::vec _entityTree->unlock(); foreach (const EntityItem* entity, entities) { - result << entity->getEntityItemID(); + result << entity->getEntityItemID().id; } } return result; @@ -353,7 +353,8 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra value.intersects = object.property("intersects").toVariant().toBool(); value.accurate = object.property("accurate").toVariant().toBool(); QScriptValue entityIDValue = object.property("entityID"); - EntityItemIDfromScriptValue(entityIDValue, value.entityID); + // EntityItemIDfromScriptValue(entityIDValue, value.entityID); + quuidFromScriptValue(entityIDValue, value.entityID); QScriptValue entityPropertiesValue = object.property("properties"); if (entityPropertiesValue.isValid()) { EntityItemPropertiesFromScriptValue(entityPropertiesValue, value.properties); diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 5d176c5186..f1876a836b 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -34,7 +34,7 @@ public: RayToEntityIntersectionResult(); bool intersects; bool accurate; - EntityItemID entityID; + QUuid entityID; EntityItemProperties properties; float distance; BoxFace face; @@ -70,31 +70,31 @@ public slots: Q_INVOKABLE bool canRez(); /// adds a model with the specific properties - Q_INVOKABLE EntityItemID addEntity(const EntityItemProperties& properties); + Q_INVOKABLE QUuid addEntity(const EntityItemProperties& properties); /// 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 - Q_INVOKABLE EntityItemProperties getEntityProperties(EntityItemID entityID); + Q_INVOKABLE EntityItemProperties getEntityProperties(QUuid entityID); /// 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 - Q_INVOKABLE EntityItemID editEntity(EntityItemID entityID, const EntityItemProperties& properties); + Q_INVOKABLE QUuid editEntity(QUuid entityID, const EntityItemProperties& properties); /// deletes a model - Q_INVOKABLE void deleteEntity(EntityItemID entityID); + Q_INVOKABLE void deleteEntity(QUuid entityID); /// finds the closest model to the center point, within 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 - Q_INVOKABLE EntityItemID findClosestEntity(const glm::vec3& center, float radius) const; + Q_INVOKABLE QUuid findClosestEntity(const glm::vec3& center, float radius) const; /// 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 - Q_INVOKABLE QVector findEntities(const glm::vec3& center, float radius) const; + Q_INVOKABLE QVector findEntities(const glm::vec3& center, float radius) const; /// 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 - Q_INVOKABLE QVector findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const; + Q_INVOKABLE QVector 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 /// may be inaccurate if the engine is unable to access the visible entities, in which case result.accurate @@ -142,7 +142,6 @@ signals: void deletingEntity(const EntityItemID& entityID); void addingEntity(const EntityItemID& entityID); - void changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID); void clearingEntities(); private: diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 48d99a2cbf..dda26079b2 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -1062,7 +1062,7 @@ bool EntityTree::readFromMap(QVariantMap& map) { EntityItem* entity = addEntity(entityItemID, properties); if (!entity) { - qCDebug(entities) << "adding Entity failed:" << entityItemID << entity->getType(); + qCDebug(entities) << "adding Entity failed:" << entityItemID << properties.getType(); } } diff --git a/libraries/entities/src/MovingEntitiesOperator.cpp b/libraries/entities/src/MovingEntitiesOperator.cpp index 32dc01b950..1418f107bb 100644 --- a/libraries/entities/src/MovingEntitiesOperator.cpp +++ b/libraries/entities/src/MovingEntitiesOperator.cpp @@ -51,7 +51,7 @@ MovingEntitiesOperator::~MovingEntitiesOperator() { void MovingEntitiesOperator::addEntityToMoveList(EntityItem* entity, const AACube& newCube) { - EntityTreeElement* oldContainingElement = _tree->getContainingElement(entity->getID()); + EntityTreeElement* oldContainingElement = _tree->getContainingElement(entity->getEntityItemID()); AABox newCubeClamped = newCube.clamp(0.0f, (float)TREE_SCALE); if (_wantDebug) { @@ -68,7 +68,7 @@ void MovingEntitiesOperator::addEntityToMoveList(EntityItem* entity, const AACub } if (!oldContainingElement) { - qCDebug(entities) << "UNEXPECTED!!!! attempting to move entity "<< entity->getID() + qCDebug(entities) << "UNEXPECTED!!!! attempting to move entity "<< entity->getEntityItemID() << "that has no containing element. "; return; // bail without adding. } @@ -90,7 +90,7 @@ void MovingEntitiesOperator::addEntityToMoveList(EntityItem* entity, const AACub if (_wantDebug) { qCDebug(entities) << "MovingEntitiesOperator::addEntityToMoveList() -----------------------------"; - qCDebug(entities) << " details.entity:" << details.entity->getID(); + qCDebug(entities) << " details.entity:" << details.entity->getEntityItemID(); qCDebug(entities) << " details.oldContainingElementCube:" << details.oldContainingElementCube; qCDebug(entities) << " details.newCube:" << details.newCube; qCDebug(entities) << " details.newCubeClamped:" << details.newCubeClamped; @@ -122,7 +122,7 @@ bool MovingEntitiesOperator::shouldRecurseSubTree(OctreeElement* element) { if (_wantDebug) { qCDebug(entities) << "MovingEntitiesOperator::shouldRecurseSubTree() details["<< detailIndex <<"]-----------------------------"; qCDebug(entities) << " element:" << element->getAACube(); - qCDebug(entities) << " details.entity:" << details.entity->getID(); + qCDebug(entities) << " details.entity:" << details.entity->getEntityItemID(); qCDebug(entities) << " details.oldContainingElementCube:" << details.oldContainingElementCube; qCDebug(entities) << " details.newCube:" << details.newCube; qCDebug(entities) << " details.newCubeClamped:" << details.newCubeClamped; @@ -167,7 +167,7 @@ bool MovingEntitiesOperator::preRecursion(OctreeElement* element) { qCDebug(entities) << "MovingEntitiesOperator::preRecursion() details["<< detailIndex <<"]-----------------------------"; qCDebug(entities) << " entityTreeElement:" << entityTreeElement->getAACube(); qCDebug(entities) << " entityTreeElement->bestFitBounds(details.newCube):" << entityTreeElement->bestFitBounds(details.newCube); - qCDebug(entities) << " details.entity:" << details.entity->getID(); + qCDebug(entities) << " details.entity:" << details.entity->getEntityItemID(); qCDebug(entities) << " details.oldContainingElementCube:" << details.oldContainingElementCube; qCDebug(entities) << " entityTreeElement:" << entityTreeElement; qCDebug(entities) << " details.newCube:" << details.newCube; @@ -193,7 +193,7 @@ bool MovingEntitiesOperator::preRecursion(OctreeElement* element) { // If this element is the best fit for the new bounds of this entity then add the entity to the element if (!details.newFound && entityTreeElement->bestFitBounds(details.newCube)) { - QUuid entityItemID = details.entity->getID(); + EntityItemID entityItemID = details.entity->getEntityItemID(); // remove from the old before adding EntityTreeElement* oldElement = details.entity->getElement(); if (oldElement != entityTreeElement) { From 124ff68cee8d478223153758479611a1c9141e67 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 20 May 2015 14:22:08 -0700 Subject: [PATCH 5/8] make EntityItemID a subclass of QUuid --- assignment-client/src/Agent.cpp | 8 ----- .../src/entities/EntityServer.cpp | 18 ---------- interface/src/DatagramProcessor.cpp | 3 -- .../src/EntityTreeRenderer.cpp | 2 +- libraries/entities/src/EntityItem.cpp | 2 +- libraries/entities/src/EntityItemID.cpp | 28 +++++++-------- libraries/entities/src/EntityItemID.h | 34 +++++++++---------- .../entities/src/EntityItemProperties.cpp | 4 +-- .../entities/src/EntityScriptingInterface.cpp | 12 +++---- libraries/entities/src/EntityTree.cpp | 10 +----- libraries/entities/src/EntityTree.h | 1 - libraries/networking/src/PacketHeaders.cpp | 1 - libraries/networking/src/PacketHeaders.h | 2 +- libraries/script-engine/src/ScriptEngine.cpp | 4 ++- 14 files changed, 45 insertions(+), 84 deletions(-) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 3030f82cf1..a23c1c0972 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -73,14 +73,6 @@ void Agent::readPendingDatagrams() { } } - } else if (datagramPacketType == PacketTypeEntityAddResponse) { - // also give our local entity tree a chance to remap any internal locally created entities - _entityViewer.getTree()->handleAddEntityResponse(receivedPacket); - - // Make sure our Node and NodeList knows we've heard from this node. - SharedNodePointer sourceNode = nodeList->sendingNodeForPacket(receivedPacket); - sourceNode->setLastHeardMicrostamp(usecTimestampNow()); - } else if (datagramPacketType == PacketTypeOctreeStats || datagramPacketType == PacketTypeEntityData || datagramPacketType == PacketTypeEntityErase diff --git a/assignment-client/src/entities/EntityServer.cpp b/assignment-client/src/entities/EntityServer.cpp index 9c57f6c757..b94b4a0c60 100644 --- a/assignment-client/src/entities/EntityServer.cpp +++ b/assignment-client/src/entities/EntityServer.cpp @@ -60,24 +60,6 @@ void EntityServer::beforeRun() { } void EntityServer::entityCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode) { - - unsigned char outputBuffer[MAX_PACKET_SIZE]; - unsigned char* copyAt = outputBuffer; - - auto nodeList = DependencyManager::get(); - - int numBytesPacketHeader = nodeList->populatePacketHeader(reinterpret_cast(outputBuffer), PacketTypeEntityAddResponse); - int packetLength = numBytesPacketHeader; - copyAt += numBytesPacketHeader; - - // encode the entity ID - QUuid entityID = newEntity.getID(); - QByteArray encodedID = entityID.toRfc4122(); - memcpy(copyAt, encodedID.constData(), encodedID.size()); - copyAt += sizeof(entityID); - packetLength += sizeof(entityID); - - nodeList->writeDatagram((char*) outputBuffer, packetLength, senderNode); } diff --git a/interface/src/DatagramProcessor.cpp b/interface/src/DatagramProcessor.cpp index 474aaf24b5..f691527186 100644 --- a/interface/src/DatagramProcessor.cpp +++ b/interface/src/DatagramProcessor.cpp @@ -82,9 +82,6 @@ void DatagramProcessor::processDatagrams() { break; } - case PacketTypeEntityAddResponse: - application->getEntities()->getTree()->handleAddEntityResponse(incomingPacket); - break; case PacketTypeEntityData: case PacketTypeEntityErase: case PacketTypeOctreeStats: diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 98040ce713..c8b20e92e1 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -840,7 +840,7 @@ RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(cons (void**)&intersectedEntity, lockType, &result.accurate, precisionPicking); if (result.intersects && intersectedEntity) { - result.entityID = intersectedEntity->getEntityItemID().id; + result.entityID = intersectedEntity->getEntityItemID(); result.properties = intersectedEntity->getProperties(); result.intersection = ray.origin + (ray.direction * result.distance); result.entity = intersectedEntity; diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 4940095e3e..e8210c7e79 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -30,7 +30,7 @@ bool EntityItem::_sendPhysicsUpdates = true; EntityItem::EntityItem(const EntityItemID& entityItemID) : _type(EntityTypes::Unknown), - _id(entityItemID.id), + _id(entityItemID), _lastSimulated(0), _lastUpdated(0), _lastEdited(0), diff --git a/libraries/entities/src/EntityItemID.cpp b/libraries/entities/src/EntityItemID.cpp index 696924403e..4e66f5d156 100644 --- a/libraries/entities/src/EntityItemID.cpp +++ b/libraries/entities/src/EntityItemID.cpp @@ -18,28 +18,26 @@ #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() : QUuid() { } + +EntityItemID::EntityItemID(const QUuid& id) : QUuid(id) +{ +} + +// EntityItemID::EntityItemID(const EntityItemID& other) : QUuid(other) +// { +// } + EntityItemID EntityItemID::readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead) { EntityItemID result; if (bytesLeftToRead >= NUM_BYTES_RFC4122_UUID) { // id QByteArray encodedID((const char*)data, NUM_BYTES_RFC4122_UUID); - result.id = QUuid::fromRfc4122(encodedID); + result = QUuid::fromRfc4122(encodedID); } return result; } @@ -49,9 +47,9 @@ QScriptValue EntityItemID::toScriptValue(QScriptEngine* engine) const { } QScriptValue EntityItemIDtoScriptValue(QScriptEngine* engine, const EntityItemID& id) { - return quuidToScriptValue(engine, id.id); + return quuidToScriptValue(engine, id); } void EntityItemIDfromScriptValue(const QScriptValue &object, EntityItemID& id) { - quuidFromScriptValue(object, id.id); + quuidFromScriptValue(object, id); } diff --git a/libraries/entities/src/EntityItemID.h b/libraries/entities/src/EntityItemID.h index a8415d4e19..547907625d 100644 --- a/libraries/entities/src/EntityItemID.h +++ b/libraries/entities/src/EntityItemID.h @@ -23,37 +23,37 @@ const QUuid UNKNOWN_ENTITY_ID; // null uuid /// Abstract ID for editing model items. Used in EntityItem JS API. -class EntityItemID { +class EntityItemID : public QUuid { public: EntityItemID(); EntityItemID(const QUuid& id); - EntityItemID(const EntityItemID& other); + // 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; } + bool isInvalidID() const { return *this == UNKNOWN_ENTITY_ID; } - QUuid 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.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 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 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 << "]"; + debug << "[entity-id:" << id.toString() << "]"; return debug; } diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index cf3d3adaa3..5f1d063b36 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -586,7 +586,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem // id // encode our ID as a byte count coded byte stream - QByteArray encodedID = id.id.toRfc4122(); // NUM_BYTES_RFC4122_UUID + QByteArray encodedID = id.toRfc4122(); // NUM_BYTES_RFC4122_UUID // encode our ID as a byte count coded byte stream ByteCountCoded tokenCoder; @@ -990,7 +990,7 @@ bool EntityItemProperties::encodeEraseEntityMessage(const EntityItemID& entityIt copyAt += sizeof(numberOfIds); outputLength = sizeof(numberOfIds); - QUuid entityID = entityItemID.id; + QUuid entityID = entityItemID; QByteArray encodedEntityID = entityID.toRfc4122(); memcpy(copyAt, encodedEntityID.constData(), NUM_BYTES_RFC4122_UUID); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 2734eddde8..9231867e0e 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -72,7 +72,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties EntityItemProperties propertiesWithSimID = properties; - EntityItemID id = EntityItemID(UNKNOWN_ENTITY_ID); + EntityItemID id = EntityItemID(QUuid::createUuid()); // If we have a local entity tree set, then also update it. bool success = true; @@ -95,7 +95,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties queueEntityMessage(PacketTypeEntityAddOrEdit, id, propertiesWithSimID); } - return id.id; + return id; } EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identity) { @@ -189,7 +189,7 @@ QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float result = closestEntity->getEntityItemID(); } } - return result.id; + return result; } @@ -210,7 +210,7 @@ QVector EntityScriptingInterface::findEntities(const glm::vec3& center, f _entityTree->unlock(); foreach (const EntityItem* entity, entities) { - result << entity->getEntityItemID().id; + result << entity->getEntityItemID(); } } return result; @@ -226,7 +226,7 @@ QVector EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corn _entityTree->unlock(); foreach (const EntityItem* entity, entities) { - result << entity->getEntityItemID().id; + result << entity->getEntityItemID(); } } return result; @@ -253,7 +253,7 @@ RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorke (void**)&intersectedEntity, lockType, &result.accurate, precisionPicking); if (result.intersects && intersectedEntity) { - result.entityID = intersectedEntity->getEntityItemID().id; + result.entityID = intersectedEntity->getEntityItemID(); result.properties = intersectedEntity->getProperties(); result.intersection = ray.origin + (ray.direction * result.distance); } diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index dda26079b2..1a8a13e246 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -367,7 +367,7 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator) // set up the deleted entities ID quint64 deletedAt = usecTimestampNow(); _recentlyDeletedEntitiesLock.lockForWrite(); - _recentlyDeletedEntityItemIDs.insert(deletedAt, theEntity->getEntityItemID().id); + _recentlyDeletedEntityItemIDs.insert(deletedAt, theEntity->getEntityItemID()); _recentlyDeletedEntitiesLock.unlock(); } @@ -381,14 +381,6 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator) } } -void EntityTree::handleAddEntityResponse(const QByteArray& packet) { - - if (!getIsClient()) { - qCDebug(entities) << "UNEXPECTED!!! EntityTree::handleAddEntityResponse() with !getIsClient() ***"; - return; - } -} - class FindNearPointArgs { public: diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index a7fa438984..43cd8780ab 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -135,7 +135,6 @@ public: int processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode); int processEraseMessageDetails(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode); - void handleAddEntityResponse(const QByteArray& packet); EntityItemFBXService* getFBXService() const { return _fbxService; } void setFBXService(EntityItemFBXService* service) { _fbxService = service; } diff --git a/libraries/networking/src/PacketHeaders.cpp b/libraries/networking/src/PacketHeaders.cpp index 262d1175b6..cc373a59ee 100644 --- a/libraries/networking/src/PacketHeaders.cpp +++ b/libraries/networking/src/PacketHeaders.cpp @@ -119,7 +119,6 @@ QString nameForPacketType(PacketType packetType) { PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityData); PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityAddOrEdit); PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityErase); - PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityAddResponse); PACKET_TYPE_NAME_LOOKUP(PacketTypeOctreeDataNack); PACKET_TYPE_NAME_LOOKUP(PacketTypeStopNode); PACKET_TYPE_NAME_LOOKUP(PacketTypeAudioEnvironment); diff --git a/libraries/networking/src/PacketHeaders.h b/libraries/networking/src/PacketHeaders.h index af4f0bf683..1adfcf5ca8 100644 --- a/libraries/networking/src/PacketHeaders.h +++ b/libraries/networking/src/PacketHeaders.h @@ -70,7 +70,7 @@ enum PacketType { PacketTypeEntityData, PacketTypeEntityAddOrEdit, PacketTypeEntityErase, - PacketTypeEntityAddResponse, + UNUSED_11, PacketTypeOctreeDataNack, // 45 PacketTypeStopNode, PacketTypeAudioEnvironment, diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 8668fb02d3..427944e254 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -319,8 +319,10 @@ void ScriptEngine::init() { registerAudioMetaTypes(this); qScriptRegisterMetaType(this, EntityItemPropertiesToScriptValue, EntityItemPropertiesFromScriptValue); + qScriptRegisterMetaType(this, EntityItemIDtoScriptValue, EntityItemIDfromScriptValue); qScriptRegisterMetaType(this, RayToEntityIntersectionResultToScriptValue, RayToEntityIntersectionResultFromScriptValue); - qScriptRegisterSequenceMetaType >(this); + qScriptRegisterSequenceMetaType>(this); + qScriptRegisterSequenceMetaType>(this); qScriptRegisterSequenceMetaType >(this); qScriptRegisterSequenceMetaType >(this); From 4a59dc24c5bb443a034fb871cea0215400b22235 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 20 May 2015 14:52:03 -0700 Subject: [PATCH 6/8] split entity-add and entity-edit messages --- .../entities/src/EntityEditPacketSender.cpp | 2 +- .../entities/src/EntityScriptingInterface.cpp | 6 +++--- libraries/entities/src/EntityTree.cpp | 21 +++++++++++-------- libraries/networking/src/PacketHeaders.cpp | 6 ++++-- libraries/networking/src/PacketHeaders.h | 8 ++++--- libraries/physics/src/EntityMotionState.cpp | 2 +- 6 files changed, 26 insertions(+), 19 deletions(-) diff --git a/libraries/entities/src/EntityEditPacketSender.cpp b/libraries/entities/src/EntityEditPacketSender.cpp index e94725782d..8d03ca0fcb 100644 --- a/libraries/entities/src/EntityEditPacketSender.cpp +++ b/libraries/entities/src/EntityEditPacketSender.cpp @@ -21,7 +21,7 @@ void EntityEditPacketSender::adjustEditPacketForClockSkew(PacketType type, unsigned char* editBuffer, size_t length, int clockSkew) { - if (type == PacketTypeEntityAddOrEdit) { + if (type == PacketTypeEntityAdd || type == PacketTypeEntityEdit) { EntityItem::adjustEditPacketForClockSkew(editBuffer, length, clockSkew); } } diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 9231867e0e..351bbc3643 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -92,7 +92,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties // queue the packet if (success) { - queueEntityMessage(PacketTypeEntityAddOrEdit, id, propertiesWithSimID); + queueEntityMessage(PacketTypeEntityAdd, id, propertiesWithSimID); } return id; @@ -144,12 +144,12 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& entity->setLastBroadcast(usecTimestampNow()); modifiedProperties.setType(entity->getType()); bidForSimulationOwnership(modifiedProperties); - queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, modifiedProperties); + queueEntityMessage(PacketTypeEntityEdit, entityID, modifiedProperties); return id; } } - queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); + queueEntityMessage(PacketTypeEntityEdit, entityID, properties); return id; } diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 1a8a13e246..e1e4bd6095 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -65,7 +65,8 @@ void EntityTree::eraseAllOctreeElements(bool createNewRoot) { bool EntityTree::handlesEditPacketType(PacketType packetType) const { // we handle these types of "edit" packets switch (packetType) { - case PacketTypeEntityAddOrEdit: + case PacketTypeEntityAdd: + case PacketTypeEntityEdit: case PacketTypeEntityErase: return true; default: @@ -559,20 +560,19 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char break; } - case PacketTypeEntityAddOrEdit: { + case PacketTypeEntityAdd: + case PacketTypeEntityEdit: { EntityItemID entityItemID; EntityItemProperties properties; 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 // an existing entity... handle appropriately if (validEditPacket) { // search for the entity by EntityItemID EntityItem* existingEntity = findEntityByEntityItemID(entityItemID); - - // If this is a knownID, then it should exist in our tree - if (existingEntity) { + if (existingEntity && packetType == PacketTypeEntityEdit) { // if the EntityItem exists, then update it if (wantEditLogging()) { qCDebug(entities) << "User [" << senderNode->getUUID() << "] editing entity. ID:" << entityItemID; @@ -580,7 +580,7 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char } updateEntity(entityItemID, properties, senderNode); existingEntity->markAsChangedOnServer(); - } else { + } else if (packetType == PacketTypeEntityAdd) { if (senderNode->getCanRez()) { // this is a new entity... assign a new entityID if (wantEditLogging()) { @@ -599,8 +599,11 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char } } else { - qCDebug(entities) << "User without 'rez rights' [" << senderNode->getUUID() << "] attempted to add an entity."; + qCDebug(entities) << "User without 'rez rights' [" << senderNode->getUUID() + << "] attempted to add an entity."; } + } else { + qCDebug(entities) << "Add or Edit failed." << packetType << existingEntity; } } break; @@ -1009,7 +1012,7 @@ bool EntityTree::sendEntitiesOperation(OctreeElement* element, void* extraData) properties.markAllChanged(); // so the entire property set is considered new, since we're making a new entity // queue the packet to send to the server - args->packetSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, newID, properties); + args->packetSender->queueEditEntityMessage(PacketTypeEntityAdd, newID, properties); // also update the local tree instantly (note: this is not our tree, but an alternate tree) if (args->localTree) { diff --git a/libraries/networking/src/PacketHeaders.cpp b/libraries/networking/src/PacketHeaders.cpp index cc373a59ee..6a5b703a29 100644 --- a/libraries/networking/src/PacketHeaders.cpp +++ b/libraries/networking/src/PacketHeaders.cpp @@ -70,7 +70,8 @@ PacketVersion versionForPacketType(PacketType packetType) { return 1; case PacketTypeStopNode: return 1; - case PacketTypeEntityAddOrEdit: + case PacketTypeEntityAdd: + case PacketTypeEntityEdit: case PacketTypeEntityData: return VERSION_NO_ENTITY_ID_SWAP; case PacketTypeEntityErase: @@ -117,7 +118,6 @@ QString nameForPacketType(PacketType packetType) { PACKET_TYPE_NAME_LOOKUP(PacketTypeNodeJsonStats); PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityQuery); PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityData); - PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityAddOrEdit); PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityErase); PACKET_TYPE_NAME_LOOKUP(PacketTypeOctreeDataNack); PACKET_TYPE_NAME_LOOKUP(PacketTypeStopNode); @@ -128,6 +128,8 @@ QString nameForPacketType(PacketType packetType) { PACKET_TYPE_NAME_LOOKUP(PacketTypeIceServerHeartbeatResponse); PACKET_TYPE_NAME_LOOKUP(PacketTypeUnverifiedPing); PACKET_TYPE_NAME_LOOKUP(PacketTypeUnverifiedPingReply); + PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityAdd); + PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityEdit); default: return QString("Type: ") + QString::number((int)packetType); } diff --git a/libraries/networking/src/PacketHeaders.h b/libraries/networking/src/PacketHeaders.h index 1adfcf5ca8..9568abb2cb 100644 --- a/libraries/networking/src/PacketHeaders.h +++ b/libraries/networking/src/PacketHeaders.h @@ -68,9 +68,9 @@ enum PacketType { PacketTypeNodeJsonStats, PacketTypeEntityQuery, // 40 PacketTypeEntityData, - PacketTypeEntityAddOrEdit, - PacketTypeEntityErase, UNUSED_11, + PacketTypeEntityErase, + UNUSED_12, PacketTypeOctreeDataNack, // 45 PacketTypeStopNode, PacketTypeAudioEnvironment, @@ -79,7 +79,9 @@ enum PacketType { PacketTypeIceServerHeartbeat, // 50 PacketTypeIceServerHeartbeatResponse, PacketTypeUnverifiedPing, - PacketTypeUnverifiedPingReply + PacketTypeUnverifiedPingReply, + PacketTypeEntityAdd, + PacketTypeEntityEdit }; typedef char PacketVersion; diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 9bba80054f..18651a7ac5 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -433,7 +433,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q qCDebug(physics) << "EntityMotionState::sendUpdate()... calling queueEditEntityMessage()..."; #endif - entityPacketSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, id, properties); + entityPacketSender->queueEditEntityMessage(PacketTypeEntityEdit, id, properties); _entity->setLastBroadcast(usecTimestampNow()); } else { #ifdef WANT_DEBUG From d8beed34d6cf08381e507658a3cf38cdce05f167 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 20 May 2015 16:27:28 -0700 Subject: [PATCH 7/8] remove // ? comments --- examples/entityScripts/sitOnEntity.js | 2 +- examples/html/entityList.html | 4 ++-- examples/html/entityProperties.html | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/entityScripts/sitOnEntity.js b/examples/entityScripts/sitOnEntity.js index 0ba2c959a2..8338761c41 100644 --- a/examples/entityScripts/sitOnEntity.js +++ b/examples/entityScripts/sitOnEntity.js @@ -312,7 +312,7 @@ this.indicator[i].position, this.indicator[i].scale / 2)) { clickedOnSeat = true; - seat.model = this.entityID; // ?? + seat.model = this.entityID; seat.position = this.indicator[i].position; seat.rotation = this.indicator[i].orientation; } diff --git a/examples/html/entityList.html b/examples/html/entityList.html index 9a46efe7b5..9506c78994 100644 --- a/examples/html/entityList.html +++ b/examples/html/entityList.html @@ -65,7 +65,7 @@ entityList.add([{ id: id, name: name, type: type, url: filename }], function(items) { var el = items[0].elm; - var id = items[0]._values.id; // ? + var id = items[0]._values.id; entities[id] = { id: id, name: name, @@ -169,7 +169,7 @@ elEntityTable.style.display = "table"; elNoEntitiesMessage.style.display = "none"; for (var i = 0; i < newEntities.length; i++) { - var id = newEntities[i].id; // ? + var id = newEntities[i].id; addEntity(id, newEntities[i].name, newEntities[i].type, newEntities[i].url); } updateSelectedEntities(data.selectedIDs); diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index 2385588fd5..a2ff71d010 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -358,7 +358,7 @@ var types = {}; for (var i = 0; i < selections.length; i++) { - ids.push(selections[i].id); // ? + ids.push(selections[i].id); var type = selections[i].properties.type; if (types[type] === undefined) { types[type] = 0; From aa1d3eb82a020fdf7b5231fc8b7999b1f7d24100 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 20 May 2015 17:31:57 -0700 Subject: [PATCH 8/8] respond to code review --- examples/example/entities/butterflies.js | 3 --- libraries/entities/src/EntityTree.cpp | 1 + libraries/entities/src/MovingEntitiesOperator.h | 4 ++-- libraries/networking/src/PacketHeaders.h | 8 +++----- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/examples/example/entities/butterflies.js b/examples/example/entities/butterflies.js index 7c8cd18376..5ad11c46e9 100644 --- a/examples/example/entities/butterflies.js +++ b/examples/example/entities/butterflies.js @@ -106,9 +106,6 @@ function updateButterflies(deltaTime) { var CHANCE_OF_IMPULSE = 0.04; for (var i = 0; i < numButterflies; i++) { if (Math.random() < CHANCE_OF_IMPULSE) { - if (!butterflies[i]) { - butterflies[i] = Entities.identifyEntity(butterflies[i]); - } var properties = Entities.getEntityProperties(butterflies[i]); if (Vec3.length(Vec3.subtract(properties.position, flockPosition)) > range) { Entities.editEntity(butterflies[i], { position: flockPosition } ); diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index e1e4bd6095..ce107f1fbd 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -587,6 +587,7 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char qCDebug(entities) << "User [" << senderNode->getUUID() << "] adding entity."; qCDebug(entities) << " properties:" << properties; } + properties.setCreated(properties.getLastEdited()); EntityItem* newEntity = addEntity(entityItemID, properties); if (newEntity) { newEntity->markAsChangedOnServer(); diff --git a/libraries/entities/src/MovingEntitiesOperator.h b/libraries/entities/src/MovingEntitiesOperator.h index 51eef0d0e3..760b001081 100644 --- a/libraries/entities/src/MovingEntitiesOperator.h +++ b/libraries/entities/src/MovingEntitiesOperator.h @@ -25,11 +25,11 @@ public: }; inline uint qHash(const EntityToMoveDetails& a, uint seed) { - return qHash(a.entity, seed); + return qHash(a.entity->getEntityItemID(), seed); } inline bool operator==(const EntityToMoveDetails& a, const EntityToMoveDetails& b) { - return a.entity == b.entity; + return a.entity->getEntityItemID() == b.entity->getEntityItemID(); } class MovingEntitiesOperator : public RecurseOctreeOperator { diff --git a/libraries/networking/src/PacketHeaders.h b/libraries/networking/src/PacketHeaders.h index 9568abb2cb..d64986c1a0 100644 --- a/libraries/networking/src/PacketHeaders.h +++ b/libraries/networking/src/PacketHeaders.h @@ -68,9 +68,9 @@ enum PacketType { PacketTypeNodeJsonStats, PacketTypeEntityQuery, // 40 PacketTypeEntityData, - UNUSED_11, + PacketTypeEntityAdd, PacketTypeEntityErase, - UNUSED_12, + PacketTypeEntityEdit, PacketTypeOctreeDataNack, // 45 PacketTypeStopNode, PacketTypeAudioEnvironment, @@ -79,9 +79,7 @@ enum PacketType { PacketTypeIceServerHeartbeat, // 50 PacketTypeIceServerHeartbeatResponse, PacketTypeUnverifiedPing, - PacketTypeUnverifiedPingReply, - PacketTypeEntityAdd, - PacketTypeEntityEdit + PacketTypeUnverifiedPingReply }; typedef char PacketVersion;