properly send full jurisdiction details in scene stats

This commit is contained in:
ZappoMan 2013-08-13 13:43:46 -07:00
parent 27d001a84d
commit 02f2de6101
2 changed files with 45 additions and 11 deletions

View file

@ -26,7 +26,7 @@ PACKET_VERSION versionForPacketType(PACKET_TYPE type) {
return 1;
case PACKET_TYPE_VOXEL_STATS:
return 1;
return 2;
default:
return 0;
}

View file

@ -17,23 +17,16 @@
const int samples = 100;
VoxelSceneStats::VoxelSceneStats() :
_elapsedAverage(samples),
_bitsPerVoxelAverage(samples)
_bitsPerVoxelAverage(samples),
_jurisdictionRoot(NULL)
{
reset();
_isReadyToSend = false;
_isStarted = false;
_jurisdictionRoot = NULL;
}
VoxelSceneStats::~VoxelSceneStats() {
if (_jurisdictionRoot) {
delete[] _jurisdictionRoot;
}
for (int i=0; i < _jurisdictionEndNodes.size(); i++) {
if (_jurisdictionEndNodes[i]) {
delete[] _jurisdictionEndNodes[i];
}
}
reset();
}
void VoxelSceneStats::sceneStarted(bool isFullScene, bool isMoving, VoxelNode* root, JurisdictionMap* jurisdictionMap) {
@ -139,6 +132,17 @@ void VoxelSceneStats::reset() {
_existsBitsWritten = 0;
_existsInPacketBitsWritten = 0;
_treesRemoved = 0;
if (_jurisdictionRoot) {
delete[] _jurisdictionRoot;
_jurisdictionRoot = NULL;
}
for (int i=0; i < _jurisdictionEndNodes.size(); i++) {
if (_jurisdictionEndNodes[i]) {
delete[] _jurisdictionEndNodes[i];
}
}
_jurisdictionEndNodes.clear();
}
void VoxelSceneStats::packetSent(int bytes) {
@ -317,6 +321,21 @@ int VoxelSceneStats::packIntoMessage(unsigned char* destinationBuffer, int avail
destinationBuffer += sizeof(bytes);
memcpy(destinationBuffer, _jurisdictionRoot, bytes);
destinationBuffer += bytes;
// if and only if there's a root jurisdiction, also include the end nodes
int endNodeCount = _jurisdictionEndNodes.size();
memcpy(destinationBuffer, &endNodeCount, sizeof(endNodeCount));
destinationBuffer += sizeof(endNodeCount);
for (int i=0; i < endNodeCount; i++) {
unsigned char* endNodeCode = _jurisdictionEndNodes[i];
int bytes = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(endNodeCode));
memcpy(destinationBuffer, &bytes, sizeof(bytes));
destinationBuffer += sizeof(bytes);
memcpy(destinationBuffer, endNodeCode, bytes);
destinationBuffer += bytes;
}
} else {
int bytes = 0;
memcpy(destinationBuffer, &bytes, sizeof(bytes));
@ -424,6 +443,21 @@ int VoxelSceneStats::unpackFromMessage(unsigned char* sourceBuffer, int availabl
_jurisdictionRoot = new unsigned char[bytes];
memcpy(_jurisdictionRoot, sourceBuffer, bytes);
sourceBuffer += bytes;
// if and only if there's a root jurisdiction, also include the end nodes
int endNodeCount = 0;
memcpy(&endNodeCount, sourceBuffer, sizeof(endNodeCount));
sourceBuffer += sizeof(endNodeCount);
for (int i=0; i < endNodeCount; i++) {
int bytes = 0;
memcpy(&bytes, sourceBuffer, sizeof(bytes));
sourceBuffer += sizeof(bytes);
unsigned char* endNodeCode = new unsigned char[bytes];
memcpy(endNodeCode, sourceBuffer, bytes);
sourceBuffer += bytes;
_jurisdictionEndNodes.push_back(endNodeCode);
}
}
// running averages