From 7d5dd278a19c36d57a819dbb953b8d186a349f4b Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Fri, 29 May 2015 16:54:40 -0700 Subject: [PATCH] adding unpacking --- .../src/RenderableLineEntityItem.cpp | 4 +-- .../entities/src/EntityItemProperties.cpp | 8 ++--- libraries/entities/src/LineEntityItem.cpp | 7 +++-- libraries/octree/src/OctreePacketData.cpp | 29 ++++++++++++++++--- libraries/octree/src/OctreePacketData.h | 6 ++-- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 63cd7f0234..f5e84a6bfa 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -45,8 +45,8 @@ void RenderableLineEntityItem::render(RenderArgs* args) { glm::vec3 p1 = {0, 0, 0}; glm::vec3 p2 = {1, 1, 0}; points<updateVertices(_lineVerticesID, getLinePoints(), lineColor); - geometryCache->updateVertices(_lineVerticesID, points, lineColor); + geometryCache->updateVertices(_lineVerticesID, getLinePoints(), lineColor); +// geometryCache->updateVertices(_lineVerticesID, points, lineColor); geometryCache->renderVertices(gpu::LINE_STRIP, _lineVerticesID); glPopMatrix(); diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 4a747aeea3..e0b200cdd8 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -753,9 +753,8 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem } if(properties.getType() == EntityTypes::Line){ - qDebug()<<"****** LINE WIDTH!!!!!!!!!!!!!!! **********" << properties.getLineWidth(); APPEND_ENTITY_PROPERTY(PROP_LINE_WIDTH, properties.getLineWidth()); -// APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, properties.getLinePoints()); + APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, properties.getLinePoints()); } APPEND_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, properties.getMarketplaceID()); @@ -993,10 +992,8 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int } if(properties.getType() == EntityTypes::Line) { - qDebug()<<"READING LINE ENTITY"; READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_WIDTH, float, setLineWidth); - qDebug()<<"width: "<< properties._lineWidth; -// READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_POINTS, QVector, setLinePoints); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_POINTS, QVector, setLinePoints); } READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MARKETPLACE_ID, QString, setMarketplaceID); @@ -1105,6 +1102,7 @@ void EntityItemProperties::markAllChanged() { _sourceUrlChanged = true; _lineWidthChanged = true; + _linePointsChanged = true; } /// The maximum bounding cube for the entity, independent of it's rotation. diff --git a/libraries/entities/src/LineEntityItem.cpp b/libraries/entities/src/LineEntityItem.cpp index 5806ca4c57..167b64bde2 100644 --- a/libraries/entities/src/LineEntityItem.cpp +++ b/libraries/entities/src/LineEntityItem.cpp @@ -45,13 +45,14 @@ EntityItemProperties LineEntityItem::getProperties() const { EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class - COPY_ENTITY_PROPERTY_TO_PROPERTIES(linePoints, getLinePoints); properties._color = getXColor(); properties._colorChanged = false; properties._lineWidth = getLineWidth(); properties._lineWidthChanged = false; + + COPY_ENTITY_PROPERTY_TO_PROPERTIES(linePoints, getLinePoints); properties._glowLevel = getGlowLevel(); @@ -91,7 +92,7 @@ int LineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor); READ_ENTITY_PROPERTY(PROP_LINE_WIDTH, float, setLineWidth); -// READ_ENTITY_PROPERTY(PROP_LINE_POINTS, QVector, setLinePoints); + READ_ENTITY_PROPERTY(PROP_LINE_POINTS, QVector, setLinePoints); return bytesRead; @@ -103,6 +104,7 @@ EntityPropertyFlags LineEntityItem::getEntityProperties(EncodeBitstreamParams& p EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); requestedProperties += PROP_COLOR; requestedProperties += PROP_LINE_WIDTH; + requestedProperties += PROP_LINE_POINTS; return requestedProperties; } @@ -118,6 +120,7 @@ void LineEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); APPEND_ENTITY_PROPERTY(PROP_LINE_WIDTH, getLineWidth()); + APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, getLinePoints()); } void LineEntityItem::debugDump() const { diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index 4f7d89492b..05c7e2ee5e 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -325,6 +325,7 @@ bool OctreePacketData::appendValue(uint8_t value) { bool OctreePacketData::appendValue(uint16_t value) { const unsigned char* data = (const unsigned char*)&value; + int length = sizeof(value); bool success = append(data, length); if (success) { @@ -381,12 +382,19 @@ bool OctreePacketData::appendValue(const glm::vec3& value) { } bool OctreePacketData::appendValue(const QVector& value){ - const unsigned char* data = (const unsigned char*)&value; - int length = sizeof(value); - bool success = append(data, length); - if (success){ + const unsigned char* data = (const unsigned char*)value.data(); + uint16_t qVecSize = (uint16_t)value.size(); + int length = qVecSize * sizeof(glm::vec3); + const unsigned char* sizePointer = (const unsigned char*)&qVecSize; + bool success = append(sizePointer, sizeof(uint16_t)); + if(success){ + _bytesOfValues += qVecSize; + _totalBytesOfValues += qVecSize; + success = append(data, length); + if (success){ _bytesOfValues += length; _totalBytesOfValues += length; + } } return success; } @@ -462,6 +470,9 @@ bool OctreePacketData::appendRawData(const unsigned char* data, int length) { } return success; } +bool OctreePacketData::appendRawData(QByteArray data) { + return appendRawData((unsigned char *)data.data(), data.size()); +} quint64 OctreePacketData::_compressContentTime = 0; quint64 OctreePacketData::_compressContentCalls = 0; @@ -585,3 +596,13 @@ int OctreePacketData::uppackDataFromBytes(const unsigned char* dataBytes, xColor result.blue = dataBytes[BLUE_INDEX]; return sizeof(rgbColor); } + +int OctreePacketData::uppackDataFromBytes(const unsigned char *dataBytes, QVector& result){ + uint16_t length; + memcpy(&length, dataBytes, sizeof(length)); + dataBytes+= sizeof(length); + qDebug()<<"size of LENGTH: "<& result) {memcpy(&result, dataBytes, sizeof(result)); return sizeof(result);} static int uppackDataFromBytes(const unsigned char* dataBytes, bool& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } static int uppackDataFromBytes(const unsigned char* dataBytes, quint64& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } static int uppackDataFromBytes(const unsigned char* dataBytes, uint32_t& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } @@ -244,7 +244,7 @@ public: static int uppackDataFromBytes(const unsigned char* dataBytes, QString& result); static int uppackDataFromBytes(const unsigned char* dataBytes, QUuid& result); static int uppackDataFromBytes(const unsigned char* dataBytes, xColor& result); - + static int uppackDataFromBytes(const unsigned char* dataBytes, QVector& result); private: /// appends raw bytes, might fail if byte would cause packet to be too large