]> git.mxchange.org Git - flightgear.git/commitdiff
allow AI models to contain <nasal><load> and <nasal><unload> blocks in
authormfranz <mfranz>
Sun, 1 Apr 2007 12:39:20 +0000 (12:39 +0000)
committermfranz <mfranz>
Sun, 1 Apr 2007 12:39:20 +0000 (12:39 +0000)
their XML wrapper/animation file. They can access their /ai/models node
via cmdarg() function. Example:

  <nasal>
          <load>
                  print("Hi, I'm the Nimitz. My data are under ",
                                  cmdarg().getPath());
          </load>
          <unload>
                  ...
          </unload>
  </nasal>

Note, however, that the <unload> block is only called on exit at the moment,
not when the tile is unloaded.

src/AIModel/AIBase.cxx
src/AIModel/AIManager.cxx
src/AIModel/AIManager.hxx
src/Scripting/NasalSys.cxx
src/Scripting/NasalSys.hxx

index e10b6143ba5e3331730db332d40c0a62a300de53..862c78f8085d68ab5013ef6cb516f73446126eee 100644 (file)
@@ -43,6 +43,7 @@
 
 #include <Main/globals.hxx>
 #include <Scenery/scenery.hxx>
+#include <Scripting/NasalSys.hxx>
 
 
 #include "AIBase.hxx"
@@ -201,7 +202,8 @@ osg::Node* FGAIBase::load3DModel(const string& fg_root,
                       SGPropertyNode *prop_root,
                       double sim_time_sec)
 {
-  model = sgLoad3DModel(fg_root, path, prop_root, sim_time_sec);
+  model = sgLoad3DModel(fg_root, path, prop_root, sim_time_sec, 0,
+                        new FGNasalModelData(prop_root));
   model->setNodeMask(model->getNodeMask() & ~SG_NODEMASK_TERRAIN_BIT);
   return model.get();
 }
index 027d59b50a68843bbd406b366f1b7ed4da7905b3..c7643a22d7d5d465adae2de1563f7118a7dd2c5f 100644 (file)
@@ -67,9 +67,11 @@ void FGAIManager::init() {
   user_pitch_node     = fgGetNode("/orientation/pitch-deg", true);
   user_yaw_node       = fgGetNode("/orientation/side-slip-deg", true);
   user_speed_node     = fgGetNode("/velocities/uBody-fps", true);
+}
 
 
-  /// Move that into the constructor
+void FGAIManager::postinit() {
+  // postinit, so that it can access the Nasal subsystem
   for(int i = 0 ; i < root->nChildren() ; i++) {
     SGPropertyNode *aiEntry = root->getChild( i );
     if( !strcmp( aiEntry->getName(), "scenario" ) ) {
index 17959776984fcd46293ddf719640d43a56204e5a..4f4392044b432bca2c058c8946aaa930d7f9a4a9 100644 (file)
@@ -58,6 +58,7 @@ public:
     ~FGAIManager();
 
     void init();
+    void postinit();
     void reinit();
     void bind();
     void unbind();
index 667891700d43696dcb4ce7cd307e2a6f76109765..d897a4f118d949e9849bc765efd8c048b305be07 100644 (file)
@@ -776,7 +776,7 @@ void FGNasalModelData::modelLoaded(const string& path, SGPropertyNode *prop,
     _module = path;
     const char *s = load ? load->getStringValue() : "";
     FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
-    nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s));
+    nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s), _props);
 }
 
 FGNasalModelData::~FGNasalModelData()
@@ -793,7 +793,7 @@ FGNasalModelData::~FGNasalModelData()
 
     if(_unload) {
         const char *s = _unload->getStringValue();
-        nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s));
+        nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s), _props);
     }
     nas->deleteModule(_module.c_str());
 }
index 06551e160dcbb33a4f5efbf16e72f2f38e37b172..ec8cf886ee568bdcdefd834fad752805b3caf884 100644 (file)
@@ -149,12 +149,13 @@ private:
 
 class FGNasalModelData : public SGModelData {
 public:
-    FGNasalModelData() : _unload(0) {}
+    FGNasalModelData(SGPropertyNode *props = 0) : _props(props), _unload(0) {}
     ~FGNasalModelData();
     void modelLoaded(const string& path, SGPropertyNode *prop, osg::Node *);
 
 private:
     string _module;
+    SGPropertyNode_ptr _props;
     SGConstPropertyNode_ptr _unload;
 };