1
0
Fork 0

fgdata/Nasal: avoid performance drop after sim reset/relocate

"/sim/signals/fdm-initialized" triggers _every_ time the FDM is reset,
so for every sim reset/relocate.
We need to uninstall the listeners after its first execution, or guard
certain parts of the initialization, to avoid starting multiple
"timer/update loops", or installing multiple property listeners.
Repeating "sim reset" often enough would eventually completely block/
overload the system.
This commit is contained in:
ThorstenB 2012-03-20 21:18:20 +01:00
parent 617fc1de70
commit e282a1e6ed
6 changed files with 23 additions and 8 deletions

View file

@ -177,12 +177,12 @@ var setAllMCBF = func(mcbf) {
} }
} }
# Initialization, called once Nasal and the FDM are loaded properly. # Initialization, called once Nasal and the FDM are loaded properly.
_setlistener("/sim/signals/fdm-initialized", func { var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized-once", func {
removelistener(fdm_init_listener); # uninstall, so we're only called once
srand(); srand();
# Engines are added dynamically because there may be an arbritary number # Engines are added dynamically because there may be an arbitrary number
var i = 1; var i = 1;
foreach (var e; props.globals.getNode("/engines").getChildren("engine")) { foreach (var e; props.globals.getNode("/engines").getChildren("engine")) {
breakHash[e.getPath()] = { type: type.MTBF, failure: fail.ENGINE, desc : "Engine " ~ i }; breakHash[e.getPath()] = { type: type.MTBF, failure: fail.ENGINE, desc : "Engine " ~ i };

View file

@ -68,8 +68,14 @@ var tanks = [];
var engines = []; var engines = [];
var fuel_freeze = nil; var fuel_freeze = nil;
var freeze_fuel_listener = nil;
var initialized = 0;
_setlistener("/sim/signals/fdm-initialized", func { _setlistener("/sim/signals/fdm-initialized", func {
setlistener("/sim/freeze/fuel", func(n) { fuel_freeze = n.getBoolValue() }, 1); if (freeze_fuel_listener == nil)
{
freeze_fuel_listener = setlistener("/sim/freeze/fuel", func(n) { fuel_freeze = n.getBoolValue() }, 1);
}
# Fuel sub-system is only used by YASim. Other FDMs (e.g. JSBSim) # Fuel sub-system is only used by YASim. Other FDMs (e.g. JSBSim)
# handle fuel themselves. # handle fuel themselves.
@ -81,6 +87,11 @@ _setlistener("/sim/signals/fdm-initialized", func {
e.getNode("out-of-fuel", 1).setBoolValue(0); e.getNode("out-of-fuel", 1).setBoolValue(0);
} }
# do the following stuff once only
if (initialized)
return;
initialized = 1;
foreach (var t; props.globals.getNode("/consumables/fuel", 1).getChildren("tank")) { foreach (var t; props.globals.getNode("/consumables/fuel", 1).getChildren("tank")) {
if (!t.getAttribute("children")) if (!t.getAttribute("children"))
continue; # skip native_fdm.cxx generated zombie tanks continue; # skip native_fdm.cxx generated zombie tanks

View file

@ -87,7 +87,8 @@ var loop = func(id) {
var loopid = 0; var loopid = 0;
_setlistener("/sim/signals/fdm-initialized", func { var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized", func {
removelistener(fdm_init_listener); # uninstall, so we're only called once
# remove top bar unless otherwise specified # remove top bar unless otherwise specified
var top = props.globals.initNode("/sim/model/geometry/square/top", 1, "BOOL"); var top = props.globals.initNode("/sim/model/geometry/square/top", 1, "BOOL");

View file

@ -114,8 +114,9 @@ var check_params = func() {
} }
} }
_setlistener("/sim/signals/fdm-initialized", var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized",
func { func {
removelistener(fdm_init_listener); # uninstall, so we're only called once
fdm = getprop("/sim/flight-model"); fdm = getprop("/sim/flight-model");
running_redout = getprop("/sim/rendering/redout/enabled"); running_redout = getprop("/sim/rendering/redout/enabled");
running_compression = getprop("/sim/rendering/headshake/enabled"); running_compression = getprop("/sim/rendering/headshake/enabled");

View file

@ -435,7 +435,8 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
# --prop:display=position/ ... adds all properties under /position/ (ends with slash!) # --prop:display=position/ ... adds all properties under /position/ (ends with slash!)
# --prop:display=position/,orientation/ ... separate multiple properties with comma # --prop:display=position/,orientation/ ... separate multiple properties with comma
# #
_setlistener("/sim/signals/fdm-initialized", func { var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized", func {
removelistener(fdm_init_listener); # uninstall, so we're only called once
foreach (var n; props.globals.getChildren("display")) { foreach (var n; props.globals.getChildren("display")) {
foreach (var p; split(",", n.getValue())) { foreach (var p; split(",", n.getValue())) {
if (!size(p)) if (!size(p))

View file

@ -655,7 +655,8 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
}); });
_setlistener("/sim/signals/fdm-initialized", func { var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized", func {
removelistener(fdm_init_listener); # uninstall, so we're only called once
var zoffset = nil; var zoffset = nil;
foreach (var v; views) { foreach (var v; views) {
var index = v.getIndex(); var index = v.getIndex();