Simulated Time

From X-Plane SDK
Revision as of 14:59, 8 November 2014 by Bsupnik (Talk | contribs) (Detecting When Time Is Not Advancing Due to Popup Windows)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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:

  1. If the sim is paused, the frame rate period is zero, because no simulated time has elapsed from draw to draw.
  2. 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.

This trick (monitoring sim/time/total_flight_time_sec) will let you determine when the simulation is advancing/processing, but tells you nothing about the map window. For example, when the map window is up, the sim will run if the IOS screen is up.