CORE AND HELPERS
On this page you can find some of the functions from the MSFS_Core.h
and complimentary utilities file SimParamArrayHelper.h
.
Variant Parameters
The main purpose of the MSFS_Core.h
is to give functions related to variants, which are essentially a type safe union. A variant stores the value of an object within a union and the object type within an enum. Variants are used as the parameter or return types for a function, where the types may change according to the other parameters involved. For example, in a function which gets the value of a variable by its name, but the type of the variable is a-priori unknown. Variants can also be used in an array, where the elements of the array can have different types.
eFsVarParamType
This is an enum which lists all the possible values of the variant:
enum eFsVarParamType : unsigned char {
FsVarParamTypeInteger,
FsVarParamTypeString,
FsVarParamTypeCRC,
};
FsVarParamVariant
This is the actual variant definition struct, which has an enum of all types, and a union of all values possible:
struct FsVarParamVariant {
eFsVarParamType type;
union {
unsigned int intValue;
const char* stringValue;
FsCRC CRCValue;
};
};
FsVarParamArray
This is a struct containing an array with pointers to the variant and a member variable with the size of the array:
struct FsVarParamArray {
unsigned int size = 0;
FsVarParamVariant* array = nullptr;
};
Utilities
Within the Utils folder of the WASM SDK, you will find the SimParamArrayHelper.h
file. The purpose of this file is essentially the creation and destruction of parameter arrays.
FsCreateParamArray
This variadic function is used to help with the creation of an array:
static FsVarParamArray FsCreateParamArray(
const char* fmt,
// additional params here following the types given in "fmt"
...
);
The parameter fmt
here is a string of letters, where each letter defines the type of the corresponding parameter in the array. The value for the fmt
string is made up of a concatenation of the following sub-strings:
- "c" - This is a CRC value (
FsSimCRC
/ unsigned long long). Note that "5" is not an unsigned long long, whereas "5ULL" is. - "s" - This is a string (
const char*
) - "i" - This is an integer (
unsigned int
)
Each sub-string in the fmt
string represents a single array value, so - for example - a simple fmt
string could be "iics", and then in the array creation you would supply four additional values that will correspond to the given data types to create a 4 value array:
FsCreateParamArray(
"iics",
0,
1,
123456ULL,
"Hey"
);
Note that it is possible to change values in the array, and change the type, after it has been created, but it is not possible to resize it. It is also very important that the array is freed when no longer needed.
FsDestroyParamArray
This function is used to destroy a pParamArray
, freeing the array and invalidating its values (ie: nullptr
in the array and it will be 0 in size):
static void FsDestroyParamArray(
FsVarParamArray* pParamArray
);