]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scripting/NasalSys.hxx
- Added ultra-light traffic is now a separate traffic class that can have its
[flightgear.git] / src / Scripting / NasalSys.hxx
index e9cb6136c5792ce3f0c7df7b27d44f933e6941d5..a68317570842fd9fcae58f6b78488c5e701491ce 100644 (file)
@@ -5,6 +5,7 @@
 #include <simgear/structure/subsystem_mgr.hxx>
 #include <simgear/nasal/nasal.h>
 #include <simgear/scene/model/model.hxx>
+#include <simgear/xml/easyxml.hxx>
 
 #include <map>
 SG_USING_STD(map);
@@ -19,7 +20,7 @@ public:
     FGNasalSys();
     virtual ~FGNasalSys();
     virtual void init();
-    virtual void update(double dt) { /* noop */ }
+    virtual void update(double dt);
 
     // Loads a nasal script from an external file and inserts it as a
     // global module of the specified name.
@@ -40,11 +41,11 @@ public:
     FGNasalScript* parseScript(const char* src, const char* name=0);
 
     // Implementation of the settimer extension function
-    void setTimer(int argc, naRef* args);
+    void setTimer(naContext c, int argc, naRef* args);
 
     // Implementation of the setlistener extension function
-    naRef setListener(int argc, naRef* args);
-    naRef removeListener(int argc, naRef* args);
+    naRef setListener(naContext c, int argc, naRef* args);
+    naRef removeListener(naContext c, int argc, naRef* args);
 
     // Returns a ghost wrapper for the current _cmdArg
     naRef cmdArgGhost();
@@ -70,6 +71,7 @@ private:
     //
     struct NasalTimer {
         virtual void timerExpired();
+        virtual ~NasalTimer() {}
         naRef handler;
         int gcKey;
         FGNasalSys* nasal;
@@ -78,6 +80,7 @@ private:
     // Listener
     map<int, FGNasalListener *> _listener;
     static int _listenerId;
+    bool _purgeListeners;
 
     void loadPropertyScripts();
     void hashset(naRef hash, const char* key, naRef val);
@@ -129,7 +132,7 @@ private:
 class FGNasalListener : public SGPropertyChangeListener {
 public:
     FGNasalListener(SGPropertyNode_ptr node, naRef handler,
-                    FGNasalSys* nasal, int key);
+                    FGNasalSys* nasal, int key, int id);
 
     ~FGNasalListener();
     void valueChanged(SGPropertyNode* node);
@@ -139,20 +142,42 @@ private:
     SGPropertyNode_ptr _node;
     naRef _handler;
     int _gcKey;
+    int _id;
     FGNasalSys* _nas;
     unsigned int _active;
+    bool _dead;
 };
 
 
 class FGNasalModelData : public SGModelData {
 public:
-    FGNasalModelData() : _unload(0) {}
+    FGNasalModelData(SGPropertyNode *props = 0) : _props(props), _unload(0) {}
     ~FGNasalModelData();
-    void modelLoaded(const string& path, SGPropertyNode *prop, ssgBranch *);
+    void modelLoaded(const string& path, SGPropertyNode *prop, osg::Node *);
 
 private:
     string _module;
+    SGPropertyNode_ptr _props;
     SGConstPropertyNode_ptr _unload;
 };
 
+
+class NasalXMLVisitor : public XMLVisitor {
+public:
+    NasalXMLVisitor(naContext c, int argc, naRef* args);
+    virtual ~NasalXMLVisitor() { naFreeContext(_c); }
+
+    virtual void startElement(const char* tag, const XMLAttributes& a);
+    virtual void endElement(const char* tag);
+    virtual void data(const char* str, int len);
+    virtual void pi(const char* target, const char* data);
+
+private:
+    void call(naRef func, int num, naRef a = naNil(), naRef b = naNil());
+    naRef make_string(const char* s, int n = -1);
+
+    naContext _c;
+    naRef _start_element, _end_element, _data, _pi;
+};
+
 #endif // __NASALSYS_HXX