hla: Add propper attribute dirty handling.

This commit is contained in:
Mathias Froehlich 2012-03-02 21:51:59 +01:00
parent a07ca86207
commit 098441f5fb
6 changed files with 21 additions and 11 deletions

View File

@ -111,6 +111,7 @@ HLAArrayDataElement::setNumElements(unsigned size)
_elementVector.resize(size); _elementVector.resize(size);
for (unsigned i = oldSize; i < size; ++i) for (unsigned i = oldSize; i < size; ++i)
_elementVector[i] = newElement(i); _elementVector[i] = newElement(i);
setDirty(true);
return true; return true;
} }
@ -177,6 +178,7 @@ HLAArrayDataElement::setElement(unsigned index, HLADataElement* value)
_elementVector[index] = value; _elementVector[index] = value;
if (value) if (value)
value->attachStamp(*this); value->attachStamp(*this);
setDirty(true);
} }
void void
@ -252,6 +254,7 @@ HLAVariantArrayDataElement::setNumElements(unsigned size)
_elementVector.resize(size); _elementVector.resize(size);
for (unsigned i = oldSize; i < size; ++i) for (unsigned i = oldSize; i < size; ++i)
_elementVector[i] = newElement(); _elementVector[i] = newElement();
setDirty(true);
return true; return true;
} }
@ -318,6 +321,7 @@ HLAVariantArrayDataElement::setElement(unsigned index, HLAVariantRecordDataEleme
_elementVector[index] = value; _elementVector[index] = value;
if (value) if (value)
value->attachStamp(*this); value->attachStamp(*this);
setDirty(true);
} }
void void

View File

@ -139,7 +139,7 @@ public:
const std::string& getValue() const const std::string& getValue() const
{ return _value; } { return _value; }
void setValue(const std::string& value) void setValue(const std::string& value)
{ _value = value; } { _value = value; setDirty(true); }
virtual bool setNumElements(unsigned count) virtual bool setNumElements(unsigned count)
{ {
@ -216,7 +216,7 @@ public:
const SGVec2<T>& getValue() const const SGVec2<T>& getValue() const
{ return _value; } { return _value; }
void setValue(const SGVec2<T>& value) void setValue(const SGVec2<T>& value)
{ _value = value; } { _value = value; setDirty(true); }
virtual bool setNumElements(unsigned count) virtual bool setNumElements(unsigned count)
{ {
@ -308,7 +308,7 @@ public:
const SGVec3<T>& getValue() const const SGVec3<T>& getValue() const
{ return _value; } { return _value; }
void setValue(const SGVec3<T>& value) void setValue(const SGVec3<T>& value)
{ _value = value; } { _value = value; setDirty(true); }
virtual bool setNumElements(unsigned count) virtual bool setNumElements(unsigned count)
{ {
@ -400,7 +400,7 @@ public:
const SGVec4<T>& getValue() const const SGVec4<T>& getValue() const
{ return _value; } { return _value; }
void setValue(const SGVec4<T>& value) void setValue(const SGVec4<T>& value)
{ _value = value; } { _value = value; setDirty(true); }
virtual bool setNumElements(unsigned count) virtual bool setNumElements(unsigned count)
{ {
@ -492,7 +492,7 @@ public:
const SGQuat<T>& getValue() const const SGQuat<T>& getValue() const
{ return _value; } { return _value; }
void setValue(const SGQuat<T>& value) void setValue(const SGQuat<T>& value)
{ _value = value; } { _value = value; setDirty(true); }
virtual bool setNumElements(unsigned count) virtual bool setNumElements(unsigned count)
{ {

View File

@ -125,6 +125,7 @@ void
HLA##type##DataElement::setValue(ctype value) \ HLA##type##DataElement::setValue(ctype value) \
{ \ { \
_value = value; \ _value = value; \
setDirty(true); \
} }
IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Char, char); IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Char, char);

View File

@ -187,6 +187,7 @@ HLAFixedRecordDataElement::setField(unsigned index, HLADataElement* value)
_fieldVector[index] = value; _fieldVector[index] = value;
if (value) if (value)
value->attachStamp(*this); value->attachStamp(*this);
setDirty(true);
} }
void void

View File

@ -121,8 +121,6 @@ HLAObjectInstance::setAttributeDataElement(unsigned index, const SGSharedPtr<HLA
_attributeVector[index]._dataElement = dataElement; _attributeVector[index]._dataElement = dataElement;
if (_attributeVector[index]._dataElement.valid()) if (_attributeVector[index]._dataElement.valid())
_attributeVector[index]._dataElement->createStamp(); _attributeVector[index]._dataElement->createStamp();
if (getAttributeOwned(index))
encodeAttributeValue(index);
} }
class HLAObjectInstance::DataElementFactoryVisitor : public HLADataElementFactoryVisitor { class HLAObjectInstance::DataElementFactoryVisitor : public HLADataElementFactoryVisitor {
@ -477,9 +475,13 @@ HLAObjectInstance::encodeAttributeValues()
{ {
unsigned numAttributes = _attributeVector.size(); unsigned numAttributes = _attributeVector.size();
for (unsigned i = 0; i < numAttributes;++i) { for (unsigned i = 0; i < numAttributes;++i) {
if (!_attributeVector[i]._unconditionalUpdate) if (_attributeVector[i]._unconditionalUpdate) {
continue;
encodeAttributeValue(i); 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!"); SG_LOG(SG_IO, SG_INFO, "Not updating inactive object!");
return; return;
} }
const HLADataElement* dataElement = getAttributeDataElement(index); HLADataElement* dataElement = getAttributeDataElement(index);
if (!dataElement) if (!dataElement)
return; return;
_rtiObjectInstance->encodeAttributeData(index, *dataElement); _rtiObjectInstance->encodeAttributeData(index, *dataElement);
dataElement->setDirty(false);
} }
void void

View File

@ -126,6 +126,7 @@ HLAVariantRecordDataElement::setAlternativeIndex(unsigned index)
return false; return false;
_dataElement.swap(dataElement); _dataElement.swap(dataElement);
_alternativeIndex = index; _alternativeIndex = index;
setDirty(true);
return true; return true;
} }