From 25511f99ec656883f2744ce2d73823e8d94ff34b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 24 Nov 2013 15:22:44 -0800 Subject: [PATCH] cleanup for coding standard --- interface/src/VoxelSystem.cpp | 12 ++++++++---- libraries/shared/src/OctalCode.cpp | 4 ++-- libraries/shared/src/SharedUtil.cpp | 10 +++++----- .../voxel-server-library/src/VoxelSendThread.cpp | 13 ++++--------- libraries/voxels/src/VoxelPacket.cpp | 10 +++++++--- libraries/voxels/src/VoxelPacket.h | 7 ++++--- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 622247df8a..92abf43061 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -599,8 +599,10 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { lockTree(); VoxelPacket packet(VOXEL_PACKET_COMPRESSION_DEFAULT); int compressedSize = numBytes - numBytesPacketHeader; - packet.loadCompressedContent(voxelData, compressedSize); -printf("got packet numBytes=%d compressed size %d uncompressed size %d\n",numBytes, compressedSize, packet.getUncompressedSize()); + packet.loadFinalizedContent(voxelData, compressedSize); + if (Menu::getInstance()->isOptionChecked(MenuOption::ExtraDebugging)) { + qDebug("got packet numBytes=%d finalized size %d uncompressed size %d\n",numBytes, compressedSize, packet.getUncompressedSize()); + } _tree->readBitstreamToTree(packet.getUncompressedData(), packet.getUncompressedSize(), args); unlockTree(); } @@ -613,8 +615,10 @@ printf("got packet numBytes=%d compressed size %d uncompressed size %d\n",numByt lockTree(); VoxelPacket packet(VOXEL_PACKET_COMPRESSION_DEFAULT); int compressedSize = numBytes - numBytesPacketHeader; - packet.loadCompressedContent(voxelData, compressedSize); -printf("got packet numBytes=%d compressed size %d uncompressed size %d\n",numBytes, compressedSize, packet.getUncompressedSize()); + packet.loadFinalizedContent(voxelData, compressedSize); + if (Menu::getInstance()->isOptionChecked(MenuOption::ExtraDebugging)) { + qDebug("got packet numBytes=%d finalized size %d uncompressed size %d\n",numBytes, compressedSize, packet.getUncompressedSize()); + } _tree->readBitstreamToTree(packet.getUncompressedData(), packet.getUncompressedSize(), args); unlockTree(); } diff --git a/libraries/shared/src/OctalCode.cpp b/libraries/shared/src/OctalCode.cpp index 5f79a7dfa5..027a6a4d68 100644 --- a/libraries/shared/src/OctalCode.cpp +++ b/libraries/shared/src/OctalCode.cpp @@ -32,12 +32,12 @@ int numberOfThreeBitSectionsInCode(const unsigned char* octalCode, int maxBytes) void printOctalCode(const unsigned char* octalCode) { if (!octalCode) { - printf("NULL\n"); + qDebug("NULL\n"); } else { for (int i = 0; i < bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(octalCode)); i++) { outputBits(octalCode[i],false); } - printf("\n"); + qDebug("\n"); } } diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index b9d5f9da60..8c56c250e0 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -71,18 +71,18 @@ void outputBufferBits(const unsigned char* buffer, int length, bool withNewLine) void outputBits(unsigned char byte, bool withNewLine) { if (isalnum(byte)) { - printf("[ %d (%c): ", byte, byte); + qDebug("[ %d (%c): ", byte, byte); } else { - printf("[ %d (0x%x): ", byte, byte); + qDebug("[ %d (0x%x): ", byte, byte); } for (int i = 0; i < 8; i++) { - printf("%d", byte >> (7 - i) & 1); + qDebug("%d", byte >> (7 - i) & 1); } - printf(" ] "); + qDebug(" ] "); if (withNewLine) { - printf("\n"); + qDebug("\n"); } } diff --git a/libraries/voxel-server-library/src/VoxelSendThread.cpp b/libraries/voxel-server-library/src/VoxelSendThread.cpp index 4137ad67cc..6c51156490 100644 --- a/libraries/voxel-server-library/src/VoxelSendThread.cpp +++ b/libraries/voxel-server-library/src/VoxelSendThread.cpp @@ -374,15 +374,7 @@ int VoxelSendThread::deepestLevelVoxelDistributor(Node* node, VoxelNodeData* nod _myServer->getServerTree().lockForRead(); nodeData->stats.encodeStarted(); - - //printf("calling nodeBag.count()=%d encode()... subTree=%p \n", nodeData->nodeBag.count(), subTree); - //printOctalCode(subTree->getOctalCode()); - bytesWritten = _myServer->getServerTree().encodeTreeBitstream(subTree, &_tempPacket, nodeData->nodeBag, params); - - - //printf("called encode()... bytesWritten=%d compressedSize=%d uncompressedSize=%d\n",bytesWritten, _tempPacket.getFinalizedSize(), _tempPacket.getUncompressedSize()); - if (bytesWritten > 0) { _encodedSomething = true; } @@ -399,7 +391,10 @@ int VoxelSendThread::deepestLevelVoxelDistributor(Node* node, VoxelNodeData* nod // mean we should send the previous packet contents and reset it. bool sendNow = (bytesWritten == 0); if (_tempPacket.hasContent() && sendNow) { - //printf("calling writeToPacket() compressedSize=%d uncompressedSize=%d\n",_tempPacket.getFinalizedSize(), _tempPacket.getUncompressedSize()); + if (_myServer->wantsDebugVoxelSending() && _myServer->wantsVerboseDebug()) { + printf("calling writeToPacket() compressedSize=%d uncompressedSize=%d\n", + _tempPacket.getFinalizedSize(), _tempPacket.getUncompressedSize()); + } nodeData->writeToPacket(_tempPacket.getFinalizedData(), _tempPacket.getFinalizedSize()); packetsSentThisInterval += handlePacketSend(node, nodeData, trueBytesSent, truePacketsSent); _tempPacket.reset(); diff --git a/libraries/voxels/src/VoxelPacket.cpp b/libraries/voxels/src/VoxelPacket.cpp index 9d0d062c1f..bbd53e070c 100644 --- a/libraries/voxels/src/VoxelPacket.cpp +++ b/libraries/voxels/src/VoxelPacket.cpp @@ -147,15 +147,19 @@ int VoxelPacket::startLevel() { void VoxelPacket::discardLevel(int key) { int bytesInLevel = _bytesInUse - key; -if (_debug) printf("discardLevel() BEFORE _dirty=%s bytesInLevel=%d _compressedBytes=%d _bytesInUse=%d\n", + if (_debug) { + printf("discardLevel() BEFORE _dirty=%s bytesInLevel=%d _compressedBytes=%d _bytesInUse=%d\n", debug::valueOf(_dirty), bytesInLevel, _compressedBytes, _bytesInUse); + } _bytesInUse -= bytesInLevel; _bytesAvailable += bytesInLevel; _dirty = true; -if (_debug) printf("discardLevel() AFTER _dirty=%s bytesInLevel=%d _compressedBytes=%d _bytesInUse=%d\n", + if (_debug) { + printf("discardLevel() AFTER _dirty=%s bytesInLevel=%d _compressedBytes=%d _bytesInUse=%d\n", debug::valueOf(_dirty), bytesInLevel, _compressedBytes, _bytesInUse); + } } bool VoxelPacket::endLevel(int key) { @@ -235,7 +239,7 @@ bool VoxelPacket::checkCompress() { } -void VoxelPacket::loadCompressedContent(const unsigned char* data, int length) { +void VoxelPacket::loadFinalizedContent(const unsigned char* data, int length) { reset(); // by definition we reset upon loading compressed content if (length > 0) { diff --git a/libraries/voxels/src/VoxelPacket.h b/libraries/voxels/src/VoxelPacket.h index 2122467af1..0791907971 100644 --- a/libraries/voxels/src/VoxelPacket.h +++ b/libraries/voxels/src/VoxelPacket.h @@ -6,9 +6,10 @@ // // TO DO: // -// * improve compression to be less expensive (mostly determine when to test compression...) +// * further testing of compression to determine optimal configuration for performance and compression // // * add stats tracking for number of bytes of octal code, bitmasks, and colors in a packet. +// // * improve semantics for "reshuffle" - current approach will work for now and with compression // but wouldn't work with RLE because the colors in the levels would get reordered and RLE would need // to be recalculated @@ -82,8 +83,8 @@ public: /// has some content been written to the packet bool hasContent() const { return (_bytesInUse > 0); } - /// load compressed content to allow access to decoded content for parsing - void loadCompressedContent(const unsigned char* data, int length); + /// load finalized content to allow access to decoded content for parsing + void loadFinalizedContent(const unsigned char* data, int length); void debugContent();