see also https://wiki.flightgear.org/Nasal_Optimisation#Emesary_real_time_executive
Using a scheduler to manage the invocation of Nasal modules provides a more predictable and efficient way to replace update loops and also optimises property tree access to one access per property per frame by using a hash that contains the property values.
There is a default global object created (emexec.ExecScheduler) that should be used in most circumstances.
Each Nasal object simply has to have an update(notification) method. This will be called on a schedule and the notification will contain any requested property values.
The exec will also adapt the rate to the frame rate; with a maximum of 50hz, but this will drop to as low as 4hz based on the frame rate to optimise workload.
The modules will be called in the order in which they were added; so it is possible to have modules in the right sequence (i.e. an earlier module calculates values that are used by a later module)
A simple example is below. The VSD_device has the update method
------
# list of prooperties to include in the notification hash
var properties_to_monitor = {
OrientationHeadingDeg : "orientation/heading-deg",
OrientationPitchDeg : "orientation/pitch-deg",
OrientationRollDeg : "orientation/roll-deg",
GroundspeedKts : "velocities/groundspeed-kt",
radar2_range : "instrumentation/radar/radar2-range",
target_display : "sim/model/f15/instrumentation/radar-awg-9/hud/target-display",
vc_kts : "instrumentation/airspeed-indicator/true-speed-kt",
};
# create Canvas based device (that has an update method)
VSD = VSD_Device.new(designation, textureImage, notification.Ident, root_node);
# register with the exec;
# - ident
# - proprties to include in notification hash
# - object (with an .update(notification) method
# - rate (4 = 1/4)
emexec.ExecModule.register("F15-VSD", properties_to_monitor, VSD, 4);