]> git.mxchange.org Git - simgear.git/blobdiff - simgear/hla/HLAFederate.cxx
Merge branch 'timoore/optimizations' into next
[simgear.git] / simgear / hla / HLAFederate.cxx
index 141cbc8e91dbce28c87b7a7574383875fe1fe420..75465af470ddf0d0fc96da1231c67c0e47db60f6 100644 (file)
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 
+#ifdef HAVE_CONFIG_H
+#  include <simgear_config.h>
+#endif
+
+#include <simgear/compiler.h>
+
 #include "HLAFederate.hxx"
 
 #include <algorithm>
@@ -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<std::string>&
 HLAFederate::getConnectArguments() const
 {
@@ -649,14 +671,11 @@ HLAFederate::timeAdvanceAvailable()
     }
 
     SGTimeStamp timeStamp;
-    if (!_rtiFederate->queryGALT(timeStamp)) {
-        SG_LOG(SG_NETWORK, SG_WARN, "HLA: Could not query GALT!");
-        return false;
-    }
-
-    if (!_rtiFederate->timeAdvanceRequestAvailable(timeStamp)) {
-        SG_LOG(SG_NETWORK, SG_WARN, "HLA: Time advance request failed!");
-        return false;
+    if (_rtiFederate->queryGALT(timeStamp)) {
+        if (!_rtiFederate->timeAdvanceRequestAvailable(timeStamp)) {
+            SG_LOG(SG_NETWORK, SG_WARN, "HLA: Time advance request failed!");
+            return false;
+        }
     }
 
     return processMessages();
@@ -735,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> 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<const HLADataType> 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)
 {