mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 16:30:39 +02:00
removing compression from VoxelNodeData to eventually move it into VoxelPacket where it belongs
This commit is contained in:
parent
11d7cb64c2
commit
4c0569fc60
6 changed files with 39 additions and 108 deletions
|
@ -58,20 +58,7 @@ void VoxelPacketProcessor::processPacket(sockaddr& senderAddress, unsigned char*
|
||||||
app->_environment.parseData(&senderAddress, packetData, messageLength);
|
app->_environment.parseData(&senderAddress, packetData, messageLength);
|
||||||
} else {
|
} else {
|
||||||
app->_voxels.setDataSourceUUID(voxelServer->getUUID());
|
app->_voxels.setDataSourceUUID(voxelServer->getUUID());
|
||||||
|
app->_voxels.parseData(packetData, messageLength);
|
||||||
// these packets are commpressed...
|
|
||||||
if (VOXEL_PACKETS_COMPRESSED) {
|
|
||||||
int numBytesPacketHeader = numBytesForPacketHeader(packetData);
|
|
||||||
QByteArray compressedData((const char*)packetData + numBytesPacketHeader,
|
|
||||||
messageLength - numBytesPacketHeader);
|
|
||||||
QByteArray uncompressedData = qUncompress(compressedData);
|
|
||||||
QByteArray uncompressedPacket((const char*)packetData, numBytesPacketHeader);
|
|
||||||
uncompressedPacket.append(uncompressedData);
|
|
||||||
|
|
||||||
app->_voxels.parseData((unsigned char*)uncompressedPacket.data(), uncompressedPacket.size());
|
|
||||||
} else {
|
|
||||||
app->_voxels.parseData(packetData, messageLength);
|
|
||||||
}
|
|
||||||
app->_voxels.setDataSourceUUID(QUuid());
|
app->_voxels.setDataSourceUUID(QUuid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,11 +30,7 @@ VoxelNodeData::VoxelNodeData(Node* owningNode) :
|
||||||
_lodChanged(false),
|
_lodChanged(false),
|
||||||
_lodInitialized(false)
|
_lodInitialized(false)
|
||||||
{
|
{
|
||||||
if (VOXEL_PACKETS_COMPRESSED) {
|
_voxelPacketAvailableBytes = MAX_VOXEL_PACKET_SIZE;
|
||||||
_voxelPacketAvailableBytes = MAX_VOXEL_PACKET_SIZE * UNCOMPRESSED_SIZE_MULTIPLE;
|
|
||||||
} else {
|
|
||||||
_voxelPacketAvailableBytes = MAX_VOXEL_PACKET_SIZE;
|
|
||||||
}
|
|
||||||
_voxelPacket = new unsigned char[_voxelPacketAvailableBytes];
|
_voxelPacket = new unsigned char[_voxelPacketAvailableBytes];
|
||||||
_voxelPacketAt = _voxelPacket;
|
_voxelPacketAt = _voxelPacket;
|
||||||
_lastVoxelPacket = new unsigned char[_voxelPacketAvailableBytes];
|
_lastVoxelPacket = new unsigned char[_voxelPacketAvailableBytes];
|
||||||
|
@ -108,89 +104,15 @@ void VoxelNodeData::resetVoxelPacket() {
|
||||||
int numBytesPacketHeader = populateTypeAndVersion(_voxelPacket, voxelPacketType);
|
int numBytesPacketHeader = populateTypeAndVersion(_voxelPacket, voxelPacketType);
|
||||||
_voxelPacketAt = _voxelPacket + numBytesPacketHeader;
|
_voxelPacketAt = _voxelPacket + numBytesPacketHeader;
|
||||||
|
|
||||||
if (VOXEL_PACKETS_COMPRESSED) {
|
_voxelPacketAvailableBytes = MAX_VOXEL_PACKET_SIZE - numBytesPacketHeader;
|
||||||
_voxelPacketAvailableBytes = (MAX_VOXEL_PACKET_SIZE * UNCOMPRESSED_SIZE_MULTIPLE) - numBytesPacketHeader;
|
|
||||||
compressPacket();
|
|
||||||
} else {
|
|
||||||
_voxelPacketAvailableBytes = MAX_VOXEL_PACKET_SIZE - numBytesPacketHeader;
|
|
||||||
}
|
|
||||||
_voxelPacketWaiting = false;
|
_voxelPacketWaiting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VoxelNodeData::willFit(unsigned char* buffer, int bytes) {
|
|
||||||
bool wouldFit = false;
|
|
||||||
if (VOXEL_PACKETS_COMPRESSED) {
|
|
||||||
int uncompressedLength = getPacketLengthUncompressed();
|
|
||||||
const int MAX_COMPRESSION = 9;
|
|
||||||
// we only want to compress the data payload, not the message header
|
|
||||||
int numBytesPacketHeader = numBytesForPacketHeader(_voxelPacket);
|
|
||||||
|
|
||||||
// start with the current uncompressed data
|
|
||||||
QByteArray uncompressedTestData((const char*)_voxelPacket + numBytesPacketHeader,
|
|
||||||
uncompressedLength - numBytesPacketHeader);
|
|
||||||
|
|
||||||
// append this next buffer...
|
|
||||||
uncompressedTestData.append((const char*)buffer, bytes);
|
|
||||||
|
|
||||||
// test compress it
|
|
||||||
QByteArray compressedData = qCompress(uncompressedTestData, MAX_COMPRESSION);
|
|
||||||
|
|
||||||
wouldFit = (compressedData.size() + numBytesPacketHeader) <= MAX_VOXEL_PACKET_SIZE;
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (!wouldFit) {
|
|
||||||
printf("would not fit... previous size: %d, buffer size: %d, would be:%d MAX_VOXEL_PACKET_SIZE: %d\n",
|
|
||||||
getPacketLength(), bytes, (compressedData.size() + numBytesPacketHeader), MAX_VOXEL_PACKET_SIZE);
|
|
||||||
} else {
|
|
||||||
printf("would fit... previous size: %d, buffer size: %d, would be:%d MAX_VOXEL_PACKET_SIZE: %d\n",
|
|
||||||
getPacketLength(), bytes, (compressedData.size() + numBytesPacketHeader), MAX_VOXEL_PACKET_SIZE);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
} else {
|
|
||||||
wouldFit = bytes <= _voxelPacketAvailableBytes;
|
|
||||||
}
|
|
||||||
return wouldFit;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VoxelNodeData::writeToPacket(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;
|
||||||
_voxelPacketWaiting = true;
|
_voxelPacketWaiting = true;
|
||||||
compressPacket();
|
|
||||||
}
|
|
||||||
|
|
||||||
const unsigned char* VoxelNodeData::getPacket() const {
|
|
||||||
if (VOXEL_PACKETS_COMPRESSED) {
|
|
||||||
return (const unsigned char*)_compressedPacket.constData();
|
|
||||||
}
|
|
||||||
return _voxelPacket;
|
|
||||||
}
|
|
||||||
|
|
||||||
int VoxelNodeData::getPacketLength() const {
|
|
||||||
if (VOXEL_PACKETS_COMPRESSED) {
|
|
||||||
return _compressedPacket.size();
|
|
||||||
}
|
|
||||||
return getPacketLengthUncompressed();
|
|
||||||
}
|
|
||||||
|
|
||||||
int VoxelNodeData::getPacketLengthUncompressed() const {
|
|
||||||
if (VOXEL_PACKETS_COMPRESSED) {
|
|
||||||
return (MAX_VOXEL_PACKET_SIZE * UNCOMPRESSED_SIZE_MULTIPLE) - _voxelPacketAvailableBytes;
|
|
||||||
}
|
|
||||||
return MAX_VOXEL_PACKET_SIZE - _voxelPacketAvailableBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VoxelNodeData::compressPacket() {
|
|
||||||
int uncompressedLength = getPacketLengthUncompressed();
|
|
||||||
const int MAX_COMPRESSION = 9;
|
|
||||||
// we only want to compress the data payload, not the message header
|
|
||||||
int numBytesPacketHeader = numBytesForPacketHeader(_voxelPacket);
|
|
||||||
QByteArray compressedData = qCompress(_voxelPacket+numBytesPacketHeader,
|
|
||||||
uncompressedLength-numBytesPacketHeader, MAX_COMPRESSION);
|
|
||||||
_compressedPacket.clear();
|
|
||||||
_compressedPacket.append((const char*)_voxelPacket, numBytesPacketHeader);
|
|
||||||
_compressedPacket.append(compressedData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelNodeData::~VoxelNodeData() {
|
VoxelNodeData::~VoxelNodeData() {
|
||||||
|
|
|
@ -29,11 +29,10 @@ public:
|
||||||
void resetVoxelPacket(); // resets voxel packet to after "V" header
|
void resetVoxelPacket(); // resets voxel packet to after "V" header
|
||||||
|
|
||||||
void writeToPacket(unsigned char* buffer, int bytes); // writes to end of packet
|
void writeToPacket(unsigned char* buffer, int bytes); // writes to end of packet
|
||||||
bool willFit(unsigned char* buffer, int bytes); // tests to see if the bytes will fit
|
bool willFit(unsigned char* buffer, int bytes) { return (bytes <= _voxelPacketAvailableBytes); }
|
||||||
|
|
||||||
const unsigned char* getPacket() const;
|
const unsigned char* getPacket() const { return _voxelPacket; }
|
||||||
int getPacketLength() const;
|
int getPacketLength() const { return MAX_VOXEL_PACKET_SIZE - _voxelPacketAvailableBytes; }
|
||||||
int getPacketLengthUncompressed() const;
|
|
||||||
|
|
||||||
bool isPacketWaiting() const { return _voxelPacketWaiting; }
|
bool isPacketWaiting() const { return _voxelPacketWaiting; }
|
||||||
|
|
||||||
|
@ -112,9 +111,6 @@ private:
|
||||||
float _lastClientVoxelSizeScale;
|
float _lastClientVoxelSizeScale;
|
||||||
bool _lodChanged;
|
bool _lodChanged;
|
||||||
bool _lodInitialized;
|
bool _lodInitialized;
|
||||||
|
|
||||||
QByteArray _compressedPacket;
|
|
||||||
void compressPacket();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__hifi__VoxelNodeData__) */
|
#endif /* defined(__hifi__VoxelNodeData__) */
|
||||||
|
|
|
@ -112,14 +112,14 @@ int VoxelSendThread::handlePacketSend(Node* node, VoxelNodeData* nodeData, int&
|
||||||
|
|
||||||
int thisWastedBytes = MAX_PACKET_SIZE - statsMessageLength; // the statsMessageLength at this point includes data
|
int thisWastedBytes = MAX_PACKET_SIZE - statsMessageLength; // the statsMessageLength at this point includes data
|
||||||
::totalWastedBytes += thisWastedBytes;
|
::totalWastedBytes += thisWastedBytes;
|
||||||
::totalUncompressed += nodeData->getPacketLengthUncompressed();
|
::totalUncompressed += nodeData->getPacketLength();
|
||||||
::totalCompressed += nodeData->getPacketLength();
|
::totalCompressed += nodeData->getPacketLength();
|
||||||
::totalPackets++;
|
::totalPackets++;
|
||||||
if (debug) {
|
if (debug) {
|
||||||
qDebug("line: %d - Adding stats to packet [%d]: uncompress size:%d [%d], compressed size:%d [%d] thisWastedBytes:%d [%d]\n",
|
qDebug("line: %d - Adding stats to packet [%d]: uncompress size:%d [%d], compressed size:%d [%d] thisWastedBytes:%d [%d]\n",
|
||||||
__LINE__,
|
__LINE__,
|
||||||
totalPackets,
|
totalPackets,
|
||||||
nodeData->getPacketLengthUncompressed(), ::totalUncompressed,
|
nodeData->getPacketLength(), ::totalUncompressed,
|
||||||
nodeData->getPacketLength(), ::totalCompressed,
|
nodeData->getPacketLength(), ::totalCompressed,
|
||||||
thisWastedBytes, ::totalWastedBytes);
|
thisWastedBytes, ::totalWastedBytes);
|
||||||
}
|
}
|
||||||
|
@ -156,14 +156,14 @@ int VoxelSendThread::handlePacketSend(Node* node, VoxelNodeData* nodeData, int&
|
||||||
|
|
||||||
thisWastedBytes = MAX_PACKET_SIZE - nodeData->getPacketLength();
|
thisWastedBytes = MAX_PACKET_SIZE - nodeData->getPacketLength();
|
||||||
::totalWastedBytes += thisWastedBytes;
|
::totalWastedBytes += thisWastedBytes;
|
||||||
::totalUncompressed += nodeData->getPacketLengthUncompressed();
|
::totalUncompressed += nodeData->getPacketLength();
|
||||||
::totalCompressed += nodeData->getPacketLength();
|
::totalCompressed += nodeData->getPacketLength();
|
||||||
::totalPackets++;
|
::totalPackets++;
|
||||||
if (debug) {
|
if (debug) {
|
||||||
qDebug("line: %d - Sending packet [%d]: uncompress size:%d [%d], compressed size:%d [%d] thisWastedBytes:%d [%d]\n",
|
qDebug("line: %d - Sending packet [%d]: uncompress size:%d [%d], compressed size:%d [%d] thisWastedBytes:%d [%d]\n",
|
||||||
__LINE__,
|
__LINE__,
|
||||||
totalPackets,
|
totalPackets,
|
||||||
nodeData->getPacketLengthUncompressed(), ::totalUncompressed,
|
nodeData->getPacketLength(), ::totalUncompressed,
|
||||||
nodeData->getPacketLength(), ::totalCompressed,
|
nodeData->getPacketLength(), ::totalCompressed,
|
||||||
thisWastedBytes, ::totalWastedBytes);
|
thisWastedBytes, ::totalWastedBytes);
|
||||||
}
|
}
|
||||||
|
@ -179,14 +179,14 @@ int VoxelSendThread::handlePacketSend(Node* node, VoxelNodeData* nodeData, int&
|
||||||
|
|
||||||
int thisWastedBytes = MAX_PACKET_SIZE - nodeData->getPacketLength();
|
int thisWastedBytes = MAX_PACKET_SIZE - nodeData->getPacketLength();
|
||||||
::totalWastedBytes += thisWastedBytes;
|
::totalWastedBytes += thisWastedBytes;
|
||||||
::totalUncompressed += nodeData->getPacketLengthUncompressed();
|
::totalUncompressed += nodeData->getPacketLength();
|
||||||
::totalCompressed += nodeData->getPacketLength();
|
::totalCompressed += nodeData->getPacketLength();
|
||||||
::totalPackets++;
|
::totalPackets++;
|
||||||
if (debug) {
|
if (debug) {
|
||||||
qDebug("line: %d - Sending packet [%d]: uncompress size:%d [%d], compressed size:%d [%d] thisWastedBytes:%d [%d]\n",
|
qDebug("line: %d - Sending packet [%d]: uncompress size:%d [%d], compressed size:%d [%d] thisWastedBytes:%d [%d]\n",
|
||||||
__LINE__,
|
__LINE__,
|
||||||
totalPackets,
|
totalPackets,
|
||||||
nodeData->getPacketLengthUncompressed(), ::totalUncompressed,
|
nodeData->getPacketLength(), ::totalUncompressed,
|
||||||
nodeData->getPacketLength(), ::totalCompressed,
|
nodeData->getPacketLength(), ::totalCompressed,
|
||||||
thisWastedBytes, ::totalWastedBytes);
|
thisWastedBytes, ::totalWastedBytes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,3 +129,29 @@ bool VoxelPacket::appendColor(rgbColor color) {
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
void VoxelPacket::compressPacket() {
|
||||||
|
int uncompressedLength = getPacketLengthUncompressed();
|
||||||
|
const int MAX_COMPRESSION = 9;
|
||||||
|
// we only want to compress the data payload, not the message header
|
||||||
|
int numBytesPacketHeader = numBytesForPacketHeader(_voxelPacket);
|
||||||
|
QByteArray compressedData = qCompress(_voxelPacket+numBytesPacketHeader,
|
||||||
|
uncompressedLength-numBytesPacketHeader, MAX_COMPRESSION);
|
||||||
|
_compressedPacket.clear();
|
||||||
|
_compressedPacket.append((const char*)_voxelPacket, numBytesPacketHeader);
|
||||||
|
_compressedPacket.append(compressedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VoxelPacket::uncompressPacket() {
|
||||||
|
int numBytesPacketHeader = numBytesForPacketHeader(packetData);
|
||||||
|
QByteArray compressedData((const char*)packetData + numBytesPacketHeader,
|
||||||
|
messageLength - numBytesPacketHeader);
|
||||||
|
QByteArray uncompressedData = qUncompress(compressedData);
|
||||||
|
QByteArray uncompressedPacket((const char*)packetData, numBytesPacketHeader);
|
||||||
|
uncompressedPacket.append(uncompressedData);
|
||||||
|
//app->_voxels.parseData((unsigned char*)uncompressedPacket.data(), uncompressedPacket.size());
|
||||||
|
}
|
||||||
|
***/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1247,7 +1247,7 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node,
|
||||||
unsigned char childrenExistInTreeBits = 0;
|
unsigned char childrenExistInTreeBits = 0;
|
||||||
unsigned char childrenExistInPacketBits = 0;
|
unsigned char childrenExistInPacketBits = 0;
|
||||||
unsigned char childrenColoredBits = 0;
|
unsigned char childrenColoredBits = 0;
|
||||||
const int BYTES_PER_COLOR = 3;
|
const int BYTES_PER_COLOR = 3;
|
||||||
|
|
||||||
// Make our local buffer large enough to handle writing at this level in case we need to.
|
// Make our local buffer large enough to handle writing at this level in case we need to.
|
||||||
int thisLevelKey = packet->startLevel();
|
int thisLevelKey = packet->startLevel();
|
||||||
|
|
Loading…
Reference in a new issue