From bc445a1eaafcd01d4ee89a1bd0037540645eb548 Mon Sep 17 00:00:00 2001 From: legoboyvdlp R Date: Sat, 28 Nov 2020 13:40:33 +0000 Subject: [PATCH] Optimization of the systems loop. Remove most of the excess code in libraries.nas, replaced with jsb / updateManager --- A320-main.xml | 1 + AircraftConfig/groundservices.xml | 62 +------- Models/Instruments/MCDU/MCDU.nas | 6 +- Nasal/Libraries/libraries.nas | 252 ++++++++++-------------------- Nasal/Libraries/shake.nas | 9 +- Nasal/Libraries/sounds.nas | 119 ++++++++++++++ Systems/a320-misc.xml | 38 +++++ 7 files changed, 250 insertions(+), 237 deletions(-) create mode 100644 Nasal/Libraries/sounds.nas diff --git a/A320-main.xml b/A320-main.xml index 489f2d47..735e4844 100644 --- a/A320-main.xml +++ b/A320-main.xml @@ -4394,6 +4394,7 @@ Aircraft/A320-family/Nasal/Libraries/libraries.nas + Aircraft/A320-family/Nasal/Libraries/sounds.nas Aircraft/A320-family/Nasal/Libraries/buttons.nas Aircraft/A320-family/Nasal/Libraries/shake.nas Aircraft/A320-family/Nasal/Libraries/zoom-views.nas diff --git a/AircraftConfig/groundservices.xml b/AircraftConfig/groundservices.xml index 0bce5733..c92062a9 100644 --- a/AircraftConfig/groundservices.xml +++ b/AircraftConfig/groundservices.xml @@ -124,16 +124,10 @@ 0 - - - /controls/gear/brake-parking - /services/chocks/enable - - - /velocities/groundspeed-kt - 2 - - + + /velocities/groundspeed-kt + 2 + dialog-apply @@ -150,50 +144,10 @@ /controls/pneumatics/switches/groundair - - - /controls/gear/brake-parking - /services/chocks/enable - - - /velocities/groundspeed-kt - 2 - - - - - dialog-apply - - true - - - - - left - /controls/hydraulic/hand-pump-yellow - - property-toggle - /controls/hydraulic/hand-pump-yellow - - - - - /controls/gear/brake-parking - /services/chocks/enable - - - /velocities/groundspeed-kt - 2 - - - /systems/electrical/bus/ac-2 - 115 - - - /controls/electrical/switches/ext-pwr - 0 - - + + /velocities/groundspeed-kt + 2 + dialog-apply diff --git a/Models/Instruments/MCDU/MCDU.nas b/Models/Instruments/MCDU/MCDU.nas index bb12d326..b04c2835 100644 --- a/Models/Instruments/MCDU/MCDU.nas +++ b/Models/Instruments/MCDU/MCDU.nas @@ -74,6 +74,7 @@ var MAGENTA = [0.6902,0.3333,0.7541]; var mcdu_keyboard_left = props.globals.getNode("/FMGC/keyboard-left", 0); var mcdu_keyboard_right = props.globals.getNode("/FMGC/keyboard-right", 0); var acconfig_weight_kgs = props.globals.getNode("/systems/acconfig/options/weight-kgs", 1); +var engRdy = props.globals.getNode("/engines/ready"); #ACCONFIG var mcdu1_lgt = props.globals.getNode("/controls/lighting/DU/mcdu1", 1); @@ -115,7 +116,6 @@ var align_set = props.globals.getNode("/FMGC/internal/align-set", 1); # FUELPRED var state1 = props.globals.getNode("/engines/engine[0]/state", 1); var state2 = props.globals.getNode("/engines/engine[1]/state", 1); -var engrdy = props.globals.getNode("/engines/ready", 1); # PERF var altitude = props.globals.getNode("/instrumentation/altimeter/indicated-altitude-ft", 1); @@ -3009,12 +3009,12 @@ var canvas_MCDU_base = { pageSwitch[i].setBoolValue(1); } - if (!engrdy.getBoolValue() or !fmgc.FMGCInternal.toFromSet) { + if (!engRdy.getBoolValue() or !fmgc.FMGCInternal.toFromSet) { me["Simple_L1"].setText("NONE"); } else { me["Simple_L1"].setText(fmgc.FMGCInternal.arrApt); } - if (!engrdy.getBoolValue() or !fmgc.FMGCInternal.altAirportSet) { + if (!engRdy.getBoolValue() or !fmgc.FMGCInternal.altAirportSet) { me["Simple_L2"].setText("NONE"); } else { me["Simple_L2"].setText(fmgc.FMGCInternal.altAirport); diff --git a/Nasal/Libraries/libraries.nas b/Nasal/Libraries/libraries.nas index 2e93c670..dfaf8938 100644 --- a/Nasal/Libraries/libraries.nas +++ b/Nasal/Libraries/libraries.nas @@ -7,6 +7,7 @@ print("------------------------------------------------"); print("Copyright (c) 2016-2020 Josh Davidson (Octal450)"); print("------------------------------------------------"); +# Disable specific menubar items setprop("/sim/menubar/default/menu[0]/item[0]/enabled", 0); setprop("/sim/menubar/default/menu[2]/item[0]/enabled", 0); setprop("/sim/menubar/default/menu[2]/item[2]/enabled", 0); @@ -28,9 +29,6 @@ var beacon = aircraft.light.new("/sim/model/lights/beacon", [0.1, 1], "/controls var strobe = aircraft.light.new("/sim/model/lights/strobe", [0.05, 0.06, 0.05, 1], "/controls/lighting/strobe"); var tail_strobe = aircraft.light.new("/sim/model/lights/tailstrobe", [0.1, 1], "/controls/lighting/strobe"); -var stateL = 0; -var stateR = 0; - ########### # Effects # ########### @@ -40,121 +38,6 @@ aircraft.rain.init(); aircraft.livery.init(getprop("/sim/model/livery-dir")); -########## -# Sounds # -########## - -setlistener("/sim/sounde/btn1", func { - if (!getprop("/sim/sounde/btn1")) { - return; - } - settimer(func { - props.globals.getNode("/sim/sounde/btn1").setBoolValue(0); - }, 0.05); -}); - -setlistener("/sim/sounde/oh-btn", func { - if (!getprop("/sim/sounde/oh-btn")) { - return; - } - settimer(func { - props.globals.getNode("/sim/sounde/oh-btn").setBoolValue(0); - }, 0.05); -}); - -setlistener("/sim/sounde/btn3", func { - if (!getprop("/sim/sounde/btn3")) { - return; - } - settimer(func { - props.globals.getNode("/sim/sounde/btn3").setBoolValue(0); - }, 0.05); -}); - -setlistener("/sim/sounde/knb1", func { - if (!getprop("/sim/sounde/knb1")) { - return; - } - settimer(func { - props.globals.getNode("/sim/sounde/knb1").setBoolValue(0); - }, 0.05); -}); - -setlistener("/sim/sounde/switch1", func { - if (!getprop("/sim/sounde/switch1")) { - return; - } - settimer(func { - props.globals.getNode("/sim/sounde/switch1").setBoolValue(0); - }, 0.05); -}); - -setlistener("/controls/lighting/seatbelt-sign", func { - props.globals.getNode("/sim/sounde/seatbelt-sign").setBoolValue(1); - settimer(func { - props.globals.getNode("/sim/sounde/seatbelt-sign").setBoolValue(0); - }, 2); -}, 0, 0); - -setlistener("/controls/lighting/no-smoking-sign", func { - props.globals.getNode("/sim/sounde/no-smoking-sign").setBoolValue(1); - settimer(func { - props.globals.getNode("/sim/sounde/no-smoking-sign").setBoolValue(0); - }, 1); -}, 0, 0); - -var flaps_click = props.globals.getNode("/sim/sounde/flaps-click"); - -setlistener("/controls/flight/flaps-input", func { - flaps_click.setBoolValue(1); -}, 0, 0); - -setlistener("/sim/sounde/flaps-click", func { - if (!flaps_click.getValue()) { - return; - } - settimer(func { - flaps_click.setBoolValue(0); - }, 0.4); -}); - -var spdbrk_click = props.globals.getNode("/sim/sounde/spdbrk-click"); - -setlistener("/controls/flight/speedbrake", func { - spdbrk_click.setBoolValue(1); -}, 0, 0); - -setlistener("/sim/sounde/spdbrk-click", func { - if (!spdbrk_click.getValue()) { - return; - } - settimer(func { - spdbrk_click.setBoolValue(0); - }, 0.4); -}); - -var relayBatt1 = func { - setprop("/sim/sounde/relay-batt-1",1); - settimer(func {setprop("/sim/sounde/relay-batt-1",0);},0.35); -} -var relayBatt2 = func { - setprop("/sim/sounde/relay-batt-2",1); - settimer(func {setprop("/sim/sounde/relay-batt-2",0);},0.35); -} -var relayApu = func { - setprop("/sim/sounde/relay-apu",1); - settimer(func {setprop("/sim/sounde/relay-apu",0);},0.35); -} -var relayExt = func { - setprop("/sim/sounde/relay-ext",1); - settimer(func {setprop("/sim/sounde/relay-ext",0);},0.35); -} - -setlistener("/systems/electrical/sources/bat-1/contact", relayBatt1, nil, 0); -setlistener("/systems/electrical/sources/bat-2/contact", relayBatt2, nil, 0); -setlistener("/systems/electrical/relay/apu-glc/contact-pos", relayApu, nil, 0); -setlistener("/systems/electrical/relay/ext-epc/contact-pos", relayExt, nil, 0); - ######### # Doors # ######### @@ -199,7 +82,11 @@ var triggerDoor = func(door, doorName, doorDesc) { ########### # Systems # ########### +var systemsInitialized = 0; +var A320Libraries = nil; + var systemsInit = func { + systemsInitialized = 0; fbw.FBW.init(); effects.light_manager.init(); systems.ELEC.init(); @@ -221,9 +108,7 @@ var systemsInit = func { mcdu.MCDU_init(1); mcdu_scratchpad.mcduMsgtimer1.start(); mcdu_scratchpad.mcduMsgtimer2.start(); - systemsLoop.start(); effects.icingInit(); - lightsLoop.start(); ecam.ECAM.init(); libraries.variousReset(); rmp.init(); @@ -235,6 +120,7 @@ var systemsInit = func { fmgc.flightPlanController.init(); fmgc.windController.init(); atsu.CompanyCall.init(); + systemsInitialized = 1; } setlistener("/sim/signals/fdm-initialized", func { @@ -242,6 +128,9 @@ setlistener("/sim/signals/fdm-initialized", func { fmgc.postInit(); fmgc.flightPlanTimer.start(); fmgc.WaypointDatabase.read(); + + A320Libraries = LibrariesRecipient.new("A320 Libraries"); + emesary.GlobalTransmitter.Register(A320Libraries); }); var collectorTankL = props.globals.getNode("/fdm/jsbsim/propulsion/tank[5]/contents-lbs"); @@ -249,10 +138,42 @@ var collectorTankR = props.globals.getNode("/fdm/jsbsim/propulsion/tank[6]/conte var groundAir = props.globals.getNode("/controls/pneumatics/switches/groundair"); var groundCart = props.globals.getNode("/controls/electrical/ground-cart"); var chocks = props.globals.getNode("/services/chocks/enable"); -var engRdy = props.globals.getNode("/engines/ready"); var groundspeed = 0; +var stateL = 0; +var stateR = 0; -var systemsLoop = maketimer(0.1, func { +var seatbeltLight = props.globals.getNode("/controls/lighting/seatbelt-sign"); +var noSmokingLight = props.globals.getNode("/controls/lighting/no-smoking-sign"); + +var update_items = [ + props.UpdateManager.FromHashValue("seatbelt", nil, func(val) { + if (val) { + if (!seatbeltLight.getBoolValue()) { + seatbeltLight.setValue(1); + } + } else { + if (seatbeltLight.getBoolValue()) { + seatbeltLight.setValue(0); + } + } + }), + props.UpdateManager.FromHashList(["noSmoking","gearPosNorm"], nil, func(val) { + if (val.noSmoking) { + if (!noSmokingLight.getBoolValue()) { + noSmokingLight.setBoolValue(1); + } + } elsif (val.noSmoking == 0.5 and val.gearPosNorm != 0) { # todo: should be when uplocks not engaged + if (!noSmokingLight.getBoolValue()) { + noSmokingLight.setBoolValue(1); + } + } else { + noSmokingLight.setBoolValue(0); # sign stays on in cabin but sound still occurs + } + }), +]; + +var systemsLoop = func(notification) { + if (!systemsInitialized) { return; } systems.ELEC.loop(); systems.PNEU.loop(); systems.HYD.loop(); @@ -267,34 +188,20 @@ var systemsLoop = maketimer(0.1, func { libraries.BUTTONS.update(); systems.HFLoop(); - groundspeed = pts.Velocities.groundspeed.getValue(); - if ((groundAir.getBoolValue() or groundCart.getBoolValue()) and ((groundspeed > 2) or (!pts.Controls.Gear.parkingBrake.getBoolValue() and !chocks.getBoolValue()))) { - groundAir.setBoolValue(0); - groundCart.setBoolValue(0); - } - - if (groundspeed > 15) { - shakeEffectA3XX.setBoolValue(1); - } else { - shakeEffectA3XX.setBoolValue(0); - } - stateL = pts.Engines.Engine.state[0].getValue(); stateR = pts.Engines.Engine.state[1].getValue(); - if (stateL == 3 and stateR == 3) { - engRdy.setBoolValue(1); - } else { - engRdy.setBoolValue(0); - } - if ((stateL == 2 or stateL == 3) and collectorTankL.getValue() < 1) { systems.cutoff_one(); } if ((stateR == 2 or stateR == 3) and collectorTankR.getValue() < 1) { systems.cutoff_two(); } -}); + + foreach (var update_item; update_items) { + update_item.update(notification); + } +} # GPWS var GPWS = { @@ -482,37 +389,6 @@ var slewPitchWheel = func(d) { # Lights # ########## -var lightsLoop = maketimer(0.2, func { - # signs - - if (getprop("/systems/pressurization/cabinalt-norm") > 11300) { - setprop("/controls/lighting/seatbelt-sign", 1); - setprop("/controls/lighting/no-smoking-sign", 1); - } else { - if (getprop("/controls/switches/seatbelt-sign") == 1) { - if (getprop("/controls/lighting/seatbelt-sign") == 0) { - setprop("/controls/lighting/seatbelt-sign", 1); - } - } elsif (getprop("/controls/switches/seatbelt-sign") == 0) { - if (getprop("/controls/lighting/seatbelt-sign") == 1) { - setprop("/controls/lighting/seatbelt-sign", 0); - } - } - - if (getprop("/controls/switches/no-smoking-sign") == 1) { - if (getprop("/controls/lighting/no-smoking-sign") == 0) { - setprop("/controls/lighting/no-smoking-sign", 1); - } - } elsif (getprop("/controls/switches/no-smoking-sign") == 0.5 and getprop("/gear/gear[0]/position-norm") != 0) { # todo: should be when uplocks not engaged - if (getprop("/controls/lighting/no-smoking-sign") == 0) { - setprop("/controls/lighting/no-smoking-sign", 1); - } - } else { - setprop("/controls/lighting/no-smoking-sign", 0); # sign stays on in cabin but sound still occurs - } - } -}); - var pilotComfortTwoPos = func(prop) { var item = getprop(prop); if (item < 0.5) { @@ -584,4 +460,36 @@ var APPanel = { }, }; + +# Emesary +var LibrariesRecipient = +{ + new: func(_ident) + { + var NewLibrariesRecipient = emesary.Recipient.new(_ident); + NewLibrariesRecipient.Receive = func(notification) + { + if (notification.NotificationType == "FrameNotification") + { + if (math.mod(notifications.frameNotification.FrameCount,4) == 0) { + systemsLoop(notification); + } + return emesary.Transmitter.ReceiptStatus_OK; + } + return emesary.Transmitter.ReceiptStatus_NotProcessed; + }; + return NewLibrariesRecipient; + }, +}; + +var input = { + "seatbelt": "/controls/switches/seatbelt-sign", + "noSmoking": "/controls/switches/no-smoking-sign", + "gearPosNorm": "/gear/gear[0]/position-norm", +}; + +foreach (var name; keys(input)) { + emesary.GlobalTransmitter.NotifyAll(notifications.FrameNotificationAddProperty.new("A320 Libraries", name, input[name])); +} + setprop("/systems/acconfig/libraries-loaded", 1); diff --git a/Nasal/Libraries/shake.nas b/Nasal/Libraries/shake.nas index d861590f..eb9e8091 100644 --- a/Nasal/Libraries/shake.nas +++ b/Nasal/Libraries/shake.nas @@ -5,16 +5,9 @@ var shakeEffectA3XX = props.globals.initNode("/systems/shake/effect", 0, "BOOL"); var shakeA3XX = props.globals.initNode("/systems/shake/shaking", 0, "DOUBLE"); var sf = 0; -var n_g_c = 0; -var n_g_l = 0; -var n_g_r = 0; var theShakeEffect = func { - n_g_c = pts.Gear.compression[0].getValue() or 0; - n_g_l = pts.Gear.compression[1].getValue() or 0; - n_g_r = pts.Gear.compression[2].getValue() or 0; - - if (shakeEffectA3XX.getBoolValue() and (n_g_c > 0 or n_g_l > 0 or n_g_r > 0)) { + if (shakeEffectA3XX.getBoolValue()) { sf = pts.Gear.rollspeed[0].getValue() / 94000; interpolate("/systems/shake/shaking", sf, 0.03); settimer(func { diff --git a/Nasal/Libraries/sounds.nas b/Nasal/Libraries/sounds.nas new file mode 100644 index 00000000..e3350c31 --- /dev/null +++ b/Nasal/Libraries/sounds.nas @@ -0,0 +1,119 @@ +# A320 Main Libraries +# Joshua Davidson (Octal450) + +# Copyright (c) 2020 Josh Davidson (Octal450) + +########## +# Sounds # +########## + +setlistener("/sim/sounde/btn1", func { + if (!getprop("/sim/sounde/btn1")) { + return; + } + settimer(func { + props.globals.getNode("/sim/sounde/btn1").setBoolValue(0); + }, 0.05); +}); + +setlistener("/sim/sounde/oh-btn", func { + if (!getprop("/sim/sounde/oh-btn")) { + return; + } + settimer(func { + props.globals.getNode("/sim/sounde/oh-btn").setBoolValue(0); + }, 0.05); +}); + +setlistener("/sim/sounde/btn3", func { + if (!getprop("/sim/sounde/btn3")) { + return; + } + settimer(func { + props.globals.getNode("/sim/sounde/btn3").setBoolValue(0); + }, 0.05); +}); + +setlistener("/sim/sounde/knb1", func { + if (!getprop("/sim/sounde/knb1")) { + return; + } + settimer(func { + props.globals.getNode("/sim/sounde/knb1").setBoolValue(0); + }, 0.05); +}); + +setlistener("/sim/sounde/switch1", func { + if (!getprop("/sim/sounde/switch1")) { + return; + } + settimer(func { + props.globals.getNode("/sim/sounde/switch1").setBoolValue(0); + }, 0.05); +}); + +setlistener("/controls/lighting/seatbelt-sign", func { + props.globals.getNode("/sim/sounde/seatbelt-sign").setBoolValue(1); + settimer(func { + props.globals.getNode("/sim/sounde/seatbelt-sign").setBoolValue(0); + }, 2); +}, 0, 0); + +setlistener("/controls/lighting/no-smoking-sign", func { + props.globals.getNode("/sim/sounde/no-smoking-sign").setBoolValue(1); + settimer(func { + props.globals.getNode("/sim/sounde/no-smoking-sign").setBoolValue(0); + }, 1); +}, 0, 0); + +var flaps_click = props.globals.getNode("/sim/sounde/flaps-click"); + +setlistener("/controls/flight/flaps-input", func { + flaps_click.setBoolValue(1); +}, 0, 0); + +setlistener("/sim/sounde/flaps-click", func { + if (!flaps_click.getValue()) { + return; + } + settimer(func { + flaps_click.setBoolValue(0); + }, 0.4); +}); + +var spdbrk_click = props.globals.getNode("/sim/sounde/spdbrk-click"); + +setlistener("/controls/flight/speedbrake", func { + spdbrk_click.setBoolValue(1); +}, 0, 0); + +setlistener("/sim/sounde/spdbrk-click", func { + if (!spdbrk_click.getValue()) { + return; + } + settimer(func { + spdbrk_click.setBoolValue(0); + }, 0.4); +}); + +var relayBatt1 = func { + setprop("/sim/sounde/relay-batt-1",1); + settimer(func {setprop("/sim/sounde/relay-batt-1",0);},0.35); +} +var relayBatt2 = func { + setprop("/sim/sounde/relay-batt-2",1); + settimer(func {setprop("/sim/sounde/relay-batt-2",0);},0.35); +} +var relayApu = func { + setprop("/sim/sounde/relay-apu",1); + settimer(func {setprop("/sim/sounde/relay-apu",0);},0.35); +} +var relayExt = func { + setprop("/sim/sounde/relay-ext",1); + settimer(func {setprop("/sim/sounde/relay-ext",0);},0.35); +} + +setlistener("/systems/electrical/sources/bat-1/contact", relayBatt1, nil, 0); +setlistener("/systems/electrical/sources/bat-2/contact", relayBatt2, nil, 0); +setlistener("/systems/electrical/relay/apu-glc/contact-pos", relayApu, nil, 0); +setlistener("/systems/electrical/relay/ext-epc/contact-pos", relayExt, nil, 0); diff --git a/Systems/a320-misc.xml b/Systems/a320-misc.xml index 22dddba9..685be99e 100644 --- a/Systems/a320-misc.xml +++ b/Systems/a320-misc.xml @@ -39,4 +39,42 @@ + + + + + + /velocities/groundspeed-kt ge 15 + + /gear/gear[0]/compression-norm ge 0 + /gear/gear[1]/compression-norm ge 0 + /gear/gear[2]/compression-norm ge 0 + + + + + + + + /engines/engine[0]/state eq 3 + /engines/engine[1]/state eq 3 + + + + + + + /velocities/groundspeed-kt ge 2 + + + + + + + /velocities/groundspeed-kt ge 2 + + + + +