1
0
Fork 0

allow AI models to contain <nasal><load> and <nasal><unload> blocks in

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.
This commit is contained in:
mfranz 2007-04-01 12:39:20 +00:00
parent 77c176424e
commit 8a6c95451b
5 changed files with 11 additions and 5 deletions

View file

@ -43,6 +43,7 @@
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Scenery/scenery.hxx> #include <Scenery/scenery.hxx>
#include <Scripting/NasalSys.hxx>
#include "AIBase.hxx" #include "AIBase.hxx"
@ -201,7 +202,8 @@ osg::Node* FGAIBase::load3DModel(const string& fg_root,
SGPropertyNode *prop_root, SGPropertyNode *prop_root,
double sim_time_sec) 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); model->setNodeMask(model->getNodeMask() & ~SG_NODEMASK_TERRAIN_BIT);
return model.get(); return model.get();
} }

View file

@ -67,9 +67,11 @@ void FGAIManager::init() {
user_pitch_node = fgGetNode("/orientation/pitch-deg", true); user_pitch_node = fgGetNode("/orientation/pitch-deg", true);
user_yaw_node = fgGetNode("/orientation/side-slip-deg", true); user_yaw_node = fgGetNode("/orientation/side-slip-deg", true);
user_speed_node = fgGetNode("/velocities/uBody-fps", 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++) { for(int i = 0 ; i < root->nChildren() ; i++) {
SGPropertyNode *aiEntry = root->getChild( i ); SGPropertyNode *aiEntry = root->getChild( i );
if( !strcmp( aiEntry->getName(), "scenario" ) ) { if( !strcmp( aiEntry->getName(), "scenario" ) ) {

View file

@ -58,6 +58,7 @@ public:
~FGAIManager(); ~FGAIManager();
void init(); void init();
void postinit();
void reinit(); void reinit();
void bind(); void bind();
void unbind(); void unbind();

View file

@ -776,7 +776,7 @@ void FGNasalModelData::modelLoaded(const string& path, SGPropertyNode *prop,
_module = path; _module = path;
const char *s = load ? load->getStringValue() : ""; const char *s = load ? load->getStringValue() : "";
FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal"); 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() FGNasalModelData::~FGNasalModelData()
@ -793,7 +793,7 @@ FGNasalModelData::~FGNasalModelData()
if(_unload) { if(_unload) {
const char *s = _unload->getStringValue(); 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()); nas->deleteModule(_module.c_str());
} }

View file

@ -149,12 +149,13 @@ private:
class FGNasalModelData : public SGModelData { class FGNasalModelData : public SGModelData {
public: public:
FGNasalModelData() : _unload(0) {} FGNasalModelData(SGPropertyNode *props = 0) : _props(props), _unload(0) {}
~FGNasalModelData(); ~FGNasalModelData();
void modelLoaded(const string& path, SGPropertyNode *prop, osg::Node *); void modelLoaded(const string& path, SGPropertyNode *prop, osg::Node *);
private: private:
string _module; string _module;
SGPropertyNode_ptr _props;
SGConstPropertyNode_ptr _unload; SGConstPropertyNode_ptr _unload;
}; };