X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fhla%2FHLAObjectInstance.cxx;h=f1b7fed07a52085103ae06422646bdf6b9f6c28f;hb=2815688c7ebf2be0dcf3cc0d271bb694dafa8ae7;hp=eb27f2523aac644bc43e6ac34b8bad636b19492b;hpb=cc8977b83d5ba20a040d1f9d54d884f6c576985e;p=simgear.git diff --git a/simgear/hla/HLAObjectInstance.cxx b/simgear/hla/HLAObjectInstance.cxx index eb27f252..f1b7fed0 100644 --- a/simgear/hla/HLAObjectInstance.cxx +++ b/simgear/hla/HLAObjectInstance.cxx @@ -47,9 +47,10 @@ HLAObjectInstance::ReflectCallback::~ReflectCallback() } HLAObjectInstance::HLAObjectInstance(HLAObjectClass* objectClass) : - _federate(objectClass->_federate), _objectClass(objectClass) { + if (objectClass) + _federate = objectClass->_federate; } HLAObjectInstance::~HLAObjectInstance() @@ -78,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); } @@ -104,6 +111,8 @@ HLAObjectInstance::getAttributeOwned(unsigned index) const const HLADataType* HLAObjectInstance::getAttributeDataType(unsigned index) const { + if (!_objectClass.valid()) + return 0; return _objectClass->getAttributeDataType(index); } @@ -435,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; @@ -471,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 { @@ -484,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 { @@ -582,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(); @@ -589,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); @@ -604,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) @@ -644,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); } @@ -664,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); }