History

CR cleanup and add shootParticle() to application

ZappoMan committed 12 years ago

Commit ae1576b1 parent 55c3e817 files · +103 −41Browse files

Showing the changes to interface/src/Application.cpp (1 of 7 files). Show all

Unified · Split

interface/src/Application.cpp+89−14
@@ -129,6 +129,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 128 unmodified lines
129129 _voxelProcessor(),
130130 _voxelHideShowThread(&_voxels),
131131 _voxelEditSender(this),
132+ _particleEditSender(this),
132133 _packetCount(0),
133134 _packetsPerSecond(0),
134135 _bytesPerSecond(0),
@@ -231,6 +232,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 96 unmodified lines
231232
232233 // Tell our voxel edit sender about our known jurisdictions
233234 _voxelEditSender.setVoxelServerJurisdictions(&_voxelServerJurisdictions);
235+ _particleEditSender.setServerJurisdictions(&_particleServerJurisdictions);
234236 }
235237
236238 Application::~Application() {
@@ -315,6 +317,7 @@ void Application::initializeGL() { · 78 unmodified lines
315317 _voxelProcessor.initialize(_enableProcessVoxelsThread);
316318 _voxelEditSender.initialize(_enableProcessVoxelsThread);
317319 _voxelHideShowThread.initialize(_enableProcessVoxelsThread);
320+ _particleEditSender.initialize(_enableProcessVoxelsThread);
318321 if (_enableProcessVoxelsThread) {
319322 qDebug("Voxel parsing thread created.\n");
320323 }
@@ -614,6 +617,9 @@ void Application::keyPressEvent(QKeyEvent* event) { · 293 unmodified lines
614617 bool isShifted = event->modifiers().testFlag(Qt::ShiftModifier);
615618 bool isMeta = event->modifiers().testFlag(Qt::ControlModifier);
616619 switch (event->key()) {
620+ case Qt::Key_N:
621+ shootParticle();
622+ break;
617623 case Qt::Key_Shift:
618624 if (Menu::getInstance()->isOptionChecked(MenuOption::VoxelSelectMode)) {
619625 _pasteMode = true;
@@ -1378,6 +1384,7 @@ void Application::terminate() { · 758 unmodified lines
13781384 _voxelProcessor.terminate();
13791385 _voxelHideShowThread.terminate();
13801386 _voxelEditSender.terminate();
1387+ _particleEditSender.terminate();
13811388 }
13821389
13831390 static Avatar* processAvatarMessageHeader(unsigned char*& packetData, size_t& dataBytes) {
@@ -1476,6 +1483,33 @@ void Application::removeVoxel(glm::vec3 position, · 92 unmodified lines
14761483 _voxels.deleteVoxelAt(voxel.x, voxel.y, voxel.z, voxel.s);
14771484 }
14781485
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+
14791513 void Application::makeVoxel(glm::vec3 position,
14801514 float scale,
14811515 unsigned char red,
@@ -2285,6 +2319,7 @@ void Application::updateThreads(float deltaTime) { · 803 unmodified lines
22852319 _voxelProcessor.threadRoutine();
22862320 _voxelHideShowThread.threadRoutine();
22872321 _voxelEditSender.threadRoutine();
2322+ _particleEditSender.threadRoutine();
22882323 }
22892324 }
22902325
@@ -2594,11 +2629,11 @@ void Application::updateAvatar(float deltaTime) { · 303 unmodified lines
25942629 loadViewFrustum(_myCamera, _viewFrustum);
25952630
25962631 // 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);
25992634 }
26002635
2601−void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType) {
2636+void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, NodeToJurisdictionMap& jurisdictions) {
26022637
26032638 // if voxels are disabled, then don't send this at all...
26042639 if (!Menu::getInstance()->isOptionChecked(MenuOption::Voxels)) {
@@ -2644,10 +2679,10 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType) { · 39 unmodified lines
26442679
26452680 // if we haven't heard from this voxel server, go ahead and send it a query, so we
26462681 // can get the jurisdiction...
2647− if (_voxelServerJurisdictions.find(nodeUUID) == _voxelServerJurisdictions.end()) {
2682+ if (jurisdictions.find(nodeUUID) == jurisdictions.end()) {
26482683 unknownJurisdictionServers++;
26492684 } else {
2650− const JurisdictionMap& map = (_voxelServerJurisdictions)[nodeUUID];
2685+ const JurisdictionMap& map = (jurisdictions)[nodeUUID];
26512686
26522687 unsigned char* rootCode = map.getRootOctalCode();
26532688
@@ -2705,13 +2740,13 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType) { · 51 unmodified lines
27052740
27062741 // if we haven't heard from this voxel server, go ahead and send it a query, so we
27072742 // can get the jurisdiction...
2708− if (_voxelServerJurisdictions.find(nodeUUID) == _voxelServerJurisdictions.end()) {
2743+ if (jurisdictions.find(nodeUUID) == jurisdictions.end()) {
27092744 unknownView = true; // assume it's in view
27102745 if (wantExtraDebugging) {
27112746 qDebug() << "no known jurisdiction for node " << *node << ", assume it's visible.\n";
27122747 }
27132748 } else {
2714− const JurisdictionMap& map = (_voxelServerJurisdictions)[nodeUUID];
2749+ const JurisdictionMap& map = (jurisdictions)[nodeUUID];
27152750
27162751 unsigned char* rootCode = map.getRootOctalCode();
27172752
@@ -4078,6 +4113,7 @@ void Application::domainChanged(QString domain) { · 1360 unmodified lines
40784113 // reset our node to stats and node to jurisdiction maps... since these must be changing...
40794114 _voxelServerJurisdictions.clear();
40804115 _voxelServerSceneStats.clear();
4116+ _particleServerJurisdictions.clear();
40814117 }
40824118
40834119 void Application::nodeAdded(Node* node) {
@@ -4116,6 +4152,37 @@ void Application::nodeKilled(Node* node) { · 32 unmodified lines
41164152 }
41174153 _voxelSceneStatsLock.unlock();
41184154
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+
41194186 } else if (node->getType() == NODE_TYPE_AGENT) {
41204187 Avatar* avatar = static_cast<Avatar*>(node->getLinkedData());
41214188 if (avatar == _lookatTargetAvatar) {
@@ -4147,10 +4214,10 @@ void Application::trackIncomingVoxelPacket(unsigned char* messageData, ssize_t m · 25 unmodified lines
41474214 }
41484215 }
41494216
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) {
41514218
41524219 // 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);
41544221
41554222 // parse the incoming stats datas stick it in a temporary object for now, while we
41564223 // determine which server it belongs to
@@ -4158,8 +4225,8 @@ int Application::parseVoxelStats(unsigned char* messageData, ssize_t messageLeng · 1 unmodified line
41584225 int statsMessageLength = temp.unpackFromMessage(messageData, messageLength);
41594226
41604227 // 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();
41634230
41644231 // now that we know the node ID, let's add these stats to the stats for that node...
41654232 _voxelSceneStatsLock.lockForWrite();
@@ -4174,8 +4241,16 @@ int Application::parseVoxelStats(unsigned char* messageData, ssize_t messageLeng · 8 unmodified lines
41744241 voxelDetailsForCode(temp.getJurisdictionRoot(), rootDetails);
41754242
41764243 // 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",
41794254 rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s);
41804255
41814256 // 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
41934268 // details from the VoxelSceneStats to construct the JurisdictionMap
41944269 JurisdictionMap jurisdictionMap;
41954270 jurisdictionMap.copyContents(temp.getJurisdictionRoot(), temp.getJurisdictionEndNodes());
4196− _voxelServerJurisdictions[nodeUUID] = jurisdictionMap;
4271+ (*jurisdiction)[nodeUUID] = jurisdictionMap;
41974272 }
41984273 return statsMessageLength;
41994274 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t