2 #include "NasalModelData.hxx"
4 #include <simgear/debug/logstream.hxx>
6 #include "NasalSys.hxx"
7 #include <Main/globals.hxx>
10 // FGNasalModelData class. If sgLoad3DModel() is called with a pointer to
11 // such a class, then it lets modelLoaded() run the <load> script, and the
12 // destructor the <unload> script. The latter happens when the model branch
13 // is removed from the scene graph.
15 unsigned int FGNasalModelData::_module_id = 0;
17 void FGNasalModelData::load()
20 m << "__model" << _module_id++;
23 SG_LOG(SG_NASAL, SG_DEBUG, "Loading nasal module " << _module.c_str());
25 const char *s = _load ? _load->getStringValue() : "";
26 FGNasalSys* nasalSys = (FGNasalSys*) globals->get_subsystem("nasal");
29 arg[0] = nasalSys->propNodeGhost(_root);
30 arg[1] = nasalSys->propNodeGhost(_prop);
31 nasalSys->createModule(_module.c_str(), _path.c_str(), s, strlen(s),
35 void FGNasalModelData::unload()
40 FGNasalSys* nasalSys = (FGNasalSys*) globals->get_subsystem("nasal");
42 SG_LOG(SG_NASAL, SG_WARN, "Trying to run an <unload> script "
43 "without Nasal subsystem present.");
47 SG_LOG(SG_NASAL, SG_DEBUG, "Unloading nasal module " << _module.c_str());
51 const char *s = _unload->getStringValue();
52 nasalSys->createModule(_module.c_str(), _module.c_str(), s, strlen(s), _root);
55 nasalSys->deleteModule(_module.c_str());
58 void FGNasalModelDataProxy::modelLoaded(const std::string& path, SGPropertyNode *prop,
61 FGNasalSys* nasalSys = (FGNasalSys*) globals->get_subsystem("nasal");
63 SG_LOG(SG_NASAL, SG_WARN, "Trying to run a <load> script "
64 "without Nasal subsystem present.");
71 SGPropertyNode *nasal = prop->getNode("nasal");
75 SGPropertyNode* load = nasal->getNode("load");
76 SGPropertyNode* unload = nasal->getNode("unload");
78 if ((!load) && (!unload))
81 _data = new FGNasalModelData(_root, path, prop, load, unload);
83 // register Nasal module to be created and loaded in the main thread.
84 nasalSys->registerToLoad(_data);
87 FGNasalModelDataProxy::~FGNasalModelDataProxy()
89 FGNasalSys* nasalSys = (FGNasalSys*) globals->get_subsystem("nasal");
90 // when necessary, register Nasal module to be destroyed/unloaded
91 // in the main thread.
92 if ((_data.valid())&&(nasalSys))
93 nasalSys->registerToUnload(_data);