CREATING A WASM PROJECT

WASM (C/C++) modules can be developed for Microsoft Flight Simulator 2024 with the Microsoft Flight Simulator Platform Toolset which is installed at the same time as the SDK itself (see the Additional Tools and Web Assembly pages for more information). In this short tutorial we'll quickly take you through the main steps required to create a WASM module.

 

 

Creating A Project

The Microsoft Flight Simulator 2024 SDK includes a number of templates that you can - and should - use to create your WASM modules. You can get these by starting Visual Studio, selecting Create A New Project, and on the templates screen search for MSFS:

 

The four available templates are:

  • MSFS 2024 WASM Standalone Module: This is the base template that should be used in the creation of all standalone modules.
  • MSFS 2024 WASM Airport Module: This is the base template that should be used in the creation of all airport modules.
  • MSFS 2024 WASM Module: This is the base template that should be used in the creation of all WASM gauges and WASM systems.
  • MSFS 2024 WASM Static Library: This is a template that can be used to create a WASM static library for future WASM modules to link to.

 

After selecting the correct template, you will be presented with the following basic project, which we'll be editing:

#include <MSFS/MSFS.h>
#include "[MODULE_NAME]_Module.h"
extern "C" MSFS_CALLBACK void module_init(void)
{
    // This is called when the module is initialized
}
extern "C" MSFS_CALLBACK void module_deinit(void)
{
    // This is called when the module is deinitialized
}

 

Those two functions are the ones common to all WASM modules, they are the first function to be called and the last one to be called. The game will look for and execute the following module functions if they exist:

  • extern "C" MSFS_CALLBACK void module_init(void): upon loading or after sign-in.
  • extern "C" MSFS_CALLBACK void module_deinit(void): upon closing the game or after sign-out.

 

 

Visual Studio Project Properties

The VS Properties Window For A WASM Module

When creating your WASM projects, most of the project settings will be the same as for a standard C++ project, however there are some things that should be set up with specific values, which we'll outline here:

 

  • Configuration Properties: These can be left with their default values.
  • C/C++: In this section you have the following properties which may need editing:
    • General - Debug Information Format: This must be set as //clang:-g. It should be set automatically, but it is worth checking.
    • General - Warning Level: Set this field to Level 3, and check your warning regularly, as clang will tell you if you do something wrong.
    • General - Multi-processor Compilation: Use this field to speed up your compilation time.
      Multi-Processor Compilation Options
    • Optimization: When debugging you should set everything to Disabled (/Od). For release, we recommend that you set this to Maximum Optimization (Favor Speed) (/O2). Note that the SDK will automatically optimize modules which have a value in Optimization field other than Disabled (using the /clang:-O3 setting, as explained in the Override Optimisations section, below). The others fields in this section can be set as you require.
      C++ Optimisation Options
  • Linker: In the Debugging section you want to set it to "Generate Debug Info (/DEBUG)" when you are testing and debugging the module, but then for release, set it to "No".
    Linker Debug Options

 

Override Optimisations

When setting up Visual Studio it should be noted that you may override the optimisation options using the Command Line section of the Linker configuration:

 

In the additional Options section you would use the following:

*/clang:-OX*

Where X is either 0, 1, 2 or 3:

  • */clang:-O0*: this is the default mode, where there will be lots of instructions meaning it will take more time to be executed. However it will also have debug data and you will be able to put breakpoint and step through the code. Use this option in development.
  • */clang:-O3*: this must be used for release builds. When using this, there are a lot of extra optimizations processed, with less instructions giving a faster module. However, this means that debug data is optimized and so you can't use breakpoints or code stepping.
  • */clang:-O1, 2.*: These are "middle" levels of optimization, and can be used if required, although it's not generally necessary.

 

 

Editing The WASM Module Project

Now you've initialised the new WASM project and setup Visual Studio, you'll need to edit the source code to include the minimum header files - supplied by the SDK - to create the module. You can find all the available files that can be included from the following SDK location:

<SDK Root>\WASM\include\MSFS

Location Of The MSFS.h File

 

These different API's are as follows, keep in that depending of the template selected, some API will not be usable in game :