X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fhla%2FHLAObjectInstance.cxx;h=f1b7fed07a52085103ae06422646bdf6b9f6c28f;hb=2815688c7ebf2be0dcf3cc0d271bb694dafa8ae7;hp=56ccf78e556640f5d209108f5877e715ce2cd68d;hpb=50380bc6c525bf06158341e3181f1f6ff0542b88;p=simgear.git diff --git a/simgear/hla/HLAObjectInstance.cxx b/simgear/hla/HLAObjectInstance.cxx index 56ccf78e..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() @@ -72,18 +79,24 @@ HLAObjectInstance::getObjectClass() const 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); } @@ -98,6 +111,8 @@ HLAObjectInstance::getAttributeOwned(unsigned index) const const HLADataType* HLAObjectInstance::getAttributeDataType(unsigned index) const { + if (!_objectClass.valid()) + return 0; return _objectClass->getAttributeDataType(index); } @@ -429,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; @@ -465,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 { @@ -478,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 { @@ -576,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(); @@ -583,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); @@ -598,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) @@ -638,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); } @@ -658,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); }