Callbacks: Difference between revisions

142 bytes added ,  23 January 2019
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
In FlightGear, a '''callback''' is a function that will typically be invoked by either a [[#Timers]] or a property [[#Listeners]]. One of the most common ways of using timers and listeners is FlightGear scripting via the built-in [[Nasal]] scripting language. However, the underlying code is not specific to Nasal scripting, i.e. is also widely used in native/C++ code.
In FlightGear, a '''callback''' is a function that will typically be invoked by either a [[#Timers]] or a property [[#Listeners]]. One of the most common ways of using timers and listeners is FlightGear scripting via the built-in [[Nasal]] scripting language. However, the underlying code is not specific to Nasal scripting, i.e. is also widely used in native/C++ code.


Improper use of timers and listeners is one of the most common causes for FlightGear performance issues, because function callbacks (code) may be registered to be triggered/executed more often than required, this problem is not specific to [[Nasal]] code written  by aircraft developers, but also C++ code written by FlightGear core developers, it's been the source of major resource leaks in FlightGear, causing severe stuttering and performance degradation.
{{Main article|Howto:Troubleshooting Nasal Callbacks}}
{{Caution|Improper use of timers and listeners is one of the most common causes for FlightGear performance issues, because function callbacks (code) may be registered to be triggered/executed more often than required (potentially, several times per frame), this problem is not specific to [[Nasal]] code written  by aircraft developers, but also C++ code written by FlightGear core developers, it's been the source of major resource leaks in FlightGear, causing severe stuttering and performance degradation over time.}}


The one thing that both timers and listeners have in common is that they're event handlers, i.e. mechanisms that allow custom code to be executed whenever a certain event is triggered, such as a configurable timer expiring and/or a property being updated/modified.
The one thing that both timers and listeners have in common is that they're event handlers, i.e. mechanisms that allow custom code to be executed whenever a certain event is triggered, such as a configurable timer expiring and/or a property being updated/modified.
Line 36: Line 37:


== Timers ==
== Timers ==
{{See also|Nasal Events}}


'''Timers''' are a way to register recurring tasks to be executed repeatedly. This is accomplished using the FlightGear event manager. Timers are the most common method for running Nasal callbacks (functions), the other being [[Listeners]].
'''Timers''' are a way to register recurring tasks to be executed repeatedly. This is accomplished using the FlightGear event manager. Timers are the most common method for running Nasal callbacks (functions), the other being [[Listeners]].