]> git.mxchange.org Git - flightgear.git/commitdiff
don't call change-only listeners at first trigger event
authormfranz <mfranz>
Sat, 7 Mar 2009 17:57:20 +0000 (17:57 +0000)
committerTim Moore <timoore@redhat.com>
Wed, 11 Mar 2009 22:14:34 +0000 (23:14 +0100)
src/Scripting/NasalSys.cxx
src/Scripting/NasalSys.hxx

index d6277ae69b5efa47d4cd45100344c5dfc10b4b15..219321b013d1bed9551eb8b2c47c8615d423a6ee 100644 (file)
@@ -975,12 +975,12 @@ naRef FGNasalSys::setListener(naContext c, int argc, naRef* args)
         return naNil();
     }
 
-    int type = argc > 3 && naIsNum(args[3]) ? (int)args[3].num : 1;
+    int init = argc > 2 && naIsNum(args[2]) ? int(args[2].num) : 0;
+    int type = argc > 3 && naIsNum(args[3]) ? int(args[3].num) : 1;
     FGNasalListener *nl = new FGNasalListener(node, code, this,
-            gcSave(code), _listenerId, type);
+            gcSave(code), _listenerId, init, type);
 
-    bool initial = argc > 2 && naTrue(args[2]);
-    node->addChangeListener(nl, initial);
+    node->addChangeListener(nl, init);
 
     _listener[_listenerId] = nl;
     return naNum(_listenerId++);
@@ -1009,19 +1009,22 @@ naRef FGNasalSys::removeListener(naContext c, int argc, naRef* args)
 // FGNasalListener class.
 
 FGNasalListener::FGNasalListener(SGPropertyNode *node, naRef code,
-                                 FGNasalSys* nasal, int key, int id, int type) :
+                                 FGNasalSys* nasal, int key, int id,
+                                 int init, int type) :
     _node(node),
     _code(code),
     _gcKey(key),
     _id(id),
     _nas(nasal),
+    _init(init),
     _type(type),
     _active(0),
     _dead(false),
-    _first_call(true),
     _last_int(0L),
     _last_float(0.0)
 {
+    if(_type == 0 && !_init)
+        changed(node);
 }
 
 FGNasalListener::~FGNasalListener()
@@ -1047,10 +1050,10 @@ void FGNasalListener::call(SGPropertyNode* which, naRef mode)
 void FGNasalListener::valueChanged(SGPropertyNode* node)
 {
     if(_type < 2 && node != _node) return;   // skip child events
-    if(_type > 0 || changed(_node) || _first_call)
+    if(_type > 0 || changed(_node) || _init)
         call(node, naNum(0));
 
-    _first_call = false;
+    _init = 0;
 }
 
 void FGNasalListener::childAdded(SGPropertyNode*, SGPropertyNode* child)
index 9b50e89f0e2f4915a0d0ba7554168701edcd84d1..090777f65a058da3934e7e503fe692aa8f4c24d1 100644 (file)
@@ -133,7 +133,7 @@ private:
 class FGNasalListener : public SGPropertyChangeListener {
 public:
     FGNasalListener(SGPropertyNode* node, naRef code, FGNasalSys* nasal,
-                    int key, int id, int type);
+                    int key, int id, int init, int type);
 
     virtual ~FGNasalListener();
     virtual void valueChanged(SGPropertyNode* node);
@@ -150,10 +150,10 @@ private:
     int _gcKey;
     int _id;
     FGNasalSys* _nas;
+    int _init;
     int _type;
     unsigned int _active;
     bool _dead;
-    bool _first_call;
     long _last_int;
     double _last_float;
     string _last_string;