GaugeAircraft

The GaugeAircraft sample illustrates how to create C++ gauges for a plane in Microsoft Flight Simulator. It is largely based on the SimpleAircraft sample, so please refer to its dedicated page for a more detailed explanation about the files needed in the project and how they can be compiled in-game to create a package.

 

You can expand the link below to see the file and folder structure of the files that have been added to the SimpleAircraft project for this sample:

File OverviewFile Overview

|+ GaugeAircraft
|---+ Sources
    |---+ Code
        |---- Attitude.cpp
        |---- Compass.cpp
        |---- Demo.cpp
        |---- SampleWasmModule.sln
        |---- SampleWasmModule.vcxproj
        |---- SampleWasmModule.vcxproj.filters
        |---+ PackageSources
            |---+ Data
                |---+ images
                |   |---- image1.jpg
                |   |---- ...
                |   |---- image12.jpg
                |---- entypo.ttf
                |---- images.txt
                |---- LICENSE_OFL.txt
                |---- NotoEmoji-Regular.ttf
                |---- Roboto-Bold.ttf
                |---- Roboto-Light.ttf
                |---- Roboto-Regular.ttf
                |---- screenshot-01.png
                |---- screenshot-02.png

 

The SampleWasmModule.sln solution will allow you to compile the code with Microsoft Visual Studio 2019 in order to create the SampleWasmModule.wasm WebAssembly module which will then be loaded by the game. Once compiled, the module will automatically be copied into the following folder

PackageSources\SimObjects\Airplanes\MyCompany_Gauge_Aircraft\panel

In order for the aircraft to use the gauges defined in the module, they have to be declared in the panel.cfg file found in the same folder:

[VCockpit01]
size_mm=1024,768
pixel_size=1024,768
texture=SCREEN_1
background_color=0,0,255
htmlgauge00=WasmInstrument/WasmInstrument.html?wasm_module=SampleWasmModule.wasm&wasm_gauge=Compass, 0,0,1024,768
 
[VCockpit02]
size_mm=1024,768
pixel_size=1024,768
texture=SCREEN_2
background_color=0,255,0
htmlgauge00=WasmInstrument/WasmInstrument.html?wasm_module=SampleWasmModule.wasm&wasm_gauge=Attitude, 0,0,1024,768
 
[Vcockpit03]
size_mm=1024,768
pixel_size=1024,768
texture=SCREEN_3
background_color=255,0,0
htmlgauge00=WasmInstrument/WasmInstrument.html?wasm_module=SampleWasmModule.wasm&wasm_gauge=Demo, 0,0,1024,768

 

As can be seen above, the gauges are referenced using the following URI scheme:

htmlgaugeNN=WasmInstrument/WasmInstrument.html?wasm_module=[MODULE].wasm&wasm_gauge=[GAUGE_NAME],[X],[Y],[WIDTH],[HEIGHT]

 

 

Gauge Files

The following files are used for the gauges in this example:

  • Attitude.cpp: provides an implementation of an Attitude gauge.
  • Compass.cpp: provides an implementation of a Compass gauge.
  • Demo.cpp: provides a basic demo using the NanoVG OpenGL graphics library to show how it can be implemented in your gauges (see here for more information).

 

 

Loading And Building The Project

Building the GaugeAircraft project is identical to building the SimpleAircraft one. However please note that if you make changes to the C++ code and recompile the WebAssembly module, you will have to build your package again (using the Build Package button in the Edit Package window). This can be done while the plane is used within the game.