Nasal loadpriority; remove nasal-dir-initialized listeners;
add more dependencies to loadpriority.xml and remove _setlistener stuff
This commit is contained in:
parent
60097f3c74
commit
148328d793
21 changed files with 492 additions and 526 deletions
|
@ -96,7 +96,7 @@ var init = func {
|
|||
}
|
||||
}
|
||||
|
||||
var id = _setlistener("/sim/signals/fdm-initialized", func {
|
||||
var id = setlistener("/sim/signals/fdm-initialized", func {
|
||||
removelistener(id);
|
||||
addons.init();
|
||||
})
|
||||
}, 0, 0);
|
||||
|
|
|
@ -1174,40 +1174,32 @@ var crossfeed_valve = {
|
|||
}
|
||||
};
|
||||
|
||||
props.globals.initNode("/sim/time/elapsed-sec", 0);
|
||||
props.globals.initNode("/sim/time/delta-sec", 0);
|
||||
props.globals.initNode("/sim/time/delta-realtime-sec", 0.00000001);
|
||||
|
||||
|
||||
|
||||
# module initialization
|
||||
# ==============================================================================
|
||||
#
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
props.globals.initNode("/sim/time/elapsed-sec", 0);
|
||||
props.globals.initNode("/sim/time/delta-sec", 0);
|
||||
props.globals.initNode("/sim/time/delta-realtime-sec", 0.00000001);
|
||||
|
||||
HUD.init();
|
||||
data.init();
|
||||
autotrim.init();
|
||||
HUD.init();
|
||||
data.init();
|
||||
autotrim.init();
|
||||
|
||||
##### temporary hack to provide backward compatibility for /sim/auto-coordination
|
||||
##### remove this code when all references to /sim/auto-coordination are gone
|
||||
var ac = props.globals.getNode("/sim/auto-coordination");
|
||||
if (ac != nil) {
|
||||
logprint(LOG_ALERT, "WARNING: using deprecated property "~
|
||||
"/sim/auto-coordination. Please change to /controls/flight/auto-coordination");
|
||||
ac.alias(props.globals.getNode("/controls/flight/auto-coordination", 1));
|
||||
}
|
||||
var ac = props.globals.getNode("/sim/auto-coordination");
|
||||
if (ac != nil) {
|
||||
logprint(LOG_ALERT, "WARNING: using deprecated property "~
|
||||
"/sim/auto-coordination. Please change to /controls/flight/auto-coordination");
|
||||
ac.alias(props.globals.getNode("/controls/flight/auto-coordination", 1));
|
||||
}
|
||||
#### end of temporary hack for /sim/auto-coordination
|
||||
|
||||
if (!getprop("/sim/startup/restore-defaults")) {
|
||||
# load user-specific aircraft settings
|
||||
data.load();
|
||||
var n = props.globals.getNode("/sim/aircraft-data");
|
||||
if (n != nil) {
|
||||
foreach (var c; n.getChildren("path")) {
|
||||
if (c.getType() != "NONE")
|
||||
data.add(c.getValue());
|
||||
}
|
||||
if (!getprop("/sim/startup/restore-defaults")) {
|
||||
# load user-specific aircraft settings
|
||||
data.load();
|
||||
var n = props.globals.getNode("/sim/aircraft-data");
|
||||
if (n != nil) {
|
||||
foreach (var c; n.getChildren("path")) {
|
||||
if (c.getType() != "NONE")
|
||||
data.add(c.getValue());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,6 +80,4 @@ var convert_checklists = func {
|
|||
}
|
||||
}
|
||||
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
convert_checklists();
|
||||
});
|
||||
convert_checklists();
|
||||
|
|
|
@ -1,40 +1,30 @@
|
|||
#########
|
||||
# contrail calculator. Based on an approxmation to the "Appleman Chart"
|
||||
# y = -0.077x2 + 2.7188x - 64.36
|
||||
#
|
||||
########
|
||||
|
||||
updateContrail = func{
|
||||
var pressure_Node = props.globals.getNode("environment/pressure-inhg");
|
||||
var temperature_Node = props.globals.getNode("environment/temperature-degc");
|
||||
var contrail_Node = props.globals.getNode("environment/contrail");
|
||||
var contrail_temp_Node = props.globals.getNode("environment/contrail-temperature-degc");
|
||||
var pressure_Node = props.globals.initNode("environment/pressure-inhg", 1, "DOUBLE");
|
||||
var temperature_Node = props.globals.initNode("environment/temperature-degc", 1, "DOUBLE");
|
||||
var contrail_Node = props.globals.initNode("environment/contrail", 1, "BOOL");
|
||||
var contrail_temp_Node = props.globals.initNode("environment/contrail-temperature-degc", 1, "DOUBLE");
|
||||
var static_contrail_node = props.globals.getNode("sim/ai/aircraft/contrail", 1);
|
||||
var time_node = props.globals.getNode("sim/time/elapsed-sec", 1);
|
||||
|
||||
updateContrail = func {
|
||||
var x = pressure_Node.getValue();
|
||||
var y = temperature_Node.getValue();
|
||||
var con_temp = -0.077 * x * x + 2.7188 * x - 64.36;
|
||||
contrail_temp_Node.setValue(con_temp);
|
||||
|
||||
if (y < con_temp and y < -40){
|
||||
if (y < con_temp and y < -40) {
|
||||
contrail_Node.setValue(1);
|
||||
} else {
|
||||
contrail_Node.setValue(0);
|
||||
}
|
||||
}
|
||||
|
||||
### Contrail
|
||||
updateContrail(); # avoid 30 second delay on startup https://sourceforge.net/p/flightgear/codetickets/2077/
|
||||
|
||||
contrailTimer = maketimer(30, updateContrail);
|
||||
contrailTimer.simulatedTime = 1;
|
||||
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
logprint(LOG_INFO, "Init contrail");
|
||||
props.globals.initNode("environment/pressure-inhg", 1, "DOUBLE");
|
||||
props.globals.initNode("environment/temperature-degc", 1, "DOUBLE");
|
||||
props.globals.initNode("environment/contrail", 1, "BOOL");
|
||||
props.globals.initNode("environment/contrail-temperature-degc", 1, "DOUBLE");
|
||||
var static_contrail_node = props.globals.getNode("sim/ai/aircraft/contrail", 1);
|
||||
var time_node = props.globals.getNode("sim/time/elapsed-sec", 1);
|
||||
|
||||
updateContrail(); # avoid 30 second delay on startup https://sourceforge.net/p/flightgear/codetickets/2077/
|
||||
contrailTimer.restart(30);
|
||||
});
|
||||
contrailTimer.restart(30);
|
||||
|
|
|
@ -973,44 +973,43 @@ var dumpProbeStats = func () {
|
|||
return;
|
||||
}
|
||||
|
||||
#-- Init -----------------------------------------------------------------------
|
||||
# General purpose breakpoint for the lazy ones.
|
||||
var bp = Breakpoint.new("default", 0);
|
||||
|
||||
var dumpN = props.getNode("/_debug/nas/_dumpstats", 1);
|
||||
dumpN.setBoolValue(0);
|
||||
setlistener(dumpN, func(n) {
|
||||
n.setBoolValue(0);
|
||||
debug.dumpProbeStats();
|
||||
}, 0, 0);
|
||||
|
||||
# --prop:debug=1 enables debug mode with additional warnings
|
||||
#
|
||||
_setlistener("sim/signals/nasal-dir-initialized", func {
|
||||
# General purpose breakpoint for the lazy ones.
|
||||
debug.bp = debug.Breakpoint.new("default", 0);
|
||||
var dumpN = props.getNode("/_debug/nas/_dumpstats", 1);
|
||||
dumpN.setBoolValue(0);
|
||||
setlistener(dumpN, func(n) {
|
||||
n.setBoolValue(0);
|
||||
debug.dumpProbeStats();
|
||||
}, 0, 0);
|
||||
|
||||
if (!getprop("debug"))
|
||||
return;
|
||||
var writewarn = func(f, p, r) {
|
||||
if (!r) {
|
||||
var hint = "";
|
||||
if ((var n = props.globals.getNode(p)) != nil) {
|
||||
if (!n.getAttribute("writable"))
|
||||
hint = " (write protected)";
|
||||
elsif (n.getAttribute("tied"))
|
||||
hint = " (tied)";
|
||||
}
|
||||
warn("Warning: " ~ f ~ " -> writing to " ~ p ~ " failed" ~ hint, 2);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
setprop = (func { var _ = setprop; func writewarn("setprop",
|
||||
globals.string.join("", arg[:-2]), call(_, arg)) })();
|
||||
props.Node.setDoubleValue = func writewarn("setDoubleValue", me.getPath(),
|
||||
props._setDoubleValue(me._g, arg));
|
||||
props.Node.setBoolValue = func writewarn("setBoolValue", me.getPath(),
|
||||
props._setBoolValue(me._g, arg));
|
||||
props.Node.setIntValue = func writewarn("setIntValue", me.getPath(),
|
||||
props._setIntValue(me._g, arg));
|
||||
props.Node.setValue = func writewarn("setValue", me.getPath(),
|
||||
props._setValue(me._g, arg));
|
||||
});
|
||||
|
||||
if (getprop("debug")) {
|
||||
var writewarn = func(f, p, r) {
|
||||
if (!r) {
|
||||
var hint = "";
|
||||
if ((var n = props.globals.getNode(p)) != nil) {
|
||||
if (!n.getAttribute("writable"))
|
||||
hint = " (write protected)";
|
||||
elsif (n.getAttribute("tied"))
|
||||
hint = " (tied)";
|
||||
}
|
||||
warn("Warning: " ~ f ~ " -> writing to " ~ p ~ " failed" ~ hint, 2);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
setprop = (func { var _ = setprop; func writewarn("setprop",
|
||||
globals.string.join("", arg[:-2]), call(_, arg)) })();
|
||||
props.Node.setDoubleValue = func writewarn("setDoubleValue", me.getPath(),
|
||||
props._setDoubleValue(me._g, arg));
|
||||
props.Node.setBoolValue = func writewarn("setBoolValue", me.getPath(),
|
||||
props._setBoolValue(me._g, arg));
|
||||
props.Node.setIntValue = func writewarn("setIntValue", me.getPath(),
|
||||
props._setIntValue(me._g, arg));
|
||||
props.Node.setValue = func writewarn("setValue", me.getPath(),
|
||||
props._setValue(me._g, arg));
|
||||
}
|
||||
|
|
|
@ -374,67 +374,64 @@ var enabled = nil;
|
|||
var loop_id = 0;
|
||||
|
||||
|
||||
# Initialization.
|
||||
#
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
# disable menu entry and return for inappropriate FDMs (see Main/fg_init.cxx)
|
||||
var fdms = {
|
||||
acms:0, ada:0, balloon:0, external:0,
|
||||
jsb:1, larcsim:1, magic:0, network:0,
|
||||
null:0, pipe:0, ufo:0, yasim:1,
|
||||
};
|
||||
var fdm = getprop("/sim/flight-model");
|
||||
if (!contains(fdms, fdm) or !fdms[fdm])
|
||||
return;
|
||||
# disable menu entry and return for inappropriate FDMs (see Main/fg_init.cxx)
|
||||
var fdms = {
|
||||
acms:0, ada:0, balloon:0, external:0,
|
||||
jsb:1, larcsim:1, magic:0, network:0,
|
||||
null:0, pipe:0, ufo:0, yasim:1,
|
||||
};
|
||||
var fdm = getprop("/sim/flight-model");
|
||||
if (!contains(fdms, fdm) or !fdms[fdm])
|
||||
return;
|
||||
|
||||
enabled = props.globals.getNode("/sim").getChildren("view");
|
||||
forindex (var i; enabled)
|
||||
enabled[i] = ((var n = enabled[i].getNode("config/dynamic-view")) != nil) and n.getBoolValue();
|
||||
enabled = props.globals.getNode("/sim").getChildren("view");
|
||||
forindex (var i; enabled)
|
||||
enabled[i] = ((var n = enabled[i].getNode("config/dynamic-view")) != nil) and n.getBoolValue();
|
||||
|
||||
# some properties may still be unavailable or nil
|
||||
props.globals.initNode("/accelerations/pilot/x-accel-fps_sec", 0);
|
||||
props.globals.initNode("/accelerations/pilot/y-accel-fps_sec", 0);
|
||||
props.globals.initNode("/accelerations/pilot/z-accel-fps_sec", -32);
|
||||
props.globals.initNode("/orientation/side-slip-deg", 0);
|
||||
props.globals.initNode("/gear/gear/wow", 1, "BOOL");
|
||||
elapsedN = props.globals.getNode("/sim/time/elapsed-sec", 1);
|
||||
# some properties may still be unavailable or nil
|
||||
props.globals.initNode("/accelerations/pilot/x-accel-fps_sec", 0);
|
||||
props.globals.initNode("/accelerations/pilot/y-accel-fps_sec", 0);
|
||||
props.globals.initNode("/accelerations/pilot/z-accel-fps_sec", -32);
|
||||
props.globals.initNode("/orientation/side-slip-deg", 0);
|
||||
props.globals.initNode("/gear/gear/wow", 1, "BOOL");
|
||||
elapsedN = props.globals.getNode("/sim/time/elapsed-sec", 1);
|
||||
|
||||
# let listeners keep some variables up-to-date, so that they don't have
|
||||
# to be queried in the loop
|
||||
setlistener("/sim/panel/visibility", func(n) { panel_visible = n.getValue() }, 1);
|
||||
setlistener("/sim/current-view/view-number", func(n) { cockpit_view = enabled[n.getValue()] }, 1);
|
||||
setlistener("/devices/status/mice/mouse/button", func(n) { mouse_button = n.getValue() }, 1);
|
||||
setlistener("/devices/status/mice/mouse/x", freeze);
|
||||
setlistener("/devices/status/mice/mouse/y", freeze);
|
||||
setlistener("/devices/status/mice/mouse/mode", func(n) {
|
||||
if (mouse_mode = n.getValue())
|
||||
view_manager.unfreeze();
|
||||
}, 1);
|
||||
# let listeners keep some variables up-to-date, so that they do not have
|
||||
# to be queried in the loop
|
||||
setlistener("/sim/panel/visibility", func(n) { panel_visible = n.getValue() }, 1);
|
||||
setlistener("/sim/current-view/view-number", func(n) { cockpit_view = enabled[n.getValue()] }, 1);
|
||||
setlistener("/devices/status/mice/mouse/button", func(n) { mouse_button = n.getValue() }, 1);
|
||||
setlistener("/devices/status/mice/mouse/x", freeze);
|
||||
setlistener("/devices/status/mice/mouse/y", freeze);
|
||||
setlistener("/devices/status/mice/mouse/mode", func(n) {
|
||||
if (mouse_mode = n.getValue())
|
||||
view_manager.unfreeze();
|
||||
}, 1);
|
||||
|
||||
setlistener("/sim/signals/reinit", func(n) {
|
||||
n.getValue() and return;
|
||||
cockpit_view = enabled[getprop("/sim/current-view/view-number")];
|
||||
view_manager.reset();
|
||||
}, 0);
|
||||
setlistener("/sim/signals/reinit", func(n) {
|
||||
n.getValue() and return;
|
||||
cockpit_view = enabled[getprop("/sim/current-view/view-number")];
|
||||
view_manager.reset();
|
||||
}, 0);
|
||||
|
||||
view_manager.init();
|
||||
view_manager.init();
|
||||
|
||||
original_resetView = view.resetView;
|
||||
view.resetView = func {
|
||||
original_resetView();
|
||||
if (cockpit_view and dynamic_view)
|
||||
view_manager.add_offset();
|
||||
}
|
||||
original_resetView = view.resetView;
|
||||
view.resetView = func {
|
||||
original_resetView();
|
||||
if (cockpit_view and dynamic_view)
|
||||
view_manager.add_offset();
|
||||
}
|
||||
|
||||
settimer(func {
|
||||
setlistener("/sim/current-view/dynamic-view", func(n) {
|
||||
dynamic_view = n.getBoolValue();
|
||||
loop_id += 1;
|
||||
view.resetView();
|
||||
if (dynamic_view)
|
||||
main_loop(loop_id);
|
||||
}, 1);
|
||||
}, 0);
|
||||
|
||||
settimer(func {
|
||||
setlistener("/sim/current-view/dynamic-view", func(n) {
|
||||
dynamic_view = n.getBoolValue();
|
||||
loop_id += 1;
|
||||
view.resetView();
|
||||
if (dynamic_view)
|
||||
main_loop(loop_id);
|
||||
}, 1);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -64,13 +64,6 @@ var resetVisibility = func {
|
|||
visibilityOverrideProp.setBoolValue(0);
|
||||
}
|
||||
|
||||
|
||||
var visibilityProp = nil;
|
||||
var visibilityOverrideProp = nil;
|
||||
var auxvisibilityProp = nil;
|
||||
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
visibilityProp = props.globals.initNode("/environment/config/presets/visibility-m", 0, "DOUBLE" );
|
||||
visibilityOverrideProp = props.globals.initNode("/environment/config/presets/visibility-m-override", 0, "BOOL" );
|
||||
auxvisibilityProp = props.globals.initNode("/local-weather/config/aux-max-vis-range-m", 0, "DOUBLE" );
|
||||
});
|
||||
var visibilityProp = props.globals.initNode("/environment/config/presets/visibility-m", 0, "DOUBLE" );
|
||||
var visibilityOverrideProp = props.globals.initNode("/environment/config/presets/visibility-m-override", 0, "BOOL" );
|
||||
var auxvisibilityProp = props.globals.initNode("/local-weather/config/aux-max-vis-range-m", 0, "DOUBLE" );
|
||||
|
|
188
Nasal/gui.nas
188
Nasal/gui.nas
|
@ -128,94 +128,6 @@ var autopilotDisableProps = [
|
|||
"/autopilot/CENTURYIII/locks"
|
||||
];
|
||||
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
screenHProp = props.globals.getNode("/sim/startup/ysize");
|
||||
|
||||
props.globals.getNode("/sim/help/debug", 1).setValues(debug_keys);
|
||||
props.globals.getNode("/sim/help/basic", 1).setValues(basic_keys);
|
||||
props.globals.getNode("/sim/help/common", 1).setValues(common_aircraft_keys);
|
||||
|
||||
# enable/disable menu entries
|
||||
menuEnable("fuel-and-payload", fdm == "yasim" or fdm == "jsb");
|
||||
menuEnable("aircraft-checklists", props.globals.getNode("/sim/checklists") != nil);
|
||||
var isAutopilotMenuEnabled = func {
|
||||
foreach( var apdp; autopilotDisableProps ) {
|
||||
if( props.globals.getNode( apdp ) != nil )
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
menuEnable("autopilot", isAutopilotMenuEnabled() );
|
||||
menuEnable("joystick-info", size(props.globals.getNode("/input/joysticks", 1).getChildren("js")));
|
||||
menuEnable("rendering-buffers", getprop("/sim/rendering/rembrandt/enabled"));
|
||||
menuEnable("rembrandt-buffers-choice", getprop("/sim/rendering/rembrandt/enabled"));
|
||||
menuEnable("stereoscopic-options", !getprop("/sim/rendering/rembrandt/enabled"));
|
||||
menuEnable("sound-config", getprop("/sim/sound/working"));
|
||||
menuEnable("swift_connection", getprop("/sim/swift/available"));
|
||||
|
||||
# frame-per-second display
|
||||
var fps = props.globals.getNode("/sim/rendering/fps-display", 1);
|
||||
setlistener(fps, fpsDisplay, 1);
|
||||
setlistener("/sim/startup/xsize", func {
|
||||
if (fps.getValue()) {
|
||||
fpsDisplay(0);
|
||||
fpsDisplay(1);
|
||||
}
|
||||
});
|
||||
|
||||
# frame-latency display
|
||||
var latency = props.globals.getNode("/sim/rendering/frame-latency-display", 1);
|
||||
setlistener(latency, latencyDisplay, 1);
|
||||
setlistener("/sim/startup/xsize", func {
|
||||
if (latency.getValue()) {
|
||||
latencyDisplay(0);
|
||||
latencyDisplay(1);
|
||||
}
|
||||
});
|
||||
|
||||
# only enable precipitation if gui *and* aircraft want it
|
||||
var p = "/sim/rendering/precipitation-";
|
||||
var precip_gui = getprop(p ~ "gui-enable");
|
||||
var precip_ac = getprop(p ~ "aircraft-enable");
|
||||
props.globals.getNode(p ~ "enable", 1).setAttribute("userarchive", 0); # TODO remove later
|
||||
var set_precip = func setprop(p ~ "enable", precip_gui and precip_ac);
|
||||
setlistener(p ~ "gui-enable", func(n) set_precip(precip_gui = n.getValue()),1);
|
||||
setlistener(p ~ "aircraft-enable", func(n) set_precip(precip_ac = n.getValue()),1);
|
||||
|
||||
# the autovisibility feature of the menubar
|
||||
# automatically show the menubar if the mouse is at the upper edge of the window
|
||||
# the menubar is hidden by a binding to a LMB click in mode 0 in mice.xml
|
||||
var menubarAutoVisibilityListener = nil;
|
||||
var menubarAutoVisibilityEdge = props.globals.initNode( "/sim/menubar/autovisibility/edge-size", 5, "INT" );
|
||||
var menubarVisibility = props.globals.initNode( "/sim/menubar/visibility", 0, "BOOL" );
|
||||
var currentMenubarVisibility = menubarVisibility.getValue();
|
||||
var mouseMode = props.globals.initNode( "/devices/status/mice/mouse/mode", 0, "INT" );
|
||||
|
||||
setlistener( "/sim/menubar/autovisibility/enabled", func(n) {
|
||||
if( n.getValue() and menubarAutoVisibilityListener == nil ) {
|
||||
currentMenubarVisibility = menubarVisibility.getValue();
|
||||
menubarVisibility.setBoolValue( 0 );
|
||||
menubarAutoVisibilityListener = setlistener( "/devices/status/mice/mouse/y", func(n) {
|
||||
if( n.getValue() == nil ) return;
|
||||
if( mouseMode.getValue() != 0 ) return;
|
||||
|
||||
if( n.getValue() <= menubarAutoVisibilityEdge.getValue() )
|
||||
menubarVisibility.setBoolValue( 1 );
|
||||
|
||||
}, 1, 0 );
|
||||
}
|
||||
|
||||
# don't listen to the mouse position if this feature is enabled
|
||||
if( n.getValue() == 0 and menubarAutoVisibilityListener != nil ) {
|
||||
removelistener( menubarAutoVisibilityListener );
|
||||
menubarAutoVisibilityListener = nil;
|
||||
menubarVisibility.setBoolValue(currentMenubarVisibility);
|
||||
}
|
||||
}, 1, 0);
|
||||
|
||||
});
|
||||
|
||||
|
||||
##
|
||||
# Show/hide the fps display dialog.
|
||||
#
|
||||
|
@ -303,6 +215,7 @@ var Widget = {
|
|||
# livery_dialog.toggle();
|
||||
#
|
||||
var Dialog = {
|
||||
instance: {},
|
||||
new: func(prop, path = nil, name = nil) {
|
||||
var m = { parents: [Dialog] };
|
||||
m.state = 0;
|
||||
|
@ -321,8 +234,7 @@ var Dialog = {
|
|||
}
|
||||
return Dialog.instance[m.name] = m;
|
||||
},
|
||||
del: func
|
||||
{
|
||||
del: func {
|
||||
if (me.listener != nil)
|
||||
removelistener(me.listener);
|
||||
},
|
||||
|
@ -368,7 +280,6 @@ var Dialog = {
|
|||
is_open: func {
|
||||
me.state;
|
||||
},
|
||||
instance: {},
|
||||
};
|
||||
|
||||
|
||||
|
@ -1424,7 +1335,7 @@ var common_aircraft_keys = {
|
|||
],
|
||||
};
|
||||
|
||||
_setlistener("/sim/signals/screenshot", func {
|
||||
setlistener("/sim/signals/screenshot", func {
|
||||
var path = getprop("/sim/paths/screenshot-last");
|
||||
var button = { button: { legend: "Ok", default: 1, binding: { command: "dialog-close" }}};
|
||||
var success= getprop("/sim/signals/screenshot");
|
||||
|
@ -1436,7 +1347,7 @@ _setlistener("/sim/signals/screenshot", func {
|
|||
});
|
||||
|
||||
var terrasync_stalled = 0;
|
||||
_setlistener("/sim/terrasync/stalled", func {
|
||||
setlistener("/sim/terrasync/stalled", func {
|
||||
var stalled = getprop("/sim/terrasync/stalled");
|
||||
if (stalled and !terrasync_stalled)
|
||||
{
|
||||
|
@ -1447,7 +1358,7 @@ _setlistener("/sim/terrasync/stalled", func {
|
|||
});
|
||||
|
||||
var do_welcome = 1;
|
||||
_setlistener("/sim/signals/fdm-initialized", func {
|
||||
setlistener("/sim/signals/fdm-initialized", func {
|
||||
var haveTutorials = size(props.globals.getNode("/sim/tutorials", 1).getChildren("tutorial"));
|
||||
gui.menuEnable("tutorial-start", haveTutorials);
|
||||
if (do_welcome and haveTutorials)
|
||||
|
@ -1497,6 +1408,91 @@ var update_shader_settings = func() {
|
|||
setprop("/sim/rendering/shaders/skydome",0);
|
||||
}
|
||||
};
|
||||
_setlistener("/sim/rendering/shaders/custom-settings", func { update_shader_settings() } );
|
||||
_setlistener("/sim/rendering/shaders/quality-level-internal", func { update_shader_settings() } );
|
||||
|
||||
setlistener("/sim/rendering/shaders/custom-settings", func { update_shader_settings() } );
|
||||
setlistener("/sim/rendering/shaders/quality-level-internal", func { update_shader_settings() } );
|
||||
update_shader_settings();
|
||||
|
||||
screenHProp = props.globals.getNode("/sim/startup/ysize");
|
||||
|
||||
props.globals.getNode("/sim/help/debug", 1).setValues(debug_keys);
|
||||
props.globals.getNode("/sim/help/basic", 1).setValues(basic_keys);
|
||||
props.globals.getNode("/sim/help/common", 1).setValues(common_aircraft_keys);
|
||||
|
||||
# enable/disable menu entries
|
||||
menuEnable("fuel-and-payload", fdm == "yasim" or fdm == "jsb");
|
||||
menuEnable("aircraft-checklists", props.globals.getNode("/sim/checklists") != nil);
|
||||
var isAutopilotMenuEnabled = func {
|
||||
foreach( var apdp; autopilotDisableProps ) {
|
||||
if( props.globals.getNode( apdp ) != nil )
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
menuEnable("autopilot", isAutopilotMenuEnabled() );
|
||||
menuEnable("joystick-info", size(props.globals.getNode("/input/joysticks", 1).getChildren("js")));
|
||||
menuEnable("rendering-buffers", getprop("/sim/rendering/rembrandt/enabled"));
|
||||
menuEnable("rembrandt-buffers-choice", getprop("/sim/rendering/rembrandt/enabled"));
|
||||
menuEnable("stereoscopic-options", !getprop("/sim/rendering/rembrandt/enabled"));
|
||||
menuEnable("sound-config", getprop("/sim/sound/working"));
|
||||
menuEnable("swift_connection", getprop("/sim/swift/available"));
|
||||
|
||||
# frame-per-second display
|
||||
var fps = props.globals.getNode("/sim/rendering/fps-display", 1);
|
||||
setlistener(fps, fpsDisplay, 1);
|
||||
setlistener("/sim/startup/xsize", func {
|
||||
if (fps.getValue()) {
|
||||
fpsDisplay(0);
|
||||
fpsDisplay(1);
|
||||
}
|
||||
});
|
||||
|
||||
# frame-latency display
|
||||
var latency = props.globals.getNode("/sim/rendering/frame-latency-display", 1);
|
||||
setlistener(latency, latencyDisplay, 1);
|
||||
setlistener("/sim/startup/xsize", func {
|
||||
if (latency.getValue()) {
|
||||
latencyDisplay(0);
|
||||
latencyDisplay(1);
|
||||
}
|
||||
});
|
||||
|
||||
# only enable precipitation if gui *and* aircraft want it
|
||||
var p = "/sim/rendering/precipitation-";
|
||||
var precip_gui = getprop(p ~ "gui-enable");
|
||||
var precip_ac = getprop(p ~ "aircraft-enable");
|
||||
props.globals.getNode(p ~ "enable", 1).setAttribute("userarchive", 0); # TODO remove later
|
||||
var set_precip = func setprop(p ~ "enable", precip_gui and precip_ac);
|
||||
setlistener(p ~ "gui-enable", func(n) set_precip(precip_gui = n.getValue()),1);
|
||||
setlistener(p ~ "aircraft-enable", func(n) set_precip(precip_ac = n.getValue()),1);
|
||||
|
||||
# the autovisibility feature of the menubar
|
||||
# automatically show the menubar if the mouse is at the upper edge of the window
|
||||
# the menubar is hidden by a binding to a LMB click in mode 0 in mice.xml
|
||||
var menubarAutoVisibilityListener = nil;
|
||||
var menubarAutoVisibilityEdge = props.globals.initNode( "/sim/menubar/autovisibility/edge-size", 5, "INT" );
|
||||
var menubarVisibility = props.globals.initNode( "/sim/menubar/visibility", 0, "BOOL" );
|
||||
var currentMenubarVisibility = menubarVisibility.getValue();
|
||||
var mouseMode = props.globals.initNode( "/devices/status/mice/mouse/mode", 0, "INT" );
|
||||
|
||||
setlistener( "/sim/menubar/autovisibility/enabled", func(n) {
|
||||
if( n.getValue() and menubarAutoVisibilityListener == nil ) {
|
||||
currentMenubarVisibility = menubarVisibility.getValue();
|
||||
menubarVisibility.setBoolValue( 0 );
|
||||
menubarAutoVisibilityListener = setlistener( "/devices/status/mice/mouse/y", func(n) {
|
||||
if( n.getValue() == nil ) return;
|
||||
if( mouseMode.getValue() != 0 ) return;
|
||||
|
||||
if( n.getValue() <= menubarAutoVisibilityEdge.getValue() )
|
||||
menubarVisibility.setBoolValue( 1 );
|
||||
|
||||
}, 1, 0 );
|
||||
}
|
||||
|
||||
# do not listen to the mouse position if this feature is enabled
|
||||
if( n.getValue() == 0 and menubarAutoVisibilityListener != nil ) {
|
||||
removelistener( menubarAutoVisibilityListener );
|
||||
menubarAutoVisibilityListener = nil;
|
||||
menubarVisibility.setBoolValue(currentMenubarVisibility);
|
||||
}
|
||||
}, 1, 0);
|
||||
|
|
|
@ -90,5 +90,4 @@ var masterSwitch = func() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", mpStart);
|
||||
mpStart();
|
||||
|
|
|
@ -4,11 +4,53 @@
|
|||
The files listed below will be loaded in order before any other files in the
|
||||
Nasal directory. This is to avoid dependency problems that would otherwise
|
||||
occur if aaaa.nas relied on props.nas
|
||||
|
||||
<file> tag must include ONLY a filename.nas nothing else.
|
||||
Comments must be placed outside the <file></file>
|
||||
================================================================================
|
||||
Short overview over the files and prominent functions they provide:
|
||||
|
||||
props.nas
|
||||
props.Node class for easy access to the property tree
|
||||
|
||||
globals.nas
|
||||
cmdarg, fgcommand, isa, setlistener,
|
||||
several constants
|
||||
deferred loading of user nas files from $FGHOME/Nasal
|
||||
|
||||
io.nas (uses string.nas)
|
||||
include, load_nasal, read_properties, write_properties,
|
||||
readxml, writexml
|
||||
|
||||
debug.nas (uses io.nas)
|
||||
benchmark, backtrace, dump,
|
||||
classes Breakpoint, Probe, Tracer
|
||||
|
||||
Dependencies:
|
||||
|
||||
modules.nas <- addons.nas
|
||||
string.nas <- io.nas
|
||||
string.nas <- gui.nas
|
||||
io.nas <- gui.nas
|
||||
gui.nas <- multiplayer.nas
|
||||
multiplayer.nas <- view.nas
|
||||
geo.nas <- view.nas
|
||||
view.nas <- dynamic_view.nas
|
||||
-->
|
||||
|
||||
<PropertyList>
|
||||
<file n="0">props.nas</file>
|
||||
<file n="1">globals.nas</file>
|
||||
<file n="2">math.nas</file>
|
||||
<file n="3">string.nas</file>
|
||||
<file n="3">io.nas</file>
|
||||
<!-- stage 0 -->
|
||||
<file>props.nas</file>
|
||||
<file>globals.nas</file>
|
||||
<file>math.nas</file>
|
||||
<file>string.nas</file>
|
||||
<file>io.nas</file>
|
||||
<file>debug.nas</file>
|
||||
<!-- stage 1 -->
|
||||
<file>modules.nas</file>
|
||||
<file>mp_broadcast.nas</file>
|
||||
<file>gui.nas</file>
|
||||
<file>multiplayer.nas</file>
|
||||
<file>geo.nas</file>
|
||||
<file>view.nas</file>
|
||||
</PropertyList>
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
# my_foo_sys.load();
|
||||
#-------------------------------------------------------------------------------
|
||||
var MODULES_DIR = getprop("/sim/fg-root")~"/Nasal/modules/";
|
||||
var MODULES_NODE = nil;
|
||||
var MODULES_NODE = props.getNode("/nasal/modules", 1);
|
||||
var MODULES_DEFAULT_FILENAME = "main.nas";
|
||||
var _modules_available = {};
|
||||
|
||||
|
@ -330,22 +330,16 @@ var load = func(name, ns="") {
|
|||
|
||||
# scan MODULES_DIR for subdirectories; it is assumed, that only well-formed
|
||||
# modules are stored in that directories, so no further checks right here
|
||||
var _findModules = func() {
|
||||
var module_dirs = io.subdirectories(MODULES_DIR);
|
||||
#var _findModules = func() {
|
||||
_modules_available = {};
|
||||
foreach (var name; module_dirs) {
|
||||
foreach (var name; io.subdirectories(MODULES_DIR)) {
|
||||
if (!io.is_regular_file(MODULES_DIR~"/"~name~"/"~MODULES_DEFAULT_FILENAME))
|
||||
break;
|
||||
_modules_available[name] = 1;
|
||||
MODULES_NODE.getNode(name~"/available",1).setBoolValue(1);
|
||||
}
|
||||
}
|
||||
|
||||
#props.getNode is available only after nasal dir has been initialized
|
||||
_setlistener("sim/signals/nasal-dir-initialized", func {
|
||||
MODULES_NODE = props.getNode("/nasal/modules", 1);
|
||||
_findModules();
|
||||
});
|
||||
#}
|
||||
#_findModules();
|
||||
|
||||
var commandModuleReload = func(node)
|
||||
{
|
||||
|
@ -359,4 +353,5 @@ var commandModuleReload = func(node)
|
|||
m.reload();
|
||||
};
|
||||
|
||||
addcommand("nasal-module-reload", commandModuleReload);
|
||||
addcommand("nasal-module-reload", commandModuleReload);
|
||||
|
||||
|
|
|
@ -266,8 +266,4 @@ var init = func {
|
|||
|
||||
data = { format: "", node: tree, children: scan(tree) };
|
||||
}
|
||||
|
||||
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", init);
|
||||
|
||||
|
||||
init();
|
|
@ -663,19 +663,13 @@ var mp_mode_changed = func(n) {
|
|||
}
|
||||
}
|
||||
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
model.init();
|
||||
setlistener("/sim/multiplay/online", mp_mode_changed, 1, 1);
|
||||
# Call-back to ensure we see our own messages.
|
||||
setlistener("/sim/multiplay/chat", chat_listener);
|
||||
|
||||
model.init();
|
||||
|
||||
setlistener("/sim/multiplay/online", mp_mode_changed, 1, 1);
|
||||
|
||||
# Call-back to ensure we see our own messages.
|
||||
setlistener("/sim/multiplay/chat", chat_listener);
|
||||
|
||||
|
||||
if (getprop("/sim/presets/avoided-mp-runway")) {
|
||||
_setlistener("/sim/sceneryloaded", func {
|
||||
if (getprop("/sim/presets/avoided-mp-runway")) {
|
||||
setlistener("/sim/sceneryloaded", func {
|
||||
gui.popupTip("Multi-player enabled, start moved to runway hold short position.");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -76,15 +76,13 @@ var _set_state = func {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
_setlistener("sim/signals/nasal-dir-initialized", func {
|
||||
events = mp_broadcast.EventChannel.new("scenery/events");
|
||||
if (getprop(shared_pp)) {
|
||||
#print("scenery.nas: starting event sharing.");
|
||||
events.start();
|
||||
} else {
|
||||
#print("scenery.nas: stopping event sharing.");
|
||||
events.stop();
|
||||
}
|
||||
setlistener(shared_pp, _set_state);
|
||||
});
|
||||
#-- Init -----------------------------------------------------------------------
|
||||
events = mp_broadcast.EventChannel.new("scenery/events");
|
||||
if (getprop(shared_pp)) {
|
||||
#print("scenery.nas: starting event sharing.");
|
||||
events.start();
|
||||
} else {
|
||||
#print("scenery.nas: stopping event sharing.");
|
||||
events.stop();
|
||||
}
|
||||
setlistener(shared_pp, _set_state);
|
||||
|
|
109
Nasal/screen.nas
109
Nasal/screen.nas
|
@ -403,63 +403,6 @@ var controls = nil;
|
|||
# Shift-Alt-click adds all children of the selected property to the property display
|
||||
# Shift-Ctrl-click removes all properties from the display
|
||||
#
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
property_display = display.new(5, -25);
|
||||
listener.display = setlistener("/sim/gui/dialogs/property-browser/selected", func(n) {
|
||||
var n = n.getValue();
|
||||
if (n != "" and getprop("/devices/status/keyboard/shift")) {
|
||||
if (getprop("/devices/status/keyboard/ctrl"))
|
||||
return property_display.reset();
|
||||
n = props.globals.getNode(n);
|
||||
if (!n.getAttribute("children"))
|
||||
property_display.add(n);
|
||||
elsif (getprop("/devices/status/keyboard/alt"))
|
||||
property_display.add(n.getChildren());
|
||||
}
|
||||
});
|
||||
|
||||
setlistener("/sim/gui/current-style", func {
|
||||
theme_font = getprop("/sim/gui/selected-style/fonts/message-display/name");
|
||||
}, 1);
|
||||
|
||||
log = window.new(nil, -30, 10, 10);
|
||||
log.sticky = 0; # don't turn on; makes scrolling up messages jump left and right
|
||||
|
||||
var b = "/sim/screen/";
|
||||
setlistener(b ~ "black", func(n) log.write(n.getValue(), 0, 0, 0));
|
||||
setlistener(b ~ "white", func(n) log.write(n.getValue(), 1, 1, 1));
|
||||
setlistener(b ~ "red", func(n) log.write(n.getValue(), 0.8, 0, 0));
|
||||
setlistener(b ~ "green", func(n) log.write(n.getValue(), 0, 0.6, 0));
|
||||
setlistener(b ~ "blue", func(n) log.write(n.getValue(), 0, 0, 0.8));
|
||||
setlistener(b ~ "yellow", func(n) log.write(n.getValue(), 0.8, 0.8, 0));
|
||||
setlistener(b ~ "magenta", func(n) log.write(n.getValue(), 0.7, 0, 0.7));
|
||||
setlistener(b ~ "cyan", func(n) log.write(n.getValue(), 0, 0.6, 0.6));
|
||||
});
|
||||
|
||||
|
||||
|
||||
# --prop:display=sim/frame-rate ... adds this property to the property display
|
||||
# --prop:display=position/ ... adds all properties under /position/ (ends with slash!)
|
||||
# --prop:display=position/,orientation/ ... separate multiple properties with comma
|
||||
#
|
||||
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))
|
||||
continue;
|
||||
if (find('%', p) >= 0)
|
||||
property_display.format = p;
|
||||
elsif (p[-1] == `/`)
|
||||
property_display.add(props.globals.getNode(p, 1).getChildren());
|
||||
else
|
||||
property_display.add(p);
|
||||
}
|
||||
}
|
||||
props.globals.removeChildren("display");
|
||||
});
|
||||
|
||||
|
||||
|
||||
var search_name_in_msg = func(msg, call) {
|
||||
var matching = 0;
|
||||
|
@ -607,3 +550,55 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
|
|||
});
|
||||
|
||||
|
||||
#-- Init -----------------------------------------------------------------------
|
||||
property_display = display.new(5, -25);
|
||||
listener.display = setlistener("/sim/gui/dialogs/property-browser/selected", func(n) {
|
||||
var n = n.getValue();
|
||||
if (n != "" and getprop("/devices/status/keyboard/shift")) {
|
||||
if (getprop("/devices/status/keyboard/ctrl"))
|
||||
return property_display.reset();
|
||||
n = props.globals.getNode(n);
|
||||
if (!n.getAttribute("children"))
|
||||
property_display.add(n);
|
||||
elsif (getprop("/devices/status/keyboard/alt"))
|
||||
property_display.add(n.getChildren());
|
||||
}
|
||||
});
|
||||
|
||||
setlistener("/sim/gui/current-style", func {
|
||||
theme_font = getprop("/sim/gui/selected-style/fonts/message-display/name");
|
||||
}, 1);
|
||||
|
||||
log = window.new(nil, -30, 10, 10);
|
||||
log.sticky = 0; # do not turn on; makes scrolling up messages jump left and right
|
||||
|
||||
var b = "/sim/screen/";
|
||||
setlistener(b ~ "black", func(n) log.write(n.getValue(), 0, 0, 0));
|
||||
setlistener(b ~ "white", func(n) log.write(n.getValue(), 1, 1, 1));
|
||||
setlistener(b ~ "red", func(n) log.write(n.getValue(), 0.8, 0, 0));
|
||||
setlistener(b ~ "green", func(n) log.write(n.getValue(), 0, 0.6, 0));
|
||||
setlistener(b ~ "blue", func(n) log.write(n.getValue(), 0, 0, 0.8));
|
||||
setlistener(b ~ "yellow", func(n) log.write(n.getValue(), 0.8, 0.8, 0));
|
||||
setlistener(b ~ "magenta", func(n) log.write(n.getValue(), 0.7, 0, 0.7));
|
||||
setlistener(b ~ "cyan", func(n) log.write(n.getValue(), 0, 0.6, 0.6));
|
||||
|
||||
# --prop:display=sim/frame-rate ... adds this property to the property display
|
||||
# --prop:display=position/ ... adds all properties under /position/ (ends with slash!)
|
||||
# --prop:display=position/,orientation/ ... separate multiple properties with comma
|
||||
#
|
||||
var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized", func {
|
||||
removelistener(fdm_init_listener); # uninstall, so we are only called once
|
||||
foreach (var n; props.globals.getChildren("display")) {
|
||||
foreach (var p; split(",", n.getValue())) {
|
||||
if (!size(p))
|
||||
continue;
|
||||
if (find('%', p) >= 0)
|
||||
property_display.format = p;
|
||||
elsif (p[-1] == `/`)
|
||||
property_display.add(props.globals.getNode(p, 1).getChildren());
|
||||
else
|
||||
property_display.add(p);
|
||||
}
|
||||
}
|
||||
props.globals.removeChildren("display");
|
||||
});
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
setlistener("/sim/presets/latitude-deg", func {
|
||||
logprint(LOG_INFO, "*** NEW LOCATION ***");
|
||||
settimer(func {
|
||||
var typ = getprop("/sim/type");
|
||||
var lat = getprop("/position/latitude-deg");
|
||||
var lon = getprop("/position/longitude-deg");
|
||||
var g = geodinfo(lat, lon);
|
||||
if ((g != nil and g[1] != nil and g[1].solid) and (typ == "seaplane") )
|
||||
fgcommand("dialog-show", props.Node.new({ "dialog-name": "seaport" }));
|
||||
}, 8);
|
||||
}, 1);
|
||||
});
|
||||
setlistener("/sim/presets/latitude-deg", func {
|
||||
logprint(LOG_INFO, "*** NEW LOCATION ***");
|
||||
settimer(func {
|
||||
var typ = getprop("/sim/type");
|
||||
var lat = getprop("/position/latitude-deg");
|
||||
var lon = getprop("/position/longitude-deg");
|
||||
var g = geodinfo(lat, lon);
|
||||
if ((g != nil and g[1] != nil and g[1].solid) and (typ == "seaplane") )
|
||||
fgcommand("dialog-show", props.Node.new({ "dialog-name": "seaport" }));
|
||||
}, 8);
|
||||
}, 1);
|
||||
|
|
|
@ -495,8 +495,4 @@ var color = func(color, s, enabled=nil) {
|
|||
# print(string.color("31;1", "this is red"));
|
||||
#
|
||||
var color_enabled = 0;
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
setlistener("/sim/startup/terminal-ansi-colors", func(n) setcolors(n.getBoolValue()), 1, 0);
|
||||
});
|
||||
|
||||
|
||||
setlistener("/sim/startup/terminal-ansi-colors", func(n) setcolors(n.getBoolValue()), 1, 0);
|
||||
|
|
|
@ -447,14 +447,12 @@ var reinit = func {
|
|||
}
|
||||
|
||||
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
var aar_capable = size(props.globals.getNode("systems/refuel", 1).getChildren("type"));
|
||||
gui.menuEnable("tanker", aar_capable);
|
||||
if (!aar_capable)
|
||||
request = func { atc_msg("no tanker in range") }; # braces mandatory
|
||||
var aar_capable = size(props.globals.getNode("systems/refuel", 1).getChildren("type"));
|
||||
gui.menuEnable("tanker", aar_capable);
|
||||
if (!aar_capable)
|
||||
request = func { atc_msg("no tanker in range") }; # braces mandatory
|
||||
|
||||
setlistener("/sim/signals/reinit", reinit, 1);
|
||||
});
|
||||
setlistener("/sim/signals/reinit", reinit, 1);
|
||||
|
||||
if (globals["tanker"] != nil) {
|
||||
# reload with io.load_nasal(getprop("/sim/fg-root") ~ "/Nasal/tanker.nas");
|
||||
|
|
|
@ -934,32 +934,31 @@ var screenWidthCompens = {
|
|||
};
|
||||
|
||||
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
views = props.globals.getNode("/sim", 1).getChildren("view");
|
||||
fovProp = props.globals.getNode("/sim/current-view/field-of-view", 1);
|
||||
point.init();
|
||||
views = props.globals.getNode("/sim", 1).getChildren("view");
|
||||
fovProp = props.globals.getNode("/sim/current-view/field-of-view", 1);
|
||||
point.init();
|
||||
|
||||
setlistener("/sim/current-view/view-number", func(n) {
|
||||
current = views[index = n.getValue()];
|
||||
}, 1);
|
||||
setlistener("/sim/current-view/view-number", func(n) {
|
||||
current = views[index = n.getValue()];
|
||||
}, 1);
|
||||
|
||||
props.globals.initNode("/position/altitude-agl-ft"); # needed by Fly-By View
|
||||
screenWidthCompens.init();
|
||||
manager.init();
|
||||
manager.register("Fly-By View", fly_by_view_handler);
|
||||
});
|
||||
_setlistener("/sim/signals/reinit", func {
|
||||
props.globals.initNode("/position/altitude-agl-ft"); # needed by Fly-By View
|
||||
screenWidthCompens.init();
|
||||
manager.init();
|
||||
manager.register("Fly-By View", fly_by_view_handler);
|
||||
|
||||
setlistener("/sim/signals/reinit", func {
|
||||
screenWidthCompens.update(opt:nil,force:1);
|
||||
});
|
||||
_setlistener("/sim/startup/xsize", func {
|
||||
setlistener("/sim/startup/xsize", func {
|
||||
screenWidthCompens.update();
|
||||
});
|
||||
_setlistener("/sim/startup/ysize", func {
|
||||
setlistener("/sim/startup/ysize", func {
|
||||
screenWidthCompens.update();
|
||||
});
|
||||
|
||||
|
||||
var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized", func {
|
||||
var fdm_init_listener = setlistener("/sim/signals/fdm-initialized", func {
|
||||
removelistener(fdm_init_listener); # uninstall, so we are only called once
|
||||
var zoffset = nil;
|
||||
foreach (var v; views) {
|
||||
|
|
|
@ -31,33 +31,30 @@ var initialize_weather_scenario = func {
|
|||
}
|
||||
};
|
||||
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
|
||||
initialize_weather_scenario();
|
||||
initialize_weather_scenario();
|
||||
|
||||
setlistener("/environment/weather-scenario", func(n) {
|
||||
var scenario = find_weather_scenario( n.getValue() );
|
||||
if( scenario == nil ) return;
|
||||
var scenarioName = scenario.getNode("name",1).getValue();
|
||||
if( scenarioName == "Disabled" ) {
|
||||
setprop( "/environment/params/metar-updates-environment", 0 );
|
||||
setprop( "/environment/realwx/enabled", 0 );
|
||||
setprop( "/environment/config/enabled", 0 );
|
||||
} else if( scenarioName == "Live data" ) {
|
||||
setprop( "/environment/params/metar-updates-environment", 1 );
|
||||
setprop( "/environment/realwx/enabled", 1 );
|
||||
setprop( "/environment/config/enabled", 1 );
|
||||
} else if( scenarioName == "Manual input" ) {
|
||||
setprop( "/environment/params/metar-updates-environment", 1 );
|
||||
setprop( "/environment/realwx/enabled", 0 );
|
||||
setprop( "/environment/config/enabled", 1 );
|
||||
} else {
|
||||
setprop( "/environment/params/metar-updates-environment", 1 );
|
||||
setprop( "/environment/realwx/enabled", 0 );
|
||||
setprop( "/environment/config/enabled", 1 );
|
||||
var metar = scenario.getNode("metar",1).getValue();
|
||||
setprop( "environment/metar/data", metar );
|
||||
}
|
||||
});
|
||||
setlistener("/environment/weather-scenario", func(n) {
|
||||
var scenario = find_weather_scenario( n.getValue() );
|
||||
if( scenario == nil ) return;
|
||||
var scenarioName = scenario.getNode("name",1).getValue();
|
||||
if( scenarioName == "Disabled" ) {
|
||||
setprop( "/environment/params/metar-updates-environment", 0 );
|
||||
setprop( "/environment/realwx/enabled", 0 );
|
||||
setprop( "/environment/config/enabled", 0 );
|
||||
} else if( scenarioName == "Live data" ) {
|
||||
setprop( "/environment/params/metar-updates-environment", 1 );
|
||||
setprop( "/environment/realwx/enabled", 1 );
|
||||
setprop( "/environment/config/enabled", 1 );
|
||||
} else if( scenarioName == "Manual input" ) {
|
||||
setprop( "/environment/params/metar-updates-environment", 1 );
|
||||
setprop( "/environment/realwx/enabled", 0 );
|
||||
setprop( "/environment/config/enabled", 1 );
|
||||
} else {
|
||||
setprop( "/environment/params/metar-updates-environment", 1 );
|
||||
setprop( "/environment/realwx/enabled", 0 );
|
||||
setprop( "/environment/config/enabled", 1 );
|
||||
var metar = scenario.getNode("metar",1).getValue();
|
||||
setprop( "environment/metar/data", metar );
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -935,104 +935,6 @@ wildfire_score_report_loop_timer.simulatedTime = 1;
|
|||
wildfire_score_CAFire_loop_timer = maketimer(CAFire.GENERATION_DURATION, CAFire, CAFire._loop_ );
|
||||
wildfire_score_CAFire_loop_timer.simulatedTime = 1;
|
||||
|
||||
###############################################################################
|
||||
# Main initialization.
|
||||
var Binary = nil;
|
||||
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
|
||||
Binary = mp_broadcast.Binary;
|
||||
|
||||
# Create configuration properties if they do not exist already.
|
||||
props.globals.initNode(CA_enabled_pp, 1, "BOOL");
|
||||
setlistener(CA_enabled_pp, func (n) {
|
||||
if (getprop("/sim/signals/reinit")) return; # Ignore resets.
|
||||
CAFire.reset(n.getValue(), SimTime.current_time());
|
||||
});
|
||||
props.globals.initNode(MP_share_pp, 1, "BOOL");
|
||||
props.globals.initNode(crash_fire_pp, 1, "BOOL");
|
||||
props.globals.initNode(impact_fire_pp, 1, "BOOL");
|
||||
props.globals.initNode(save_on_exit_pp, 0, "BOOL");
|
||||
props.globals.initNode(restore_on_startup_pp, 0, "BOOL");
|
||||
props.globals.initNode(models_enabled_pp, 1, "BOOL");
|
||||
props.globals.initNode(report_score_pp, 1, "BOOL");
|
||||
props.globals.initNode(event_file_pp, "", "STRING");
|
||||
props.globals.initNode(time_hack_pp, "", "STRING");
|
||||
|
||||
props.globals.initNode(fire_LOD_pp, 10, "INT");
|
||||
props.globals.initNode(smoke_LOD_pp, 10, "INT");
|
||||
|
||||
SimTime.init();
|
||||
broadcast =
|
||||
mp_broadcast.BroadcastChannel.new(msg_channel_mpp, parse_msg);
|
||||
CAFire.init();
|
||||
|
||||
# Start the score reporting.
|
||||
wildfire_score_report_loop_timer.restart(CAFire.GENERATION_DURATION);
|
||||
|
||||
setlistener("/sim/signals/exit", func {
|
||||
if (getprop(report_score_pp) and (CAFire.cells_created > 0))
|
||||
print_score();
|
||||
if (getprop(save_on_exit_pp))
|
||||
CAFire.save_event_log(SAVEDIR ~ "fire_log.xml");
|
||||
});
|
||||
|
||||
# Determine the skip-ahead-to time, if any.
|
||||
var time_hack = time_string_to_epoch(getprop(time_hack_pp));
|
||||
if (time_hack > SimTime.current_time()) {
|
||||
logprint(LOG_ALERT,
|
||||
"wildfire.nas: Ignored time hack " ~
|
||||
(SimTime.current_time() - time_hack) ~
|
||||
" seconds into the future.");
|
||||
# Skip ahead to current time instead.
|
||||
time_hack = -1;
|
||||
} elsif (time_hack > 0) {
|
||||
logprint(LOG_ALERT,
|
||||
"wildfire.nas: Time hack " ~
|
||||
(SimTime.current_time() - time_hack) ~
|
||||
" seconds ago.");
|
||||
} else {
|
||||
# Skip ahead to current time instead.
|
||||
time_hack = -1;
|
||||
}
|
||||
|
||||
if (getprop(event_file_pp) != "") {
|
||||
settimer(func {
|
||||
# Delay loading the log until the terrain is there. Note: hack.
|
||||
CAFire.load_event_log(getprop(event_file_pp), time_hack);
|
||||
}, 3);
|
||||
} elsif (getprop(restore_on_startup_pp)) {
|
||||
settimer(func {
|
||||
# Delay loading the log until the terrain is there. Note: hack.
|
||||
# Restore skips ahead to current time.
|
||||
CAFire.load_event_log(SAVEDIR ~ "fire_log.xml", -1);
|
||||
}, 3);
|
||||
}
|
||||
|
||||
# Detect aircraft crash.
|
||||
setlistener("sim/crashed", func(n) {
|
||||
if (getprop(crash_fire_pp) and n.getBoolValue())
|
||||
wildfire.ignite(geo.aircraft_position());
|
||||
});
|
||||
|
||||
# Detect impact.
|
||||
var impact_node = props.globals.getNode("sim/ai/aircraft/impact/bomb", 1);
|
||||
setlistener("sim/ai/aircraft/impact/bomb", func(n) {
|
||||
|
||||
if (getprop(impact_fire_pp) and n.getBoolValue()){
|
||||
var node = props.globals.getNode(n.getValue(), 1);
|
||||
var impactpos = geo.Coord.new();
|
||||
impactpos.set_latlon
|
||||
(node.getNode("impact/latitude-deg").getValue(),
|
||||
node.getNode("impact/longitude-deg").getValue());
|
||||
wildfire.ignite(impactpos);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
logprint(LOG_INFO, "Wildfire ... initialized.");
|
||||
});
|
||||
###############################################################################
|
||||
|
||||
###############################################################################
|
||||
# Utility functions
|
||||
|
@ -1192,5 +1094,97 @@ var dialog = {
|
|||
"fire_log.xml"); # default file name
|
||||
selector.open();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
# Main initialization.
|
||||
var Binary = mp_broadcast.Binary;
|
||||
|
||||
# Create configuration properties if they do not exist already.
|
||||
props.globals.initNode(CA_enabled_pp, 1, "BOOL");
|
||||
setlistener(CA_enabled_pp, func (n) {
|
||||
if (getprop("/sim/signals/reinit")) return; # Ignore resets.
|
||||
CAFire.reset(n.getValue(), SimTime.current_time());
|
||||
});
|
||||
props.globals.initNode(MP_share_pp, 1, "BOOL");
|
||||
props.globals.initNode(crash_fire_pp, 1, "BOOL");
|
||||
props.globals.initNode(impact_fire_pp, 1, "BOOL");
|
||||
props.globals.initNode(save_on_exit_pp, 0, "BOOL");
|
||||
props.globals.initNode(restore_on_startup_pp, 0, "BOOL");
|
||||
props.globals.initNode(models_enabled_pp, 1, "BOOL");
|
||||
props.globals.initNode(report_score_pp, 1, "BOOL");
|
||||
props.globals.initNode(event_file_pp, "", "STRING");
|
||||
props.globals.initNode(time_hack_pp, "", "STRING");
|
||||
|
||||
props.globals.initNode(fire_LOD_pp, 10, "INT");
|
||||
props.globals.initNode(smoke_LOD_pp, 10, "INT");
|
||||
|
||||
SimTime.init();
|
||||
broadcast = mp_broadcast.BroadcastChannel.new(msg_channel_mpp, parse_msg);
|
||||
CAFire.init();
|
||||
|
||||
# Start the score reporting.
|
||||
wildfire_score_report_loop_timer.restart(CAFire.GENERATION_DURATION);
|
||||
|
||||
setlistener("/sim/signals/exit", func {
|
||||
if (getprop(report_score_pp) and (CAFire.cells_created > 0))
|
||||
print_score();
|
||||
if (getprop(save_on_exit_pp))
|
||||
CAFire.save_event_log(SAVEDIR ~ "fire_log.xml");
|
||||
});
|
||||
|
||||
# Determine the skip-ahead-to time, if any.
|
||||
var time_hack = time_string_to_epoch(getprop(time_hack_pp));
|
||||
if (time_hack > SimTime.current_time()) {
|
||||
logprint(LOG_ALERT,
|
||||
"wildfire.nas: Ignored time hack " ~
|
||||
(SimTime.current_time() - time_hack) ~
|
||||
" seconds into the future.");
|
||||
# Skip ahead to current time instead.
|
||||
time_hack = -1;
|
||||
} elsif (time_hack > 0) {
|
||||
logprint(LOG_ALERT,
|
||||
"wildfire.nas: Time hack " ~
|
||||
(SimTime.current_time() - time_hack) ~
|
||||
" seconds ago.");
|
||||
} else {
|
||||
# Skip ahead to current time instead.
|
||||
time_hack = -1;
|
||||
}
|
||||
|
||||
if (getprop(event_file_pp) != "") {
|
||||
settimer(func {
|
||||
# Delay loading the log until the terrain is there. Note: hack.
|
||||
CAFire.load_event_log(getprop(event_file_pp), time_hack);
|
||||
}, 3);
|
||||
} elsif (getprop(restore_on_startup_pp)) {
|
||||
settimer(func {
|
||||
# Delay loading the log until the terrain is there. Note: hack.
|
||||
# Restore skips ahead to current time.
|
||||
CAFire.load_event_log(SAVEDIR ~ "fire_log.xml", -1);
|
||||
}, 3);
|
||||
}
|
||||
|
||||
# Detect aircraft crash.
|
||||
setlistener("sim/crashed", func(n) {
|
||||
if (getprop(crash_fire_pp) and n.getBoolValue())
|
||||
wildfire.ignite(geo.aircraft_position());
|
||||
});
|
||||
|
||||
# Detect impact.
|
||||
var impact_node = props.globals.getNode("sim/ai/aircraft/impact/bomb", 1);
|
||||
setlistener("sim/ai/aircraft/impact/bomb", func(n) {
|
||||
|
||||
if (getprop(impact_fire_pp) and n.getBoolValue()){
|
||||
var node = props.globals.getNode(n.getValue(), 1);
|
||||
var impactpos = geo.Coord.new();
|
||||
impactpos.set_latlon
|
||||
(node.getNode("impact/latitude-deg").getValue(),
|
||||
node.getNode("impact/longitude-deg").getValue());
|
||||
wildfire.ignite(impactpos);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
logprint(LOG_INFO, "Wildfire ... initialized.");
|
||||
|
|
Loading…
Add table
Reference in a new issue