mirror of
https://github.com/overte-org/overte.git
synced 2025-08-16 15:32:14 +02:00
cleaned up some comments and code
This commit is contained in:
parent
cb43b0dea1
commit
99c427c97d
6 changed files with 81 additions and 19 deletions
|
@ -60,7 +60,7 @@ bool shouldDo(float desiredInterval, float deltaTime) {
|
|||
return randFloat() < deltaTime / desiredInterval;
|
||||
}
|
||||
|
||||
void outputBufferBits(unsigned char* buffer, int length, bool withNewLine) {
|
||||
void outputBufferBits(const unsigned char* buffer, int length, bool withNewLine) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
outputBits(buffer[i], false);
|
||||
}
|
||||
|
@ -71,18 +71,18 @@ void outputBufferBits(unsigned char* buffer, int length, bool withNewLine) {
|
|||
|
||||
void outputBits(unsigned char byte, bool withNewLine) {
|
||||
if (isalnum(byte)) {
|
||||
qDebug("[ %d (%c): ", byte, byte);
|
||||
printf("[ %d (%c): ", byte, byte);
|
||||
} else {
|
||||
qDebug("[ %d (0x%x): ", byte, byte);
|
||||
printf("[ %d (0x%x): ", byte, byte);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
qDebug("%d", byte >> (7 - i) & 1);
|
||||
printf("%d", byte >> (7 - i) & 1);
|
||||
}
|
||||
qDebug(" ] ");
|
||||
printf(" ] ");
|
||||
|
||||
if (withNewLine) {
|
||||
qDebug("\n");
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ bool randomBoolean();
|
|||
|
||||
bool shouldDo(float desiredInterval, float deltaTime);
|
||||
|
||||
void outputBufferBits(unsigned char* buffer, int length, bool withNewLine = true);
|
||||
void outputBufferBits(const unsigned char* buffer, int length, bool withNewLine = true);
|
||||
void outputBits(unsigned char byte, bool withNewLine = true);
|
||||
void printVoxelCode(unsigned char* voxelCode);
|
||||
int numberOfOnes(unsigned char byte);
|
||||
|
|
|
@ -105,7 +105,7 @@ void VoxelNodeData::resetVoxelPacket() {
|
|||
_voxelPacketWaiting = false;
|
||||
}
|
||||
|
||||
void VoxelNodeData::writeToPacket(unsigned char* buffer, int bytes) {
|
||||
void VoxelNodeData::writeToPacket(const unsigned char* buffer, int bytes) {
|
||||
memcpy(_voxelPacketAt, buffer, bytes);
|
||||
_voxelPacketAvailableBytes -= bytes;
|
||||
_voxelPacketAt += bytes;
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
|
||||
void resetVoxelPacket(); // resets voxel packet to after "V" header
|
||||
|
||||
void writeToPacket(unsigned char* buffer, int bytes); // writes to end of packet
|
||||
void writeToPacket(const unsigned char* buffer, int bytes); // writes to end of packet
|
||||
|
||||
const unsigned char* getPacket() const { return _voxelPacket; }
|
||||
int getPacketLength() const { return (MAX_VOXEL_PACKET_SIZE - _voxelPacketAvailableBytes); }
|
||||
|
|
|
@ -16,6 +16,10 @@ void VoxelPacket::reset() {
|
|||
_bytesInUse = 0;
|
||||
_bytesAvailable = MAX_VOXEL_PACKET_SIZE;
|
||||
_subTreeAt = 0;
|
||||
_uncompressedData.clear();
|
||||
|
||||
//printf("VoxelPacket::reset()... ");
|
||||
//debugCompareBuffers();
|
||||
}
|
||||
|
||||
VoxelPacket::~VoxelPacket() {
|
||||
|
@ -25,10 +29,24 @@ bool VoxelPacket::append(const unsigned char* data, int length) {
|
|||
bool success = false;
|
||||
|
||||
if (length <= _bytesAvailable) {
|
||||
int priorBytesInUse = _bytesInUse;
|
||||
|
||||
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;
|
||||
_bytesAvailable -= length;
|
||||
success = true;
|
||||
|
||||
|
||||
//printf("VoxelPacket::append(data, length=%d... priorBytesInUse=%d)... ", length, priorBytesInUse);
|
||||
debugCompareBuffers();
|
||||
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
@ -37,9 +55,16 @@ bool VoxelPacket::append(unsigned char byte) {
|
|||
bool success = false;
|
||||
if (_bytesAvailable > 0) {
|
||||
_buffer[_bytesInUse] = byte;
|
||||
//_uncompressedData.append(byte);
|
||||
_uncompressedData[_bytesInUse] = byte;
|
||||
|
||||
_bytesInUse++;
|
||||
_bytesAvailable--;
|
||||
success = true;
|
||||
|
||||
//printf("VoxelPacket::append(byte)... ");
|
||||
debugCompareBuffers();
|
||||
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
@ -48,7 +73,12 @@ bool VoxelPacket::updatePriorBitMask(int offset, unsigned char bitmask) {
|
|||
bool success = false;
|
||||
if (offset >= 0 && offset < _bytesInUse) {
|
||||
_buffer[offset] = bitmask;
|
||||
_uncompressedData.replace(offset, sizeof(bitmask), (const char*)&bitmask, sizeof(bitmask));
|
||||
success = true;
|
||||
|
||||
//printf("VoxelPacket::updatePriorBitMask()... ");
|
||||
debugCompareBuffers();
|
||||
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
@ -57,7 +87,12 @@ bool VoxelPacket::updatePriorBytes(int offset, const unsigned char* replacementB
|
|||
bool success = false;
|
||||
if (length >= 0 && offset >= 0 && ((offset + length) <= _bytesInUse)) {
|
||||
memcpy(&_buffer[offset], replacementBytes, length);
|
||||
_uncompressedData.replace(offset, length, (const char*)replacementBytes, length);
|
||||
success = true;
|
||||
|
||||
//printf("VoxelPacket::updatePriorBytes(offset=%d length=%d)...", offset, length);
|
||||
debugCompareBuffers();
|
||||
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
@ -106,17 +141,12 @@ void VoxelPacket::endLevel() {
|
|||
}
|
||||
|
||||
bool VoxelPacket::appendBitMask(unsigned char bitmask) {
|
||||
bool success = false;
|
||||
if (_bytesAvailable > 0) {
|
||||
_buffer[_bytesInUse] = bitmask;
|
||||
_bytesInUse++;
|
||||
_bytesAvailable--;
|
||||
success = true;
|
||||
}
|
||||
return success;
|
||||
printf("VoxelPacket::appendBitMask()...\n");
|
||||
return append(bitmask);
|
||||
}
|
||||
|
||||
bool VoxelPacket::appendColor(const nodeColor& color) {
|
||||
printf("VoxelPacket::appendColor()...\n");
|
||||
// eventually we can make this use a dictionary...
|
||||
bool success = false;
|
||||
const int BYTES_PER_COLOR = 3;
|
||||
|
@ -153,5 +183,22 @@ 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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef __hifi__VoxelPacket__
|
||||
#define __hifi__VoxelPacket__
|
||||
|
||||
#include <QByteArray>
|
||||
|
||||
#include <SharedUtil.h>
|
||||
#include "VoxelConstants.h"
|
||||
#include "VoxelNode.h"
|
||||
|
@ -66,12 +68,20 @@ public:
|
|||
int getUncompressedByteOffset(int offsetFromEnd = 0) const { return _bytesInUse - offsetFromEnd; }
|
||||
|
||||
/// get access to the finalized data (it may be compressed or rewritten into optimal form)
|
||||
unsigned char* getFinalizedData() { return &_buffer[0]; }
|
||||
const unsigned char* getFinalizedData() {
|
||||
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)
|
||||
int getFinalizedSize() const { return _bytesInUse; }
|
||||
|
||||
/// get pointer to the start of uncompressed stream buffer
|
||||
const unsigned char* getUncompressedData() { return &_buffer[0]; }
|
||||
const unsigned char* getUncompressedData() {
|
||||
debugCompareBuffers();
|
||||
return &_buffer[0];
|
||||
//return (const unsigned char*)_uncompressedData.constData();
|
||||
}
|
||||
/// the size of the packet in uncompressed form
|
||||
int getUncompressedSize() { return _bytesInUse; }
|
||||
|
||||
|
@ -85,10 +95,15 @@ private:
|
|||
/// append a single byte, might fail if byte would cause packet to be too large
|
||||
bool append(unsigned char byte);
|
||||
|
||||
QByteArray _uncompressedData;
|
||||
unsigned char _buffer[MAX_VOXEL_PACKET_SIZE];
|
||||
|
||||
int _bytesInUse;
|
||||
int _bytesAvailable;
|
||||
int _subTreeAt;
|
||||
|
||||
void debugCompareBuffers() const;
|
||||
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__VoxelPacket__) */
|
Loading…
Reference in a new issue