Using listeners and signals with Nasal: Difference between revisions

Jump to navigation Jump to search
m
Line 14: Line 14:


Keep in mind that listeners are not "background processes" at all - a listener will be triggered by the property tree once a node is accessed, which will invoke the Nasal callback. Timers and listeners are NOT background "processes". They are just invoked by different subsystems, i.e. the property tree (listeners) or the events subsystem (timers). There are other subsystems that can also invoke Nasal handlers, such as the GUI system or the AI code. This all takes place inside the FG main loop (=main thread), not some separate background/worker thread. Which is also the reason why all the Nasal APIs are safe to be used.
Keep in mind that listeners are not "background processes" at all - a listener will be triggered by the property tree once a node is accessed, which will invoke the Nasal callback. Timers and listeners are NOT background "processes". They are just invoked by different subsystems, i.e. the property tree (listeners) or the events subsystem (timers). There are other subsystems that can also invoke Nasal handlers, such as the GUI system or the AI code. This all takes place inside the FG main loop (=main thread), not some separate background/worker thread. Which is also the reason why all the Nasal APIs are safe to be used.
It is important to understand that a "listener" is a passive thing, i.e. a "list" (array) of optional functions that are to be invoked whenever a property is modified/written to - thus, once you modify the property, the property tree code will check the size of the "callback list" that contains callbacks that are to be notified (called) when the property is written - and then calls each callback in a foreach() loop.
Which is to say that those performance monitor stats are not necessarily representative when it comes to Nasal callbacks invoked as timers/listeners, which also applies to C++ code using these two APIs (timers & listeners).


Listeners are not actively "listening" at all - there's no "listener watch" running - unlike timers, listeners are totally passive instead - it works basically like this:
Listeners are not actively "listening" at all - there's no "listener watch" running - unlike timers, listeners are totally passive instead - it works basically like this:

Navigation menu