From 4ec3850aaf1247d1ca9fdde6b88ce3229343034b Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Tue, 20 Mar 2012 21:19:42 +0100 Subject: [PATCH] c172p: avoid performance drop after sim reset/relocate "/sim/signals/fdm-initialized" triggers _every_ time the FDM is reset. 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. --- Aircraft/c172p/Nasal/immat.nas | 14 ++++++++++---- Aircraft/c172p/Nasal/light.nas | 18 ++++++++---------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Aircraft/c172p/Nasal/immat.nas b/Aircraft/c172p/Nasal/immat.nas index 63f52370f..204da628f 100644 --- a/Aircraft/c172p/Nasal/immat.nas +++ b/Aircraft/c172p/Nasal/immat.nas @@ -22,14 +22,20 @@ var refresh_immat = func { var immat_dialog = gui.Dialog.new("/sim/gui/dialogs/c172p/status/dialog", "Aircraft/c172p/Dialogs/immat.xml"); +var refresh_immat_listener = nil; + setlistener("/sim/signals/fdm-initialized", func { if (props.globals.getNode("/sim/model/immat") == nil) { var immat = props.globals.getNode("/sim/model/immat",1); var callsign = props.globals.getNode("/sim/multiplay/callsign").getValue(); - if (callsign != "callsign") immat.setValue(callsign); - else immat.setValue("F-GHYQ"); + if (callsign != "callsign") + immat.setValue(callsign); + else + immat.setValue("F-GHYQ"); } refresh_immat(); - setlistener("sim/model/immat", refresh_immat, 0); + if (refresh_immat_listener == nil) + { + refresh_immat_listener = setlistener("sim/model/immat", refresh_immat, 0); + } },0); - diff --git a/Aircraft/c172p/Nasal/light.nas b/Aircraft/c172p/Nasal/light.nas index 16f59780f..f54a06137 100644 --- a/Aircraft/c172p/Nasal/light.nas +++ b/Aircraft/c172p/Nasal/light.nas @@ -7,24 +7,22 @@ aircraft.light.new("sim/model/c172p/lighting/strobes", [0.015, 1.985], strobe_sw var beacon_switch = props.globals.getNode("controls/lighting/beacon", 1); aircraft.light.new("sim/model/c172p/lighting/beacon-top", [0.10, 0.90], beacon_switch); -# Control both panel and instrument light intensity with one property +# Control both panel and instrument light intensity with one property var instrumentsNorm = props.globals.getNode("controls/lighting/instruments-norm", 1); var instrumentLightFactor = props.globals.getNode("sim/model/material/instruments/factor", 1); var panelLights = props.globals.getNode("controls/lighting/panel-norm", 1); var update_intensity = func { - instrumentLightFactor.setDoubleValue(instrumentsNorm.getValue()); panelLights.setDoubleValue(instrumentsNorm.getValue()); - settimer(update_intensity, 0); + settimer(update_intensity, 0.1); } -# Setup listener call to start update loop once the fdm is initialized -# -setlistener("sim/signals/fdm-initialized", update_intensity); - -# Make sure that update_intensity is called when the sim is reset -setlistener("sim/signals/reset", update_intensity); - +# Setup listener call to start update loop once the fdm is initialized, +# but only start the update loop _once_. +var fdm_init_listener = setlistener("sim/signals/fdm-initialized", func { + removelistener(fdm_init_listener); + update_intensity(); +});