Skip to content

Commit

Permalink
refactor: Cpp WASM Lightweight Framework (#7711)
Browse files Browse the repository at this point in the history
* Cpp WASM Lightweight Framework - squashed for rebase with new repo

* Rebased to new repo structure

* added build-script execute permissions

* Refactored common code to fbw-common folder

* Optimized imports

* Corrected comment

* Added extra-backend to A380X (modules not adapted to A380 yet)

* Removed updateDataToSim from DataDefinitionVariable

* Updated documentation

* Updated documentation

* Fixed some A380 build issues

* Some minor A380X fixes pushback, lighting presets ok, aircraft presets needs new procedures

* Fix pushback and aircraft presets reads from sim to respect cache

* Fix cache and age handling

* Examples for debugging

* Removed redundant timeStamp/tickCounter in DataManager

* Testing and minor changes

* Some commenting for examples

* Change order in in list of sources files

* Added getter for isInitialized in Module.h

* Added method for checking if a variable needs updating to the ManagedDataObjectBase class

* Removed DataDefinitionVariable.cpp by moving remaining definition to .h

* Added warning and small potential bug fix in Event.cpp

* Removed DataDefinitionVariable.cpp by moving remaining definition to .h

* Added a verbose var for easier debugging to AircraftPresets

* Added typedefs to AircraftProcedures.h

* Add warning for unknown/unimplemented sim messages

* Introduced verbose LVAR for AircraftPresets

* Simplification and commenting

* Use optional instead of nullptr check

* Added templated callback for static callback for key event handler

* Added dummy classes for KeyEvent and InputEvent

* Added ClientDataAreaVariable

* Used template for math almostEqual

* Renamed templated .h files to .hpp as they include full definition with no .cpp file

* Added simtime and tickcounter to the processSimData method to allow for time/tick stamping when the actual data update happens.

* Using c++-20 standard

* Commenting

* C++20 as standard and build script/cmake tweaks

* Refined ClientDataAreaVariable and added documentation.

* Clean up examples

* Rebase fix

* Removed unnecessary includes

* More rebase fixes

* Some tests and comments to string variable length

* Move changed check and added listener to ManagedDataObjectBase. Also change some ctor parameters to use move

* Change base data to automatic update

* ClientDataBufferedArea (WIP)

ClientDataBufferedArea (WIP)

ClientDataBuffereArea (WIP)

* Not working yet - ClientDataBufferedArea

* Debug improvements to ClientDataBufferedAreaVariable.hpp and ExampleModule

* Added KeyEvent Handling

* Added KeyEvent Handling

* Moved Callback.h into DataManager folder

* Moved constructor of DataObjectBase.h to protected

* Documentation update

* Some restructuring and cleanup

* Cleanup examples

* Added getter for SimConnect handle

* Added example for input events

* Added input events to Event class and added documentation

* Added ClientEvent to replace Event

* Completed ClientEvent class

* Removed/replaced old Event class

* Made all data types ctors private so only DataManager can be used to create instances

* Changed to clang-format - touched basically all files

* Added method for DownUp event in one

* Added option to not immediately register an event when constructing it

* Added pause detection with events which doesn't work b/o sim bug. Commented out.

* Added System Event mapping, completed ClientEvent and documentation

* Fixed ClientDataBufferedAreaVariable.hpp

* Simplified ClientDataAreaVariable.hpp and ClientDataBufferedAreaVariable.hpp creation

* Added writing (sending) of ClientDataBufferedAreaVariable.hpp

* Clean up, documentation, clean up examples

* Moved SimconnectExceptionStrings.h

* Added quantity from Sven's code

* Renamed math_utils lib

* Optimized Lighting Presets to change slower over time so knob animation can keep up.

* Updated some documentation

* Updated some GUIDELINE
 documentation

* Made nodiscard more consistent

* Added setInputGroupPriority to ClientEvent

* Added another input event example

* Added @brief tags to classes for doxygen docs

* Some clean up

* Some clean up

* Updated A380X with latest A32NX code

* Fixed accidental deletion of files

* Fixed a compiler warning when not in debug mode

* Bug fix in Lighting Presets

* Review fixes and changes

* fix compiler warnings if logging is disabled

* move some base scripts to prepare for later replacement of manual build scripts

* define the build script for the common framework

* add a cmake script to automatically create the correct binaries

* define the build targets for A32NX and A380X

* define the top-level scripts for both aircrafts

* adapt the build scripts

* Make the scripts executable

* add a compilation error in case of an invalid configuration

* build the base for both aircrafts

* use one toplevel cmake-build-script

* update the execution flag

* restructure the scripts to use only the top-level script

* C++ wasm modules are built by one script

* adapt the igniter commands

* Rename the build script tp prepare for it to be valid for all cpp wasm modules

* Added check if out folder exists when using build script directly

* Changes to Cmake script to accomodate review changes

* Restore fbw-a380x/src/wasm/fadec_a380/src/SimVars.h

* Restore fbw-a32nx/src/wasm/fadec_a320/src/SimVars.h

* Deactivating A80 compilation for the time being - will be reactivated again at a later point

* Added debug clean build script

* Fixed wasm build as CMake does not check for change on dependencies of custom commands as long as file exists.

* Fixed wasm debug build

* Fixes from review

* Some cleanup

* Turn off verbose CMake

* Refactor update time/tick check

* Removed marco definition in favor of templated using statement

* Removed marco definition in favor of templated using statement

* Renamed fbw-common/src/wasm/extra-backend to fbw-common/src/wasm/cpp-msfs-framework

* Refactor to avoid aircraft dependency in framework by adding aircraft prefix in the modules at runtime

* Moved the framework Example to the cpp-msfs-framework folder

* Moved Pushback to fbw-common

* Refactored AircraftPresets to use an aircraft specific configuration

* Moved AircraftPresets to fbw-common

* Data type changed for consistency

* Refactored LightingPresets to split into common and aircraft-specific parts.

* Added A380 compilation again

* Fixed log output for a380x

* Temporarily using A32NX_ prefix for A380 as A380X flyPad does not use the prefix yet

* Renaming base variables in MsfsHandler

* Testing and commenting for A380X

* Formatted CMake with 4 spaces for continuation

* Additional commenting

* Updated copyright

* Minor cleanup

* Removed unnecessary keep file

* Fixed some clang-tidy warnings

* Rebase fixes

* Cleanup imports and small consistency refactorings

* Added docs comment

* Added move ctor/assign delete and some additional cleanup

* Added ScopedTimer

* Added SimpleProfiler.hpp

* Profiled and optimized LightingPresets

* Added profiling class and compile option - see SimpleProfiler class

* Added unregistering of all named var on msfsHandler shut down

* Added template type check to ProfileBuffer.hpp

* Added check if timer is started when calling stop.

* Commenting

* Added nodiscard to SimpleProfiler.hpp

* Using accumulate for summing

* Commenting

* Added event base pause detection

* Changed base data from single lvar into datadefinition with lvar

* Fixed example pointers

* removed -Werror

* added prefix handling to base data lvars

* Updated comment for pause detection

* Updated comment and reformatting

* ID starting at 0 now

* Added min/max to ProfileBuffer.hpp

* Added methods to retrieve trimmedAvg, min and max values.

* Added default values for allocateClientDataArea back

* Fixed refactor changes not reflected due to comments/ifdefs

* Small refactor for readability

* Small refactor for lib performance

* Small cosmetic refactors

* Combined autoRead/autoWrite to enum updateMode

* Deactivating Examples

* Remove unnecessary assert

* Simplification of InertialDampener

* Replaced accumulate with reduce in ProfileBuffer.hpp

* Change trimmed average to 5%

* Simplification in Pushback.cpp

* Format fix for docs

* Cleanup some code

* Renamed .h to .hpp for files with included definition and no cpp

* Added make_ functions for custom-, sim- and system-events

* Fixed registeredToSim flag handling

* Removed executor_code precompile

* Using new make_ functions for creating events

* Commenting

* Optimized/fixed strobe handling in presets

* Update to README

* Simplification and commenting

* Fixed comment

* Added comment/Todo

* Code simplification

* Fix C++ build and change wasm-opt similar to other c++ build code

* Updated framework READMEs

* Code cleanup

* Fix/optimize build

* Calling set on a chashable variable now sets hasChanged.

* Fixed CHANGELOG.md

* Small code optimizations

* Comment fix

* Code review fixes

* Change A380X panel.cfg to use extra-backend.

---------

Co-authored-by: Sven Czarnian <[email protected]>
  • Loading branch information
frankkopp and svengcz authored Jan 4, 2024
1 parent 95a47eb commit b0e45de
Show file tree
Hide file tree
Showing 117 changed files with 11,039 additions and 4,529 deletions.
2 changes: 2 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
1. [EFCS] Implement calculated yaw damper gain - @lukecologne (luke)
1. [EFCS] Decrease yaw damper at low speeds on ground, down to 0 below 40kts - @lukecologne (luke)
1. [FLIGHTMODEL] Fix pitch trim on approach - @donstim (donbikes)
1. [GENERAL] Added C++ WASM framework and migrated all flypad-backend code to it - @frankkopp (Frank Kopp)
1. [EFB] C++ WASM framework, extra-backend to replace flypad-backend, smooth dial turning for Lighting Presets - @frankkopp (Frank Kopp)

## 0.11.0

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@
# explicit exclusions
/.env
node_modules/
obj/
target/
obj/
cmake-build*/
*.tgz
*.wasm
cmake-build*
Expand Down
12 changes: 8 additions & 4 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
"${MSFS_SDK}/SimConnect SDK/include",
"${workspaceFolder}/fbw-common/src/wasm/fbw_common/src/**",
"${workspaceFolder}/fbw-a32nx/src/wasm/fbw_a320/src/**",
"${workspaceFolder}/fbw-a380x/src/wasm/fbw_a380/src/**"
],
"${workspaceFolder}/fbw-a380x/src/wasm/fbw_a380/src/**",
"${workspaceFolder}/fbw-common/src/wasm/cpp-msfs-framework/**",
"${workspaceFolder}/fbw-common/src/wasm/extra-backend/**",
"${workspaceFolder}/fbw-a32nx/src/wasm/extra-backend-a32nx/src/**",
"${workspaceFolder}/fbw-a380x/src/wasm/extra-backend-a380x/src/**",
"${workspaceFolder}/fbw-a32nx/src/wasm/fadec_a320/src/**",
"${workspaceFolder}/fbw-a380x/src/wasm/fadec_a380/src/**" ],
"defines": [
"_MSFS_WASM=1",
"__wasi__",
Expand All @@ -18,13 +23,12 @@
"_MBCS"
],
"windowsSdkVersion": "10.0.18362.0",
//"compilerPath": "${MSFS_SDK}/WASM/llvm/bin/clang-cl.exe",
"compilerArgs": [
"--sysroot ${MSFS_SDK}/WASM/wasi-sysroot",
"-target wasm32-unknown-wasi"
],
"cStandard": "c17",
"cppStandard": "c++17",
"cppStandard": "c++20",
"intelliSenseMode": "msvc-x64"
}
],
Expand Down
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"name": "Attach",
"type": "cppvsdbg",
"request": "attach",
"processId": "${command:pickProcess}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
Expand Down Expand Up @@ -45,4 +46,4 @@
}
}
]
}
}
74 changes: 53 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,59 @@
# This CMakeLists.txt file is used only for syntax highlighting and navigating
# through the code in an IDE. It is not used for building the project.

