From ccc9eabd33afe152c46ab471569ddcd2eac5909e Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 26 Jun 2014 16:39:52 -0700 Subject: [PATCH] first cut at renaming Models to Entities --- assignment-client/src/Agent.cpp | 36 +- assignment-client/src/Agent.h | 10 +- assignment-client/src/AssignmentFactory.cpp | 4 +- assignment-client/src/models/ModelNodeData.h | 22 +- assignment-client/src/models/ModelServer.cpp | 90 ++-- assignment-client/src/models/ModelServer.h | 32 +- .../src/models/ModelServerConsts.h | 8 +- domain-server/src/DomainServer.cpp | 2 +- examples/editModels.js | 261 +++++----- interface/src/Application.cpp | 64 +-- interface/src/Application.h | 14 +- interface/src/DatagramProcessor.cpp | 14 +- interface/src/models/ModelTreeRenderer.cpp | 144 +++--- interface/src/models/ModelTreeRenderer.h | 34 +- interface/src/ui/NodeBounds.cpp | 20 +- interface/src/ui/NodeBounds.h | 6 +- interface/src/ui/OctreeStatsDialog.cpp | 4 +- .../src/voxels/OctreePacketProcessor.cpp | 8 +- .../models/src/EntityEditPacketSender.cpp | 20 +- libraries/models/src/EntityEditPacketSender.h | 22 +- libraries/models/src/EntityItem.cpp | 338 ++++++------- libraries/models/src/EntityItem.h | 118 ++--- .../models/src/EntityScriptingInterface.cpp | 198 ++++---- .../models/src/EntityScriptingInterface.h | 74 +-- libraries/models/src/EntityTree.cpp | 456 +++++++++--------- libraries/models/src/EntityTree.h | 94 ++-- libraries/models/src/EntityTreeElement.cpp | 348 ++++++------- libraries/models/src/EntityTreeElement.h | 90 ++-- .../models/src/EntityTreeHeadlessViewer.cpp | 18 +- .../models/src/EntityTreeHeadlessViewer.h | 26 +- libraries/networking/src/Assignment.cpp | 4 +- libraries/networking/src/Assignment.h | 2 +- libraries/networking/src/Node.cpp | 2 +- libraries/networking/src/Node.h | 2 +- libraries/networking/src/PacketHeaders.cpp | 4 +- libraries/networking/src/PacketHeaders.h | 16 +- libraries/script-engine/src/ScriptEngine.cpp | 32 +- libraries/script-engine/src/ScriptEngine.h | 8 +- tests/octree/src/ModelTests.cpp | 137 +++--- tests/octree/src/ModelTests.h | 10 +- tests/octree/src/OctreeTests.cpp | 54 +-- tests/octree/src/main.cpp | 4 +- 42 files changed, 1426 insertions(+), 1424 deletions(-) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index fcc2288356..a5ca1059f9 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -27,7 +27,7 @@ #include #include // TODO: consider moving to scriptengine.h -#include // TODO: consider moving to scriptengine.h +#include // TODO: consider moving to scriptengine.h #include "Agent.h" @@ -35,7 +35,7 @@ Agent::Agent(const QByteArray& packet) : ThreadedAssignment(packet), _voxelEditSender(), _particleEditSender(), - _modelEditSender(), + _entityEditSender(), _receivedAudioBuffer(NETWORK_BUFFER_LENGTH_SAMPLES_STEREO), _avatarHashMap() { @@ -44,7 +44,7 @@ Agent::Agent(const QByteArray& packet) : _scriptEngine.getVoxelsScriptingInterface()->setPacketSender(&_voxelEditSender); _scriptEngine.getParticlesScriptingInterface()->setPacketSender(&_particleEditSender); - _scriptEngine.getModelsScriptingInterface()->setPacketSender(&_modelEditSender); + _scriptEngine.getEntityScriptingInterface()->setPacketSender(&_entityEditSender); } void Agent::readPendingDatagrams() { @@ -72,8 +72,8 @@ void Agent::readPendingDatagrams() { _scriptEngine.getParticlesScriptingInterface()->getJurisdictionListener()-> queueReceivedPacket(matchedNode, receivedPacket); break; - case NodeType::ModelServer: - _scriptEngine.getModelsScriptingInterface()->getJurisdictionListener()-> + case NodeType::EntityServer: + _scriptEngine.getEntityScriptingInterface()->getJurisdictionListener()-> queueReceivedPacket(matchedNode, receivedPacket); break; } @@ -90,12 +90,12 @@ void Agent::readPendingDatagrams() { SharedNodePointer sourceNode = nodeList->sendingNodeForPacket(receivedPacket); sourceNode->setLastHeardMicrostamp(usecTimestampNow()); - } else if (datagramPacketType == PacketTypeModelAddResponse) { + } else if (datagramPacketType == PacketTypeEntityAddResponse) { // this will keep creatorTokenIDs to IDs mapped correctly - ModelItem::handleAddModelResponse(receivedPacket); + EntityItem::handleAddEntityResponse(receivedPacket); // also give our local particle tree a chance to remap any internal locally created particles - _modelViewer.getTree()->handleAddModelResponse(receivedPacket); + _entityViewer.getTree()->handleAddEntityResponse(receivedPacket); // Make sure our Node and NodeList knows we've heard from this node. SharedNodePointer sourceNode = nodeList->sendingNodeForPacket(receivedPacket); @@ -105,8 +105,8 @@ void Agent::readPendingDatagrams() { || datagramPacketType == PacketTypeParticleErase || datagramPacketType == PacketTypeOctreeStats || datagramPacketType == PacketTypeVoxelData - || datagramPacketType == PacketTypeModelData - || datagramPacketType == PacketTypeModelErase + || datagramPacketType == PacketTypeEntityData + || datagramPacketType == PacketTypeEntityErase ) { // Make sure our Node and NodeList knows we've heard from this node. SharedNodePointer sourceNode = nodeList->sendingNodeForPacket(receivedPacket); @@ -138,8 +138,8 @@ void Agent::readPendingDatagrams() { _particleViewer.processDatagram(mutablePacket, sourceNode); } - if (datagramPacketType == PacketTypeModelData || datagramPacketType == PacketTypeModelErase) { - _modelViewer.processDatagram(mutablePacket, sourceNode); + if (datagramPacketType == PacketTypeEntityData || datagramPacketType == PacketTypeEntityErase) { + _entityViewer.processDatagram(mutablePacket, sourceNode); } if (datagramPacketType == PacketTypeVoxelData) { @@ -185,7 +185,7 @@ void Agent::run() { << NodeType::AvatarMixer << NodeType::VoxelServer << NodeType::ParticleServer - << NodeType::ModelServer + << NodeType::EntityServer ); // figure out the URL for the script for this agent assignment @@ -252,11 +252,11 @@ void Agent::run() { _particleViewer.init(); _scriptEngine.getParticlesScriptingInterface()->setParticleTree(_particleViewer.getTree()); - _scriptEngine.registerGlobalObject("ModelViewer", &_modelViewer); - JurisdictionListener* modelJL = _scriptEngine.getModelsScriptingInterface()->getJurisdictionListener(); - _modelViewer.setJurisdictionListener(modelJL); - _modelViewer.init(); - _scriptEngine.getModelsScriptingInterface()->setModelTree(_modelViewer.getTree()); + _scriptEngine.registerGlobalObject("EntityViewer", &_entityViewer); + JurisdictionListener* modelJL = _scriptEngine.getEntityScriptingInterface()->getJurisdictionListener(); + _entityViewer.setJurisdictionListener(modelJL); + _entityViewer.init(); + _scriptEngine.getEntityScriptingInterface()->setEntityTree(_entityViewer.getTree()); _scriptEngine.setScriptContents(scriptContents); _scriptEngine.run(); diff --git a/assignment-client/src/Agent.h b/assignment-client/src/Agent.h index 9af95e757c..c7c1b26fa5 100644 --- a/assignment-client/src/Agent.h +++ b/assignment-client/src/Agent.h @@ -20,9 +20,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -64,11 +64,11 @@ private: ScriptEngine _scriptEngine; VoxelEditPacketSender _voxelEditSender; ParticleEditPacketSender _particleEditSender; - ModelEditPacketSender _modelEditSender; + EntityEditPacketSender _entityEditSender; ParticleTreeHeadlessViewer _particleViewer; VoxelTreeHeadlessViewer _voxelViewer; - ModelTreeHeadlessViewer _modelViewer; + EntityTreeHeadlessViewer _entityViewer; MixedAudioRingBuffer _receivedAudioBuffer; AvatarHashMap _avatarHashMap; diff --git a/assignment-client/src/AssignmentFactory.cpp b/assignment-client/src/AssignmentFactory.cpp index d2c2016328..709001ff85 100644 --- a/assignment-client/src/AssignmentFactory.cpp +++ b/assignment-client/src/AssignmentFactory.cpp @@ -42,8 +42,8 @@ ThreadedAssignment* AssignmentFactory::unpackAssignment(const QByteArray& packet return new ParticleServer(packet); case Assignment::MetavoxelServerType: return new MetavoxelServer(packet); - case Assignment::ModelServerType: - return new ModelServer(packet); + case Assignment::EntityServerType: + return new EntityServer(packet); default: return NULL; } diff --git a/assignment-client/src/models/ModelNodeData.h b/assignment-client/src/models/ModelNodeData.h index dda83e0225..872e7dc5da 100644 --- a/assignment-client/src/models/ModelNodeData.h +++ b/assignment-client/src/models/ModelNodeData.h @@ -1,5 +1,5 @@ // -// ModelNodeData.h +// EntityNodeData.h // assignment-client/src/models // // Created by Brad Hefta-Gaub on 4/29/14 @@ -9,26 +9,26 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_ModelNodeData_h -#define hifi_ModelNodeData_h +#ifndef hifi_EntityNodeData_h +#define hifi_EntityNodeData_h #include #include "../octree/OctreeQueryNode.h" -class ModelNodeData : public OctreeQueryNode { +class EntityNodeData : public OctreeQueryNode { public: - ModelNodeData() : + EntityNodeData() : OctreeQueryNode(), - _lastDeletedModelsSentAt(0) { }; + _lastDeletedEntitysSentAt(0) { }; - virtual PacketType getMyPacketType() const { return PacketTypeModelData; } + virtual PacketType getMyPacketType() const { return PacketTypeEntityData; } - quint64 getLastDeletedModelsSentAt() const { return _lastDeletedModelsSentAt; } - void setLastDeletedModelsSentAt(quint64 sentAt) { _lastDeletedModelsSentAt = sentAt; } + quint64 getLastDeletedEntitysSentAt() const { return _lastDeletedEntitysSentAt; } + void setLastDeletedEntitysSentAt(quint64 sentAt) { _lastDeletedEntitysSentAt = sentAt; } private: - quint64 _lastDeletedModelsSentAt; + quint64 _lastDeletedEntitysSentAt; }; -#endif // hifi_ModelNodeData_h +#endif // hifi_EntityNodeData_h diff --git a/assignment-client/src/models/ModelServer.cpp b/assignment-client/src/models/ModelServer.cpp index ae6ffaf969..ef80daa8a2 100644 --- a/assignment-client/src/models/ModelServer.cpp +++ b/assignment-client/src/models/ModelServer.cpp @@ -1,5 +1,5 @@ // -// ModelServer.cpp +// EntityServer.cpp // assignment-client/src/models // // Created by Brad Hefta-Gaub on 4/29/14 @@ -10,58 +10,58 @@ // #include -#include +#include -#include "ModelServer.h" -#include "ModelServerConsts.h" -#include "ModelNodeData.h" +#include "ModelServer.h" // rename to "EntityServer.h" +#include "ModelServerConsts.h" // rename to ""EntityServerConsts.h" +#include "ModelNodeData.h" // rename to ""EntityNodeData.h" -const char* MODEL_SERVER_NAME = "Model"; +const char* MODEL_SERVER_NAME = "Entity"; const char* MODEL_SERVER_LOGGING_TARGET_NAME = "model-server"; const char* LOCAL_MODELS_PERSIST_FILE = "resources/models.svo"; -ModelServer::ModelServer(const QByteArray& packet) : OctreeServer(packet) { +EntityServer::EntityServer(const QByteArray& packet) : OctreeServer(packet) { // nothing special to do here... } -ModelServer::~ModelServer() { - ModelTree* tree = (ModelTree*)_tree; +EntityServer::~EntityServer() { + EntityTree* tree = (EntityTree*)_tree; tree->removeNewlyCreatedHook(this); } -OctreeQueryNode* ModelServer::createOctreeQueryNode() { - return new ModelNodeData(); +OctreeQueryNode* EntityServer::createOctreeQueryNode() { + return new EntityNodeData(); } -Octree* ModelServer::createTree() { - ModelTree* tree = new ModelTree(true); +Octree* EntityServer::createTree() { + EntityTree* tree = new EntityTree(true); tree->addNewlyCreatedHook(this); return tree; } -void ModelServer::beforeRun() { - QTimer* pruneDeletedModelsTimer = new QTimer(this); - connect(pruneDeletedModelsTimer, SIGNAL(timeout()), this, SLOT(pruneDeletedModels())); +void EntityServer::beforeRun() { + QTimer* pruneDeletedEntitysTimer = new QTimer(this); + connect(pruneDeletedEntitysTimer, SIGNAL(timeout()), this, SLOT(pruneDeletedEntitys())); const int PRUNE_DELETED_MODELS_INTERVAL_MSECS = 1 * 1000; // once every second - pruneDeletedModelsTimer->start(PRUNE_DELETED_MODELS_INTERVAL_MSECS); + pruneDeletedEntitysTimer->start(PRUNE_DELETED_MODELS_INTERVAL_MSECS); } -void ModelServer::modelCreated(const ModelItem& newModel, const SharedNodePointer& senderNode) { +void EntityServer::modelCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode) { unsigned char outputBuffer[MAX_PACKET_SIZE]; unsigned char* copyAt = outputBuffer; - int numBytesPacketHeader = populatePacketHeader(reinterpret_cast(outputBuffer), PacketTypeModelAddResponse); + int numBytesPacketHeader = populatePacketHeader(reinterpret_cast(outputBuffer), PacketTypeEntityAddResponse); int packetLength = numBytesPacketHeader; copyAt += numBytesPacketHeader; // encode the creatorTokenID - uint32_t creatorTokenID = newModel.getCreatorTokenID(); + uint32_t creatorTokenID = newEntity.getCreatorTokenID(); memcpy(copyAt, &creatorTokenID, sizeof(creatorTokenID)); copyAt += sizeof(creatorTokenID); packetLength += sizeof(creatorTokenID); // encode the model ID - uint32_t modelID = newModel.getID(); + uint32_t modelID = newEntity.getID(); memcpy(copyAt, &modelID, sizeof(modelID)); copyAt += sizeof(modelID); packetLength += sizeof(modelID); @@ -70,38 +70,38 @@ void ModelServer::modelCreated(const ModelItem& newModel, const SharedNodePointe } -// ModelServer will use the "special packets" to send list of recently deleted models -bool ModelServer::hasSpecialPacketToSend(const SharedNodePointer& node) { - bool shouldSendDeletedModels = false; +// EntityServer will use the "special packets" to send list of recently deleted models +bool EntityServer::hasSpecialPacketToSend(const SharedNodePointer& node) { + bool shouldSendDeletedEntitys = false; // check to see if any new models have been added since we last sent to this node... - ModelNodeData* nodeData = static_cast(node->getLinkedData()); + EntityNodeData* nodeData = static_cast(node->getLinkedData()); if (nodeData) { - quint64 deletedModelsSentAt = nodeData->getLastDeletedModelsSentAt(); + quint64 deletedEntitysSentAt = nodeData->getLastDeletedEntitysSentAt(); - ModelTree* tree = static_cast(_tree); - shouldSendDeletedModels = tree->hasModelsDeletedSince(deletedModelsSentAt); + EntityTree* tree = static_cast(_tree); + shouldSendDeletedEntitys = tree->hasEntitysDeletedSince(deletedEntitysSentAt); } - return shouldSendDeletedModels; + return shouldSendDeletedEntitys; } -int ModelServer::sendSpecialPacket(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent) { +int EntityServer::sendSpecialPacket(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent) { unsigned char outputBuffer[MAX_PACKET_SIZE]; size_t packetLength = 0; - ModelNodeData* nodeData = static_cast(node->getLinkedData()); + EntityNodeData* nodeData = static_cast(node->getLinkedData()); if (nodeData) { - quint64 deletedModelsSentAt = nodeData->getLastDeletedModelsSentAt(); + quint64 deletedEntitysSentAt = nodeData->getLastDeletedEntitysSentAt(); quint64 deletePacketSentAt = usecTimestampNow(); - ModelTree* tree = static_cast(_tree); + EntityTree* tree = static_cast(_tree); bool hasMoreToSend = true; // TODO: is it possible to send too many of these packets? what if you deleted 1,000,000 models? packetsSent = 0; while (hasMoreToSend) { - hasMoreToSend = tree->encodeModelsDeletedSince(queryNode->getSequenceNumber(), deletedModelsSentAt, + hasMoreToSend = tree->encodeEntitysDeletedSince(queryNode->getSequenceNumber(), deletedEntitysSentAt, outputBuffer, MAX_PACKET_SIZE, packetLength); //qDebug() << "sending PacketType_MODEL_ERASE packetLength:" << packetLength; @@ -111,30 +111,30 @@ int ModelServer::sendSpecialPacket(const SharedNodePointer& node, OctreeQueryNod packetsSent++; } - nodeData->setLastDeletedModelsSentAt(deletePacketSentAt); + nodeData->setLastDeletedEntitysSentAt(deletePacketSentAt); } // TODO: caller is expecting a packetLength, what if we send more than one packet?? return packetLength; } -void ModelServer::pruneDeletedModels() { - ModelTree* tree = static_cast(_tree); - if (tree->hasAnyDeletedModels()) { +void EntityServer::pruneDeletedEntitys() { + EntityTree* tree = static_cast(_tree); + if (tree->hasAnyDeletedEntitys()) { //qDebug() << "there are some deleted models to consider..."; - quint64 earliestLastDeletedModelsSent = usecTimestampNow() + 1; // in the future + quint64 earliestLastDeletedEntitysSent = usecTimestampNow() + 1; // in the future foreach (const SharedNodePointer& otherNode, NodeList::getInstance()->getNodeHash()) { if (otherNode->getLinkedData()) { - ModelNodeData* nodeData = static_cast(otherNode->getLinkedData()); - quint64 nodeLastDeletedModelsSentAt = nodeData->getLastDeletedModelsSentAt(); - if (nodeLastDeletedModelsSentAt < earliestLastDeletedModelsSent) { - earliestLastDeletedModelsSent = nodeLastDeletedModelsSentAt; + EntityNodeData* nodeData = static_cast(otherNode->getLinkedData()); + quint64 nodeLastDeletedEntitysSentAt = nodeData->getLastDeletedEntitysSentAt(); + if (nodeLastDeletedEntitysSentAt < earliestLastDeletedEntitysSent) { + earliestLastDeletedEntitysSent = nodeLastDeletedEntitysSentAt; } } } - //qDebug() << "earliestLastDeletedModelsSent=" << earliestLastDeletedModelsSent; - tree->forgetModelsDeletedBefore(earliestLastDeletedModelsSent); + //qDebug() << "earliestLastDeletedEntitysSent=" << earliestLastDeletedEntitysSent; + tree->forgetEntitysDeletedBefore(earliestLastDeletedEntitysSent); } } diff --git a/assignment-client/src/models/ModelServer.h b/assignment-client/src/models/ModelServer.h index 8a26f07f11..2c2e5d4ead 100644 --- a/assignment-client/src/models/ModelServer.h +++ b/assignment-client/src/models/ModelServer.h @@ -1,5 +1,5 @@ // -// ModelServer.h +// EntityServer.h // assignment-client/src/models // // Created by Brad Hefta-Gaub on 4/29/14 @@ -9,43 +9,43 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_ModelServer_h -#define hifi_ModelServer_h +#ifndef hifi_EntityServer_h +#define hifi_EntityServer_h #include "../octree/OctreeServer.h" -#include "ModelItem.h" -#include "ModelServerConsts.h" -#include "ModelTree.h" +#include "EntityItem.h" +#include "ModelServerConsts.h" // rename to ""EntityServerConsts.h" +#include "EntityTree.h" -/// Handles assignments of type ModelServer - sending models to various clients. -class ModelServer : public OctreeServer, public NewlyCreatedModelHook { +/// Handles assignments of type EntityServer - sending models to various clients. +class EntityServer : public OctreeServer, public NewlyCreatedEntityHook { Q_OBJECT public: - ModelServer(const QByteArray& packet); - ~ModelServer(); + EntityServer(const QByteArray& packet); + ~EntityServer(); // Subclasses must implement these methods virtual OctreeQueryNode* createOctreeQueryNode(); virtual Octree* createTree(); - virtual char getMyNodeType() const { return NodeType::ModelServer; } - virtual PacketType getMyQueryMessageType() const { return PacketTypeModelQuery; } + virtual char getMyNodeType() const { return NodeType::EntityServer; } + virtual PacketType getMyQueryMessageType() const { return PacketTypeEntityQuery; } virtual const char* getMyServerName() const { return MODEL_SERVER_NAME; } virtual const char* getMyLoggingServerTargetName() const { return MODEL_SERVER_LOGGING_TARGET_NAME; } virtual const char* getMyDefaultPersistFilename() const { return LOCAL_MODELS_PERSIST_FILE; } - virtual PacketType getMyEditNackType() const { return PacketTypeModelEditNack; } + virtual PacketType getMyEditNackType() const { return PacketTypeEntityEditNack; } // subclass may implement these method virtual void beforeRun(); virtual bool hasSpecialPacketToSend(const SharedNodePointer& node); virtual int sendSpecialPacket(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent); - virtual void modelCreated(const ModelItem& newModel, const SharedNodePointer& senderNode); + virtual void modelCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode); public slots: - void pruneDeletedModels(); + void pruneDeletedEntitys(); private: }; -#endif // hifi_ModelServer_h +#endif // hifi_EntityServer_h diff --git a/assignment-client/src/models/ModelServerConsts.h b/assignment-client/src/models/ModelServerConsts.h index 7d480caaac..1cdf685cd4 100644 --- a/assignment-client/src/models/ModelServerConsts.h +++ b/assignment-client/src/models/ModelServerConsts.h @@ -1,5 +1,5 @@ // -// ModelServerConsts.h +// EntityServerConsts.h // assignment-client/src/models // // Created by Brad Hefta-Gaub on 4/29/14 @@ -9,11 +9,11 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_ModelServerConsts_h -#define hifi_ModelServerConsts_h +#ifndef hifi_EntityServerConsts_h +#define hifi_EntityServerConsts_h extern const char* MODEL_SERVER_NAME; extern const char* MODEL_SERVER_LOGGING_TARGET_NAME; extern const char* LOCAL_MODELS_PERSIST_FILE; -#endif // hifi_ModelServerConsts_h +#endif // hifi_EntityServerConsts_h diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index d55a9b52ca..9da9a5f017 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -387,7 +387,7 @@ void DomainServer::populateDefaultStaticAssignmentsExcludingTypes(const QSet MIN_ANGULAR_SIZE && angularSize < MAX_ANGULAR_SIZE) { - this.glowedIntersectingModel = intersection.modelID; - Models.editModel(this.glowedIntersectingModel, { glowLevel: 0.25 }); + var angularSize = 2 * Math.atan(intersection.properties.radius / Vec3.distance(Camera.getPosition(), intersection.properties.position)) * 180 / 3.14; + if (intersection.accurate && intersection.entityID.isKnownID && angularSize > MIN_ANGULAR_SIZE && angularSize < MAX_ANGULAR_SIZE) { + this.glowedIntersectingModel = intersection.entityID; + Entities.editEntity(this.glowedIntersectingModel, { glowLevel: 0.25 }); } } } @@ -343,15 +343,15 @@ function controller(wichSide) { Overlays.editOverlay(this.topDown, { visible: show }); } - this.moveModel = function () { + this.moveEntity = function () { if (this.grabbing) { - if (!this.modelID.isKnownID) { - print("Unknown grabbed ID " + this.modelID.id + ", isKnown: " + this.modelID.isKnownID); - this.modelID = Models.findRayIntersection({ + if (!this.entityID.isKnownID) { + print("Unknown grabbed ID " + this.entityID.id + ", isKnown: " + this.entityID.isKnownID); + this.entityID = Entities.findRayIntersection({ origin: this.palmPosition, direction: this.front - }).modelID; - print("Identified ID " + this.modelID.id + ", isKnown: " + this.modelID.isKnownID); + }).entityID; + print("Identified ID " + this.entityID.id + ", isKnown: " + this.entityID.isKnownID); } var newPosition; var newRotation; @@ -398,7 +398,7 @@ function controller(wichSide) { break; } - Models.editModel(this.modelID, { + Entities.editEntity(this.entityID, { position: newPosition, modelRotation: newRotation }); @@ -504,39 +504,39 @@ function controller(wichSide) { radius: attachments[attachmentIndex].scale / 2.0, modelURL: attachments[attachmentIndex].modelURL }; - newModel = Models.addModel(newProperties); + newModel = Entities.addEntity(newProperties); } else { // There is none so ... // Checking model tree Vec3.print("Looking at: ", this.palmPosition); var pickRay = { origin: this.palmPosition, direction: Vec3.normalize(Vec3.subtract(this.tipPosition, this.palmPosition)) }; - var foundIntersection = Models.findRayIntersection(pickRay); + var foundIntersection = Entities.findRayIntersection(pickRay); if(!foundIntersection.accurate) { print("No accurate intersection"); return; } - newModel = foundIntersection.modelID; + newModel = foundIntersection.entityID; if (!newModel.isKnownID) { - var identify = Models.identifyModel(newModel); + var identify = Entities.identifyEntity(newModel); if (!identify.isKnownID) { print("Unknown ID " + identify.id + " (update loop " + newModel.id + ")"); return; } newModel = identify; } - newProperties = Models.getModelProperties(newModel); + newProperties = Entities.getEntityProperties(newModel); } - print("foundModel.modelURL=" + newProperties.modelURL); + print("foundEntity.modelURL=" + newProperties.modelURL); if (isLocked(newProperties)) { print("Model locked " + newProperties.id); } else { - var check = this.checkModel(newProperties); + var check = this.checkEntity(newProperties); if (!check.valid) { return; } @@ -563,7 +563,7 @@ var leftController = new controller(LEFT); var rightController = new controller(RIGHT); function moveModels() { - if (leftController.grabbing && rightController.grabbing && rightController.modelID.id == leftController.modelID.id) { + if (leftController.grabbing && rightController.grabbing && rightController.entityID.id == leftController.entityID.id) { var newPosition = leftController.oldModelPosition; var rotation = leftController.oldModelRotation; var ratio = 1; @@ -619,7 +619,7 @@ function moveModels() { break; } - Models.editModel(leftController.modelID, { + Entities.editEntity(leftController.entityID, { position: newPosition, modelRotation: rotation, radius: leftController.oldModelRadius * ratio @@ -635,8 +635,8 @@ function moveModels() { return; } - leftController.moveModel(); - rightController.moveModel(); + leftController.moveEntity(); + rightController.moveEntity(); } var hydraConnected = false; @@ -700,9 +700,9 @@ function moveOverlays() { -var modelSelected = false; -var selectedModelID; -var selectedModelProperties; +var entitySelected = false; +var selectedEntityID; +var selectedEntityProperties; var mouseLastPosition; var orientation; var intersection; @@ -768,7 +768,7 @@ function mousePressEvent(event) { } mouseLastPosition = { x: event.x, y: event.y }; - modelSelected = false; + entitySelected = false; var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); if (newModel == toolBar.clicked(clickedOverlay)) { @@ -780,7 +780,7 @@ function mousePressEvent(event) { var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); if (position.x > 0 && position.y > 0 && position.z > 0) { - Models.addModel({ position: position, + Entities.addEntity({ position: position, radius: radiusDefault, modelURL: url }); @@ -791,23 +791,24 @@ function mousePressEvent(event) { } else { var pickRay = Camera.computePickRay(event.x, event.y); Vec3.print("[Mouse] Looking at: ", pickRay.origin); - var foundIntersection = Models.findRayIntersection(pickRay); - + var foundIntersection = Entities.findRayIntersection(pickRay); + if(!foundIntersection.accurate) { return; } - var foundModel = foundIntersection.modelID; - - if (!foundModel.isKnownID) { - var identify = Models.identifyModel(foundModel); + var foundEntity = foundIntersection.entityID; + + if (!foundEntity.isKnownID) { + var identify = Entities.identifyEntity(foundEntity); if (!identify.isKnownID) { - print("Unknown ID " + identify.id + " (update loop " + foundModel.id + ")"); + print("Unknown ID " + identify.id + " (update loop " + foundEntity.id + ")"); return; } - foundModel = identify; + foundEntity = identify; } - - var properties = Models.getModelProperties(foundModel); + + var properties = Entities.getEntityProperties(foundEntity); + if (isLocked(properties)) { print("Model locked " + properties.id); } else { @@ -834,9 +835,9 @@ function mousePressEvent(event) { var angularSize = 2 * Math.atan(properties.radius / Vec3.distance(Camera.getPosition(), properties.position)) * 180 / 3.14; if (0 < x && angularSize > MIN_ANGULAR_SIZE) { if (angularSize < MAX_ANGULAR_SIZE) { - modelSelected = true; - selectedModelID = foundModel; - selectedModelProperties = properties; + entitySelected = true; + selectedEntityID = foundEntity; + selectedEntityProperties = properties; orientation = MyAvatar.orientation; intersection = rayPlaneIntersection(pickRay, P, Quat.getFront(orientation)); @@ -847,28 +848,28 @@ function mousePressEvent(event) { } } - if (modelSelected) { - selectedModelProperties.oldRadius = selectedModelProperties.radius; - selectedModelProperties.oldPosition = { - x: selectedModelProperties.position.x, - y: selectedModelProperties.position.y, - z: selectedModelProperties.position.z, + if (entitySelected) { + selectedEntityProperties.oldRadius = selectedEntityProperties.radius; + selectedEntityProperties.oldPosition = { + x: selectedEntityProperties.position.x, + y: selectedEntityProperties.position.y, + z: selectedEntityProperties.position.z, }; - selectedModelProperties.oldRotation = { - x: selectedModelProperties.modelRotation.x, - y: selectedModelProperties.modelRotation.y, - z: selectedModelProperties.modelRotation.z, - w: selectedModelProperties.modelRotation.w, + selectedEntityProperties.oldRotation = { + x: selectedEntityProperties.modelRotation.x, + y: selectedEntityProperties.modelRotation.y, + z: selectedEntityProperties.modelRotation.z, + w: selectedEntityProperties.modelRotation.w, }; - selectedModelProperties.glowLevel = 0.0; + selectedEntityProperties.glowLevel = 0.0; - print("Clicked on " + selectedModelID.id + " " + modelSelected); - tooltip.updateText(selectedModelProperties); + print("Clicked on " + selectedEntityID.id + " " + entitySelected); + tooltip.updateText(selectedEntityProperties); tooltip.show(true); } } -var glowedModelID = { id: -1, isKnownID: false }; +var glowedEntityID = { id: -1, isKnownID: false }; var oldModifier = 0; var modifier = 0; var wasShifted = false; @@ -879,19 +880,19 @@ function mouseMoveEvent(event) { var pickRay = Camera.computePickRay(event.x, event.y); - if (!modelSelected) { - var modelIntersection = Models.findRayIntersection(pickRay); - if (modelIntersection.accurate) { - if(glowedModelID.isKnownID && glowedModelID.id != modelIntersection.modelID.id) { - Models.editModel(glowedModelID, { glowLevel: 0.0 }); - glowedModelID.id = -1; - glowedModelID.isKnownID = false; + if (!entitySelected) { + var entityIntersection = Entities.findRayIntersection(pickRay); + if (entityIntersection.accurate) { + if(glowedEntityID.isKnownID && glowedEntityID.id != entityIntersection.entityID.id) { + Entities.editEntity(glowedEntityID, { glowLevel: 0.0 }); + glowedEntityID.id = -1; + glowedEntityID.isKnownID = false; } - var angularSize = 2 * Math.atan(modelIntersection.modelProperties.radius / Vec3.distance(Camera.getPosition(), modelIntersection.modelProperties.position)) * 180 / 3.14; - if (modelIntersection.modelID.isKnownID && angularSize > MIN_ANGULAR_SIZE && angularSize < MAX_ANGULAR_SIZE) { - Models.editModel(modelIntersection.modelID, { glowLevel: 0.25 }); - glowedModelID = modelIntersection.modelID; + var angularSize = 2 * Math.atan(entityIntersection.properties.radius / Vec3.distance(Camera.getPosition(), entityIntersection.properties.position)) * 180 / 3.14; + if (entityIntersection.entityID.isKnownID && angularSize > MIN_ANGULAR_SIZE && angularSize < MAX_ANGULAR_SIZE) { + Entities.editEntity(entityIntersection.entityID, { glowLevel: 0.25 }); + glowedEntityID = entityIntersection.entityID; } } return; @@ -910,22 +911,22 @@ function mouseMoveEvent(event) { } pickRay = Camera.computePickRay(event.x, event.y); if (wasShifted != event.isShifted || modifier != oldModifier) { - selectedModelProperties.oldRadius = selectedModelProperties.radius; + selectedEntityProperties.oldRadius = selectedEntityProperties.radius; - selectedModelProperties.oldPosition = { - x: selectedModelProperties.position.x, - y: selectedModelProperties.position.y, - z: selectedModelProperties.position.z, + selectedEntityProperties.oldPosition = { + x: selectedEntityProperties.position.x, + y: selectedEntityProperties.position.y, + z: selectedEntityProperties.position.z, }; - selectedModelProperties.oldRotation = { - x: selectedModelProperties.modelRotation.x, - y: selectedModelProperties.modelRotation.y, - z: selectedModelProperties.modelRotation.z, - w: selectedModelProperties.modelRotation.w, + selectedEntityProperties.oldRotation = { + x: selectedEntityProperties.modelRotation.x, + y: selectedEntityProperties.modelRotation.y, + z: selectedEntityProperties.modelRotation.z, + w: selectedEntityProperties.modelRotation.w, }; orientation = MyAvatar.orientation; intersection = rayPlaneIntersection(pickRay, - selectedModelProperties.oldPosition, + selectedEntityProperties.oldPosition, Quat.getFront(orientation)); mouseLastPosition = { x: event.x, y: event.y }; @@ -940,10 +941,10 @@ function mouseMoveEvent(event) { return; case 1: // Let's Scale - selectedModelProperties.radius = (selectedModelProperties.oldRadius * + selectedEntityProperties.radius = (selectedEntityProperties.oldRadius * (1.0 + (mouseLastPosition.y - event.y) / SCALE_FACTOR)); - if (selectedModelProperties.radius < 0.01) { + if (selectedEntityProperties.radius < 0.01) { print("Scale too small ... bailling."); return; } @@ -952,7 +953,7 @@ function mouseMoveEvent(event) { case 2: // Let's translate var newIntersection = rayPlaneIntersection(pickRay, - selectedModelProperties.oldPosition, + selectedEntityProperties.oldPosition, Quat.getFront(orientation)); var vector = Vec3.subtract(newIntersection, intersection) if (event.isShifted) { @@ -962,15 +963,15 @@ function mouseMoveEvent(event) { Vec3.multiply(Quat.getFront(orientation), j)); } - selectedModelProperties.position = Vec3.sum(selectedModelProperties.oldPosition, vector); + selectedEntityProperties.position = Vec3.sum(selectedEntityProperties.oldPosition, vector); break; case 3: // Let's rotate if (somethingChanged) { - selectedModelProperties.oldRotation.x = selectedModelProperties.modelRotation.x; - selectedModelProperties.oldRotation.y = selectedModelProperties.modelRotation.y; - selectedModelProperties.oldRotation.z = selectedModelProperties.modelRotation.z; - selectedModelProperties.oldRotation.w = selectedModelProperties.modelRotation.w; + selectedEntityProperties.oldRotation.x = selectedEntityProperties.modelRotation.x; + selectedEntityProperties.oldRotation.y = selectedEntityProperties.modelRotation.y; + selectedEntityProperties.oldRotation.z = selectedEntityProperties.modelRotation.z; + selectedEntityProperties.oldRotation.w = selectedEntityProperties.modelRotation.w; mouseLastPosition.x = event.x; mouseLastPosition.y = event.y; somethingChanged = false; @@ -984,7 +985,7 @@ function mouseMoveEvent(event) { var rotationAxis = (!zIsPressed && xIsPressed) ? { x: 1, y: 0, z: 0 } : (!zIsPressed && !xIsPressed) ? { x: 0, y: 1, z: 0 } : { x: 0, y: 0, z: 1 }; - rotationAxis = Vec3.multiplyQbyV(selectedModelProperties.modelRotation, rotationAxis); + rotationAxis = Vec3.multiplyQbyV(selectedEntityProperties.modelRotation, rotationAxis); var orthogonalAxis = Vec3.cross(cameraForward, rotationAxis); var mouseDelta = { x: event.x - mouseLastPosition .x, y: mouseLastPosition.y - event.y, z: 0 }; @@ -1001,17 +1002,17 @@ function mouseMoveEvent(event) { y: (!zIsPressed && !xIsPressed) ? delta : 0, // neither is pressed z: (zIsPressed && !xIsPressed) ? delta : 0 // z is pressed }); - rotation = Quat.multiply(selectedModelProperties.oldRotation, rotation); + rotation = Quat.multiply(selectedEntityProperties.oldRotation, rotation); - selectedModelProperties.modelRotation.x = rotation.x; - selectedModelProperties.modelRotation.y = rotation.y; - selectedModelProperties.modelRotation.z = rotation.z; - selectedModelProperties.modelRotation.w = rotation.w; + selectedEntityProperties.modelRotation.x = rotation.x; + selectedEntityProperties.modelRotation.y = rotation.y; + selectedEntityProperties.modelRotation.z = rotation.z; + selectedEntityProperties.modelRotation.w = rotation.w; break; } - Models.editModel(selectedModelID, selectedModelProperties); - tooltip.updateText(selectedModelProperties); + Entities.editEntity(selectedEntityID, selectedEntityProperties); + tooltip.updateText(selectedEntityProperties); } @@ -1020,14 +1021,14 @@ function mouseReleaseEvent(event) { return; } - if (modelSelected) { + if (entitySelected) { tooltip.show(false); } - modelSelected = false; + entitySelected = false; - glowedModelID.id = -1; - glowedModelID.isKnownID = false; + glowedEntityID.id = -1; + glowedEntityID.isKnownID = false; } // In order for editVoxels and editModels to play nice together, they each check to see if a "delete" menu item already @@ -1080,38 +1081,38 @@ function handeMenuEvent(menuItem){ print("menuItemEvent() in JS... menuItem=" + menuItem); if (menuItem == "Delete") { if (leftController.grabbing) { - print(" Delete Model.... leftController.modelID="+ leftController.modelID); - Models.deleteModel(leftController.modelID); + print(" Delete Model.... leftController.entityID="+ leftController.entityID); + Entities.deleteEntity(leftController.entityID); leftController.grabbing = false; } else if (rightController.grabbing) { - print(" Delete Model.... rightController.modelID="+ rightController.modelID); - Models.deleteModel(rightController.modelID); + print(" Delete Model.... rightController.entityID="+ rightController.entityID); + Entities.deleteEntity(rightController.entityID); rightController.grabbing = false; - } else if (modelSelected) { - print(" Delete Model.... selectedModelID="+ selectedModelID); - Models.deleteModel(selectedModelID); - modelSelected = false; + } else if (entitySelected) { + print(" Delete Model.... selectedEntityID="+ selectedEntityID); + Entities.deleteEntity(selectedEntityID); + entitySelected = false; } else { print(" Delete Model.... not holding..."); } } else if (menuItem == "Edit Properties...") { var editModelID = -1; if (leftController.grabbing) { - print(" Edit Properties.... leftController.modelID="+ leftController.modelID); - editModelID = leftController.modelID; + print(" Edit Properties.... leftController.entityID="+ leftController.entityID); + editModelID = leftController.entityID; } else if (rightController.grabbing) { - print(" Edit Properties.... rightController.modelID="+ rightController.modelID); - editModelID = rightController.modelID; - } else if (modelSelected) { - print(" Edit Properties.... selectedModelID="+ selectedModelID); - editModelID = selectedModelID; + print(" Edit Properties.... rightController.entityID="+ rightController.entityID); + editModelID = rightController.entityID; + } else if (entitySelected) { + print(" Edit Properties.... selectedEntityID="+ selectedEntityID); + editModelID = selectedEntityID; } else { print(" Edit Properties.... not holding..."); } if (editModelID != -1) { print(" Edit Properties.... about to edit properties..."); var propertyName = Window.prompt("Which property would you like to change?", "modelURL"); - var properties = Models.getModelProperties(editModelID); + var properties = Entities.getEntityProperties(editModelID); var oldValue = properties[propertyName]; var newValue = Window.prompt("New value for: " + propertyName, oldValue); if (newValue != "") { @@ -1127,7 +1128,7 @@ function handeMenuEvent(menuItem){ } } properties[propertyName] = newValue; - Models.editModel(editModelID, properties); + Entities.editEntity(editModelID, properties); } } } @@ -1152,10 +1153,10 @@ Controller.keyPressEvent.connect(function(event) { } // resets model orientation when holding with mouse - if (event.text == "r" && modelSelected) { - selectedModelProperties.modelRotation = Quat.fromVec3Degrees({ x: 0, y: 0, z: 0 }); - Models.editModel(selectedModelID, selectedModelProperties); - tooltip.updateText(selectedModelProperties); + if (event.text == "r" && entitySelected) { + selectedEntityProperties.modelRotation = Quat.fromVec3Degrees({ x: 0, y: 0, z: 0 }); + Entities.editEntity(selectedEntityID, selectedEntityProperties); + tooltip.updateText(selectedEntityProperties); somethingChanged = true; } }); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 75c3f442ca..edf1f81e9f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -54,7 +54,7 @@ #include #include #include -#include +#include #include #include #include @@ -284,13 +284,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : // tell the NodeList instance who to tell the domain server we care about nodeList->addSetOfNodeTypesToNodeInterestSet(NodeSet() << NodeType::AudioMixer << NodeType::AvatarMixer - << NodeType::VoxelServer << NodeType::ParticleServer << NodeType::ModelServer + << NodeType::VoxelServer << NodeType::ParticleServer << NodeType::EntityServer << NodeType::MetavoxelServer); // connect to the packet sent signal of the _voxelEditSender and the _particleEditSender connect(&_voxelEditSender, &VoxelEditPacketSender::packetSent, this, &Application::packetSent); connect(&_particleEditSender, &ParticleEditPacketSender::packetSent, this, &Application::packetSent); - connect(&_modelEditSender, &ModelEditPacketSender::packetSent, this, &Application::packetSent); + connect(&_entityEditSender, &EntityEditPacketSender::packetSent, this, &Application::packetSent); // move the silentNodeTimer to the _nodeThread QTimer* silentNodeTimer = new QTimer(); @@ -334,7 +334,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : // Tell our voxel edit sender about our known jurisdictions _voxelEditSender.setVoxelServerJurisdictions(&_voxelServerJurisdictions); _particleEditSender.setServerJurisdictions(&_particleServerJurisdictions); - _modelEditSender.setServerJurisdictions(&_modelServerJurisdictions); + _entityEditSender.setServerJurisdictions(&_entityServerJurisdictions); Particle::setVoxelEditPacketSender(&_voxelEditSender); Particle::setParticleEditPacketSender(&_particleEditSender); @@ -346,7 +346,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : // probably not the right long term solution. But for now, we're going to do this to // allow you to move a particle around in your hand _particleEditSender.setPacketsPerSecond(3000); // super high!! - _modelEditSender.setPacketsPerSecond(3000); // super high!! + _entityEditSender.setPacketsPerSecond(3000); // super high!! // Set the sixense filtering _sixenseManager.setFilter(Menu::getInstance()->isOptionChecked(MenuOption::FilterSixense)); @@ -424,7 +424,7 @@ Application::~Application() { _voxelHideShowThread.terminate(); _voxelEditSender.terminate(); _particleEditSender.terminate(); - _modelEditSender.terminate(); + _entityEditSender.terminate(); storeSizeAndPosition(); saveScripts(); @@ -523,7 +523,7 @@ void Application::initializeGL() { _voxelEditSender.initialize(_enableProcessVoxelsThread); _voxelHideShowThread.initialize(_enableProcessVoxelsThread); _particleEditSender.initialize(_enableProcessVoxelsThread); - _modelEditSender.initialize(_enableProcessVoxelsThread); + _entityEditSender.initialize(_enableProcessVoxelsThread); if (_enableProcessVoxelsThread) { qDebug("Voxel parsing thread created."); @@ -749,7 +749,7 @@ void Application::controlledBroadcastToNodes(const QByteArray& packet, const Nod break; case NodeType::VoxelServer: case NodeType::ParticleServer: - case NodeType::ModelServer: + case NodeType::EntityServer: channel = BandwidthMeter::VOXELS; break; default: @@ -1285,7 +1285,7 @@ void Application::dropEvent(QDropEvent *event) { void Application::sendPingPackets() { QByteArray pingPacket = NodeList::getInstance()->constructPingPacket(); controlledBroadcastToNodes(pingPacket, NodeSet() - << NodeType::VoxelServer << NodeType::ParticleServer << NodeType::ModelServer + << NodeType::VoxelServer << NodeType::ParticleServer << NodeType::EntityServer << NodeType::AudioMixer << NodeType::AvatarMixer << NodeType::MetavoxelServer); } @@ -1687,8 +1687,8 @@ void Application::init() { _particles.init(); _particles.setViewFrustum(getViewFrustum()); - _models.init(); - _models.setViewFrustum(getViewFrustum()); + _entities.init(); + _entities.setViewFrustum(getViewFrustum()); _metavoxels.init(); @@ -1909,7 +1909,7 @@ void Application::updateThreads(float deltaTime) { _voxelHideShowThread.threadRoutine(); _voxelEditSender.threadRoutine(); _particleEditSender.threadRoutine(); - _modelEditSender.threadRoutine(); + _entityEditSender.threadRoutine(); } } @@ -2052,8 +2052,8 @@ void Application::update(float deltaTime) { } { - PerformanceTimer perfTimer("idle/update/_models"); - _models.update(); // update the models... + PerformanceTimer perfTimer("idle/update/_entities"); + _entities.update(); // update the models... } { @@ -2111,7 +2111,7 @@ void Application::updateMyAvatar(float deltaTime) { _lastQueriedTime = now; queryOctree(NodeType::VoxelServer, PacketTypeVoxelQuery, _voxelServerJurisdictions); queryOctree(NodeType::ParticleServer, PacketTypeParticleQuery, _particleServerJurisdictions); - queryOctree(NodeType::ModelServer, PacketTypeModelQuery, _modelServerJurisdictions); + queryOctree(NodeType::EntityServer, PacketTypeEntityQuery, _entityServerJurisdictions); _lastQueriedViewFrustum = _viewFrustum; } } @@ -2143,7 +2143,7 @@ int Application::sendNackPackets() { if (node->getActiveSocket() && ( node->getType() == NodeType::VoxelServer || node->getType() == NodeType::ParticleServer - || node->getType() == NodeType::ModelServer) + || node->getType() == NodeType::EntityServer) ) { QUuid nodeUUID = node->getUUID(); @@ -2535,7 +2535,7 @@ void Application::updateShadowMap() { _avatarManager.renderAvatars(Avatar::SHADOW_RENDER_MODE); _particles.render(OctreeRenderer::SHADOW_RENDER_MODE); - _models.render(OctreeRenderer::SHADOW_RENDER_MODE); + _entities.render(OctreeRenderer::SHADOW_RENDER_MODE); glDisable(GL_POLYGON_OFFSET_FILL); @@ -2736,7 +2736,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { PerformanceTimer perfTimer("paintGL/displaySide/models"); PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::displaySide() ... models..."); - _models.render(); + _entities.render(); } // render the ambient occlusion effect if enabled @@ -3247,7 +3247,7 @@ void Application::domainChanged(const QString& domainHostname) { _particles.clear(); // reset the model renderer - _models.clear(); + _entities.clear(); // reset the voxels renderer _voxels.killLocalVoxels(); @@ -3286,7 +3286,7 @@ void Application::nodeKilled(SharedNodePointer node) { _voxelEditSender.nodeKilled(node); _particleEditSender.nodeKilled(node); - _modelEditSender.nodeKilled(node); + _entityEditSender.nodeKilled(node); if (node->getType() == NodeType::VoxelServer) { QUuid nodeUUID = node->getUUID(); @@ -3362,16 +3362,16 @@ void Application::nodeKilled(SharedNodePointer node) { } _octreeSceneStatsLock.unlock(); - } else if (node->getType() == NodeType::ModelServer) { + } else if (node->getType() == NodeType::EntityServer) { QUuid nodeUUID = node->getUUID(); // see if this is the first we've heard of this node... - _modelServerJurisdictions.lockForRead(); - if (_modelServerJurisdictions.find(nodeUUID) != _modelServerJurisdictions.end()) { - unsigned char* rootCode = _modelServerJurisdictions[nodeUUID].getRootOctalCode(); + _entityServerJurisdictions.lockForRead(); + if (_entityServerJurisdictions.find(nodeUUID) != _entityServerJurisdictions.end()) { + unsigned char* rootCode = _entityServerJurisdictions[nodeUUID].getRootOctalCode(); VoxelPositionSize rootDetails; voxelDetailsForCode(rootCode, rootDetails); - _modelServerJurisdictions.unlock(); + _entityServerJurisdictions.unlock(); qDebug("model server going away...... v[%f, %f, %f, %f]", rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s); @@ -3388,10 +3388,10 @@ void Application::nodeKilled(SharedNodePointer node) { } // If the model server is going away, remove it from our jurisdiction map so we don't send voxels to a dead server - _modelServerJurisdictions.lockForWrite(); - _modelServerJurisdictions.erase(_modelServerJurisdictions.find(nodeUUID)); + _entityServerJurisdictions.lockForWrite(); + _entityServerJurisdictions.erase(_entityServerJurisdictions.find(nodeUUID)); } - _modelServerJurisdictions.unlock(); + _entityServerJurisdictions.unlock(); // also clean up scene stats for that server _octreeSceneStatsLock.lockForWrite(); @@ -3457,8 +3457,8 @@ int Application::parseOctreeStats(const QByteArray& packet, const SharedNodePoin jurisdiction = &_particleServerJurisdictions; serverType = "Particle"; } else { - jurisdiction = &_modelServerJurisdictions; - serverType = "Model"; + jurisdiction = &_entityServerJurisdictions; + serverType = "Entity"; } jurisdiction->lockForRead(); @@ -3563,8 +3563,8 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript scriptEngine->getParticlesScriptingInterface()->setPacketSender(&_particleEditSender); scriptEngine->getParticlesScriptingInterface()->setParticleTree(_particles.getTree()); - scriptEngine->getModelsScriptingInterface()->setPacketSender(&_modelEditSender); - scriptEngine->getModelsScriptingInterface()->setModelTree(_models.getTree()); + scriptEngine->getEntityScriptingInterface()->setPacketSender(&_entityEditSender); + scriptEngine->getEntityScriptingInterface()->setEntityTree(_entities.getTree()); // hook our avatar object into this script engine scriptEngine->setAvatarData(_myAvatar, "MyAvatar"); // leave it as a MyAvatar class to expose thrust features diff --git a/interface/src/Application.h b/interface/src/Application.h index af0dfe9d15..1a961ff7ba 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -30,7 +30,7 @@ #include #include -#include +#include #include #include #include @@ -63,7 +63,7 @@ #include "devices/PrioVR.h" #include "devices/SixenseManager.h" #include "devices/Visage.h" -#include "models/ModelTreeRenderer.h" +#include "models/ModelTreeRenderer.h" // rename to "models/EntityTreeRenderer.h" #include "particles/ParticleTreeRenderer.h" #include "renderer/AmbientOcclusionEffect.h" #include "renderer/GeometryCache.h" @@ -195,7 +195,7 @@ public: const OctreePacketProcessor& getOctreePacketProcessor() const { return _octreeProcessor; } ParticleTreeRenderer* getParticles() { return &_particles; } MetavoxelSystem* getMetavoxels() { return &_metavoxels; } - ModelTreeRenderer* getModels() { return &_models; } + EntityTreeRenderer* getEntities() { return &_entities; } bool getImportSucceded() { return _importSucceded; } VoxelSystem* getSharedVoxelSystem() { return &_sharedVoxelSystem; } VoxelTree* getClipboard() { return &_clipboard; } @@ -280,7 +280,7 @@ public: glm::vec2 getViewportDimensions() const{ return glm::vec2(_glWidget->width(),_glWidget->height()); } NodeToJurisdictionMap& getVoxelServerJurisdictions() { return _voxelServerJurisdictions; } NodeToJurisdictionMap& getParticleServerJurisdictions() { return _particleServerJurisdictions; } - NodeToJurisdictionMap& getModelServerJurisdictions() { return _modelServerJurisdictions; } + NodeToJurisdictionMap& getEntityServerJurisdictions() { return _entityServerJurisdictions; } void pasteVoxelsToOctalCode(const unsigned char* octalCodeDestination); void skipVersion(QString latestVersion); @@ -454,7 +454,7 @@ private: ParticleTreeRenderer _particles; ParticleCollisionSystem _particleCollisionSystem; - ModelTreeRenderer _models; + EntityTreeRenderer _entities; QByteArray _voxelsFilename; bool _wantToKillLocalVoxels; @@ -541,7 +541,7 @@ private: VoxelHideShowThread _voxelHideShowThread; VoxelEditPacketSender _voxelEditSender; ParticleEditPacketSender _particleEditSender; - ModelEditPacketSender _modelEditSender; + EntityEditPacketSender _entityEditSender; int _packetsPerSecond; int _bytesPerSecond; @@ -554,7 +554,7 @@ private: NodeToJurisdictionMap _voxelServerJurisdictions; NodeToJurisdictionMap _particleServerJurisdictions; - NodeToJurisdictionMap _modelServerJurisdictions; + NodeToJurisdictionMap _entityServerJurisdictions; NodeToOctreeSceneStats _octreeServerSceneStats; QReadWriteLock _octreeSceneStatsLock; diff --git a/interface/src/DatagramProcessor.cpp b/interface/src/DatagramProcessor.cpp index 29528da126..0fe45a0d85 100644 --- a/interface/src/DatagramProcessor.cpp +++ b/interface/src/DatagramProcessor.cpp @@ -57,15 +57,15 @@ void DatagramProcessor::processDatagrams() { Particle::handleAddParticleResponse(incomingPacket); application->getParticles()->getTree()->handleAddParticleResponse(incomingPacket); break; - case PacketTypeModelAddResponse: + case PacketTypeEntityAddResponse: // this will keep creatorTokenIDs to IDs mapped correctly - ModelItem::handleAddModelResponse(incomingPacket); - application->getModels()->getTree()->handleAddModelResponse(incomingPacket); + EntityItem::handleAddEntityResponse(incomingPacket); + application->getEntities()->getTree()->handleAddEntityResponse(incomingPacket); break; case PacketTypeParticleData: case PacketTypeParticleErase: - case PacketTypeModelData: - case PacketTypeModelErase: + case PacketTypeEntityData: + case PacketTypeEntityErase: case PacketTypeVoxelData: case PacketTypeVoxelErase: case PacketTypeOctreeStats: @@ -151,8 +151,8 @@ void DatagramProcessor::processDatagrams() { case PacketTypeParticleEditNack: application->_particleEditSender.processNackPacket(incomingPacket); break; - case PacketTypeModelEditNack: - application->_modelEditSender.processNackPacket(incomingPacket); + case PacketTypeEntityEditNack: + application->_entityEditSender.processNackPacket(incomingPacket); break; default: nodeList->processNodeData(senderSockAddr, incomingPacket); diff --git a/interface/src/models/ModelTreeRenderer.cpp b/interface/src/models/ModelTreeRenderer.cpp index 9c4b08fd99..c4013307ab 100644 --- a/interface/src/models/ModelTreeRenderer.cpp +++ b/interface/src/models/ModelTreeRenderer.cpp @@ -1,5 +1,5 @@ // -// ModelTreeRenderer.cpp +// EntityTreeRenderer.cpp // interface/src // // Created by Brad Hefta-Gaub on 12/6/13. @@ -15,131 +15,131 @@ #include "InterfaceConfig.h" #include "Menu.h" -#include "ModelTreeRenderer.h" +#include "ModelTreeRenderer.h" // rename to "EntityTreeRenderer.h" -ModelTreeRenderer::ModelTreeRenderer() : +EntityTreeRenderer::EntityTreeRenderer() : OctreeRenderer() { } -ModelTreeRenderer::~ModelTreeRenderer() { +EntityTreeRenderer::~EntityTreeRenderer() { clearModelsCache(); } -void ModelTreeRenderer::clear() { +void EntityTreeRenderer::clear() { OctreeRenderer::clear(); clearModelsCache(); } -void ModelTreeRenderer::clearModelsCache() { - qDebug() << "ModelTreeRenderer::clearModelsCache()..."; +void EntityTreeRenderer::clearModelsCache() { + qDebug() << "EntityTreeRenderer::clearModelsCache()..."; - // delete the models in _knownModelsItemModels - foreach(Model* model, _knownModelsItemModels) { + // delete the models in _knownEntityItemModels + foreach(Model* model, _knownEntityItemModels) { delete model; } - _knownModelsItemModels.clear(); + _knownEntityItemModels.clear(); - foreach(Model* model, _unknownModelsItemModels) { + foreach(Model* model, _unknownEntityItemModels) { delete model; } - _unknownModelsItemModels.clear(); + _unknownEntityItemModels.clear(); } -void ModelTreeRenderer::init() { +void EntityTreeRenderer::init() { OctreeRenderer::init(); - static_cast(_tree)->setFBXService(this); + static_cast(_tree)->setFBXService(this); } -void ModelTreeRenderer::setTree(Octree* newTree) { +void EntityTreeRenderer::setTree(Octree* newTree) { OctreeRenderer::setTree(newTree); - static_cast(_tree)->setFBXService(this); + static_cast(_tree)->setFBXService(this); } -void ModelTreeRenderer::update() { +void EntityTreeRenderer::update() { if (_tree) { - ModelTree* tree = static_cast(_tree); + EntityTree* tree = static_cast(_tree); tree->update(); } } -void ModelTreeRenderer::render(RenderMode renderMode) { +void EntityTreeRenderer::render(RenderMode renderMode) { OctreeRenderer::render(renderMode); } -const FBXGeometry* ModelTreeRenderer::getGeometryForModel(const ModelItem& modelItem) { +const FBXGeometry* EntityTreeRenderer::getGeometryForEntity(const EntityItem& entityItem) { const FBXGeometry* result = NULL; - Model* model = getModel(modelItem); + Model* model = getModel(entityItem); if (model) { result = &model->getGeometry()->getFBXGeometry(); } return result; } -Model* ModelTreeRenderer::getModel(const ModelItem& modelItem) { +Model* EntityTreeRenderer::getModel(const EntityItem& entityItem) { Model* model = NULL; - if (modelItem.isKnownID()) { - if (_knownModelsItemModels.find(modelItem.getID()) != _knownModelsItemModels.end()) { - model = _knownModelsItemModels[modelItem.getID()]; - if (QUrl(modelItem.getModelURL()) != model->getURL()) { + if (entityItem.isKnownID()) { + if (_knownEntityItemModels.find(entityItem.getID()) != _knownEntityItemModels.end()) { + model = _knownEntityItemModels[entityItem.getID()]; + if (QUrl(entityItem.getModelURL()) != model->getURL()) { delete model; // delete the old model... model = NULL; - _knownModelsItemModels.remove(modelItem.getID()); + _knownEntityItemModels.remove(entityItem.getID()); } } // if we don't have a model... if (!model) { - // Make sure we only create new models on the thread that owns the ModelTreeRenderer + // Make sure we only create new models on the thread that owns the EntityTreeRenderer if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "getModel", Qt::BlockingQueuedConnection, - Q_RETURN_ARG(Model*, model), Q_ARG(const ModelItem&, modelItem)); + Q_RETURN_ARG(Model*, model), Q_ARG(const EntityItem&, entityItem)); return model; } model = new Model(); model->init(); - model->setURL(QUrl(modelItem.getModelURL())); - _knownModelsItemModels[modelItem.getID()] = model; + model->setURL(QUrl(entityItem.getModelURL())); + _knownEntityItemModels[entityItem.getID()] = model; } } else { - if (_unknownModelsItemModels.find(modelItem.getCreatorTokenID()) != _unknownModelsItemModels.end()) { - model = _unknownModelsItemModels[modelItem.getCreatorTokenID()]; - if (QUrl(modelItem.getModelURL()) != model->getURL()) { + if (_unknownEntityItemModels.find(entityItem.getCreatorTokenID()) != _unknownEntityItemModels.end()) { + model = _unknownEntityItemModels[entityItem.getCreatorTokenID()]; + if (QUrl(entityItem.getModelURL()) != model->getURL()) { delete model; // delete the old model... model = NULL; - _unknownModelsItemModels.remove(modelItem.getID()); + _unknownEntityItemModels.remove(entityItem.getID()); } } if (!model) { - // Make sure we only create new models on the thread that owns the ModelTreeRenderer + // Make sure we only create new models on the thread that owns the EntityTreeRenderer if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "getModel", Qt::BlockingQueuedConnection, - Q_RETURN_ARG(Model*, model), Q_ARG(const ModelItem&, modelItem)); + Q_RETURN_ARG(Model*, model), Q_ARG(const EntityItem&, entityItem)); return model; } model = new Model(); model->init(); - model->setURL(QUrl(modelItem.getModelURL())); - _unknownModelsItemModels[modelItem.getCreatorTokenID()] = model; + model->setURL(QUrl(entityItem.getModelURL())); + _unknownEntityItemModels[entityItem.getCreatorTokenID()] = model; } } return model; } -void ModelTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) { +void EntityTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) { args->_elementsTouched++; // actually render it here... - // we need to iterate the actual modelItems of the element - ModelTreeElement* modelTreeElement = (ModelTreeElement*)element; + // we need to iterate the actual entityItems of the element + EntityTreeElement* entityTreeElement = (EntityTreeElement*)element; - QList& modelItems = modelTreeElement->getModels(); + QList& entityItems = entityTreeElement->getEntities(); - uint16_t numberOfModels = modelItems.size(); + uint16_t numberOfEntities = entityItems.size(); bool isShadowMode = args->_renderMode == OctreeRenderer::SHADOW_RENDER_MODE; @@ -148,9 +148,9 @@ void ModelTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) bool displayElementChildProxies = Menu::getInstance()->isOptionChecked(MenuOption::DisplayModelElementChildProxies); - if (!isShadowMode && displayElementProxy && numberOfModels > 0) { - glm::vec3 elementCenter = modelTreeElement->getAACube().calcCenter() * (float)TREE_SCALE; - float elementSize = modelTreeElement->getScale() * (float)TREE_SCALE; + if (!isShadowMode && displayElementProxy && numberOfEntities > 0) { + glm::vec3 elementCenter = entityTreeElement->getAACube().calcCenter() * (float)TREE_SCALE; + float elementSize = entityTreeElement->getScale() * (float)TREE_SCALE; glColor3f(1.0f, 0.0f, 0.0f); glPushMatrix(); glTranslatef(elementCenter.x, elementCenter.y, elementCenter.z); @@ -212,17 +212,17 @@ void ModelTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) } - for (uint16_t i = 0; i < numberOfModels; i++) { - ModelItem& modelItem = modelItems[i]; - // render modelItem aspoints - AACube modelCube = modelItem.getAACube(); + for (uint16_t i = 0; i < numberOfEntities; i++) { + EntityItem& entityItem = entityItems[i]; + // render entityItem aspoints + AACube modelCube = entityItem.getAACube(); modelCube.scale(TREE_SCALE); if (args->_viewFrustum->cubeInFrustum(modelCube) != ViewFrustum::OUTSIDE) { - glm::vec3 position = modelItem.getPosition() * (float)TREE_SCALE; - float radius = modelItem.getRadius() * (float)TREE_SCALE; - float size = modelItem.getSize() * (float)TREE_SCALE; + glm::vec3 position = entityItem.getPosition() * (float)TREE_SCALE; + float radius = entityItem.getRadius() * (float)TREE_SCALE; + float size = entityItem.getSize() * (float)TREE_SCALE; - bool drawAsModel = modelItem.hasModel(); + bool drawAsModel = entityItem.hasModel(); args->_itemsRendered++; @@ -231,27 +231,27 @@ void ModelTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) { const float alpha = 1.0f; - Model* model = getModel(modelItem); + Model* model = getModel(entityItem); if (model) { model->setScaleToFit(true, radius * 2.0f); model->setSnapModelToCenter(true); // set the rotation - glm::quat rotation = modelItem.getModelRotation(); + glm::quat rotation = entityItem.getRotation(); model->setRotation(rotation); // set the position model->setTranslation(position); // handle animations.. - if (modelItem.hasAnimation()) { - if (!modelItem.jointsMapped()) { + if (entityItem.hasAnimation()) { + if (!entityItem.jointsMapped()) { QStringList modelJointNames = model->getJointNames(); - modelItem.mapJoints(modelJointNames); + entityItem.mapJoints(modelJointNames); } - QVector frameData = modelItem.getAnimationFrame(); + QVector frameData = entityItem.getAnimationFrame(); for (int i = 0; i < frameData.size(); i++) { model->setJointState(i, true, frameData[i]); } @@ -260,18 +260,18 @@ void ModelTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) // make sure to simulate so everything gets set up correctly for rendering model->simulate(0.0f); - // TODO: should we allow modelItems to have alpha on their models? + // TODO: should we allow entityItems to have alpha on their models? Model::RenderMode modelRenderMode = args->_renderMode == OctreeRenderer::SHADOW_RENDER_MODE ? Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE; - if (modelItem.getGlowLevel() > 0.0f) { - Glower glower(modelItem.getGlowLevel()); + if (entityItem.getGlowLevel() > 0.0f) { + Glower glower(entityItem.getGlowLevel()); if (model->isActive()) { model->render(alpha, modelRenderMode); } else { // if we couldn't get a model, then just draw a sphere - glColor3ub(modelItem.getColor()[RED_INDEX],modelItem.getColor()[GREEN_INDEX],modelItem.getColor()[BLUE_INDEX]); + glColor3ub(entityItem.getColor()[RED_INDEX],entityItem.getColor()[GREEN_INDEX],entityItem.getColor()[BLUE_INDEX]); glPushMatrix(); glTranslatef(position.x, position.y, position.z); glutSolidSphere(radius, 15, 15); @@ -282,7 +282,7 @@ void ModelTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) model->render(alpha, modelRenderMode); } else { // if we couldn't get a model, then just draw a sphere - glColor3ub(modelItem.getColor()[RED_INDEX],modelItem.getColor()[GREEN_INDEX],modelItem.getColor()[BLUE_INDEX]); + glColor3ub(entityItem.getColor()[RED_INDEX],entityItem.getColor()[GREEN_INDEX],entityItem.getColor()[BLUE_INDEX]); glPushMatrix(); glTranslatef(position.x, position.y, position.z); glutSolidSphere(radius, 15, 15); @@ -333,7 +333,7 @@ void ModelTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) } } else { // if we couldn't get a model, then just draw a sphere - glColor3ub(modelItem.getColor()[RED_INDEX],modelItem.getColor()[GREEN_INDEX],modelItem.getColor()[BLUE_INDEX]); + glColor3ub(entityItem.getColor()[RED_INDEX],entityItem.getColor()[GREEN_INDEX],entityItem.getColor()[BLUE_INDEX]); glPushMatrix(); glTranslatef(position.x, position.y, position.z); glutSolidSphere(radius, 15, 15); @@ -342,7 +342,7 @@ void ModelTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) } glPopMatrix(); } else { - //glColor3ub(modelItem.getColor()[RED_INDEX],modelItem.getColor()[GREEN_INDEX],modelItem.getColor()[BLUE_INDEX]); + //glColor3ub(entityItem.getColor()[RED_INDEX],entityItem.getColor()[GREEN_INDEX],entityItem.getColor()[BLUE_INDEX]); glColor3f(1.0f, 0.0f, 0.0f); glPushMatrix(); glTranslatef(position.x, position.y, position.z); @@ -355,15 +355,15 @@ void ModelTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) } } -float ModelTreeRenderer::getSizeScale() const { +float EntityTreeRenderer::getSizeScale() const { return Menu::getInstance()->getVoxelSizeScale(); } -int ModelTreeRenderer::getBoundaryLevelAdjust() const { +int EntityTreeRenderer::getBoundaryLevelAdjust() const { return Menu::getInstance()->getBoundaryLevelAdjust(); } -void ModelTreeRenderer::processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode) { - static_cast(_tree)->processEraseMessage(dataByteArray, sourceNode); +void EntityTreeRenderer::processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode) { + static_cast(_tree)->processEraseMessage(dataByteArray, sourceNode); } diff --git a/interface/src/models/ModelTreeRenderer.h b/interface/src/models/ModelTreeRenderer.h index b6df71565d..1dbd2ce8ad 100644 --- a/interface/src/models/ModelTreeRenderer.h +++ b/interface/src/models/ModelTreeRenderer.h @@ -1,5 +1,5 @@ // -// ModelTreeRenderer.h +// EntityTreeRenderer.h // interface/src // // Created by Brad Hefta-Gaub on 12/6/13. @@ -9,13 +9,13 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_ModelTreeRenderer_h -#define hifi_ModelTreeRenderer_h +#ifndef hifi_EntityTreeRenderer_h +#define hifi_EntityTreeRenderer_h #include #include -#include +#include #include #include #include @@ -26,15 +26,15 @@ #include "renderer/Model.h" // Generic client side Octree renderer class. -class ModelTreeRenderer : public OctreeRenderer, public ModelItemFBXService { +class EntityTreeRenderer : public OctreeRenderer, public EntityItemFBXService { public: - ModelTreeRenderer(); - virtual ~ModelTreeRenderer(); + EntityTreeRenderer(); + virtual ~EntityTreeRenderer(); - virtual Octree* createTree() { return new ModelTree(true); } - virtual char getMyNodeType() const { return NodeType::ModelServer; } - virtual PacketType getMyQueryMessageType() const { return PacketTypeModelQuery; } - virtual PacketType getExpectedPacketType() const { return PacketTypeModelData; } + virtual Octree* createTree() { return new EntityTree(true); } + virtual char getMyNodeType() const { return NodeType::EntityServer; } + virtual PacketType getMyQueryMessageType() const { return PacketTypeEntityQuery; } + virtual PacketType getExpectedPacketType() const { return PacketTypeEntityData; } virtual void renderElement(OctreeElement* element, RenderArgs* args); virtual float getSizeScale() const; virtual int getBoundaryLevelAdjust() const; @@ -42,23 +42,23 @@ public: void update(); - ModelTree* getTree() { return (ModelTree*)_tree; } + EntityTree* getTree() { return (EntityTree*)_tree; } void processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode); virtual void init(); virtual void render(RenderMode renderMode = DEFAULT_RENDER_MODE); - virtual const FBXGeometry* getGeometryForModel(const ModelItem& modelItem); + virtual const FBXGeometry* getGeometryForEntity(const EntityItem& modelItem); /// clears the tree virtual void clear(); protected: void clearModelsCache(); - Model* getModel(const ModelItem& modelItem); - QMap _knownModelsItemModels; - QMap _unknownModelsItemModels; + Model* getModel(const EntityItem& modelItem); + QMap _knownEntityItemModels; + QMap _unknownEntityItemModels; }; -#endif // hifi_ModelTreeRenderer_h +#endif // hifi_EntityTreeRenderer_h diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp index 12a93095cd..bcb5395a78 100644 --- a/interface/src/ui/NodeBounds.cpp +++ b/interface/src/ui/NodeBounds.cpp @@ -5,7 +5,7 @@ // Created by Ryan Huffman on 05/14/14. // Copyright 2014 High Fidelity, Inc. // -// This class draws a border around the different Voxel, Model, and Particle nodes on the current domain, +// This class draws a border around the different Voxel, Entity, and Particle nodes on the current domain, // and a semi-transparent cube around the currently mouse-overed node. // // Distributed under the Apache License, Version 2.0. @@ -20,20 +20,20 @@ NodeBounds::NodeBounds(QObject* parent) : QObject(parent), _showVoxelNodes(false), - _showModelNodes(false), + _showEntityNodes(false), _showParticleNodes(false), _overlayText() { } void NodeBounds::draw() { - if (!(_showVoxelNodes || _showModelNodes || _showParticleNodes)) { + if (!(_showVoxelNodes || _showEntityNodes || _showParticleNodes)) { _overlayText[0] = '\0'; return; } NodeToJurisdictionMap& voxelServerJurisdictions = Application::getInstance()->getVoxelServerJurisdictions(); - NodeToJurisdictionMap& modelServerJurisdictions = Application::getInstance()->getModelServerJurisdictions(); + NodeToJurisdictionMap& entityServerJurisdictions = Application::getInstance()->getEntityServerJurisdictions(); NodeToJurisdictionMap& particleServerJurisdictions = Application::getInstance()->getParticleServerJurisdictions(); NodeToJurisdictionMap* serverJurisdictions; @@ -61,8 +61,8 @@ void NodeBounds::draw() { if (nodeType == NodeType::VoxelServer && _showVoxelNodes) { serverJurisdictions = &voxelServerJurisdictions; - } else if (nodeType == NodeType::ModelServer && _showModelNodes) { - serverJurisdictions = &modelServerJurisdictions; + } else if (nodeType == NodeType::EntityServer && _showEntityNodes) { + serverJurisdictions = &entityServerJurisdictions; } else if (nodeType == NodeType::ParticleServer && _showParticleNodes) { serverJurisdictions = &particleServerJurisdictions; } else { @@ -89,7 +89,7 @@ void NodeBounds::draw() { + ((serverBounds.getVertex(TOP_LEFT_FAR) - serverBounds.getVertex(BOTTOM_RIGHT_NEAR)) / 2.0f); const float VOXEL_NODE_SCALE = 1.00f; - const float MODEL_NODE_SCALE = 0.99f; + const float ENTITY_NODE_SCALE = 0.99f; const float PARTICLE_NODE_SCALE = 0.98f; float scaleFactor = rootDetails.s * TREE_SCALE; @@ -101,8 +101,8 @@ void NodeBounds::draw() { // Scale different node types slightly differently because it's common for them to overlap. if (nodeType == NodeType::VoxelServer) { scaleFactor *= VOXEL_NODE_SCALE; - } else if (nodeType == NodeType::ModelServer) { - scaleFactor *= MODEL_NODE_SCALE; + } else if (nodeType == NodeType::EntityServer) { + scaleFactor *= ENTITY_NODE_SCALE; } else { scaleFactor *= PARTICLE_NODE_SCALE; } @@ -216,7 +216,7 @@ void NodeBounds::drawNodeBorder(const glm::vec3& center, float scale, float red, void NodeBounds::getColorForNodeType(NodeType_t nodeType, float& red, float& green, float& blue) { red = nodeType == NodeType::VoxelServer ? 1.0 : 0.0; green = nodeType == NodeType::ParticleServer ? 1.0 : 0.0; - blue = nodeType == NodeType::ModelServer ? 1.0 : 0.0; + blue = nodeType == NodeType::EntityServer ? 1.0 : 0.0; } void NodeBounds::drawOverlay() { diff --git a/interface/src/ui/NodeBounds.h b/interface/src/ui/NodeBounds.h index bd54b84e98..39f98200d1 100644 --- a/interface/src/ui/NodeBounds.h +++ b/interface/src/ui/NodeBounds.h @@ -24,7 +24,7 @@ public: NodeBounds(QObject* parent = NULL); bool getShowVoxelNodes() { return _showVoxelNodes; } - bool getShowModelNodes() { return _showModelNodes; } + bool getShowEntityNodes() { return _showEntityNodes; } bool getShowParticleNodes() { return _showParticleNodes; } void draw(); @@ -32,7 +32,7 @@ public: public slots: void setShowVoxelNodes(bool value) { _showVoxelNodes = value; } - void setShowModelNodes(bool value) { _showModelNodes = value; } + void setShowEntityNodes(bool value) { _showEntityNodes = value; } void setShowParticleNodes(bool value) { _showParticleNodes = value; } protected: @@ -41,7 +41,7 @@ protected: private: bool _showVoxelNodes; - bool _showModelNodes; + bool _showEntityNodes; bool _showParticleNodes; char _overlayText[MAX_OVERLAY_TEXT_LENGTH + 1]; diff --git a/interface/src/ui/OctreeStatsDialog.cpp b/interface/src/ui/OctreeStatsDialog.cpp index 3296d8ccb2..b03bc88485 100644 --- a/interface/src/ui/OctreeStatsDialog.cpp +++ b/interface/src/ui/OctreeStatsDialog.cpp @@ -232,8 +232,8 @@ void OctreeStatsDialog::showAllOctreeServers() { showOctreeServersOfType(serverCount, NodeType::ParticleServer, "Particle", Application::getInstance()->getParticleServerJurisdictions()); - showOctreeServersOfType(serverCount, NodeType::ModelServer, "Model", - Application::getInstance()->getModelServerJurisdictions()); + showOctreeServersOfType(serverCount, NodeType::EntityServer, "Model", + Application::getInstance()->getEntityServerJurisdictions()); if (_voxelServerLabelsCount > serverCount) { for (int i = serverCount; i < _voxelServerLabelsCount; i++) { diff --git a/interface/src/voxels/OctreePacketProcessor.cpp b/interface/src/voxels/OctreePacketProcessor.cpp index 66190a5689..3af4b68476 100644 --- a/interface/src/voxels/OctreePacketProcessor.cpp +++ b/interface/src/voxels/OctreePacketProcessor.cpp @@ -95,12 +95,12 @@ void OctreePacketProcessor::processPacket(const SharedNodePointer& sendingNode, app->_particles.processDatagram(mutablePacket, sendingNode); } break; - case PacketTypeModelErase: { - app->_models.processEraseMessage(mutablePacket, sendingNode); + case PacketTypeEntityErase: { + app->_entities.processEraseMessage(mutablePacket, sendingNode); } break; - case PacketTypeModelData: { - app->_models.processDatagram(mutablePacket, sendingNode); + case PacketTypeEntityData: { + app->_entities.processDatagram(mutablePacket, sendingNode); } break; case PacketTypeEnvironmentData: { diff --git a/libraries/models/src/EntityEditPacketSender.cpp b/libraries/models/src/EntityEditPacketSender.cpp index 5059b8891b..27d60f6c33 100644 --- a/libraries/models/src/EntityEditPacketSender.cpp +++ b/libraries/models/src/EntityEditPacketSender.cpp @@ -1,5 +1,5 @@ // -// ModelEditPacketSender.cpp +// EntityEditPacketSender.cpp // libraries/models/src // // Created by Brad Hefta-Gaub on 8/12/13. @@ -13,11 +13,11 @@ #include #include #include -#include "ModelEditPacketSender.h" -#include "ModelItem.h" +#include "EntityEditPacketSender.h" +#include "EntityItem.h" -void ModelEditPacketSender::sendEditModelMessage(PacketType type, ModelItemID modelID, const ModelItemProperties& properties) { +void EntityEditPacketSender::sendEditEntityMessage(PacketType type, EntityItemID modelID, const EntityItemProperties& properties) { // allows app to disable sending if for example voxels have been disabled if (!_shouldSend) { return; // bail early @@ -27,7 +27,7 @@ void ModelEditPacketSender::sendEditModelMessage(PacketType type, ModelItemID mo int sizeOut = 0; // This encodes the voxel edit message into a buffer... - if (ModelItem::encodeModelEditMessageDetails(type, modelID, properties, &bufferOut[0], _maxPacketSize, sizeOut)){ + if (EntityItem::encodeEntityEditMessageDetails(type, modelID, properties, &bufferOut[0], _maxPacketSize, sizeOut)){ // If we don't have voxel jurisdictions, then we will simply queue up these packets and wait till we have // jurisdictions for processing if (!serversExist()) { @@ -38,13 +38,13 @@ void ModelEditPacketSender::sendEditModelMessage(PacketType type, ModelItemID mo } } -void ModelEditPacketSender::adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssize_t length, int clockSkew) { - ModelItem::adjustEditPacketForClockSkew(codeColorBuffer, length, clockSkew); +void EntityEditPacketSender::adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssize_t length, int clockSkew) { + EntityItem::adjustEditPacketForClockSkew(codeColorBuffer, length, clockSkew); } -void ModelEditPacketSender::queueModelEditMessage(PacketType type, ModelItemID modelID, - const ModelItemProperties& properties) { +void EntityEditPacketSender::queueEntityEditMessage(PacketType type, EntityItemID modelID, + const EntityItemProperties& properties) { if (!_shouldSend) { return; // bail early } @@ -53,7 +53,7 @@ void ModelEditPacketSender::queueModelEditMessage(PacketType type, ModelItemID m static unsigned char bufferOut[MAX_PACKET_SIZE]; int sizeOut = 0; - if (ModelItem::encodeModelEditMessageDetails(type, modelID, properties, &bufferOut[0], _maxPacketSize, sizeOut)) { + if (EntityItem::encodeEntityEditMessageDetails(type, modelID, properties, &bufferOut[0], _maxPacketSize, sizeOut)) { queueOctreeEditMessage(type, bufferOut, sizeOut); } } diff --git a/libraries/models/src/EntityEditPacketSender.h b/libraries/models/src/EntityEditPacketSender.h index 198c9a3be2..99cf251bbe 100644 --- a/libraries/models/src/EntityEditPacketSender.h +++ b/libraries/models/src/EntityEditPacketSender.h @@ -1,5 +1,5 @@ // -// ModelEditPacketSender.h +// EntityEditPacketSender.h // libraries/models/src // // Created by Brad Hefta-Gaub on 8/12/13. @@ -9,29 +9,29 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_ModelEditPacketSender_h -#define hifi_ModelEditPacketSender_h +#ifndef hifi_EntityEditPacketSender_h +#define hifi_EntityEditPacketSender_h #include -#include "ModelItem.h" +#include "EntityItem.h" /// Utility for processing, packing, queueing and sending of outbound edit voxel messages. -class ModelEditPacketSender : public OctreeEditPacketSender { +class EntityEditPacketSender : public OctreeEditPacketSender { Q_OBJECT public: /// Send model add message immediately - /// NOTE: ModelItemProperties assumes that all distances are in meter units - void sendEditModelMessage(PacketType type, ModelItemID modelID, const ModelItemProperties& properties); + /// NOTE: EntityItemProperties assumes that all distances are in meter units + void sendEditEntityMessage(PacketType type, EntityItemID modelID, const EntityItemProperties& properties); /// Queues an array of several voxel edit messages. Will potentially send a pending multi-command packet. Determines /// 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: ModelItemProperties assumes that all distances are in meter units - void queueModelEditMessage(PacketType type, ModelItemID modelID, const ModelItemProperties& properties); + /// NOTE: EntityItemProperties assumes that all distances are in meter units + void queueEntityEditMessage(PacketType type, EntityItemID modelID, const EntityItemProperties& properties); // My server type is the model server - virtual char getMyNodeType() const { return NodeType::ModelServer; } + virtual char getMyNodeType() const { return NodeType::EntityServer; } virtual void adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssize_t length, int clockSkew); }; -#endif // hifi_ModelEditPacketSender_h +#endif // hifi_EntityEditPacketSender_h diff --git a/libraries/models/src/EntityItem.cpp b/libraries/models/src/EntityItem.cpp index e701659b72..5c38595058 100644 --- a/libraries/models/src/EntityItem.cpp +++ b/libraries/models/src/EntityItem.cpp @@ -1,5 +1,5 @@ // -// ModelItem.cpp +// EntityItem.cpp // libraries/models/src // // Created by Brad Hefta-Gaub on 12/4/13. @@ -25,30 +25,30 @@ // better to add includes to the include path, but not link #include "../../script-engine/src/ScriptEngine.h" -#include "ModelsScriptingInterface.h" -#include "ModelItem.h" -#include "ModelTree.h" +#include "EntityScriptingInterface.h" +#include "EntityItem.h" +#include "EntityTree.h" -uint32_t ModelItem::_nextID = 0; +uint32_t EntityItem::_nextID = 0; // for locally created models -std::map ModelItem::_tokenIDsToIDs; -uint32_t ModelItem::_nextCreatorTokenID = 0; +std::map EntityItem::_tokenIDsToIDs; +uint32_t EntityItem::_nextCreatorTokenID = 0; -uint32_t ModelItem::getIDfromCreatorTokenID(uint32_t creatorTokenID) { +uint32_t EntityItem::getIDfromCreatorTokenID(uint32_t creatorTokenID) { if (_tokenIDsToIDs.find(creatorTokenID) != _tokenIDsToIDs.end()) { return _tokenIDsToIDs[creatorTokenID]; } return UNKNOWN_MODEL_ID; } -uint32_t ModelItem::getNextCreatorTokenID() { +uint32_t EntityItem::getNextCreatorTokenID() { uint32_t creatorTokenID = _nextCreatorTokenID; _nextCreatorTokenID++; return creatorTokenID; } -void ModelItem::handleAddModelResponse(const QByteArray& packet) { +void EntityItem::handleAddEntityResponse(const QByteArray& packet) { const unsigned char* dataAt = reinterpret_cast(packet.data()); int numBytesPacketHeader = numBytesForPacketHeader(packet); dataAt += numBytesPacketHeader; @@ -65,12 +65,12 @@ void ModelItem::handleAddModelResponse(const QByteArray& packet) { _tokenIDsToIDs[creatorTokenID] = modelItemID; } -ModelItem::ModelItem() { +EntityItem::EntityItem() { rgbColor noColor = { 0, 0, 0 }; init(glm::vec3(0,0,0), 0, noColor, NEW_MODEL); } -void ModelItem::initFromModelItemID(const ModelItemID& modelItemID) { +void EntityItem::initFromEntityItemID(const EntityItemID& modelItemID) { _id = modelItemID.id; _creatorTokenID = modelItemID.creatorTokenID; @@ -85,7 +85,7 @@ void ModelItem::initFromModelItemID(const ModelItemID& modelItemID) { memcpy(_color, noColor, sizeof(_color)); _shouldDie = false; _modelURL = MODEL_DEFAULT_MODEL_URL; - _modelRotation = MODEL_DEFAULT_MODEL_ROTATION; + _rotation = MODEL_DEFAULT_MODEL_ROTATION; // animation related _animationURL = MODEL_DEFAULT_ANIMATION_URL; @@ -98,19 +98,19 @@ void ModelItem::initFromModelItemID(const ModelItemID& modelItemID) { _lastAnimated = now; } -ModelItem::ModelItem(const ModelItemID& modelItemID) { - initFromModelItemID(modelItemID); +EntityItem::EntityItem(const EntityItemID& modelItemID) { + initFromEntityItemID(modelItemID); } -ModelItem::ModelItem(const ModelItemID& modelItemID, const ModelItemProperties& properties) { - initFromModelItemID(modelItemID); +EntityItem::EntityItem(const EntityItemID& modelItemID, const EntityItemProperties& properties) { + initFromEntityItemID(modelItemID); setProperties(properties, true); // force copy } -ModelItem::~ModelItem() { +EntityItem::~EntityItem() { } -void ModelItem::init(glm::vec3 position, float radius, rgbColor color, uint32_t id) { +void EntityItem::init(glm::vec3 position, float radius, rgbColor color, uint32_t id) { if (id == NEW_MODEL) { _id = _nextID; _nextID++; @@ -126,7 +126,7 @@ void ModelItem::init(glm::vec3 position, float radius, rgbColor color, uint32_t memcpy(_color, color, sizeof(_color)); _shouldDie = false; _modelURL = MODEL_DEFAULT_MODEL_URL; - _modelRotation = MODEL_DEFAULT_MODEL_ROTATION; + _rotation = MODEL_DEFAULT_MODEL_ROTATION; // animation related _animationURL = MODEL_DEFAULT_ANIMATION_URL; @@ -138,8 +138,8 @@ void ModelItem::init(glm::vec3 position, float radius, rgbColor color, uint32_t _lastAnimated = now; } -OctreeElement::AppendState ModelItem::appendModelData(OctreePacketData* packetData, EncodeBitstreamParams& params, - ModelTreeElementExtraEncodeData* modelTreeElementExtraEncodeData) const { +OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packetData, EncodeBitstreamParams& params, + EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData) const { // ALL this fits... // object ID [16 bytes] @@ -154,8 +154,8 @@ OctreeElement::AppendState ModelItem::appendModelData(OctreePacketData* packetDa quint64 updateDelta = getLastUpdated() <= getLastEdited() ? 0 : getLastUpdated() - getLastEdited(); ByteCountCoded updateDeltaCoder = updateDelta; QByteArray encodedUpdateDelta = updateDeltaCoder; - ModelPropertyFlags propertyFlags(PROP_LAST_ITEM); - ModelPropertyFlags requestedProperties; + EntityPropertyFlags propertyFlags(PROP_LAST_ITEM); + EntityPropertyFlags requestedProperties; requestedProperties += PROP_POSITION; requestedProperties += PROP_RADIUS; @@ -168,12 +168,12 @@ OctreeElement::AppendState ModelItem::appendModelData(OctreePacketData* packetDa requestedProperties += PROP_ANIMATION_PLAYING; requestedProperties += PROP_SHOULD_BE_DELETED; - ModelPropertyFlags propertiesDidntFit = requestedProperties; + EntityPropertyFlags propertiesDidntFit = requestedProperties; - // If we are being called for a subsequent pass at appendModelData() that failed to completely encode this item, + // If we are being called for a subsequent pass at appendEntityData() that failed to completely encode this item, // then our modelTreeElementExtraEncodeData should include data about which properties we need to append. - if (modelTreeElementExtraEncodeData && modelTreeElementExtraEncodeData->includedItems.contains(getModelItemID())) { - requestedProperties = modelTreeElementExtraEncodeData->includedItems.value(getModelItemID()); + if (modelTreeElementExtraEncodeData && modelTreeElementExtraEncodeData->includedItems.contains(getEntityItemID())) { + requestedProperties = modelTreeElementExtraEncodeData->includedItems.value(getEntityItemID()); } //qDebug() << "requestedProperties="; @@ -195,7 +195,7 @@ OctreeElement::AppendState ModelItem::appendModelData(OctreePacketData* packetDa bool headerFits = successIDFits && successTypeFits && successLastEditedFits && successLastUpdatedFits && successPropertyFlagsFits; - int startOfModelItemData = packetData->getUncompressedByteOffset(); + int startOfEntityItemData = packetData->getUncompressedByteOffset(); if (headerFits) { bool successPropertyFits; @@ -271,7 +271,7 @@ OctreeElement::AppendState ModelItem::appendModelData(OctreePacketData* packetDa if (requestedProperties.getHasProperty(PROP_ROTATION)) { //qDebug() << "PROP_ROTATION requested..."; LevelDetails propertyLevel = packetData->startLevel(); - successPropertyFits = packetData->appendValue(getModelRotation()); + successPropertyFits = packetData->appendValue(getRotation()); if (successPropertyFits) { propertyFlags |= PROP_ROTATION; propertiesDidntFit -= PROP_ROTATION; @@ -411,7 +411,7 @@ OctreeElement::AppendState ModelItem::appendModelData(OctreePacketData* packetDa } } if (propertyCount > 0) { - int endOfModelItemData = packetData->getUncompressedByteOffset(); + int endOfEntityItemData = packetData->getUncompressedByteOffset(); encodedPropertyFlags = propertyFlags; int newPropertyFlagsLength = encodedPropertyFlags.length(); @@ -423,9 +423,9 @@ OctreeElement::AppendState ModelItem::appendModelData(OctreePacketData* packetDa int oldSize = packetData->getUncompressedSize(); const unsigned char* modelItemData = packetData->getUncompressedData(propertyFlagsOffset + oldPropertyFlagsLength); - int modelItemDataLength = endOfModelItemData - startOfModelItemData; - int newModelItemDataStart = propertyFlagsOffset + newPropertyFlagsLength; - packetData->updatePriorBytes(newModelItemDataStart, modelItemData, modelItemDataLength); + int modelItemDataLength = endOfEntityItemData - startOfEntityItemData; + int newEntityItemDataStart = propertyFlagsOffset + newPropertyFlagsLength; + packetData->updatePriorBytes(newEntityItemDataStart, modelItemData, modelItemDataLength); int newSize = oldSize - (oldPropertyFlagsLength - newPropertyFlagsLength); packetData->setUncompressedSize(newSize); @@ -449,13 +449,13 @@ OctreeElement::AppendState ModelItem::appendModelData(OctreePacketData* packetDa // 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 - modelTreeElementExtraEncodeData->includedItems.insert(getModelItemID(), propertiesDidntFit); + modelTreeElementExtraEncodeData->includedItems.insert(getEntityItemID(), propertiesDidntFit); } return appendState; } -int ModelItem::expectedBytes() { +int EntityItem::expectedBytes() { int expectedBytes = sizeof(uint32_t) // id + sizeof(float) // age + sizeof(quint64) // last updated @@ -467,7 +467,7 @@ int ModelItem::expectedBytes() { return expectedBytes; } -int ModelItem::oldVersionReadModelDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) { +int EntityItem::oldVersionReadEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) { int bytesRead = 0; if (bytesLeftToRead >= expectedBytes()) { @@ -523,7 +523,7 @@ int ModelItem::oldVersionReadModelDataFromBuffer(const unsigned char* data, int bytesRead += modelURLLength; // modelRotation - int bytes = unpackOrientationQuatFromBytes(dataAt, _modelRotation); + int bytes = unpackOrientationQuatFromBytes(dataAt, _rotation); dataAt += bytes; bytesRead += bytes; @@ -557,9 +557,9 @@ int ModelItem::oldVersionReadModelDataFromBuffer(const unsigned char* data, int return bytesRead; } -ModelItemID ModelItem::readModelItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead, +EntityItemID EntityItem::readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) { - ModelItemID result; + EntityItemID result; if (bytesLeftToRead >= sizeof(uint32_t)) { // id uint32_t id; @@ -571,10 +571,10 @@ ModelItemID ModelItem::readModelItemIDFromBuffer(const unsigned char* data, int return result; } -int ModelItem::readModelDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) { +int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) { if (args.bitstreamVersion < VERSION_MODELS_SUPPORT_SPLIT_MTU) { - return oldVersionReadModelDataFromBuffer(data, bytesLeftToRead, args); + return oldVersionReadEntityDataFromBuffer(data, bytesLeftToRead, args); } // Header bytes @@ -627,7 +627,7 @@ int ModelItem::readModelDataFromBuffer(const unsigned char* data, int bytesLeftT // Property Flags QByteArray encodedPropertyFlags = originalDataBuffer.mid(bytesRead); // maximum possible size - ModelPropertyFlags propertyFlags = encodedPropertyFlags; + EntityPropertyFlags propertyFlags = encodedPropertyFlags; encodedUpdateDelta = updateDeltaCoder; // determine true length dataAt += propertyFlags.getEncodedLength(); bytesRead += propertyFlags.getEncodedLength(); @@ -662,7 +662,7 @@ int ModelItem::readModelDataFromBuffer(const unsigned char* data, int bytesLeftT // PROP_ROTATION if (propertyFlags.getHasProperty(PROP_ROTATION)) { - int bytes = unpackOrientationQuatFromBytes(dataAt, _modelRotation); + int bytes = unpackOrientationQuatFromBytes(dataAt, _rotation); dataAt += bytes; bytesRead += bytes; } @@ -721,13 +721,13 @@ int ModelItem::readModelDataFromBuffer(const unsigned char* data, int bytesLeftT return bytesRead; } -ModelItem ModelItem::fromEditPacket(const unsigned char* data, int length, int& processedBytes, ModelTree* tree, bool& valid) { +EntityItem EntityItem::fromEditPacket(const unsigned char* data, int length, int& processedBytes, EntityTree* tree, bool& valid) { bool wantDebug = false; if (wantDebug) { - qDebug() << "ModelItem ModelItem::fromEditPacket() length=" << length; + qDebug() << "EntityItem EntityItem::fromEditPacket() length=" << length; } - ModelItem newModelItem; // id and _lastUpdated will get set here... + EntityItem newEntityItem; // id and _lastUpdated will get set here... const unsigned char* dataAt = data; processedBytes = 0; @@ -736,7 +736,7 @@ ModelItem ModelItem::fromEditPacket(const unsigned char* data, int length, int& int lengthOfOctcode = bytesRequiredForCodeLength(octets); if (wantDebug) { - qDebug() << "ModelItem ModelItem::fromEditPacket() lengthOfOctcode=" << lengthOfOctcode; + qDebug() << "EntityItem EntityItem::fromEditPacket() lengthOfOctcode=" << lengthOfOctcode; } // we don't actually do anything with this octcode... @@ -750,13 +750,13 @@ ModelItem ModelItem::fromEditPacket(const unsigned char* data, int length, int& processedBytes += sizeof(editID); if (wantDebug) { - qDebug() << "ModelItem ModelItem::fromEditPacket() editID=" << editID; + qDebug() << "EntityItem EntityItem::fromEditPacket() editID=" << editID; } - bool isNewModelItem = (editID == NEW_MODEL); + bool isNewEntityItem = (editID == NEW_MODEL); // special case for handling "new" modelItems - if (isNewModelItem) { + if (isNewEntityItem) { // If this is a NEW_MODEL, 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 uint32_t creatorTokenID; @@ -764,16 +764,16 @@ ModelItem ModelItem::fromEditPacket(const unsigned char* data, int length, int& dataAt += sizeof(creatorTokenID); processedBytes += sizeof(creatorTokenID); - newModelItem.setCreatorTokenID(creatorTokenID); - newModelItem._newlyCreated = true; + newEntityItem.setCreatorTokenID(creatorTokenID); + newEntityItem._newlyCreated = true; valid = true; } else { // look up the existing modelItem - const ModelItem* existingModelItem = tree->findModelByID(editID, true); + const EntityItem* existingEntityItem = tree->findEntityByID(editID, true); // copy existing properties before over-writing with new properties - if (existingModelItem) { - newModelItem = *existingModelItem; + if (existingEntityItem) { + newEntityItem = *existingEntityItem; valid = true; } else { // the user attempted to edit a modelItem that doesn't exist @@ -785,19 +785,19 @@ ModelItem ModelItem::fromEditPacket(const unsigned char* data, int length, int& // of the edit packet so that we don't end up out of sync on our bitstream // fall through.... } - newModelItem._id = editID; - newModelItem._newlyCreated = false; + newEntityItem._id = editID; + newEntityItem._newlyCreated = false; } // lastEdited - memcpy(&newModelItem._lastEdited, dataAt, sizeof(newModelItem._lastEdited)); - dataAt += sizeof(newModelItem._lastEdited); - processedBytes += sizeof(newModelItem._lastEdited); + memcpy(&newEntityItem._lastEdited, dataAt, sizeof(newEntityItem._lastEdited)); + dataAt += sizeof(newEntityItem._lastEdited); + processedBytes += sizeof(newEntityItem._lastEdited); // All of the remaining items are optional, and may or may not be included based on their included values in the // properties included bits uint16_t packetContainsBits = 0; - if (!isNewModelItem) { + if (!isNewEntityItem) { memcpy(&packetContainsBits, dataAt, sizeof(packetContainsBits)); dataAt += sizeof(packetContainsBits); processedBytes += sizeof(packetContainsBits); @@ -806,109 +806,109 @@ ModelItem ModelItem::fromEditPacket(const unsigned char* data, int length, int& if (!packetContainsBits) { //qDebug() << "edit packet didn't contain any information ignore it..."; valid = false; - return newModelItem; + return newEntityItem; } } // radius - if (isNewModelItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_RADIUS) == MODEL_PACKET_CONTAINS_RADIUS)) { - memcpy(&newModelItem._radius, dataAt, sizeof(newModelItem._radius)); - dataAt += sizeof(newModelItem._radius); - processedBytes += sizeof(newModelItem._radius); + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_RADIUS) == MODEL_PACKET_CONTAINS_RADIUS)) { + memcpy(&newEntityItem._radius, dataAt, sizeof(newEntityItem._radius)); + dataAt += sizeof(newEntityItem._radius); + processedBytes += sizeof(newEntityItem._radius); } // position - if (isNewModelItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_POSITION) == MODEL_PACKET_CONTAINS_POSITION)) { - memcpy(&newModelItem._position, dataAt, sizeof(newModelItem._position)); - dataAt += sizeof(newModelItem._position); - processedBytes += sizeof(newModelItem._position); + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_POSITION) == MODEL_PACKET_CONTAINS_POSITION)) { + memcpy(&newEntityItem._position, dataAt, sizeof(newEntityItem._position)); + dataAt += sizeof(newEntityItem._position); + processedBytes += sizeof(newEntityItem._position); } // color - if (isNewModelItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_COLOR) == MODEL_PACKET_CONTAINS_COLOR)) { - memcpy(newModelItem._color, dataAt, sizeof(newModelItem._color)); - dataAt += sizeof(newModelItem._color); - processedBytes += sizeof(newModelItem._color); + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_COLOR) == MODEL_PACKET_CONTAINS_COLOR)) { + memcpy(newEntityItem._color, dataAt, sizeof(newEntityItem._color)); + dataAt += sizeof(newEntityItem._color); + processedBytes += sizeof(newEntityItem._color); } // shouldDie - if (isNewModelItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_SHOULDDIE) == MODEL_PACKET_CONTAINS_SHOULDDIE)) { - memcpy(&newModelItem._shouldDie, dataAt, sizeof(newModelItem._shouldDie)); - dataAt += sizeof(newModelItem._shouldDie); - processedBytes += sizeof(newModelItem._shouldDie); + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_SHOULDDIE) == MODEL_PACKET_CONTAINS_SHOULDDIE)) { + memcpy(&newEntityItem._shouldDie, dataAt, sizeof(newEntityItem._shouldDie)); + dataAt += sizeof(newEntityItem._shouldDie); + processedBytes += sizeof(newEntityItem._shouldDie); } // modelURL - if (isNewModelItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_MODEL_URL) == MODEL_PACKET_CONTAINS_MODEL_URL)) { + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_MODEL_URL) == MODEL_PACKET_CONTAINS_MODEL_URL)) { uint16_t modelURLLength; memcpy(&modelURLLength, dataAt, sizeof(modelURLLength)); dataAt += sizeof(modelURLLength); processedBytes += sizeof(modelURLLength); QString tempString((const char*)dataAt); - newModelItem._modelURL = tempString; + newEntityItem._modelURL = tempString; dataAt += modelURLLength; processedBytes += modelURLLength; } // modelRotation - if (isNewModelItem || ((packetContainsBits & + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_MODEL_ROTATION) == MODEL_PACKET_CONTAINS_MODEL_ROTATION)) { - int bytes = unpackOrientationQuatFromBytes(dataAt, newModelItem._modelRotation); + int bytes = unpackOrientationQuatFromBytes(dataAt, newEntityItem._rotation); dataAt += bytes; processedBytes += bytes; } // animationURL - if (isNewModelItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_ANIMATION_URL) == MODEL_PACKET_CONTAINS_ANIMATION_URL)) { + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_ANIMATION_URL) == MODEL_PACKET_CONTAINS_ANIMATION_URL)) { uint16_t animationURLLength; memcpy(&animationURLLength, dataAt, sizeof(animationURLLength)); dataAt += sizeof(animationURLLength); processedBytes += sizeof(animationURLLength); QString tempString((const char*)dataAt); - newModelItem._animationURL = tempString; + newEntityItem._animationURL = tempString; dataAt += animationURLLength; processedBytes += animationURLLength; } // animationIsPlaying - if (isNewModelItem || ((packetContainsBits & + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_ANIMATION_PLAYING) == MODEL_PACKET_CONTAINS_ANIMATION_PLAYING)) { - memcpy(&newModelItem._animationIsPlaying, dataAt, sizeof(newModelItem._animationIsPlaying)); - dataAt += sizeof(newModelItem._animationIsPlaying); - processedBytes += sizeof(newModelItem._animationIsPlaying); + memcpy(&newEntityItem._animationIsPlaying, dataAt, sizeof(newEntityItem._animationIsPlaying)); + dataAt += sizeof(newEntityItem._animationIsPlaying); + processedBytes += sizeof(newEntityItem._animationIsPlaying); } // animationFrameIndex - if (isNewModelItem || ((packetContainsBits & + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_ANIMATION_FRAME) == MODEL_PACKET_CONTAINS_ANIMATION_FRAME)) { - memcpy(&newModelItem._animationFrameIndex, dataAt, sizeof(newModelItem._animationFrameIndex)); - dataAt += sizeof(newModelItem._animationFrameIndex); - processedBytes += sizeof(newModelItem._animationFrameIndex); + memcpy(&newEntityItem._animationFrameIndex, dataAt, sizeof(newEntityItem._animationFrameIndex)); + dataAt += sizeof(newEntityItem._animationFrameIndex); + processedBytes += sizeof(newEntityItem._animationFrameIndex); } // animationFPS - if (isNewModelItem || ((packetContainsBits & + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_ANIMATION_FPS) == MODEL_PACKET_CONTAINS_ANIMATION_FPS)) { - memcpy(&newModelItem._animationFPS, dataAt, sizeof(newModelItem._animationFPS)); - dataAt += sizeof(newModelItem._animationFPS); - processedBytes += sizeof(newModelItem._animationFPS); + memcpy(&newEntityItem._animationFPS, dataAt, sizeof(newEntityItem._animationFPS)); + dataAt += sizeof(newEntityItem._animationFPS); + processedBytes += sizeof(newEntityItem._animationFPS); } const bool wantDebugging = false; if (wantDebugging) { - qDebug("ModelItem::fromEditPacket()..."); - qDebug() << " ModelItem id in packet:" << editID; - newModelItem.debugDump(); + qDebug("EntityItem::fromEditPacket()..."); + qDebug() << " EntityItem id in packet:" << editID; + newEntityItem.debugDump(); } - return newModelItem; + return newEntityItem; } -void ModelItem::debugDump() const { - qDebug("ModelItem id :%u", _id); +void EntityItem::debugDump() const { + qDebug("EntityItem id :%u", _id); qDebug(" edited ago:%f", getEditedAgo()); qDebug(" should die:%s", debug::valueOf(getShouldDie())); qDebug(" position:%f,%f,%f", _position.x, _position.y, _position.z); @@ -917,7 +917,7 @@ void ModelItem::debugDump() const { qDebug() << " modelURL:" << qPrintable(getModelURL()); } -bool ModelItem::encodeModelEditMessageDetails(PacketType command, ModelItemID id, const ModelItemProperties& properties, +bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID id, const EntityItemProperties& properties, unsigned char* bufferOut, int sizeIn, int& sizeOut) { bool success = true; // assume the best @@ -947,7 +947,7 @@ bool ModelItem::encodeModelEditMessageDetails(PacketType command, ModelItemID id sizeOut += lengthOfOctcode; // Now add our edit content details... - bool isNewModelItem = (id.id == NEW_MODEL); + bool isNewEntityItem = (id.id == NEW_MODEL); // id memcpy(copyAt, &id.id, sizeof(id.id)); @@ -955,7 +955,7 @@ bool ModelItem::encodeModelEditMessageDetails(PacketType command, ModelItemID id sizeOut += sizeof(id.id); // special case for handling "new" modelItems - if (isNewModelItem) { + if (isNewEntityItem) { // If this is a NEW_MODEL, 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 memcpy(copyAt, &id.creatorTokenID, sizeof(id.creatorTokenID)); @@ -972,14 +972,14 @@ bool ModelItem::encodeModelEditMessageDetails(PacketType command, ModelItemID id // For new modelItems, all remaining items are mandatory, for an edited modelItem, All of the remaining items are // optional, and may or may not be included based on their included values in the properties included bits uint16_t packetContainsBits = properties.getChangedBits(); - if (!isNewModelItem) { + if (!isNewEntityItem) { memcpy(copyAt, &packetContainsBits, sizeof(packetContainsBits)); copyAt += sizeof(packetContainsBits); sizeOut += sizeof(packetContainsBits); } // radius - if (isNewModelItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_RADIUS) == MODEL_PACKET_CONTAINS_RADIUS)) { + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_RADIUS) == MODEL_PACKET_CONTAINS_RADIUS)) { float radius = properties.getRadius() / (float) TREE_SCALE; memcpy(copyAt, &radius, sizeof(radius)); copyAt += sizeof(radius); @@ -987,7 +987,7 @@ bool ModelItem::encodeModelEditMessageDetails(PacketType command, ModelItemID id } // position - if (isNewModelItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_POSITION) == MODEL_PACKET_CONTAINS_POSITION)) { + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_POSITION) == MODEL_PACKET_CONTAINS_POSITION)) { glm::vec3 position = properties.getPosition() / (float)TREE_SCALE; memcpy(copyAt, &position, sizeof(position)); copyAt += sizeof(position); @@ -995,7 +995,7 @@ bool ModelItem::encodeModelEditMessageDetails(PacketType command, ModelItemID id } // color - if (isNewModelItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_COLOR) == MODEL_PACKET_CONTAINS_COLOR)) { + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_COLOR) == MODEL_PACKET_CONTAINS_COLOR)) { rgbColor color = { properties.getColor().red, properties.getColor().green, properties.getColor().blue }; memcpy(copyAt, color, sizeof(color)); copyAt += sizeof(color); @@ -1003,7 +1003,7 @@ bool ModelItem::encodeModelEditMessageDetails(PacketType command, ModelItemID id } // shoulDie - if (isNewModelItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_SHOULDDIE) == MODEL_PACKET_CONTAINS_SHOULDDIE)) { + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_SHOULDDIE) == MODEL_PACKET_CONTAINS_SHOULDDIE)) { bool shouldDie = properties.getShouldDie(); memcpy(copyAt, &shouldDie, sizeof(shouldDie)); copyAt += sizeof(shouldDie); @@ -1011,7 +1011,7 @@ bool ModelItem::encodeModelEditMessageDetails(PacketType command, ModelItemID id } // modelURL - if (isNewModelItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_MODEL_URL) == MODEL_PACKET_CONTAINS_MODEL_URL)) { + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_MODEL_URL) == MODEL_PACKET_CONTAINS_MODEL_URL)) { uint16_t urlLength = properties.getModelURL().size() + 1; memcpy(copyAt, &urlLength, sizeof(urlLength)); copyAt += sizeof(urlLength); @@ -1022,14 +1022,14 @@ bool ModelItem::encodeModelEditMessageDetails(PacketType command, ModelItemID id } // modelRotation - if (isNewModelItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_MODEL_ROTATION) == MODEL_PACKET_CONTAINS_MODEL_ROTATION)) { - int bytes = packOrientationQuatToBytes(copyAt, properties.getModelRotation()); + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_MODEL_ROTATION) == MODEL_PACKET_CONTAINS_MODEL_ROTATION)) { + int bytes = packOrientationQuatToBytes(copyAt, properties.getRotation()); copyAt += bytes; sizeOut += bytes; } // animationURL - if (isNewModelItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_ANIMATION_URL) == MODEL_PACKET_CONTAINS_ANIMATION_URL)) { + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_ANIMATION_URL) == MODEL_PACKET_CONTAINS_ANIMATION_URL)) { uint16_t urlLength = properties.getAnimationURL().size() + 1; memcpy(copyAt, &urlLength, sizeof(urlLength)); copyAt += sizeof(urlLength); @@ -1040,7 +1040,7 @@ bool ModelItem::encodeModelEditMessageDetails(PacketType command, ModelItemID id } // animationIsPlaying - if (isNewModelItem || ((packetContainsBits & + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_ANIMATION_PLAYING) == MODEL_PACKET_CONTAINS_ANIMATION_PLAYING)) { bool animationIsPlaying = properties.getAnimationIsPlaying(); @@ -1050,7 +1050,7 @@ bool ModelItem::encodeModelEditMessageDetails(PacketType command, ModelItemID id } // animationFrameIndex - if (isNewModelItem || ((packetContainsBits & + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_ANIMATION_FRAME) == MODEL_PACKET_CONTAINS_ANIMATION_FRAME)) { float animationFrameIndex = properties.getAnimationFrameIndex(); @@ -1060,7 +1060,7 @@ bool ModelItem::encodeModelEditMessageDetails(PacketType command, ModelItemID id } // animationFPS - if (isNewModelItem || ((packetContainsBits & + if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_ANIMATION_FPS) == MODEL_PACKET_CONTAINS_ANIMATION_FPS)) { float animationFPS = properties.getAnimationFPS(); @@ -1071,8 +1071,8 @@ bool ModelItem::encodeModelEditMessageDetails(PacketType command, ModelItemID id bool wantDebugging = false; if (wantDebugging) { - qDebug("encodeModelItemEditMessageDetails()...."); - qDebug("ModelItem id :%u", id.id); + qDebug("encodeEntityItemEditMessageDetails()...."); + qDebug("EntityItem id :%u", id.id); qDebug(" nextID:%u", _nextID); } @@ -1083,7 +1083,7 @@ bool ModelItem::encodeModelEditMessageDetails(PacketType command, ModelItemID id } // adjust any internal timestamps to fix clock skew for this server -void ModelItem::adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssize_t length, int clockSkew) { +void EntityItem::adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssize_t length, int clockSkew) { unsigned char* dataAt = codeColorBuffer; int octets = numberOfThreeBitSectionsInCode(dataAt); int lengthOfOctcode = bytesRequiredForCodeLength(octets); @@ -1107,7 +1107,7 @@ void ModelItem::adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssi memcpy(dataAt, &lastEditedInServerTime, sizeof(lastEditedInServerTime)); const bool wantDebug = false; if (wantDebug) { - qDebug("ModelItem::adjustEditPacketForClockSkew()..."); + qDebug("EntityItem::adjustEditPacketForClockSkew()..."); qDebug() << " lastEditedInLocalTime: " << lastEditedInLocalTime; qDebug() << " clockSkew: " << clockSkew; qDebug() << " lastEditedInServerTime: " << lastEditedInServerTime; @@ -1115,27 +1115,27 @@ void ModelItem::adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssi } -QMap ModelItem::_loadedAnimations; // TODO: improve cleanup by leveraging the AnimationPointer(s) -AnimationCache ModelItem::_animationCache; +QMap EntityItem::_loadedAnimations; // TODO: improve cleanup by leveraging the AnimationPointer(s) +AnimationCache EntityItem::_animationCache; // This class/instance will cleanup the animations once unloaded. -class ModelAnimationsBookkeeper { +class EntityAnimationsBookkeeper { public: - ~ModelAnimationsBookkeeper() { - ModelItem::cleanupLoadedAnimations(); + ~EntityAnimationsBookkeeper() { + EntityItem::cleanupLoadedAnimations(); } }; -ModelAnimationsBookkeeper modelAnimationsBookkeeperInstance; +EntityAnimationsBookkeeper modelAnimationsBookkeeperInstance; -void ModelItem::cleanupLoadedAnimations() { +void EntityItem::cleanupLoadedAnimations() { foreach(AnimationPointer animation, _loadedAnimations) { animation.clear(); } _loadedAnimations.clear(); } -Animation* ModelItem::getAnimation(const QString& url) { +Animation* EntityItem::getAnimation(const QString& url) { AnimationPointer animation; // if we don't already have this model then create it and initialize it @@ -1148,7 +1148,7 @@ Animation* ModelItem::getAnimation(const QString& url) { return animation.data(); } -void ModelItem::mapJoints(const QStringList& modelJointNames) { +void EntityItem::mapJoints(const QStringList& modelJointNames) { // if we don't have animation, or we're already joint mapped then bail early if (!hasAnimation() || _jointMappingCompleted) { return; @@ -1169,7 +1169,7 @@ void ModelItem::mapJoints(const QStringList& modelJointNames) { } } -QVector ModelItem::getAnimationFrame() { +QVector EntityItem::getAnimationFrame() { QVector frameData; if (hasAnimation() && _jointMappingCompleted) { Animation* myAnimation = getAnimation(_animationURL); @@ -1191,7 +1191,7 @@ QVector ModelItem::getAnimationFrame() { return frameData; } -void ModelItem::update(const quint64& updateTime) { +void EntityItem::update(const quint64& updateTime) { _lastUpdated = updateTime; setShouldDie(getShouldDie()); @@ -1204,7 +1204,7 @@ void ModelItem::update(const quint64& updateTime) { const bool wantDebugging = false; if (wantDebugging) { - qDebug() << "ModelItem::update() now=" << now; + qDebug() << "EntityItem::update() now=" << now; qDebug() << " updateTime=" << updateTime; qDebug() << " _lastAnimated=" << _lastAnimated; qDebug() << " deltaTime=" << deltaTime; @@ -1221,27 +1221,27 @@ void ModelItem::update(const quint64& updateTime) { } } -void ModelItem::copyChangedProperties(const ModelItem& other) { +void EntityItem::copyChangedProperties(const EntityItem& other) { *this = other; } -ModelItemProperties ModelItem::getProperties() const { - ModelItemProperties properties; - properties.copyFromModelItem(*this); +EntityItemProperties EntityItem::getProperties() const { + EntityItemProperties properties; + properties.copyFromEntityItem(*this); return properties; } -void ModelItem::setProperties(const ModelItemProperties& properties, bool forceCopy) { - properties.copyToModelItem(*this, forceCopy); +void EntityItem::setProperties(const EntityItemProperties& properties, bool forceCopy) { + properties.copyToEntityItem(*this, forceCopy); } -ModelItemProperties::ModelItemProperties() : +EntityItemProperties::EntityItemProperties() : _position(0), _color(), _radius(MODEL_DEFAULT_RADIUS), _shouldDie(false), _modelURL(""), - _modelRotation(MODEL_DEFAULT_MODEL_ROTATION), + _rotation(MODEL_DEFAULT_MODEL_ROTATION), _animationURL(""), _animationIsPlaying(false), _animationFrameIndex(0.0), @@ -1257,7 +1257,7 @@ ModelItemProperties::ModelItemProperties() : _radiusChanged(false), _shouldDieChanged(false), _modelURLChanged(false), - _modelRotationChanged(false), + _rotationChanged(false), _animationURLChanged(false), _animationIsPlayingChanged(false), _animationFrameIndexChanged(false), @@ -1267,8 +1267,8 @@ ModelItemProperties::ModelItemProperties() : { } -void ModelItemProperties::debugDump() const { - qDebug() << "ModelItemProperties..."; +void EntityItemProperties::debugDump() const { + qDebug() << "EntityItemProperties..."; qDebug() << " _id=" << _id; qDebug() << " _idSet=" << _idSet; qDebug() << " _position=" << _position.x << "," << _position.y << "," << _position.z; @@ -1278,7 +1278,7 @@ void ModelItemProperties::debugDump() const { } -uint16_t ModelItemProperties::getChangedBits() const { +uint16_t EntityItemProperties::getChangedBits() const { uint16_t changedBits = 0; if (_radiusChanged) { changedBits += MODEL_PACKET_CONTAINS_RADIUS; @@ -1300,7 +1300,7 @@ uint16_t ModelItemProperties::getChangedBits() const { changedBits += MODEL_PACKET_CONTAINS_MODEL_URL; } - if (_modelRotationChanged) { + if (_rotationChanged) { changedBits += MODEL_PACKET_CONTAINS_MODEL_ROTATION; } @@ -1324,7 +1324,7 @@ uint16_t ModelItemProperties::getChangedBits() const { } -QScriptValue ModelItemProperties::copyToScriptValue(QScriptEngine* engine) const { +QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) const { QScriptValue properties = engine->newObject(); QScriptValue position = vec3toScriptValue(engine, _position); @@ -1339,7 +1339,7 @@ QScriptValue ModelItemProperties::copyToScriptValue(QScriptEngine* engine) const properties.setProperty("modelURL", _modelURL); - QScriptValue modelRotation = quatToScriptValue(engine, _modelRotation); + QScriptValue modelRotation = quatToScriptValue(engine, _rotation); properties.setProperty("modelRotation", modelRotation); properties.setProperty("animationURL", _animationURL); @@ -1356,7 +1356,7 @@ QScriptValue ModelItemProperties::copyToScriptValue(QScriptEngine* engine) const return properties; } -void ModelItemProperties::copyFromScriptValue(const QScriptValue &object) { +void EntityItemProperties::copyFromScriptValue(const QScriptValue &object) { QScriptValue position = object.property("position"); if (position.isValid()) { @@ -1431,14 +1431,14 @@ void ModelItemProperties::copyFromScriptValue(const QScriptValue &object) { QScriptValue z = modelRotation.property("z"); QScriptValue w = modelRotation.property("w"); if (x.isValid() && y.isValid() && z.isValid() && w.isValid()) { - glm::quat newModelRotation; - newModelRotation.x = x.toVariant().toFloat(); - newModelRotation.y = y.toVariant().toFloat(); - newModelRotation.z = z.toVariant().toFloat(); - newModelRotation.w = w.toVariant().toFloat(); - if (_defaultSettings || newModelRotation != _modelRotation) { - _modelRotation = newModelRotation; - _modelRotationChanged = true; + glm::quat newRotation; + newRotation.x = x.toVariant().toFloat(); + newRotation.y = y.toVariant().toFloat(); + newRotation.z = z.toVariant().toFloat(); + newRotation.w = w.toVariant().toFloat(); + if (_defaultSettings || newRotation != _rotation) { + _rotation = newRotation; + _rotationChanged = true; } } } @@ -1496,7 +1496,7 @@ void ModelItemProperties::copyFromScriptValue(const QScriptValue &object) { _lastEdited = usecTimestampNow(); } -void ModelItemProperties::copyToModelItem(ModelItem& modelItem, bool forceCopy) const { +void EntityItemProperties::copyToEntityItem(EntityItem& modelItem, bool forceCopy) const { bool somethingChanged = false; if (_positionChanged || forceCopy) { modelItem.setPosition(_position / (float) TREE_SCALE); @@ -1523,8 +1523,8 @@ void ModelItemProperties::copyToModelItem(ModelItem& modelItem, bool forceCopy) somethingChanged = true; } - if (_modelRotationChanged || forceCopy) { - modelItem.setModelRotation(_modelRotation); + if (_rotationChanged || forceCopy) { + modelItem.setRotation(_rotation); somethingChanged = true; } @@ -1558,20 +1558,20 @@ void ModelItemProperties::copyToModelItem(ModelItem& modelItem, bool forceCopy) if (wantDebug) { uint64_t now = usecTimestampNow(); int elapsed = now - _lastEdited; - qDebug() << "ModelItemProperties::copyToModelItem() AFTER update... edited AGO=" << elapsed << + qDebug() << "EntityItemProperties::copyToEntityItem() AFTER update... edited AGO=" << elapsed << "now=" << now << " _lastEdited=" << _lastEdited; } modelItem.setLastEdited(_lastEdited); } } -void ModelItemProperties::copyFromModelItem(const ModelItem& modelItem) { +void EntityItemProperties::copyFromEntityItem(const EntityItem& modelItem) { _position = modelItem.getPosition() * (float) TREE_SCALE; _color = modelItem.getXColor(); _radius = modelItem.getRadius() * (float) TREE_SCALE; _shouldDie = modelItem.getShouldDie(); _modelURL = modelItem.getModelURL(); - _modelRotation = modelItem.getModelRotation(); + _rotation = modelItem.getRotation(); _animationURL = modelItem.getAnimationURL(); _animationIsPlaying = modelItem.getAnimationIsPlaying(); _animationFrameIndex = modelItem.getAnimationFrameIndex(); @@ -1587,7 +1587,7 @@ void ModelItemProperties::copyFromModelItem(const ModelItem& modelItem) { _shouldDieChanged = false; _modelURLChanged = false; - _modelRotationChanged = false; + _rotationChanged = false; _animationURLChanged = false; _animationIsPlayingChanged = false; _animationFrameIndexChanged = false; @@ -1596,16 +1596,16 @@ void ModelItemProperties::copyFromModelItem(const ModelItem& modelItem) { _defaultSettings = false; } -QScriptValue ModelItemPropertiesToScriptValue(QScriptEngine* engine, const ModelItemProperties& properties) { +QScriptValue EntityItemPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties) { return properties.copyToScriptValue(engine); } -void ModelItemPropertiesFromScriptValue(const QScriptValue &object, ModelItemProperties& properties) { +void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemProperties& properties) { properties.copyFromScriptValue(object); } -QScriptValue ModelItemIDtoScriptValue(QScriptEngine* engine, const ModelItemID& id) { +QScriptValue EntityItemIDtoScriptValue(QScriptEngine* engine, const EntityItemID& id) { QScriptValue obj = engine->newObject(); obj.setProperty("id", id.id); obj.setProperty("creatorTokenID", id.creatorTokenID); @@ -1613,7 +1613,7 @@ QScriptValue ModelItemIDtoScriptValue(QScriptEngine* engine, const ModelItemID& return obj; } -void ModelItemIDfromScriptValue(const QScriptValue &object, ModelItemID& id) { +void EntityItemIDfromScriptValue(const QScriptValue &object, EntityItemID& id) { id.id = object.property("id").toVariant().toUInt(); id.creatorTokenID = object.property("creatorTokenID").toVariant().toUInt(); id.isKnownID = object.property("isKnownID").toVariant().toBool(); diff --git a/libraries/models/src/EntityItem.h b/libraries/models/src/EntityItem.h index c1dfb49d45..afc9ac5926 100644 --- a/libraries/models/src/EntityItem.h +++ b/libraries/models/src/EntityItem.h @@ -1,5 +1,5 @@ // -// ModelItem.h +// EntityItem.h // libraries/models/src // // Created by Brad Hefta-Gaub on 12/4/13. @@ -9,8 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_ModelItem_h -#define hifi_ModelItem_h +#ifndef hifi_EntityItem_h +#define hifi_EntityItem_h #include #include @@ -24,12 +24,12 @@ #include #include -class ModelItem; -class ModelEditPacketSender; -class ModelItemProperties; -class ModelsScriptingInterface; -class ModelTree; -class ModelTreeElementExtraEncodeData; +class EntityItem; +class EntityEditPacketSender; +class EntityItemProperties; +class EntitysScriptingInterface; +class EntityTree; +class EntityTreeElementExtraEncodeData; class ScriptEngine; class VoxelEditPacketSender; class VoxelsScriptingInterface; @@ -58,7 +58,7 @@ const QString MODEL_DEFAULT_ANIMATION_URL(""); const float MODEL_DEFAULT_ANIMATION_FPS = 30.0f; // PropertyFlags support -enum ModelPropertyList { +enum EntityPropertyList { PROP_PAGED_PROPERTY, PROP_CUSTOM_PROPERTIES_INCLUDED, PROP_VISIBLE, @@ -76,22 +76,22 @@ enum ModelPropertyList { PROP_LAST_ITEM = PROP_SHOULD_BE_DELETED }; -typedef PropertyFlags ModelPropertyFlags; +typedef PropertyFlags EntityPropertyFlags; /// A collection of properties of a model item used in the scripting API. Translates between the actual properties of a model /// and a JavaScript style hash/QScriptValue storing a set of properties. Used in scripting to set/get the complete set of /// model item properties via JavaScript hashes/QScriptValues /// all units for position, radius, etc are in meter units -class ModelItemProperties { +class EntityItemProperties { public: - ModelItemProperties(); + EntityItemProperties(); QScriptValue copyToScriptValue(QScriptEngine* engine) const; void copyFromScriptValue(const QScriptValue& object); - void copyToModelItem(ModelItem& modelItem, bool forceCopy = false) const; - void copyFromModelItem(const ModelItem& modelItem); + void copyToEntityItem(EntityItem& modelItem, bool forceCopy = false) const; + void copyFromEntityItem(const EntityItem& modelItem); const glm::vec3& getPosition() const { return _position; } xColor getColor() const { return _color; } @@ -99,7 +99,7 @@ public: bool getShouldDie() const { return _shouldDie; } const QString& getModelURL() const { return _modelURL; } - const glm::quat& getModelRotation() const { return _modelRotation; } + const glm::quat& getRotation() const { return _rotation; } const QString& getAnimationURL() const { return _animationURL; } float getAnimationFrameIndex() const { return _animationFrameIndex; } bool getAnimationIsPlaying() const { return _animationIsPlaying; } @@ -117,14 +117,14 @@ public: // model related properties void setModelURL(const QString& url) { _modelURL = url; _modelURLChanged = true; } - void setModelRotation(const glm::quat& rotation) { _modelRotation = rotation; _modelRotationChanged = true; } + void setRotation(const glm::quat& rotation) { _rotation = rotation; _rotationChanged = true; } void setAnimationURL(const QString& url) { _animationURL = url; _animationURLChanged = true; } void setAnimationFrameIndex(float value) { _animationFrameIndex = value; _animationFrameIndexChanged = true; } void setAnimationIsPlaying(bool value) { _animationIsPlaying = value; _animationIsPlayingChanged = true; } void setAnimationFPS(float value) { _animationFPS = value; _animationFPSChanged = true; } void setGlowLevel(float value) { _glowLevel = value; _glowLevelChanged = true; } - /// used by ModelScriptingInterface to return ModelItemProperties for unknown models + /// used by EntityScriptingInterface to return EntityItemProperties for unknown models void setIsUnknownID() { _id = UNKNOWN_MODEL_ID; _idSet = true; } glm::vec3 getMinimumPoint() const { return _position - glm::vec3(_radius, _radius, _radius); } @@ -139,7 +139,7 @@ private: bool _shouldDie; /// to delete it QString _modelURL; - glm::quat _modelRotation; + glm::quat _rotation; QString _animationURL; bool _animationIsPlaying; float _animationFrameIndex; @@ -156,7 +156,7 @@ private: bool _shouldDieChanged; bool _modelURLChanged; - bool _modelRotationChanged; + bool _rotationChanged; bool _animationURLChanged; bool _animationIsPlayingChanged; bool _animationFrameIndexChanged; @@ -164,23 +164,23 @@ private: bool _glowLevelChanged; bool _defaultSettings; }; -Q_DECLARE_METATYPE(ModelItemProperties); -QScriptValue ModelItemPropertiesToScriptValue(QScriptEngine* engine, const ModelItemProperties& properties); -void ModelItemPropertiesFromScriptValue(const QScriptValue &object, ModelItemProperties& properties); +Q_DECLARE_METATYPE(EntityItemProperties); +QScriptValue EntityItemPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties); +void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemProperties& properties); -/// Abstract ID for editing model items. Used in ModelItem JS API - When models are created in the JS api, they are given a +/// Abstract ID for editing model items. Used in EntityItem JS API - When models are created in the JS api, they are given a /// 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 ModelItemID { +class EntityItemID { public: - ModelItemID() : + EntityItemID() : id(NEW_MODEL), creatorTokenID(UNKNOWN_MODEL_TOKEN), isKnownID(false) { }; - ModelItemID(uint32_t id, uint32_t creatorTokenID, bool isKnownID) : + EntityItemID(uint32_t id, uint32_t creatorTokenID, bool isKnownID) : id(id), creatorTokenID(creatorTokenID), isKnownID(isKnownID) { }; - ModelItemID(uint32_t id) : + EntityItemID(uint32_t id) : id(id), creatorTokenID(UNKNOWN_MODEL_TOKEN), isKnownID(true) { }; uint32_t id; @@ -188,18 +188,18 @@ public: bool isKnownID; }; -inline bool operator<(const ModelItemID& a, const ModelItemID& b) { +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 ModelItemID& a, const ModelItemID& b) { +inline bool operator==(const EntityItemID& a, const EntityItemID& b) { if (a.id == UNKNOWN_MODEL_ID && b.id == UNKNOWN_MODEL_ID) { return a.creatorTokenID == b.creatorTokenID; } return a.id == b.id; } -inline uint qHash(const ModelItemID& a, uint seed) { +inline uint qHash(const EntityItemID& a, uint seed) { qint64 temp; if (a.id == UNKNOWN_MODEL_ID) { temp = -a.creatorTokenID; @@ -209,30 +209,30 @@ inline uint qHash(const ModelItemID& a, uint seed) { return qHash(temp, seed); } -inline QDebug operator<<(QDebug debug, const ModelItemID& id) { +inline QDebug operator<<(QDebug debug, const EntityItemID& id) { debug << "[ id:" << id.id << ", creatorTokenID:" << id.creatorTokenID << "]"; return debug; } -Q_DECLARE_METATYPE(ModelItemID); -Q_DECLARE_METATYPE(QVector); -QScriptValue ModelItemIDtoScriptValue(QScriptEngine* engine, const ModelItemID& properties); -void ModelItemIDfromScriptValue(const QScriptValue &object, ModelItemID& properties); +Q_DECLARE_METATYPE(EntityItemID); +Q_DECLARE_METATYPE(QVector); +QScriptValue EntityItemIDtoScriptValue(QScriptEngine* engine, const EntityItemID& properties); +void EntityItemIDfromScriptValue(const QScriptValue &object, EntityItemID& properties); -/// ModelItem class - this is the actual model item class. -class ModelItem { +/// EntityItem class - this is the actual model item class. +class EntityItem { public: - ModelItem(); - ModelItem(const ModelItemID& modelItemID); - ModelItem(const ModelItemID& modelItemID, const ModelItemProperties& properties); + EntityItem(); + EntityItem(const EntityItemID& modelItemID); + EntityItem(const EntityItemID& modelItemID, const EntityItemProperties& properties); /// creates an NEW model from an model add or edit message data buffer - static ModelItem fromEditPacket(const unsigned char* data, int length, int& processedBytes, ModelTree* tree, bool& valid); + static EntityItem fromEditPacket(const unsigned char* data, int length, int& processedBytes, EntityTree* tree, bool& valid); - virtual ~ModelItem(); + virtual ~EntityItem(); quint8 getType() const { return 0; } /// place holder for now @@ -257,13 +257,13 @@ public: // model related properties bool hasModel() const { return !_modelURL.isEmpty(); } const QString& getModelURL() const { return _modelURL; } - const glm::quat& getModelRotation() const { return _modelRotation; } + const glm::quat& getRotation() const { return _rotation; } bool hasAnimation() const { return !_animationURL.isEmpty(); } const QString& getAnimationURL() const { return _animationURL; } float getGlowLevel() const { return _glowLevel; } - ModelItemID getModelItemID() const { return ModelItemID(getID(), getCreatorTokenID(), getID() != UNKNOWN_MODEL_ID); } - ModelItemProperties getProperties() const; + EntityItemID getEntityItemID() const { return EntityItemID(getID(), getCreatorTokenID(), getID() != UNKNOWN_MODEL_ID); } + EntityItemProperties getProperties() const; /// The last updated/simulated time of this model from the time perspective of the authoritative server/source quint64 getLastUpdated() const { return _lastUpdated; } @@ -298,27 +298,27 @@ public: // model related properties void setModelURL(const QString& url) { _modelURL = url; } - void setModelRotation(const glm::quat& rotation) { _modelRotation = rotation; } + void setRotation(const glm::quat& rotation) { _rotation = rotation; } void setAnimationURL(const QString& url) { _animationURL = url; } void setAnimationFrameIndex(float value) { _animationFrameIndex = value; } void setAnimationIsPlaying(bool value) { _animationIsPlaying = value; } void setAnimationFPS(float value) { _animationFPS = value; } void setGlowLevel(float glowLevel) { _glowLevel = glowLevel; } - void setProperties(const ModelItemProperties& properties, bool forceCopy = false); + void setProperties(const EntityItemProperties& properties, bool forceCopy = false); - OctreeElement::AppendState appendModelData(OctreePacketData* packetData, EncodeBitstreamParams& params, - ModelTreeElementExtraEncodeData* modelTreeElementExtraEncodeData) const; + OctreeElement::AppendState appendEntityData(OctreePacketData* packetData, EncodeBitstreamParams& params, + EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData) const; - static ModelItemID readModelItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead, + static EntityItemID readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args); - int readModelDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args); + int readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args); /// For reading models from pre V3 bitstreams - int oldVersionReadModelDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args); + int oldVersionReadEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args); static int expectedBytes(); - static bool encodeModelEditMessageDetails(PacketType command, ModelItemID id, const ModelItemProperties& details, + static bool encodeEntityEditMessageDetails(PacketType command, EntityItemID id, const EntityItemProperties& details, unsigned char* bufferOut, int sizeIn, int& sizeOut); static void adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssize_t length, int clockSkew); @@ -328,12 +328,12 @@ public: void debugDump() const; // similar to assignment/copy, but it handles keeping lifetime accurate - void copyChangedProperties(const ModelItem& other); + void copyChangedProperties(const EntityItem& other); // these methods allow you to create models, and later edit them. static uint32_t getIDfromCreatorTokenID(uint32_t creatorTokenID); static uint32_t getNextCreatorTokenID(); - static void handleAddModelResponse(const QByteArray& packet); + static void handleAddEntityResponse(const QByteArray& packet); void mapJoints(const QStringList& modelJointNames); QVector getAnimationFrame(); @@ -346,7 +346,7 @@ public: static void cleanupLoadedAnimations(); protected: - void initFromModelItemID(const ModelItemID& modelItemID); + void initFromEntityItemID(const EntityItemID& modelItemID); virtual void init(glm::vec3 position, float radius, rgbColor color, uint32_t id = NEW_MODEL); glm::vec3 _position; @@ -358,7 +358,7 @@ protected: // model related items QString _modelURL; - glm::quat _modelRotation; + glm::quat _rotation; float _glowLevel; @@ -389,4 +389,4 @@ protected: }; -#endif // hifi_ModelItem_h +#endif // hifi_EntityItem_h diff --git a/libraries/models/src/EntityScriptingInterface.cpp b/libraries/models/src/EntityScriptingInterface.cpp index 7e08571fe5..691d109bbb 100644 --- a/libraries/models/src/EntityScriptingInterface.cpp +++ b/libraries/models/src/EntityScriptingInterface.cpp @@ -1,5 +1,5 @@ // -// ModelsScriptingInterface.cpp +// EntityScriptingInterface.cpp // libraries/models/src // // Created by Brad Hefta-Gaub on 12/6/13. @@ -9,73 +9,73 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "ModelsScriptingInterface.h" -#include "ModelTree.h" +#include "EntityScriptingInterface.h" +#include "EntityTree.h" -ModelsScriptingInterface::ModelsScriptingInterface() : +EntityScriptingInterface::EntityScriptingInterface() : _nextCreatorTokenID(0), - _modelTree(NULL) + _entityTree(NULL) { } -void ModelsScriptingInterface::queueModelMessage(PacketType packetType, - ModelItemID modelID, const ModelItemProperties& properties) { - getModelPacketSender()->queueModelEditMessage(packetType, modelID, properties); +void EntityScriptingInterface::queueEntityMessage(PacketType packetType, + EntityItemID entityID, const EntityItemProperties& properties) { + getEntityPacketSender()->queueEntityEditMessage(packetType, entityID, properties); } -ModelItemID ModelsScriptingInterface::addModel(const ModelItemProperties& properties) { +EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& properties) { // The application will keep track of creatorTokenID - uint32_t creatorTokenID = ModelItem::getNextCreatorTokenID(); + uint32_t creatorTokenID = EntityItem::getNextCreatorTokenID(); - ModelItemID id(NEW_MODEL, creatorTokenID, false ); + EntityItemID id(NEW_MODEL, creatorTokenID, false ); // queue the packet - queueModelMessage(PacketTypeModelAddOrEdit, id, properties); + queueEntityMessage(PacketTypeEntityAddOrEdit, id, properties); // If we have a local model tree set, then also update it. - if (_modelTree) { - _modelTree->lockForWrite(); - _modelTree->addModel(id, properties); - _modelTree->unlock(); + if (_entityTree) { + _entityTree->lockForWrite(); + _entityTree->addEntity(id, properties); + _entityTree->unlock(); } return id; } -ModelItemID ModelsScriptingInterface::identifyModel(ModelItemID modelID) { - uint32_t actualID = modelID.id; +EntityItemID EntityScriptingInterface::identifyEntity(EntityItemID entityID) { + uint32_t actualID = entityID.id; - if (!modelID.isKnownID) { - actualID = ModelItem::getIDfromCreatorTokenID(modelID.creatorTokenID); + if (!entityID.isKnownID) { + actualID = EntityItem::getIDfromCreatorTokenID(entityID.creatorTokenID); if (actualID == UNKNOWN_MODEL_ID) { - return modelID; // bailing early + return entityID; // bailing early } // found it! - modelID.id = actualID; - modelID.isKnownID = true; + entityID.id = actualID; + entityID.isKnownID = true; } - return modelID; + return entityID; } -ModelItemProperties ModelsScriptingInterface::getModelProperties(ModelItemID modelID) { - ModelItemProperties results; - ModelItemID identity = identifyModel(modelID); +EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID entityID) { + EntityItemProperties results; + EntityItemID identity = identifyEntity(entityID); if (!identity.isKnownID) { results.setIsUnknownID(); return results; } - if (_modelTree) { - _modelTree->lockForRead(); - const ModelItem* model = _modelTree->findModelByID(identity.id, true); + if (_entityTree) { + _entityTree->lockForRead(); + const EntityItem* model = _entityTree->findEntityByID(identity.id, true); if (model) { - results.copyFromModelItem(*model); + results.copyFromEntityItem(*model); } else { results.setIsUnknownID(); } - _modelTree->unlock(); + _entityTree->unlock(); } return results; @@ -83,73 +83,73 @@ ModelItemProperties ModelsScriptingInterface::getModelProperties(ModelItemID mod -ModelItemID ModelsScriptingInterface::editModel(ModelItemID modelID, const ModelItemProperties& properties) { - uint32_t actualID = modelID.id; +EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const EntityItemProperties& properties) { + uint32_t actualID = entityID.id; // if the model is unknown, attempt to look it up - if (!modelID.isKnownID) { - actualID = ModelItem::getIDfromCreatorTokenID(modelID.creatorTokenID); + if (!entityID.isKnownID) { + actualID = EntityItem::getIDfromCreatorTokenID(entityID.creatorTokenID); } // if at this point, we know the id, send the update to the model server if (actualID != UNKNOWN_MODEL_ID) { - modelID.id = actualID; - modelID.isKnownID = true; - queueModelMessage(PacketTypeModelAddOrEdit, modelID, properties); + entityID.id = actualID; + entityID.isKnownID = true; + queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); } // If we have a local model 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 models just with creatorTokenID - if (_modelTree) { - _modelTree->lockForWrite(); - _modelTree->updateModel(modelID, properties); - _modelTree->unlock(); + if (_entityTree) { + _entityTree->lockForWrite(); + _entityTree->updateEntity(entityID, properties); + _entityTree->unlock(); } - return modelID; + return entityID; } -// TODO: This deleteModel() method uses the PacketType_MODEL_ADD_OR_EDIT message to send +// TODO: This deleteEntity() method uses the PacketType_MODEL_ADD_OR_EDIT message to send // a changed model with a shouldDie() property set to true. This works and is currently the only // way to tell the model server to delete a model. But we should change this to use the PacketType_MODEL_ERASE // message which takes a list of model id's to delete. -void ModelsScriptingInterface::deleteModel(ModelItemID modelID) { +void EntityScriptingInterface::deleteEntity(EntityItemID entityID) { // setup properties to kill the model - ModelItemProperties properties; + EntityItemProperties properties; properties.setShouldDie(true); - uint32_t actualID = modelID.id; + uint32_t actualID = entityID.id; // if the model is unknown, attempt to look it up - if (!modelID.isKnownID) { - actualID = ModelItem::getIDfromCreatorTokenID(modelID.creatorTokenID); + if (!entityID.isKnownID) { + actualID = EntityItem::getIDfromCreatorTokenID(entityID.creatorTokenID); } // if at this point, we know the id, send the update to the model server if (actualID != UNKNOWN_MODEL_ID) { - modelID.id = actualID; - modelID.isKnownID = true; - queueModelMessage(PacketTypeModelAddOrEdit, modelID, properties); + entityID.id = actualID; + entityID.isKnownID = true; + queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); } // If we have a local model tree set, then also update it. - if (_modelTree) { - _modelTree->lockForWrite(); - _modelTree->deleteModel(modelID); - _modelTree->unlock(); + if (_entityTree) { + _entityTree->lockForWrite(); + _entityTree->deleteEntity(entityID); + _entityTree->unlock(); } } -ModelItemID ModelsScriptingInterface::findClosestModel(const glm::vec3& center, float radius) const { - ModelItemID result(UNKNOWN_MODEL_ID, UNKNOWN_MODEL_TOKEN, false); - if (_modelTree) { - _modelTree->lockForRead(); - const ModelItem* closestModel = _modelTree->findClosestModel(center/(float)TREE_SCALE, +EntityItemID EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const { + EntityItemID result(UNKNOWN_MODEL_ID, UNKNOWN_MODEL_TOKEN, false); + if (_entityTree) { + _entityTree->lockForRead(); + const EntityItem* closestEntity = _entityTree->findClosestEntity(center/(float)TREE_SCALE, radius/(float)TREE_SCALE); - _modelTree->unlock(); - if (closestModel) { - result.id = closestModel->getID(); + _entityTree->unlock(); + if (closestEntity) { + result.id = closestEntity->getID(); result.isKnownID = true; } } @@ -157,41 +157,41 @@ ModelItemID ModelsScriptingInterface::findClosestModel(const glm::vec3& center, } -QVector ModelsScriptingInterface::findModels(const glm::vec3& center, float radius) const { - QVector result; - if (_modelTree) { - _modelTree->lockForRead(); - QVector models; - _modelTree->findModels(center/(float)TREE_SCALE, radius/(float)TREE_SCALE, models); - _modelTree->unlock(); +QVector EntityScriptingInterface::findEntities(const glm::vec3& center, float radius) const { + QVector result; + if (_entityTree) { + _entityTree->lockForRead(); + QVector models; + _entityTree->findEntities(center/(float)TREE_SCALE, radius/(float)TREE_SCALE, models); + _entityTree->unlock(); - foreach (const ModelItem* model, models) { - ModelItemID thisModelItemID(model->getID(), UNKNOWN_MODEL_TOKEN, true); - result << thisModelItemID; + foreach (const EntityItem* model, models) { + EntityItemID thisEntityItemID(model->getID(), UNKNOWN_MODEL_TOKEN, true); + result << thisEntityItemID; } } return result; } -RayToModelIntersectionResult ModelsScriptingInterface::findRayIntersection(const PickRay& ray) { +RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray) { return findRayIntersectionWorker(ray, Octree::TryLock); } -RayToModelIntersectionResult ModelsScriptingInterface::findRayIntersectionBlocking(const PickRay& ray) { +RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionBlocking(const PickRay& ray) { return findRayIntersectionWorker(ray, Octree::Lock); } -RayToModelIntersectionResult ModelsScriptingInterface::findRayIntersectionWorker(const PickRay& ray, +RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType) { - RayToModelIntersectionResult result; - if (_modelTree) { + RayToEntityIntersectionResult result; + if (_entityTree) { OctreeElement* element; - ModelItem* intersectedModel; - result.intersects = _modelTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face, - (void**)&intersectedModel, lockType, &result.accurate); - if (result.intersects && intersectedModel) { - result.modelID = intersectedModel->getModelItemID(); - result.modelProperties = intersectedModel->getProperties(); + EntityItem* intersectedEntity; + result.intersects = _entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face, + (void**)&intersectedEntity, lockType, &result.accurate); + if (result.intersects && intersectedEntity) { + result.entityID = intersectedEntity->getEntityItemID(); + result.properties = intersectedEntity->getProperties(); result.intersection = ray.origin + (ray.direction * result.distance); } } @@ -199,25 +199,25 @@ RayToModelIntersectionResult ModelsScriptingInterface::findRayIntersectionWorker } -RayToModelIntersectionResult::RayToModelIntersectionResult() : +RayToEntityIntersectionResult::RayToEntityIntersectionResult() : intersects(false), accurate(true), // assume it's accurate - modelID(), - modelProperties(), + entityID(), + properties(), distance(0), face() { }; -QScriptValue RayToModelIntersectionResultToScriptValue(QScriptEngine* engine, const RayToModelIntersectionResult& value) { +QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, const RayToEntityIntersectionResult& value) { QScriptValue obj = engine->newObject(); obj.setProperty("intersects", value.intersects); obj.setProperty("accurate", value.accurate); - QScriptValue modelItemValue = ModelItemIDtoScriptValue(engine, value.modelID); - obj.setProperty("modelID", modelItemValue); + QScriptValue modelItemValue = EntityItemIDtoScriptValue(engine, value.entityID); + obj.setProperty("entityID", modelItemValue); - QScriptValue modelPropertiesValue = ModelItemPropertiesToScriptValue(engine, value.modelProperties); - obj.setProperty("modelProperties", modelPropertiesValue); + QScriptValue modelPropertiesValue = EntityItemPropertiesToScriptValue(engine, value.properties); + obj.setProperty("properties", modelPropertiesValue); obj.setProperty("distance", value.distance); @@ -253,16 +253,16 @@ QScriptValue RayToModelIntersectionResultToScriptValue(QScriptEngine* engine, co return obj; } -void RayToModelIntersectionResultFromScriptValue(const QScriptValue& object, RayToModelIntersectionResult& value) { +void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, RayToEntityIntersectionResult& value) { value.intersects = object.property("intersects").toVariant().toBool(); value.accurate = object.property("accurate").toVariant().toBool(); - QScriptValue modelIDValue = object.property("modelID"); + QScriptValue modelIDValue = object.property("entityID"); if (modelIDValue.isValid()) { - ModelItemIDfromScriptValue(modelIDValue, value.modelID); + EntityItemIDfromScriptValue(modelIDValue, value.entityID); } - QScriptValue modelPropertiesValue = object.property("modelProperties"); + QScriptValue modelPropertiesValue = object.property("properties"); if (modelPropertiesValue.isValid()) { - ModelItemPropertiesFromScriptValue(modelPropertiesValue, value.modelProperties); + EntityItemPropertiesFromScriptValue(modelPropertiesValue, value.properties); } value.distance = object.property("distance").toVariant().toFloat(); diff --git a/libraries/models/src/EntityScriptingInterface.h b/libraries/models/src/EntityScriptingInterface.h index c723c9071a..af4537c834 100644 --- a/libraries/models/src/EntityScriptingInterface.h +++ b/libraries/models/src/EntityScriptingInterface.h @@ -1,5 +1,5 @@ // -// ModelsScriptingInterface.h +// EntityScriptingInterface.h // libraries/models/src // // Created by Brad Hefta-Gaub on 12/6/13. @@ -9,8 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_ModelsScriptingInterface_h -#define hifi_ModelsScriptingInterface_h +#ifndef hifi_EntityScriptingInterface_h +#define hifi_EntityScriptingInterface_h #include @@ -19,88 +19,88 @@ #include #include -#include "ModelEditPacketSender.h" +#include "EntityEditPacketSender.h" -class RayToModelIntersectionResult { +class RayToEntityIntersectionResult { public: - RayToModelIntersectionResult(); + RayToEntityIntersectionResult(); bool intersects; bool accurate; - ModelItemID modelID; - ModelItemProperties modelProperties; + EntityItemID entityID; + EntityItemProperties properties; float distance; BoxFace face; glm::vec3 intersection; }; -Q_DECLARE_METATYPE(RayToModelIntersectionResult) +Q_DECLARE_METATYPE(RayToEntityIntersectionResult) -QScriptValue RayToModelIntersectionResultToScriptValue(QScriptEngine* engine, const RayToModelIntersectionResult& results); -void RayToModelIntersectionResultFromScriptValue(const QScriptValue& object, RayToModelIntersectionResult& results); +QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, const RayToEntityIntersectionResult& results); +void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, RayToEntityIntersectionResult& results); -/// handles scripting of Model commands from JS passed to assigned clients -class ModelsScriptingInterface : public OctreeScriptingInterface { +/// handles scripting of Entity commands from JS passed to assigned clients +class EntityScriptingInterface : public OctreeScriptingInterface { Q_OBJECT public: - ModelsScriptingInterface(); + EntityScriptingInterface(); - ModelEditPacketSender* getModelPacketSender() const { return (ModelEditPacketSender*)getPacketSender(); } - virtual NodeType_t getServerNodeType() const { return NodeType::ModelServer; } - virtual OctreeEditPacketSender* createPacketSender() { return new ModelEditPacketSender(); } + EntityEditPacketSender* getEntityPacketSender() const { return (EntityEditPacketSender*)getPacketSender(); } + virtual NodeType_t getServerNodeType() const { return NodeType::EntityServer; } + virtual OctreeEditPacketSender* createPacketSender() { return new EntityEditPacketSender(); } - void setModelTree(ModelTree* modelTree) { _modelTree = modelTree; } - ModelTree* getModelTree(ModelTree*) { return _modelTree; } + void setEntityTree(EntityTree* modelTree) { _entityTree = modelTree; } + EntityTree* getEntityTree(EntityTree*) { return _entityTree; } public slots: /// adds a model with the specific properties - ModelItemID addModel(const ModelItemProperties& properties); + EntityItemID addEntity(const EntityItemProperties& properties); /// identify a recently created model to determine its true ID - ModelItemID identifyModel(ModelItemID modelID); + EntityItemID identifyEntity(EntityItemID entityID); /// 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 - ModelItemProperties getModelProperties(ModelItemID modelID); + EntityItemProperties getEntityProperties(EntityItemID entityID); - /// edits a model updating only the included properties, will return the identified ModelItemID in case of - /// successful edit, if the input modelID is for an unknown model this function will have no effect - ModelItemID editModel(ModelItemID modelID, const ModelItemProperties& properties); + /// 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 + EntityItemID editEntity(EntityItemID entityID, const EntityItemProperties& properties); /// deletes a model - void deleteModel(ModelItemID modelID); + void deleteEntity(EntityItemID entityID); /// finds the closest model to the center point, within the radius - /// will return a ModelItemID.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 - ModelItemID findClosestModel(const glm::vec3& center, float radius) const; + 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 - QVector findModels(const glm::vec3& center, float radius) const; + QVector findEntities(const glm::vec3& center, float radius) const; /// If the scripting context has visible voxels, this will determine a ray intersection, the results /// may be inaccurate if the engine is unable to access the visible voxels, in which case result.accurate /// will be false. - Q_INVOKABLE RayToModelIntersectionResult findRayIntersection(const PickRay& ray); + Q_INVOKABLE RayToEntityIntersectionResult findRayIntersection(const PickRay& ray); /// If the scripting context has visible voxels, this will determine a ray intersection, and will block in /// order to return an accurate result - Q_INVOKABLE RayToModelIntersectionResult findRayIntersectionBlocking(const PickRay& ray); + Q_INVOKABLE RayToEntityIntersectionResult findRayIntersectionBlocking(const PickRay& ray); signals: - void modelCollisionWithVoxel(const ModelItemID& modelID, const VoxelDetail& voxel, const CollisionInfo& collision); - void modelCollisionWithModel(const ModelItemID& idA, const ModelItemID& idB, const CollisionInfo& collision); + void modelCollisionWithVoxel(const EntityItemID& entityID, const VoxelDetail& voxel, const CollisionInfo& collision); + void modelCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const CollisionInfo& collision); private: - void queueModelMessage(PacketType packetType, ModelItemID modelID, const ModelItemProperties& 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 - RayToModelIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType); + RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType); uint32_t _nextCreatorTokenID; - ModelTree* _modelTree; + EntityTree* _entityTree; }; -#endif // hifi_ModelsScriptingInterface_h +#endif // hifi_EntityScriptingInterface_h diff --git a/libraries/models/src/EntityTree.cpp b/libraries/models/src/EntityTree.cpp index a4a77f0010..630b0503c2 100644 --- a/libraries/models/src/EntityTree.cpp +++ b/libraries/models/src/EntityTree.cpp @@ -1,5 +1,5 @@ // -// ModelTree.cpp +// EntityTree.cpp // libraries/models/src // // Created by Brad Hefta-Gaub on 12/4/13. @@ -9,74 +9,74 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "ModelTree.h" +#include "EntityTree.h" -ModelTree::ModelTree(bool shouldReaverage) : Octree(shouldReaverage) { +EntityTree::EntityTree(bool shouldReaverage) : Octree(shouldReaverage) { _rootElement = createNewElement(); } -ModelTreeElement* ModelTree::createNewElement(unsigned char * octalCode) { - ModelTreeElement* newElement = new ModelTreeElement(octalCode); +EntityTreeElement* EntityTree::createNewElement(unsigned char * octalCode) { + EntityTreeElement* newElement = new EntityTreeElement(octalCode); newElement->setTree(this); return newElement; } -void ModelTree::eraseAllOctreeElements() { +void EntityTree::eraseAllOctreeElements() { _modelToElementMap.clear(); Octree::eraseAllOctreeElements(); } -bool ModelTree::handlesEditPacketType(PacketType packetType) const { +bool EntityTree::handlesEditPacketType(PacketType packetType) const { // we handle these types of "edit" packets switch (packetType) { - case PacketTypeModelAddOrEdit: - case PacketTypeModelErase: + case PacketTypeEntityAddOrEdit: + case PacketTypeEntityErase: return true; default: return false; } } -class StoreModelOperator : public RecurseOctreeOperator { +class StoreEntityOperator : public RecurseOctreeOperator { public: - StoreModelOperator(ModelTree* tree, const ModelItem& searchModel); + StoreEntityOperator(EntityTree* tree, const EntityItem& searchEntity); virtual bool PreRecursion(OctreeElement* element); virtual bool PostRecursion(OctreeElement* element); virtual OctreeElement* PossiblyCreateChildAt(OctreeElement* element, int childIndex); private: - ModelTree* _tree; - const ModelItem& _newModel; - const ModelItem* _oldModel; - ModelTreeElement* _containingElement; + EntityTree* _tree; + const EntityItem& _newEntity; + const EntityItem* _oldEntity; + EntityTreeElement* _containingElement; bool _foundOld; bool _foundNew; quint64 _changeTime; - bool subTreeContainsOldModel(OctreeElement* element); - bool subTreeContainsNewModel(OctreeElement* element); + bool subTreeContainsOldEntity(OctreeElement* element); + bool subTreeContainsNewEntity(OctreeElement* element); }; -StoreModelOperator::StoreModelOperator(ModelTree* tree, const ModelItem& searchModel) : +StoreEntityOperator::StoreEntityOperator(EntityTree* tree, const EntityItem& searchEntity) : _tree(tree), - _newModel(searchModel), - _oldModel(NULL), + _newEntity(searchEntity), + _oldEntity(NULL), _containingElement(NULL), _foundOld(false), _foundNew(false), _changeTime(usecTimestampNow()) { // check our tree, to determine if this model is known - _containingElement = _tree->getContainingElement(searchModel.getModelItemID()); + _containingElement = _tree->getContainingElement(searchEntity.getEntityItemID()); if (_containingElement) { - _oldModel = _containingElement->getModelWithModelItemID(searchModel.getModelItemID()); - if (!_oldModel) { - //assert(_oldModel); - qDebug() << "that's UNEXPECTED, we got a _containingElement, but couldn't find the oldModel!"; + _oldEntity = _containingElement->getEntityWithEntityItemID(searchEntity.getEntityItemID()); + if (!_oldEntity) { + //assert(_oldEntity); + qDebug() << "that's UNEXPECTED, we got a _containingElement, but couldn't find the oldEntity!"; } // If this containing element would be the best fit for our new model, then just do the new // portion of the store pass, since the change path will be the same for both parts of the update - if (_containingElement->bestFitModelBounds(_newModel)) { + if (_containingElement->bestFitEntityBounds(_newEntity)) { _foundOld = true; } } else { @@ -87,28 +87,28 @@ StoreModelOperator::StoreModelOperator(ModelTree* tree, const ModelItem& searchM } // does this model tree element contain the old model -bool StoreModelOperator::subTreeContainsOldModel(OctreeElement* element) { - bool containsModel = false; +bool StoreEntityOperator::subTreeContainsOldEntity(OctreeElement* element) { + bool containsEntity = false; // If we don't have an old model, then we don't contain the model, otherwise // check the bounds - if (_oldModel) { + if (_oldEntity) { AACube elementCube = element->getAACube(); - AACube modelCube = _oldModel->getAACube(); - containsModel = elementCube.contains(modelCube); + AACube modelCube = _oldEntity->getAACube(); + containsEntity = elementCube.contains(modelCube); } - return containsModel; + return containsEntity; } -bool StoreModelOperator::subTreeContainsNewModel(OctreeElement* element) { +bool StoreEntityOperator::subTreeContainsNewEntity(OctreeElement* element) { AACube elementCube = element->getAACube(); - AACube modelCube = _newModel.getAACube(); + AACube modelCube = _newEntity.getAACube(); return elementCube.contains(modelCube); } -bool StoreModelOperator::PreRecursion(OctreeElement* element) { - ModelTreeElement* modelTreeElement = static_cast(element); +bool StoreEntityOperator::PreRecursion(OctreeElement* element) { + EntityTreeElement* modelTreeElement = static_cast(element); // In Pre-recursion, we're generally deciding whether or not we want to recurse this // path of the tree. For this operation, we want to recurse the branch of the tree if @@ -123,23 +123,23 @@ bool StoreModelOperator::PreRecursion(OctreeElement* element) { // If we haven't yet found the old model, and this subTreeContains our old // model, then we need to keep searching. - if (!_foundOld && subTreeContainsOldModel(element)) { + if (!_foundOld && subTreeContainsOldEntity(element)) { // If this is the element we're looking for, then ask it to remove the old model // and we can stop searching. if (modelTreeElement == _containingElement) { // If the containgElement IS NOT the best fit for the new model properties - // then we need to remove it, and the updateModel below will store it in the + // then we need to remove it, and the updateEntity below will store it in the // correct element. - if (!_containingElement->bestFitModelBounds(_newModel)) { - modelTreeElement->removeModelWithModelItemID(_newModel.getModelItemID()); + if (!_containingElement->bestFitEntityBounds(_newEntity)) { + modelTreeElement->removeEntityWithEntityItemID(_newEntity.getEntityItemID()); // If we haven't yet found the new location, then we need to // make sure to remove our model to element map, because for // now we're not in that map if (!_foundNew) { - _tree->setContainingElement(_newModel.getModelItemID(), NULL); + _tree->setContainingElement(_newEntity.getEntityItemID(), NULL); } } _foundOld = true; @@ -151,12 +151,12 @@ bool StoreModelOperator::PreRecursion(OctreeElement* element) { // If we haven't yet found the new model, and this subTreeContains our new // model, then we need to keep searching. - if (!_foundNew && subTreeContainsNewModel(element)) { + if (!_foundNew && subTreeContainsNewEntity(element)) { - // Note: updateModel() will only operate on correctly found models and/or add them + // Note: updateEntity() will only operate on correctly found models and/or add them // to the element if they SHOULD be stored there. - if (modelTreeElement->updateModel(_newModel)) { - //qDebug() << "StoreModelOperator::PreRecursion()... model was updated!"; + if (modelTreeElement->updateEntity(_newEntity)) { + //qDebug() << "StoreEntityOperator::PreRecursion()... model was updated!"; _foundNew = true; // NOTE: don't change the keepSearching here, if it came in here // false then we stay false, if it came in here true, then it @@ -171,7 +171,7 @@ bool StoreModelOperator::PreRecursion(OctreeElement* element) { return keepSearching; // if we haven't yet found it, keep looking } -bool StoreModelOperator::PostRecursion(OctreeElement* element) { +bool StoreEntityOperator::PostRecursion(OctreeElement* element) { // Post-recursion is the unwinding process. For this operation, while we // unwind we want to mark the path as being dirty if we changed it below. // We might have two paths, one for the old model and one for the new model. @@ -179,21 +179,21 @@ bool StoreModelOperator::PostRecursion(OctreeElement* element) { // As we unwind, if we're in either of these two paths, we mark our element // as dirty. - if ((_foundOld && subTreeContainsOldModel(element)) || - (_foundNew && subTreeContainsNewModel(element))) { + if ((_foundOld && subTreeContainsOldEntity(element)) || + (_foundNew && subTreeContainsNewEntity(element))) { element->markWithChangedTime(); } return keepSearching; // if we haven't yet found it, keep looking } -OctreeElement* StoreModelOperator::PossiblyCreateChildAt(OctreeElement* element, int childIndex) { +OctreeElement* StoreEntityOperator::PossiblyCreateChildAt(OctreeElement* element, int childIndex) { // If we're getting called, it's because there was no child element at this index while recursing. // We only care if this happens while still searching for the new model location. // Check to see if if (!_foundNew) { - int indexOfChildContainingNewModel = element->getMyChildContaining(_newModel.getAACube()); + int indexOfChildContainingNewEntity = element->getMyChildContaining(_newEntity.getAACube()); - if (childIndex == indexOfChildContainingNewModel) { + if (childIndex == indexOfChildContainingNewEntity) { return element->addChildAtIndex(childIndex); } } @@ -201,120 +201,120 @@ OctreeElement* StoreModelOperator::PossiblyCreateChildAt(OctreeElement* element, } -void ModelTree::storeModel(const ModelItem& model, const SharedNodePointer& senderNode) { +void EntityTree::storeEntity(const EntityItem& model, const SharedNodePointer& senderNode) { // NOTE: callers must lock the tree before using this method // First, look for the existing model in the tree.. - StoreModelOperator theOperator(this, model); + StoreEntityOperator theOperator(this, model); recurseTreeWithOperator(&theOperator); _isDirty = true; bool wantDebug = false; if (wantDebug) { - ModelTreeElement* containingElement = getContainingElement(model.getModelItemID()); - qDebug() << "ModelTree::storeModel().... after store... containingElement=" << containingElement; + EntityTreeElement* containingElement = getContainingElement(model.getEntityItemID()); + qDebug() << "EntityTree::storeEntity().... after store... containingElement=" << containingElement; } } -void ModelTree::updateModel(const ModelItemID& modelID, const ModelItemProperties& properties) { - ModelItem updateItem(modelID); +void EntityTree::updateEntity(const EntityItemID& modelID, const EntityItemProperties& properties) { + EntityItem updateItem(modelID); bool wantDebug = false; if (wantDebug) { - qDebug() << "ModelTree::updateModel(modelID, properties) line:" << __LINE__ << "updateItem:"; + qDebug() << "EntityTree::updateEntity(modelID, properties) line:" << __LINE__ << "updateItem:"; updateItem.debugDump(); } // since the properties might not be complete, they may only contain some values, // we need to first see if we already have the model in our tree, and make a copy of // its existing properties first - ModelTreeElement* containingElement = getContainingElement(modelID); + EntityTreeElement* containingElement = getContainingElement(modelID); if (wantDebug) { - qDebug() << "ModelTree::updateModel(modelID, properties) containingElement=" << containingElement; + qDebug() << "EntityTree::updateEntity(modelID, properties) containingElement=" << containingElement; } if (containingElement) { - const ModelItem* oldModel = containingElement->getModelWithModelItemID(modelID); - if (oldModel) { - ModelItemProperties oldProps = oldModel->getProperties(); + const EntityItem* oldEntity = containingElement->getEntityWithEntityItemID(modelID); + if (oldEntity) { + EntityItemProperties oldProps = oldEntity->getProperties(); if (wantDebug) { - qDebug() << "ModelTree::updateModel(modelID, properties) ********** COPY PROPERTIES FROM oldModel=" << oldModel << "*******************"; - qDebug() << "ModelTree::updateModel(modelID, properties) oldModel=" << oldModel; + qDebug() << "EntityTree::updateEntity(modelID, properties) ********** COPY PROPERTIES FROM oldEntity=" << oldEntity << "*******************"; + qDebug() << "EntityTree::updateEntity(modelID, properties) oldEntity=" << oldEntity; oldProps.debugDump(); - qDebug() << "ModelTree::updateModel(modelID, properties) line:" << __LINE__ << "about to call updateItem.setProperties(oldProps);"; + qDebug() << "EntityTree::updateEntity(modelID, properties) line:" << __LINE__ << "about to call updateItem.setProperties(oldProps);"; } updateItem.setProperties(oldProps, true); // force copy if (wantDebug) { - qDebug() << "ModelTree::updateModel(modelID, properties) line:" << __LINE__ << "updateItem:"; + qDebug() << "EntityTree::updateEntity(modelID, properties) line:" << __LINE__ << "updateItem:"; updateItem.debugDump(); } } else { if (wantDebug) { - qDebug() << "ModelTree::updateModel(modelID, properties) WAIT WHAT!!! COULDN'T FIND oldModel=" << oldModel; + qDebug() << "EntityTree::updateEntity(modelID, properties) WAIT WHAT!!! COULDN'T FIND oldEntity=" << oldEntity; } } } updateItem.setProperties(properties); if (wantDebug) { - qDebug() << "ModelTree::updateModel(modelID, properties) line:" << __LINE__ << "updateItem:"; + qDebug() << "EntityTree::updateEntity(modelID, properties) line:" << __LINE__ << "updateItem:"; updateItem.debugDump(); } - storeModel(updateItem); + storeEntity(updateItem); } -void ModelTree::addModel(const ModelItemID& modelID, const ModelItemProperties& properties) { - ModelItem updateItem(modelID, properties); - storeModel(updateItem); +void EntityTree::addEntity(const EntityItemID& modelID, const EntityItemProperties& properties) { + EntityItem updateItem(modelID, properties); + storeEntity(updateItem); } -class ModelToDeleteDetails { +class EntityToDeleteDetails { public: - const ModelItem* model; + const EntityItem* model; AACube cube; - ModelTreeElement* containingElement; + EntityTreeElement* containingElement; }; -inline uint qHash(const ModelToDeleteDetails& a, uint seed) { - return qHash(a.model->getModelItemID(), seed); +inline uint qHash(const EntityToDeleteDetails& a, uint seed) { + return qHash(a.model->getEntityItemID(), seed); } -inline bool operator==(const ModelToDeleteDetails& a, const ModelToDeleteDetails& b) { - return a.model->getModelItemID() == b.model->getModelItemID(); +inline bool operator==(const EntityToDeleteDetails& a, const EntityToDeleteDetails& b) { + return a.model->getEntityItemID() == b.model->getEntityItemID(); } -class DeleteModelOperator : public RecurseOctreeOperator { +class DeleteEntityOperator : public RecurseOctreeOperator { public: - DeleteModelOperator(ModelTree* tree); - DeleteModelOperator(ModelTree* tree, const ModelItemID& searchModelID); - void modelToDelete(const ModelItemID& searchModelID); + DeleteEntityOperator(EntityTree* tree); + DeleteEntityOperator(EntityTree* tree, const EntityItemID& searchEntityID); + void modelToDelete(const EntityItemID& searchEntityID); virtual bool PreRecursion(OctreeElement* element); virtual bool PostRecursion(OctreeElement* element); private: - ModelTree* _tree; - QSet _modelsToDelete; + EntityTree* _tree; + QSet _modelsToDelete; quint64 _changeTime; int _foundCount; int _lookingCount; - bool subTreeContainsSomeModelsToDelete(OctreeElement* element); + bool subTreeContainsSomeEntitysToDelete(OctreeElement* element); }; -DeleteModelOperator::DeleteModelOperator(ModelTree* tree, const ModelItemID& searchModelID) : +DeleteEntityOperator::DeleteEntityOperator(EntityTree* tree, const EntityItemID& searchEntityID) : _tree(tree), _changeTime(usecTimestampNow()), _foundCount(0), _lookingCount(0) { - modelToDelete(searchModelID); + modelToDelete(searchEntityID); } -DeleteModelOperator::DeleteModelOperator(ModelTree* tree) : +DeleteEntityOperator::DeleteEntityOperator(EntityTree* tree) : _tree(tree), _changeTime(usecTimestampNow()), _foundCount(0), @@ -322,16 +322,16 @@ DeleteModelOperator::DeleteModelOperator(ModelTree* tree) : { } -void DeleteModelOperator::modelToDelete(const ModelItemID& searchModelID) { +void DeleteEntityOperator::modelToDelete(const EntityItemID& searchEntityID) { // check our tree, to determine if this model is known - ModelToDeleteDetails details; - details.containingElement = _tree->getContainingElement(searchModelID); + EntityToDeleteDetails details; + details.containingElement = _tree->getContainingElement(searchEntityID); if (details.containingElement) { - details.model = details.containingElement->getModelWithModelItemID(searchModelID); + details.model = details.containingElement->getEntityWithEntityItemID(searchEntityID); if (!details.model) { //assert(false); - qDebug() << "that's UNEXPECTED, we got a _containingElement, but couldn't find the oldModel!"; + qDebug() << "that's UNEXPECTED, we got a _containingElement, but couldn't find the oldEntity!"; } else { details.cube = details.model->getAACube(); _modelsToDelete << details; @@ -342,25 +342,25 @@ void DeleteModelOperator::modelToDelete(const ModelItemID& searchModelID) { // does this model tree element contain the old model -bool DeleteModelOperator::subTreeContainsSomeModelsToDelete(OctreeElement* element) { - bool containsModel = false; +bool DeleteEntityOperator::subTreeContainsSomeEntitysToDelete(OctreeElement* element) { + bool containsEntity = false; // If we don't have an old model, then we don't contain the model, otherwise // check the bounds if (_modelsToDelete.size() > 0) { AACube elementCube = element->getAACube(); - foreach(const ModelToDeleteDetails& details, _modelsToDelete) { + foreach(const EntityToDeleteDetails& details, _modelsToDelete) { if (elementCube.contains(details.cube)) { - containsModel = true; + containsEntity = true; break; // if it contains at least one, we're good to go } } } - return containsModel; + return containsEntity; } -bool DeleteModelOperator::PreRecursion(OctreeElement* element) { - ModelTreeElement* modelTreeElement = static_cast(element); +bool DeleteEntityOperator::PreRecursion(OctreeElement* element) { + EntityTreeElement* modelTreeElement = static_cast(element); // In Pre-recursion, we're generally deciding whether or not we want to recurse this // path of the tree. For this operation, we want to recurse the branch of the tree if @@ -375,18 +375,18 @@ bool DeleteModelOperator::PreRecursion(OctreeElement* element) { // If we haven't yet found all the models, and this sub tree contains at least one of our // models, then we need to keep searching. - if ((_foundCount < _lookingCount) && subTreeContainsSomeModelsToDelete(element)) { + if ((_foundCount < _lookingCount) && subTreeContainsSomeEntitysToDelete(element)) { // check against each of our search models - foreach(const ModelToDeleteDetails& details, _modelsToDelete) { + foreach(const EntityToDeleteDetails& details, _modelsToDelete) { // If this is the element we're looking for, then ask it to remove the old model // and we can stop searching. if (modelTreeElement == details.containingElement) { // This is a good place to delete it!!! - ModelItemID modelItemID = details.model->getModelItemID(); - modelTreeElement->removeModelWithModelItemID(modelItemID); + EntityItemID modelItemID = details.model->getEntityItemID(); + modelTreeElement->removeEntityWithEntityItemID(modelItemID); _tree->setContainingElement(modelItemID, NULL); _foundCount++; } @@ -399,7 +399,7 @@ bool DeleteModelOperator::PreRecursion(OctreeElement* element) { return keepSearching; // if we haven't yet found it, keep looking } -bool DeleteModelOperator::PostRecursion(OctreeElement* element) { +bool DeleteEntityOperator::PostRecursion(OctreeElement* element) { // Post-recursion is the unwinding process. For this operation, while we // unwind we want to mark the path as being dirty if we changed it below. // We might have two paths, one for the old model and one for the new model. @@ -407,33 +407,33 @@ bool DeleteModelOperator::PostRecursion(OctreeElement* element) { // As we unwind, if we're in either of these two paths, we mark our element // as dirty. - if ((subTreeContainsSomeModelsToDelete(element))) { + if ((subTreeContainsSomeEntitysToDelete(element))) { element->markWithChangedTime(); } return keepSearching; // if we haven't yet found it, keep looking } -void ModelTree::deleteModel(const ModelItemID& modelID) { +void EntityTree::deleteEntity(const EntityItemID& modelID) { // NOTE: callers must lock the tree before using this method // First, look for the existing model in the tree.. - DeleteModelOperator theOperator(this, modelID); + DeleteEntityOperator theOperator(this, modelID); recurseTreeWithOperator(&theOperator); _isDirty = true; bool wantDebug = false; if (wantDebug) { - ModelTreeElement* containingElement = getContainingElement(modelID); - qDebug() << "ModelTree::storeModel().... after store... containingElement=" << containingElement; + EntityTreeElement* containingElement = getContainingElement(modelID); + qDebug() << "EntityTree::storeEntity().... after store... containingElement=" << containingElement; } } -void ModelTree::deleteModels(QSet modelIDs) { +void EntityTree::deleteEntitys(QSet modelIDs) { // NOTE: callers must lock the tree before using this method - DeleteModelOperator theOperator(this); - foreach(const ModelItemID& modelID, modelIDs) { + DeleteEntityOperator theOperator(this); + foreach(const EntityItemID& modelID, modelIDs) { // First, look for the existing model in the tree.. theOperator.modelToDelete(modelID); } @@ -443,9 +443,9 @@ void ModelTree::deleteModels(QSet modelIDs) { bool wantDebug = false; if (wantDebug) { - foreach(const ModelItemID& modelID, modelIDs) { - ModelTreeElement* containingElement = getContainingElement(modelID); - qDebug() << "ModelTree::storeModel().... after store... containingElement=" << containingElement; + foreach(const EntityItemID& modelID, modelIDs) { + EntityTreeElement* containingElement = getContainingElement(modelID); + qDebug() << "EntityTree::storeEntity().... after store... containingElement=" << containingElement; } } } @@ -454,29 +454,29 @@ void ModelTree::deleteModels(QSet modelIDs) { // in the event that this tree is also viewing the scene, then we need to also // search the tree to make sure we don't have a duplicate model from the viewing // operation. -bool ModelTree::findAndUpdateModelItemIDOperation(OctreeElement* element, void* extraData) { +bool EntityTree::findAndUpdateEntityItemIDOperation(OctreeElement* element, void* extraData) { bool keepSearching = true; - FindAndUpdateModelItemIDArgs* args = static_cast(extraData); - ModelTreeElement* modelTreeElement = static_cast(element); + FindAndUpdateEntityItemIDArgs* args = static_cast(extraData); + EntityTreeElement* modelTreeElement = static_cast(element); - // Note: updateModelItemID() will only operate on correctly found models - modelTreeElement->updateModelItemID(args); + // Note: updateEntityItemID() will only operate on correctly found models + modelTreeElement->updateEntityItemID(args); - // if we've found and replaced both the creatorTokenID and the viewedModel, then we + // if we've found and replaced both the creatorTokenID and the viewedEntity, then we // can stop looking, otherwise we will keep looking - if (args->creatorTokenFound && args->viewedModelFound) { + if (args->creatorTokenFound && args->viewedEntityFound) { keepSearching = false; } return keepSearching; } -void ModelTree::handleAddModelResponse(const QByteArray& packet) { +void EntityTree::handleAddEntityResponse(const QByteArray& packet) { const bool wantDebug = false; if (wantDebug) { - qDebug() << "ModelTree::handleAddModelResponse()..."; + qDebug() << "EntityTree::handleAddEntityResponse()..."; } int numBytesPacketHeader = numBytesForPacketHeader(packet); @@ -497,12 +497,12 @@ void ModelTree::handleAddModelResponse(const QByteArray& packet) { } // update models in our tree - bool assumeModelFound = !getIsViewing(); // if we're not a viewing tree, then we don't have to find the actual model - FindAndUpdateModelItemIDArgs args = { + bool assumeEntityFound = !getIsViewing(); // if we're not a viewing tree, then we don't have to find the actual model + FindAndUpdateEntityItemIDArgs args = { modelID, creatorTokenID, false, - assumeModelFound, + assumeEntityFound, getIsViewing() }; @@ -512,7 +512,7 @@ void ModelTree::handleAddModelResponse(const QByteArray& packet) { } lockForWrite(); // TODO: Switch this to use list of known model IDs.... - recurseTreeWithOperation(findAndUpdateModelItemIDOperation, &args); + recurseTreeWithOperation(findAndUpdateEntityItemIDOperation, &args); unlock(); } @@ -522,14 +522,14 @@ public: glm::vec3 position; float targetRadius; bool found; - const ModelItem* closestModel; - float closestModelDistance; + const EntityItem* closestEntity; + float closestEntityDistance; }; -bool ModelTree::findNearPointOperation(OctreeElement* element, void* extraData) { +bool EntityTree::findNearPointOperation(OctreeElement* element, void* extraData) { FindNearPointArgs* args = static_cast(extraData); - ModelTreeElement* modelTreeElement = static_cast(element); + EntityTreeElement* modelTreeElement = static_cast(element); glm::vec3 penetration; bool sphereIntersection = modelTreeElement->getAACube().findSpherePenetration(args->position, @@ -537,19 +537,19 @@ bool ModelTree::findNearPointOperation(OctreeElement* element, void* extraData) // If this modelTreeElement contains the point, then search it... if (sphereIntersection) { - const ModelItem* thisClosestModel = modelTreeElement->getClosestModel(args->position); + const EntityItem* thisClosestEntity = modelTreeElement->getClosestEntity(args->position); // we may have gotten NULL back, meaning no model was available - if (thisClosestModel) { - glm::vec3 modelPosition = thisClosestModel->getPosition(); - float distanceFromPointToModel = glm::distance(modelPosition, args->position); + if (thisClosestEntity) { + glm::vec3 modelPosition = thisClosestEntity->getPosition(); + float distanceFromPointToEntity = glm::distance(modelPosition, args->position); // If we're within our target radius - if (distanceFromPointToModel <= args->targetRadius) { + if (distanceFromPointToEntity <= args->targetRadius) { // we are closer than anything else we've found - if (distanceFromPointToModel < args->closestModelDistance) { - args->closestModel = thisClosestModel; - args->closestModelDistance = distanceFromPointToModel; + if (distanceFromPointToEntity < args->closestEntityDistance) { + args->closestEntity = thisClosestEntity; + args->closestEntityDistance = distanceFromPointToEntity; args->found = true; } } @@ -563,24 +563,24 @@ bool ModelTree::findNearPointOperation(OctreeElement* element, void* extraData) return false; } -const ModelItem* ModelTree::findClosestModel(glm::vec3 position, float targetRadius) { +const EntityItem* EntityTree::findClosestEntity(glm::vec3 position, float targetRadius) { FindNearPointArgs args = { position, targetRadius, false, NULL, FLT_MAX }; lockForRead(); // NOTE: This should use recursion, since this is a spatial operation recurseTreeWithOperation(findNearPointOperation, &args); unlock(); - return args.closestModel; + return args.closestEntity; } class FindAllNearPointArgs { public: glm::vec3 position; float targetRadius; - QVector models; + QVector models; }; -bool ModelTree::findInSphereOperation(OctreeElement* element, void* extraData) { +bool EntityTree::findInSphereOperation(OctreeElement* element, void* extraData) { FindAllNearPointArgs* args = static_cast(extraData); glm::vec3 penetration; bool sphereIntersection = element->getAACube().findSpherePenetration(args->position, @@ -588,8 +588,8 @@ bool ModelTree::findInSphereOperation(OctreeElement* element, void* extraData) { // If this element contains the point, then search it... if (sphereIntersection) { - ModelTreeElement* modelTreeElement = static_cast(element); - modelTreeElement->getModels(args->position, args->targetRadius, args->models); + EntityTreeElement* modelTreeElement = static_cast(element); + modelTreeElement->getEntitys(args->position, args->targetRadius, args->models); return true; // keep searching in case children have closer models } @@ -597,84 +597,84 @@ bool ModelTree::findInSphereOperation(OctreeElement* element, void* extraData) { return false; } -void ModelTree::findModels(const glm::vec3& center, float radius, QVector& foundModels) { +void EntityTree::findEntities(const glm::vec3& center, float radius, QVector& foundEntitys) { FindAllNearPointArgs args = { center, radius }; lockForRead(); // NOTE: This should use recursion, since this is a spatial operation recurseTreeWithOperation(findInSphereOperation, &args); unlock(); // swap the two lists of model pointers instead of copy - foundModels.swap(args.models); + foundEntitys.swap(args.models); } -class FindModelsInCubeArgs { +class FindEntitysInCubeArgs { public: - FindModelsInCubeArgs(const AACube& cube) - : _cube(cube), _foundModels() { + FindEntitysInCubeArgs(const AACube& cube) + : _cube(cube), _foundEntitys() { } AACube _cube; - QVector _foundModels; + QVector _foundEntitys; }; -bool ModelTree::findInCubeOperation(OctreeElement* element, void* extraData) { - FindModelsInCubeArgs* args = static_cast< FindModelsInCubeArgs*>(extraData); +bool EntityTree::findInCubeOperation(OctreeElement* element, void* extraData) { + FindEntitysInCubeArgs* args = static_cast< FindEntitysInCubeArgs*>(extraData); const AACube& elementCube = element->getAACube(); if (elementCube.touches(args->_cube)) { - ModelTreeElement* modelTreeElement = static_cast(element); - modelTreeElement->getModels(args->_cube, args->_foundModels); + EntityTreeElement* modelTreeElement = static_cast(element); + modelTreeElement->getEntitys(args->_cube, args->_foundEntitys); return true; } return false; } -void ModelTree::findModels(const AACube& cube, QVector foundModels) { - FindModelsInCubeArgs args(cube); +void EntityTree::findEntities(const AACube& cube, QVector foundEntitys) { + FindEntitysInCubeArgs args(cube); lockForRead(); // NOTE: This should use recursion, since this is a spatial operation recurseTreeWithOperation(findInCubeOperation, &args); unlock(); // swap the two lists of model pointers instead of copy - foundModels.swap(args._foundModels); + foundEntitys.swap(args._foundEntitys); } -const ModelItem* ModelTree::findModelByID(uint32_t id, bool alreadyLocked) const { - ModelItemID modelID(id); +const EntityItem* EntityTree::findEntityByID(uint32_t id, bool alreadyLocked) const { + EntityItemID modelID(id); bool wantDebug = false; if (wantDebug) { - qDebug() << "ModelTree::findModelByID()..."; + qDebug() << "EntityTree::findEntityByID()..."; qDebug() << " id=" << id; qDebug() << " modelID=" << modelID; qDebug() << "_modelToElementMap=" << _modelToElementMap; } - return findModelByModelItemID(modelID); + return findEntityByEntityItemID(modelID); } -const ModelItem* ModelTree::findModelByModelItemID(const ModelItemID& modelID) const { - const ModelItem* foundModel = NULL; - ModelTreeElement* containingElement = getContainingElement(modelID); +const EntityItem* EntityTree::findEntityByEntityItemID(const EntityItemID& modelID) const { + const EntityItem* foundEntity = NULL; + EntityTreeElement* containingElement = getContainingElement(modelID); if (containingElement) { - foundModel = containingElement->getModelWithModelItemID(modelID); + foundEntity = containingElement->getEntityWithEntityItemID(modelID); } - return foundModel; + return foundEntity; } -int ModelTree::processEditPacketData(PacketType packetType, const unsigned char* packetData, int packetLength, +int EntityTree::processEditPacketData(PacketType packetType, const unsigned char* packetData, int packetLength, const unsigned char* editData, int maxLength, const SharedNodePointer& senderNode) { int processedBytes = 0; // we handle these types of "edit" packets switch (packetType) { - case PacketTypeModelAddOrEdit: { + case PacketTypeEntityAddOrEdit: { bool isValid; - ModelItem newModel = ModelItem::fromEditPacket(editData, maxLength, processedBytes, this, isValid); + EntityItem newEntity = EntityItem::fromEditPacket(editData, maxLength, processedBytes, this, isValid); if (isValid) { - storeModel(newModel, senderNode); - if (newModel.isNewlyCreated()) { - notifyNewlyCreatedModel(newModel, senderNode); + storeEntity(newEntity, senderNode); + if (newEntity.isNewlyCreated()) { + notifyNewlyCreatedEntity(newEntity, senderNode); } } } break; @@ -687,21 +687,21 @@ int ModelTree::processEditPacketData(PacketType packetType, const unsigned char* return processedBytes; } -void ModelTree::notifyNewlyCreatedModel(const ModelItem& newModel, const SharedNodePointer& senderNode) { +void EntityTree::notifyNewlyCreatedEntity(const EntityItem& newEntity, const SharedNodePointer& senderNode) { _newlyCreatedHooksLock.lockForRead(); for (size_t i = 0; i < _newlyCreatedHooks.size(); i++) { - _newlyCreatedHooks[i]->modelCreated(newModel, senderNode); + _newlyCreatedHooks[i]->modelCreated(newEntity, senderNode); } _newlyCreatedHooksLock.unlock(); } -void ModelTree::addNewlyCreatedHook(NewlyCreatedModelHook* hook) { +void EntityTree::addNewlyCreatedHook(NewlyCreatedEntityHook* hook) { _newlyCreatedHooksLock.lockForWrite(); _newlyCreatedHooks.push_back(hook); _newlyCreatedHooksLock.unlock(); } -void ModelTree::removeNewlyCreatedHook(NewlyCreatedModelHook* hook) { +void EntityTree::removeNewlyCreatedHook(NewlyCreatedEntityHook* hook) { _newlyCreatedHooksLock.lockForWrite(); for (size_t i = 0; i < _newlyCreatedHooks.size(); i++) { if (_newlyCreatedHooks[i] == hook) { @@ -713,49 +713,49 @@ void ModelTree::removeNewlyCreatedHook(NewlyCreatedModelHook* hook) { } -bool ModelTree::updateOperation(OctreeElement* element, void* extraData) { - ModelTreeUpdateArgs* args = static_cast(extraData); - ModelTreeElement* modelTreeElement = static_cast(element); +bool EntityTree::updateOperation(OctreeElement* element, void* extraData) { + EntityTreeUpdateArgs* args = static_cast(extraData); + EntityTreeElement* modelTreeElement = static_cast(element); modelTreeElement->update(*args); return true; } -bool ModelTree::pruneOperation(OctreeElement* element, void* extraData) { - ModelTreeElement* modelTreeElement = static_cast(element); +bool EntityTree::pruneOperation(OctreeElement* element, void* extraData) { + EntityTreeElement* modelTreeElement = static_cast(element); for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { - ModelTreeElement* childAt = modelTreeElement->getChildAtIndex(i); - if (childAt && childAt->isLeaf() && !childAt->hasModels()) { + EntityTreeElement* childAt = modelTreeElement->getChildAtIndex(i); + if (childAt && childAt->isLeaf() && !childAt->hasEntities()) { modelTreeElement->deleteChildAtIndex(i); } } return true; } -void ModelTree::update() { +void EntityTree::update() { lockForWrite(); _isDirty = true; // TODO: could we manage this by iterating the known models map/hash? Would that be faster? - ModelTreeUpdateArgs args; + EntityTreeUpdateArgs args; recurseTreeWithOperation(updateOperation, &args); // now add back any of the particles that moved elements.... - int movingModels = args._movingModels.size(); + int movingEntitys = args._movingEntitys.size(); - for (int i = 0; i < movingModels; i++) { - bool shouldDie = args._movingModels[i].getShouldDie(); + for (int i = 0; i < movingEntitys; i++) { + bool shouldDie = args._movingEntitys[i].getShouldDie(); // if the particle is still inside our total bounds, then re-add it AACube treeBounds = getRoot()->getAACube(); - if (!shouldDie && treeBounds.contains(args._movingModels[i].getPosition())) { - storeModel(args._movingModels[i]); + if (!shouldDie && treeBounds.contains(args._movingEntitys[i].getPosition())) { + storeEntity(args._movingEntitys[i]); } else { - uint32_t modelItemID = args._movingModels[i].getID(); + uint32_t modelItemID = args._movingEntitys[i].getID(); quint64 deletedAt = usecTimestampNow(); - _recentlyDeletedModelsLock.lockForWrite(); - _recentlyDeletedModelItemIDs.insert(deletedAt, modelItemID); - _recentlyDeletedModelsLock.unlock(); + _recentlyDeletedEntitysLock.lockForWrite(); + _recentlyDeletedEntityItemIDs.insert(deletedAt, modelItemID); + _recentlyDeletedEntitysLock.unlock(); } } @@ -765,13 +765,13 @@ void ModelTree::update() { } -bool ModelTree::hasModelsDeletedSince(quint64 sinceTime) { +bool EntityTree::hasEntitysDeletedSince(quint64 sinceTime) { // we can probably leverage the ordered nature of QMultiMap to do this quickly... bool hasSomethingNewer = false; - _recentlyDeletedModelsLock.lockForRead(); - QMultiMap::const_iterator iterator = _recentlyDeletedModelItemIDs.constBegin(); - while (iterator != _recentlyDeletedModelItemIDs.constEnd()) { + _recentlyDeletedEntitysLock.lockForRead(); + QMultiMap::const_iterator iterator = _recentlyDeletedEntityItemIDs.constBegin(); + while (iterator != _recentlyDeletedEntityItemIDs.constEnd()) { //qDebug() << "considering... time/key:" << iterator.key(); if (iterator.key() > sinceTime) { //qDebug() << "YES newer... time/key:" << iterator.key(); @@ -779,18 +779,18 @@ bool ModelTree::hasModelsDeletedSince(quint64 sinceTime) { } ++iterator; } - _recentlyDeletedModelsLock.unlock(); + _recentlyDeletedEntitysLock.unlock(); return hasSomethingNewer; } // sinceTime is an in/out parameter - it will be side effected with the last time sent out -bool ModelTree::encodeModelsDeletedSince(OCTREE_PACKET_SEQUENCE sequenceNumber, quint64& sinceTime, unsigned char* outputBuffer, +bool EntityTree::encodeEntitysDeletedSince(OCTREE_PACKET_SEQUENCE sequenceNumber, quint64& sinceTime, unsigned char* outputBuffer, size_t maxLength, size_t& outputLength) { bool hasMoreToSend = true; unsigned char* copyAt = outputBuffer; - size_t numBytesPacketHeader = populatePacketHeader(reinterpret_cast(outputBuffer), PacketTypeModelErase); + size_t numBytesPacketHeader = populatePacketHeader(reinterpret_cast(outputBuffer), PacketTypeEntityErase); copyAt += numBytesPacketHeader; outputLength = numBytesPacketHeader; @@ -822,10 +822,10 @@ bool ModelTree::encodeModelsDeletedSince(OCTREE_PACKET_SEQUENCE sequenceNumber, // we keep a multi map of model IDs to timestamps, we only want to include the model IDs that have been // deleted since we last sent to this node - _recentlyDeletedModelsLock.lockForRead(); - QMultiMap::const_iterator iterator = _recentlyDeletedModelItemIDs.constBegin(); - while (iterator != _recentlyDeletedModelItemIDs.constEnd()) { - QList values = _recentlyDeletedModelItemIDs.values(iterator.key()); + _recentlyDeletedEntitysLock.lockForRead(); + QMultiMap::const_iterator iterator = _recentlyDeletedEntityItemIDs.constBegin(); + while (iterator != _recentlyDeletedEntityItemIDs.constEnd()) { + QList values = _recentlyDeletedEntityItemIDs.values(iterator.key()); for (int valueItem = 0; valueItem < values.size(); ++valueItem) { // if the timestamp is more recent then out last sent time, include it @@ -854,10 +854,10 @@ bool ModelTree::encodeModelsDeletedSince(OCTREE_PACKET_SEQUENCE sequenceNumber, } // if we got to the end, then we're done sending - if (iterator == _recentlyDeletedModelItemIDs.constEnd()) { + if (iterator == _recentlyDeletedEntityItemIDs.constEnd()) { hasMoreToSend = false; } - _recentlyDeletedModelsLock.unlock(); + _recentlyDeletedEntitysLock.unlock(); // replace the correct count for ids included memcpy(numberOfIDsAt, &numberOfIds, sizeof(numberOfIds)); @@ -866,15 +866,15 @@ bool ModelTree::encodeModelsDeletedSince(OCTREE_PACKET_SEQUENCE sequenceNumber, // called by the server when it knows all nodes have been sent deleted packets -void ModelTree::forgetModelsDeletedBefore(quint64 sinceTime) { - //qDebug() << "forgetModelsDeletedBefore()"; +void EntityTree::forgetEntitysDeletedBefore(quint64 sinceTime) { + //qDebug() << "forgetEntitysDeletedBefore()"; QSet keysToRemove; - _recentlyDeletedModelsLock.lockForWrite(); - QMultiMap::iterator iterator = _recentlyDeletedModelItemIDs.begin(); + _recentlyDeletedEntitysLock.lockForWrite(); + QMultiMap::iterator iterator = _recentlyDeletedEntityItemIDs.begin(); // First find all the keys in the map that are older and need to be deleted - while (iterator != _recentlyDeletedModelItemIDs.end()) { + while (iterator != _recentlyDeletedEntityItemIDs.end()) { if (iterator.key() <= sinceTime) { keysToRemove << iterator.key(); } @@ -883,15 +883,15 @@ void ModelTree::forgetModelsDeletedBefore(quint64 sinceTime) { // Now run through the keysToRemove and remove them foreach (quint64 value, keysToRemove) { - //qDebug() << "removing the key, _recentlyDeletedModelItemIDs.remove(value); time/key:" << value; - _recentlyDeletedModelItemIDs.remove(value); + //qDebug() << "removing the key, _recentlyDeletedEntityItemIDs.remove(value); time/key:" << value; + _recentlyDeletedEntityItemIDs.remove(value); } - _recentlyDeletedModelsLock.unlock(); + _recentlyDeletedEntitysLock.unlock(); } -void ModelTree::processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode) { +void EntityTree::processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode) { const unsigned char* packetData = (const unsigned char*)dataByteArray.constData(); const unsigned char* dataAt = packetData; size_t packetLength = dataByteArray.size(); @@ -910,7 +910,7 @@ void ModelTree::processEraseMessage(const QByteArray& dataByteArray, const Share processedBytes += sizeof(numberOfIds); if (numberOfIds > 0) { - QSet modelItemIDsToDelete; + QSet modelItemIDsToDelete; for (size_t i = 0; i < numberOfIds; i++) { if (processedBytes + sizeof(uint32_t) > packetLength) { @@ -922,15 +922,15 @@ void ModelTree::processEraseMessage(const QByteArray& dataByteArray, const Share dataAt += sizeof(modelID); processedBytes += sizeof(modelID); - ModelItemID modelItemID(modelID); + EntityItemID modelItemID(modelID); modelItemIDsToDelete << modelItemID; } - deleteModels(modelItemIDsToDelete); + deleteEntitys(modelItemIDsToDelete); } } -ModelTreeElement* ModelTree::getContainingElement(const ModelItemID& modelItemID) const { +EntityTreeElement* EntityTree::getContainingElement(const EntityItemID& modelItemID) const { //qDebug() << "_modelToElementMap=" << _modelToElementMap; // TODO: do we need to make this thread safe? Or is it acceptable as is @@ -940,7 +940,7 @@ ModelTreeElement* ModelTree::getContainingElement(const ModelItemID& modelItemID return NULL; } -void ModelTree::setContainingElement(const ModelItemID& modelItemID, ModelTreeElement* element) { +void EntityTree::setContainingElement(const EntityItemID& modelItemID, EntityTreeElement* element) { // TODO: do we need to make this thread safe? Or is it acceptable as is if (element) { _modelToElementMap[modelItemID] = element; @@ -952,8 +952,8 @@ void ModelTree::setContainingElement(const ModelItemID& modelItemID, ModelTreeEl //qDebug() << "AFTER _modelToElementMap=" << _modelToElementMap; } -void ModelTree::debugDumpMap() { - QHashIterator i(_modelToElementMap); +void EntityTree::debugDumpMap() { + QHashIterator i(_modelToElementMap); while (i.hasNext()) { i.next(); qDebug() << i.key() << ": " << i.value(); diff --git a/libraries/models/src/EntityTree.h b/libraries/models/src/EntityTree.h index 5306da9efc..afce86aac7 100644 --- a/libraries/models/src/EntityTree.h +++ b/libraries/models/src/EntityTree.h @@ -1,5 +1,5 @@ // -// ModelTree.h +// EntityTree.h // libraries/models/src // // Created by Brad Hefta-Gaub on 12/4/13. @@ -9,39 +9,39 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_ModelTree_h -#define hifi_ModelTree_h +#ifndef hifi_EntityTree_h +#define hifi_EntityTree_h #include -#include "ModelTreeElement.h" +#include "EntityTreeElement.h" -class NewlyCreatedModelHook { +class NewlyCreatedEntityHook { public: - virtual void modelCreated(const ModelItem& newModel, const SharedNodePointer& senderNode) = 0; + virtual void modelCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode) = 0; }; -class ModelItemFBXService { +class EntityItemFBXService { public: - virtual const FBXGeometry* getGeometryForModel(const ModelItem& modelItem) = 0; + virtual const FBXGeometry* getGeometryForEntity(const EntityItem& modelItem) = 0; }; -class ModelTree : public Octree { +class EntityTree : public Octree { Q_OBJECT public: - ModelTree(bool shouldReaverage = false); + EntityTree(bool shouldReaverage = false); /// Implements our type specific root element factory - virtual ModelTreeElement* createNewElement(unsigned char * octalCode = NULL); + virtual EntityTreeElement* createNewElement(unsigned char * octalCode = NULL); /// Type safe version of getRoot() - ModelTreeElement* getRoot() { return static_cast(_rootElement); } + EntityTreeElement* getRoot() { return static_cast(_rootElement); } virtual void eraseAllOctreeElements(); // These methods will allow the OctreeServer to send your tree inbound edit packets of your // own definition. Implement these to allow your octree based server to support editing virtual bool getWantSVOfileVersions() const { return true; } - virtual PacketType expectedDataPacketType() const { return PacketTypeModelData; } + virtual PacketType expectedDataPacketType() const { return PacketTypeEntityData; } virtual bool canProcessVersion(PacketVersion thisVersion) const { return true; } // we support all versions virtual bool handlesEditPacketType(PacketType packetType) const; virtual int processEditPacketData(PacketType packetType, const unsigned char* packetData, int packetLength, @@ -50,48 +50,48 @@ public: virtual bool rootElementHasData() const { return true; } virtual void update(); - void OLD__storeModel(const ModelItem& model, const SharedNodePointer& senderNode = SharedNodePointer()); - void storeModel(const ModelItem& model, const SharedNodePointer& senderNode = SharedNodePointer()); - void updateModel(const ModelItemID& modelID, const ModelItemProperties& properties); - void addModel(const ModelItemID& modelID, const ModelItemProperties& properties); - void deleteModel(const ModelItemID& modelID); - void deleteModels(QSet modelIDs); - const ModelItem* findClosestModel(glm::vec3 position, float targetRadius); - const ModelItem* findModelByID(uint32_t id, bool alreadyLocked = false) const; - const ModelItem* findModelByModelItemID(const ModelItemID& modelID) const; + void OLD__storeEntity(const EntityItem& model, const SharedNodePointer& senderNode = SharedNodePointer()); + void storeEntity(const EntityItem& model, const SharedNodePointer& senderNode = SharedNodePointer()); + void updateEntity(const EntityItemID& modelID, const EntityItemProperties& properties); + void addEntity(const EntityItemID& modelID, const EntityItemProperties& properties); + void deleteEntity(const EntityItemID& modelID); + void deleteEntitys(QSet modelIDs); + const EntityItem* findClosestEntity(glm::vec3 position, float targetRadius); + const EntityItem* findEntityByID(uint32_t id, bool alreadyLocked = false) const; + const EntityItem* findEntityByEntityItemID(const EntityItemID& modelID) const; /// finds all models that touch a sphere /// \param center the center of the sphere /// \param radius the radius of the sphere - /// \param foundModels[out] vector of const ModelItem* - /// \remark Side effect: any initial contents in foundModels will be lost - void findModels(const glm::vec3& center, float radius, QVector& foundModels); + /// \param foundEntitys[out] vector of const EntityItem* + /// \remark Side effect: any initial contents in foundEntitys will be lost + void findEntities(const glm::vec3& center, float radius, QVector& foundEntitys); /// finds all models that touch a cube /// \param cube the query cube - /// \param foundModels[out] vector of non-const ModelItem* + /// \param foundEntitys[out] vector of non-const EntityItem* /// \remark Side effect: any initial contents in models will be lost - void findModels(const AACube& cube, QVector foundModels); + void findEntities(const AACube& cube, QVector foundEntitys); - void addNewlyCreatedHook(NewlyCreatedModelHook* hook); - void removeNewlyCreatedHook(NewlyCreatedModelHook* hook); + void addNewlyCreatedHook(NewlyCreatedEntityHook* hook); + void removeNewlyCreatedHook(NewlyCreatedEntityHook* hook); - bool hasAnyDeletedModels() const { return _recentlyDeletedModelItemIDs.size() > 0; } - bool hasModelsDeletedSince(quint64 sinceTime); - bool encodeModelsDeletedSince(OCTREE_PACKET_SEQUENCE sequenceNumber, quint64& sinceTime, + bool hasAnyDeletedEntitys() const { return _recentlyDeletedEntityItemIDs.size() > 0; } + bool hasEntitysDeletedSince(quint64 sinceTime); + bool encodeEntitysDeletedSince(OCTREE_PACKET_SEQUENCE sequenceNumber, quint64& sinceTime, unsigned char* packetData, size_t maxLength, size_t& outputLength); - void forgetModelsDeletedBefore(quint64 sinceTime); + void forgetEntitysDeletedBefore(quint64 sinceTime); void processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode); - void handleAddModelResponse(const QByteArray& packet); + void handleAddEntityResponse(const QByteArray& packet); - void setFBXService(ModelItemFBXService* service) { _fbxService = service; } - const FBXGeometry* getGeometryForModel(const ModelItem& modelItem) { - return _fbxService ? _fbxService->getGeometryForModel(modelItem) : NULL; + void setFBXService(EntityItemFBXService* service) { _fbxService = service; } + const FBXGeometry* getGeometryForEntity(const EntityItem& modelItem) { + return _fbxService ? _fbxService->getGeometryForEntity(modelItem) : NULL; } - ModelTreeElement* getContainingElement(const ModelItemID& modelItemID) const; - void setContainingElement(const ModelItemID& modelItemID, ModelTreeElement* element); + EntityTreeElement* getContainingElement(const EntityItemID& modelItemID) const; + void setContainingElement(const EntityItemID& modelItemID, EntityTreeElement* element); void debugDumpMap(); private: @@ -104,19 +104,19 @@ private: static bool pruneOperation(OctreeElement* element, void* extraData); static bool findByIDOperation(OctreeElement* element, void* extraData); static bool findAndDeleteOperation(OctreeElement* element, void* extraData); - static bool findAndUpdateModelItemIDOperation(OctreeElement* element, void* extraData); + static bool findAndUpdateEntityItemIDOperation(OctreeElement* element, void* extraData); static bool findInCubeOperation(OctreeElement* element, void* extraData); - void notifyNewlyCreatedModel(const ModelItem& newModel, const SharedNodePointer& senderNode); + void notifyNewlyCreatedEntity(const EntityItem& newEntity, const SharedNodePointer& senderNode); QReadWriteLock _newlyCreatedHooksLock; - QVector _newlyCreatedHooks; + QVector _newlyCreatedHooks; - QReadWriteLock _recentlyDeletedModelsLock; - QMultiMap _recentlyDeletedModelItemIDs; - ModelItemFBXService* _fbxService; + QReadWriteLock _recentlyDeletedEntitysLock; + QMultiMap _recentlyDeletedEntityItemIDs; + EntityItemFBXService* _fbxService; - QHash _modelToElementMap; + QHash _modelToElementMap; }; -#endif // hifi_ModelTree_h +#endif // hifi_EntityTree_h diff --git a/libraries/models/src/EntityTreeElement.cpp b/libraries/models/src/EntityTreeElement.cpp index 639c4980e0..c42b7143eb 100644 --- a/libraries/models/src/EntityTreeElement.cpp +++ b/libraries/models/src/EntityTreeElement.cpp @@ -1,5 +1,5 @@ // -// ModelTreeElement.cpp +// EntityTreeElement.cpp // libraries/models/src // // Created by Brad Hefta-Gaub on 12/4/13. @@ -14,38 +14,38 @@ #include #include -#include "ModelTree.h" -#include "ModelTreeElement.h" +#include "EntityTree.h" +#include "EntityTreeElement.h" -ModelTreeElement::ModelTreeElement(unsigned char* octalCode) : OctreeElement(), _modelItems(NULL) { +EntityTreeElement::EntityTreeElement(unsigned char* octalCode) : OctreeElement(), _entityItems(NULL) { init(octalCode); }; -ModelTreeElement::~ModelTreeElement() { - //qDebug() << "ModelTreeElement::~ModelTreeElement() this=" << this; - _voxelMemoryUsage -= sizeof(ModelTreeElement); - delete _modelItems; - _modelItems = NULL; +EntityTreeElement::~EntityTreeElement() { + //qDebug() << "EntityTreeElement::~EntityTreeElement() this=" << this; + _voxelMemoryUsage -= sizeof(EntityTreeElement); + delete _entityItems; + _entityItems = NULL; } // This will be called primarily on addChildAt(), which means we're adding a child of our // own type to our own tree. This means we should initialize that child with any tree and type // specific settings that our children must have. One example is out VoxelSystem, which // we know must match ours. -OctreeElement* ModelTreeElement::createNewElement(unsigned char* octalCode) { - ModelTreeElement* newChild = new ModelTreeElement(octalCode); +OctreeElement* EntityTreeElement::createNewElement(unsigned char* octalCode) { + EntityTreeElement* newChild = new EntityTreeElement(octalCode); newChild->setTree(_myTree); return newChild; } -void ModelTreeElement::init(unsigned char* octalCode) { +void EntityTreeElement::init(unsigned char* octalCode) { OctreeElement::init(octalCode); - _modelItems = new QList; - _voxelMemoryUsage += sizeof(ModelTreeElement); + _entityItems = new QList; + _voxelMemoryUsage += sizeof(EntityTreeElement); } -ModelTreeElement* ModelTreeElement::addChildAtIndex(int index) { - ModelTreeElement* newElement = (ModelTreeElement*)OctreeElement::addChildAtIndex(index); +EntityTreeElement* EntityTreeElement::addChildAtIndex(int index) { + EntityTreeElement* newElement = (EntityTreeElement*)OctreeElement::addChildAtIndex(index); newElement->setTree(_myTree); return newElement; } @@ -55,83 +55,83 @@ ModelTreeElement* ModelTreeElement::addChildAtIndex(int index) { // fit, but some models did fit, then the element outputs what can fit. Once the general Octree::encodeXXX() // process supports partial encoding of an octree element, this will need to be updated to handle spanning its // contents across multiple packets. -OctreeElement::AppendState ModelTreeElement::appendElementData(OctreePacketData* packetData, +OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData* packetData, EncodeBitstreamParams& params) const { OctreeElement::AppendState appendElementState = OctreeElement::COMPLETED; // assume the best... // first, check the params.extraEncodeData to see if there's any partial re-encode data for this element OctreeElementExtraEncodeData* extraEncodeData = params.extraEncodeData; - ModelTreeElementExtraEncodeData* modelTreeElementExtraEncodeData = NULL; + EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData = NULL; bool hadElementExtraData = false; if (extraEncodeData && extraEncodeData->contains(this)) { - modelTreeElementExtraEncodeData = static_cast(extraEncodeData->value(this)); + modelTreeElementExtraEncodeData = static_cast(extraEncodeData->value(this)); hadElementExtraData = true; } else { // if there wasn't one already, then create one - modelTreeElementExtraEncodeData = new ModelTreeElementExtraEncodeData(); + modelTreeElementExtraEncodeData = new EntityTreeElementExtraEncodeData(); } LevelDetails elementLevel = packetData->startLevel(); // write our models out... first determine which of the models are in view based on our params - uint16_t numberOfModels = 0; - uint16_t actualNumberOfModels = 0; - QVector indexesOfModelsToInclude; + uint16_t numberOfEntitys = 0; + uint16_t actualNumberOfEntitys = 0; + QVector indexesOfEntitysToInclude; - for (uint16_t i = 0; i < _modelItems->size(); i++) { - const ModelItem& model = (*_modelItems)[i]; - bool includeThisModel = true; + for (uint16_t i = 0; i < _entityItems->size(); i++) { + const EntityItem& model = (*_entityItems)[i]; + bool includeThisEntity = true; if (hadElementExtraData) { - includeThisModel = modelTreeElementExtraEncodeData->includedItems.contains(model.getModelItemID()); + includeThisEntity = modelTreeElementExtraEncodeData->includedItems.contains(model.getEntityItemID()); } - if (includeThisModel && params.viewFrustum) { + if (includeThisEntity && params.viewFrustum) { AACube modelCube = model.getAACube(); modelCube.scale(TREE_SCALE); if (params.viewFrustum->cubeInFrustum(modelCube) == ViewFrustum::OUTSIDE) { - includeThisModel = false; // out of view, don't include it + includeThisEntity = false; // out of view, don't include it } } - if (includeThisModel) { - indexesOfModelsToInclude << i; - numberOfModels++; + if (includeThisEntity) { + indexesOfEntitysToInclude << i; + numberOfEntitys++; } } - int numberOfModelsOffset = packetData->getUncompressedByteOffset(); - bool successAppendModelCount = packetData->appendValue(numberOfModels); + int numberOfEntitysOffset = packetData->getUncompressedByteOffset(); + bool successAppendEntityCount = packetData->appendValue(numberOfEntitys); - if (successAppendModelCount) { - foreach (uint16_t i, indexesOfModelsToInclude) { - const ModelItem& model = (*_modelItems)[i]; + if (successAppendEntityCount) { + foreach (uint16_t i, indexesOfEntitysToInclude) { + const EntityItem& model = (*_entityItems)[i]; LevelDetails modelLevel = packetData->startLevel(); - OctreeElement::AppendState appendModelState = model.appendModelData(packetData, params, modelTreeElementExtraEncodeData); + OctreeElement::AppendState appendEntityState = model.appendEntityData(packetData, params, modelTreeElementExtraEncodeData); // If none of this model data was able to be appended, then discard it // and don't include it in our model count - if (appendModelState == OctreeElement::NONE) { + if (appendEntityState == OctreeElement::NONE) { packetData->discardLevel(modelLevel); } else { // If either ALL or some of it got appended, then end the level (commit it) // and include the model in our final count of models packetData->endLevel(modelLevel); - actualNumberOfModels++; + actualNumberOfEntitys++; } // If the model item got completely appended, then we can remove it from the extra encode data - if (appendModelState == OctreeElement::COMPLETED) { - modelTreeElementExtraEncodeData->includedItems.remove(model.getModelItemID()); + if (appendEntityState == OctreeElement::COMPLETED) { + modelTreeElementExtraEncodeData->includedItems.remove(model.getEntityItemID()); } // If any part of the model items didn't fit, then the element is considered partial // NOTE: if the model item didn't fit or only partially fit, then the model item should have // added itself to the extra encode data. - if (appendModelState != OctreeElement::COMPLETED) { + if (appendEntityState != OctreeElement::COMPLETED) { appendElementState = OctreeElement::PARTIAL; } } @@ -153,18 +153,18 @@ OctreeElement::AppendState ModelTreeElement::appendElementData(OctreePacketData* } // Determine if no models at all were able to fit - bool noModelsFit = (numberOfModels > 0 && actualNumberOfModels == 0); + bool noEntitysFit = (numberOfEntitys > 0 && actualNumberOfEntitys == 0); // If we wrote fewer models than we expected, update the number of models in our packet - bool successUpdateModelCount = true; - if (!noModelsFit && numberOfModels != actualNumberOfModels) { - successUpdateModelCount = packetData->updatePriorBytes(numberOfModelsOffset, - (const unsigned char*)&actualNumberOfModels, sizeof(actualNumberOfModels)); + bool successUpdateEntityCount = true; + if (!noEntitysFit && numberOfEntitys != actualNumberOfEntitys) { + successUpdateEntityCount = packetData->updatePriorBytes(numberOfEntitysOffset, + (const unsigned char*)&actualNumberOfEntitys, sizeof(actualNumberOfEntitys)); } // If we weren't able to update our model count, or we couldn't fit any models, then // we should discard our element and return a result of NONE - if (!successUpdateModelCount || noModelsFit) { + if (!successUpdateEntityCount || noEntitysFit) { packetData->discardLevel(elementLevel); appendElementState = OctreeElement::NONE; } else { @@ -174,13 +174,13 @@ OctreeElement::AppendState ModelTreeElement::appendElementData(OctreePacketData* return appendElementState; } -bool ModelTreeElement::containsModelBounds(const ModelItem& model) const { +bool EntityTreeElement::containsEntityBounds(const EntityItem& model) const { glm::vec3 clampedMin = glm::clamp(model.getMinimumPoint(), 0.0f, 1.0f); glm::vec3 clampedMax = glm::clamp(model.getMaximumPoint(), 0.0f, 1.0f); return _cube.contains(clampedMin) && _cube.contains(clampedMax); } -bool ModelTreeElement::bestFitModelBounds(const ModelItem& model) const { +bool EntityTreeElement::bestFitEntityBounds(const EntityItem& model) const { glm::vec3 clampedMin = glm::clamp(model.getMinimumPoint(), 0.0f, 1.0f); glm::vec3 clampedMax = glm::clamp(model.getMaximumPoint(), 0.0f, 1.0f); if (_cube.contains(clampedMin) && _cube.contains(clampedMax)) { @@ -200,12 +200,12 @@ bool ModelTreeElement::bestFitModelBounds(const ModelItem& model) const { return false; } -void ModelTreeElement::update(ModelTreeUpdateArgs& args) { +void EntityTreeElement::update(EntityTreeUpdateArgs& args) { args._totalElements++; // update our contained models - QList::iterator modelItr = _modelItems->begin(); - while(modelItr != _modelItems->end()) { - ModelItem& model = (*modelItr); + QList::iterator modelItr = _entityItems->begin(); + while(modelItr != _entityItems->end()) { + EntityItem& model = (*modelItr); args._totalItems++; // TODO: this _lastChanged isn't actually changing because we're not marking this element as changed. @@ -215,11 +215,11 @@ void ModelTreeElement::update(ModelTreeUpdateArgs& args) { // If the model wants to die, or if it's left our bounding box, then move it // into the arguments moving models. These will be added back or deleted completely - if (model.getShouldDie() || !bestFitModelBounds(model)) { - args._movingModels.push_back(model); + if (model.getShouldDie() || !bestFitEntityBounds(model)) { + args._movingEntitys.push_back(model); // erase this model - modelItr = _modelItems->erase(modelItr); + modelItr = _entityItems->erase(modelItr); args._movingItems++; @@ -227,8 +227,8 @@ void ModelTreeElement::update(ModelTreeUpdateArgs& args) { markWithChangedTime(); // TODO: is this a good place to change the containing element map??? - qDebug() << "ModelTreeElement::update()... calling _myTree->setContainingElement(model.getModelItemID(), NULL); ********"; - _myTree->setContainingElement(model.getModelItemID(), NULL); + qDebug() << "EntityTreeElement::update()... calling _myTree->setContainingElement(model.getEntityItemID(), NULL); ********"; + _myTree->setContainingElement(model.getEntityItemID(), NULL); } else { ++modelItr; @@ -236,17 +236,17 @@ void ModelTreeElement::update(ModelTreeUpdateArgs& args) { } } -bool ModelTreeElement::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, +bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject) { // only called if we do intersect our bounding cube, but find if we actually intersect with models... - QList::iterator modelItr = _modelItems->begin(); - QList::const_iterator modelEnd = _modelItems->end(); + QList::iterator modelItr = _entityItems->begin(); + QList::const_iterator modelEnd = _entityItems->end(); bool somethingIntersected = false; while(modelItr != modelEnd) { - ModelItem& model = (*modelItr); + EntityItem& model = (*modelItr); AACube modelCube = model.getAACube(); float localDistance; @@ -254,7 +254,7 @@ bool ModelTreeElement::findDetailedRayIntersection(const glm::vec3& origin, cons // if the ray doesn't intersect with our cube, we can stop searching! if (modelCube.findRayIntersection(origin, direction, localDistance, localFace)) { - const FBXGeometry* fbxGeometry = _myTree->getGeometryForModel(model); + const FBXGeometry* fbxGeometry = _myTree->getGeometryForEntity(model); if (fbxGeometry && fbxGeometry->meshExtents.isValid()) { Extents extents = fbxGeometry->meshExtents; @@ -280,7 +280,7 @@ bool ModelTreeElement::findDetailedRayIntersection(const glm::vec3& origin, cons Extents rotatedExtents = extents; - calculateRotatedExtents(rotatedExtents, model.getModelRotation()); + calculateRotatedExtents(rotatedExtents, model.getRotation()); rotatedExtents.minimum += model.getPosition(); rotatedExtents.maximum += model.getPosition(); @@ -292,15 +292,15 @@ bool ModelTreeElement::findDetailedRayIntersection(const glm::vec3& origin, cons if (rotatedExtentsBox.findRayIntersection(origin, direction, localDistance, localFace)) { // extents is the model relative, scaled, centered extents of the model - glm::mat4 rotation = glm::mat4_cast(model.getModelRotation()); + glm::mat4 rotation = glm::mat4_cast(model.getRotation()); glm::mat4 translation = glm::translate(model.getPosition()); glm::mat4 modelToWorldMatrix = translation * rotation; - glm::mat4 worldToModelMatrix = glm::inverse(modelToWorldMatrix); + glm::mat4 worldToEntityMatrix = glm::inverse(modelToWorldMatrix); AABox modelFrameBox(extents.minimum, (extents.maximum - extents.minimum)); - glm::vec3 modelFrameOrigin = glm::vec3(worldToModelMatrix * glm::vec4(origin, 1.0f)); - glm::vec3 modelFrameDirection = glm::vec3(worldToModelMatrix * glm::vec4(direction, 0.0f)); + glm::vec3 modelFrameOrigin = glm::vec3(worldToEntityMatrix * glm::vec4(origin, 1.0f)); + glm::vec3 modelFrameDirection = glm::vec3(worldToEntityMatrix * glm::vec4(direction, 0.0f)); // we can use the AABox's ray intersection by mapping our origin and direction into the model frame // and testing intersection there. @@ -326,12 +326,12 @@ bool ModelTreeElement::findDetailedRayIntersection(const glm::vec3& origin, cons return somethingIntersected; } -bool ModelTreeElement::findSpherePenetration(const glm::vec3& center, float radius, +bool EntityTreeElement::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, void** penetratedObject) const { - QList::iterator modelItr = _modelItems->begin(); - QList::const_iterator modelEnd = _modelItems->end(); + QList::iterator modelItr = _entityItems->begin(); + QList::const_iterator modelEnd = _entityItems->end(); while(modelItr != modelEnd) { - ModelItem& model = (*modelItr); + EntityItem& model = (*modelItr); glm::vec3 modelCenter = model.getPosition(); float modelRadius = model.getRadius(); @@ -350,27 +350,27 @@ bool ModelTreeElement::findSpherePenetration(const glm::vec3& center, float radi return false; } -bool ModelTreeElement::updateModel(const ModelItem& model) { +bool EntityTreeElement::updateEntity(const EntityItem& model) { const bool wantDebug = false; if (wantDebug) { - ModelItemID modelItemID = model.getModelItemID(); - qDebug() << "ModelTreeElement::updateModel(model) modelID.id=" + EntityItemID modelItemID = model.getEntityItemID(); + qDebug() << "EntityTreeElement::updateEntity(model) modelID.id=" << modelItemID.id << "creatorTokenID=" << modelItemID.creatorTokenID; } // NOTE: this method must first lookup the model by ID, hence it is O(N) // and "model is not found" is worst-case (full N) but maybe we don't care? // (guaranteed that num models per elemen is small?) - uint16_t numberOfModels = _modelItems->size(); - for (uint16_t i = 0; i < numberOfModels; i++) { - ModelItem& thisModel = (*_modelItems)[i]; - if (thisModel.getID() == model.getID()) { + uint16_t numberOfEntitys = _entityItems->size(); + for (uint16_t i = 0; i < numberOfEntitys; i++) { + EntityItem& thisEntity = (*_entityItems)[i]; + if (thisEntity.getID() == model.getID()) { if (wantDebug) { qDebug() << "found model with id"; } - int difference = thisModel.getLastUpdated() - model.getLastUpdated(); - bool changedOnServer = thisModel.getLastEdited() <= model.getLastEdited(); - bool localOlder = thisModel.getLastUpdated() < model.getLastUpdated(); + int difference = thisEntity.getLastUpdated() - model.getLastUpdated(); + bool changedOnServer = thisEntity.getLastEdited() <= model.getLastEdited(); + bool localOlder = thisEntity.getLastUpdated() < model.getLastUpdated(); if (changedOnServer || localOlder) { if (wantDebug) { qDebug("local model [id:%d] %s and %s than server model by %d, model.isNewlyCreated()=%s", @@ -379,11 +379,11 @@ bool ModelTreeElement::updateModel(const ModelItem& model) { difference, debug::valueOf(model.isNewlyCreated()) ); } - thisModel.copyChangedProperties(model); + thisEntity.copyChangedProperties(model); markWithChangedTime(); // seems like we shouldn't need this - _myTree->setContainingElement(model.getModelItemID(), this); + _myTree->setContainingElement(model.getEntityItemID(), this); } else { if (wantDebug) { qDebug(">>> IGNORING SERVER!!! Would've caused jutter! <<< " @@ -398,52 +398,52 @@ bool ModelTreeElement::updateModel(const ModelItem& model) { } // If we didn't find the model here, then let's check to see if we should add it... - if (bestFitModelBounds(model)) { - _modelItems->push_back(model); + if (bestFitEntityBounds(model)) { + _entityItems->push_back(model); markWithChangedTime(); // Since we're adding this item to this element, we need to let the tree know about it - _myTree->setContainingElement(model.getModelItemID(), this); + _myTree->setContainingElement(model.getEntityItemID(), this); return true; } return false; } -void ModelTreeElement::updateModelItemID(FindAndUpdateModelItemIDArgs* args) { +void EntityTreeElement::updateEntityItemID(FindAndUpdateEntityItemIDArgs* args) { bool wantDebug = false; - uint16_t numberOfModels = _modelItems->size(); - for (uint16_t i = 0; i < numberOfModels; i++) { - ModelItem& thisModel = (*_modelItems)[i]; + uint16_t numberOfEntitys = _entityItems->size(); + for (uint16_t i = 0; i < numberOfEntitys; i++) { + EntityItem& thisEntity = (*_entityItems)[i]; if (!args->creatorTokenFound) { // first, we're looking for matching creatorTokenIDs, if we find that, then we fix it to know the actual ID - if (thisModel.getCreatorTokenID() == args->creatorTokenID) { + if (thisEntity.getCreatorTokenID() == args->creatorTokenID) { if (wantDebug) { - qDebug() << "ModelTreeElement::updateModelItemID()... found the model... updating it's ID... " + qDebug() << "EntityTreeElement::updateEntityItemID()... found the model... updating it's ID... " << "creatorTokenID=" << args->creatorTokenID << "modelID=" << args->modelID; } - thisModel.setID(args->modelID); + thisEntity.setID(args->modelID); args->creatorTokenFound = true; } } // if we're in an isViewing tree, we also need to look for an kill any viewed models - if (!args->viewedModelFound && args->isViewing) { - if (thisModel.getCreatorTokenID() == UNKNOWN_MODEL_TOKEN && thisModel.getID() == args->modelID) { + if (!args->viewedEntityFound && args->isViewing) { + if (thisEntity.getCreatorTokenID() == UNKNOWN_MODEL_TOKEN && thisEntity.getID() == args->modelID) { if (wantDebug) { - qDebug() << "ModelTreeElement::updateModelItemID()... VIEWED MODEL FOUND??? " + qDebug() << "EntityTreeElement::updateEntityItemID()... VIEWED MODEL FOUND??? " << "args->creatorTokenID=" << args->creatorTokenID - << "thisModel.getCreatorTokenID()=" << thisModel.getCreatorTokenID() + << "thisEntity.getCreatorTokenID()=" << thisEntity.getCreatorTokenID() << "args->modelID=" << args->modelID; } - _modelItems->removeAt(i); // remove the model at this index - numberOfModels--; // this means we have 1 fewer model in this list + _entityItems->removeAt(i); // remove the model at this index + numberOfEntitys--; // this means we have 1 fewer model in this list i--; // and we actually want to back up i as well. - args->viewedModelFound = true; + args->viewedEntityFound = true; } } } @@ -451,102 +451,102 @@ void ModelTreeElement::updateModelItemID(FindAndUpdateModelItemIDArgs* args) { -const ModelItem* ModelTreeElement::getClosestModel(glm::vec3 position) const { - const ModelItem* closestModel = NULL; - float closestModelDistance = FLT_MAX; - uint16_t numberOfModels = _modelItems->size(); - for (uint16_t i = 0; i < numberOfModels; i++) { - float distanceToModel = glm::distance(position, (*_modelItems)[i].getPosition()); - if (distanceToModel < closestModelDistance) { - closestModel = &(*_modelItems)[i]; +const EntityItem* EntityTreeElement::getClosestEntity(glm::vec3 position) const { + const EntityItem* closestEntity = NULL; + float closestEntityDistance = FLT_MAX; + uint16_t numberOfEntitys = _entityItems->size(); + for (uint16_t i = 0; i < numberOfEntitys; i++) { + float distanceToEntity = glm::distance(position, (*_entityItems)[i].getPosition()); + if (distanceToEntity < closestEntityDistance) { + closestEntity = &(*_entityItems)[i]; } } - return closestModel; + return closestEntity; } -void ModelTreeElement::getModels(const glm::vec3& searchPosition, float searchRadius, QVector& foundModels) const { - uint16_t numberOfModels = _modelItems->size(); - for (uint16_t i = 0; i < numberOfModels; i++) { - const ModelItem* model = &(*_modelItems)[i]; +void EntityTreeElement::getEntitys(const glm::vec3& searchPosition, float searchRadius, QVector& foundEntitys) const { + uint16_t numberOfEntitys = _entityItems->size(); + for (uint16_t i = 0; i < numberOfEntitys; i++) { + const EntityItem* model = &(*_entityItems)[i]; float distance = glm::length(model->getPosition() - searchPosition); if (distance < searchRadius + model->getRadius()) { - foundModels.push_back(model); + foundEntitys.push_back(model); } } } -void ModelTreeElement::getModels(const AACube& box, QVector& foundModels) { - QList::iterator modelItr = _modelItems->begin(); - QList::iterator modelEnd = _modelItems->end(); +void EntityTreeElement::getEntitys(const AACube& box, QVector& foundEntitys) { + QList::iterator modelItr = _entityItems->begin(); + QList::iterator modelEnd = _entityItems->end(); AACube modelCube; while(modelItr != modelEnd) { - ModelItem* model = &(*modelItr); + EntityItem* model = &(*modelItr); float radius = model->getRadius(); // NOTE: we actually do cube-cube collision queries here, which is sloppy but good enough for now // TODO: decide whether to replace modelCube-cube query with sphere-cube (requires a square root // but will be slightly more accurate). modelCube.setBox(model->getPosition() - glm::vec3(radius), 2.f * radius); if (modelCube.touches(_cube)) { - foundModels.push_back(model); + foundEntitys.push_back(model); } ++modelItr; } } -const ModelItem* ModelTreeElement::getModelWithID(uint32_t id) const { +const EntityItem* EntityTreeElement::getEntityWithID(uint32_t id) const { // NOTE: this lookup is O(N) but maybe we don't care? (guaranteed that num models per elemen is small?) - const ModelItem* foundModel = NULL; - uint16_t numberOfModels = _modelItems->size(); - for (uint16_t i = 0; i < numberOfModels; i++) { - if ((*_modelItems)[i].getID() == id) { - foundModel = &(*_modelItems)[i]; + const EntityItem* foundEntity = NULL; + uint16_t numberOfEntitys = _entityItems->size(); + for (uint16_t i = 0; i < numberOfEntitys; i++) { + if ((*_entityItems)[i].getID() == id) { + foundEntity = &(*_entityItems)[i]; break; } } - return foundModel; + return foundEntity; } -const ModelItem* ModelTreeElement::getModelWithModelItemID(const ModelItemID& id) const { +const EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemID& id) const { // NOTE: this lookup is O(N) but maybe we don't care? (guaranteed that num models per elemen is small?) - const ModelItem* foundModel = NULL; - uint16_t numberOfModels = _modelItems->size(); - for (uint16_t i = 0; i < numberOfModels; i++) { - if ((*_modelItems)[i].getModelItemID() == id) { - foundModel = &(*_modelItems)[i]; + const EntityItem* foundEntity = NULL; + uint16_t numberOfEntitys = _entityItems->size(); + for (uint16_t i = 0; i < numberOfEntitys; i++) { + if ((*_entityItems)[i].getEntityItemID() == id) { + foundEntity = &(*_entityItems)[i]; break; } } - return foundModel; + return foundEntity; } -bool ModelTreeElement::removeModelWithID(uint32_t id) { - bool foundModel = false; - uint16_t numberOfModels = _modelItems->size(); - for (uint16_t i = 0; i < numberOfModels; i++) { - if ((*_modelItems)[i].getID() == id) { - foundModel = true; - _modelItems->removeAt(i); +bool EntityTreeElement::removeEntityWithID(uint32_t id) { + bool foundEntity = false; + uint16_t numberOfEntitys = _entityItems->size(); + for (uint16_t i = 0; i < numberOfEntitys; i++) { + if ((*_entityItems)[i].getID() == id) { + foundEntity = true; + _entityItems->removeAt(i); break; } } - return foundModel; + return foundEntity; } -bool ModelTreeElement::removeModelWithModelItemID(const ModelItemID& id) { - bool foundModel = false; - uint16_t numberOfModels = _modelItems->size(); - for (uint16_t i = 0; i < numberOfModels; i++) { - if ((*_modelItems)[i].getModelItemID() == id) { - foundModel = true; - _modelItems->removeAt(i); +bool EntityTreeElement::removeEntityWithEntityItemID(const EntityItemID& id) { + bool foundEntity = false; + uint16_t numberOfEntitys = _entityItems->size(); + for (uint16_t i = 0; i < numberOfEntitys; i++) { + if ((*_entityItems)[i].getEntityItemID() == id) { + foundEntity = true; + _entityItems->removeAt(i); break; } } - return foundModel; + return foundEntity; } -int ModelTreeElement::readElementDataFromBuffer(const unsigned char* data, int bytesLeftToRead, +int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) { // If we're the root, but this bitstream doesn't support root elements with data, then @@ -559,33 +559,33 @@ int ModelTreeElement::readElementDataFromBuffer(const unsigned char* data, int b const unsigned char* dataAt = data; int bytesRead = 0; - uint16_t numberOfModels = 0; - int expectedBytesPerModel = ModelItem::expectedBytes(); + uint16_t numberOfEntitys = 0; + int expectedBytesPerEntity = EntityItem::expectedBytes(); - if (bytesLeftToRead >= (int)sizeof(numberOfModels)) { + if (bytesLeftToRead >= (int)sizeof(numberOfEntitys)) { // read our models in.... - numberOfModels = *(uint16_t*)dataAt; + numberOfEntitys = *(uint16_t*)dataAt; - dataAt += sizeof(numberOfModels); - bytesLeftToRead -= (int)sizeof(numberOfModels); - bytesRead += sizeof(numberOfModels); + dataAt += sizeof(numberOfEntitys); + bytesLeftToRead -= (int)sizeof(numberOfEntitys); + bytesRead += sizeof(numberOfEntitys); - if (bytesLeftToRead >= (int)(numberOfModels * expectedBytesPerModel)) { - for (uint16_t i = 0; i < numberOfModels; i++) { - ModelItem tempModel; // we will read into this - ModelItemID modelItemID = ModelItem::readModelItemIDFromBuffer(dataAt, bytesLeftToRead, args); - const ModelItem* existingModelItem = _myTree->findModelByModelItemID(modelItemID); - if (existingModelItem) { + if (bytesLeftToRead >= (int)(numberOfEntitys * expectedBytesPerEntity)) { + for (uint16_t i = 0; i < numberOfEntitys; i++) { + EntityItem tempEntity; // we will read into this + EntityItemID modelItemID = EntityItem::readEntityItemIDFromBuffer(dataAt, bytesLeftToRead, args); + const EntityItem* existingEntityItem = _myTree->findEntityByEntityItemID(modelItemID); + if (existingEntityItem) { // copy original properties... - tempModel.copyChangedProperties(*existingModelItem); + tempEntity.copyChangedProperties(*existingEntityItem); } // read only the changed properties - int bytesForThisModel = tempModel.readModelDataFromBuffer(dataAt, bytesLeftToRead, args); + int bytesForThisEntity = tempEntity.readEntityDataFromBuffer(dataAt, bytesLeftToRead, args); - _myTree->storeModel(tempModel); - dataAt += bytesForThisModel; - bytesLeftToRead -= bytesForThisModel; - bytesRead += bytesForThisModel; + _myTree->storeEntity(tempEntity); + dataAt += bytesForThisEntity; + bytesLeftToRead -= bytesForThisEntity; + bytesRead += bytesForThisEntity; } } } @@ -594,7 +594,7 @@ int ModelTreeElement::readElementDataFromBuffer(const unsigned char* data, int b } // will average a "common reduced LOD view" from the the child elements... -void ModelTreeElement::calculateAverageFromChildren() { +void EntityTreeElement::calculateAverageFromChildren() { // nothing to do here yet... } @@ -602,7 +602,7 @@ void ModelTreeElement::calculateAverageFromChildren() { // and in that case will collapse children and make this node // a leaf, returns TRUE if all the leaves are collapsed into a // single node -bool ModelTreeElement::collapseChildren() { +bool EntityTreeElement::collapseChildren() { // nothing to do here yet... return false; } diff --git a/libraries/models/src/EntityTreeElement.h b/libraries/models/src/EntityTreeElement.h index 6e011534e6..b19ea6b318 100644 --- a/libraries/models/src/EntityTreeElement.h +++ b/libraries/models/src/EntityTreeElement.h @@ -1,5 +1,5 @@ // -// ModelTreeElement.h +// EntityTreeElement.h // libraries/models/src // // Created by Brad Hefta-Gaub on 12/4/13. @@ -9,65 +9,65 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_ModelTreeElement_h -#define hifi_ModelTreeElement_h +#ifndef hifi_EntityTreeElement_h +#define hifi_EntityTreeElement_h #include #include -#include "ModelItem.h" -#include "ModelTree.h" +#include "EntityItem.h" +#include "EntityTree.h" -class ModelTree; -class ModelTreeElement; +class EntityTree; +class EntityTreeElement; -class ModelTreeUpdateArgs { +class EntityTreeUpdateArgs { public: - ModelTreeUpdateArgs() : + EntityTreeUpdateArgs() : _totalElements(0), _totalItems(0), _movingItems(0) { } - QList _movingModels; + QList _movingEntitys; int _totalElements; int _totalItems; int _movingItems; }; -class FindAndUpdateModelItemIDArgs { +class FindAndUpdateEntityItemIDArgs { public: uint32_t modelID; uint32_t creatorTokenID; bool creatorTokenFound; - bool viewedModelFound; + bool viewedEntityFound; bool isViewing; }; -class ModelTreeElementExtraEncodeData { +class EntityTreeElementExtraEncodeData { public: - QMap includedItems; + QMap includedItems; }; -class ModelTreeElement : public OctreeElement { - friend class ModelTree; // to allow createElement to new us... +class EntityTreeElement : public OctreeElement { + friend class EntityTree; // to allow createElement to new us... - ModelTreeElement(unsigned char* octalCode = NULL); + EntityTreeElement(unsigned char* octalCode = NULL); virtual OctreeElement* createNewElement(unsigned char* octalCode = NULL); public: - virtual ~ModelTreeElement(); + virtual ~EntityTreeElement(); // type safe versions of OctreeElement methods - ModelTreeElement* getChildAtIndex(int index) { return (ModelTreeElement*)OctreeElement::getChildAtIndex(index); } + EntityTreeElement* getChildAtIndex(int index) { return (EntityTreeElement*)OctreeElement::getChildAtIndex(index); } // methods you can and should override to implement your tree functionality /// Adds a child to the current element. Override this if there is additional child initialization your class needs. - virtual ModelTreeElement* addChildAtIndex(int index); + virtual EntityTreeElement* addChildAtIndex(int index); /// Override this to implement LOD averaging on changes to the tree. virtual void calculateAverageFromChildren(); @@ -77,11 +77,11 @@ public: /// Should this element be considered to have content in it. This will be used in collision and ray casting methods. /// By default we assume that only leaves are actual content, but some octrees may have different semantics. - virtual bool hasContent() const { return hasModels(); } + virtual bool hasContent() const { return hasEntities(); } /// Should this element be considered to have detailed content in it. Specifically should it be rendered. /// By default we assume that only leaves have detailed content, but some octrees may have different semantics. - virtual bool hasDetailedContent() const { return hasModels(); } + virtual bool hasDetailedContent() const { return hasEntities(); } /// Override this to break up large octree elements when an edit operation is performed on a smaller octree element. /// For example, if the octrees represent solid cubes and a delete of a smaller octree element is done then the @@ -103,9 +103,9 @@ public: /// where an element is not actually rendering all should render elements. If the isRendered() state doesn't match the /// shouldRender() state, the tree will remark elements as changed even in cases there the elements have not changed. virtual bool isRendered() const { return getShouldRender(); } - virtual bool deleteApproved() const { return !hasModels(); } + virtual bool deleteApproved() const { return !hasEntities(); } - virtual bool canRayIntersect() const { return hasModels(); } + virtual bool canRayIntersect() const { return hasEntities(); } virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject); @@ -113,42 +113,42 @@ public: virtual bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, void** penetratedObject) const; - const QList& getModels() const { return *_modelItems; } - QList& getModels() { return *_modelItems; } - bool hasModels() const { return _modelItems ? _modelItems->size() > 0 : false; } + const QList& getEntities() const { return *_entityItems; } + QList& getEntities() { return *_entityItems; } + bool hasEntities() const { return _entityItems ? _entityItems->size() > 0 : false; } - void update(ModelTreeUpdateArgs& args); - void setTree(ModelTree* tree) { _myTree = tree; } + void update(EntityTreeUpdateArgs& args); + void setTree(EntityTree* tree) { _myTree = tree; } - bool updateModel(const ModelItem& model); - void updateModelItemID(FindAndUpdateModelItemIDArgs* args); + bool updateEntity(const EntityItem& model); + void updateEntityItemID(FindAndUpdateEntityItemIDArgs* args); - const ModelItem* getClosestModel(glm::vec3 position) const; + const EntityItem* getClosestEntity(glm::vec3 position) const; /// finds all models that touch a sphere /// \param position the center of the query sphere /// \param radius the radius of the query sphere - /// \param models[out] vector of const ModelItem* - void getModels(const glm::vec3& position, float radius, QVector& foundModels) const; + /// \param models[out] vector of const EntityItem* + void getEntitys(const glm::vec3& position, float radius, QVector& foundEntitys) const; /// finds all models that touch a box /// \param box the query box - /// \param models[out] vector of non-const ModelItem* - void getModels(const AACube& box, QVector& foundModels); + /// \param models[out] vector of non-const EntityItem* + void getEntitys(const AACube& box, QVector& foundEntitys); - const ModelItem* getModelWithID(uint32_t id) const; - const ModelItem* getModelWithModelItemID(const ModelItemID& id) const; + const EntityItem* getEntityWithID(uint32_t id) const; + const EntityItem* getEntityWithEntityItemID(const EntityItemID& id) const; - bool removeModelWithID(uint32_t id); - bool removeModelWithModelItemID(const ModelItemID& id); + bool removeEntityWithID(uint32_t id); + bool removeEntityWithEntityItemID(const EntityItemID& id); - bool containsModelBounds(const ModelItem& model) const; - bool bestFitModelBounds(const ModelItem& model) const; + bool containsEntityBounds(const EntityItem& model) const; + bool bestFitEntityBounds(const EntityItem& model) const; protected: virtual void init(unsigned char * octalCode); - ModelTree* _myTree; - QList* _modelItems; + EntityTree* _myTree; + QList* _entityItems; }; -#endif // hifi_ModelTreeElement_h +#endif // hifi_EntityTreeElement_h diff --git a/libraries/models/src/EntityTreeHeadlessViewer.cpp b/libraries/models/src/EntityTreeHeadlessViewer.cpp index 5a0907b201..df00d302e3 100644 --- a/libraries/models/src/EntityTreeHeadlessViewer.cpp +++ b/libraries/models/src/EntityTreeHeadlessViewer.cpp @@ -1,5 +1,5 @@ // -// ModelTreeHeadlessViewer.cpp +// EntityTreeHeadlessViewer.cpp // libraries/models/src // // Created by Brad Hefta-Gaub on 2/26/14. @@ -9,23 +9,23 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "ModelTreeHeadlessViewer.h" +#include "EntityTreeHeadlessViewer.h" -ModelTreeHeadlessViewer::ModelTreeHeadlessViewer() : +EntityTreeHeadlessViewer::EntityTreeHeadlessViewer() : OctreeHeadlessViewer() { } -ModelTreeHeadlessViewer::~ModelTreeHeadlessViewer() { +EntityTreeHeadlessViewer::~EntityTreeHeadlessViewer() { } -void ModelTreeHeadlessViewer::init() { +void EntityTreeHeadlessViewer::init() { OctreeHeadlessViewer::init(); } -void ModelTreeHeadlessViewer::update() { +void EntityTreeHeadlessViewer::update() { if (_tree) { - ModelTree* tree = static_cast(_tree); + EntityTree* tree = static_cast(_tree); if (tree->tryLockForWrite()) { tree->update(); tree->unlock(); @@ -33,6 +33,6 @@ void ModelTreeHeadlessViewer::update() { } } -void ModelTreeHeadlessViewer::processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode) { - static_cast(_tree)->processEraseMessage(dataByteArray, sourceNode); +void EntityTreeHeadlessViewer::processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode) { + static_cast(_tree)->processEraseMessage(dataByteArray, sourceNode); } diff --git a/libraries/models/src/EntityTreeHeadlessViewer.h b/libraries/models/src/EntityTreeHeadlessViewer.h index 9bd766153f..b6cc04fb12 100644 --- a/libraries/models/src/EntityTreeHeadlessViewer.h +++ b/libraries/models/src/EntityTreeHeadlessViewer.h @@ -1,5 +1,5 @@ // -// ModelTreeHeadlessViewer.h +// EntityTreeHeadlessViewer.h // libraries/models/src // // Created by Brad Hefta-Gaub on 2/26/14. @@ -9,8 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_ModelTreeHeadlessViewer_h -#define hifi_ModelTreeHeadlessViewer_h +#ifndef hifi_EntityTreeHeadlessViewer_h +#define hifi_EntityTreeHeadlessViewer_h #include #include @@ -19,27 +19,27 @@ #include #include -#include "ModelTree.h" +#include "EntityTree.h" // Generic client side Octree renderer class. -class ModelTreeHeadlessViewer : public OctreeHeadlessViewer { +class EntityTreeHeadlessViewer : public OctreeHeadlessViewer { Q_OBJECT public: - ModelTreeHeadlessViewer(); - virtual ~ModelTreeHeadlessViewer(); + EntityTreeHeadlessViewer(); + virtual ~EntityTreeHeadlessViewer(); - virtual Octree* createTree() { return new ModelTree(true); } - virtual char getMyNodeType() const { return NodeType::ModelServer; } - virtual PacketType getMyQueryMessageType() const { return PacketTypeModelQuery; } - virtual PacketType getExpectedPacketType() const { return PacketTypeModelData; } + virtual Octree* createTree() { return new EntityTree(true); } + virtual char getMyNodeType() const { return NodeType::EntityServer; } + virtual PacketType getMyQueryMessageType() const { return PacketTypeEntityQuery; } + virtual PacketType getExpectedPacketType() const { return PacketTypeEntityData; } void update(); - ModelTree* getTree() { return (ModelTree*)_tree; } + EntityTree* getTree() { return (EntityTree*)_tree; } void processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode); virtual void init(); }; -#endif // hifi_ModelTreeHeadlessViewer_h +#endif // hifi_EntityTreeHeadlessViewer_h diff --git a/libraries/networking/src/Assignment.cpp b/libraries/networking/src/Assignment.cpp index fd6ecd4602..93dcd5e226 100644 --- a/libraries/networking/src/Assignment.cpp +++ b/libraries/networking/src/Assignment.cpp @@ -29,8 +29,8 @@ Assignment::Type Assignment::typeForNodeType(NodeType_t nodeType) { return Assignment::VoxelServerType; case NodeType::ParticleServer: return Assignment::ParticleServerType; - case NodeType::ModelServer: - return Assignment::ModelServerType; + case NodeType::EntityServer: + return Assignment::EntityServerType; case NodeType::MetavoxelServer: return Assignment::MetavoxelServerType; default: diff --git a/libraries/networking/src/Assignment.h b/libraries/networking/src/Assignment.h index 3898b84787..2276fdf873 100644 --- a/libraries/networking/src/Assignment.h +++ b/libraries/networking/src/Assignment.h @@ -32,7 +32,7 @@ public: VoxelServerType, ParticleServerType, MetavoxelServerType, - ModelServerType, + EntityServerType, AllTypes }; diff --git a/libraries/networking/src/Node.cpp b/libraries/networking/src/Node.cpp index 360172efde..662c827069 100644 --- a/libraries/networking/src/Node.cpp +++ b/libraries/networking/src/Node.cpp @@ -29,7 +29,7 @@ void NodeType::init() { TypeNameHash.insert(NodeType::DomainServer, "Domain Server"); TypeNameHash.insert(NodeType::VoxelServer, "Voxel Server"); TypeNameHash.insert(NodeType::ParticleServer, "Particle Server"); - TypeNameHash.insert(NodeType::ModelServer, "Model Server"); + TypeNameHash.insert(NodeType::EntityServer, "Entity Server"); TypeNameHash.insert(NodeType::MetavoxelServer, "Metavoxel Server"); TypeNameHash.insert(NodeType::Agent, "Agent"); TypeNameHash.insert(NodeType::AudioMixer, "Audio Mixer"); diff --git a/libraries/networking/src/Node.h b/libraries/networking/src/Node.h index 85fe2e4458..0d5703b45c 100644 --- a/libraries/networking/src/Node.h +++ b/libraries/networking/src/Node.h @@ -31,7 +31,7 @@ namespace NodeType { const NodeType_t DomainServer = 'D'; const NodeType_t VoxelServer = 'V'; const NodeType_t ParticleServer = 'P'; - const NodeType_t ModelServer = 'o'; + const NodeType_t EntityServer = 'o'; // was ModelServer const NodeType_t MetavoxelServer = 'm'; const NodeType_t EnvironmentServer = 'E'; const NodeType_t Agent = 'I'; diff --git a/libraries/networking/src/PacketHeaders.cpp b/libraries/networking/src/PacketHeaders.cpp index c655db3053..f7d72cc1e2 100644 --- a/libraries/networking/src/PacketHeaders.cpp +++ b/libraries/networking/src/PacketHeaders.cpp @@ -72,9 +72,9 @@ PacketVersion versionForPacketType(PacketType type) { return 1; case PacketTypeParticleErase: return 1; - case PacketTypeModelData: + case PacketTypeEntityData: return VERSION_MODELS_SUPPORT_SPLIT_MTU; - case PacketTypeModelErase: + case PacketTypeEntityErase: return 1; default: return 0; diff --git a/libraries/networking/src/PacketHeaders.h b/libraries/networking/src/PacketHeaders.h index af121af36d..c21880b724 100644 --- a/libraries/networking/src/PacketHeaders.h +++ b/libraries/networking/src/PacketHeaders.h @@ -61,15 +61,15 @@ enum PacketType { PacketTypeDomainConnectRequest, PacketTypeDomainServerRequireDTLS, PacketTypeNodeJsonStats, - PacketTypeModelQuery, - PacketTypeModelData, // 41 - PacketTypeModelAddOrEdit, - PacketTypeModelErase, - PacketTypeModelAddResponse, + PacketTypeEntityQuery, + PacketTypeEntityData, // 41 + PacketTypeEntityAddOrEdit, + PacketTypeEntityErase, + PacketTypeEntityAddResponse, PacketTypeOctreeDataNack, // 45 PacketTypeVoxelEditNack, PacketTypeParticleEditNack, - PacketTypeModelEditNack, + PacketTypeEntityEditNack, // 48 }; typedef char PacketVersion; @@ -78,8 +78,8 @@ const QSet NON_VERIFIED_PACKETS = QSet() << PacketTypeDomainServerRequireDTLS << PacketTypeDomainConnectRequest << PacketTypeDomainList << PacketTypeDomainListRequest << PacketTypeDomainOAuthRequest << PacketTypeCreateAssignment << PacketTypeRequestAssignment << PacketTypeStunResponse - << PacketTypeNodeJsonStats << PacketTypeVoxelQuery << PacketTypeParticleQuery << PacketTypeModelQuery - << PacketTypeOctreeDataNack << PacketTypeVoxelEditNack << PacketTypeParticleEditNack << PacketTypeModelEditNack; + << PacketTypeNodeJsonStats << PacketTypeVoxelQuery << PacketTypeParticleQuery << PacketTypeEntityQuery + << PacketTypeOctreeDataNack << PacketTypeVoxelEditNack << PacketTypeParticleEditNack << PacketTypeEntityEditNack; const int NUM_BYTES_MD5_HASH = 16; const int NUM_STATIC_HEADER_BYTES = sizeof(PacketVersion) + NUM_BYTES_RFC4122_UUID; diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index b0cce114a9..2b203cc555 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -39,7 +39,7 @@ VoxelsScriptingInterface ScriptEngine::_voxelsScriptingInterface; ParticlesScriptingInterface ScriptEngine::_particlesScriptingInterface; -ModelsScriptingInterface ScriptEngine::_modelsScriptingInterface; +EntityScriptingInterface ScriptEngine::_entityScriptingInterface; static QScriptValue soundConstructor(QScriptContext* context, QScriptEngine* engine) { QUrl soundURL = QUrl(context->argument(0).toString()); @@ -227,10 +227,10 @@ void ScriptEngine::init() { qScriptRegisterMetaType(&_engine, ParticleIDtoScriptValue, ParticleIDfromScriptValue); qScriptRegisterSequenceMetaType >(&_engine); - qScriptRegisterMetaType(&_engine, ModelItemPropertiesToScriptValue, ModelItemPropertiesFromScriptValue); - qScriptRegisterMetaType(&_engine, ModelItemIDtoScriptValue, ModelItemIDfromScriptValue); - qScriptRegisterMetaType(&_engine, RayToModelIntersectionResultToScriptValue, RayToModelIntersectionResultFromScriptValue); - qScriptRegisterSequenceMetaType >(&_engine); + qScriptRegisterMetaType(&_engine, EntityItemPropertiesToScriptValue, EntityItemPropertiesFromScriptValue); + qScriptRegisterMetaType(&_engine, EntityItemIDtoScriptValue, EntityItemIDfromScriptValue); + qScriptRegisterMetaType(&_engine, RayToEntityIntersectionResultToScriptValue, RayToEntityIntersectionResultFromScriptValue); + qScriptRegisterSequenceMetaType >(&_engine); qScriptRegisterSequenceMetaType >(&_engine); qScriptRegisterSequenceMetaType >(&_engine); @@ -257,7 +257,7 @@ void ScriptEngine::init() { registerGlobalObject("Script", this); registerGlobalObject("Audio", &_audioScriptingInterface); registerGlobalObject("Controller", _controllerScriptingInterface); - registerGlobalObject("Models", &_modelsScriptingInterface); + registerGlobalObject("Entities", &_entityScriptingInterface); registerGlobalObject("Particles", &_particlesScriptingInterface); registerGlobalObject("Quat", &_quatLibrary); registerGlobalObject("Vec3", &_vec3Library); @@ -403,13 +403,13 @@ void ScriptEngine::run() { } } - if (_modelsScriptingInterface.getModelPacketSender()->serversExist()) { + if (_entityScriptingInterface.getEntityPacketSender()->serversExist()) { // release the queue of edit voxel messages. - _modelsScriptingInterface.getModelPacketSender()->releaseQueuedMessages(); + _entityScriptingInterface.getEntityPacketSender()->releaseQueuedMessages(); // since we're in non-threaded mode, call process so that the packets are sent - if (!_modelsScriptingInterface.getModelPacketSender()->isThreaded()) { - _modelsScriptingInterface.getModelPacketSender()->process(); + if (!_entityScriptingInterface.getEntityPacketSender()->isThreaded()) { + _entityScriptingInterface.getEntityPacketSender()->process(); } } @@ -524,13 +524,13 @@ void ScriptEngine::run() { } } - if (_modelsScriptingInterface.getModelPacketSender()->serversExist()) { - // release the queue of edit voxel messages. - _modelsScriptingInterface.getModelPacketSender()->releaseQueuedMessages(); + if (_entityScriptingInterface.getEntityPacketSender()->serversExist()) { + // release the queue of edit entity messages. + _entityScriptingInterface.getEntityPacketSender()->releaseQueuedMessages(); // since we're in non-threaded mode, call process so that the packets are sent - if (!_modelsScriptingInterface.getModelPacketSender()->isThreaded()) { - _modelsScriptingInterface.getModelPacketSender()->process(); + if (!_entityScriptingInterface.getEntityPacketSender()->isThreaded()) { + _entityScriptingInterface.getEntityPacketSender()->process(); } } diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index bf2ac40568..d2ded557f2 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -29,7 +29,7 @@ #include "ScriptUUID.h" #include "Vec3.h" -class ModelsScriptingInterface; +class EntityScriptingInterface; class ParticlesScriptingInterface; class VoxelsScriptingInterface; @@ -53,8 +53,8 @@ public: /// Access the ParticlesScriptingInterface in order to initialize it with a custom packet sender and jurisdiction listener static ParticlesScriptingInterface* getParticlesScriptingInterface() { return &_particlesScriptingInterface; } - /// Access the ModelsScriptingInterface in order to initialize it with a custom packet sender and jurisdiction listener - static ModelsScriptingInterface* getModelsScriptingInterface() { return &_modelsScriptingInterface; } + /// Access the EntityScriptingInterface in order to initialize it with a custom packet sender and jurisdiction listener + static EntityScriptingInterface* getEntityScriptingInterface() { return &_entityScriptingInterface; } /// sets the script contents, will return false if failed, will fail if script is already running bool setScriptContents(const QString& scriptContents, const QString& fileNameString = QString("")); @@ -134,7 +134,7 @@ private: static VoxelsScriptingInterface _voxelsScriptingInterface; static ParticlesScriptingInterface _particlesScriptingInterface; - static ModelsScriptingInterface _modelsScriptingInterface; + static EntityScriptingInterface _entityScriptingInterface; AbstractControllerScriptingInterface* _controllerScriptingInterface; AudioScriptingInterface _audioScriptingInterface; diff --git a/tests/octree/src/ModelTests.cpp b/tests/octree/src/ModelTests.cpp index 79a2a1c860..fea84f0737 100644 --- a/tests/octree/src/ModelTests.cpp +++ b/tests/octree/src/ModelTests.cpp @@ -1,5 +1,5 @@ // -// ModelTests.h +// EntityTests.h // tests/octree/src // // Created by Brad Hefta-Gaub on 06/04/2014. @@ -14,18 +14,19 @@ #include -#include -#include -#include +#include +#include +#include #include #include #include #include -#include "ModelTests.h" +//#include "EntityTests.h" +#include "ModelTests.h" // needs to be EntityTests.h soon -void ModelTests::modelTreeTests(bool verbose) { +void EntityTests::modelTreeTests(bool verbose) { bool extraVerbose = false; int testsTaken = 0; int testsPassed = 0; @@ -35,14 +36,14 @@ void ModelTests::modelTreeTests(bool verbose) { qDebug() << "******************************************************************************************"; } - qDebug() << "ModelTests::modelTreeTests()"; + qDebug() << "EntityTests::modelTreeTests()"; // Tree, id, and model properties used in many tests below... - ModelTree tree; + EntityTree tree; uint32_t id = 1; - ModelItemID modelID(id); + EntityItemID modelID(id); modelID.isKnownID = false; // this is a temporary workaround to allow local tree models to be added with known IDs - ModelItemProperties properties; + EntityItemProperties properties; float oneMeter = 1.0f; float halfMeter = oneMeter / 2.0f; float halfOfDomain = TREE_SCALE * 0.5f; @@ -62,17 +63,17 @@ void ModelTests::modelTreeTests(bool verbose) { properties.setRadius(halfMeter); properties.setModelURL("https://s3-us-west-1.amazonaws.com/highfidelity-public/ozan/theater.fbx"); - tree.addModel(modelID, properties); + tree.addEntity(modelID, properties); float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units - const ModelItem* foundModelByRadius = tree.findClosestModel(positionAtCenterInTreeUnits, targetRadius); - const ModelItem* foundModelByID = tree.findModelByID(id); - ModelTreeElement* containingElement = tree.getContainingElement(modelID); + const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionAtCenterInTreeUnits, targetRadius); + const EntityItem* foundEntityByID = tree.findEntityByID(id); + EntityTreeElement* containingElement = tree.getContainingElement(modelID); AACube elementCube = containingElement ? containingElement->getAACube() : AACube(); if (verbose) { - qDebug() << "foundModelByRadius=" << foundModelByRadius; - qDebug() << "foundModelByID=" << foundModelByID; + qDebug() << "foundEntityByRadius=" << foundEntityByRadius; + qDebug() << "foundEntityByID=" << foundEntityByID; qDebug() << "containingElement=" << containingElement; qDebug() << "containingElement.box=" << elementCube.getCorner().x * TREE_SCALE << "," @@ -83,7 +84,7 @@ void ModelTests::modelTreeTests(bool verbose) { //containingElement->printDebugDetails("containingElement"); } - bool passed = foundModelByRadius && foundModelByID && (foundModelByRadius == foundModelByID); + bool passed = foundEntityByRadius && foundEntityByID && (foundEntityByRadius == foundEntityByID); if (passed) { testsPassed++; } else { @@ -105,17 +106,17 @@ void ModelTests::modelTreeTests(bool verbose) { properties.setPosition(newPosition); - tree.updateModel(modelID, properties); + tree.updateEntity(modelID, properties); float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units - const ModelItem* foundModelByRadius = tree.findClosestModel(positionNearOriginInTreeUnits, targetRadius); - const ModelItem* foundModelByID = tree.findModelByID(id); - ModelTreeElement* containingElement = tree.getContainingElement(modelID); + const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionNearOriginInTreeUnits, targetRadius); + const EntityItem* foundEntityByID = tree.findEntityByID(id); + EntityTreeElement* containingElement = tree.getContainingElement(modelID); AACube elementCube = containingElement ? containingElement->getAACube() : AACube(); if (verbose) { - qDebug() << "foundModelByRadius=" << foundModelByRadius; - qDebug() << "foundModelByID=" << foundModelByID; + qDebug() << "foundEntityByRadius=" << foundEntityByRadius; + qDebug() << "foundEntityByID=" << foundEntityByID; qDebug() << "containingElement=" << containingElement; qDebug() << "containingElement.box=" << elementCube.getCorner().x * TREE_SCALE << "," @@ -125,7 +126,7 @@ void ModelTests::modelTreeTests(bool verbose) { //containingElement->printDebugDetails("containingElement"); } - bool passed = foundModelByRadius && foundModelByID && (foundModelByRadius == foundModelByID); + bool passed = foundEntityByRadius && foundEntityByID && (foundEntityByRadius == foundEntityByID); if (passed) { testsPassed++; } else { @@ -145,17 +146,17 @@ void ModelTests::modelTreeTests(bool verbose) { properties.setPosition(newPosition); - tree.updateModel(modelID, properties); + tree.updateEntity(modelID, properties); float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units - const ModelItem* foundModelByRadius = tree.findClosestModel(positionAtCenterInTreeUnits, targetRadius); - const ModelItem* foundModelByID = tree.findModelByID(id); - ModelTreeElement* containingElement = tree.getContainingElement(modelID); + const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionAtCenterInTreeUnits, targetRadius); + const EntityItem* foundEntityByID = tree.findEntityByID(id); + EntityTreeElement* containingElement = tree.getContainingElement(modelID); AACube elementCube = containingElement ? containingElement->getAACube() : AACube(); if (verbose) { - qDebug() << "foundModelByRadius=" << foundModelByRadius; - qDebug() << "foundModelByID=" << foundModelByID; + qDebug() << "foundEntityByRadius=" << foundEntityByRadius; + qDebug() << "foundEntityByID=" << foundEntityByID; qDebug() << "containingElement=" << containingElement; qDebug() << "containingElement.box=" << elementCube.getCorner().x * TREE_SCALE << "," @@ -165,7 +166,7 @@ void ModelTests::modelTreeTests(bool verbose) { //containingElement->printDebugDetails("containingElement"); } - bool passed = foundModelByRadius && foundModelByID && (foundModelByRadius == foundModelByID); + bool passed = foundEntityByRadius && foundEntityByID && (foundEntityByRadius == foundEntityByID); if (passed) { testsPassed++; } else { @@ -177,24 +178,24 @@ void ModelTests::modelTreeTests(bool verbose) { { testsTaken++; const int TEST_ITERATIONS = 1000; - QString testName = "Performance - findClosestModel() "+ QString::number(TEST_ITERATIONS) + " times"; + QString testName = "Performance - findClosestEntity() "+ QString::number(TEST_ITERATIONS) + " times"; if (verbose) { qDebug() << "Test" << testsTaken <<":" << qPrintable(testName); } float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units quint64 start = usecTimestampNow(); - const ModelItem* foundModelByRadius = NULL; + const EntityItem* foundEntityByRadius = NULL; for (int i = 0; i < TEST_ITERATIONS; i++) { - foundModelByRadius = tree.findClosestModel(positionAtCenterInTreeUnits, targetRadius); + foundEntityByRadius = tree.findClosestEntity(positionAtCenterInTreeUnits, targetRadius); } quint64 end = usecTimestampNow(); if (verbose) { - qDebug() << "foundModelByRadius=" << foundModelByRadius; + qDebug() << "foundEntityByRadius=" << foundEntityByRadius; } - bool passed = foundModelByRadius; + bool passed = foundEntityByRadius; if (passed) { testsPassed++; } else { @@ -209,23 +210,23 @@ void ModelTests::modelTreeTests(bool verbose) { { testsTaken++; const int TEST_ITERATIONS = 1000; - QString testName = "Performance - findModelByID() "+ QString::number(TEST_ITERATIONS) + " times"; + QString testName = "Performance - findEntityByID() "+ QString::number(TEST_ITERATIONS) + " times"; if (verbose) { qDebug() << "Test" << testsTaken <<":" << qPrintable(testName); } quint64 start = usecTimestampNow(); - const ModelItem* foundModelByID = NULL; + const EntityItem* foundEntityByID = NULL; for (int i = 0; i < TEST_ITERATIONS; i++) { - foundModelByID = tree.findModelByID(id); + foundEntityByID = tree.findEntityByID(id); } quint64 end = usecTimestampNow(); if (verbose) { - qDebug() << "foundModelByID=" << foundModelByID; + qDebug() << "foundEntityByID=" << foundEntityByID; } - bool passed = foundModelByID; + bool passed = foundEntityByID; if (passed) { testsPassed++; } else { @@ -253,7 +254,7 @@ void ModelTests::modelTreeTests(bool verbose) { quint64 totalElapsedFind = 0; for (int i = 0; i < TEST_ITERATIONS; i++) { uint32_t id = i + 2; // make sure it doesn't collide with previous model ids - ModelItemID modelID(id); + EntityItemID modelID(id); modelID.isKnownID = false; // this is a temporary workaround to allow local tree models to be added with known IDs float randomX = randFloatInRange(1.0f ,(float)TREE_SCALE - 1.0f); @@ -273,7 +274,7 @@ void ModelTests::modelTreeTests(bool verbose) { } quint64 startAdd = usecTimestampNow(); - tree.addModel(modelID, properties); + tree.addEntity(modelID, properties); quint64 endAdd = usecTimestampNow(); totalElapsedAdd += (endAdd - startAdd); @@ -283,19 +284,19 @@ void ModelTests::modelTreeTests(bool verbose) { quint64 startFind = usecTimestampNow(); float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units - const ModelItem* foundModelByRadius = tree.findClosestModel(randomPositionInTreeUnits, targetRadius); - const ModelItem* foundModelByID = tree.findModelByID(id); + const EntityItem* foundEntityByRadius = tree.findClosestEntity(randomPositionInTreeUnits, targetRadius); + const EntityItem* foundEntityByID = tree.findEntityByID(id); quint64 endFind = usecTimestampNow(); totalElapsedFind += (endFind - startFind); - ModelTreeElement* containingElement = tree.getContainingElement(modelID); + EntityTreeElement* containingElement = tree.getContainingElement(modelID); AACube elementCube = containingElement ? containingElement->getAACube() : AACube(); - bool elementIsBestFit = containingElement->bestFitModelBounds(*foundModelByID); + bool elementIsBestFit = containingElement->bestFitEntityBounds(*foundEntityByID); if (extraVerbose) { - qDebug() << "foundModelByRadius=" << foundModelByRadius; - qDebug() << "foundModelByID=" << foundModelByID; + qDebug() << "foundEntityByRadius=" << foundEntityByRadius; + qDebug() << "foundEntityByID=" << foundEntityByID; qDebug() << "containingElement=" << containingElement; qDebug() << "containingElement.box=" << elementCube.getCorner().x * TREE_SCALE << "," @@ -312,13 +313,13 @@ void ModelTests::modelTreeTests(bool verbose) { qDebug() << "after test:" << i << "getOctreeElementsCount()=" << tree.getOctreeElementsCount(); } - bool passed = foundModelByRadius && foundModelByID && (foundModelByRadius == foundModelByID) && elementIsBestFit; + bool passed = foundEntityByRadius && foundEntityByID && (foundEntityByRadius == foundEntityByID) && elementIsBestFit; if (passed) { iterationsPassed++; } else { if (extraVerbose) { qDebug() << "FAILED - Test" << testsTaken <<":" << qPrintable(testName) << "iteration:" << i - << "foundModelByRadius=" << foundModelByRadius << "foundModelByID=" << foundModelByID + << "foundEntityByRadius=" << foundEntityByRadius << "foundEntityByID=" << foundEntityByID << "x/y/z=" << randomX << "," << randomY << "," << randomZ << "elementIsBestFit=" << elementIsBestFit; } @@ -357,7 +358,7 @@ void ModelTests::modelTreeTests(bool verbose) { quint64 totalElapsedFind = 0; for (int i = 0; i < TEST_ITERATIONS; i++) { uint32_t id = i + 2; // These are the models we added above - ModelItemID modelID(id); + EntityItemID modelID(id); modelID.isKnownID = true; // this is a temporary workaround to allow local tree models to be added with known IDs if (extraVerbose) { @@ -365,7 +366,7 @@ void ModelTests::modelTreeTests(bool verbose) { } quint64 startDelete = usecTimestampNow(); - tree.deleteModel(modelID); + tree.deleteEntity(modelID); quint64 endDelete = usecTimestampNow(); totalElapsedDelete += (endDelete - startDelete); @@ -374,14 +375,14 @@ void ModelTests::modelTreeTests(bool verbose) { } quint64 startFind = usecTimestampNow(); - const ModelItem* foundModelByID = tree.findModelByID(id); + const EntityItem* foundEntityByID = tree.findEntityByID(id); quint64 endFind = usecTimestampNow(); totalElapsedFind += (endFind - startFind); - ModelTreeElement* containingElement = tree.getContainingElement(modelID); + EntityTreeElement* containingElement = tree.getContainingElement(modelID); if (extraVerbose) { - qDebug() << "foundModelByID=" << foundModelByID; + qDebug() << "foundEntityByID=" << foundEntityByID; qDebug() << "containingElement=" << containingElement; } @@ -390,13 +391,13 @@ void ModelTests::modelTreeTests(bool verbose) { qDebug() << "after test:" << i << "getOctreeElementsCount()=" << tree.getOctreeElementsCount(); } - bool passed = foundModelByID == NULL && containingElement == NULL; + bool passed = foundEntityByID == NULL && containingElement == NULL; if (passed) { iterationsPassed++; } else { if (extraVerbose) { qDebug() << "FAILED - Test" << testsTaken <<":" << qPrintable(testName) << "iteration:" << i - << "foundModelByID=" << foundModelByID + << "foundEntityByID=" << foundEntityByID << "containingElement=" << containingElement; } } @@ -437,10 +438,10 @@ void ModelTests::modelTreeTests(bool verbose) { quint64 totalElapsedFind = 0; for (int i = 0; i < TEST_ITERATIONS; i++) { - QSet modelsToDelete; + QSet modelsToDelete; for (int j = 0; j < MODELS_PER_ITERATION; j++) { uint32_t id = 2 + (i * MODELS_PER_ITERATION) + j; // These are the models we added above - ModelItemID modelID(id); + EntityItemID modelID(id); modelsToDelete << modelID; } @@ -449,7 +450,7 @@ void ModelTests::modelTreeTests(bool verbose) { } quint64 startDelete = usecTimestampNow(); - tree.deleteModels(modelsToDelete); + tree.deleteEntitys(modelsToDelete); quint64 endDelete = usecTimestampNow(); totalElapsedDelete += (endDelete - startDelete); @@ -460,21 +461,21 @@ void ModelTests::modelTreeTests(bool verbose) { quint64 startFind = usecTimestampNow(); for (int j = 0; j < MODELS_PER_ITERATION; j++) { uint32_t id = 2 + (i * MODELS_PER_ITERATION) + j; // These are the models we added above - ModelItemID modelID(id); - const ModelItem* foundModelByID = tree.findModelByID(id); - ModelTreeElement* containingElement = tree.getContainingElement(modelID); + EntityItemID modelID(id); + const EntityItem* foundEntityByID = tree.findEntityByID(id); + EntityTreeElement* containingElement = tree.getContainingElement(modelID); if (extraVerbose) { - qDebug() << "foundModelByID=" << foundModelByID; + qDebug() << "foundEntityByID=" << foundEntityByID; qDebug() << "containingElement=" << containingElement; } - bool passed = foundModelByID == NULL && containingElement == NULL; + bool passed = foundEntityByID == NULL && containingElement == NULL; if (passed) { iterationsPassed++; } else { if (extraVerbose) { qDebug() << "FAILED - Test" << testsTaken <<":" << qPrintable(testName) << "iteration:" << i - << "foundModelByID=" << foundModelByID + << "foundEntityByID=" << foundEntityByID << "containingElement=" << containingElement; } } @@ -511,7 +512,7 @@ void ModelTests::modelTreeTests(bool verbose) { } -void ModelTests::runAllTests(bool verbose) { +void EntityTests::runAllTests(bool verbose) { modelTreeTests(verbose); } diff --git a/tests/octree/src/ModelTests.h b/tests/octree/src/ModelTests.h index dd764edf9d..606979c9cf 100644 --- a/tests/octree/src/ModelTests.h +++ b/tests/octree/src/ModelTests.h @@ -1,5 +1,5 @@ // -// ModelTests.h +// EntityTests.h // tests/octree/src // // Created by Brad Hefta-Gaub on 06/04/2014. @@ -9,12 +9,12 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_ModelTests_h -#define hifi_ModelTests_h +#ifndef hifi_EntityTests_h +#define hifi_EntityTests_h -namespace ModelTests { +namespace EntityTests { void modelTreeTests(bool verbose = false); void runAllTests(bool verbose = false); } -#endif // hifi_ModelTests_h +#endif // hifi_EntityTests_h diff --git a/tests/octree/src/OctreeTests.cpp b/tests/octree/src/OctreeTests.cpp index bbd2ef5040..edb888c5b8 100644 --- a/tests/octree/src/OctreeTests.cpp +++ b/tests/octree/src/OctreeTests.cpp @@ -15,9 +15,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -64,11 +64,11 @@ void OctreeTests::propertyFlagsTests(bool verbose) { { if (verbose) { - qDebug() << "Test 1: ModelProperties: using setHasProperty()"; + qDebug() << "Test 1: EntityProperties: using setHasProperty()"; } testsTaken++; - ModelPropertyFlags props; + EntityPropertyFlags props; props.setHasProperty(PROP_VISIBLE); props.setHasProperty(PROP_POSITION); props.setHasProperty(PROP_RADIUS); @@ -89,7 +89,7 @@ void OctreeTests::propertyFlagsTests(bool verbose) { testsPassed++; } else { testsFailed++; - qDebug() << "FAILED - Test 1: ModelProperties: using setHasProperty()"; + qDebug() << "FAILED - Test 1: EntityProperties: using setHasProperty()"; } } @@ -1272,7 +1272,7 @@ void OctreeTests::byteCountCodingTests(bool verbose) { void OctreeTests::modelItemTests(bool verbose) { //verbose = true; - ModelTreeElementExtraEncodeData modelTreeElementExtraEncodeData; + EntityTreeElementExtraEncodeData modelTreeElementExtraEncodeData; int testsTaken = 0; int testsPassed = 0; int testsFailed = 0; @@ -1285,12 +1285,12 @@ void OctreeTests::modelItemTests(bool verbose) { EncodeBitstreamParams params; OctreePacketData packetData; - ModelItem modelItem; + EntityItem entityItem; - modelItem.setID(1042); - modelItem.setModelURL("http://foo.com/foo.fbx"); + entityItem.setID(1042); + entityItem.setModelURL("http://foo.com/foo.fbx"); - bool appendResult = modelItem.appendModelData(&packetData, params, &modelTreeElementExtraEncodeData); + bool appendResult = entityItem.appendEntityData(&packetData, params, &modelTreeElementExtraEncodeData); int bytesWritten = packetData.getUncompressedSize(); if (verbose) { qDebug() << "Test 1: bytesRead == bytesWritten ..."; @@ -1300,11 +1300,11 @@ void OctreeTests::modelItemTests(bool verbose) { { ReadBitstreamToTreeParams args; - ModelItem modelItemFromBuffer; + EntityItem modelItemFromBuffer; const unsigned char* data = packetData.getUncompressedData(); int bytesLeftToRead = packetData.getUncompressedSize(); - int bytesRead = modelItemFromBuffer.readModelDataFromBuffer(data, bytesLeftToRead, args); + int bytesRead = modelItemFromBuffer.readEntityDataFromBuffer(data, bytesLeftToRead, args); if (verbose) { qDebug() << "bytesRead=" << bytesRead; qDebug() << "modelItemFromBuffer.getID()=" << modelItemFromBuffer.getID(); @@ -1337,7 +1337,7 @@ void OctreeTests::modelItemTests(bool verbose) { } // TEST 3: - // Reset the packet, fill it with data so that ModelItem header won't fit, and verify that we don't let it fit + // Reset the packet, fill it with data so that EntityItem header won't fit, and verify that we don't let it fit { packetData.reset(); int remainingSpace = 10; @@ -1345,10 +1345,10 @@ void OctreeTests::modelItemTests(bool verbose) { QByteArray garbageData(almostFullOfData, 0); packetData.appendValue(garbageData); - appendResult = modelItem.appendModelData(&packetData, params, &modelTreeElementExtraEncodeData); + appendResult = entityItem.appendEntityData(&packetData, params, &modelTreeElementExtraEncodeData); bytesWritten = packetData.getUncompressedSize() - almostFullOfData; if (verbose) { - qDebug() << "Test 3: attempt to appendModelData in nearly full packetData ..."; + qDebug() << "Test 3: attempt to appendEntityData in nearly full packetData ..."; qDebug() << "appendResult=" << appendResult; qDebug() << "bytesWritten=" << bytesWritten; } @@ -1359,12 +1359,12 @@ void OctreeTests::modelItemTests(bool verbose) { testsPassed++; } else { testsFailed++; - qDebug() << "FAILED - Test 3: attempt to appendModelData in nearly full packetData ..."; + qDebug() << "FAILED - Test 3: attempt to appendEntityData in nearly full packetData ..."; } } // TEST 4: - // Reset the packet, fill it with data so that some of ModelItem won't fit, and verify that we write what can fit + // Reset the packet, fill it with data so that some of EntityItem won't fit, and verify that we write what can fit { packetData.reset(); int remainingSpace = 50; @@ -1372,10 +1372,10 @@ void OctreeTests::modelItemTests(bool verbose) { QByteArray garbageData(almostFullOfData, 0); packetData.appendValue(garbageData); - appendResult = modelItem.appendModelData(&packetData, params, &modelTreeElementExtraEncodeData); + appendResult = entityItem.appendEntityData(&packetData, params, &modelTreeElementExtraEncodeData); bytesWritten = packetData.getUncompressedSize() - almostFullOfData; if (verbose) { - qDebug() << "Test 4: attempt to appendModelData in nearly full packetData which some should fit ..."; + qDebug() << "Test 4: attempt to appendEntityData in nearly full packetData which some should fit ..."; qDebug() << "appendResult=" << appendResult; qDebug() << "bytesWritten=" << bytesWritten; } @@ -1386,17 +1386,17 @@ void OctreeTests::modelItemTests(bool verbose) { testsPassed++; } else { testsFailed++; - qDebug() << "FAILED - Test 4: attempt to appendModelData in nearly full packetData which some should fit ..."; + qDebug() << "FAILED - Test 4: attempt to appendEntityData in nearly full packetData which some should fit ..."; } ReadBitstreamToTreeParams args; - ModelItem modelItemFromBuffer; + EntityItem modelItemFromBuffer; const unsigned char* data = packetData.getUncompressedData() + almostFullOfData; int bytesLeftToRead = packetData.getUncompressedSize() - almostFullOfData; - int bytesRead = modelItemFromBuffer.readModelDataFromBuffer(data, bytesLeftToRead, args); + int bytesRead = modelItemFromBuffer.readEntityDataFromBuffer(data, bytesLeftToRead, args); if (verbose) { - qDebug() << "Test 5: partial ModelItem written ... bytesRead == bytesWritten..."; + qDebug() << "Test 5: partial EntityItem written ... bytesRead == bytesWritten..."; qDebug() << "bytesRead=" << bytesRead; qDebug() << "modelItemFromBuffer.getID()=" << modelItemFromBuffer.getID(); qDebug() << "modelItemFromBuffer.getModelURL()=" << modelItemFromBuffer.getModelURL(); @@ -1409,11 +1409,11 @@ void OctreeTests::modelItemTests(bool verbose) { testsPassed++; } else { testsFailed++; - qDebug() << "FAILED - Test 5: partial ModelItem written ... bytesRead == bytesWritten..."; + qDebug() << "FAILED - Test 5: partial EntityItem written ... bytesRead == bytesWritten..."; } if (verbose) { - qDebug() << "Test 6: partial ModelItem written ... getModelURL() NOT SET ..."; + qDebug() << "Test 6: partial EntityItem written ... getModelURL() NOT SET ..."; } testsTaken++; @@ -1423,7 +1423,7 @@ void OctreeTests::modelItemTests(bool verbose) { testsPassed++; } else { testsFailed++; - qDebug() << "FAILED - Test 6: partial ModelItem written ... getModelURL() NOT SET ..."; + qDebug() << "FAILED - Test 6: partial EntityItem written ... getModelURL() NOT SET ..."; } } diff --git a/tests/octree/src/main.cpp b/tests/octree/src/main.cpp index ff6e5bcbf2..adf3f6dfe4 100644 --- a/tests/octree/src/main.cpp +++ b/tests/octree/src/main.cpp @@ -9,7 +9,7 @@ // #include "AABoxCubeTests.h" -#include "ModelTests.h" +#include "ModelTests.h" // needs to be EntityTests.h soon #include "OctreeTests.h" #include "SharedUtil.h" @@ -19,6 +19,6 @@ int main(int argc, const char* argv[]) { qDebug() << "OctreeTests::runAllTests()"; //OctreeTests::runAllTests(verbose); //AABoxCubeTests::runAllTests(verbose); - ModelTests::runAllTests(verbose); + EntityTests::runAllTests(verbose); return 0; }