X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fhla%2FHLAObjectInstance.cxx;h=f1b7fed07a52085103ae06422646bdf6b9f6c28f;hb=2815688c7ebf2be0dcf3cc0d271bb694dafa8ae7;hp=f54ca8bb4598dd823884149e9abb62dd045051ca;hpb=a07ca86207108af66ca3335e4fcc11935c5ef079;p=simgear.git diff --git a/simgear/hla/HLAObjectInstance.cxx b/simgear/hla/HLAObjectInstance.cxx index f54ca8bb..f1b7fed0 100644 --- a/simgear/hla/HLAObjectInstance.cxx +++ b/simgear/hla/HLAObjectInstance.cxx @@ -15,6 +15,12 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + #include "HLAObjectInstance.hxx" #include @@ -41,9 +47,10 @@ HLAObjectInstance::ReflectCallback::~ReflectCallback() } HLAObjectInstance::HLAObjectInstance(HLAObjectClass* objectClass) : - _federate(objectClass->_federate), _objectClass(objectClass) { + if (objectClass) + _federate = objectClass->_federate; } HLAObjectInstance::~HLAObjectInstance() @@ -51,21 +58,45 @@ HLAObjectInstance::~HLAObjectInstance() _clearRTIObjectInstance(); } +const std::string& +HLAObjectInstance::getName() const +{ + return _name; +} + +const SGWeakPtr& +HLAObjectInstance::getFederate() const +{ + return _federate; +} + +const SGSharedPtr& +HLAObjectInstance::getObjectClass() const +{ + return _objectClass; +} + unsigned HLAObjectInstance::getNumAttributes() const { + if (!_objectClass.valid()) + return 0; return _objectClass->getNumAttributes(); } unsigned HLAObjectInstance::getAttributeIndex(const std::string& name) const { + if (!_objectClass.valid()) + return ~0u; return _objectClass->getAttributeIndex(name); } std::string HLAObjectInstance::getAttributeName(unsigned index) const { + if (!_objectClass.valid()) + return std::string(); return _objectClass->getAttributeName(index); } @@ -80,6 +111,8 @@ HLAObjectInstance::getAttributeOwned(unsigned index) const const HLADataType* HLAObjectInstance::getAttributeDataType(unsigned index) const { + if (!_objectClass.valid()) + return 0; return _objectClass->getAttributeDataType(index); } @@ -121,8 +154,6 @@ HLAObjectInstance::setAttributeDataElement(unsigned index, const SGSharedPtrcreateStamp(); - if (getAttributeOwned(index)) - encodeAttributeValue(index); } class HLAObjectInstance::DataElementFactoryVisitor : public HLADataElementFactoryVisitor { @@ -413,15 +444,27 @@ HLAObjectInstance::setAttributes(const HLAAttributePathElementMap& attributePath void HLAObjectInstance::registerInstance() +{ + registerInstance(_objectClass.get()); +} + +void +HLAObjectInstance::registerInstance(HLAObjectClass* objectClass) { if (_rtiObjectInstance.valid()) { SG_LOG(SG_IO, SG_ALERT, "Trying to register object " << getName() << " already known to the RTI!"); return; } - if (!_objectClass.valid()) { + if (!objectClass) { SG_LOG(SG_IO, SG_ALERT, "Could not register object with unknown object class!"); return; } + if (_objectClass.valid() && objectClass != _objectClass.get()) { + SG_LOG(SG_IO, SG_ALERT, "Could not change object class while registering!"); + return; + } + _objectClass = objectClass; + _federate = _objectClass->_federate; // This error must have been flagged before if (!_objectClass->_rtiObjectClass.valid()) return; @@ -449,8 +492,6 @@ HLAObjectInstance::deleteInstance(const RTIData& tag) void HLAObjectInstance::updateAttributeValues(const RTIData& tag) { - if (_attributeCallback.valid()) - _attributeCallback->updateAttributeValues(*this, tag); if (_updateCallback.valid()) { _updateCallback->updateAttributeValues(*this, tag); } else { @@ -462,8 +503,6 @@ HLAObjectInstance::updateAttributeValues(const RTIData& tag) void HLAObjectInstance::updateAttributeValues(const SGTimeStamp& timeStamp, const RTIData& tag) { - if (_attributeCallback.valid()) - _attributeCallback->updateAttributeValues(*this, tag); if (_updateCallback.valid()) { _updateCallback->updateAttributeValues(*this, timeStamp, tag); } else { @@ -477,9 +516,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 +533,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 @@ -555,6 +599,9 @@ HLAObjectInstance::reflectAttributeValue(unsigned index, const SGTimeStamp& time void HLAObjectInstance::_setRTIObjectInstance(RTIObjectInstance* rtiObjectInstance) { + if (!_objectClass.valid()) + return; + _rtiObjectInstance = rtiObjectInstance; _rtiObjectInstance->setObjectInstance(this); _name = _rtiObjectInstance->getName(); @@ -562,7 +609,7 @@ HLAObjectInstance::_setRTIObjectInstance(RTIObjectInstance* rtiObjectInstance) unsigned numAttributes = getNumAttributes(); _attributeVector.resize(numAttributes); for (unsigned i = 0; i < numAttributes; ++i) { - HLAUpdateType updateType = getObjectClass()->getAttributeUpdateType(i); + HLAUpdateType updateType = _objectClass->getAttributeUpdateType(i); if (getAttributeOwned(i) && updateType != HLAUndefinedUpdate) { _attributeVector[i]._enabledUpdate = true; _attributeVector[i]._unconditionalUpdate = (updateType == HLAPeriodicUpdate); @@ -577,7 +624,7 @@ HLAObjectInstance::_setRTIObjectInstance(RTIObjectInstance* rtiObjectInstance) // This makes sense with any new object. Even if we registered one, there might be unpublished attributes. HLAIndexList indexList; for (unsigned i = 0; i < numAttributes; ++i) { - HLAUpdateType updateType = getObjectClass()->getAttributeUpdateType(i); + HLAUpdateType updateType = _objectClass->getAttributeUpdateType(i); if (getAttributeOwned(i)) continue; if (updateType == HLAUndefinedUpdate) @@ -617,16 +664,6 @@ HLAObjectInstance::_reflectAttributeValues(const HLAIndexList& indexList, const { if (_reflectCallback.valid()) { _reflectCallback->reflectAttributeValues(*this, indexList, tag); - } else if (_attributeCallback.valid()) { - reflectAttributeValues(indexList, tag); - - RTIIndexDataPairList dataPairList; - for (HLAIndexList::const_iterator i = indexList.begin(); i != indexList.end(); ++i) { - dataPairList.push_back(RTIIndexDataPair()); - dataPairList.back().first = *i; - getAttributeData(*i, dataPairList.back().second); - } - _attributeCallback->reflectAttributeValues(*this, dataPairList, tag); } else { reflectAttributeValues(indexList, tag); } @@ -637,16 +674,6 @@ HLAObjectInstance::_reflectAttributeValues(const HLAIndexList& indexList, const { if (_reflectCallback.valid()) { _reflectCallback->reflectAttributeValues(*this, indexList, timeStamp, tag); - } else if (_attributeCallback.valid()) { - reflectAttributeValues(indexList, timeStamp, tag); - - RTIIndexDataPairList dataPairList; - for (HLAIndexList::const_iterator i = indexList.begin(); i != indexList.end(); ++i) { - dataPairList.push_back(RTIIndexDataPair()); - dataPairList.back().first = *i; - getAttributeData(*i, dataPairList.back().second); - } - _attributeCallback->reflectAttributeValues(*this, dataPairList, timeStamp, tag); } else { reflectAttributeValues(indexList, timeStamp, tag); }