clean up subclass properties, properly handle new baseclass props like damping

This commit is contained in:
ZappoMan 2014-08-10 14:20:37 -07:00
parent 55e12baf78
commit a96aa5f937
11 changed files with 92 additions and 21 deletions

View file

@ -1680,6 +1680,7 @@ function handeMenuEvent(menuItem){
properties.velocity.y = array[index++].value;
properties.velocity.z = array[index++].value;
properties.damping = array[index++].value;
print("properties.damping=" + properties.damping);
if (properties.type == "Box") {
properties.color.red = array[index++].value;

View file

@ -109,6 +109,13 @@ int BoxEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, i
}
// TODO: eventually only include properties changed since the params.lastViewFrustumSent time
EntityPropertyFlags BoxEntityItem::getEntityProperties(EncodeBitstreamParams& params) const {
EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params);
requestedProperties += PROP_COLOR;
return requestedProperties;
}
void BoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData,
EntityPropertyFlags& requestedProperties,

View file

@ -26,6 +26,9 @@ public:
virtual EntityItemProperties getProperties() const;
virtual void setProperties(const EntityItemProperties& properties, bool forceCopy = false);
// TODO: eventually only include properties changed since the params.lastViewFrustumSent time
virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const;
virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData,
EntityPropertyFlags& requestedProperties,

View file

