|
1 | | -# msfs-rs |
| 1 | + |
2 | 2 |
|
3 | | -See https://flybywiresim.github.io/msfs-rs/msfs/ |
| 3 | +# ✈️ msfs-rs 🦀 |
| 4 | + |
| 5 | +**Use Rust to interact with Microsoft Flight Simulator** |
| 6 | + |
| 7 | +[**As seen in the FlyByWire A32NX and A380X!**](https://flybywiresim.com/projects/) |
| 8 | + |
| 9 | +* Write custom aircraft logic in Rust |
| 10 | + * Systems |
| 11 | + * Gauges |
| 12 | + * Instrument panels (NanoVG) |
| 13 | + * Replace aircraft code |
| 14 | + * RPL |
| 15 | + * C++ |
| 16 | + * JavaScript |
| 17 | + * TypeScript |
| 18 | + * WASM |
| 19 | +* Interact with the Microsoft SDK |
| 20 | +* Create external applications that interact with MSFS using SimConnect |
| 21 | + |
| 22 | +[](https://discord.gg/flybywire) |
| 23 | +[](https://x.com/FlybywireSim) |
| 24 | +[](https://www.youtube.com/c/FlyByWire-Simulations) |
| 25 | +[](https://www.facebook.com/FlyByWireSimulations/) |
| 26 | +[](https://instagram.com/flybywiresim) |
| 27 | +[](https://bsky.app/profile/flybywiresim.com) |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## Example |
| 32 | +Drawing a red rectangle on a glass instrument panel inside an aircraft cockpit: |
| 33 | + |
| 34 | +```rust |
| 35 | +// gauge_logic.rs |
| 36 | +use msfs::{nvg, MSFSEvent}; |
| 37 | + |
| 38 | +#[msfs::gauge(name=Demo)] |
| 39 | +async fn demo(mut gauge: msfs::Gauge) -> Result<(), Box<dyn std::error::Error>> { |
| 40 | + // Use NanoVG to draw |
| 41 | + let nvg = gauge.create_nanovg().unwrap(); |
| 42 | + |
| 43 | + let black = nvg::Style::default().fill(nvg::Color::from_rgb(0, 0, 0)); |
| 44 | + let red = nvg::Style::default().fill(nvg::Color::from_rgb(255, 0, 0)); |
| 45 | + |
| 46 | + // Reacting to MSFS events |
| 47 | + while let Some(event) = gauge.next_event().await { |
| 48 | + match event { |
| 49 | + MSFSEvent::PreDraw(d) => { |
| 50 | + nvg.draw_frame(d.width(), d.height(), |f| { |
| 51 | + // Red rectangle |
| 52 | + f.draw_path(&red, |p| { |
| 53 | + p.rect(20.0, 20.0, 40.0, 40.0); |
| 54 | + println!("Hello rusty world!"); |
| 55 | + |
| 56 | + Ok(()) |
| 57 | + })?; |
| 58 | + |
| 59 | + Ok(()) |
| 60 | + }); |
| 61 | + } |
| 62 | + _ => {} |
| 63 | + } |
| 64 | + } |
| 65 | + Ok(()) |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +``` |
| 70 | +[VCockpit01] |
| 71 | +size_mm=1024,768 |
| 72 | +pixel_size=1024,768 |
| 73 | +texture=$SCREEN_1 |
| 74 | +background_color=0,0,255 |
| 75 | +htmlgauge00=WasmInstrument/WasmInstrument.html?wasm_module=gauge_logic.wasm&wasm_gauge=Demo, 0,0,1024,768 |
| 76 | +``` |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +--- |
| 81 | + |
| 82 | +## Getting started |
| 83 | +```bash |
| 84 | +$ cd examples/nvg |
| 85 | +$ cargo build --target wasm32-wasip1 |
| 86 | +``` |
| 87 | +* [Check out the other examples](examples/) |
| 88 | +* [Download the MSFS SDK](https://docs.flightsimulator.com/html/Introduction/SDK_Overview.htm) |
| 89 | + |
| 90 | +## Further reading |
| 91 | +* [Documentation](https://flybywiresim.github.io/msfs-rs/msfs/) |
| 92 | +* [Microsoft Flight Simulator SDK](https://docs.flightsimulator.com/html/Introduction/Introduction.htm) |
| 93 | + * [Creating an aircraft with custom logic](https://docs.flightsimulator.com/html/Samples_And_Tutorials/Samples/SimObjects_Aircraft/GaugeAircraft.htm) |
| 94 | + * [Programming APIs](https://docs.flightsimulator.com/html/Programming_Tools/Programming_APIs.htm) |
| 95 | + * [Microsoft's Samples and Examples](https://docs.flightsimulator.com/html/Samples_And_Tutorials/Samples_And_Tutorials.htm) |
| 96 | + * [External interaction with SimConnect](https://docs.flightsimulator.com/html/Programming_Tools/SimConnect/SimConnect_SDK.htm) |
| 97 | + |
| 98 | +## Help |
| 99 | +* Join the [Discord #rust-lang channel](https://discord.gg/flybywire) |
0 commit comments