Callbacks: Difference between revisions

Jump to navigation Jump to search
2,324 bytes added ,  20 February 2016
Line 30: Line 30:


== Timers ==
== Timers ==
{{Merge|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]].
Please noote that that settimer() should be considered deprecated, and maketimer() should be favored instead.


* [[Nasal Callbacks Explained]]
 
"events" in the performance monitor can usually be attributed to Nasal timers, Nasal is not the only subsystem to use the event manager
 
there's basically a separate "events" subsystem which is based on FGTimer/SGTimer objects that trigger callbacks - in this case, Nasal callbacks. This can also be seen in the system monitor: http://wiki.flightgear.org/Howto:Use_the_system_monitor
 
the settimer() and setlistener() APIs are particularly tedious to manage properly - but the de facto practice is to use those as the main building blocks to write/integrate full subsystems into the FlightGear main loop - tiny coding errors may not have much of an effect, but under certain circumstances, those coding errors will add up (i.e. over time), so that the original "task" of checking your inbox once per hour, ends up being executed hundreds of times per second - the underlying code would still be correct though, it's just the event handling code that is not written correctly, which is often the case when using reset/re-init or when changing locations
 
In a sense, timers are "active" - while listeners are "passive", because they get only ever invoked once the property is modified. Still, the reason for using timers is usually saving resources - by running certain code at configurable intervals.
 
In other words, there are subsystems that run Nasal code, without showing up in the Nasal category - such as property tree or events system.
Still, that doesn't currently tell you which code (function, loop, file, line number etc) is really adding up/expensive.
 
the event manager subsystem (SGEventMgr) which has two internal "queues" for keeping a list of callbacks that shall be invoked when a certain event (timeout) happens, as well as the property tree interface to register Nasal callbacks via the SGPropertyChangeListener API:
 
http://api-docs.freeflightsim.org/simge ... ntMgr.html
http://api-docs.freeflightsim.org/simge ... tener.html
 
* [[Howto:Timers and properties]]

Navigation menu