From aac42058ac5e152e2077f0d7ea9aace380faf123 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 30 Apr 2014 09:25:52 -0700 Subject: [PATCH] first cut at modelserver --- assignment-client/CMakeLists.txt | 1 + assignment-client/src/Agent.cpp | 18 +++++++- assignment-client/src/Agent.h | 4 ++ assignment-client/src/octree/OctreeServer.cpp | 2 +- domain-server/src/DomainServer.cpp | 2 +- interface/CMakeLists.txt | 1 + interface/src/Application.cpp | 46 +++++++++++++++++-- interface/src/Application.h | 2 + interface/src/ui/OctreeStatsDialog.cpp | 3 ++ interface/src/ui/Stats.cpp | 1 + libraries/networking/src/Assignment.cpp | 2 + libraries/networking/src/Assignment.h | 1 + libraries/networking/src/Node.cpp | 1 + libraries/networking/src/Node.h | 1 + libraries/networking/src/PacketHeaders.h | 5 ++ libraries/particles/src/ParticleTree.cpp | 2 +- libraries/particles/src/ParticleTree.h | 1 + libraries/script-engine/CMakeLists.txt | 1 + libraries/script-engine/src/ScriptEngine.cpp | 2 + libraries/script-engine/src/ScriptEngine.h | 6 +++ 20 files changed, 92 insertions(+), 10 deletions(-) diff --git a/assignment-client/CMakeLists.txt b/assignment-client/CMakeLists.txt index b78d4f81f9..e783001228 100644 --- a/assignment-client/CMakeLists.txt +++ b/assignment-client/CMakeLists.txt @@ -30,6 +30,7 @@ link_hifi_library(octree ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(voxels ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(fbx ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(particles ${TARGET_NAME} "${ROOT_DIR}") +link_hifi_library(models ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(metavoxels ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(networking ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(script-engine ${TARGET_NAME} "${ROOT_DIR}") diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index e39cb39307..9b4f22679a 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -25,7 +25,9 @@ #include #include #include -#include + +#include // TODO: consider moving to scriptengine.h +#include // TODO: consider moving to scriptengine.h #include "Agent.h" @@ -68,6 +70,10 @@ void Agent::readPendingDatagrams() { _scriptEngine.getParticlesScriptingInterface()->getJurisdictionListener()-> queueReceivedPacket(matchedNode, receivedPacket); break; + case NodeType::ModelServer: + _scriptEngine.getModelsScriptingInterface()->getJurisdictionListener()-> + queueReceivedPacket(matchedNode, receivedPacket); + break; } } @@ -86,6 +92,8 @@ void Agent::readPendingDatagrams() { || datagramPacketType == PacketTypeParticleErase || datagramPacketType == PacketTypeOctreeStats || datagramPacketType == PacketTypeVoxelData + || datagramPacketType == PacketTypeModelData + || datagramPacketType == PacketTypeModelErase ) { // Make sure our Node and NodeList knows we've heard from this node. SharedNodePointer sourceNode = nodeList->sendingNodeForPacket(receivedPacket); @@ -117,6 +125,10 @@ void Agent::readPendingDatagrams() { _particleViewer.processDatagram(mutablePacket, sourceNode); } + if (datagramPacketType == PacketTypeModelData || datagramPacketType == PacketTypeModelErase) { + _modelViewer.processDatagram(mutablePacket, sourceNode); + } + if (datagramPacketType == PacketTypeVoxelData) { _voxelViewer.processDatagram(mutablePacket, sourceNode); } @@ -159,7 +171,9 @@ void Agent::run() { << NodeType::AudioMixer << NodeType::AvatarMixer << NodeType::VoxelServer - << NodeType::ParticleServer); + << NodeType::ParticleServer + << NodeType::ModelServer + ); // figure out the URL for the script for this agent assignment QUrl scriptURL; diff --git a/assignment-client/src/Agent.h b/assignment-client/src/Agent.h index 9f6a8089cf..6b874a03a8 100644 --- a/assignment-client/src/Agent.h +++ b/assignment-client/src/Agent.h @@ -20,6 +20,9 @@ #include #include +#include +#include +#include #include #include #include @@ -64,6 +67,7 @@ private: ParticleTreeHeadlessViewer _particleViewer; VoxelTreeHeadlessViewer _voxelViewer; + ModelTreeHeadlessViewer _modelViewer; MixedAudioRingBuffer _receivedAudioBuffer; AvatarHashMap _avatarHashMap; diff --git a/assignment-client/src/octree/OctreeServer.cpp b/assignment-client/src/octree/OctreeServer.cpp index bd04dd85d7..5769c15ef1 100644 --- a/assignment-client/src/octree/OctreeServer.cpp +++ b/assignment-client/src/octree/OctreeServer.cpp @@ -833,7 +833,7 @@ void OctreeServer::readPendingDatagrams() { SharedNodePointer matchingNode = nodeList->sendingNodeForPacket(receivedPacket); if (packetType == getMyQueryMessageType()) { - // If we got a PacketType_VOXEL_QUERY, then we're talking to an NodeType_t_AVATAR, and we + // If we got a query packet, then we're talking to an agent, and we // need to make sure we have it in our nodeList. if (matchingNode) { nodeList->updateNodeWithDataFromPacket(matchingNode, receivedPacket); diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index e65f3968e0..77d5afffd7 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -341,7 +341,7 @@ void DomainServer::populateDefaultStaticAssignmentsExcludingTypes(const QSetaddSetOfNodeTypesToNodeInterestSet(NodeSet() << NodeType::AudioMixer << NodeType::AvatarMixer - << NodeType::VoxelServer << NodeType::ParticleServer + << NodeType::VoxelServer << NodeType::ParticleServer << NodeType::ModelServer << NodeType::MetavoxelServer); // connect to the packet sent signal of the _voxelEditSender and the _particleEditSender @@ -758,6 +758,8 @@ void Application::controlledBroadcastToNodes(const QByteArray& packet, const Nod channel = BandwidthMeter::AVATARS; break; case NodeType::VoxelServer: + case NodeType::ParticleServer: + case NodeType::ModelServer: channel = BandwidthMeter::VOXELS; break; default: @@ -1264,8 +1266,8 @@ void Application::dropEvent(QDropEvent *event) { void Application::sendPingPackets() { QByteArray pingPacket = NodeList::getInstance()->constructPingPacket(); - controlledBroadcastToNodes(pingPacket, NodeSet() << NodeType::VoxelServer - << NodeType::ParticleServer + controlledBroadcastToNodes(pingPacket, NodeSet() + << NodeType::VoxelServer << NodeType::ParticleServer << NodeType::ModelServer << NodeType::AudioMixer << NodeType::AvatarMixer << NodeType::MetavoxelServer); } @@ -2025,6 +2027,7 @@ void Application::updateMyAvatar(float deltaTime) { _lastQueriedTime = now; queryOctree(NodeType::VoxelServer, PacketTypeVoxelQuery, _voxelServerJurisdictions); queryOctree(NodeType::ParticleServer, PacketTypeParticleQuery, _particleServerJurisdictions); + queryOctree(NodeType::ModelServer, PacketTypeModelQuery, _modelServerJurisdictions); _lastQueriedViewFrustum = _viewFrustum; } } @@ -3163,7 +3166,7 @@ void Application::nodeKilled(SharedNodePointer node) { _voxelFades.push_back(fade); } - // If the voxel server is going away, remove it from our jurisdiction map so we don't send voxels to a dead server + // If the particle server is going away, remove it from our jurisdiction map so we don't send voxels to a dead server _particleServerJurisdictions.erase(_particleServerJurisdictions.find(nodeUUID)); } @@ -3174,6 +3177,37 @@ void Application::nodeKilled(SharedNodePointer node) { } _octreeSceneStatsLock.unlock(); + } else if (node->getType() == NodeType::ModelServer) { + QUuid nodeUUID = node->getUUID(); + // see if this is the first we've heard of this node... + if (_modelServerJurisdictions.find(nodeUUID) != _modelServerJurisdictions.end()) { + unsigned char* rootCode = _modelServerJurisdictions[nodeUUID].getRootOctalCode(); + VoxelPositionSize rootDetails; + voxelDetailsForCode(rootCode, rootDetails); + + qDebug("model server going away...... v[%f, %f, %f, %f]", + rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s); + + // Add the jurisditionDetails object to the list of "fade outs" + if (!Menu::getInstance()->isOptionChecked(MenuOption::DontFadeOnVoxelServerChanges)) { + VoxelFade fade(VoxelFade::FADE_OUT, NODE_KILLED_RED, NODE_KILLED_GREEN, NODE_KILLED_BLUE); + fade.voxelDetails = rootDetails; + const float slightly_smaller = 0.99f; + fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller; + _voxelFades.push_back(fade); + } + + // If the model server is going away, remove it from our jurisdiction map so we don't send voxels to a dead server + _modelServerJurisdictions.erase(_modelServerJurisdictions.find(nodeUUID)); + } + + // also clean up scene stats for that server + _octreeSceneStatsLock.lockForWrite(); + if (_octreeServerSceneStats.find(nodeUUID) != _octreeServerSceneStats.end()) { + _octreeServerSceneStats.erase(nodeUUID); + } + _octreeSceneStatsLock.unlock(); + } else if (node->getType() == NodeType::AvatarMixer) { // our avatar mixer has gone away - clear the hash of avatars _avatarManager.clearOtherAvatars(); @@ -3226,8 +3260,10 @@ int Application::parseOctreeStats(const QByteArray& packet, const SharedNodePoin NodeToJurisdictionMap* jurisdiction = NULL; if (sendingNode->getType() == NodeType::VoxelServer) { jurisdiction = &_voxelServerJurisdictions; - } else { + } else if (sendingNode->getType() == NodeType::ParticleServer) { jurisdiction = &_particleServerJurisdictions; + } else { + jurisdiction = &_modelServerJurisdictions; } diff --git a/interface/src/Application.h b/interface/src/Application.h index 325770a8df..042b6dc7f8 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -243,6 +243,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; } void pasteVoxelsToOctalCode(const unsigned char* octalCodeDestination); void skipVersion(QString latestVersion); @@ -500,6 +501,7 @@ private: NodeToJurisdictionMap _voxelServerJurisdictions; NodeToJurisdictionMap _particleServerJurisdictions; + NodeToJurisdictionMap _modelServerJurisdictions; NodeToOctreeSceneStats _octreeServerSceneStats; QReadWriteLock _octreeSceneStatsLock; diff --git a/interface/src/ui/OctreeStatsDialog.cpp b/interface/src/ui/OctreeStatsDialog.cpp index c56aa0b6ab..ceeb2cf2d7 100644 --- a/interface/src/ui/OctreeStatsDialog.cpp +++ b/interface/src/ui/OctreeStatsDialog.cpp @@ -232,6 +232,9 @@ void OctreeStatsDialog::showAllOctreeServers() { showOctreeServersOfType(serverCount, NodeType::ParticleServer, "Particle", Application::getInstance()->getParticleServerJurisdictions()); + showOctreeServersOfType(serverCount, NodeType::ModelServer, "Model", + Application::getInstance()->getModelServerJurisdictions()); + if (_voxelServerLabelsCount > serverCount) { for (int i = serverCount; i < _voxelServerLabelsCount; i++) { int serverLabel = _voxelServerLables[i]; diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 2f1c055540..a391ed239c 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -237,6 +237,7 @@ void Stats::display( int voxelServerCount = 0; foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { + // TODO: this should also support particles and models if (node->getType() == NodeType::VoxelServer) { totalPingVoxel += node->getPingMs(); voxelServerCount++; diff --git a/libraries/networking/src/Assignment.cpp b/libraries/networking/src/Assignment.cpp index dd318aad8e..620c826846 100644 --- a/libraries/networking/src/Assignment.cpp +++ b/libraries/networking/src/Assignment.cpp @@ -29,6 +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::MetavoxelServer: return Assignment::MetavoxelServerType; default: diff --git a/libraries/networking/src/Assignment.h b/libraries/networking/src/Assignment.h index f0f7e8db1a..54aebf9257 100644 --- a/libraries/networking/src/Assignment.h +++ b/libraries/networking/src/Assignment.h @@ -32,6 +32,7 @@ public: VoxelServerType, ParticleServerType, MetavoxelServerType, + ModelServerType, AllTypes }; diff --git a/libraries/networking/src/Node.cpp b/libraries/networking/src/Node.cpp index 15ee443e1f..05f425374b 100644 --- a/libraries/networking/src/Node.cpp +++ b/libraries/networking/src/Node.cpp @@ -29,6 +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::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 0f63d01525..f52cda0d0d 100644 --- a/libraries/networking/src/Node.h +++ b/libraries/networking/src/Node.h @@ -30,6 +30,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 MetavoxelServer = 'm'; const NodeType_t EnvironmentServer = 'E'; const NodeType_t Agent = 'I'; diff --git a/libraries/networking/src/PacketHeaders.h b/libraries/networking/src/PacketHeaders.h index b7535e5064..e69bc341be 100644 --- a/libraries/networking/src/PacketHeaders.h +++ b/libraries/networking/src/PacketHeaders.h @@ -61,6 +61,11 @@ enum PacketType { PacketTypeDomainConnectRequest, PacketTypeDomainServerRequireDTLS, PacketTypeNodeJsonStats, + PacketTypeModelQuery, + PacketTypeModelData, + PacketTypeModelAddOrEdit, + PacketTypeModelErase, + PacketTypeModelAddResponse, }; typedef char PacketVersion; diff --git a/libraries/particles/src/ParticleTree.cpp b/libraries/particles/src/ParticleTree.cpp index aeaf25e23c..09e034ccd1 100644 --- a/libraries/particles/src/ParticleTree.cpp +++ b/libraries/particles/src/ParticleTree.cpp @@ -320,7 +320,7 @@ public: QVector _foundParticles; }; -bool findInBoxForUpdateOperation(OctreeElement* element, void* extraData) { +bool ParticleTree::findInBoxForUpdateOperation(OctreeElement* element, void* extraData) { FindParticlesInBoxArgs* args = static_cast< FindParticlesInBoxArgs*>(extraData); const AABox& elementBox = element->getAABox(); if (elementBox.touches(args->_box)) { diff --git a/libraries/particles/src/ParticleTree.h b/libraries/particles/src/ParticleTree.h index a31c2d38aa..76b9926bdf 100644 --- a/libraries/particles/src/ParticleTree.h +++ b/libraries/particles/src/ParticleTree.h @@ -84,6 +84,7 @@ private: static bool findByIDOperation(OctreeElement* element, void* extraData); static bool findAndDeleteOperation(OctreeElement* element, void* extraData); static bool findAndUpdateParticleIDOperation(OctreeElement* element, void* extraData); + static bool findInBoxForUpdateOperation(OctreeElement* element, void* extraData); void notifyNewlyCreatedParticle(const Particle& newParticle, const SharedNodePointer& senderNode); diff --git a/libraries/script-engine/CMakeLists.txt b/libraries/script-engine/CMakeLists.txt index 48d13e7742..ee918ff864 100644 --- a/libraries/script-engine/CMakeLists.txt +++ b/libraries/script-engine/CMakeLists.txt @@ -26,6 +26,7 @@ link_hifi_library(octree ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(voxels ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(fbx ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(particles ${TARGET_NAME} "${ROOT_DIR}") +link_hifi_library(models ${TARGET_NAME} "${ROOT_DIR}") # link ZLIB find_package(ZLIB) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index b8b755e099..f4d77b13e1 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -36,6 +37,7 @@ VoxelsScriptingInterface ScriptEngine::_voxelsScriptingInterface; ParticlesScriptingInterface ScriptEngine::_particlesScriptingInterface; +ModelsScriptingInterface ScriptEngine::_modelsScriptingInterface; static QScriptValue soundConstructor(QScriptContext* context, QScriptEngine* engine) { QUrl soundURL = QUrl(context->argument(0).toString()); diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index 9ea99276d3..4a86ffafe4 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -30,7 +30,9 @@ #include "ScriptUUID.h" #include "Vec3.h" +class ModelsScriptingInterface; class ParticlesScriptingInterface; +class VoxelsScriptingInterface; const QString NO_SCRIPT(""); @@ -52,6 +54,9 @@ 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; } + /// 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("")); @@ -126,6 +131,7 @@ private: static VoxelsScriptingInterface _voxelsScriptingInterface; static ParticlesScriptingInterface _particlesScriptingInterface; + static ModelsScriptingInterface _modelsScriptingInterface; AbstractControllerScriptingInterface* _controllerScriptingInterface; AudioScriptingInterface _audioScriptingInterface;