]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scripting/NasalSys.cxx
Canvas: update for SimGear changes.
[flightgear.git] / src / Scripting / NasalSys.cxx
index b7bf068a5f7ff7956c232fdc52fb7b06d1f0c942..d4c1ae0e25d9ba89594ebefda4b164b89d73ed60 100644 (file)
@@ -105,6 +105,8 @@ public:
     _sys->gcRelease(_gcSelf);
   }
   
+  bool isRunning() const { return _isRunning; }
+    
   void stop()
   {
     if (_isRunning) {
@@ -139,6 +141,9 @@ public:
   {
     naRef *args = NULL;
     _sys->callMethod(_func, _self, 0, args, naNil() /* locals */);
+    if (_singleShot) {
+      _isRunning = false;
+    }
   }
   
   void setSingleShot(bool aSingleShot)
@@ -591,6 +596,16 @@ static naRef f_resolveDataPath(naContext c, naRef me, int argc, naRef* args)
     return naStr_fromdata(naNewString(c), const_cast<char*>(pdata), strlen(pdata));
 }
 
+static naRef f_findDataDir(naContext c, naRef me, int argc, naRef* args)
+{
+    if(argc != 1 || !naIsString(args[0]))
+        naRuntimeError(c, "bad arguments to findDataDir()");
+    
+    SGPath p = globals->find_data_dir(naStr_data(args[0]));
+    const char* pdata = p.c_str();
+    return naStr_fromdata(naNewString(c), const_cast<char*>(pdata), strlen(pdata));
+}
+
 class NasalCommand : public SGCommandMgr::Command
 {
 public:
@@ -719,6 +734,7 @@ static struct { const char* name; naCFunction func; } funcs[] = {
     { "abort", f_abort },
     { "directory", f_directory },
     { "resolvepath", f_resolveDataPath },
+    { "finddata", f_findDataDir },
     { "parsexml", f_parsexml },
     { "systime", f_systime },
     { 0, 0 }
@@ -783,7 +799,8 @@ void FGNasalSys::init()
       .method("start", &TimerObj::start)
       .method("stop", &TimerObj::stop)
       .method("restart", &TimerObj::restart)
-      .member("singleShot", &TimerObj::isSingleShot, &TimerObj::setSingleShot);
+      .member("singleShot", &TimerObj::isSingleShot, &TimerObj::setSingleShot)
+      .member("isRunning", &TimerObj::isRunning);
   
     // Now load the various source files in the Nasal directory
     simgear::Dir nasalDir(SGPath(globals->get_fg_root(), "Nasal"));
@@ -816,8 +833,7 @@ naRef FGNasalSys::wrappedPropsNode(SGPropertyNode* aProps)
 {
     static naRef wrapNodeFunc = naNil();
     if (naIsNil(wrapNodeFunc)) {
-        nasal::Hash g(_globals, _context);
-        nasal::Hash props = g.get<nasal::Hash>("props");
+        nasal::Hash props = getGlobals().get<nasal::Hash>("props");
         wrapNodeFunc = props.get("wrapNode");
     }
     
@@ -839,8 +855,11 @@ void FGNasalSys::update(double)
 
     if (!_loadList.empty())
     {
-        // process Nasal load hook (only one per update loop to avoid excessive lags)
-        _loadList.pop()->load();
+        if( _delay_load )
+          _delay_load = false;
+        else
+          // process Nasal load hook (only one per update loop to avoid excessive lags)
+          _loadList.pop()->load();
     }
     else
     if (!_unloadList.empty())
@@ -885,7 +904,7 @@ void FGNasalSys::loadScriptDirectory(simgear::Dir nasalDir)
 // Create module with list of scripts
 void FGNasalSys::addModule(string moduleName, simgear::PathList scripts)
 {
-    if (scripts.size()>0)
+    if (! scripts.empty())
     {
         SGPropertyNode* nasal = globals->get_props()->getNode("nasal");
         SGPropertyNode* module_node = nasal->getChild(moduleName,0,true);
@@ -1235,7 +1254,9 @@ naRef FGNasalSys::removeListener(naContext c, int argc, naRef* args)
 
 void FGNasalSys::registerToLoad(FGNasalModelData *data)
 {
-    _loadList.push(data);
+  if( _loadList.empty() )
+    _delay_load = true;
+  _loadList.push(data);
 }
 
 void FGNasalSys::registerToUnload(FGNasalModelData *data)
@@ -1274,7 +1295,6 @@ FGNasalListener::~FGNasalListener()
 void FGNasalListener::call(SGPropertyNode* which, naRef mode)
 {
     if(_active || _dead) return;
-    SG_LOG(SG_NASAL, SG_DEBUG, "trigger listener #" << _id);
     _active++;
     naRef arg[4];
     arg[0] = _nas->propNodeGhost(which);