Module xplane::flight_loop

source ·
Expand description

Flight loop callbacks

§Flight loop callbacks

X-Plane can call plugin code at timed intervals or when it runs its flight model.

A FlightLoop object must persist for callbacks to occur. When the FlightLoop is dropped, its callbacks will stop.

§Examples

Closure handler:

use xplane::{XPAPI, flight_loop::{FlightLoop, FlightLoopPhase, LoopState, LoopResult}};

struct MyLoopState;
fn a_callback(xpapi: &mut XPAPI) {
    let handler = |_xpapi: &mut XPAPI, loop_state: &mut LoopState<()>| -> LoopResult {
        println!("Flight loop callback running");
        LoopResult::NextLoop
    };

    let mut flight_loop = xpapi.new_flight_loop(FlightLoopPhase::BeforeFlightModel, handler, ());
    flight_loop.schedule_immediate();
}

Struct handler:

use xplane::{XPAPI, flight_loop::{FlightLoop, FlightLoopCallback, FlightLoopPhase, LoopState, LoopResult}};

struct MyLoopHandler;

impl FlightLoopCallback<()> for MyLoopHandler {
    fn flight_loop(&mut self, _xpapi: &mut XPAPI, state: &mut LoopState<()>) -> LoopResult {
        println!("Flight loop callback running");
        // You can keep state data in your own struct.
        LoopResult::NextLoop
    }
}
fn a_callback(xpapi: &mut XPAPI) {
    let mut flight_loop = xpapi.new_flight_loop(FlightLoopPhase::BeforeFlightModel, MyLoopHandler, ());
    flight_loop.schedule_immediate();
}

Structs§

  • Tracks a flight loop callback, which can be called by X-Plane periodically for calculations
  • Information available during a flight loop callback

Enums§

  • Loop results, which determine when the callback will be called next

Traits§