From 513285a00e6216c891fdcff3edb31803a620248b Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 29 Jun 2015 07:27:34 -0700 Subject: [PATCH] use macros for packing/unpacking QByteArray --- .../entities/src/EntityItemProperties.cpp | 35 +++++-------------- libraries/entities/src/EntityItemProperties.h | 1 + 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index ae37d61e5f..2705933b72 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -706,22 +706,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem // PROP_PAGED_PROPERTY, // PROP_CUSTOM_PROPERTIES_INCLUDED, - if (requestedProperties.getHasProperty(PROP_SIMULATION_OWNER)) { - LevelDetails propertyLevel = packetData->startLevel(); - successPropertyFits = packetData->appendValue(properties._simulationOwner.toByteArray()); - if (successPropertyFits) { - propertyFlags |= PROP_SIMULATION_OWNER; - propertiesDidntFit -= PROP_SIMULATION_OWNER; - propertyCount++; - packetData->endLevel(propertyLevel); - } else { - packetData->discardLevel(propertyLevel); - appendState = OctreeElement::PARTIAL; - } - } else { - propertiesDidntFit -= PROP_SIMULATION_OWNER; - } - + APPEND_ENTITY_PROPERTY(PROP_SIMULATION_OWNER, properties._simulationOwner.toByteArray()); APPEND_ENTITY_PROPERTY(PROP_POSITION, properties.getPosition()); APPEND_ENTITY_PROPERTY(PROP_DIMENSIONS, properties.getDimensions()); // NOTE: PROP_RADIUS obsolete APPEND_ENTITY_PROPERTY(PROP_ROTATION, properties.getRotation()); @@ -976,17 +961,7 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int dataAt += propertyFlags.getEncodedLength(); processedBytes += propertyFlags.getEncodedLength(); - if (propertyFlags.getHasProperty(PROP_SIMULATION_OWNER)) { - QByteArray fromBuffer; - int bytes = OctreePacketData::unpackDataFromBytes(dataAt, fromBuffer); - - dataAt += bytes; - processedBytes += bytes; - SimulationOwner simOwner; - simOwner.fromByteArray(fromBuffer); - properties.setSimulationOwner(simOwner); - } - + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SIMULATION_OWNER, QByteArray, setSimulationOwner); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_POSITION, glm::vec3, setPosition); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_DIMENSIONS, glm::vec3, setDimensions); // NOTE: PROP_RADIUS obsolete READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ROTATION, glm::quat, setRotation); @@ -1271,3 +1246,9 @@ void EntityItemProperties::setSimulationOwner(const QUuid& id, uint8_t priority) _simulationOwnerChanged = true; } } + +void EntityItemProperties::setSimulationOwner(const QByteArray& data) { + if (_simulationOwner.fromByteArray(data)) { + _simulationOwnerChanged = true; + } +} diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 32190664e4..3ad12a03f5 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -210,6 +210,7 @@ public: void clearSimulationOwner(); void setSimulationOwner(const QUuid& id, uint8_t priority); + void setSimulationOwner(const QByteArray& data); void promoteSimulationPriority(quint8 priority) { _simulationOwner.promotePriority(priority); } private: