1
0
Fork 0

globals.nas: add _setlistener wrapper (needs to be used in INIT style

functions when used in $FG_ROOT/Nasal/*.nas, because it
             depends on props.nas being available; no restrictions in
             aircraft files, where it will proof most useful

gui.nas:     replace inefficient FPS display polling loop with listener
             callback
This commit is contained in:
mfranz 2005-12-16 19:15:08 +00:00
parent df6d7171a6
commit 523b81e317
2 changed files with 15 additions and 6 deletions

View file

@ -62,6 +62,17 @@ interpolate = func {
_interpolate(arg[0], size(arg) == 1 ? [] : subvec(arg, 1));
}
##
# Convenience wrapper for the _setlistener function. Takes a
# single string or props.Node object in arg[0] indicating the
# listened to property, and a function in arg[1].
#
setlistener = func {
_setlistener(isa(arg[0], props.Node) ? arg[0]._g : arg[0], arg[1]);
}
##
# Returns true if the symbol name is defined in the caller, or the
# caller's lexical namespace. (i.e. defined("varname") tells you if

View file

@ -57,11 +57,10 @@ menuEnable = func(name, state) {
# property and the argument for the "dialog-show" command. This
# probably isn't really needed...
#
screenHProp = tipArg = fps = nil;
screenHProp = tipArg = nil;
INIT = func {
screenHProp = props.globals.getNode("/sim/startup/ysize");
tipArg = props.Node.new({ "dialog-name" : "PopTip" });
fps = props.globals.getNode("/sim/rendering/fps-display");
props.globals.getNode("/sim/help/debug", 1).setValues(debug_keys);
props.globals.getNode("/sim/help/basic", 1).setValues(basic_keys);
@ -71,7 +70,7 @@ INIT = func {
menuEnable("fuel-and-payload", getprop("/sim/flight-model") == "yasim");
menuEnable("autopilot", props.globals.getNode("/autopilot/KAP140/locks") == nil);
fps_loop();
setlistener("/sim/rendering/fps-display", fpsDisplay);
}
settimer(INIT, 0);
@ -80,14 +79,13 @@ settimer(INIT, 0);
# Show/hide the fps display dialog.
#
var show_fps = 0;
fps_loop = func {
var i = fps.getValue();
fpsDisplay = func {
var i = cmdarg().getBoolValue();
if (i != show_fps) {
fgcommand(i ? "dialog-show" : "dialog-close",
props.Node.new({"dialog-name": "fps"}));
show_fps = i;
}
settimer(fps_loop, 1);
}