X-Plane tracks two forms of time: simulated time and real time.
- Simulated time tracks the simulation of an airplane flight. It is affected by pausing the sim, doubling X-Plane's simulation rate, etc.
- Real time tracks the actual real world time of the computer X-Plane is running on, and never stops or changes speed.
Simulated time can be tracked via the following datarefs:
sim/time/total_running_time_sec- simulated time in seconds since X-Plane started.
sim/time/total_flight_time_sec- simulated time in seconds since the las time the flight model was reset (E.g. an airplane load, etc).
sim/time/sim_speed- the multiplier between real time and sim time, e.g. 0 for paused, 1 for normal operation, 4 for 4x simulation.
sim/operation/misc/frame_rate_period- the length of a simulated graphics frame in simulation time.
The frame rate period has a few surprising effects:
- If the sim is paused, the frame rate period is zero, because no simulated time has elapsed from draw to draw.
- If the sim is in 2x simulation, the frame rate period doubles, because twice as much sim time goes by each time we draw.
Real time can be tracked using XPLMGetElaspedTime. Real time is also the time passed to the XPLMProcessing callback functions, and is the time used to schedule periodic flight loop callbacks.
Detecting When Time Is Not Advancing Due to Popup Windows
Sometimes when a window pops up over the sim (e.g. the map or an alert) the flight model will stop running. You may need to detect this to stop running certain kinds of code:
- Sound code.
- Code that adds forces.
- Code that modifies the FM output with a post-flight loop callback.
You can detect this by tracking sim/time/total_flight_time_sec - if sim/time/total_flight_time_sec has not increased since the last callback, then (on this callback) the sim is occluded. Please note that you need to look at this and sim/time/sim_speed to get the total effect of time on the simulation.