don't call change-only listeners at first trigger event
This commit is contained in:
parent
b125315e50
commit
b57f623520
2 changed files with 13 additions and 10 deletions
src/Scripting
|
@ -975,12 +975,12 @@ naRef FGNasalSys::setListener(naContext c, int argc, naRef* args)
|
||||||
return naNil();
|
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,
|
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, init);
|
||||||
node->addChangeListener(nl, initial);
|
|
||||||
|
|
||||||
_listener[_listenerId] = nl;
|
_listener[_listenerId] = nl;
|
||||||
return naNum(_listenerId++);
|
return naNum(_listenerId++);
|
||||||
|
@ -1009,19 +1009,22 @@ naRef FGNasalSys::removeListener(naContext c, int argc, naRef* args)
|
||||||
// FGNasalListener class.
|
// FGNasalListener class.
|
||||||
|
|
||||||
FGNasalListener::FGNasalListener(SGPropertyNode *node, naRef code,
|
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),
|
_node(node),
|
||||||
_code(code),
|
_code(code),
|
||||||
_gcKey(key),
|
_gcKey(key),
|
||||||
_id(id),
|
_id(id),
|
||||||
_nas(nasal),
|
_nas(nasal),
|
||||||
|
_init(init),
|
||||||
_type(type),
|
_type(type),
|
||||||
_active(0),
|
_active(0),
|
||||||
_dead(false),
|
_dead(false),
|
||||||
_first_call(true),
|
|
||||||
_last_int(0L),
|
_last_int(0L),
|
||||||
_last_float(0.0)
|
_last_float(0.0)
|
||||||
{
|
{
|
||||||
|
if(_type == 0 && !_init)
|
||||||
|
changed(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
FGNasalListener::~FGNasalListener()
|
FGNasalListener::~FGNasalListener()
|
||||||
|
@ -1047,10 +1050,10 @@ void FGNasalListener::call(SGPropertyNode* which, naRef mode)
|
||||||
void FGNasalListener::valueChanged(SGPropertyNode* node)
|
void FGNasalListener::valueChanged(SGPropertyNode* node)
|
||||||
{
|
{
|
||||||
if(_type < 2 && node != _node) return; // skip child events
|
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));
|
call(node, naNum(0));
|
||||||
|
|
||||||
_first_call = false;
|
_init = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGNasalListener::childAdded(SGPropertyNode*, SGPropertyNode* child)
|
void FGNasalListener::childAdded(SGPropertyNode*, SGPropertyNode* child)
|
||||||
|
|
|
@ -133,7 +133,7 @@ private:
|
||||||
class FGNasalListener : public SGPropertyChangeListener {
|
class FGNasalListener : public SGPropertyChangeListener {
|
||||||
public:
|
public:
|
||||||
FGNasalListener(SGPropertyNode* node, naRef code, FGNasalSys* nasal,
|
FGNasalListener(SGPropertyNode* node, naRef code, FGNasalSys* nasal,
|
||||||
int key, int id, int type);
|
int key, int id, int init, int type);
|
||||||
|
|
||||||
virtual ~FGNasalListener();
|
virtual ~FGNasalListener();
|
||||||
virtual void valueChanged(SGPropertyNode* node);
|
virtual void valueChanged(SGPropertyNode* node);
|
||||||
|
@ -150,10 +150,10 @@ private:
|
||||||
int _gcKey;
|
int _gcKey;
|
||||||
int _id;
|
int _id;
|
||||||
FGNasalSys* _nas;
|
FGNasalSys* _nas;
|
||||||
|
int _init;
|
||||||
int _type;
|
int _type;
|
||||||
unsigned int _active;
|
unsigned int _active;
|
||||||
bool _dead;
|
bool _dead;
|
||||||
bool _first_call;
|
|
||||||
long _last_int;
|
long _last_int;
|
||||||
double _last_float;
|
double _last_float;
|
||||||
string _last_string;
|
string _last_string;
|
||||||
|
|
Loading…
Add table
Reference in a new issue