diff --git a/Nasal/failures.nas b/Nasal/failures.nas index ccf6f7966..23cb7384d 100644 --- a/Nasal/failures.nas +++ b/Nasal/failures.nas @@ -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 }; diff --git a/Nasal/fuel.nas b/Nasal/fuel.nas index edf28ac0b..d7054afbd 100644 --- a/Nasal/fuel.nas +++ b/Nasal/fuel.nas @@ -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 diff --git a/Nasal/glide_slope_tunnel.nas b/Nasal/glide_slope_tunnel.nas index c6564df2d..2ad9c9f7d 100644 --- a/Nasal/glide_slope_tunnel.nas +++ b/Nasal/glide_slope_tunnel.nas @@ -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"); diff --git a/Nasal/redout.nas b/Nasal/redout.nas index 88d3cdb67..1a2126270 100644 --- a/Nasal/redout.nas +++ b/Nasal/redout.nas @@ -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"); diff --git a/Nasal/screen.nas b/Nasal/screen.nas index 2d572aa57..391790882 100644 --- a/Nasal/screen.nas +++ b/Nasal/screen.nas @@ -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)) diff --git a/Nasal/view.nas b/Nasal/view.nas index a1975d092..bbfe8834b 100644 --- a/Nasal/view.nas +++ b/Nasal/view.nas @@ -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();