]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scripting/NasalModelData.cxx
Remove debug console output in FGApproachController
[flightgear.git] / src / Scripting / NasalModelData.cxx
index 2181cb17f6b36ac8324ade2c6725892c9b73b7a3..e4f22692ba399d6c64fbbce248dc9e759fadbcce 100644 (file)
@@ -1,15 +1,18 @@
 
 #include "NasalModelData.hxx"
 #include "NasalSys.hxx"
+#include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
 
+#include <osg/Transform>
+#include <osg/observer_ptr>
+
 #include <simgear/math/SGMath.hxx>
 #include <simgear/nasal/cppbind/Ghost.hxx>
+#include <simgear/scene/util/OsgDebug.hxx>
 #include <simgear/scene/util/OsgMath.hxx>
 #include <simgear/debug/logstream.hxx>
 
-#include <osg/Transform>
-
 #include <boost/bind.hpp>
 
 #include <algorithm>
@@ -31,7 +34,7 @@ typedef nasal::Ghost<NodeRef> NasalNode;
  * model.
  */
 static naRef f_node_getPose( const osg::Node& node,
-                                   const nasal::CallContext& ctx )
+                             const nasal::CallContext& ctx )
 {
   osg::NodePathList parent_paths = node.getParentalNodePaths();
   for( osg::NodePathList::const_iterator path = parent_paths.begin();
@@ -79,12 +82,28 @@ FGNasalModelData::FGNasalModelData( SGPropertyNode *root,
   _module_id( _max_module_id++ )
 {
   _loaded_models.push_back(this);
+
+  SG_LOG
+  (
+    SG_NASAL,
+    SG_INFO,
+    "New model with attached script(s) "
+    "(branch = " << branch << ","
+    " path = " << simgear::getNodePathString(branch) << ")"
+  );
 }
 
 //------------------------------------------------------------------------------
 FGNasalModelData::~FGNasalModelData()
 {
   _loaded_models.remove(this);
+
+  SG_LOG
+  (
+    SG_NASAL,
+    SG_INFO,
+    "Removed model with script(s) (branch = " << _branch.get() << ")"
+  );
 }
 
 //------------------------------------------------------------------------------
@@ -104,13 +123,9 @@ void FGNasalModelData::load()
   nasal::Hash module = nasalSys->getGlobals().createHash(_module);
   module.set("_module_id", _module_id);
 
-  if( !NasalNode::isInit() )
-  {
-    NasalNode::init("osg.Node")
+  NasalNode::init("osg.Node")
       .method("getPose", &f_node_getPose);
-  }
-
-  module.set("_model", NodeRef(_branch));
+  module.set("_model", _branch);
 
   naRef arg[2];
   arg[0] = nasalSys->propNodeGhost(_root);
@@ -146,7 +161,7 @@ void FGNasalModelData::unload()
 //------------------------------------------------------------------------------
 osg::Node* FGNasalModelData::getNode()
 {
-  return _branch;
+  return _branch.get();
 }
 
 //------------------------------------------------------------------------------
@@ -180,13 +195,9 @@ void FGNasalModelDataProxy::modelLoaded( const std::string& path,
                                          SGPropertyNode *prop,
                                          osg::Node *branch )
 {
-    FGNasalSys* nasalSys = (FGNasalSys*) globals->get_subsystem("nasal");
-    if(!nasalSys) {
-        SG_LOG(SG_NASAL, SG_WARN, "Trying to run a <load> script "
-               "without Nasal subsystem present.");
+    if( fgGetBool("/sim/disable-embedded-nasal") )
         return;
-    }
-    
+
     if(!prop)
         return;
     
@@ -194,6 +205,18 @@ void FGNasalModelDataProxy::modelLoaded( const std::string& path,
     if(!nasal)
         return;
     
+    FGNasalSys* nasalSys = (FGNasalSys*) globals->get_subsystem("nasal");
+    if(!nasalSys)
+    {
+        SG_LOG
+        (
+          SG_NASAL,
+          SG_WARN,
+          "Can not load model script(s) (Nasal subsystem not available)."
+        );
+        return;
+    }
+
     SGPropertyNode* load   = nasal->getNode("load");
     SGPropertyNode* unload = nasal->getNode("unload");