X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fhla%2FHLAFederate.cxx;h=d52dbccae8f480c284e847bdd814d7beb17157c6;hb=201cb61f842ef50a19438e3872ba22e588fa1afc;hp=1b99ff28c3e4b29e591d74485915297212345ee4;hpb=27219e0f5811d46dfcf0b7facfa36d1b5c9101a4;p=simgear.git diff --git a/simgear/hla/HLAFederate.cxx b/simgear/hla/HLAFederate.cxx index 1b99ff28..d52dbcca 100644 --- a/simgear/hla/HLAFederate.cxx +++ b/simgear/hla/HLAFederate.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 "HLAFederate.hxx" #include @@ -72,6 +78,22 @@ HLAFederate::setVersion(HLAFederate::Version version) return true; } +bool +HLAFederate::setVersion(const std::string& version) +{ + if (version == "RTI13") + return setVersion(RTI13); + else if (version == "RTI1516") + return setVersion(RTI1516); + else if (version == "RTI1516E") + return setVersion(RTI1516E); + else { + /// at some time think about routing these down to the factory + SG_LOG(SG_NETWORK, SG_ALERT, "HLA: Unknown version string in HLAFederate::setVersion!"); + return false; + } +} + const std::list& HLAFederate::getConnectArguments() const { @@ -732,87 +754,6 @@ HLAFederate::processMessages() return true; } -bool -HLAFederate::tick(const double& minimum, const double& maximum) -{ - if (!_rtiFederate.valid()) { - SG_LOG(SG_NETWORK, SG_WARN, "HLA: Accessing unconnected federate!"); - return false; - } - return _rtiFederate->processMessages(minimum, maximum); -} - -bool -HLAFederate::readObjectModelTemplate(const std::string& objectModel, - HLAFederate::ObjectModelFactory& objectModelFactory) -{ - // The XML version of the federate object model. - // This one covers the generic attributes, parameters and data types. - HLAOMTXmlVisitor omtXmlVisitor; - try { - readXML(objectModel, omtXmlVisitor); - } catch (const sg_throwable& e) { - SG_LOG(SG_IO, SG_ALERT, "Could not open HLA XML object model file: " - << e.getMessage()); - return false; - } catch (...) { - SG_LOG(SG_IO, SG_ALERT, "Could not open HLA XML object model file"); - return false; - } - - omtXmlVisitor.setDataTypesToFederate(*this); - - unsigned numObjectClasses = omtXmlVisitor.getNumObjectClasses(); - for (unsigned i = 0; i < numObjectClasses; ++i) { - const HLAOMTXmlVisitor::ObjectClass* objectClass = omtXmlVisitor.getObjectClass(i); - std::string objectClassName = objectClass->getName(); - - SGSharedPtr hlaObjectClass = objectModelFactory.createObjectClass(objectClassName, *this); - if (!hlaObjectClass.valid()) { - SG_LOG(SG_IO, SG_INFO, "Ignoring object class \"" << objectClassName << "\"."); - continue; - } - - bool publish = objectModelFactory.publishObjectClass(objectClassName, objectClass->getSharing()); - bool subscribe = objectModelFactory.subscribeObjectClass(objectClassName, objectClass->getSharing()); - - // process the attributes - for (unsigned j = 0; j < objectClass->getNumAttributes(); ++j) { - const simgear::HLAOMTXmlVisitor::Attribute* attribute; - attribute = objectClass->getAttribute(j); - - std::string attributeName = attribute->getName(); - unsigned index = hlaObjectClass->addAttribute(attributeName); - - if (index == ~0u) { - SG_LOG(SG_IO, SG_WARN, "RTI does not know the \"" << attributeName << "\" attribute!"); - continue; - } - - // the attributes datatype - SGSharedPtr dataType = getDataType(attribute->getDataType()); - if (!dataType.valid()) { - SG_LOG(SG_IO, SG_WARN, "Could not find data type for attribute \"" - << attributeName << "\" in object class \"" << objectClassName << "\"!"); - } - hlaObjectClass->setAttributeDataType(index, dataType); - hlaObjectClass->setAttributeUpdateType(index, attribute->getUpdateType()); - if (subscribe && objectModelFactory.subscribeAttribute(objectClassName, attributeName, attribute->_sharing)) - hlaObjectClass->setAttributeSubscriptionType(index, attribute->getSubscriptionType()); - if (publish && objectModelFactory.publishAttribute(objectClassName, attributeName, attribute->_sharing)) - hlaObjectClass->setAttributePublicationType(index, attribute->getPublicationType()); - } - - if (publish) - hlaObjectClass->publish(); - if (subscribe) - hlaObjectClass->subscribe(); - - } - - return resolveObjectModel(); -} - bool HLAFederate::readRTI13ObjectModelTemplate(const std::string& objectModel) { @@ -1128,7 +1069,10 @@ HLAFederate::init() bool HLAFederate::update() { - return timeAdvanceBy(_timeIncrement); + if (_timeIncrement <= SGTimeStamp::fromSec(0)) + return processMessages(); + else + return timeAdvanceBy(_timeIncrement); } bool @@ -1185,9 +1129,9 @@ HLAFederate::_clearRTI() } bool -HLAFederate::_insertInteractionClass(const SGSharedPtr& interactionClass) +HLAFederate::_insertInteractionClass(HLAInteractionClass* interactionClass) { - if (!interactionClass.valid()) + if (!interactionClass) return false; if (_interactionClassMap.find(interactionClass->getName()) != _interactionClassMap.end()) { SG_LOG(SG_IO, SG_ALERT, "HLA: _insertInteractionClass: object instance with name \"" @@ -1199,9 +1143,9 @@ HLAFederate::_insertInteractionClass(const SGSharedPtr& int } bool -HLAFederate::_insertObjectClass(const SGSharedPtr& objectClass) +HLAFederate::_insertObjectClass(HLAObjectClass* objectClass) { - if (!objectClass.valid()) + if (!objectClass) return false; if (_objectClassMap.find(objectClass->getName()) != _objectClassMap.end()) { SG_LOG(SG_IO, SG_ALERT, "HLA: _insertObjectClass: object instance with name \"" @@ -1213,9 +1157,9 @@ HLAFederate::_insertObjectClass(const SGSharedPtr& objectClass) } bool -HLAFederate::_insertObjectInstance(const SGSharedPtr& objectInstance) +HLAFederate::_insertObjectInstance(HLAObjectInstance* objectInstance) { - if (!objectInstance.valid()) + if (!objectInstance) return false; if (objectInstance->getName().empty()) { SG_LOG(SG_IO, SG_ALERT, "HLA: _insertObjectInstance: trying to insert object instance with empty name!");