Revert "cleaned up some comments and code"

This reverts commit 99c427c97d.
This commit is contained in:
ZappoMan 2013-11-23 16:19:57 -08:00
parent 99c427c97d
commit 0f66f4c1bd
6 changed files with 19 additions and 81 deletions

View file

@ -60,7 +60,7 @@ bool shouldDo(float desiredInterval, float deltaTime) {
return randFloat() < deltaTime / desiredInterval; return randFloat() < deltaTime / desiredInterval;
} }
void outputBufferBits(const unsigned char* buffer, int length, bool withNewLine) { void outputBufferBits(unsigned char* buffer, int length, bool withNewLine) {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
outputBits(buffer[i], false); outputBits(buffer[i], false);
} }
@ -71,18 +71,18 @@ void outputBufferBits(const unsigned char* buffer, int length, bool withNewLine)
void outputBits(unsigned char byte, bool withNewLine) { void outputBits(unsigned char byte, bool withNewLine) {
if (isalnum(byte)) { if (isalnum(byte)) {
printf("[ %d (%c): ", byte, byte); qDebug("[ %d (%c): ", byte, byte);
} else { } else {
printf("[ %d (0x%x): ", byte, byte); qDebug("[ %d (0x%x): ", byte, byte);
} }
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
printf("%d", byte >> (7 - i) & 1); qDebug("%d", byte >> (7 - i) & 1);
} }
printf(" ] "); qDebug(" ] ");
if (withNewLine) { if (withNewLine) {
printf("\n"); qDebug("\n");
} }
} }

View file

@ -52,7 +52,7 @@ bool randomBoolean();
bool shouldDo(float desiredInterval, float deltaTime); bool shouldDo(float desiredInterval, float deltaTime);
void outputBufferBits(const unsigned char* buffer, int length, bool withNewLine = true); void outputBufferBits(unsigned char* buffer, int length, bool withNewLine = true);
void outputBits(unsigned char byte, bool withNewLine = true); void outputBits(unsigned char byte, bool withNewLine = true);
void printVoxelCode(unsigned char* voxelCode); void printVoxelCode(unsigned char* voxelCode);
int numberOfOnes(unsigned char byte); int numberOfOnes(unsigned char byte);

View file

