From 098441f5fbbcff41508b9411ecf2904f84a7eb81 Mon Sep 17 00:00:00 2001 From: Mathias Froehlich Date: Fri, 2 Mar 2012 21:51:59 +0100 Subject: [PATCH] hla: Add propper attribute dirty handling. --- simgear/hla/HLAArrayDataElement.cxx | 4 ++++ simgear/hla/HLAArrayDataElement.hxx | 10 +++++----- simgear/hla/HLABasicDataElement.cxx | 1 + simgear/hla/HLAFixedRecordDataElement.cxx | 1 + simgear/hla/HLAObjectInstance.cxx | 15 +++++++++------ simgear/hla/HLAVariantRecordDataElement.cxx | 1 + 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/simgear/hla/HLAArrayDataElement.cxx b/simgear/hla/HLAArrayDataElement.cxx index 5fcbbd0a..9f8f5aeb 100644 --- a/simgear/hla/HLAArrayDataElement.cxx +++ b/simgear/hla/HLAArrayDataElement.cxx @@ -111,6 +111,7 @@ HLAArrayDataElement::setNumElements(unsigned size) _elementVector.resize(size); for (unsigned i = oldSize; i < size; ++i) _elementVector[i] = newElement(i); + setDirty(true); return true; } @@ -177,6 +178,7 @@ HLAArrayDataElement::setElement(unsigned index, HLADataElement* value) _elementVector[index] = value; if (value) value->attachStamp(*this); + setDirty(true); } void @@ -252,6 +254,7 @@ HLAVariantArrayDataElement::setNumElements(unsigned size) _elementVector.resize(size); for (unsigned i = oldSize; i < size; ++i) _elementVector[i] = newElement(); + setDirty(true); return true; } @@ -318,6 +321,7 @@ HLAVariantArrayDataElement::setElement(unsigned index, HLAVariantRecordDataEleme _elementVector[index] = value; if (value) value->attachStamp(*this); + setDirty(true); } void diff --git a/simgear/hla/HLAArrayDataElement.hxx b/simgear/hla/HLAArrayDataElement.hxx index 4557d006..72f1478b 100644 --- a/simgear/hla/HLAArrayDataElement.hxx +++ b/simgear/hla/HLAArrayDataElement.hxx @@ -139,7 +139,7 @@ public: const std::string& getValue() const { return _value; } void setValue(const std::string& value) - { _value = value; } + { _value = value; setDirty(true); } virtual bool setNumElements(unsigned count) { @@ -216,7 +216,7 @@ public: const SGVec2& getValue() const { return _value; } void setValue(const SGVec2& value) - { _value = value; } + { _value = value; setDirty(true); } virtual bool setNumElements(unsigned count) { @@ -308,7 +308,7 @@ public: const SGVec3& getValue() const { return _value; } void setValue(const SGVec3& value) - { _value = value; } + { _value = value; setDirty(true); } virtual bool setNumElements(unsigned count) { @@ -400,7 +400,7 @@ public: const SGVec4& getValue() const { return _value; } void setValue(const SGVec4& value) - { _value = value; } + { _value = value; setDirty(true); } virtual bool setNumElements(unsigned count) { @@ -492,7 +492,7 @@ public: const SGQuat& getValue() const { return _value; } void setValue(const SGQuat& value) - { _value = value; } + { _value = value; setDirty(true); } virtual bool setNumElements(unsigned count) { diff --git a/simgear/hla/HLABasicDataElement.cxx b/simgear/hla/HLABasicDataElement.cxx index f68cad36..c4b985b9 100644 --- a/simgear/hla/HLABasicDataElement.cxx +++ b/simgear/hla/HLABasicDataElement.cxx @@ -125,6 +125,7 @@ void HLA##type##DataElement::setValue(ctype value) \ { \ _value = value; \ + setDirty(true); \ } IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Char, char); diff --git a/simgear/hla/HLAFixedRecordDataElement.cxx b/simgear/hla/HLAFixedRecordDataElement.cxx index d04c2732..9a0311bd 100644 --- a/simgear/hla/HLAFixedRecordDataElement.cxx +++ b/simgear/hla/HLAFixedRecordDataElement.cxx @@ -187,6 +187,7 @@ HLAFixedRecordDataElement::setField(unsigned index, HLADataElement* value) _fieldVector[index] = value; if (value) value->attachStamp(*this); + setDirty(true); } void diff --git a/simgear/hla/HLAObjectInstance.cxx b/simgear/hla/HLAObjectInstance.cxx index f54ca8bb..a163c595 100644 --- a/simgear/hla/HLAObjectInstance.cxx +++ b/simgear/hla/HLAObjectInstance.cxx @@ -121,8 +121,6 @@ HLAObjectInstance::setAttributeDataElement(unsigned index, const SGSharedPtrcreateStamp(); - if (getAttributeOwned(index)) - encodeAttributeValue(index); } class HLAObjectInstance::DataElementFactoryVisitor : public HLADataElementFactoryVisitor { @@ -477,9 +475,13 @@ HLAObjectInstance::encodeAttributeValues() { unsigned numAttributes = _attributeVector.size(); for (unsigned i = 0; i < numAttributes;++i) { - if (!_attributeVector[i]._unconditionalUpdate) - continue; - encodeAttributeValue(i); + if (_attributeVector[i]._unconditionalUpdate) { + encodeAttributeValue(i); + } else if (_attributeVector[i]._enabledUpdate) { + const HLADataElement* dataElement = getAttributeDataElement(i); + if (dataElement && dataElement->getDirty()) + encodeAttributeValue(i); + } } } @@ -490,10 +492,11 @@ HLAObjectInstance::encodeAttributeValue(unsigned index) SG_LOG(SG_IO, SG_INFO, "Not updating inactive object!"); return; } - const HLADataElement* dataElement = getAttributeDataElement(index); + HLADataElement* dataElement = getAttributeDataElement(index); if (!dataElement) return; _rtiObjectInstance->encodeAttributeData(index, *dataElement); + dataElement->setDirty(false); } void diff --git a/simgear/hla/HLAVariantRecordDataElement.cxx b/simgear/hla/HLAVariantRecordDataElement.cxx index e3ef35a1..5dac6d52 100644 --- a/simgear/hla/HLAVariantRecordDataElement.cxx +++ b/simgear/hla/HLAVariantRecordDataElement.cxx @@ -126,6 +126,7 @@ HLAVariantRecordDataElement::setAlternativeIndex(unsigned index) return false; _dataElement.swap(dataElement); _alternativeIndex = index; + setDirty(true); return true; }