Skip to content

Commit

Permalink
refactor: Cpp WASM Lightweight Framework
Browse files Browse the repository at this point in the history
FBW PR 7711

fix

fix
  • Loading branch information
Revyn112 committed Jan 5, 2024
1 parent b3fb664 commit 847c541
Show file tree
Hide file tree
Showing 46 changed files with 609 additions and 362 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ Cargo.toml
!jest.config.js
!/jest/**

!CMakeLists.txt
CMakeLists.txt
!CMakeLists-A333X.txt
!CMakeLists-A339X.txt
!CMakeLists-SU95X.txt

# Project folders

Expand Down Expand Up @@ -142,8 +145,9 @@ Cargo.toml
# explicit exclusions
/.env
node_modules/
obj/
target/
obj/
cmake-build*/
*.tgz
*.wasm

Expand Down
15 changes: 10 additions & 5 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
"${MSFS_SDK}/WASM/include",
"${MSFS_SDK}/WASM/wasi-sysroot/include",
"${MSFS_SDK}/SimConnect SDK/include",
"${workspaceFolder}/a32nx/fbw-common/src/wasm/fbw_common/src/**",
"${workspaceFolder}/a32nx/fbw-a32nx/src/wasm/fbw_a320/src/**",
"${workspaceFolder}/a32nx/fbw-a380x/src/wasm/fbw_a380/src/**"
"${workspaceFolder}/flybywire/fbw-common/src/wasm/fbw_common/src/**",
"${workspaceFolder}/flybywire/fbw-a32nx/src/wasm/fbw_a320/src/**",
"${workspaceFolder}/flybywire/fbw-a380x/src/wasm/fbw_a380/src/**",
"${workspaceFolder}/flybywire/fbw-common/src/wasm/cpp-msfs-framework/**",
"${workspaceFolder}/flybywire/fbw-common/src/wasm/extra-backend/**",
"${workspaceFolder}/flybywire/fbw-a32nx/src/wasm/extra-backend-a32nx/src/**",
"${workspaceFolder}/flybywire/fbw-a380x/src/wasm/extra-backend-a380x/src/**",
"${workspaceFolder}/flybywire/fbw-a32nx/src/wasm/fadec_a320/src/**",
"${workspaceFolder}/flybywire/fbw-a380x/src/wasm/fadec_a380/src/**"
],
"defines": [
"_MSFS_WASM=1",
Expand All @@ -18,13 +24,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
1 change: 1 addition & 0 deletions .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
56 changes: 56 additions & 0 deletions CMakeLists-A333X.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
cmake_minimum_required(VERSION 3.18)
project(flybywire-aircraft C CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_VERBOSE_MAKEFILE OFF)
set(FBW_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
set(FBW_COMMON ${FBW_ROOT}/build-a333x-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")

message("MSFS_SDK: " ${MSFS_SDK})

# add the include paths
include_directories(
"${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 the common components
add_subdirectory(build-a333x-common/src/wasm)

# add the A333X components
add_subdirectory(build-a333x/src/wasm)
56 changes: 56 additions & 0 deletions CMakeLists-A339X.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
cmake_minimum_required(VERSION 3.18)
project(flybywire-aircraft C CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_VERBOSE_MAKEFILE OFF)
set(FBW_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
set(FBW_COMMON ${FBW_ROOT}/build-a339x-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")

message("MSFS_SDK: " ${MSFS_SDK})

# add the include paths
include_directories(
"${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 the common components
add_subdirectory(build-a339x-common/src/wasm)

# add the A339X components
add_subdirectory(build-a339x/src/wasm)
56 changes: 56 additions & 0 deletions CMakeLists-SU95X.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
cmake_minimum_required(VERSION 3.18)
project(flybywire-aircraft C CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_VERBOSE_MAKEFILE OFF)
set(FBW_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
set(FBW_COMMON ${FBW_ROOT}/build-su95x-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")

message("MSFS_SDK: " ${MSFS_SDK})

# add the include paths
include_directories(
"${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 the common components
add_subdirectory(build-su95x-common/src/wasm)

# add the A339X components
add_subdirectory(build-su95x/src/wasm)
15 changes: 8 additions & 7 deletions a333x-igniter.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default new TaskOfTasks("all", [
new ExecTask("textures-cockpit", "npm run build-a333x:copy-textures-cockpit"),
new ExecTask("textures-fuselage", "npm run build-a333x:copy-textures-fuselage"),
new ExecTask("cargo-config", "npm run build-a333x:copy-cargo-config"),
new ExecTask("cmake-config", "npm run build-a333x:copy-cmake-config"),
], true),
new TaskOfTasks("localization", [
new ExecTask("efb-translation", "npm run build-a333x:efb-translation"),
Expand Down Expand Up @@ -129,19 +130,19 @@ export default new TaskOfTasks("all", [
"build-a333x/out/headwindsim-aircraft-a330-300/SimObjects/Airplanes/Headwind_A330_300/panel/fbw.wasm"
]),
new ExecTask("systems-terronnd", [
"build-a333x-common/src/wasm/terronnd/build.sh",
"wasm-opt -O1 --signext-lowering -o build-a333x/out/headwindsim-aircraft-a330-300/SimObjects/Airplanes/Headwind_A330_300/panel/terronnd.wasm build-a333x-common/src/wasm/terronnd/out/terronnd.wasm"
"npm run build-a333x:terronnd",
], [
"build-a333x-common/src/wasm/terronnd",
"build-a333x/out/headwindsim-aircraft-a330-300/SimObjects/Airplanes/Headwind_A330_300/panel/terronnd.wasm",
"build-a333x-common/src/wasm/terronnd/out/terronnd.wasm",
]),
new ExecTask("flypad-backend",
"npm run build-a333x:flypad-backend",
new ExecTask("extra-backend",
"npm run build-a333x:cpp-wasm-cmake",
[
"build-a333x/src/wasm/flypad-backend",
"build-a333x-common/src/wasm/fbw_common",
"build-a333x/out/headwindsim-aircraft-a330-300/SimObjects/Airplanes/Headwind_A330_300/panel/flypad-backend.wasm"
"build-a333x-common/src/wasm/cpp-msfs-framework",
"build-a333x-common/src/wasm/extra-backend",
"build-a333x/src/wasm/extra-backend-a32nx",
"build-a333x/out/headwindsim-aircraft-a330-900/SimObjects/Airplanes/Headwind_A330neo/panel/extra-backend-a32nx.wasm"
])
], true),
]),
Expand Down
15 changes: 8 additions & 7 deletions a339x-igniter.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default new TaskOfTasks("all", [
new ExecTask("textures-cockpit", "npm run build-a339x:copy-textures-cockpit"),
new ExecTask("textures-fuselage", "npm run build-a339x:copy-textures-fuselage"),
new ExecTask("cargo-config", "npm run build-a339x:copy-cargo-config"),
new ExecTask("cmake-config", "npm run build-a339x:copy-cmake-config"),
], true),
new TaskOfTasks("localization", [
new ExecTask("efb-translation", "npm run build-a339x:efb-translation"),
Expand Down Expand Up @@ -129,19 +130,19 @@ export default new TaskOfTasks("all", [
"build-a339x/out/headwindsim-aircraft-a330-900/SimObjects/Airplanes/Headwind_A330neo/panel/fbw.wasm"
]),
new ExecTask("systems-terronnd", [
"build-a339x-common/src/wasm/terronnd/build.sh",
"wasm-opt -O1 --signext-lowering -o build-a339x/out/headwindsim-aircraft-a330-900/SimObjects/Airplanes/Headwind_A330neo/panel/terronnd.wasm build-a339x-common/src/wasm/terronnd/out/terronnd.wasm"
"npm run build-a339x:terronnd",
], [
"build-a339x-common/src/wasm/terronnd",
"build-a339x/out/headwindsim-aircraft-a330-900/SimObjects/Airplanes/Headwind_A330neo/panel/terronnd.wasm",
"build-a339x-common/src/wasm/terronnd/out/terronnd.wasm",
]),
new ExecTask("flypad-backend",
"npm run build-a339x:flypad-backend",
new ExecTask("extra-backend",
"npm run build-a339x:cpp-wasm-cmake",
[
"build-a339x/src/wasm/flypad-backend",
"build-a339x-common/src/wasm/fbw_common",
"build-a339x/out/headwindsim-aircraft-a330-900/SimObjects/Airplanes/Headwind_A330neo/panel/flypad-backend.wasm"
"build-a339x-common/src/wasm/cpp-msfs-framework",
"build-a339x-common/src/wasm/extra-backend",
"build-a339x/src/wasm/extra-backend-a32nx",
"build-a339x/out/headwindsim-aircraft-a330-900/SimObjects/Airplanes/Headwind_A330neo/panel/extra-backend-a32nx.wasm"
])
], true),
]),
Expand Down
2 changes: 1 addition & 1 deletion flybywire
Submodule flybywire updated 192 files
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 hdw-a333x/src/systems/instruments/src/EFB/Efb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,28 +212,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
13 changes: 13 additions & 0 deletions hdw-a333x/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}/../../../build-a333x/out/headwindsim-aircraft-a330-300/SimObjects/Airplanes/Headwind_A330_300/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_a330)
add_subdirectory(fbw_a320)
endif ()
Loading

0 comments on commit 847c541

Please sign in to comment.