From 01ba5ee81ab449361bdd5f2e910ee6484c73fb5b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 5 Aug 2013 16:30:08 -0700 Subject: [PATCH] adding jurisdiction to scene stats to implement add/drop effect, added command line to voxel server to not send environments --- libraries/shared/src/PacketHeaders.cpp | 4 ++- libraries/voxels/src/JurisdictionMap.h | 2 ++ libraries/voxels/src/VoxelSceneStats.cpp | 31 +++++++++++++++++++++++- libraries/voxels/src/VoxelSceneStats.h | 5 +++- voxel-server/src/main.cpp | 14 +++++++++-- 5 files changed, 51 insertions(+), 5 deletions(-) diff --git a/libraries/shared/src/PacketHeaders.cpp b/libraries/shared/src/PacketHeaders.cpp index 99c887614c..04b13c8ccd 100644 --- a/libraries/shared/src/PacketHeaders.cpp +++ b/libraries/shared/src/PacketHeaders.cpp @@ -24,7 +24,9 @@ PACKET_VERSION versionForPacketType(PACKET_TYPE type) { case PACKET_TYPE_AVATAR_FACE_VIDEO: return 1; - + + case PACKET_TYPE_VOXEL_STATS: + return 1; default: return 0; } diff --git a/libraries/voxels/src/JurisdictionMap.h b/libraries/voxels/src/JurisdictionMap.h index 6c7cc4f0ca..59e08e85e9 100644 --- a/libraries/voxels/src/JurisdictionMap.h +++ b/libraries/voxels/src/JurisdictionMap.h @@ -30,6 +30,8 @@ public: bool writeToFile(const char* filename); bool readFromFile(const char* filename); + + unsigned char* getRootOctalCode() const { return _rootOctalCode; } private: void clear(); diff --git a/libraries/voxels/src/VoxelSceneStats.cpp b/libraries/voxels/src/VoxelSceneStats.cpp index 9dd696eaa6..96bedcf2b1 100644 --- a/libraries/voxels/src/VoxelSceneStats.cpp +++ b/libraries/voxels/src/VoxelSceneStats.cpp @@ -22,9 +22,10 @@ VoxelSceneStats::VoxelSceneStats() : reset(); _isReadyToSend = false; _isStarted = false; + _jurisdictionRoot = NULL; } -void VoxelSceneStats::sceneStarted(bool isFullScene, bool isMoving, VoxelNode* root) { +void VoxelSceneStats::sceneStarted(bool isFullScene, bool isMoving, VoxelNode* root, JurisdictionMap* jurisdictionMap) { reset(); // resets packet and voxel stats _isStarted = true; _start = usecTimestampNow(); @@ -34,6 +35,7 @@ void VoxelSceneStats::sceneStarted(bool isFullScene, bool isMoving, VoxelNode* r _isFullScene = isFullScene; _isMoving = isMoving; + _jurisdictionRoot = jurisdictionMap->getRootOctalCode(); } void VoxelSceneStats::sceneCompleted() { @@ -273,6 +275,20 @@ int VoxelSceneStats::packIntoMessage(unsigned char* destinationBuffer, int avail destinationBuffer += sizeof(_existsInPacketBitsWritten); memcpy(destinationBuffer, &_treesRemoved, sizeof(_treesRemoved)); destinationBuffer += sizeof(_treesRemoved); + + // add the root jurisdiction + if (_jurisdictionRoot) { + // copy the + int bytes = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(_jurisdictionRoot)); + memcpy(destinationBuffer, &bytes, sizeof(bytes)); + destinationBuffer += sizeof(bytes); + memcpy(destinationBuffer, _jurisdictionRoot, bytes); + destinationBuffer += bytes; + } else { + int bytes = 0; + memcpy(destinationBuffer, &bytes, sizeof(bytes)); + destinationBuffer += sizeof(bytes); + } return destinationBuffer - bufferStart; // includes header! } @@ -363,6 +379,19 @@ int VoxelSceneStats::unpackFromMessage(unsigned char* sourceBuffer, int availabl sourceBuffer += sizeof(_existsInPacketBitsWritten); memcpy(&_treesRemoved, sourceBuffer, sizeof(_treesRemoved)); sourceBuffer += sizeof(_treesRemoved); + + // read the root jurisdiction + int bytes = 0; + memcpy(&bytes, sourceBuffer, sizeof(bytes)); + sourceBuffer += sizeof(bytes); + + if (bytes == 0) { + _jurisdictionRoot = NULL; + } else { + _jurisdictionRoot = new unsigned char[bytes]; + memcpy(_jurisdictionRoot, sourceBuffer, bytes); + sourceBuffer += bytes; + } // running averages _elapsedAverage.updateAverage((float)_elapsed); diff --git a/libraries/voxels/src/VoxelSceneStats.h b/libraries/voxels/src/VoxelSceneStats.h index ded2061a6e..a2ea4a0f40 100644 --- a/libraries/voxels/src/VoxelSceneStats.h +++ b/libraries/voxels/src/VoxelSceneStats.h @@ -12,6 +12,7 @@ #include #include +#include "JurisdictionMap.h" class VoxelNode; @@ -19,7 +20,7 @@ class VoxelSceneStats { public: VoxelSceneStats(); void reset(); - void sceneStarted(bool fullScene, bool moving, VoxelNode* root); + void sceneStarted(bool fullScene, bool moving, VoxelNode* root, JurisdictionMap* jurisdictionMap); void sceneCompleted(); void printDebugDetails(); @@ -165,6 +166,8 @@ private: static ItemInfo _ITEMS[]; static int const MAX_ITEM_VALUE_LENGTH = 128; char _itemValueBuffer[MAX_ITEM_VALUE_LENGTH]; + + unsigned char* _jurisdictionRoot; }; #endif /* defined(__hifi__VoxelSceneStats__) */ diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 5d7489135a..4b44ec3a59 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -64,6 +64,7 @@ bool debugVoxelSending = false; bool shouldShowAnimationDebug = false; bool displayVoxelStats = false; bool debugVoxelReceiving = false; +bool sendEnvironments = true; EnvironmentData environmentData[3]; @@ -255,7 +256,7 @@ void deepestLevelVoxelDistributor(NodeList* nodeList, // start tracking our stats bool isFullScene = (!viewFrustumChanged || !nodeData->getWantDelta()) && nodeData->getViewFrustumJustStoppedChanging(); - nodeData->stats.sceneStarted(isFullScene, viewFrustumChanged, ::serverTree.rootNode); + nodeData->stats.sceneStarted(isFullScene, viewFrustumChanged, ::serverTree.rootNode, ::jurisdiction); } // If we have something in our nodeBag, then turn them into packets and send them out... @@ -265,7 +266,7 @@ void deepestLevelVoxelDistributor(NodeList* nodeList, int packetsSentThisInterval = 0; uint64_t start = usecTimestampNow(); - bool shouldSendEnvironments = shouldDo(ENVIRONMENT_SEND_INTERVAL_USECS, VOXEL_SEND_INTERVAL_USECS); + bool shouldSendEnvironments = ::sendEnvironments && shouldDo(ENVIRONMENT_SEND_INTERVAL_USECS, VOXEL_SEND_INTERVAL_USECS); while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - (shouldSendEnvironments ? 1 : 0)) { // Check to see if we're taking too long, and if so bail early... uint64_t now = usecTimestampNow(); @@ -473,6 +474,15 @@ int main(int argc, const char * argv[]) { jurisdiction = new JurisdictionMap(jurisdictionRoot, jurisdictionEndNodes); } } + + // should we send environments? Default is yes, but this command line suppresses sending + const char* DONT_SEND_ENVIRONMENTS = "--dontSendEnvironments"; + bool dontSendEnvironments = cmdOptionExists(argc, argv, DONT_SEND_ENVIRONMENTS); + if (dontSendEnvironments) { + printf("Sending environments suppressed...\n"); + ::sendEnvironments = false; + } + printf("Sending environments=%s\n", debug::valueOf(::sendEnvironments)); NodeList* nodeList = NodeList::createInstance(NODE_TYPE_VOXEL_SERVER, listenPort); setvbuf(stdout, NULL, _IOLBF, 0);