mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-08 18:16:49 +02:00
DRY up the property setting code by using macro for repeated pattern
This commit is contained in:
parent
033017346c
commit
799931aa6c
7 changed files with 76 additions and 553 deletions
|
@ -109,21 +109,5 @@ void BoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitst
|
||||||
|
|
||||||
bool successPropertyFits = true;
|
bool successPropertyFits = true;
|
||||||
|
|
||||||
// PROP_COLOR
|
APPEND_ENTITY_PROPERTY(PROP_COLOR, appendColor, getColor());
|
||||||
if (requestedProperties.getHasProperty(PROP_COLOR)) {
|
|
||||||
LevelDetails propertyLevel = packetData->startLevel();
|
|
||||||
successPropertyFits = packetData->appendColor(getColor());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_COLOR;
|
|
||||||
propertiesDidntFit -= PROP_COLOR;
|
|
||||||
propertyCount++;
|
|
||||||
packetData->endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData->discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_COLOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -171,158 +171,15 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet
|
||||||
// PROP_CUSTOM_PROPERTIES_INCLUDED,
|
// PROP_CUSTOM_PROPERTIES_INCLUDED,
|
||||||
// PROP_VISIBLE,
|
// PROP_VISIBLE,
|
||||||
|
|
||||||
// PROP_POSITION
|
APPEND_ENTITY_PROPERTY(PROP_POSITION, appendPosition, getPosition());
|
||||||
if (requestedProperties.getHasProperty(PROP_POSITION)) {
|
APPEND_ENTITY_PROPERTY(PROP_RADIUS, appendValue, getRadius());
|
||||||
LevelDetails propertyLevel = packetData->startLevel();
|
APPEND_ENTITY_PROPERTY(PROP_ROTATION, appendValue, getRotation());
|
||||||
successPropertyFits = packetData->appendPosition(getPosition());
|
APPEND_ENTITY_PROPERTY(PROP_MASS, appendValue, getMass());
|
||||||
if (successPropertyFits) {
|
APPEND_ENTITY_PROPERTY(PROP_VELOCITY, appendValue, getVelocity());
|
||||||
propertyFlags |= PROP_POSITION;
|
APPEND_ENTITY_PROPERTY(PROP_GRAVITY, appendValue, getGravity());
|
||||||
propertiesDidntFit -= PROP_POSITION;
|
APPEND_ENTITY_PROPERTY(PROP_DAMPING, appendValue, getDamping());
|
||||||
propertyCount++;
|
APPEND_ENTITY_PROPERTY(PROP_LIFETIME, appendValue, getLifetime());
|
||||||
packetData->endLevel(propertyLevel);
|
APPEND_ENTITY_PROPERTY(PROP_SCRIPT, appendValue, getScript());
|
||||||
} else {
|
|
||||||
packetData->discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_POSITION;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_RADIUS
|
|
||||||
if (requestedProperties.getHasProperty(PROP_RADIUS)) {
|
|
||||||
LevelDetails propertyLevel = packetData->startLevel();
|
|
||||||
successPropertyFits = packetData->appendValue(getRadius());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_RADIUS;
|
|
||||||
propertiesDidntFit -= PROP_RADIUS;
|
|
||||||
propertyCount++;
|
|
||||||
packetData->endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData->discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_RADIUS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_ROTATION
|
|
||||||
if (requestedProperties.getHasProperty(PROP_ROTATION)) {
|
|
||||||
LevelDetails propertyLevel = packetData->startLevel();
|
|
||||||
successPropertyFits = packetData->appendValue(getRotation());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_ROTATION;
|
|
||||||
propertiesDidntFit -= PROP_ROTATION;
|
|
||||||
propertyCount++;
|
|
||||||
packetData->endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData->discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_ROTATION;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_MASS,
|
|
||||||
if (requestedProperties.getHasProperty(PROP_MASS)) {
|
|
||||||
LevelDetails propertyLevel = packetData->startLevel();
|
|
||||||
successPropertyFits = packetData->appendValue(getMass());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_MASS;
|
|
||||||
propertiesDidntFit -= PROP_MASS;
|
|
||||||
propertyCount++;
|
|
||||||
packetData->endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData->discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_MASS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_VELOCITY,
|
|
||||||
if (requestedProperties.getHasProperty(PROP_VELOCITY)) {
|
|
||||||
LevelDetails propertyLevel = packetData->startLevel();
|
|
||||||
successPropertyFits = packetData->appendValue(getVelocity());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_VELOCITY;
|
|
||||||
propertiesDidntFit -= PROP_VELOCITY;
|
|
||||||
propertyCount++;
|
|
||||||
packetData->endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData->discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_VELOCITY;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_GRAVITY,
|
|
||||||
if (requestedProperties.getHasProperty(PROP_GRAVITY)) {
|
|
||||||
LevelDetails propertyLevel = packetData->startLevel();
|
|
||||||
successPropertyFits = packetData->appendValue(getGravity());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_GRAVITY;
|
|
||||||
propertiesDidntFit -= PROP_GRAVITY;
|
|
||||||
propertyCount++;
|
|
||||||
packetData->endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData->discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_GRAVITY;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_DAMPING,
|
|
||||||
if (requestedProperties.getHasProperty(PROP_DAMPING)) {
|
|
||||||
LevelDetails propertyLevel = packetData->startLevel();
|
|
||||||
successPropertyFits = packetData->appendValue(getDamping());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_DAMPING;
|
|
||||||
propertiesDidntFit -= PROP_DAMPING;
|
|
||||||
propertyCount++;
|
|
||||||
packetData->endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData->discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_DAMPING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_LIFETIME,
|
|
||||||
if (requestedProperties.getHasProperty(PROP_LIFETIME)) {
|
|
||||||
LevelDetails propertyLevel = packetData->startLevel();
|
|
||||||
successPropertyFits = packetData->appendValue(getLifetime());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_LIFETIME;
|
|
||||||
propertiesDidntFit -= PROP_LIFETIME;
|
|
||||||
propertyCount++;
|
|
||||||
packetData->endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData->discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_LIFETIME;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_SCRIPT,
|
|
||||||
if (requestedProperties.getHasProperty(PROP_SCRIPT)) {
|
|
||||||
LevelDetails propertyLevel = packetData->startLevel();
|
|
||||||
successPropertyFits = packetData->appendValue(getScript());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_SCRIPT;
|
|
||||||
propertiesDidntFit -= PROP_SCRIPT;
|
|
||||||
propertyCount++;
|
|
||||||
packetData->endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData->discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_SCRIPT;
|
|
||||||
}
|
|
||||||
|
|
||||||
appendSubclassData(packetData, params, entityTreeElementExtraEncodeData,
|
appendSubclassData(packetData, params, entityTreeElementExtraEncodeData,
|
||||||
requestedProperties,
|
requestedProperties,
|
||||||
|
|
|
@ -208,4 +208,6 @@ protected:
|
||||||
QString _script;
|
QString _script;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // hifi_EntityItem_h
|
#endif // hifi_EntityItem_h
|
||||||
|
|
|
@ -433,7 +433,8 @@ void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemP
|
||||||
bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItemID id, const EntityItemProperties& properties,
|
bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItemID id, const EntityItemProperties& properties,
|
||||||
unsigned char* bufferOut, int sizeIn, int& sizeOut) {
|
unsigned char* bufferOut, int sizeIn, int& sizeOut) {
|
||||||
|
|
||||||
OctreePacketData packetData(false, sizeIn); // create a packetData object to add out packet details too.
|
OctreePacketData ourDataPacket(false, sizeIn); // create a packetData object to add out packet details too.
|
||||||
|
OctreePacketData* packetData = &ourDataPacket; // we want a pointer to this so we can use our APPEND_ENTITY_PROPERTY macro
|
||||||
|
|
||||||
bool success = true; // assume the best
|
bool success = true; // assume the best
|
||||||
OctreeElement::AppendState appendState = OctreeElement::COMPLETED; // assume the best
|
OctreeElement::AppendState appendState = OctreeElement::COMPLETED; // assume the best
|
||||||
|
@ -449,7 +450,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
|
||||||
float rootScale = 0.5f;
|
float rootScale = 0.5f;
|
||||||
unsigned char* octcode = pointToOctalCode(rootPosition.x, rootPosition.y, rootPosition.z, rootScale);
|
unsigned char* octcode = pointToOctalCode(rootPosition.x, rootPosition.y, rootPosition.z, rootScale);
|
||||||
|
|
||||||
success = packetData.startSubTree(octcode);
|
success = packetData->startSubTree(octcode);
|
||||||
delete[] octcode;
|
delete[] octcode;
|
||||||
|
|
||||||
// assuming we have rome to fit our octalCode, proceed...
|
// assuming we have rome to fit our octalCode, proceed...
|
||||||
|
@ -493,36 +494,36 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
|
||||||
// requestedProperties = modelTreeElementExtraEncodeData->includedItems.value(getEntityItemID());
|
// requestedProperties = modelTreeElementExtraEncodeData->includedItems.value(getEntityItemID());
|
||||||
//}
|
//}
|
||||||
|
|
||||||
LevelDetails entityLevel = packetData.startLevel();
|
LevelDetails entityLevel = packetData->startLevel();
|
||||||
|
|
||||||
// Last Edited quint64 always first, before any other details, which allows us easy access to adjusting this
|
// Last Edited quint64 always first, before any other details, which allows us easy access to adjusting this
|
||||||
// timestamp for clock skew
|
// timestamp for clock skew
|
||||||
quint64 lastEdited = properties.getLastEdited();
|
quint64 lastEdited = properties.getLastEdited();
|
||||||
bool successLastEditedFits = packetData.appendValue(lastEdited);
|
bool successLastEditedFits = packetData->appendValue(lastEdited);
|
||||||
|
|
||||||
bool successIDFits = packetData.appendValue(encodedID);
|
bool successIDFits = packetData->appendValue(encodedID);
|
||||||
if (isNewEntityItem && successIDFits) {
|
if (isNewEntityItem && successIDFits) {
|
||||||
successIDFits = packetData.appendValue(encodedToken);
|
successIDFits = packetData->appendValue(encodedToken);
|
||||||
}
|
}
|
||||||
bool successTypeFits = packetData.appendValue(encodedType);
|
bool successTypeFits = packetData->appendValue(encodedType);
|
||||||
|
|
||||||
// NOTE: We intentionally do not send "created" times in edit messages. This is because:
|
// NOTE: We intentionally do not send "created" times in edit messages. This is because:
|
||||||
// 1) if the edit is to an existing entity, the created time can not be changed
|
// 1) if the edit is to an existing entity, the created time can not be changed
|
||||||
// 2) if the edit is to a new entity, the created time is the last edited time
|
// 2) if the edit is to a new entity, the created time is the last edited time
|
||||||
|
|
||||||
// TODO: Should we get rid of this in this in edit packets, since this has to always be 0?
|
// TODO: Should we get rid of this in this in edit packets, since this has to always be 0?
|
||||||
bool successLastUpdatedFits = packetData.appendValue(encodedUpdateDelta);
|
bool successLastUpdatedFits = packetData->appendValue(encodedUpdateDelta);
|
||||||
|
|
||||||
int propertyFlagsOffset = packetData.getUncompressedByteOffset();
|
int propertyFlagsOffset = packetData->getUncompressedByteOffset();
|
||||||
QByteArray encodedPropertyFlags = propertyFlags;
|
QByteArray encodedPropertyFlags = propertyFlags;
|
||||||
int oldPropertyFlagsLength = encodedPropertyFlags.length();
|
int oldPropertyFlagsLength = encodedPropertyFlags.length();
|
||||||
bool successPropertyFlagsFits = packetData.appendValue(encodedPropertyFlags);
|
bool successPropertyFlagsFits = packetData->appendValue(encodedPropertyFlags);
|
||||||
int propertyCount = 0;
|
int propertyCount = 0;
|
||||||
|
|
||||||
bool headerFits = successIDFits && successTypeFits && successLastEditedFits
|
bool headerFits = successIDFits && successTypeFits && successLastEditedFits
|
||||||
&& successLastUpdatedFits && successPropertyFlagsFits;
|
&& successLastUpdatedFits && successPropertyFlagsFits;
|
||||||
|
|
||||||
int startOfEntityItemData = packetData.getUncompressedByteOffset();
|
int startOfEntityItemData = packetData->getUncompressedByteOffset();
|
||||||
|
|
||||||
if (headerFits) {
|
if (headerFits) {
|
||||||
bool successPropertyFits;
|
bool successPropertyFits;
|
||||||
|
@ -533,276 +534,49 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
|
||||||
// PROP_CUSTOM_PROPERTIES_INCLUDED,
|
// PROP_CUSTOM_PROPERTIES_INCLUDED,
|
||||||
// PROP_VISIBLE,
|
// PROP_VISIBLE,
|
||||||
|
|
||||||
// PROP_POSITION
|
APPEND_ENTITY_PROPERTY(PROP_POSITION, appendPosition, properties.getPosition());
|
||||||
if (requestedProperties.getHasProperty(PROP_POSITION)) {
|
APPEND_ENTITY_PROPERTY(PROP_RADIUS, appendValue, properties.getRadius());
|
||||||
LevelDetails propertyLevel = packetData.startLevel();
|
APPEND_ENTITY_PROPERTY(PROP_ROTATION, appendValue, properties.getRotation());
|
||||||
successPropertyFits = packetData.appendPosition(properties.getPosition());
|
APPEND_ENTITY_PROPERTY(PROP_MASS, appendValue, properties.getMass());
|
||||||
if (successPropertyFits) {
|
APPEND_ENTITY_PROPERTY(PROP_VELOCITY, appendValue, properties.getVelocity());
|
||||||
propertyFlags |= PROP_POSITION;
|
APPEND_ENTITY_PROPERTY(PROP_GRAVITY, appendValue, properties.getGravity());
|
||||||
propertiesDidntFit -= PROP_POSITION;
|
APPEND_ENTITY_PROPERTY(PROP_DAMPING, appendValue, properties.getDamping());
|
||||||
propertyCount++;
|
APPEND_ENTITY_PROPERTY(PROP_LIFETIME, appendValue, properties.getLifetime());
|
||||||
packetData.endLevel(propertyLevel);
|
//APPEND_ENTITY_PROPERTY(PROP_SCRIPT, appendValue, properties.getScript()); // not supported by edit messages
|
||||||
} else {
|
APPEND_ENTITY_PROPERTY(PROP_COLOR, appendColor, properties.getColor());
|
||||||
packetData.discardLevel(propertyLevel);
|
APPEND_ENTITY_PROPERTY(PROP_MODEL_URL, appendValue, properties.getModelURL());
|
||||||
appendState = OctreeElement::PARTIAL;
|
APPEND_ENTITY_PROPERTY(PROP_ANIMATION_URL, appendValue, properties.getAnimationURL());
|
||||||
}
|
APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FPS, appendValue, properties.getAnimationFPS());
|
||||||
} else {
|
APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, appendValue, properties.getAnimationFrameIndex());
|
||||||
propertiesDidntFit -= PROP_POSITION;
|
APPEND_ENTITY_PROPERTY(PROP_ANIMATION_PLAYING, appendValue, properties.getAnimationIsPlaying());
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_RADIUS
|
|
||||||
if (requestedProperties.getHasProperty(PROP_RADIUS)) {
|
|
||||||
LevelDetails propertyLevel = packetData.startLevel();
|
|
||||||
successPropertyFits = packetData.appendValue(properties.getRadius());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_RADIUS;
|
|
||||||
propertiesDidntFit -= PROP_RADIUS;
|
|
||||||
propertyCount++;
|
|
||||||
packetData.endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData.discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_RADIUS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_ROTATION
|
|
||||||
if (requestedProperties.getHasProperty(PROP_ROTATION)) {
|
|
||||||
LevelDetails propertyLevel = packetData.startLevel();
|
|
||||||
successPropertyFits = packetData.appendValue(properties.getRotation());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_ROTATION;
|
|
||||||
propertiesDidntFit -= PROP_ROTATION;
|
|
||||||
propertyCount++;
|
|
||||||
packetData.endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData.discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_ROTATION;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_MASS,
|
|
||||||
if (requestedProperties.getHasProperty(PROP_MASS)) {
|
|
||||||
LevelDetails propertyLevel = packetData.startLevel();
|
|
||||||
successPropertyFits = packetData.appendValue(properties.getMass());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_MASS;
|
|
||||||
propertiesDidntFit -= PROP_MASS;
|
|
||||||
propertyCount++;
|
|
||||||
packetData.endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData.discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_MASS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_VELOCITY,
|
|
||||||
if (requestedProperties.getHasProperty(PROP_VELOCITY)) {
|
|
||||||
LevelDetails propertyLevel = packetData.startLevel();
|
|
||||||
successPropertyFits = packetData.appendValue(properties.getVelocity());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_VELOCITY;
|
|
||||||
propertiesDidntFit -= PROP_VELOCITY;
|
|
||||||
propertyCount++;
|
|
||||||
packetData.endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData.discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_VELOCITY;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_GRAVITY,
|
|
||||||
if (requestedProperties.getHasProperty(PROP_GRAVITY)) {
|
|
||||||
LevelDetails propertyLevel = packetData.startLevel();
|
|
||||||
successPropertyFits = packetData.appendValue(properties.getGravity());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_GRAVITY;
|
|
||||||
propertiesDidntFit -= PROP_GRAVITY;
|
|
||||||
propertyCount++;
|
|
||||||
packetData.endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData.discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_GRAVITY;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_DAMPING,
|
|
||||||
if (requestedProperties.getHasProperty(PROP_DAMPING)) {
|
|
||||||
LevelDetails propertyLevel = packetData.startLevel();
|
|
||||||
successPropertyFits = packetData.appendValue(properties.getDamping());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_DAMPING;
|
|
||||||
propertiesDidntFit -= PROP_DAMPING;
|
|
||||||
propertyCount++;
|
|
||||||
packetData.endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData.discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_DAMPING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_LIFETIME,
|
|
||||||
if (requestedProperties.getHasProperty(PROP_LIFETIME)) {
|
|
||||||
LevelDetails propertyLevel = packetData.startLevel();
|
|
||||||
successPropertyFits = packetData.appendValue(properties.getLifetime());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_LIFETIME;
|
|
||||||
propertiesDidntFit -= PROP_LIFETIME;
|
|
||||||
propertyCount++;
|
|
||||||
packetData.endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData.discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_LIFETIME;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// PROP_SCRIPT
|
|
||||||
// script would go here...
|
|
||||||
|
|
||||||
|
|
||||||
// PROP_COLOR
|
|
||||||
if (requestedProperties.getHasProperty(PROP_COLOR)) {
|
|
||||||
LevelDetails propertyLevel = packetData.startLevel();
|
|
||||||
successPropertyFits = packetData.appendColor(properties.getColor());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_COLOR;
|
|
||||||
propertiesDidntFit -= PROP_COLOR;
|
|
||||||
propertyCount++;
|
|
||||||
packetData.endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData.discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_COLOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_MODEL_URL
|
|
||||||
if (requestedProperties.getHasProperty(PROP_MODEL_URL)) {
|
|
||||||
LevelDetails propertyLevel = packetData.startLevel();
|
|
||||||
successPropertyFits = packetData.appendValue(properties.getModelURL());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_MODEL_URL;
|
|
||||||
propertiesDidntFit -= PROP_MODEL_URL;
|
|
||||||
propertyCount++;
|
|
||||||
packetData.endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData.discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_MODEL_URL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_ANIMATION_URL
|
|
||||||
if (requestedProperties.getHasProperty(PROP_ANIMATION_URL)) {
|
|
||||||
LevelDetails propertyLevel = packetData.startLevel();
|
|
||||||
successPropertyFits = packetData.appendValue(properties.getAnimationURL());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_ANIMATION_URL;
|
|
||||||
propertiesDidntFit -= PROP_ANIMATION_URL;
|
|
||||||
propertyCount++;
|
|
||||||
packetData.endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData.discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_ANIMATION_URL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_ANIMATION_FPS
|
|
||||||
if (requestedProperties.getHasProperty(PROP_ANIMATION_FPS)) {
|
|
||||||
LevelDetails propertyLevel = packetData.startLevel();
|
|
||||||
successPropertyFits = packetData.appendValue(properties.getAnimationFPS());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_ANIMATION_FPS;
|
|
||||||
propertiesDidntFit -= PROP_ANIMATION_FPS;
|
|
||||||
propertyCount++;
|
|
||||||
packetData.endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData.discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_ANIMATION_FPS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_ANIMATION_FRAME_INDEX
|
|
||||||
if (requestedProperties.getHasProperty(PROP_ANIMATION_FRAME_INDEX)) {
|
|
||||||
LevelDetails propertyLevel = packetData.startLevel();
|
|
||||||
successPropertyFits = packetData.appendValue(properties.getAnimationFrameIndex());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_ANIMATION_FRAME_INDEX;
|
|
||||||
propertiesDidntFit -= PROP_ANIMATION_FRAME_INDEX;
|
|
||||||
propertyCount++;
|
|
||||||
packetData.endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData.discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_ANIMATION_FRAME_INDEX;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_ANIMATION_PLAYING
|
|
||||||
if (requestedProperties.getHasProperty(PROP_ANIMATION_PLAYING)) {
|
|
||||||
LevelDetails propertyLevel = packetData.startLevel();
|
|
||||||
successPropertyFits = packetData.appendValue(properties.getAnimationIsPlaying());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_ANIMATION_PLAYING;
|
|
||||||
propertiesDidntFit -= PROP_ANIMATION_PLAYING;
|
|
||||||
propertyCount++;
|
|
||||||
packetData.endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData.discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_ANIMATION_PLAYING;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (propertyCount > 0) {
|
if (propertyCount > 0) {
|
||||||
int endOfEntityItemData = packetData.getUncompressedByteOffset();
|
int endOfEntityItemData = packetData->getUncompressedByteOffset();
|
||||||
|
|
||||||
encodedPropertyFlags = propertyFlags;
|
encodedPropertyFlags = propertyFlags;
|
||||||
int newPropertyFlagsLength = encodedPropertyFlags.length();
|
int newPropertyFlagsLength = encodedPropertyFlags.length();
|
||||||
packetData.updatePriorBytes(propertyFlagsOffset,
|
packetData->updatePriorBytes(propertyFlagsOffset,
|
||||||
(const unsigned char*)encodedPropertyFlags.constData(), encodedPropertyFlags.length());
|
(const unsigned char*)encodedPropertyFlags.constData(), encodedPropertyFlags.length());
|
||||||
|
|
||||||
// if the size of the PropertyFlags shrunk, we need to shift everything down to front of packet.
|
// if the size of the PropertyFlags shrunk, we need to shift everything down to front of packet.
|
||||||
if (newPropertyFlagsLength < oldPropertyFlagsLength) {
|
if (newPropertyFlagsLength < oldPropertyFlagsLength) {
|
||||||
int oldSize = packetData.getUncompressedSize();
|
int oldSize = packetData->getUncompressedSize();
|
||||||
|
|
||||||
const unsigned char* modelItemData = packetData.getUncompressedData(propertyFlagsOffset + oldPropertyFlagsLength);
|
const unsigned char* modelItemData = packetData->getUncompressedData(propertyFlagsOffset + oldPropertyFlagsLength);
|
||||||
int modelItemDataLength = endOfEntityItemData - startOfEntityItemData;
|
int modelItemDataLength = endOfEntityItemData - startOfEntityItemData;
|
||||||
int newEntityItemDataStart = propertyFlagsOffset + newPropertyFlagsLength;
|
int newEntityItemDataStart = propertyFlagsOffset + newPropertyFlagsLength;
|
||||||
packetData.updatePriorBytes(newEntityItemDataStart, modelItemData, modelItemDataLength);
|
packetData->updatePriorBytes(newEntityItemDataStart, modelItemData, modelItemDataLength);
|
||||||
|
|
||||||
int newSize = oldSize - (oldPropertyFlagsLength - newPropertyFlagsLength);
|
int newSize = oldSize - (oldPropertyFlagsLength - newPropertyFlagsLength);
|
||||||
packetData.setUncompressedSize(newSize);
|
packetData->setUncompressedSize(newSize);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
assert(newPropertyFlagsLength == oldPropertyFlagsLength); // should not have grown
|
assert(newPropertyFlagsLength == oldPropertyFlagsLength); // should not have grown
|
||||||
}
|
}
|
||||||
|
|
||||||
packetData.endLevel(entityLevel);
|
packetData->endLevel(entityLevel);
|
||||||
} else {
|
} else {
|
||||||
packetData.discardLevel(entityLevel);
|
packetData->discardLevel(entityLevel);
|
||||||
appendState = OctreeElement::NONE; // if we got here, then we didn't include the item
|
appendState = OctreeElement::NONE; // if we got here, then we didn't include the item
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -819,13 +593,13 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
packetData.endSubTree();
|
packetData->endSubTree();
|
||||||
const unsigned char* finalizedData = packetData.getFinalizedData();
|
const unsigned char* finalizedData = packetData->getFinalizedData();
|
||||||
int finalizedSize = packetData.getFinalizedSize();
|
int finalizedSize = packetData->getFinalizedSize();
|
||||||
memcpy(bufferOut, finalizedData, finalizedSize);
|
memcpy(bufferOut, finalizedData, finalizedSize);
|
||||||
sizeOut = finalizedSize;
|
sizeOut = finalizedSize;
|
||||||
} else {
|
} else {
|
||||||
packetData.discardSubTree();
|
packetData->discardSubTree();
|
||||||
sizeOut = 0;
|
sizeOut = 0;
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
|
|
|
@ -257,5 +257,23 @@ Q_DECLARE_METATYPE(EntityItemProperties);
|
||||||
QScriptValue EntityItemPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties);
|
QScriptValue EntityItemPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties);
|
||||||
void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemProperties& properties);
|
void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemProperties& properties);
|
||||||
|
|
||||||
|
// This macro is used in a couple of methods for appending data into an entity property stream
|
||||||
|
#define APPEND_ENTITY_PROPERTY(P,O,V) \
|
||||||
|
if (requestedProperties.getHasProperty(P)) { \
|
||||||
|
LevelDetails propertyLevel = packetData->startLevel(); \
|
||||||
|
successPropertyFits = packetData->O(V); \
|
||||||
|
if (successPropertyFits) { \
|
||||||
|
propertyFlags |= P; \
|
||||||
|
propertiesDidntFit -= P; \
|
||||||
|
propertyCount++; \
|
||||||
|
packetData->endLevel(propertyLevel); \
|
||||||
|
} else { \
|
||||||
|
packetData->discardLevel(propertyLevel); \
|
||||||
|
appendState = OctreeElement::PARTIAL; \
|
||||||
|
} \
|
||||||
|
} else { \
|
||||||
|
propertiesDidntFit -= P; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // hifi_EntityItemProperties_h
|
#endif // hifi_EntityItemProperties_h
|
||||||
|
|
|
@ -328,108 +328,12 @@ void ModelEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit
|
||||||
|
|
||||||
bool successPropertyFits = true;
|
bool successPropertyFits = true;
|
||||||
|
|
||||||
// PROP_COLOR
|
APPEND_ENTITY_PROPERTY(PROP_COLOR, appendColor, getColor());
|
||||||
if (requestedProperties.getHasProperty(PROP_COLOR)) {
|
APPEND_ENTITY_PROPERTY(PROP_MODEL_URL, appendValue, getModelURL());
|
||||||
LevelDetails propertyLevel = packetData->startLevel();
|
APPEND_ENTITY_PROPERTY(PROP_ANIMATION_URL, appendValue, getAnimationURL());
|
||||||
successPropertyFits = packetData->appendColor(getColor());
|
APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FPS, appendValue, getAnimationFPS());
|
||||||
if (successPropertyFits) {
|
APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, appendValue, getAnimationFrameIndex());
|
||||||
propertyFlags |= PROP_COLOR;
|
APPEND_ENTITY_PROPERTY(PROP_ANIMATION_PLAYING, appendValue, getAnimationIsPlaying());
|
||||||
propertiesDidntFit -= PROP_COLOR;
|
|
||||||
propertyCount++;
|
|
||||||
packetData->endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData->discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_COLOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_MODEL_URL
|
|
||||||
if (requestedProperties.getHasProperty(PROP_MODEL_URL)) {
|
|
||||||
LevelDetails propertyLevel = packetData->startLevel();
|
|
||||||
successPropertyFits = packetData->appendValue(getModelURL());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_MODEL_URL;
|
|
||||||
propertiesDidntFit -= PROP_MODEL_URL;
|
|
||||||
propertyCount++;
|
|
||||||
packetData->endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData->discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_MODEL_URL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_ANIMATION_URL
|
|
||||||
if (requestedProperties.getHasProperty(PROP_ANIMATION_URL)) {
|
|
||||||
LevelDetails propertyLevel = packetData->startLevel();
|
|
||||||
successPropertyFits = packetData->appendValue(getAnimationURL());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_ANIMATION_URL;
|
|
||||||
propertiesDidntFit -= PROP_ANIMATION_URL;
|
|
||||||
propertyCount++;
|
|
||||||
packetData->endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData->discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_ANIMATION_URL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_ANIMATION_FPS
|
|
||||||
if (requestedProperties.getHasProperty(PROP_ANIMATION_FPS)) {
|
|
||||||
LevelDetails propertyLevel = packetData->startLevel();
|
|
||||||
successPropertyFits = packetData->appendValue(getAnimationFPS());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_ANIMATION_FPS;
|
|
||||||
propertiesDidntFit -= PROP_ANIMATION_FPS;
|
|
||||||
propertyCount++;
|
|
||||||
packetData->endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData->discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_ANIMATION_FPS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_ANIMATION_FRAME_INDEX
|
|
||||||
if (requestedProperties.getHasProperty(PROP_ANIMATION_FRAME_INDEX)) {
|
|
||||||
LevelDetails propertyLevel = packetData->startLevel();
|
|
||||||
successPropertyFits = packetData->appendValue(getAnimationFrameIndex());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_ANIMATION_FRAME_INDEX;
|
|
||||||
propertiesDidntFit -= PROP_ANIMATION_FRAME_INDEX;
|
|
||||||
propertyCount++;
|
|
||||||
packetData->endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData->discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_ANIMATION_FRAME_INDEX;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROP_ANIMATION_PLAYING
|
|
||||||
if (requestedProperties.getHasProperty(PROP_ANIMATION_PLAYING)) {
|
|
||||||
LevelDetails propertyLevel = packetData->startLevel();
|
|
||||||
successPropertyFits = packetData->appendValue(getAnimationIsPlaying());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_ANIMATION_PLAYING;
|
|
||||||
propertiesDidntFit -= PROP_ANIMATION_PLAYING;
|
|
||||||
propertyCount++;
|
|
||||||
packetData->endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData->discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_ANIMATION_PLAYING;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -104,21 +104,5 @@ void SphereEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBi
|
||||||
OctreeElement::AppendState& appendState) const {
|
OctreeElement::AppendState& appendState) const {
|
||||||
|
|
||||||
bool successPropertyFits = true;
|
bool successPropertyFits = true;
|
||||||
|
APPEND_ENTITY_PROPERTY(PROP_COLOR, appendColor, getColor());
|
||||||
// PROP_COLOR
|
|
||||||
if (requestedProperties.getHasProperty(PROP_COLOR)) {
|
|
||||||
LevelDetails propertyLevel = packetData->startLevel();
|
|
||||||
successPropertyFits = packetData->appendColor(getColor());
|
|
||||||
if (successPropertyFits) {
|
|
||||||
propertyFlags |= PROP_COLOR;
|
|
||||||
propertiesDidntFit -= PROP_COLOR;
|
|
||||||
propertyCount++;
|
|
||||||
packetData->endLevel(propertyLevel);
|
|
||||||
} else {
|
|
||||||
packetData->discardLevel(propertyLevel);
|
|
||||||
appendState = OctreeElement::PARTIAL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
propertiesDidntFit -= PROP_COLOR;
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue