From 8a6c95451b5a1b9a3ac0202d8a68a94f179f3c8c Mon Sep 17 00:00:00 2001 From: mfranz Date: Sun, 1 Apr 2007 12:39:20 +0000 Subject: [PATCH] allow AI models to contain and blocks in their XML wrapper/animation file. They can access their /ai/models node via cmdarg() function. Example: print("Hi, I'm the Nimitz. My data are under ", cmdarg().getPath()); ... Note, however, that the block is only called on exit at the moment, not when the tile is unloaded. --- src/AIModel/AIBase.cxx | 4 +++- src/AIModel/AIManager.cxx | 4 +++- src/AIModel/AIManager.hxx | 1 + src/Scripting/NasalSys.cxx | 4 ++-- src/Scripting/NasalSys.hxx | 3 ++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index e10b6143b..862c78f80 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -43,6 +43,7 @@ #include
#include +#include #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(); } diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index 027d59b50..c7643a22d 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -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" ) ) { diff --git a/src/AIModel/AIManager.hxx b/src/AIModel/AIManager.hxx index 179597769..4f4392044 100644 --- a/src/AIModel/AIManager.hxx +++ b/src/AIModel/AIManager.hxx @@ -58,6 +58,7 @@ public: ~FGAIManager(); void init(); + void postinit(); void reinit(); void bind(); void unbind(); diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 667891700..d897a4f11 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -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()); } diff --git a/src/Scripting/NasalSys.hxx b/src/Scripting/NasalSys.hxx index 06551e160..ec8cf886e 100644 --- a/src/Scripting/NasalSys.hxx +++ b/src/Scripting/NasalSys.hxx @@ -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; };