cmake_minimum_required(VERSION 3.19)
project(flybywire-a32nx)
cmake_minimum_required(VERSION 3.18)
project(flybywire-aircraft C CXX)

set(CMAKE_CXX_STANDARD 20)
set(MSFS_SDK "C:\\MSFS SDK")
set(FBW_ROOT ${CMAKE_SOURCE_DIR})
set(CMAKE_VERBOSE_MAKEFILE OFF)
set(FBW_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
set(FBW_COMMON ${FBW_ROOT}/fbw-common/src/wasm)

# cmake helper scripts
include("${FBW_COMMON}/cpp-msfs-framework/cmake/TargetDefinition.cmake")

# compiler refinement
set(COMPILER_FLAGS "-Wall -Wextra -Wno-unused-function -Wno-unused-command-line-argument -Wno-ignored-attributes -Wno-macro-redefined -target wasm32-unknown-wasi --sysroot \"${MSFS_SDK}/WASM/wasi-sysroot\" -mthread-model single -fno-exceptions -fms-extensions -fvisibility=hidden -ffunction-sections -fdata-sections -fno-stack-protector")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILER_FLAGS}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto -O2 -DNDEBUG")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -DDEBUG")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILER_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto -O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -DDEBUG")

# include sub directories
message("MSFS_SDK: " ${MSFS_SDK})

