From ce41477f466bcb63b4954b8580695e5cad90f0fe Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 7 Nov 2013 15:23:23 -0800 Subject: [PATCH 01/12] fix VS crash on domain server restart --- .../voxel-server-library/src/VoxelServer.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libraries/voxel-server-library/src/VoxelServer.cpp b/libraries/voxel-server-library/src/VoxelServer.cpp index de421341f3..6457e261b3 100644 --- a/libraries/voxel-server-library/src/VoxelServer.cpp +++ b/libraries/voxel-server-library/src/VoxelServer.cpp @@ -611,6 +611,22 @@ void VoxelServer::run() { } } qDebug() << "VoxelServer::run()... AFTER loop...\n"; + + // walk the node list and disconnect any connected agent nodes + for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { + // only send to the NodeTypes that are NODE_TYPE_VOXEL_SERVER + if (node->getType() == NODE_TYPE_AGENT) { + node->lock(); + VoxelNodeData* nodeData = (VoxelNodeData*) node->getLinkedData(); + if (nodeData) { + qDebug() << "VoxelServer::run()... unlinking node...\n"; + node->setLinkedData(NULL); + delete nodeData; + } + node->unlock(); + } + } + // call NodeList::clear() so that all of our node specific objects, including our sending threads, are // properly shutdown and cleaned up. From 385865c6c1f2d17b56d67ad2a9517d9bd5af4e45 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 7 Nov 2013 15:25:21 -0800 Subject: [PATCH 02/12] remove comment --- libraries/voxel-server-library/src/VoxelServer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/voxel-server-library/src/VoxelServer.cpp b/libraries/voxel-server-library/src/VoxelServer.cpp index 6457e261b3..a6fff4b08e 100644 --- a/libraries/voxel-server-library/src/VoxelServer.cpp +++ b/libraries/voxel-server-library/src/VoxelServer.cpp @@ -614,7 +614,6 @@ void VoxelServer::run() { // walk the node list and disconnect any connected agent nodes for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { - // only send to the NodeTypes that are NODE_TYPE_VOXEL_SERVER if (node->getType() == NODE_TYPE_AGENT) { node->lock(); VoxelNodeData* nodeData = (VoxelNodeData*) node->getLinkedData(); From fffbdb1db0565669b47f88a95faeada84a6ad1eb Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 7 Nov 2013 15:52:19 -0800 Subject: [PATCH 03/12] reverted code --- .../voxel-server-library/src/VoxelServer.cpp | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/libraries/voxel-server-library/src/VoxelServer.cpp b/libraries/voxel-server-library/src/VoxelServer.cpp index a6fff4b08e..0b868d8908 100644 --- a/libraries/voxel-server-library/src/VoxelServer.cpp +++ b/libraries/voxel-server-library/src/VoxelServer.cpp @@ -612,21 +612,6 @@ void VoxelServer::run() { } qDebug() << "VoxelServer::run()... AFTER loop...\n"; - // walk the node list and disconnect any connected agent nodes - for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { - if (node->getType() == NODE_TYPE_AGENT) { - node->lock(); - VoxelNodeData* nodeData = (VoxelNodeData*) node->getLinkedData(); - if (nodeData) { - qDebug() << "VoxelServer::run()... unlinking node...\n"; - node->setLinkedData(NULL); - delete nodeData; - } - node->unlock(); - } - } - - // call NodeList::clear() so that all of our node specific objects, including our sending threads, are // properly shutdown and cleaned up. NodeList::getInstance()->clear(); From 8043970df78b2a3d0f7a5872a8167190c8899d6f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 8 Nov 2013 02:22:10 -0800 Subject: [PATCH 04/12] bug fixes to JurisdictionListener, PacketSender, addition of packetsToSendCount() to Voxels JS --- .../src/voxels/VoxelScriptingInterface.cpp | 7 +++- .../src/voxels/VoxelScriptingInterface.h | 4 +++ libraries/shared/src/PacketSender.cpp | 35 ++++++++++++++----- .../shared/src/ReceivedPacketProcessor.cpp | 9 ++++- .../shared/src/ReceivedPacketProcessor.h | 5 ++- libraries/voxels/src/JurisdictionListener.cpp | 9 +++-- libraries/voxels/src/JurisdictionListener.h | 2 +- 7 files changed, 56 insertions(+), 15 deletions(-) diff --git a/assignment-client/src/voxels/VoxelScriptingInterface.cpp b/assignment-client/src/voxels/VoxelScriptingInterface.cpp index 5b1a296aa7..687b0fe0b8 100644 --- a/assignment-client/src/voxels/VoxelScriptingInterface.cpp +++ b/assignment-client/src/voxels/VoxelScriptingInterface.cpp @@ -40,4 +40,9 @@ void VoxelScriptingInterface::queueVoxelDelete(float x, float y, float z, float VoxelDetail deleteVoxelDetail = {x, y, z, scale, 0, 0, 0}; _voxelPacketSender.queueVoxelEditMessages(PACKET_TYPE_ERASE_VOXEL, 1, &deleteVoxelDetail); -} \ No newline at end of file +} + + +int VoxelScriptingInterface::packetsToSendCount() const { + return _voxelPacketSender.packetsToSendCount(); +} diff --git a/assignment-client/src/voxels/VoxelScriptingInterface.h b/assignment-client/src/voxels/VoxelScriptingInterface.h index a2c18b8018..60a4fbc0b1 100644 --- a/assignment-client/src/voxels/VoxelScriptingInterface.h +++ b/assignment-client/src/voxels/VoxelScriptingInterface.h @@ -49,6 +49,10 @@ public slots: /// \param z the z-coordinate of the voxel (in VS space) /// \param scale the scale of the voxel (in VS space) void queueVoxelDelete(float x, float y, float z, float scale); + + /// get the current number of pending, queued, but unsent packets + int packetsToSendCount() const; + private: /// attached VoxelEditPacketSender that handles queuing and sending of packets to VS VoxelEditPacketSender _voxelPacketSender; diff --git a/libraries/shared/src/PacketSender.cpp b/libraries/shared/src/PacketSender.cpp index c03ef21bea..76d4ac47ad 100644 --- a/libraries/shared/src/PacketSender.cpp +++ b/libraries/shared/src/PacketSender.cpp @@ -39,8 +39,11 @@ void PacketSender::queuePacketForSending(sockaddr& address, unsigned char* packe } bool PacketSender::process() { + bool hasSlept = false; uint64_t USECS_PER_SECOND = 1000 * 1000; + uint64_t USECS_SMALL_ADJUST = 2 * 1000; // approaximate 2ms uint64_t SEND_INTERVAL_USECS = (_packetsPerSecond == 0) ? USECS_PER_SECOND : (USECS_PER_SECOND / _packetsPerSecond); + uint64_t INTERVAL_SLEEP_USECS = (SEND_INTERVAL_USECS > USECS_SMALL_ADJUST) ? SEND_INTERVAL_USECS - USECS_SMALL_ADJUST : SEND_INTERVAL_USECS; // keep track of our process call times, so we have a reliable account of how often our caller calls us uint64_t now = usecTimestampNow(); @@ -50,7 +53,8 @@ bool PacketSender::process() { if (_packets.size() == 0) { if (isThreaded()) { - usleep(SEND_INTERVAL_USECS); + usleep(INTERVAL_SLEEP_USECS); + hasSlept = true; } else { return isStillRunning(); // in non-threaded mode, if there's nothing to do, just return, keep running till they terminate us } @@ -62,6 +66,7 @@ bool PacketSender::process() { // if we're in non-threaded mode, then we actually need to determine how many packets to send per call to process // based on how often we get called... We do this by keeping a running average of our call times, and we determine // how many packets to send per call + if (!isThreaded()) { int averageCallTime; const int TRUST_AVERAGE_AFTER = AVERAGE_CALL_TIME_SAMPLES * 2; @@ -89,8 +94,6 @@ bool PacketSender::process() { int packetsLeft = _packets.size(); bool keepGoing = packetsLeft > 0; while (keepGoing) { - uint64_t SEND_INTERVAL_USECS = (_packetsPerSecond == 0) ? USECS_PER_SECOND : (USECS_PER_SECOND / _packetsPerSecond); - lock(); NetworkPacket& packet = _packets.front(); NetworkPacket temporary = packet; // make a copy @@ -117,14 +120,15 @@ bool PacketSender::process() { if (keepGoing) { now = usecTimestampNow(); uint64_t elapsed = now - _lastSendTime; - int usecToSleep = SEND_INTERVAL_USECS - elapsed; - + int usecToSleep = INTERVAL_SLEEP_USECS - elapsed; + // we only sleep in non-threaded mode if (usecToSleep > 0) { - if (usecToSleep > SEND_INTERVAL_USECS) { - usecToSleep = SEND_INTERVAL_USECS; + if (usecToSleep > INTERVAL_SLEEP_USECS) { + usecToSleep = INTERVAL_SLEEP_USECS; } usleep(usecToSleep); + hasSlept = true; } } @@ -133,8 +137,21 @@ bool PacketSender::process() { keepGoing = (packetsThisCall < packetsPerCall) && (packetsLeft > 0); } + // if threaded and we only sent one packet, we still want to sleep.... + if (isThreaded() && !hasSlept) { + now = usecTimestampNow(); + uint64_t elapsed = now - _lastSendTime; + int usecToSleep = INTERVAL_SLEEP_USECS - elapsed; + // we only sleep in non-threaded mode + if (usecToSleep > 0) { + if (usecToSleep > INTERVAL_SLEEP_USECS) { + usecToSleep = INTERVAL_SLEEP_USECS; + } + usleep(usecToSleep); + } + } + _lastSendTime = now; } - - return isStillRunning(); // keep running till they terminate us + return isStillRunning(); } diff --git a/libraries/shared/src/ReceivedPacketProcessor.cpp b/libraries/shared/src/ReceivedPacketProcessor.cpp index c1d0a84f0f..a46cd36dbe 100644 --- a/libraries/shared/src/ReceivedPacketProcessor.cpp +++ b/libraries/shared/src/ReceivedPacketProcessor.cpp @@ -12,6 +12,10 @@ #include "ReceivedPacketProcessor.h" #include "SharedUtil.h" +ReceivedPacketProcessor::ReceivedPacketProcessor() { + _dontSleep = false; +} + void ReceivedPacketProcessor::queueReceivedPacket(sockaddr& address, unsigned char* packetData, ssize_t packetLength) { // Make sure our Node and NodeList knows we've heard from this node. Node* node = NodeList::getInstance()->nodeWithAddress(&address); @@ -26,7 +30,10 @@ void ReceivedPacketProcessor::queueReceivedPacket(sockaddr& address, unsigned ch } bool ReceivedPacketProcessor::process() { - if (_packets.size() == 0) { + + // If a derived class handles process sleeping, like the JurisdiciontListener, then it can set + // this _dontSleep member and we will honor that request. + if (_packets.size() == 0 && !_dontSleep) { const uint64_t RECEIVED_THREAD_SLEEP_INTERVAL = (1000 * 1000)/60; // check at 60fps usleep(RECEIVED_THREAD_SLEEP_INTERVAL); } diff --git a/libraries/shared/src/ReceivedPacketProcessor.h b/libraries/shared/src/ReceivedPacketProcessor.h index 78017bffd7..f36473ae12 100644 --- a/libraries/shared/src/ReceivedPacketProcessor.h +++ b/libraries/shared/src/ReceivedPacketProcessor.h @@ -17,6 +17,7 @@ /// Generalized threaded processor for handling received inbound packets. class ReceivedPacketProcessor : public virtual GenericThread { public: + ReceivedPacketProcessor(); /// Add packet from network receive thread to the processing queue. /// \param sockaddr& senderAddress the address of the sender @@ -30,7 +31,7 @@ public: /// How many received packets waiting are to be processed int packetsToProcessCount() const { return _packets.size(); } - + protected: /// Callback for processing of recieved packets. Implement this to process the incoming packets. /// \param sockaddr& senderAddress the address of the sender @@ -42,6 +43,8 @@ protected: /// Implements generic processing behavior for this thread. virtual bool process(); + bool _dontSleep; + private: std::vector _packets; diff --git a/libraries/voxels/src/JurisdictionListener.cpp b/libraries/voxels/src/JurisdictionListener.cpp index 6871c881df..223b602dfa 100644 --- a/libraries/voxels/src/JurisdictionListener.cpp +++ b/libraries/voxels/src/JurisdictionListener.cpp @@ -19,6 +19,7 @@ JurisdictionListener::JurisdictionListener(PacketSenderNotify* notify) : PacketSender(notify, JurisdictionListener::DEFAULT_PACKETS_PER_SECOND) { + ReceivedPacketProcessor::_dontSleep = true; // we handle sleeping so this class doesn't need to NodeList* nodeList = NodeList::getInstance(); nodeList->addHook(this); } @@ -53,8 +54,11 @@ bool JurisdictionListener::queueJurisdictionRequest() { } } - // set our packets per second to be the number of nodes - setPacketsPerSecond(nodeCount); + if (nodeCount > 0){ + setPacketsPerSecond(nodeCount); + } else { + setPacketsPerSecond(NO_SERVER_CHECK_RATE); + } // keep going if still running return isStillRunning(); @@ -84,5 +88,6 @@ bool JurisdictionListener::process() { // NOTE: This will sleep if there are no pending packets to process continueProcessing = ReceivedPacketProcessor::process(); } + return continueProcessing; } diff --git a/libraries/voxels/src/JurisdictionListener.h b/libraries/voxels/src/JurisdictionListener.h index 0a614446ed..8f7c4e6cf6 100644 --- a/libraries/voxels/src/JurisdictionListener.h +++ b/libraries/voxels/src/JurisdictionListener.h @@ -24,6 +24,7 @@ class JurisdictionListener : public NodeListHook, public PacketSender, public ReceivedPacketProcessor { public: static const int DEFAULT_PACKETS_PER_SECOND = 1; + static const int NO_SERVER_CHECK_RATE=60; JurisdictionListener(PacketSenderNotify* notify = NULL); ~JurisdictionListener(); @@ -50,6 +51,5 @@ private: NodeToJurisdictionMap _jurisdictions; bool queueJurisdictionRequest(); - }; #endif // __shared__JurisdictionListener__ From 20c66386f8a1161db417379d4c15d4d651af8e63 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 8 Nov 2013 02:24:46 -0800 Subject: [PATCH 05/12] fix comment --- libraries/voxels/src/JurisdictionListener.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/voxels/src/JurisdictionListener.h b/libraries/voxels/src/JurisdictionListener.h index 8f7c4e6cf6..7376c9196f 100644 --- a/libraries/voxels/src/JurisdictionListener.h +++ b/libraries/voxels/src/JurisdictionListener.h @@ -24,7 +24,7 @@ class JurisdictionListener : public NodeListHook, public PacketSender, public ReceivedPacketProcessor { public: static const int DEFAULT_PACKETS_PER_SECOND = 1; - static const int NO_SERVER_CHECK_RATE=60; + static const int NO_SERVER_CHECK_RATE = 60; // if no servers yet detected, keep checking at 60fps JurisdictionListener(PacketSenderNotify* notify = NULL); ~JurisdictionListener(); From a7084868342f5dc9d003bcf5679b6fe7591aa508 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 8 Nov 2013 02:25:51 -0800 Subject: [PATCH 06/12] fix comment --- libraries/shared/src/PacketSender.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/shared/src/PacketSender.cpp b/libraries/shared/src/PacketSender.cpp index 76d4ac47ad..a9fe778abd 100644 --- a/libraries/shared/src/PacketSender.cpp +++ b/libraries/shared/src/PacketSender.cpp @@ -137,7 +137,7 @@ bool PacketSender::process() { keepGoing = (packetsThisCall < packetsPerCall) && (packetsLeft > 0); } - // if threaded and we only sent one packet, we still want to sleep.... + // if threaded and we haven't slept? We want to sleep.... if (isThreaded() && !hasSlept) { now = usecTimestampNow(); uint64_t elapsed = now - _lastSendTime; From 3da6062639d72b6b969d43c530c53f34b5b1af1c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 8 Nov 2013 02:26:23 -0800 Subject: [PATCH 07/12] fix comment --- libraries/shared/src/PacketSender.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/shared/src/PacketSender.cpp b/libraries/shared/src/PacketSender.cpp index a9fe778abd..cb00af5e01 100644 --- a/libraries/shared/src/PacketSender.cpp +++ b/libraries/shared/src/PacketSender.cpp @@ -142,7 +142,6 @@ bool PacketSender::process() { now = usecTimestampNow(); uint64_t elapsed = now - _lastSendTime; int usecToSleep = INTERVAL_SLEEP_USECS - elapsed; - // we only sleep in non-threaded mode if (usecToSleep > 0) { if (usecToSleep > INTERVAL_SLEEP_USECS) { usecToSleep = INTERVAL_SLEEP_USECS; From b0a4ffb11c7f57196e593368fbf8a21f0b41ec1f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 8 Nov 2013 02:27:34 -0800 Subject: [PATCH 08/12] fix comments line breaks --- libraries/shared/src/PacketSender.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/shared/src/PacketSender.cpp b/libraries/shared/src/PacketSender.cpp index cb00af5e01..f2a104634e 100644 --- a/libraries/shared/src/PacketSender.cpp +++ b/libraries/shared/src/PacketSender.cpp @@ -43,7 +43,8 @@ bool PacketSender::process() { uint64_t USECS_PER_SECOND = 1000 * 1000; uint64_t USECS_SMALL_ADJUST = 2 * 1000; // approaximate 2ms uint64_t SEND_INTERVAL_USECS = (_packetsPerSecond == 0) ? USECS_PER_SECOND : (USECS_PER_SECOND / _packetsPerSecond); - uint64_t INTERVAL_SLEEP_USECS = (SEND_INTERVAL_USECS > USECS_SMALL_ADJUST) ? SEND_INTERVAL_USECS - USECS_SMALL_ADJUST : SEND_INTERVAL_USECS; + uint64_t INTERVAL_SLEEP_USECS = (SEND_INTERVAL_USECS > USECS_SMALL_ADJUST) ? + SEND_INTERVAL_USECS - USECS_SMALL_ADJUST : SEND_INTERVAL_USECS; // keep track of our process call times, so we have a reliable account of how often our caller calls us uint64_t now = usecTimestampNow(); @@ -56,7 +57,8 @@ bool PacketSender::process() { usleep(INTERVAL_SLEEP_USECS); hasSlept = true; } else { - return isStillRunning(); // in non-threaded mode, if there's nothing to do, just return, keep running till they terminate us + // in non-threaded mode, if there's nothing to do, just return, keep running till they terminate us + return isStillRunning(); } } From a75e577d0a5fc8da1be28b69322d44632943aa4d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 8 Nov 2013 09:32:06 -0800 Subject: [PATCH 09/12] voxel edit packet debugging support --- .../voxel-server-library/src/VoxelServer.cpp | 19 ++++++++++++------- .../voxel-server-library/src/VoxelServer.h | 2 ++ .../src/VoxelServerPacketProcessor.cpp | 8 ++++---- .../voxels/src/VoxelEditPacketSender.cpp | 6 ++++-- libraries/voxels/src/VoxelEditPacketSender.h | 2 ++ 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/libraries/voxel-server-library/src/VoxelServer.cpp b/libraries/voxel-server-library/src/VoxelServer.cpp index 0b868d8908..0bafa64a5b 100644 --- a/libraries/voxel-server-library/src/VoxelServer.cpp +++ b/libraries/voxel-server-library/src/VoxelServer.cpp @@ -71,6 +71,7 @@ VoxelServer::VoxelServer(const unsigned char* dataBuffer, int numBytes) : Assign _sendEnvironments = true; _sendMinimalEnvironment = false; _dumpVoxelsOnMove = false; + _verboseDebug = false; _jurisdiction = NULL; _jurisdictionSender = NULL; _voxelServerPacketProcessor = NULL; @@ -427,14 +428,14 @@ void VoxelServer::run() { // should we send environments? Default is yes, but this command line suppresses sending const char* SEND_ENVIRONMENTS = "--sendEnvironments"; - bool dontSendEnvironments = !getCmdOption(_argc, _argv, SEND_ENVIRONMENTS); + bool dontSendEnvironments = !cmdOptionExists(_argc, _argv, SEND_ENVIRONMENTS); if (dontSendEnvironments) { qDebug("Sending environments suppressed...\n"); _sendEnvironments = false; } else { // should we send environments? Default is yes, but this command line suppresses sending const char* MINIMAL_ENVIRONMENT = "--minimalEnvironment"; - _sendMinimalEnvironment = getCmdOption(_argc, _argv, MINIMAL_ENVIRONMENT); + _sendMinimalEnvironment = cmdOptionExists(_argc, _argv, MINIMAL_ENVIRONMENT); qDebug("Using Minimal Environment=%s\n", debug::valueOf(_sendMinimalEnvironment)); } qDebug("Sending environments=%s\n", debug::valueOf(_sendEnvironments)); @@ -455,24 +456,28 @@ void VoxelServer::run() { srand((unsigned)time(0)); const char* DISPLAY_VOXEL_STATS = "--displayVoxelStats"; - _displayVoxelStats = getCmdOption(_argc, _argv, DISPLAY_VOXEL_STATS); + _displayVoxelStats = cmdOptionExists(_argc, _argv, DISPLAY_VOXEL_STATS); qDebug("displayVoxelStats=%s\n", debug::valueOf(_displayVoxelStats)); + const char* VERBOSE_DEBUG = "--verboseDebug"; + _verboseDebug = cmdOptionExists(_argc, _argv, VERBOSE_DEBUG); + qDebug("verboseDebug=%s\n", debug::valueOf(_verboseDebug)); + const char* DEBUG_VOXEL_SENDING = "--debugVoxelSending"; - _debugVoxelSending = getCmdOption(_argc, _argv, DEBUG_VOXEL_SENDING); + _debugVoxelSending = cmdOptionExists(_argc, _argv, DEBUG_VOXEL_SENDING); qDebug("debugVoxelSending=%s\n", debug::valueOf(_debugVoxelSending)); const char* DEBUG_VOXEL_RECEIVING = "--debugVoxelReceiving"; - _debugVoxelReceiving = getCmdOption(_argc, _argv, DEBUG_VOXEL_RECEIVING); + _debugVoxelReceiving = cmdOptionExists(_argc, _argv, DEBUG_VOXEL_RECEIVING); qDebug("debugVoxelReceiving=%s\n", debug::valueOf(_debugVoxelReceiving)); const char* WANT_ANIMATION_DEBUG = "--shouldShowAnimationDebug"; - _shouldShowAnimationDebug = getCmdOption(_argc, _argv, WANT_ANIMATION_DEBUG); + _shouldShowAnimationDebug = cmdOptionExists(_argc, _argv, WANT_ANIMATION_DEBUG); qDebug("shouldShowAnimationDebug=%s\n", debug::valueOf(_shouldShowAnimationDebug)); // By default we will voxel persist, if you want to disable this, then pass in this parameter const char* NO_VOXEL_PERSIST = "--NoVoxelPersist"; - if (getCmdOption(_argc, _argv, NO_VOXEL_PERSIST)) { + if (cmdOptionExists(_argc, _argv, NO_VOXEL_PERSIST)) { _wantVoxelPersist = false; } qDebug("wantVoxelPersist=%s\n", debug::valueOf(_wantVoxelPersist)); diff --git a/libraries/voxel-server-library/src/VoxelServer.h b/libraries/voxel-server-library/src/VoxelServer.h index 92590489f8..4aee48e5f1 100644 --- a/libraries/voxel-server-library/src/VoxelServer.h +++ b/libraries/voxel-server-library/src/VoxelServer.h @@ -40,6 +40,7 @@ public: bool wantsDebugVoxelSending() const { return _debugVoxelSending; } bool wantsDebugVoxelReceiving() const { return _debugVoxelReceiving; } + bool wantsVerboseDebug() const { return _verboseDebug; } bool wantShowAnimationDebug() const { return _shouldShowAnimationDebug; } bool wantSendEnvironments() const { return _sendEnvironments; } bool wantDumpVoxelsOnMove() const { return _dumpVoxelsOnMove; } @@ -76,6 +77,7 @@ private: bool _sendEnvironments; bool _sendMinimalEnvironment; bool _dumpVoxelsOnMove; + bool _verboseDebug; JurisdictionMap* _jurisdiction; JurisdictionSender* _jurisdictionSender; VoxelServerPacketProcessor* _voxelServerPacketProcessor; diff --git a/libraries/voxel-server-library/src/VoxelServerPacketProcessor.cpp b/libraries/voxel-server-library/src/VoxelServerPacketProcessor.cpp index 672c4f0d50..5cbc942d16 100644 --- a/libraries/voxel-server-library/src/VoxelServerPacketProcessor.cpp +++ b/libraries/voxel-server-library/src/VoxelServerPacketProcessor.cpp @@ -24,10 +24,10 @@ VoxelServerPacketProcessor::VoxelServerPacketProcessor(VoxelServer* myServer) : void VoxelServerPacketProcessor::processPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength) { - bool debugProcessPacket = _myServer->wantsDebugVoxelReceiving(); + bool debugProcessPacket = _myServer->wantsVerboseDebug(); if (debugProcessPacket) { - printf("VoxelServerPacketProcessor::processPacket(() packetData=%p packetLength=%ld\n", packetData, packetLength); + printf("VoxelServerPacketProcessor::processPacket() packetData=%p packetLength=%ld\n", packetData, packetLength); } int numBytesPacketHeader = numBytesForPacketHeader(packetData); @@ -58,7 +58,7 @@ void VoxelServerPacketProcessor::processPacket(sockaddr& senderAddress, unsigned int maxSize = packetLength - atByte; if (debugProcessPacket) { - printf("VoxelServerPacketProcessor::processPacket(() %s packetData=%p packetLength=%ld voxelData=%p atByte=%d maxSize=%d\n", + printf("VoxelServerPacketProcessor::processPacket() %s packetData=%p packetLength=%ld voxelData=%p atByte=%d maxSize=%d\n", destructive ? "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE" : "PACKET_TYPE_SET_VOXEL", packetData, packetLength, voxelData, atByte, maxSize); } @@ -100,7 +100,7 @@ void VoxelServerPacketProcessor::processPacket(sockaddr& senderAddress, unsigned } if (debugProcessPacket) { - printf("VoxelServerPacketProcessor::processPacket(() DONE LOOPING FOR %s packetData=%p packetLength=%ld voxelData=%p atByte=%d\n", + printf("VoxelServerPacketProcessor::processPacket() DONE LOOPING FOR %s packetData=%p packetLength=%ld voxelData=%p atByte=%d\n", destructive ? "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE" : "PACKET_TYPE_SET_VOXEL", packetData, packetLength, voxelData, atByte); } diff --git a/libraries/voxels/src/VoxelEditPacketSender.cpp b/libraries/voxels/src/VoxelEditPacketSender.cpp index 8b7c82a4ca..d1ba513c4d 100644 --- a/libraries/voxels/src/VoxelEditPacketSender.cpp +++ b/libraries/voxels/src/VoxelEditPacketSender.cpp @@ -32,7 +32,8 @@ VoxelEditPacketSender::VoxelEditPacketSender(PacketSenderNotify* notify) : _shouldSend(true), _maxPendingMessages(DEFAULT_MAX_PENDING_MESSAGES), _releaseQueuedMessagesPending(false), - _voxelServerJurisdictions(NULL) { + _voxelServerJurisdictions(NULL), + _sequenceNumber(0) { } VoxelEditPacketSender::~VoxelEditPacketSender() { @@ -274,7 +275,8 @@ void VoxelEditPacketSender::releaseQueuedPacket(EditPacketBuffer& packetBuffer) void VoxelEditPacketSender::initializePacket(EditPacketBuffer& packetBuffer, PACKET_TYPE type) { packetBuffer._currentSize = populateTypeAndVersion(&packetBuffer._currentBuffer[0], type); unsigned short int* sequenceAt = (unsigned short int*)&packetBuffer._currentBuffer[packetBuffer._currentSize]; - *sequenceAt = 0; + *sequenceAt = _sequenceNumber; + _sequenceNumber++; packetBuffer._currentSize += sizeof(unsigned short int); // set to command + sequence packetBuffer._currentType = type; } diff --git a/libraries/voxels/src/VoxelEditPacketSender.h b/libraries/voxels/src/VoxelEditPacketSender.h index bb54009d1a..eecb7e8677 100644 --- a/libraries/voxels/src/VoxelEditPacketSender.h +++ b/libraries/voxels/src/VoxelEditPacketSender.h @@ -105,5 +105,7 @@ private: std::vector _preServerSingleMessagePackets; // these will go out as is NodeToJurisdictionMap* _voxelServerJurisdictions; + + unsigned short int _sequenceNumber; }; #endif // __shared__VoxelEditPacketSender__ From a9c5c0707f7a925a38ddfbdd3d27752c237fff36 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 8 Nov 2013 10:32:46 -0800 Subject: [PATCH 10/12] added sentAt timestamps to voxel edit packets so we can measure transit time --- libraries/shared/src/PacketHeaders.cpp | 5 +++ libraries/shared/src/SharedUtil.cpp | 11 +++++-- .../src/VoxelServerPacketProcessor.cpp | 31 +++++++++++++++---- .../voxels/src/VoxelEditPacketSender.cpp | 11 ++++++- libraries/voxels/src/VoxelTree.cpp | 10 ++++-- 5 files changed, 56 insertions(+), 12 deletions(-) diff --git a/libraries/shared/src/PacketHeaders.cpp b/libraries/shared/src/PacketHeaders.cpp index dc953b6b80..b03daeec05 100644 --- a/libraries/shared/src/PacketHeaders.cpp +++ b/libraries/shared/src/PacketHeaders.cpp @@ -38,6 +38,11 @@ PACKET_VERSION versionForPacketType(PACKET_TYPE type) { case PACKET_TYPE_VOXEL_QUERY: return 1; + + case PACKET_TYPE_SET_VOXEL: + case PACKET_TYPE_SET_VOXEL_DESTRUCTIVE: + case PACKET_TYPE_ERASE_VOXEL: + return 1; default: return 0; diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index 0b8af8b48b..99b24979cc 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -250,10 +250,15 @@ bool createVoxelEditMessage(unsigned char command, short int sequence, int numBytesPacketHeader = populateTypeAndVersion(messageBuffer, command); unsigned short int* sequenceAt = (unsigned short int*) &messageBuffer[numBytesPacketHeader]; - *sequenceAt = sequence; - unsigned char* copyAt = &messageBuffer[numBytesPacketHeader + sizeof(sequence)]; - int actualMessageSize = numBytesPacketHeader + sizeof(sequence); + + // pack in timestamp + uint64_t now = usecTimestampNow(); + uint64_t* timeAt = (uint64_t*)&messageBuffer[numBytesPacketHeader + sizeof(sequence)]; + *timeAt = now; + + unsigned char* copyAt = &messageBuffer[numBytesPacketHeader + sizeof(sequence) + sizeof(now)]; + int actualMessageSize = numBytesPacketHeader + sizeof(sequence) + sizeof(now); for (int i = 0; i < voxelCount && success; i++) { // get the coded voxel diff --git a/libraries/voxel-server-library/src/VoxelServerPacketProcessor.cpp b/libraries/voxel-server-library/src/VoxelServerPacketProcessor.cpp index 5cbc942d16..a86dead1d0 100644 --- a/libraries/voxel-server-library/src/VoxelServerPacketProcessor.cpp +++ b/libraries/voxel-server-library/src/VoxelServerPacketProcessor.cpp @@ -40,19 +40,22 @@ void VoxelServerPacketProcessor::processPacket(sockaddr& senderAddress, unsigned _receivedPacketCount++; - unsigned short int itemNumber = (*((unsigned short int*)(packetData + numBytesPacketHeader))); + unsigned short int sequence = (*((unsigned short int*)(packetData + numBytesPacketHeader))); + uint64_t sentAt = (*((uint64_t*)(packetData + numBytesPacketHeader + sizeof(sequence)))); + uint64_t arrivedAt = usecTimestampNow(); + uint64_t transitTime = arrivedAt - sentAt; if (_myServer->wantShowAnimationDebug()) { - printf("got %s - command from client receivedBytes=%ld itemNumber=%d\n", + printf("got %s - command from client receivedBytes=%ld sequence=%d transitTime=%llu usecs\n", destructive ? "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE" : "PACKET_TYPE_SET_VOXEL", - packetLength, itemNumber); + packetLength, sequence, transitTime); } if (_myServer->wantsDebugVoxelReceiving()) { - printf("got %s - %d command from client receivedBytes=%ld itemNumber=%d\n", + printf("got %s - %d command from client receivedBytes=%ld sequence=%d transitTime=%llu usecs\n", destructive ? "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE" : "PACKET_TYPE_SET_VOXEL", - _receivedPacketCount, packetLength, itemNumber); + _receivedPacketCount, packetLength, sequence, transitTime); } - int atByte = numBytesPacketHeader + sizeof(itemNumber); + int atByte = numBytesPacketHeader + sizeof(sequence) + sizeof(sentAt); unsigned char* voxelData = (unsigned char*)&packetData[atByte]; while (atByte < packetLength) { int maxSize = packetLength - atByte; @@ -113,6 +116,22 @@ void VoxelServerPacketProcessor::processPacket(sockaddr& senderAddress, unsigned } else if (packetData[0] == PACKET_TYPE_ERASE_VOXEL) { + _receivedPacketCount++; + + unsigned short int sequence = (*((unsigned short int*)(packetData + numBytesPacketHeader))); + uint64_t sentAt = (*((uint64_t*)(packetData + numBytesPacketHeader + sizeof(sequence)))); + uint64_t arrivedAt = usecTimestampNow(); + uint64_t transitTime = arrivedAt - sentAt; + if (_myServer->wantShowAnimationDebug()) { + printf("got PACKET_TYPE_ERASE_VOXEL - command from client receivedBytes=%ld sequence=%d transitTime=%llu usecs\n", + packetLength, sequence, transitTime); + } + + if (_myServer->wantsDebugVoxelReceiving()) { + printf("got PACKET_TYPE_ERASE_VOXEL - %d command from client receivedBytes=%ld sequence=%d transitTime=%llu usecs\n", + _receivedPacketCount, packetLength, sequence, transitTime); + } + // Send these bits off to the VoxelTree class to process them _myServer->getServerTree().lockForWrite(); _myServer->getServerTree().processRemoveVoxelBitstream((unsigned char*)packetData, packetLength); diff --git a/libraries/voxels/src/VoxelEditPacketSender.cpp b/libraries/voxels/src/VoxelEditPacketSender.cpp index d1ba513c4d..125d80e61a 100644 --- a/libraries/voxels/src/VoxelEditPacketSender.cpp +++ b/libraries/voxels/src/VoxelEditPacketSender.cpp @@ -274,10 +274,19 @@ void VoxelEditPacketSender::releaseQueuedPacket(EditPacketBuffer& packetBuffer) void VoxelEditPacketSender::initializePacket(EditPacketBuffer& packetBuffer, PACKET_TYPE type) { packetBuffer._currentSize = populateTypeAndVersion(&packetBuffer._currentBuffer[0], type); + + // pack in sequence number unsigned short int* sequenceAt = (unsigned short int*)&packetBuffer._currentBuffer[packetBuffer._currentSize]; *sequenceAt = _sequenceNumber; + packetBuffer._currentSize += sizeof(unsigned short int); // nudge past sequence _sequenceNumber++; - packetBuffer._currentSize += sizeof(unsigned short int); // set to command + sequence + + // pack in timestamp + uint64_t now = usecTimestampNow(); + uint64_t* timeAt = (uint64_t*)&packetBuffer._currentBuffer[packetBuffer._currentSize]; + *timeAt = now; + packetBuffer._currentSize += sizeof(uint64_t); // nudge past timestamp + packetBuffer._currentType = type; } diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index e0e1ac5367..2681742437 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -576,9 +576,15 @@ void VoxelTree::readCodeColorBufferToTreeRecursion(VoxelNode* node, void* extraD } } -void VoxelTree::processRemoveVoxelBitstream(unsigned char * bitstream, int bufferSizeBytes) { +void VoxelTree::processRemoveVoxelBitstream(unsigned char* bitstream, int bufferSizeBytes) { //unsigned short int itemNumber = (*((unsigned short int*)&bitstream[sizeof(PACKET_HEADER)])); - int atByte = sizeof(short int) + numBytesForPacketHeader(bitstream); + + int numBytesPacketHeader = numBytesForPacketHeader(bitstream); + unsigned short int sequence = (*((unsigned short int*)(bitstream + numBytesPacketHeader))); + uint64_t sentAt = (*((uint64_t*)(bitstream + numBytesPacketHeader + sizeof(sequence)))); + + int atByte = numBytesPacketHeader + sizeof(sequence) + sizeof(sentAt); + unsigned char* voxelCode = (unsigned char*)&bitstream[atByte]; while (atByte < bufferSizeBytes) { int maxSize = bufferSizeBytes - atByte; From 2e8cb63abb3e3632bc91f35a3b1d72187015bb80 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 8 Nov 2013 10:47:47 -0800 Subject: [PATCH 11/12] add more voxel edit transit time debugging --- .../voxel-server-library/src/VoxelServer.cpp | 28 +++++++++++++++++++ .../src/VoxelServerPacketProcessor.cpp | 19 ++++--------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/libraries/voxel-server-library/src/VoxelServer.cpp b/libraries/voxel-server-library/src/VoxelServer.cpp index 0bafa64a5b..1ce0bcd59d 100644 --- a/libraries/voxel-server-library/src/VoxelServer.cpp +++ b/libraries/voxel-server-library/src/VoxelServer.cpp @@ -608,6 +608,34 @@ void VoxelServer::run() { || packetData[0] == PACKET_TYPE_SET_VOXEL_DESTRUCTIVE || packetData[0] == PACKET_TYPE_ERASE_VOXEL || packetData[0] == PACKET_TYPE_Z_COMMAND)) { + + + const char* messageName; + switch (packetData[0]) { + case PACKET_TYPE_SET_VOXEL: + messageName = "PACKET_TYPE_SET_VOXEL"; + break; + case PACKET_TYPE_SET_VOXEL_DESTRUCTIVE: + messageName = "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE"; + break; + case PACKET_TYPE_ERASE_VOXEL: + messageName = "PACKET_TYPE_ERASE_VOXEL"; + break; + } + int numBytesPacketHeader = numBytesForPacketHeader(packetData); + + if (packetData[0] != PACKET_TYPE_Z_COMMAND) { + unsigned short int sequence = (*((unsigned short int*)(packetData + numBytesPacketHeader))); + uint64_t sentAt = (*((uint64_t*)(packetData + numBytesPacketHeader + sizeof(sequence)))); + uint64_t arrivedAt = usecTimestampNow(); + uint64_t transitTime = arrivedAt - sentAt; + if (wantShowAnimationDebug() || wantsDebugVoxelReceiving()) { + printf("RECEIVE THREAD: got %s - command from client receivedBytes=%ld sequence=%d transitTime=%llu usecs\n", + messageName, + packetLength, sequence, transitTime); + } + } + _voxelServerPacketProcessor->queueReceivedPacket(senderAddress, packetData, packetLength); } else { // let processNodeData handle it. diff --git a/libraries/voxel-server-library/src/VoxelServerPacketProcessor.cpp b/libraries/voxel-server-library/src/VoxelServerPacketProcessor.cpp index a86dead1d0..eb96706f12 100644 --- a/libraries/voxel-server-library/src/VoxelServerPacketProcessor.cpp +++ b/libraries/voxel-server-library/src/VoxelServerPacketProcessor.cpp @@ -44,14 +44,9 @@ void VoxelServerPacketProcessor::processPacket(sockaddr& senderAddress, unsigned uint64_t sentAt = (*((uint64_t*)(packetData + numBytesPacketHeader + sizeof(sequence)))); uint64_t arrivedAt = usecTimestampNow(); uint64_t transitTime = arrivedAt - sentAt; - if (_myServer->wantShowAnimationDebug()) { - printf("got %s - command from client receivedBytes=%ld sequence=%d transitTime=%llu usecs\n", - destructive ? "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE" : "PACKET_TYPE_SET_VOXEL", - packetLength, sequence, transitTime); - } - if (_myServer->wantsDebugVoxelReceiving()) { - printf("got %s - %d command from client receivedBytes=%ld sequence=%d transitTime=%llu usecs\n", + if (_myServer->wantShowAnimationDebug() || _myServer->wantsDebugVoxelReceiving()) { + printf("PROCESSING THREAD: got %s - %d command from client receivedBytes=%ld sequence=%d transitTime=%llu usecs\n", destructive ? "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE" : "PACKET_TYPE_SET_VOXEL", _receivedPacketCount, packetLength, sequence, transitTime); } @@ -122,13 +117,9 @@ void VoxelServerPacketProcessor::processPacket(sockaddr& senderAddress, unsigned uint64_t sentAt = (*((uint64_t*)(packetData + numBytesPacketHeader + sizeof(sequence)))); uint64_t arrivedAt = usecTimestampNow(); uint64_t transitTime = arrivedAt - sentAt; - if (_myServer->wantShowAnimationDebug()) { - printf("got PACKET_TYPE_ERASE_VOXEL - command from client receivedBytes=%ld sequence=%d transitTime=%llu usecs\n", - packetLength, sequence, transitTime); - } - - if (_myServer->wantsDebugVoxelReceiving()) { - printf("got PACKET_TYPE_ERASE_VOXEL - %d command from client receivedBytes=%ld sequence=%d transitTime=%llu usecs\n", + + if (_myServer->wantShowAnimationDebug() || _myServer->wantsDebugVoxelReceiving()) { + printf("PROCESSING THREAD: got PACKET_TYPE_ERASE_VOXEL - %d command from client receivedBytes=%ld sequence=%d transitTime=%llu usecs\n", _receivedPacketCount, packetLength, sequence, transitTime); } From db9fa631121f963da9899eb11ece4a68a25758ea Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 8 Nov 2013 11:19:35 -0800 Subject: [PATCH 12/12] Partial orchidectomy: removed (some of) Jeffrey's balls. --- interface/src/avatar/AvatarTouch.cpp | 52 ---------------------------- 1 file changed, 52 deletions(-) diff --git a/interface/src/avatar/AvatarTouch.cpp b/interface/src/avatar/AvatarTouch.cpp index 1e06663b01..78a63bd3aa 100644 --- a/interface/src/avatar/AvatarTouch.cpp +++ b/interface/src/avatar/AvatarTouch.cpp @@ -86,59 +86,7 @@ void AvatarTouch::render(glm::vec3 cameraPosition) { glm::vec3 p(_yourBodyPosition); p.y = 0.0005f; renderCircle(p, _reachableRadius, glm::vec3(0.0f, 1.0f, 0.0f), 30); - - // show if we are holding hands... - if (_weAreHoldingHands) { - renderBeamBetweenHands(); - - /* - glPushMatrix(); - glTranslatef(_yourHandPosition.x, _yourHandPosition.y, _yourHandPosition.z); - glColor4f(1.0, 0.0, 0.0, 0.7); glutSolidSphere(0.020f, 10.0f, 10.0f); - glColor4f(1.0, 0.0, 0.0, 0.7); glutSolidSphere(0.025f, 10.0f, 10.0f); - glColor4f(1.0, 0.0, 0.0, 0.7); glutSolidSphere(0.030f, 10.0f, 10.0f); - glPopMatrix(); - */ - - /* - glColor4f(0.9, 0.3, 0.3, 0.5); - renderSphereOutline(_myHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP * 0.3f, 20, cameraPosition); - renderSphereOutline(_myHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP * 0.2f, 20, cameraPosition); - renderSphereOutline(_myHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP * 0.1f, 20, cameraPosition); - - renderSphereOutline(_yourHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP * 0.3f, 20, cameraPosition); - renderSphereOutline(_yourHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP * 0.2f, 20, cameraPosition); - renderSphereOutline(_yourHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP * 0.1f, 20, cameraPosition); - */ - } - - //show that our hands are close enough to grasp.. - if (_handsCloseEnoughToGrasp) { - glColor4f(0.9, 0.3, 0.3, 0.5); - renderSphereOutline(_myHandPosition, 0.03f, 20, cameraPosition); - renderSphereOutline(_yourHandPosition, 0.03f, 20, cameraPosition); - } - - // if your hand is grasping, show it... - if (_yourHandState == HAND_STATE_GRASPING) { - glPushMatrix(); - glTranslatef(_yourHandPosition.x, _yourHandPosition.y, _yourHandPosition.z); - glColor4f(1.0, 0.7, 0.8, 0.4); glutSolidSphere(0.020f, 10.0f, 10.0f); - glColor4f(1.0, 0.7, 0.4, 0.3); glutSolidSphere(0.025f, 10.0f, 10.0f); - glColor4f(1.0, 0.7, 0.2, 0.2); glutSolidSphere(0.030f, 10.0f, 10.0f); - glPopMatrix(); - } } - - // if my hand is grasping, show it... - if (_myHandState == HAND_STATE_GRASPING) { - glPushMatrix(); - glTranslatef(_myHandPosition.x, _myHandPosition.y, _myHandPosition.z); - glColor4f(1.0, 0.7, 0.8, 0.4); glutSolidSphere(0.020f, 10.0f, 10.0f); - glColor4f(1.0, 0.7, 0.4, 0.3); glutSolidSphere(0.025f, 10.0f, 10.0f); - glColor4f(1.0, 0.7, 0.2, 0.2); glutSolidSphere(0.030f, 10.0f, 10.0f); - glPopMatrix(); - } }