Using listeners and signals with Nasal: Difference between revisions

Jump to navigation Jump to search
m
→‎Nasal code coupled to the autopilot system: http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg13029.html
m (→‎Nasal code coupled to the autopilot system: http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg13025.html)
m (→‎Nasal code coupled to the autopilot system: http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg13029.html)
Line 193: Line 193:


=== Nasal code coupled to the autopilot system ===
=== Nasal code coupled to the autopilot system ===
The FDM doesn't run at a fixed rate, either. It runs 120 times per second (if so configured), but it runs all iterations for a frame one after the other, then waits until the next frame.  
The FDM doesn't run at a fixed rate, either. It runs 120 times per second (if so configured), but it runs all iterations for a frame one after the other, then waits until the next frame. The FDM runs at 120 hertz and with a fixed time step.
 
However, we play one small trick to make that happen.  We take the time that has elapsed since the last frame, compute how many whole iterations of the
FDM will fit in that time slice (at 1/120th of a second per iteration.) Then we invoke the FDM that many times with a time step of 1/120th of a
second.  Finally we save out the remainder and add that into the next time slice.
 
This can produce a small amount of temporal jitter between the graphics and the fdm if the graphics frame rates are not a diviser of 120.  In the best
case scenario, you've locked your graphics frame rate to 60 hz so the FDM runs exactly 2 iterations every time it is invoked and there is no temporal
jitter at all, ever.
 
One thing to keep in mind is that handing a different size time slice to the FDM every frame (and sometimes that time slice could be 1 second or more?)
can lead to instabilities in the math.  So our approach is intended to avoid that potential problem.  As far as the FDM is concerned, it *is* running
asyncronously, at a fixed time step.  But, we are playing a little trick on the FDM (it doesn't care) in order to handle the unfortunate possibility of
non-fixed and highly variable frame rates on PC hardware running consumer grade operating systems.


Some people have a need to run Nasal code at the same rate as the simulation. Currently, without modifying the source code for FlightGear, the only way
Some people have a need to run Nasal code at the same rate as the simulation. Currently, without modifying the source code for FlightGear, the only way

Navigation menu