# add the include paths
include_directories(
${PROJECT_SOURCE_DIR}/fbw-a32nx/src/wasm/fadec_a320
${PROJECT_SOURCE_DIR}/fbw-a32nx/src/wasm/fbw_a320
${PROJECT_SOURCE_DIR}/fbw-a32nx/src/wasm/flypad-backend
${PROJECT_SOURCE_DIR}/fbw-a380x/src/wasm/fadec_a380
${PROJECT_SOURCE_DIR}/fbw-a380x/src/wasm/fbw_a380
${PROJECT_SOURCE_DIR}/fbw-common/src/wasm/fadec_common
${PROJECT_SOURCE_DIR}/fbw-common/src/wasm/fbw_common
"${MSFS_SDK}/WASM/include"
"${MSFS_SDK}/WASM/wasi-sysroot/include"
"${MSFS_SDK}/WASM/wasi-sysroot/include/c++/v1"
"${MSFS_SDK}/SimConnect SDK/include"
"${FBW_COMMON}/cpp-msfs-framework/lib"
"${FBW_COMMON}/cpp-msfs-framework/MsfsHandler"
"${FBW_COMMON}/cpp-msfs-framework/MsfsHandler/DataTypes"
)

# add compiler definitions
add_definitions(
-D_MSFS_WASM=1
-D__wasi__
-D_LIBC_NO_EXCEPTIONS
-D_LIBCPP_HAS_NO_THREADS
-D_WINDLL
-D_MBCS
# ZERO_LVL=0 CRITICAL_LVL=1 ERROR_LVL=2 WARN_LVL=3 INFO_LVL=4 DEBUG_LVL=5 VERBOSE=6 TRACE_LVL=7
-DLOG_LEVEL=4
# EXAMPLES | NO_EXAMPLES
-DNO_EXAMPLES
#PROFILING | NO_PROFILING - for logging of profiling information of pre-, post-, update() calls
-DNO_PROFILING
)