@ -105,7 +105,7 @@ void VoxelNodeData::resetVoxelPacket() {
_voxelPacketWaiting = false; _voxelPacketWaiting = false;
} }
void VoxelNodeData::writeToPacket(const unsigned char* buffer, int bytes) { void VoxelNodeData::writeToPacket(unsigned char* buffer, int bytes) {
memcpy(_voxelPacketAt, buffer, bytes); memcpy(_voxelPacketAt, buffer, bytes);
_voxelPacketAvailableBytes -= bytes; _voxelPacketAvailableBytes -= bytes;
_voxelPacketAt += bytes; _voxelPacketAt += bytes;

View file

@ -28,7 +28,7 @@ public:
void resetVoxelPacket(); // resets voxel packet to after "V" header void resetVoxelPacket(); // resets voxel packet to after "V" header
void writeToPacket(const unsigned char* buffer, int bytes); // writes to end of packet void writeToPacket(unsigned char* buffer, int bytes); // writes to end of packet
const unsigned char* getPacket() const { return _voxelPacket; } const unsigned char* getPacket() const { return _voxelPacket; }
int getPacketLength() const { return (MAX_VOXEL_PACKET_SIZE - _voxelPacketAvailableBytes); } int getPacketLength() const { return (MAX_VOXEL_PACKET_SIZE - _voxelPacketAvailableBytes); }

View file

@ -16,10 +16,6 @@ void VoxelPacket::reset() {
_bytesInUse = 0; _bytesInUse = 0;
_bytesAvailable = MAX_VOXEL_PACKET_SIZE; _bytesAvailable = MAX_VOXEL_PACKET_SIZE;
_subTreeAt = 0; _subTreeAt = 0;
_uncompressedData.clear();
//printf("VoxelPacket::reset()... ");
//debugCompareBuffers();
} }
VoxelPacket::~VoxelPacket() { VoxelPacket::~VoxelPacket() {
@ -29,24 +25,10 @@ bool VoxelPacket::append(const unsigned char* data, int length) {
bool success = false; bool success = false;
if (length <= _bytesAvailable) { if (length <= _bytesAvailable) {
int priorBytesInUse = _bytesInUse;
memcpy(&_buffer[_bytesInUse], data, length); memcpy(&_buffer[_bytesInUse], data, length);
//QByteArray newData((const char*)data, length);
//_uncompressedData.append(newData);
_uncompressedData.resize(_bytesInUse+length);
char* writeable = _uncompressedData.data();
memcpy(&writeable[_bytesInUse], data, length);
_bytesInUse += length; _bytesInUse += length;
_bytesAvailable -= length; _bytesAvailable -= length;
success = true; success = true;
//printf("VoxelPacket::append(data, length=%d... priorBytesInUse=%d)... ", length, priorBytesInUse);
debugCompareBuffers();
} }
return success; return success;
} }
@ -55,16 +37,9 @@ bool VoxelPacket::append(unsigned char byte) {
bool success = false; bool success = false;
if (_bytesAvailable > 0) { if (_bytesAvailable > 0) {
_buffer[_bytesInUse] = byte; _buffer[_bytesInUse] = byte;
//_uncompressedData.append(byte);
_uncompressedData[_bytesInUse] = byte;
_bytesInUse++; _bytesInUse++;
_bytesAvailable--; _bytesAvailable--;
success = true; success = true;
//printf("VoxelPacket::append(byte)... ");
debugCompareBuffers();
} }
return success; return success;
} }
@ -73,12 +48,7 @@ bool VoxelPacket::updatePriorBitMask(int offset, unsigned char bitmask) {
bool success = false; bool success = false;
if (offset >= 0 && offset < _bytesInUse) { if (offset >= 0 && offset < _bytesInUse) {
_buffer[offset] = bitmask; _buffer[offset] = bitmask;
_uncompressedData.replace(offset, sizeof(bitmask), (const char*)&bitmask, sizeof(bitmask));
success = true; success = true;
//printf("VoxelPacket::updatePriorBitMask()... ");
debugCompareBuffers();
} }
return success; return success;
} }
@ -87,12 +57,7 @@ bool VoxelPacket::updatePriorBytes(int offset, const unsigned char* replacementB
bool success = false; bool success = false;
if (length >= 0 && offset >= 0 && ((offset + length) <= _bytesInUse)) { if (length >= 0 && offset >= 0 && ((offset + length) <= _bytesInUse)) {
memcpy(&_buffer[offset], replacementBytes, length); memcpy(&_buffer[offset], replacementBytes, length);
_uncompressedData.replace(offset, length, (const char*)replacementBytes, length);
success = true; success = true;
//printf("VoxelPacket::updatePriorBytes(offset=%d length=%d)...", offset, length);
debugCompareBuffers();
} }
return success; return success;
} }
@ -141,12 +106,17 @@ void VoxelPacket::endLevel() {
} }
bool VoxelPacket::appendBitMask(unsigned char bitmask) { bool VoxelPacket::appendBitMask(unsigned char bitmask) {
printf("VoxelPacket::appendBitMask()...\n"); bool success = false;
return append(bitmask); if (_bytesAvailable > 0) {
_buffer[_bytesInUse] = bitmask;
_bytesInUse++;
_bytesAvailable--;
success = true;
}
return success;
} }
bool VoxelPacket::appendColor(const nodeColor& color) { bool VoxelPacket::appendColor(const nodeColor& color) {
printf("VoxelPacket::appendColor()...\n");
// eventually we can make this use a dictionary... // eventually we can make this use a dictionary...
bool success = false; bool success = false;
const int BYTES_PER_COLOR = 3; const int BYTES_PER_COLOR = 3;
@ -183,22 +153,5 @@ void VoxelPacket::uncompressPacket() {
} }
***/ ***/
void VoxelPacket::debugCompareBuffers() const {
const unsigned char* buffer = &_buffer[0];
const unsigned char* byteArray = (const unsigned char*)_uncompressedData.constData();
if (memcmp(buffer, byteArray, _bytesInUse) == 0) {
//printf("VoxelPacket::debugCompareBuffers()... they match...\n");
//printf("\n");
} else {
printf("VoxelPacket::debugCompareBuffers()... THEY DON'T MATCH <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
printf("_buffer=");
outputBufferBits(buffer, _bytesInUse);
printf("_uncompressedData=");
outputBufferBits(byteArray, _bytesInUse);
printf("VoxelPacket::debugCompareBuffers()... THEY DON'T MATCH <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
}
}

View file

@ -16,8 +16,6 @@
#ifndef __hifi__VoxelPacket__ #ifndef __hifi__VoxelPacket__
#define __hifi__VoxelPacket__ #define __hifi__VoxelPacket__
#include <QByteArray>
#include <SharedUtil.h> #include <SharedUtil.h>
#include "VoxelConstants.h" #include "VoxelConstants.h"
#include "VoxelNode.h" #include "VoxelNode.h"
@ -68,20 +66,12 @@ public:
int getUncompressedByteOffset(int offsetFromEnd = 0) const { return _bytesInUse - offsetFromEnd; } int getUncompressedByteOffset(int offsetFromEnd = 0) const { return _bytesInUse - offsetFromEnd; }
/// get access to the finalized data (it may be compressed or rewritten into optimal form) /// get access to the finalized data (it may be compressed or rewritten into optimal form)
const unsigned char* getFinalizedData() { unsigned char* getFinalizedData() { return &_buffer[0]; }
debugCompareBuffers();
return &_buffer[0];
//return (const unsigned char*)_uncompressedData.constData();
}
/// get size of the finalized data (it may be compressed or rewritten into optimal form) /// get size of the finalized data (it may be compressed or rewritten into optimal form)
int getFinalizedSize() const { return _bytesInUse; } int getFinalizedSize() const { return _bytesInUse; }
/// get pointer to the start of uncompressed stream buffer /// get pointer to the start of uncompressed stream buffer
const unsigned char* getUncompressedData() { const unsigned char* getUncompressedData() { return &_buffer[0]; }
debugCompareBuffers();
return &_buffer[0];
//return (const unsigned char*)_uncompressedData.constData();
}
/// the size of the packet in uncompressed form /// the size of the packet in uncompressed form
int getUncompressedSize() { return _bytesInUse; } int getUncompressedSize() { return _bytesInUse; }
@ -95,15 +85,10 @@ private:
/// append a single byte, might fail if byte would cause packet to be too large /// append a single byte, might fail if byte would cause packet to be too large
bool append(unsigned char byte); bool append(unsigned char byte);
QByteArray _uncompressedData;
unsigned char _buffer[MAX_VOXEL_PACKET_SIZE]; unsigned char _buffer[MAX_VOXEL_PACKET_SIZE];
int _bytesInUse; int _bytesInUse;
int _bytesAvailable; int _bytesAvailable;
int _subTreeAt; int _subTreeAt;
void debugCompareBuffers() const;
}; };
#endif /* defined(__hifi__VoxelPacket__) */ #endif /* defined(__hifi__VoxelPacket__) */