1
0
Fork 0

Optimization of the systems loop. Remove most of the excess code in libraries.nas, replaced with jsb / updateManager

This commit is contained in:
legoboyvdlp R 2020-11-28 13:40:33 +00:00
parent 98378f45ea
commit bc445a1eaa
7 changed files with 250 additions and 237 deletions

View file

@ -4394,6 +4394,7 @@
</pts>
<libraries>
<file>Aircraft/A320-family/Nasal/Libraries/libraries.nas</file>
<file>Aircraft/A320-family/Nasal/Libraries/sounds.nas</file>
<file>Aircraft/A320-family/Nasal/Libraries/buttons.nas</file>
<file>Aircraft/A320-family/Nasal/Libraries/shake.nas</file>
<file>Aircraft/A320-family/Nasal/Libraries/zoom-views.nas</file>

View file

@ -124,16 +124,10 @@
<value>0</value>
</binding>
<enable>
<and>
<or>
<property>/controls/gear/brake-parking</property>
<property>/services/chocks/enable</property>
</or>
<less-than>
<property>/velocities/groundspeed-kt</property>
<value>2</value>
</less-than>
</and>
<less-than>
<property>/velocities/groundspeed-kt</property>
<value>2</value>
</less-than>
</enable>
<binding>
<command>dialog-apply</command>
@ -150,50 +144,10 @@
<property>/controls/pneumatics/switches/groundair</property>
</binding>
<enable>
<and>
<or>
<property>/controls/gear/brake-parking</property>
<property>/services/chocks/enable</property>
</or>
<less-than>
<property>/velocities/groundspeed-kt</property>
<value>2</value>
</less-than>
</and>
</enable>
<binding>
<command>dialog-apply</command>
</binding>
<live>true</live>
</checkbox>
<checkbox>
<label>Yellow HYD Hand Pump</label>
<halign>left</halign>
<property>/controls/hydraulic/hand-pump-yellow</property>
<binding>
<command>property-toggle</command>
<property>/controls/hydraulic/hand-pump-yellow</property>
</binding>
<enable>
<and>
<or>
<property>/controls/gear/brake-parking</property>
<property>/services/chocks/enable</property>
</or>
<less-than>
<property>/velocities/groundspeed-kt</property>
<value>2</value>
</less-than>
<less-than>
<property>/systems/electrical/bus/ac-2</property>
<value>115</value>
</less-than>
<equals>
<property>/controls/electrical/switches/ext-pwr</property>
<value>0</value>
</equals>
</and>
<less-than>
<property>/velocities/groundspeed-kt</property>
<value>2</value>
</less-than>
</enable>
<binding>
<command>dialog-apply</command>

View file

@ -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);

View file

@ -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);

View file

@ -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 {

119
Nasal/Libraries/sounds.nas Normal file
View file

@ -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);

View file

@ -39,4 +39,42 @@
</channel>
<channel name="Shake" execrate="8">
<switch name="/systems/shake/effect">
<default value="0"/>
<test logic="AND" value="1">
/velocities/groundspeed-kt ge 15
<test logic="OR">
/gear/gear[0]/compression-norm ge 0
/gear/gear[1]/compression-norm ge 0
/gear/gear[2]/compression-norm ge 0
</test>
</test>
</switch>
<switch name="/engines/ready">
<default value="0"/>
<test logic="AND" value="1">
/engines/engine[0]/state eq 3
/engines/engine[1]/state eq 3
</test>
</switch>
<switch name="/controls/pneumatics/switches/groundair">
<default value="/controls/pneumatics/switches/groundair"/>
<test logic="AND" value="0">
/velocities/groundspeed-kt ge 2
</test>
</switch>
<switch name="/controls/electrical/ground-cart">
<default value="/controls/electrical/ground-cart"/>
<test logic="AND" value="0">
/velocities/groundspeed-kt ge 2
</test>
</switch>
</channel>
</system>