add_subdirectory(./fbw-a32nx/src/wasm/fadec_a320)
add_subdirectory(./fbw-a32nx/src/wasm/fbw_a320)
add_subdirectory(./fbw-a32nx/src/wasm/flypad-backend)
add_subdirectory(./fbw-a380x/src/wasm/fadec_a380)
add_subdirectory(./fbw-a380x/src/wasm/fbw_a380)
add_subdirectory(./fbw-a380x/src/wasm/flypad-backend)
# add the common components
add_subdirectory(fbw-common/src/wasm)

# add the A32NX components
add_subdirectory(fbw-a32nx/src/wasm)

# add the A380X components
add_subdirectory(fbw-a380x/src/wasm)
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ background_color = 0,0,0
htmlgauge00 = WasmInstrument/WasmInstrument.html?wasm_module=systems.wasm&wasm_gauge=systems,0,0,1,1
htmlgauge01 = WasmInstrument/WasmInstrument.html?wasm_module=fbw.wasm&wasm_gauge=fbw,0,0,1,1
htmlgauge02 = WasmInstrument/WasmInstrument.html?wasm_module=fadec.wasm&wasm_gauge=FadecGauge,0,0,1,1
htmlgauge03 = WasmInstrument/WasmInstrument.html?wasm_module=flypad-backend.wasm&wasm_gauge=FlyPadBackend,0,0,1,1
htmlgauge03 = WasmInstrument/WasmInstrument.html?wasm_module=extra-backend-a32nx.wasm&wasm_gauge=Gauge_Extra_Backend,0,0,1,1

