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:
parent
617fc1de70
commit
e282a1e6ed
6 changed files with 23 additions and 8 deletions
|
@ -177,12 +177,12 @@ var setAllMCBF = func(mcbf) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
# 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();
|
||||
|
||||
# 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;
|
||||
foreach (var e; props.globals.getNode("/engines").getChildren("engine")) {
|
||||
breakHash[e.getPath()] = { type: type.MTBF, failure: fail.ENGINE, desc : "Engine " ~ i };
|
||||
|
|
|
@ -68,8 +68,14 @@ var tanks = [];
|
|||
var engines = [];
|
||||
var fuel_freeze = nil;
|
||||
|
||||
var freeze_fuel_listener = nil;
|
||||
var initialized = 0;
|
||||
|
||||
_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)
|
||||
# handle fuel themselves.
|
||||
|
@ -81,6 +87,11 @@ _setlistener("/sim/signals/fdm-initialized", func {
|
|||
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")) {
|
||||
if (!t.getAttribute("children"))
|
||||
continue; # skip native_fdm.cxx generated zombie tanks
|
||||
|
|
|
@ -87,7 +87,8 @@ var loop = func(id) {
|
|||
|
||||
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
|
||||
var top = props.globals.initNode("/sim/model/geometry/square/top", 1, "BOOL");
|
||||
|
||||
|
|
|
@ -114,8 +114,9 @@ var check_params = func() {
|
|||
}
|
||||
}
|
||||
|
||||
_setlistener("/sim/signals/fdm-initialized",
|
||||
var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized",
|
||||
func {
|
||||
removelistener(fdm_init_listener); # uninstall, so we're only called once
|
||||
fdm = getprop("/sim/flight-model");
|
||||
running_redout = getprop("/sim/rendering/redout/enabled");
|
||||
running_compression = getprop("/sim/rendering/headshake/enabled");
|
||||
|
|
|
@ -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/,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 p; split(",", n.getValue())) {
|
||||
if (!size(p))
|
||||
|
|
|
@ -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;
|
||||
foreach (var v; views) {
|
||||
var index = v.getIndex();
|
||||
|
|
Loading…
Reference in a new issue