mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-08 00:50:44 +02:00
Pack/Unpack asymetry fix + added forgotten consts
This commit is contained in:
parent
d9dde06c14
commit
f0af2f022e
4 changed files with 28 additions and 23 deletions
|
@ -69,12 +69,12 @@ void ModelReferential::update() {
|
|||
}
|
||||
}
|
||||
|
||||
int ModelReferential::packExtraData(unsigned char* destinationBuffer) {
|
||||
int ModelReferential::packExtraData(unsigned char* destinationBuffer) const {
|
||||
memcpy(destinationBuffer, &_modelID, sizeof(_modelID));
|
||||
return sizeof(_modelID);
|
||||
}
|
||||
|
||||
int ModelReferential::unpackExtraData(const unsigned char *sourceBuffer) {
|
||||
int ModelReferential::unpackExtraData(const unsigned char *sourceBuffer, int size) {
|
||||
memcpy(&_modelID, sourceBuffer, sizeof(_modelID));
|
||||
return sizeof(_modelID);
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ public:
|
|||
virtual void update();
|
||||
|
||||
protected:
|
||||
virtual int packExtraData(unsigned char* destinationBuffer);
|
||||
virtual int unpackExtraData(const unsigned char* sourceBuffer);
|
||||
virtual int packExtraData(unsigned char* destinationBuffer) const;
|
||||
virtual int unpackExtraData(const unsigned char* sourceBuffer, int size);
|
||||
|
||||
uint32_t _modelID;
|
||||
ModelTree* _tree;
|
||||
|
|
|
@ -36,7 +36,7 @@ Referential::Referential(const unsigned char*& sourceBuffer, AvatarData* avatar)
|
|||
Referential::~Referential() {
|
||||
}
|
||||
|
||||
int Referential::packReferential(unsigned char* destinationBuffer) {
|
||||
int Referential::packReferential(unsigned char* destinationBuffer) const {
|
||||
const unsigned char* startPosition = destinationBuffer;
|
||||
destinationBuffer += pack(destinationBuffer);
|
||||
|
||||
|
@ -53,17 +53,21 @@ int Referential::unpackReferential(const unsigned char* sourceBuffer) {
|
|||
sourceBuffer += unpack(sourceBuffer);
|
||||
|
||||
char expectedSize = *sourceBuffer++;
|
||||
char bytesRead = unpackExtraData(sourceBuffer);
|
||||
char bytesRead = unpackExtraData(sourceBuffer, expectedSize);
|
||||
_isValid = (bytesRead == expectedSize);
|
||||
if (!_isValid) {
|
||||
qDebug() << "[ERROR] Referential extra data overflow";
|
||||
}
|
||||
sourceBuffer += expectedSize;
|
||||
|
||||
return sourceBuffer - startPosition;
|
||||
}
|
||||
|
||||
int Referential::pack(unsigned char* destinationBuffer) {
|
||||
int Referential::pack(unsigned char* destinationBuffer) const {
|
||||
unsigned char* startPosition = destinationBuffer;
|
||||
*destinationBuffer++ = (unsigned char)_type;
|
||||
memcpy(destinationBuffer, &_createdAt, sizeof(_createdAt));
|
||||
destinationBuffer += sizeof(_createdAt);
|
||||
|
||||
destinationBuffer += packFloatVec3ToSignedTwoByteFixed(destinationBuffer, _translation, 0);
|
||||
destinationBuffer += packOrientationQuatToBytes(destinationBuffer, _rotation);
|
||||
|
@ -83,13 +87,14 @@ int Referential::unpack(const unsigned char* sourceBuffer) {
|
|||
return sourceBuffer - startPosition;
|
||||
}
|
||||
|
||||
|
||||
int Referential::unpackExtraData(const unsigned char* sourceBuffer) {
|
||||
const unsigned char* startPosition = sourceBuffer;
|
||||
int size = *sourceBuffer;
|
||||
_extraDataBuffer.clear();
|
||||
_extraDataBuffer.setRawData(reinterpret_cast<const char*>(sourceBuffer), size + 1);
|
||||
sourceBuffer += size + 1;
|
||||
return sourceBuffer - startPosition;
|
||||
int Referential::packExtraData(unsigned char *destinationBuffer) const {
|
||||
memcpy(destinationBuffer, _extraDataBuffer.data(), _extraDataBuffer.size());
|
||||
return _extraDataBuffer.size();
|
||||
}
|
||||
|
||||
int Referential::unpackExtraData(const unsigned char* sourceBuffer, int size) {
|
||||
_extraDataBuffer.clear();
|
||||
_extraDataBuffer.setRawData(reinterpret_cast<const char*>(sourceBuffer), size);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,24 +28,24 @@ public:
|
|||
Referential(const unsigned char*& sourceBuffer, AvatarData* avatar);
|
||||
virtual ~Referential();
|
||||
|
||||
Type type() { return _type; }
|
||||
quint64 createdAt() { return _createdAt; }
|
||||
bool isValid() { return _isValid; }
|
||||
bool hasExtraData() { return !_extraDataBuffer.isEmpty(); }
|
||||
Type type() const { return _type; }
|
||||
quint64 createdAt() const { return _createdAt; }
|
||||
bool isValid() const { return _isValid; }
|
||||
bool hasExtraData() const { return !_extraDataBuffer.isEmpty(); }
|
||||
|
||||
virtual void update() {}
|
||||
int packReferential(unsigned char* destinationBuffer);
|
||||
int packReferential(unsigned char* destinationBuffer) const;
|
||||
int unpackReferential(const unsigned char* sourceBuffer);
|
||||
|
||||
protected:
|
||||
Referential(Type type, AvatarData* avatar);
|
||||
|
||||
// packs the base class data
|
||||
int pack(unsigned char* destinationBuffer);
|
||||
int pack(unsigned char* destinationBuffer) const;
|
||||
int unpack(const unsigned char* sourceBuffer);
|
||||
// virtual functions that pack fthe extra data of subclasses (needs to be reimplemented in subclass)
|
||||
virtual int packExtraData(unsigned char* destinationBuffer) { return 0; }
|
||||
virtual int unpackExtraData(const unsigned char* sourceBuffer);
|
||||
virtual int packExtraData(unsigned char* destinationBuffer) const;
|
||||
virtual int unpackExtraData(const unsigned char* sourceBuffer, int size);
|
||||
|
||||
Type _type;
|
||||
quint64 _createdAt;
|
||||
|
|
Loading…
Reference in a new issue