History

Merge branch 'master' of https://github.com/worklist/hifi into metavoxels

Andrzej Kapolka committed 12 years ago

Commit 652be272 parents c1aec11 acc90bf64 files · +2952 −596Browse files

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

Unified · Split

interface/src/Application.cpp+139−35
@@ -131,6 +131,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 130 unmodified lines
131131 _voxelProcessor(),
132132 _voxelHideShowThread(&_voxels),
133133 _voxelEditSender(this),
134+ _particleEditSender(this),
134135 _packetCount(0),
135136 _packetsPerSecond(0),
136137 _bytesPerSecond(0),
@@ -206,7 +207,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 69 unmodified lines
206207 #endif
207208
208209 // tell the NodeList instance who to tell the domain server we care about
209− const char nodeTypesOfInterest[] = {NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER, NODE_TYPE_VOXEL_SERVER};
210+ const char nodeTypesOfInterest[] = {NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER, NODE_TYPE_VOXEL_SERVER,
211+ NODE_TYPE_PARTICLE_SERVER};
210212 nodeList->setNodeTypesOfInterest(nodeTypesOfInterest, sizeof(nodeTypesOfInterest));
211213
212214 QTimer* silentNodeTimer = new QTimer(this);
@@ -232,6 +234,12 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 19 unmodified lines
232234
233235 // Tell our voxel edit sender about our known jurisdictions
234236 _voxelEditSender.setVoxelServerJurisdictions(&_voxelServerJurisdictions);
237+ _particleEditSender.setServerJurisdictions(&_particleServerJurisdictions);
238+
239+ // For now we're going to set the PPS for outbound packets to be super high, this is
240+ // probably not the right long term solution. But for now, we're going to do this to
241+ // allow you to move a particle around in your hand
242+ _particleEditSender.setPacketsPerSecond(3000); // super high!!
235243 }
236244
237245 Application::~Application() {
@@ -319,6 +327,7 @@ void Application::initializeGL() { · 81 unmodified lines
319327 _voxelProcessor.initialize(_enableProcessVoxelsThread);
320328 _voxelEditSender.initialize(_enableProcessVoxelsThread);
321329 _voxelHideShowThread.initialize(_enableProcessVoxelsThread);
330+ _particleEditSender.initialize(_enableProcessVoxelsThread);
322331 if (_enableProcessVoxelsThread) {
323332 qDebug("Voxel parsing thread created.\n");
324333 }
@@ -620,6 +629,9 @@ void Application::keyPressEvent(QKeyEvent* event) { · 295 unmodified lines
620629 bool isShifted = event->modifiers().testFlag(Qt::ShiftModifier);
621630 bool isMeta = event->modifiers().testFlag(Qt::ControlModifier);
622631 switch (event->key()) {
632+ case Qt::Key_N:
633+ shootParticle();
634+ break;
623635 case Qt::Key_Shift:
624636 if (Menu::getInstance()->isOptionChecked(MenuOption::VoxelSelectMode)) {
625637 _pasteMode = true;
@@ -1229,7 +1241,8 @@ void Application::wheelEvent(QWheelEvent* event) { · 603 unmodified lines
12291241
12301242 void Application::sendPingPackets() {
12311243
1232− const char nodesToPing[] = {NODE_TYPE_VOXEL_SERVER, NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER};
1244+ const char nodesToPing[] = {NODE_TYPE_VOXEL_SERVER, NODE_TYPE_PARTICLE_SERVER,
1245+ NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER};
12331246
12341247 uint64_t currentTime = usecTimestampNow();
12351248 unsigned char pingPacket[numBytesForPacketHeader((unsigned char*) &PACKET_TYPE_PING) + sizeof(currentTime)];
@@ -1383,6 +1396,7 @@ void Application::terminate() { · 147 unmodified lines
13831396 _voxelProcessor.terminate();
13841397 _voxelHideShowThread.terminate();
13851398 _voxelEditSender.terminate();
1399+ _particleEditSender.terminate();
13861400 }
13871401
13881402 static Avatar* processAvatarMessageHeader(unsigned char*& packetData, size_t& dataBytes) {
@@ -1485,6 +1499,46 @@ void Application::removeVoxel(glm::vec3 position, · 96 unmodified lines
14851499 _voxels.deleteVoxelAt(voxel.x, voxel.y, voxel.z, voxel.s);
14861500 }
14871501
1502+void Application::shootParticle() {
1503+
1504+ glm::vec3 position = _viewFrustum.getPosition();
1505+ glm::vec3 direction = _viewFrustum.getDirection();
1506+ const float LINEAR_VELOCITY = 5.f;
1507+ glm::vec3 lookingAt = position + (direction * LINEAR_VELOCITY);
1508+
1509+ const float radius = 0.125 / TREE_SCALE;
1510+ xColor color = { 0, 255, 255};
1511+ glm::vec3 velocity = lookingAt - position;
1512+ glm::vec3 gravity = DEFAULT_GRAVITY * 0.f;
1513+ float damping = DEFAULT_DAMPING * 0.01f;
1514+ QString updateScript("");
1515+
1516+ ParticleEditHandle* particleEditHandle = makeParticle(position / (float)TREE_SCALE, radius, color,
1517+ velocity / (float)TREE_SCALE, gravity, damping, updateScript);
1518+
1519+ // If we wanted to be able to edit this particle after shooting, then we could store this value
1520+ // and use it for editing later. But we don't care about that for "shooting" and therefore we just
1521+ // clean up our memory now. deleting a ParticleEditHandle does not effect the underlying particle,
1522+ // it just removes your ability to edit that particle later.
1523+ delete particleEditHandle;
1524+}
1525+
1526+// Caller is responsible for managing this EditableParticle
1527+ParticleEditHandle* Application::newParticleEditHandle(uint32_t id) {
1528+ ParticleEditHandle* particleEditHandle = new ParticleEditHandle(&_particleEditSender, _particles.getTree());
1529+ return particleEditHandle;
1530+}
1531+
1532+// Caller is responsible for managing this EditableParticle
1533+ParticleEditHandle* Application::makeParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity,
1534+ glm::vec3 gravity, float damping, QString updateScript) {
1535+
1536+ ParticleEditHandle* particleEditHandle = newParticleEditHandle();
1537+ particleEditHandle->createParticle(position, radius, color, velocity, gravity, damping, updateScript);
1538+ return particleEditHandle;
1539+}
1540+
1541+
14881542 void Application::makeVoxel(glm::vec3 position,
14891543 float scale,
14901544 unsigned char red,
@@ -1507,18 +1561,7 @@ void Application::makeVoxel(glm::vec3 position, · 16 unmodified lines
15071561 _voxels.createVoxel(voxel.x, voxel.y, voxel.z, voxel.s,
15081562 voxel.red, voxel.green, voxel.blue,
15091563 isDestructive);
1510−
1511− // Implement voxel fade effect
1512− VoxelFade fade(VoxelFade::FADE_OUT, 1.0f, 1.0f, 1.0f);
1513− const float VOXEL_BOUNDS_ADJUST = 0.01f;
1514− float slightlyBigger = voxel.s * VOXEL_BOUNDS_ADJUST;
1515− fade.voxelDetails.x = voxel.x - slightlyBigger;
1516− fade.voxelDetails.y = voxel.y - slightlyBigger;
1517− fade.voxelDetails.z = voxel.z - slightlyBigger;
1518− fade.voxelDetails.s = voxel.s + slightlyBigger + slightlyBigger;
1519− _voxelFades.push_back(fade);
1520−
1521−}
1564+ }
15221565
15231566 const glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail _mouseVoxel) {
15241567 return glm::vec3((_mouseVoxel.x + _mouseVoxel.s / 2.f) * TREE_SCALE,
@@ -1802,6 +1845,9 @@ void Application::init() { · 277 unmodified lines
18021845 _voxels.setVoxelsAsPoints(Menu::getInstance()->isOptionChecked(MenuOption::VoxelsAsPoints));
18031846 _voxels.setDisableFastVoxelPipeline(false);
18041847 _voxels.init();
1848+
1849+ _particles.init();
1850+ _particles.setViewFrustum(getViewFrustum());
18051851
18061852 _metavoxels.init();
18071853
@@ -2290,6 +2336,7 @@ void Application::updateThreads(float deltaTime) { · 482 unmodified lines
22902336 _voxelProcessor.threadRoutine();
22912337 _voxelHideShowThread.threadRoutine();
22922338 _voxelEditSender.threadRoutine();
2339+ _particleEditSender.threadRoutine();
22932340 }
22942341 }
22952342
@@ -2480,6 +2527,8 @@ void Application::update(float deltaTime) { · 184 unmodified lines
24802527 updateDialogs(deltaTime); // update various stats dialogs if present
24812528 updateAudio(deltaTime); // Update audio stats for procedural sounds
24822529 updateCursor(deltaTime); // Handle cursor updates
2530+
2531+ _particles.update(); // update the particles...
24832532 }
24842533
24852534 void Application::updateAvatar(float deltaTime) {
@@ -2492,7 +2541,10 @@ void Application::updateAvatar(float deltaTime) { · 6 unmodified lines
24922541 _yawFromTouch = 0.f;
24932542
24942543 // apply pitch from touch
2495− _myAvatar.getHead().setMousePitch(_myAvatar.getHead().getMousePitch() + _pitchFromTouch);
2544+ _myAvatar.getHead().setMousePitch(_myAvatar.getHead().getMousePitch() +
2545+ _myAvatar.getHand().getPitchUpdate() +
2546+ _pitchFromTouch);
2547+ _myAvatar.getHand().setPitchUpdate(0.f);
24962548 _pitchFromTouch = 0.0f;
24972549
24982550 // Update my avatar's state from gyros and/or webcam
@@ -2592,10 +2644,11 @@ void Application::updateAvatar(float deltaTime) { · 93 unmodified lines
25922644 loadViewFrustum(_myCamera, _viewFrustum);
25932645
25942646 // Update my voxel servers with my current voxel query...
2595− queryVoxels();
2647+ queryOctree(NODE_TYPE_VOXEL_SERVER, PACKET_TYPE_VOXEL_QUERY, _voxelServerJurisdictions);
2648+ queryOctree(NODE_TYPE_PARTICLE_SERVER, PACKET_TYPE_PARTICLE_QUERY, _particleServerJurisdictions);
25962649 }
25972650
2598−void Application::queryVoxels() {
2651+void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, NodeToJurisdictionMap& jurisdictions) {
25992652
26002653 // if voxels are disabled, then don't send this at all...
26012654 if (!Menu::getInstance()->isOptionChecked(MenuOption::Voxels)) {
@@ -2631,8 +2684,9 @@ void Application::queryVoxels() { · 29 unmodified lines
26312684 int unknownJurisdictionServers = 0;
26322685
26332686 for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
2634− // only send to the NodeTypes that are NODE_TYPE_VOXEL_SERVER
2635− if (node->getActiveSocket() != NULL && node->getType() == NODE_TYPE_VOXEL_SERVER) {
2687+
2688+ // only send to the NodeTypes that are serverType
2689+ if (node->getActiveSocket() != NULL && node->getType() == serverType) {
26362690 totalServers++;
26372691
26382692 // get the server bounds for this server
@@ -2640,10 +2694,10 @@ void Application::queryVoxels() { · 1 unmodified line
26402694
26412695 // if we haven't heard from this voxel server, go ahead and send it a query, so we
26422696 // can get the jurisdiction...
2643− if (_voxelServerJurisdictions.find(nodeUUID) == _voxelServerJurisdictions.end()) {
2697+ if (jurisdictions.find(nodeUUID) == jurisdictions.end()) {
26442698 unknownJurisdictionServers++;
26452699 } else {
2646− const JurisdictionMap& map = (_voxelServerJurisdictions)[nodeUUID];
2700+ const JurisdictionMap& map = (jurisdictions)[nodeUUID];
26472701
26482702 unsigned char* rootCode = map.getRootOctalCode();
26492703
@@ -2662,7 +2716,7 @@ void Application::queryVoxels() { · 12 unmodified lines
26622716 }
26632717 }
26642718 }
2665−
2719+
26662720 if (wantExtraDebugging && unknownJurisdictionServers > 0) {
26672721 qDebug("Servers: total %d, in view %d, unknown jurisdiction %d \n",
26682722 totalServers, inViewServers, unknownJurisdictionServers);
@@ -2689,8 +2743,8 @@ void Application::queryVoxels() { · 20 unmodified lines
26892743 }
26902744
26912745 for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
2692− // only send to the NodeTypes that are NODE_TYPE_VOXEL_SERVER
2693− if (node->getActiveSocket() != NULL && node->getType() == NODE_TYPE_VOXEL_SERVER) {
2746+ // only send to the NodeTypes that are serverType
2747+ if (node->getActiveSocket() != NULL && node->getType() == serverType) {
26942748
26952749
26962750 // get the server bounds for this server
@@ -2701,13 +2755,13 @@ void Application::queryVoxels() { · 4 unmodified lines
27012755
27022756 // if we haven't heard from this voxel server, go ahead and send it a query, so we
27032757 // can get the jurisdiction...
2704− if (_voxelServerJurisdictions.find(nodeUUID) == _voxelServerJurisdictions.end()) {
2758+ if (jurisdictions.find(nodeUUID) == jurisdictions.end()) {
27052759 unknownView = true; // assume it's in view
27062760 if (wantExtraDebugging) {
27072761 qDebug() << "no known jurisdiction for node " << *node << ", assume it's visible.\n";
27082762 }
27092763 } else {
2710− const JurisdictionMap& map = (_voxelServerJurisdictions)[nodeUUID];
2764+ const JurisdictionMap& map = (jurisdictions)[nodeUUID];
27112765
27122766 unsigned char* rootCode = map.getRootOctalCode();
27132767
@@ -2763,7 +2817,7 @@ void Application::queryVoxels() { · 49 unmodified lines
27632817 unsigned char* endOfVoxelQueryPacket = voxelQueryPacket;
27642818
27652819 // insert packet type/version and node UUID
2766− endOfVoxelQueryPacket += populateTypeAndVersion(endOfVoxelQueryPacket, PACKET_TYPE_VOXEL_QUERY);
2820+ endOfVoxelQueryPacket += populateTypeAndVersion(endOfVoxelQueryPacket, packetType);
27672821 QByteArray ownerUUID = nodeList->getOwnerUUID().toRfc4122();
27682822 memcpy(endOfVoxelQueryPacket, ownerUUID.constData(), ownerUUID.size());
27692823 endOfVoxelQueryPacket += ownerUUID.size();
@@ -3016,7 +3070,10 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { · 246 unmodified lines
30163070 "Application::displaySide() ... metavoxels...");
30173071 _metavoxels.render();
30183072 }
3019−
3073+
3074+ // render particles...
3075+ _particles.render();
3076+
30203077 // render the ambient occlusion effect if enabled
30213078 if (Menu::getInstance()->isOptionChecked(MenuOption::AmbientOcclusion)) {
30223079 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
@@ -4078,6 +4135,7 @@ void Application::domainChanged(QString domain) { · 1055 unmodified lines
40784135 // reset our node to stats and node to jurisdiction maps... since these must be changing...
40794136 _voxelServerJurisdictions.clear();
40804137 _voxelServerSceneStats.clear();
4138+ _particleServerJurisdictions.clear();
40814139 }
40824140
40834141 void Application::nodeAdded(Node* node) {
@@ -4116,6 +4174,37 @@ void Application::nodeKilled(Node* node) { · 32 unmodified lines
41164174 }
41174175 _voxelSceneStatsLock.unlock();
41184176
4177+ } else if (node->getType() == NODE_TYPE_PARTICLE_SERVER) {
4178+ QUuid nodeUUID = node->getUUID();
4179+ // see if this is the first we've heard of this node...
4180+ if (_particleServerJurisdictions.find(nodeUUID) != _particleServerJurisdictions.end()) {
4181+ unsigned char* rootCode = _particleServerJurisdictions[nodeUUID].getRootOctalCode();
4182+ VoxelPositionSize rootDetails;
4183+ voxelDetailsForCode(rootCode, rootDetails);
4184+
4185+ printf("particle server going away...... v[%f, %f, %f, %f]\n",
4186+ rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s);
4187+
4188+ // Add the jurisditionDetails object to the list of "fade outs"
4189+ if (!Menu::getInstance()->isOptionChecked(MenuOption::DontFadeOnVoxelServerChanges)) {
4190+ VoxelFade fade(VoxelFade::FADE_OUT, NODE_KILLED_RED, NODE_KILLED_GREEN, NODE_KILLED_BLUE);
4191+ fade.voxelDetails = rootDetails;
4192+ const float slightly_smaller = 0.99;
4193+ fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller;
4194+ _voxelFades.push_back(fade);
4195+ }
4196+
4197+ // If the voxel server is going away, remove it from our jurisdiction map so we don't send voxels to a dead server
4198+ _particleServerJurisdictions.erase(nodeUUID);
4199+ }
4200+
4201+ // also clean up scene stats for that server
4202+ _voxelSceneStatsLock.lockForWrite();
4203+ if (_voxelServerSceneStats.find(nodeUUID) != _voxelServerSceneStats.end()) {
4204+ _voxelServerSceneStats.erase(nodeUUID);
4205+ }
4206+ _voxelSceneStatsLock.unlock();
4207+
41194208 } else if (node->getType() == NODE_TYPE_AGENT) {
41204209 Avatar* avatar = static_cast<Avatar*>(node->getLinkedData());
41214210 if (avatar == _lookatTargetAvatar) {
@@ -4147,10 +4236,10 @@ void Application::trackIncomingVoxelPacket(unsigned char* messageData, ssize_t m · 25 unmodified lines
41474236 }
41484237 }
41494238
4150−int Application::parseVoxelStats(unsigned char* messageData, ssize_t messageLength, const HifiSockAddr& senderSockAddr) {
4239+int Application::parseOctreeStats(unsigned char* messageData, ssize_t messageLength, const HifiSockAddr& senderSockAddr) {
41514240
41524241 // But, also identify the sender, and keep track of the contained jurisdiction root for this server
4153− Node* voxelServer = NodeList::getInstance()->nodeWithAddress(senderSockAddr);
4242+ Node* server = NodeList::getInstance()->nodeWithAddress(senderSockAddr);
41544243
41554244 // parse the incoming stats datas stick it in a temporary object for now, while we
41564245 // determine which server it belongs to
@@ -4158,8 +4247,8 @@ int Application::parseVoxelStats(unsigned char* messageData, ssize_t messageLeng · 1 unmodified line
41584247 int statsMessageLength = temp.unpackFromMessage(messageData, messageLength);
41594248
41604249 // quick fix for crash... why would voxelServer be NULL?
4161− if (voxelServer) {
4162− QUuid nodeUUID = voxelServer->getUUID();
4250+ if (server) {
4251+ QUuid nodeUUID = server->getUUID();
41634252
41644253 // now that we know the node ID, let's add these stats to the stats for that node...
41654254 _voxelSceneStatsLock.lockForWrite();
@@ -4174,8 +4263,16 @@ int Application::parseVoxelStats(unsigned char* messageData, ssize_t messageLeng · 8 unmodified lines
41744263 voxelDetailsForCode(temp.getJurisdictionRoot(), rootDetails);
41754264
41764265 // 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",
4266+ NodeToJurisdictionMap* jurisdiction = NULL;
4267+ if (server->getType() == NODE_TYPE_VOXEL_SERVER) {
4268+ jurisdiction = &_voxelServerJurisdictions;
4269+ } else {
4270+ jurisdiction = &_particleServerJurisdictions;
4271+ }
4272+
4273+
4274+ if (jurisdiction->find(nodeUUID) == jurisdiction->end()) {
4275+ printf("stats from new server... v[%f, %f, %f, %f]\n",
41794276 rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s);
41804277
41814278 // Add the jurisditionDetails object to the list of "fade outs"
@@ -4193,7 +4290,7 @@ int Application::parseVoxelStats(unsigned char* messageData, ssize_t messageLeng · 11 unmodified lines
41934290 // details from the VoxelSceneStats to construct the JurisdictionMap
41944291 JurisdictionMap jurisdictionMap;
41954292 jurisdictionMap.copyContents(temp.getJurisdictionRoot(), temp.getJurisdictionEndNodes());
4196− _voxelServerJurisdictions[nodeUUID] = jurisdictionMap;
4293+ (*jurisdiction)[nodeUUID] = jurisdictionMap;
41974294 }
41984295 return statsMessageLength;
41994296 }
@@ -4229,6 +4326,13 @@ void* Application::networkReceive(void* args) { · 29 unmodified lines
42294326 QMetaObject::invokeMethod(&app->_audio, "addReceivedAudioToBuffer", Qt::QueuedConnection,
42304327 Q_ARG(QByteArray, QByteArray((char*) app->_incomingPacket, bytesReceived)));
42314328 break;
4329+
4330+ case PACKET_TYPE_PARTICLE_ADD_RESPONSE:
4331+ // look up our ParticleEditHanders....
4332+ ParticleEditHandle::handleAddResponse(app->_incomingPacket, bytesReceived);
4333+ break;
4334+
4335+ case PACKET_TYPE_PARTICLE_DATA:
42324336 case PACKET_TYPE_VOXEL_DATA:
42334337 case PACKET_TYPE_VOXEL_ERASE:
42344338 case PACKET_TYPE_OCTREE_STATS:

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