Showing the changes to interface/src/Application.cpp (1 of 7 files). Show all
Unified · Split
| @@ -129,6 +129,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 128 unmodified lines | ||
| 129 | 129 | _voxelProcessor(), |
| 130 | 130 | _voxelHideShowThread(&_voxels), |
| 131 | 131 | _voxelEditSender(this), |
| 132 | + _particleEditSender(this), | |
| 132 | 133 | _packetCount(0), |
| 133 | 134 | _packetsPerSecond(0), |
| 134 | 135 | _bytesPerSecond(0), |
| @@ -231,6 +232,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 96 unmodified lines | ||
| 231 | 232 | |
| 232 | 233 | // Tell our voxel edit sender about our known jurisdictions |
| 233 | 234 | _voxelEditSender.setVoxelServerJurisdictions(&_voxelServerJurisdictions); |
| 235 | + _particleEditSender.setServerJurisdictions(&_particleServerJurisdictions); | |
| 234 | 236 | } |
| 235 | 237 | |
| 236 | 238 | Application::~Application() { |
| @@ -315,6 +317,7 @@ void Application::initializeGL() { · 78 unmodified lines | ||
| 315 | 317 | _voxelProcessor.initialize(_enableProcessVoxelsThread); |
| 316 | 318 | _voxelEditSender.initialize(_enableProcessVoxelsThread); |
| 317 | 319 | _voxelHideShowThread.initialize(_enableProcessVoxelsThread); |
| 320 | + _particleEditSender.initialize(_enableProcessVoxelsThread); | |
| 318 | 321 | if (_enableProcessVoxelsThread) { |
| 319 | 322 | qDebug("Voxel parsing thread created.\n"); |
| 320 | 323 | } |
| @@ -614,6 +617,9 @@ void Application::keyPressEvent(QKeyEvent* event) { · 293 unmodified lines | ||
| 614 | 617 | bool isShifted = event->modifiers().testFlag(Qt::ShiftModifier); |
| 615 | 618 | bool isMeta = event->modifiers().testFlag(Qt::ControlModifier); |
| 616 | 619 | switch (event->key()) { |
| 620 | + case Qt::Key_N: | |
| 621 | + shootParticle(); | |
| 622 | + break; | |
| 617 | 623 | case Qt::Key_Shift: |
| 618 | 624 | if (Menu::getInstance()->isOptionChecked(MenuOption::VoxelSelectMode)) { |
| 619 | 625 | _pasteMode = true; |
| @@ -1378,6 +1384,7 @@ void Application::terminate() { · 758 unmodified lines | ||
| 1378 | 1384 | _voxelProcessor.terminate(); |
| 1379 | 1385 | _voxelHideShowThread.terminate(); |
| 1380 | 1386 | _voxelEditSender.terminate(); |
| 1387 | + _particleEditSender.terminate(); | |
| 1381 | 1388 | } |
| 1382 | 1389 | |
| 1383 | 1390 | static Avatar* processAvatarMessageHeader(unsigned char*& packetData, size_t& dataBytes) { |
| @@ -1476,6 +1483,33 @@ void Application::removeVoxel(glm::vec3 position, · 92 unmodified lines | ||
| 1476 | 1483 | _voxels.deleteVoxelAt(voxel.x, voxel.y, voxel.z, voxel.s); |
| 1477 | 1484 | } |
| 1478 | 1485 | |
| 1486 | +void Application::shootParticle() { | |
| 1487 | + | |
| 1488 | + glm::vec3 position = _viewFrustum.getOffsetPosition(); | |
| 1489 | + glm::vec3 direction = _viewFrustum.getOffsetDirection(); | |
| 1490 | + glm::vec3 lookingAt = position + (direction * 0.2f); | |
| 1491 | + | |
| 1492 | + const float radius = 0.5 / TREE_SCALE; | |
| 1493 | + xColor color = { 255, 0, 0}; | |
| 1494 | + glm::vec3 velocity = lookingAt - position; | |
| 1495 | + glm::vec3 gravity = DEFAULT_GRAVITY; | |
| 1496 | + float damping = DEFAULT_DAMPING; | |
| 1497 | + QString updateScript(""); | |
| 1498 | + makeParticle(position, radius, color, velocity, gravity, damping, updateScript); | |
| 1499 | +} | |
| 1500 | + | |
| 1501 | +void Application::makeParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity, | |
| 1502 | + glm::vec3 gravity, float damping, QString updateScript) { | |
| 1503 | + | |
| 1504 | + // setup a ParticleDetail struct with the data | |
| 1505 | + ParticleDetail addParticleDetail = { position, radius, {color.red, color.green, color.blue }, | |
| 1506 | + velocity, gravity, damping, updateScript }; | |
| 1507 | + | |
| 1508 | + // queue the packet | |
| 1509 | + _particleEditSender.queueParticleEditMessages(PACKET_TYPE_PARTICLE_ADD, 1, &addParticleDetail); | |
| 1510 | +} | |
| 1511 | + | |
| 1512 | + | |
| 1479 | 1513 | void Application::makeVoxel(glm::vec3 position, |
| 1480 | 1514 | float scale, |
| 1481 | 1515 | unsigned char red, |
| @@ -2285,6 +2319,7 @@ void Application::updateThreads(float deltaTime) { · 803 unmodified lines | ||
| 2285 | 2319 | _voxelProcessor.threadRoutine(); |
| 2286 | 2320 | _voxelHideShowThread.threadRoutine(); |
| 2287 | 2321 | _voxelEditSender.threadRoutine(); |
| 2322 | + _particleEditSender.threadRoutine(); | |
| 2288 | 2323 | } |
| 2289 | 2324 | } |
| 2290 | 2325 | |
| @@ -2594,11 +2629,11 @@ void Application::updateAvatar(float deltaTime) { · 303 unmodified lines | ||
| 2594 | 2629 | loadViewFrustum(_myCamera, _viewFrustum); |
| 2595 | 2630 | |
| 2596 | 2631 | // Update my voxel servers with my current voxel query... |
| 2597 | − queryOctree(NODE_TYPE_VOXEL_SERVER, PACKET_TYPE_VOXEL_QUERY); | |
| 2598 | − queryOctree(NODE_TYPE_PARTICLE_SERVER, PACKET_TYPE_PARTICLE_QUERY); | |
| 2632 | + queryOctree(NODE_TYPE_VOXEL_SERVER, PACKET_TYPE_VOXEL_QUERY, _voxelServerJurisdictions); | |
| 2633 | + queryOctree(NODE_TYPE_PARTICLE_SERVER, PACKET_TYPE_PARTICLE_QUERY, _particleServerJurisdictions); | |
| 2599 | 2634 | } |
| 2600 | 2635 | |
| 2601 | −void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType) { | |
| 2636 | +void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, NodeToJurisdictionMap& jurisdictions) { | |
| 2602 | 2637 | |
| 2603 | 2638 | // if voxels are disabled, then don't send this at all... |
| 2604 | 2639 | if (!Menu::getInstance()->isOptionChecked(MenuOption::Voxels)) { |
| @@ -2644,10 +2679,10 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType) { · 39 unmodified lines | ||
| 2644 | 2679 | |
| 2645 | 2680 | // if we haven't heard from this voxel server, go ahead and send it a query, so we |
| 2646 | 2681 | // can get the jurisdiction... |
| 2647 | − if (_voxelServerJurisdictions.find(nodeUUID) == _voxelServerJurisdictions.end()) { | |
| 2682 | + if (jurisdictions.find(nodeUUID) == jurisdictions.end()) { | |
| 2648 | 2683 | unknownJurisdictionServers++; |
| 2649 | 2684 | } else { |
| 2650 | − const JurisdictionMap& map = (_voxelServerJurisdictions)[nodeUUID]; | |
| 2685 | + const JurisdictionMap& map = (jurisdictions)[nodeUUID]; | |
| 2651 | 2686 | |
| 2652 | 2687 | unsigned char* rootCode = map.getRootOctalCode(); |
| 2653 | 2688 | |
| @@ -2705,13 +2740,13 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType) { · 51 unmodified lines | ||
| 2705 | 2740 | |
| 2706 | 2741 | // if we haven't heard from this voxel server, go ahead and send it a query, so we |
| 2707 | 2742 | // can get the jurisdiction... |
| 2708 | − if (_voxelServerJurisdictions.find(nodeUUID) == _voxelServerJurisdictions.end()) { | |
| 2743 | + if (jurisdictions.find(nodeUUID) == jurisdictions.end()) { | |
| 2709 | 2744 | unknownView = true; // assume it's in view |
| 2710 | 2745 | if (wantExtraDebugging) { |
| 2711 | 2746 | qDebug() << "no known jurisdiction for node " << *node << ", assume it's visible.\n"; |
| 2712 | 2747 | } |
| 2713 | 2748 | } else { |
| 2714 | − const JurisdictionMap& map = (_voxelServerJurisdictions)[nodeUUID]; | |
| 2749 | + const JurisdictionMap& map = (jurisdictions)[nodeUUID]; | |
| 2715 | 2750 | |
| 2716 | 2751 | unsigned char* rootCode = map.getRootOctalCode(); |
| 2717 | 2752 | |
| @@ -4078,6 +4113,7 @@ void Application::domainChanged(QString domain) { · 1360 unmodified lines | ||
| 4078 | 4113 | // reset our node to stats and node to jurisdiction maps... since these must be changing... |
| 4079 | 4114 | _voxelServerJurisdictions.clear(); |
| 4080 | 4115 | _voxelServerSceneStats.clear(); |
| 4116 | + _particleServerJurisdictions.clear(); | |
| 4081 | 4117 | } |
| 4082 | 4118 | |
| 4083 | 4119 | void Application::nodeAdded(Node* node) { |
| @@ -4116,6 +4152,37 @@ void Application::nodeKilled(Node* node) { · 32 unmodified lines | ||
| 4116 | 4152 | } |
| 4117 | 4153 | _voxelSceneStatsLock.unlock(); |
| 4118 | 4154 | |
| 4155 | + } else if (node->getType() == NODE_TYPE_PARTICLE_SERVER) { | |
| 4156 | + QUuid nodeUUID = node->getUUID(); | |
| 4157 | + // see if this is the first we've heard of this node... | |
| 4158 | + if (_particleServerJurisdictions.find(nodeUUID) != _particleServerJurisdictions.end()) { | |
| 4159 | + unsigned char* rootCode = _particleServerJurisdictions[nodeUUID].getRootOctalCode(); | |
| 4160 | + VoxelPositionSize rootDetails; | |
| 4161 | + voxelDetailsForCode(rootCode, rootDetails); | |
| 4162 | + | |
| 4163 | + printf("particle server going away...... v[%f, %f, %f, %f]\n", | |
| 4164 | + rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s); | |
| 4165 | + | |
| 4166 | + // Add the jurisditionDetails object to the list of "fade outs" | |
| 4167 | + if (!Menu::getInstance()->isOptionChecked(MenuOption::DontFadeOnVoxelServerChanges)) { | |
| 4168 | + VoxelFade fade(VoxelFade::FADE_OUT, NODE_KILLED_RED, NODE_KILLED_GREEN, NODE_KILLED_BLUE); | |
| 4169 | + fade.voxelDetails = rootDetails; | |
| 4170 | + const float slightly_smaller = 0.99; | |
| 4171 | + fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller; | |
| 4172 | + _voxelFades.push_back(fade); | |
| 4173 | + } | |
| 4174 | + | |
| 4175 | + // If the voxel server is going away, remove it from our jurisdiction map so we don't send voxels to a dead server | |
| 4176 | + _particleServerJurisdictions.erase(nodeUUID); | |
| 4177 | + } | |
| 4178 | + | |
| 4179 | + // also clean up scene stats for that server | |
| 4180 | + _voxelSceneStatsLock.lockForWrite(); | |
| 4181 | + if (_voxelServerSceneStats.find(nodeUUID) != _voxelServerSceneStats.end()) { | |
| 4182 | + _voxelServerSceneStats.erase(nodeUUID); | |
| 4183 | + } | |
| 4184 | + _voxelSceneStatsLock.unlock(); | |
| 4185 | + | |
| 4119 | 4186 | } else if (node->getType() == NODE_TYPE_AGENT) { |
| 4120 | 4187 | Avatar* avatar = static_cast<Avatar*>(node->getLinkedData()); |
| 4121 | 4188 | if (avatar == _lookatTargetAvatar) { |
| @@ -4147,10 +4214,10 @@ void Application::trackIncomingVoxelPacket(unsigned char* messageData, ssize_t m · 25 unmodified lines | ||
| 4147 | 4214 | } |
| 4148 | 4215 | } |
| 4149 | 4216 | |
| 4150 | −int Application::parseVoxelStats(unsigned char* messageData, ssize_t messageLength, const HifiSockAddr& senderSockAddr) { | |
| 4217 | +int Application::parseOctreeStats(unsigned char* messageData, ssize_t messageLength, const HifiSockAddr& senderSockAddr) { | |
| 4151 | 4218 | |
| 4152 | 4219 | // But, also identify the sender, and keep track of the contained jurisdiction root for this server |
| 4153 | − Node* voxelServer = NodeList::getInstance()->nodeWithAddress(senderSockAddr); | |
| 4220 | + Node* server = NodeList::getInstance()->nodeWithAddress(senderSockAddr); | |
| 4154 | 4221 | |
| 4155 | 4222 | // parse the incoming stats datas stick it in a temporary object for now, while we |
| 4156 | 4223 | // determine which server it belongs to |
| @@ -4158,8 +4225,8 @@ int Application::parseVoxelStats(unsigned char* messageData, ssize_t messageLeng · 1 unmodified line | ||
| 4158 | 4225 | int statsMessageLength = temp.unpackFromMessage(messageData, messageLength); |
| 4159 | 4226 | |
| 4160 | 4227 | // quick fix for crash... why would voxelServer be NULL? |
| 4161 | − if (voxelServer) { | |
| 4162 | − QUuid nodeUUID = voxelServer->getUUID(); | |
| 4228 | + if (server) { | |
| 4229 | + QUuid nodeUUID = server->getUUID(); | |
| 4163 | 4230 | |
| 4164 | 4231 | // now that we know the node ID, let's add these stats to the stats for that node... |
| 4165 | 4232 | _voxelSceneStatsLock.lockForWrite(); |
| @@ -4174,8 +4241,16 @@ int Application::parseVoxelStats(unsigned char* messageData, ssize_t messageLeng · 8 unmodified lines | ||
| 4174 | 4241 | voxelDetailsForCode(temp.getJurisdictionRoot(), rootDetails); |
| 4175 | 4242 | |
| 4176 | 4243 | // see if this is the first we've heard of this node... |
| 4177 | − if (_voxelServerJurisdictions.find(nodeUUID) == _voxelServerJurisdictions.end()) { | |
| 4178 | − printf("stats from new voxel server... v[%f, %f, %f, %f]\n", | |
| 4244 | + NodeToJurisdictionMap* jurisdiction = NULL; | |
| 4245 | + if (server->getType() == NODE_TYPE_VOXEL_SERVER) { | |
| 4246 | + jurisdiction = &_voxelServerJurisdictions; | |
| 4247 | + } else { | |
| 4248 | + jurisdiction = &_particleServerJurisdictions; | |
| 4249 | + } | |
| 4250 | + | |
| 4251 | + | |
| 4252 | + if (jurisdiction->find(nodeUUID) == jurisdiction->end()) { | |
| 4253 | + printf("stats from new server... v[%f, %f, %f, %f]\n", | |
| 4179 | 4254 | rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s); |
| 4180 | 4255 | |
| 4181 | 4256 | // Add the jurisditionDetails object to the list of "fade outs" |
| @@ -4193,7 +4268,7 @@ int Application::parseVoxelStats(unsigned char* messageData, ssize_t messageLeng · 11 unmodified lines | ||
| 4193 | 4268 | // details from the VoxelSceneStats to construct the JurisdictionMap |
| 4194 | 4269 | JurisdictionMap jurisdictionMap; |
| 4195 | 4270 | jurisdictionMap.copyContents(temp.getJurisdictionRoot(), temp.getJurisdictionEndNodes()); |
| 4196 | − _voxelServerJurisdictions[nodeUUID] = jurisdictionMap; | |
| 4271 | + (*jurisdiction)[nodeUUID] = jurisdictionMap; | |
| 4197 | 4272 | } |
| 4198 | 4273 | return statsMessageLength; |
| 4199 | 4274 | } |