@ -72,6 +72,22 @@ EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemPropert
EntityItem::~EntityItem() {
}
EntityPropertyFlags EntityItem::getEntityProperties(EncodeBitstreamParams& params) const {
EntityPropertyFlags requestedProperties;
requestedProperties += PROP_POSITION;
requestedProperties += PROP_RADIUS;
requestedProperties += PROP_ROTATION;
requestedProperties += PROP_MASS;
requestedProperties += PROP_VELOCITY;
requestedProperties += PROP_GRAVITY;
requestedProperties += PROP_DAMPING;
requestedProperties += PROP_LIFETIME;
requestedProperties += PROP_SCRIPT;
return requestedProperties;
}
OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packetData, EncodeBitstreamParams& params,
EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData) const {
@ -96,20 +112,7 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet
ByteCountCoded<quint64> updateDeltaCoder = updateDelta;
QByteArray encodedUpdateDelta = updateDeltaCoder;
EntityPropertyFlags propertyFlags(PROP_LAST_ITEM);
EntityPropertyFlags requestedProperties;
// TODO: make this a virtual method that allows the subclass to fill in the properties it supports...
requestedProperties += PROP_POSITION;
requestedProperties += PROP_RADIUS;
requestedProperties += PROP_MODEL_URL;
requestedProperties += PROP_ROTATION;
requestedProperties += PROP_COLOR;
requestedProperties += PROP_ANIMATION_URL;
requestedProperties += PROP_ANIMATION_FPS;
requestedProperties += PROP_ANIMATION_FRAME_INDEX;
requestedProperties += PROP_ANIMATION_PLAYING;
requestedProperties += PROP_SHOULD_BE_DELETED;
EntityPropertyFlags requestedProperties = getEntityProperties(params);
EntityPropertyFlags propertiesDidntFit = requestedProperties;
// If we are being called for a subsequent pass at appendEntityData() that failed to completely encode this item,
@ -289,6 +292,7 @@ qDebug() << "EntityItem::appendEntityData() ... lastEdited=" << lastEdited;
LevelDetails propertyLevel = packetData->startLevel();
successPropertyFits = packetData->appendValue(getDamping());
if (successPropertyFits) {
qDebug() << "success writing PROP_DAMPING=" << getDamping();
propertyFlags |= PROP_DAMPING;
propertiesDidntFit -= PROP_DAMPING;
propertyCount++;
@ -296,9 +300,11 @@ qDebug() << "EntityItem::appendEntityData() ... lastEdited=" << lastEdited;
} else {
packetData->discardLevel(propertyLevel);
appendState = OctreeElement::PARTIAL;
qDebug() << "didn't fit PROP_DAMPING=" << getDamping();
}
} else {
propertiesDidntFit -= PROP_DAMPING;
qDebug() << "not requested PROP_DAMPING=" << getDamping();
}
// PROP_LIFETIME,
@ -574,12 +580,18 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
// PROP_DAMPING,
if (propertyFlags.getHasProperty(PROP_DAMPING)) {
float value;
memcpy(&value, dataAt, sizeof(value));
dataAt += sizeof(value);
bytesRead += sizeof(value);
qDebug() << "property included in buffer PROP_DAMPING=" << value;
if (overwriteLocalData) {
_damping = value;
qDebug() << " overwriting local value... PROP_DAMPING=" << getDamping();
}
}
@ -693,6 +705,9 @@ EntityItemProperties EntityItem::getProperties() const {
}
void EntityItem::setProperties(const EntityItemProperties& properties, bool forceCopy) {
qDebug() << "EntityItem::setProperties()... forceCopy=" << forceCopy;
qDebug() << "EntityItem::setProperties() properties.getDamping()=" << properties.getDamping();
bool somethingChanged = false;
if (properties._positionChanged || forceCopy) {
setPosition(properties._position / (float) TREE_SCALE);
@ -733,6 +748,8 @@ void EntityItem::setProperties(const EntityItemProperties& properties, bool forc
somethingChanged = true;
}
qDebug() << ">>>>>>>>>>>>>>>>>>> EntityItem::setProperties(); <<<<<<<<<<<<<<<<<<<<<<<<< properties._dampingChanged=" << properties._dampingChanged;
if (properties._dampingChanged || forceCopy) {
setDamping(properties._damping);
somethingChanged = true;

View file

@ -56,6 +56,9 @@ public:
float getEditedAgo() const /// Elapsed seconds since this entity was last edited
{ return (float)(usecTimestampNow() - _lastEdited) / (float)USECS_PER_SECOND; }
// TODO: eventually only include properties changed since the params.lastViewFrustumSent time
virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const;
virtual OctreeElement::AppendState appendEntityData(OctreePacketData* packetData, EncodeBitstreamParams& params,
EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData) const;

View file

@ -108,6 +108,9 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const {
if (_dampingChanged) {
changedProperties += PROP_DAMPING;
qDebug() << "******************************* _dampingChanged!!! changedProperties += PROP_DAMPING;";
} else {
qDebug() << "******************************* NOT _dampingChanged!!! not adding PROP_DAMPING;";
}
if (_lifetimeChanged) {
@ -306,12 +309,17 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) {
}
QScriptValue damping = object.property("damping");
qDebug() << "damping.isValid()=" << damping.isValid();
if (damping.isValid()) {
float newValue;
newValue = damping.toVariant().toFloat();
qDebug() << "damping newValue=" << newValue;
if (_defaultSettings || newValue != _damping) {
_damping = newValue;
_dampingChanged = true;
qDebug() << "damping _dampingChanged=" << _dampingChanged;
} else {
qDebug() << "NOT setting damping _dampingChanged=" << _dampingChanged;
}
}
@ -673,19 +681,29 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
// PROP_DAMPING,
if (requestedProperties.getHasProperty(PROP_DAMPING)) {
qDebug() << "******************************* requestedProperties.getHasProperty(PROP_DAMPING);";
LevelDetails propertyLevel = packetData.startLevel();
successPropertyFits = packetData.appendValue(properties.getDamping());
if (successPropertyFits) {
qDebug() << "******************************* PROP_DAMPING fit... getDamping()=" << properties.getDamping();
propertyFlags |= PROP_DAMPING;
propertiesDidntFit -= PROP_DAMPING;
propertyCount++;
packetData.endLevel(propertyLevel);
} else {
qDebug() << "******************************* PROP_DAMPING didn't fit...";
packetData.discardLevel(propertyLevel);
appendState = OctreeElement::PARTIAL;
}
} else {
propertiesDidntFit -= PROP_DAMPING;
qDebug() << "******************************* PROP_DAMPING not requested...";
}
// PROP_LIFETIME,
@ -1089,7 +1107,7 @@ qDebug() << "EntityItemProperties::decodeEntityEditPacket() ... lastEdited=" <<
dataAt += sizeof(value);
processedBytes += sizeof(value);
properties.setDamping(value);
qDebug() << "EntityItemProperties::decodeEntityEditPacket() PROP_DAMPING value=" << value;
qDebug() << "******************************* EntityItemProperties::decodeEntityEditPacket() PROP_DAMPING value=" << value;
}
// PROP_LIFETIME,

View file

@ -132,19 +132,19 @@ public:
void setShouldBeDeleted(bool shouldBeDeleted) { _shouldBeDeleted = shouldBeDeleted; _shouldBeDeletedChanged = true; }
float getMass() const { return _mass; }
void setMass(float value) { _mass = value; }
void setMass(float value) { _mass = value; _massChanged = true; }
const glm::vec3& getVelocity() const { return _velocity; } /// velocity in domain scale units (0.0-1.0) per second
void setVelocity(const glm::vec3& value) { _velocity = value; } /// velocity in domain scale units (0.0-1.0) per second
void setVelocity(const glm::vec3& value) { _velocity = value; _velocityChanged = true; } /// velocity in domain scale units (0.0-1.0) per second
const glm::vec3& getGravity() const { return _gravity; } /// gravity in domain scale units (0.0-1.0) per second squared
void setGravity(const glm::vec3& value) { _gravity = value; } /// gravity in domain scale units (0.0-1.0) per second squared
void setGravity(const glm::vec3& value) { _gravity = value; _gravityChanged = true; } /// gravity in domain scale units (0.0-1.0) per second squared
float getDamping() const { return _damping; }
void setDamping(float value) { _damping = value; }
void setDamping(float value) { _damping = value; _dampingChanged = true; }
float getLifetime() const { return _lifetime; } /// get the lifetime in seconds for the entity
void setLifetime(float value) { _lifetime = value; } /// set the lifetime in seconds for the entity
void setLifetime(float value) { _lifetime = value; _lifetimeChanged = true; } /// set the lifetime in seconds for the entity
// NOTE: how do we handle _defaultSettings???
bool containsBoundsProperties() const { return (_positionChanged || _radiusChanged); }

View file

@ -319,11 +319,15 @@ bool UpdateEntityOperator::PreRecursion(OctreeElement* element) {
assert(!_removeOld); // We shouldn't be in a remove old case and also be the new best fit
// set the entity properties and mark our element as changed.
qDebug() << "BEFORE _existingEntity->setProperties(_properties); <<<<<<<<<<<<<<<<<<<<<<<<< _properties.getDamping()=" << _properties.getDamping();
_existingEntity->setProperties(_properties);
qDebug() << "AFTER _existingEntity->setProperties(_properties); <<<<<<<<<<<<<<<<<<<<<<<<<";
} else {
// otherwise, this is an add case.
entityTreeElement->addEntityItem(_existingEntity);
qDebug() << "BEFORE _existingEntity->setProperties(_properties); <<<<<<<<<<<<<<<<<<<<<<<<< _properties.getDamping()=" << _properties.getDamping();
_existingEntity->setProperties(_properties); // still need to update the properties!
qDebug() << "AFTER _existingEntity->setProperties(_properties); <<<<<<<<<<<<<<<<<<<<<<<<<";
_tree->setContainingElement(_entityItemID, entityTreeElement);
}
_foundNew = true; // we found the new item!

View file

@ -65,7 +65,7 @@ EntityItemProperties ModelEntityItem::getProperties() const {
void ModelEntityItem::setProperties(const EntityItemProperties& properties, bool forceCopy) {
qDebug() << "ModelEntityItem::setProperties()...";
qDebug() << "ModelEntityItem::ModelEntityItem() properties.getModelURL()=" << properties.getModelURL();
qDebug() << "ModelEntityItem::setProperties() properties.getModelURL()=" << properties.getModelURL();
bool somethingChanged = false;
EntityItem::setProperties(properties, forceCopy); // set the properties in our base class
@ -316,6 +316,18 @@ int ModelEntityItem::oldVersionReadEntityDataFromBuffer(const unsigned char* dat
}
// TODO: eventually only include properties changed since the params.lastViewFrustumSent time
EntityPropertyFlags ModelEntityItem::getEntityProperties(EncodeBitstreamParams& params) const {
EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params);
requestedProperties += PROP_MODEL_URL;
requestedProperties += PROP_ANIMATION_URL;
requestedProperties += PROP_ANIMATION_FPS;
requestedProperties += PROP_ANIMATION_FRAME_INDEX;
requestedProperties += PROP_ANIMATION_PLAYING;
return requestedProperties;
}
void ModelEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,

View file

@ -26,6 +26,9 @@ public:
virtual EntityItemProperties getProperties() const;
virtual void setProperties(const EntityItemProperties& properties, bool forceCopy = false);
// TODO: eventually only include properties changed since the params.lastViewFrustumSent time
virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const;
virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData,
EntityPropertyFlags& requestedProperties,

View file

@ -40,9 +40,12 @@ Model properties:
// REQUIRED TO DO:
A) add velocity, gravity, damping to entity base class
Ab) implement support for requestedProperties in appendEntityData() to be virtual to handle various subclasses
Ac) implement support for requestedProperties in appendEntityData() that only include CHANGED properties for the viewer...
Az) visible???
2) EntityTree::update()/EntityTreeElement::update()... velocity changes...
C) verify "update" works