[VCockpit18]
size_mm = 0,0
Expand Down
8 changes: 6 additions & 2 deletions fbw-a32nx/src/systems/instruments/src/EFB/Efb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,28 +211,32 @@ const Efb = () => {

// Automatically load a lighting preset
useEffect(() => {
if (ac1BusIsPowered && autoLoadLightingPresetEnabled) {
if (ac1BusIsPowered && powerState === PowerStates.LOADED && autoLoadLightingPresetEnabled) {
// TIME OF DAY enum : 1 = Day ; 2 = Dusk/Dawn ; 3 = Night
switch (timeOfDay) {
case 1:
if (autoLoadDayLightingPresetID !== 0) {
console.log('Auto-loading lighting preset: ', autoLoadDayLightingPresetID);
setLoadLightingPresetVar(autoLoadDayLightingPresetID);
}
break;
case 2:
if (autoLoadDawnDuskLightingPresetID !== 0) {
console.log('Auto-loading lighting preset: ', autoLoadDawnDuskLightingPresetID);
setLoadLightingPresetVar(autoLoadDawnDuskLightingPresetID);
}
break;
case 3:
if (autoLoadNightLightingPresetID !== 0) {
console.log('Auto-loading lighting preset: ', autoLoadNightLightingPresetID);
setLoadLightingPresetVar(autoLoadNightLightingPresetID);
}
break;
default:
break;
}
}
}, [ac1BusIsPowered, autoLoadLightingPresetEnabled]);
}, [ac1BusIsPowered, powerState, autoLoadLightingPresetEnabled]);

useInterval(() => {
if (!autoFillChecklists) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export const StepDescription = new Map([
[2090, 'ATC ALT RPTG On'],
[2100, 'TCAS TRAFFIC ABV'],
[2110, 'COCKPIT DOOR LCK'],
[2120, 'Strobe Auto'],
[2120, 'Strobe On'],
[2121, 'Strobe Off'],
[2122, 'Strobe Auto'],
Expand Down
13 changes: 13 additions & 0 deletions fbw-a32nx/src/wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# folder structure
set(OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../out/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/panel)

# add compiler definitions
add_definitions(-DA32NX)

add_subdirectory(extra-backend-a32nx)

# FIXME: remove the if-clause as soon as all components are using CMake
if (WIN32)
add_subdirectory(fadec_a320)
add_subdirectory(fbw_a320)
endif ()
2 changes: 1 addition & 1 deletion fbw-a32nx/src/wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ This directory contains the source Rust and C++ files for the WASM modules.
```
- fadec_a320 <c++ src for fadec>
- fbw_a320 <c++ src for fbw/ap>
- flypad-backend <c++ src for flypad backend>
- extra-backend-a32nx <c++ src for backend for flyPad and other extra non-aviation systems>
- systems <rust src for other systems>
```
42 changes: 42 additions & 0 deletions fbw-a32nx/src/wasm/extra-backend-a32nx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# extra-backend-a32nx CMakeLists.txt

# add additional compiler definitions for the a32nx extra-backend build
add_definitions()

# add the local include directories
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/AircraftPresets
${CMAKE_CURRENT_SOURCE_DIR}/src/LightingPresets
${FBW_COMMON}/cpp-msfs-framework/
${FBW_COMMON}/extra-backend/
)

# define the source files
set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/Gauge_Extra_Backend.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/LightingPresets/LightingPresets_A32NX.cpp
${FBW_COMMON}/cpp-msfs-framework/Example/ExampleModule.cpp
${FBW_COMMON}/extra-backend/Pushback/Pushback.cpp
${FBW_COMMON}/extra-backend/AircraftPresets/AircraftPresets.cpp
${FBW_COMMON}/extra-backend/LightingPresets/LightingPresets.cpp
)
set(INCLUDE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/AircraftPresets/AircraftPresetProcedures_A32NX.h
${CMAKE_CURRENT_SOURCE_DIR}/src/LightingPresets/LightingPresets_A32NX.h
${FBW_COMMON}/cpp-msfs-framework/Example/ExampleModule.h
${FBW_COMMON}/cpp-msfs-framework/Example/longtext.h
${FBW_COMMON}/extra-backend/Pushback/InertialDampener.hpp
${FBW_COMMON}/extra-backend/Pushback/Pushback.h
${FBW_COMMON}/extra-backend/AircraftPresets/AircraftPresets.h
${FBW_COMMON}/extra-backend/AircraftPresets/PresetProcedures.h
${FBW_COMMON}/extra-backend/AircraftPresets/ProcedureStep.h
${FBW_COMMON}/extra-backend/LightingPresets/LightingPresets.h
)

# create the targets
add_library(extra-backend-a32nx OBJECT ${SOURCE_FILES} ${INCLUDE_FILES})
add_wasm_library(
NAME extra-backend-a32nx
DEPENDENCIES extra-backend-a32nx cpp-msfs-framework-a32nx
)
Loading

0 comments on commit b0e45de

Please sign in to comment.