diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 0fee134c9a5..a1576db6a44 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -77,6 +77,7 @@ 1. [A32NX] Fixed appearance of FCU decals on MSFS2024 - @tracernz (Mike) 1. [FMS] Fixed issue with airport loading timing out on MSFS2024 - @tracernz (Mike) 1. [A32NX] Fixed APU fire detection - @tracernz (Mike) +1. [MSFS2024] Fix systems initialization behavior for MSFS2024 - @flogross89 (floridude) 1. [A380X/COND] Fix wasm crash during rapid decompression - @mjuhe (Miquel Juhe) ## 0.12.0 diff --git a/fbw-a32nx/docs/a320-simvars.md b/fbw-a32nx/docs/a320-simvars.md index 49e0e482316..2a9cb1b4828 100644 --- a/fbw-a32nx/docs/a320-simvars.md +++ b/fbw-a32nx/docs/a320-simvars.md @@ -35,9 +35,16 @@ ## Uncategorized -- A32NX_IS_READY +- A32NX_STARTUP_STATE - Bool - - Indicates that the JavaScript part is ready + - Indicates the startup state of the aircraft systems + - State | Value + --- | --- + Uninitialized | 0 + FltFileLoaded | 1 + ExtrasHostInitialized | 2 + InstrumentsInitialized | 3 + WasmInitialized | 4 - A32NX_IS_STATIONARY - Bool @@ -48,19 +55,19 @@ - Bool - Indicates if any GND equipment is visible or not -- A32NX_START_STATE +- A32NX_FLT_INIT_STATE - Enum - Indicates the state in which MSFS started - State | Value --- | --- - Hangar | 1 - Apron | 2 - Taxi | 3 - Runway | 4 - Climb | 5 - Cruise | 6 - Approach | 7 - Final | 8 + Hangar | 0 + Apron | 1 + Taxi | 2 + Runway | 3 + Climb | 4 + Cruise | 5 + Approach | 6 + Final | 7 - A32NX_NO_SMOKING_MEMO - Boolean that determines whether the NO SMOKING memo should be visible on the upper ECAM diff --git a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/Climb.flt b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/Climb.flt index d355eabc499..2ab59a5619c 100644 --- a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/Climb.flt +++ b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/Climb.flt @@ -118,7 +118,8 @@ FoldingWingsHandle=False FoldingWingsState=0, 0 [LocalVars.0] -A32NX_START_STATE=5 +A32NX_STARTUP_STATE=1 +A32NX_FLT_INIT_STATE=4 XMLVAR_RMP_L_On=1 XMLVAR_RMP_R_On=1 XMLVAR_Baro1_Mode=1 diff --git a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/approach.FLT b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/approach.FLT index 1e6595f0ae9..25e6fa4722e 100644 --- a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/approach.FLT +++ b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/approach.FLT @@ -118,8 +118,8 @@ FoldingWingsHandle=False FoldingWingsState=0, 0 [LocalVars.0] -A32NX_IS_READY=0 -A32NX_START_STATE=7 +A32NX_STARTUP_STATE=1 +A32NX_FLT_INIT_STATE=6 A32NX_RMP_L_TOGGLE_SWITCH=1 A32NX_RMP_R_TOGGLE_SWITCH=1 A32NX_RMP_L_SELECTED_MODE=1 diff --git a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/apron.FLT b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/apron.FLT index eff93387130..04de136be21 100644 --- a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/apron.FLT +++ b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/apron.FLT @@ -125,8 +125,8 @@ FoldingWingsState=0, 0 ExternalPowerSwitch=False [LocalVars.0] -A32NX_IS_READY=0 -A32NX_START_STATE=2 +A32NX_STARTUP_STATE=1 +A32NX_FLT_INIT_STATE=1 A32NX_RMP_L_TOGGLE_SWITCH=1 A32NX_RMP_R_TOGGLE_SWITCH=1 A32NX_RMP_L_SELECTED_MODE=1 diff --git a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/cruise.FLT b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/cruise.FLT index 04045efef29..b0453e734ce 100644 --- a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/cruise.FLT +++ b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/cruise.FLT @@ -118,8 +118,8 @@ FoldingWingsHandle=False FoldingWingsState=0, 0 [LocalVars.0] -A32NX_IS_READY=0 -A32NX_START_STATE=6 +A32NX_STARTUP_STATE=1 +A32NX_FLT_INIT_STATE=5 A32NX_RMP_L_TOGGLE_SWITCH=1 A32NX_RMP_R_TOGGLE_SWITCH=1 A32NX_RMP_L_SELECTED_MODE=1 diff --git a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/final.FLT b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/final.FLT index e1769c43dd6..9393aba33b7 100644 --- a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/final.FLT +++ b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/final.FLT @@ -114,8 +114,8 @@ LaunchBarSwitch=False SeatBeltsSwitch = True [LocalVars.0] -A32NX_IS_READY=0 -A32NX_START_STATE=8 +A32NX_STARTUP_STATE=1 +A32NX_FLT_INIT_STATE=7 A32NX_RMP_L_TOGGLE_SWITCH=1 A32NX_RMP_R_TOGGLE_SWITCH=1 A32NX_RMP_L_SELECTED_MODE=1 diff --git a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/hangar.flt b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/hangar.flt index b61b37d7804..ecc243458bc 100644 --- a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/hangar.flt +++ b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/hangar.flt @@ -122,8 +122,8 @@ FoldingWingsState=0, 0 ExternalPowerSwitch=False [LocalVars.0] -A32NX_IS_READY=0 -A32NX_START_STATE=1 +A32NX_STARTUP_STATE=1 +A32NX_FLT_INIT_STATE=0 A32NX_RMP_L_TOGGLE_SWITCH=1 A32NX_RMP_R_TOGGLE_SWITCH=1 A32NX_RMP_L_SELECTED_MODE=1 diff --git a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/runway.FLT b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/runway.FLT index 1762b763bc4..437c517da5e 100644 --- a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/runway.FLT +++ b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/runway.FLT @@ -121,8 +121,8 @@ LaunchBarSwitch=False SeatBeltsSwitch = True [LocalVars.0] -A32NX_IS_READY=0 -A32NX_START_STATE=4 +A32NX_STARTUP_STATE=1 +A32NX_FLT_INIT_STATE=3 A32NX_RMP_L_TOGGLE_SWITCH=1 A32NX_RMP_R_TOGGLE_SWITCH=1 A32NX_RMP_L_SELECTED_MODE=1 diff --git a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/taxi.flt b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/taxi.flt index 45b28fba4f7..fc9ebc14b29 100644 --- a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/taxi.flt +++ b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/SimObjects/AirPlanes/FlyByWire_A320_NEO/taxi.flt @@ -133,7 +133,8 @@ Potentiometer.96=0 Potentiometer.97=0 [LocalVars.0] -A32NX_START_STATE=3 +A32NX_STARTUP_STATE=1 +A32NX_FLT_INIT_STATE=2 A32NX_RMP_L_TOGGLE_SWITCH=1 A32NX_RMP_R_TOGGLE_SWITCH=1 A32NX_RMP_L_SELECTED_MODE=1 diff --git a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/html_ui/Pages/A32NX_Core/A32NX_TipsManager.js b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/html_ui/Pages/A32NX_Core/A32NX_TipsManager.js index 9b16500ffc6..a28620b4a72 100644 --- a/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/html_ui/Pages/A32NX_Core/A32NX_TipsManager.js +++ b/fbw-a32nx/src/base/flybywire-aircraft-a320-neo/html_ui/Pages/A32NX_Core/A32NX_TipsManager.js @@ -52,7 +52,7 @@ class A32NX_TipsManager { checkAssistenceConfiguration() { // only check when actually flying, otherwise return - if (SimVar.GetSimVarValue("L:A32NX_IS_READY", "Number") !== 1) { + if (SimVar.GetSimVarValue('L:A32NX_STARTUP_STATE', 'number') >= 3) { this.wasAnyAssistanceActive = false; return; } diff --git a/fbw-a32nx/src/systems/extras-host/index.ts b/fbw-a32nx/src/systems/extras-host/index.ts index ef203f29900..7c22aa0aac4 100644 --- a/fbw-a32nx/src/systems/extras-host/index.ts +++ b/fbw-a32nx/src/systems/extras-host/index.ts @@ -6,7 +6,7 @@ // Copyright (c) 2022 FlyByWire Simulations // SPDX-License-Identifier: GPL-3.0 -import { Clock, EventBus, HEventPublisher, InstrumentBackplane } from '@microsoft/msfs-sdk'; +import { Clock, EventBus, GameStateProvider, HEventPublisher, InstrumentBackplane } from '@microsoft/msfs-sdk'; import { ExtrasSimVarPublisher, FlightDeckBounds, @@ -17,6 +17,7 @@ import { MsfsMiscPublisher, NotificationManager, PilotSeatManager, + trySetAircraftReadyState, } from '@flybywiresim/fbw-sdk'; import { PushbuttonCheck } from 'extras-host/modules/pushbutton_check/PushbuttonCheck'; import { FlightPlanAsoboSync } from 'extras-host/modules/flightplan_sync/FlightPlanAsoboSync'; @@ -167,7 +168,7 @@ class ExtrasHost extends BaseInstrument { super.Update(); if (this.gameState !== GameState.ingame) { - const gs = this.getGameState(); + const gs = GameStateProvider.get().get(); if (gs === GameState.ingame) { this.hEventPublisher.startPublish(); this.versionCheck.startPublish(); @@ -182,6 +183,7 @@ class ExtrasHost extends BaseInstrument { this.keyInterceptor.update(); this.aircraftSync.update(); + trySetAircraftReadyState(GameStateProvider.get().get()); this.backplane.onUpdate(); } } diff --git a/fbw-a32nx/src/systems/fmgc/src/components/ReadySignal.ts b/fbw-a32nx/src/systems/fmgc/src/components/ReadySignal.ts deleted file mode 100644 index 6be99e158c0..00000000000 --- a/fbw-a32nx/src/systems/fmgc/src/components/ReadySignal.ts +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2021-2023 FlyByWire Simulations -// -// SPDX-License-Identifier: GPL-3.0 - -import { UpdateThrottler } from '@flybywiresim/fbw-sdk'; -import { FlightPlanService } from '@fmgc/flightplanning/FlightPlanService'; -import { FmgcComponent } from './FmgcComponent'; - -export class ReadySignal implements FmgcComponent { - private baseInstrument: BaseInstrument = null; - - private updateThrottler = new UpdateThrottler(1000); - - init(baseInstrument: BaseInstrument, _flightPlanService: FlightPlanService): void { - this.baseInstrument = baseInstrument; - } - - update(deltaTime: number): void { - if ( - this.updateThrottler.canUpdate(deltaTime) !== -1 && - this.baseInstrument.getGameState() === GameState.ingame && - SimVar.GetSimVarValue('L:A32NX_IS_READY', 'number') !== 1 - ) { - // set ready signal that JS code is initialized and flight is actually started - // -> user pressed 'READY TO FLY' button - SimVar.SetSimVarValue('L:A32NX_IS_READY', 'number', 1); - } - } -} diff --git a/fbw-a32nx/src/systems/fmgc/src/components/index.ts b/fbw-a32nx/src/systems/fmgc/src/components/index.ts index 72cc0ea7fdd..76000dab639 100644 --- a/fbw-a32nx/src/systems/fmgc/src/components/index.ts +++ b/fbw-a32nx/src/systems/fmgc/src/components/index.ts @@ -3,14 +3,13 @@ // SPDX-License-Identifier: GPL-3.0 import { FcuSync } from '@fmgc/components/FcuSync'; -import { ReadySignal } from '@fmgc/components/ReadySignal'; import { FlightPlanService } from '@fmgc/flightplanning/FlightPlanService'; import { FmgcComponent } from './FmgcComponent'; import { FmsMessages } from './fms-messages'; const fmsMessages = new FmsMessages(); -const components: FmgcComponent[] = [fmsMessages, new ReadySignal(), new FcuSync()]; +const components: FmgcComponent[] = [fmsMessages, new FcuSync()]; export function initComponents(baseInstrument: BaseInstrument, flightPlanService: FlightPlanService): void { components.forEach((component) => component.init(baseInstrument, flightPlanService)); diff --git a/fbw-a32nx/src/systems/shared/src/flightphase.ts b/fbw-a32nx/src/systems/shared/src/flightphase.ts index 9af8c9de636..b7ebd925f51 100644 --- a/fbw-a32nx/src/systems/shared/src/flightphase.ts +++ b/fbw-a32nx/src/systems/shared/src/flightphase.ts @@ -2,6 +2,7 @@ // // SPDX-License-Identifier: GPL-3.0 +import { getStartupState, StartupState } from '@flybywiresim/fbw-sdk'; import { VerticalMode } from '@shared/autopilot'; export enum FmgcFlightPhase { @@ -16,7 +17,7 @@ export enum FmgcFlightPhase { } export function isReady(): boolean { - return SimVar.GetSimVarValue('L:A32NX_IS_READY', 'number') === 1; + return getStartupState() >= StartupState.InstrumentsInitialized; } export function isSlewActive(): boolean { diff --git a/fbw-a32nx/src/wasm/fadec_a32nx/src/Fadec/EngineControlA32NX.cpp b/fbw-a32nx/src/wasm/fadec_a32nx/src/Fadec/EngineControlA32NX.cpp index 09e20bfe5f9..46a921d7bd4 100644 --- a/fbw-a32nx/src/wasm/fadec_a32nx/src/Fadec/EngineControlA32NX.cpp +++ b/fbw-a32nx/src/wasm/fadec_a32nx/src/Fadec/EngineControlA32NX.cpp @@ -219,7 +219,7 @@ void EngineControl_A32NX::initializeEngineControlData() { const double rightAuxQuantity = simData.simVarsDataPtr->data().fuelTankQuantityRightAux; // gal // only loads saved fuel quantity on C/D spawn - if (simData.startState->updateFromSim(timeStamp, tickCounter) == 2) { + if (simData.fltInitState->updateFromSim(timeStamp, tickCounter) == 2) { // Load fuel configuration from file fuelConfiguration.setConfigFilename(FILENAME_FADEC_CONF_DIRECTORY + atcId + FILENAME_FADEC_CONF_FILE_EXTENSION); fuelConfiguration.loadConfigurationFromIni(); diff --git a/fbw-a32nx/src/wasm/fadec_a32nx/src/Fadec/FadecSimData_A32NX.hpp b/fbw-a32nx/src/wasm/fadec_a32nx/src/Fadec/FadecSimData_A32NX.hpp index ca36c1fa4fc..39f21e011dd 100644 --- a/fbw-a32nx/src/wasm/fadec_a32nx/src/Fadec/FadecSimData_A32NX.hpp +++ b/fbw-a32nx/src/wasm/fadec_a32nx/src/Fadec/FadecSimData_A32NX.hpp @@ -212,7 +212,7 @@ class FadecSimData_A32NX { NamedVariablePtr packsState[2]; NamedVariablePtr refuelRate; NamedVariablePtr refuelStartedByUser; - NamedVariablePtr startState; + NamedVariablePtr fltInitState; NamedVariablePtr thrustLimitClimb; NamedVariablePtr thrustLimitFlex; NamedVariablePtr thrustLimitIdle; @@ -289,7 +289,7 @@ class FadecSimData_A32NX { void initLvars(DataManager* dm) { // TODO: consider DataDefinition for the groups tha are read/write each tick - startState = dm->make_named_var("A32NX_START_STATE", UNITS.Number, NO_AUTO_UPDATE); + fltInitState = dm->make_named_var("A32NX_FLT_INIT_STATE", UNITS.Number, NO_AUTO_UPDATE); engineEgt[L] = dm->make_named_var("A32NX_ENGINE_EGT:1", UNITS.Number, AUTO_READ_WRITE); engineEgt[R] = dm->make_named_var("A32NX_ENGINE_EGT:2", UNITS.Number, AUTO_READ_WRITE); diff --git a/fbw-a32nx/src/wasm/fbw_a320/src/FlyByWireInterface.cpp b/fbw-a32nx/src/wasm/fbw_a320/src/FlyByWireInterface.cpp index b81e6b791b0..caa25d75636 100644 --- a/fbw-a32nx/src/wasm/fbw_a320/src/FlyByWireInterface.cpp +++ b/fbw-a32nx/src/wasm/fbw_a320/src/FlyByWireInterface.cpp @@ -70,6 +70,10 @@ bool FlyByWireInterface::update(double sampleTime) { // get sim data SimData simData = simConnectInterface.getSimData(); + if (idStartupState->get() < 3) { + return result; + } + // update performance monitoring result &= updatePerformanceMonitoring(sampleTime); @@ -86,7 +90,7 @@ bool FlyByWireInterface::update(double sampleTime) { if (simData.slew_on) { wasInSlew = true; return result; - } else if (pauseDetected || simData.cameraState >= 10.0 || !idIsReady->get() || simData.simulationTime < 2) { + } else if (pauseDetected || simData.cameraState >= 10.0 || simData.simulationTime < 2) { return result; } @@ -283,8 +287,8 @@ void FlyByWireInterface::loadConfiguration() { void FlyByWireInterface::setupLocalVariables() { // regsiter L variable for init state and ready signal - idIsReady = std::make_unique("A32NX_IS_READY"); - idStartState = std::make_unique("A32NX_START_STATE"); + idStartupState = std::make_unique("A32NX_STARTUP_STATE"); + idFltInitState = std::make_unique("A32NX_FLT_INIT_STATE"); // regsiter L variable for logging idLoggingFlightControlsEnabled = std::make_unique("A32NX_LOGGING_FLIGHT_CONTROLS_ENABLED"); @@ -833,7 +837,7 @@ void FlyByWireInterface::setupLocalVariables() { bool FlyByWireInterface::handleFcuInitialization(double sampleTime) { // init should be run only once and only when is ready is signaled - if (wasFcuInitialized || !idIsReady->get()) { + if (wasFcuInitialized || idStartupState->get() < 3) { return true; } @@ -849,7 +853,7 @@ bool FlyByWireInterface::handleFcuInitialization(double sampleTime) { auto timeSinceReady = simData.simulationTime - simulationTimeReady; // determine if we need to run init code - if (idStartState->get() >= 5 && timeSinceReady > 6.0) { + if (idFltInitState->get() >= 5 && timeSinceReady > 6.0) { // init FCU for in flight configuration long targetAltitude = simData.H_ind_ft; long targetHeading = std::fmod(simData.Psi_magnetic_deg, 360.0); @@ -860,7 +864,7 @@ bool FlyByWireInterface::handleFcuInitialization(double sampleTime) { simConnectInterface.sendEvent(SimConnectInterface::A32NX_FCU_VS_SET, simData.H_ind_ft < targetAltitude ? 1000 : -1000); simConnectInterface.sendEvent(SimConnectInterface::A32NX_FCU_VS_PULL); wasFcuInitialized = true; - } else if (idStartState->get() == 4 && timeSinceReady > 1.0) { + } else if (idFltInitState->get() == 4 && timeSinceReady > 1.0) { // init FCU for on runway -> ready for take-off simConnectInterface.sendEvent(SimConnectInterface::A32NX_FCU_ALT_SET, 15000); wasFcuInitialized = true; diff --git a/fbw-a32nx/src/wasm/fbw_a320/src/FlyByWireInterface.h b/fbw-a32nx/src/wasm/fbw_a320/src/FlyByWireInterface.h index 5e0aa06ba7f..8551c4ff091 100644 --- a/fbw-a32nx/src/wasm/fbw_a320/src/FlyByWireInterface.h +++ b/fbw-a32nx/src/wasm/fbw_a320/src/FlyByWireInterface.h @@ -168,8 +168,8 @@ class FlyByWireInterface { bool wasFcuInitialized = false; double simulationTimeReady = 0.0; - std::unique_ptr idIsReady; - std::unique_ptr idStartState; + std::unique_ptr idStartupState; + std::unique_ptr idFltInitState; bool developmentLocalVariablesEnabled = false; bool useCalculatedLocalizerAndGlideSlope = false; diff --git a/fbw-a32nx/src/wasm/systems/a320_systems/src/hydraulic/mod.rs b/fbw-a32nx/src/wasm/systems/a320_systems/src/hydraulic/mod.rs index 5f6c646c7b7..d7d3788e7be 100644 --- a/fbw-a32nx/src/wasm/systems/a320_systems/src/hydraulic/mod.rs +++ b/fbw-a32nx/src/wasm/systems/a320_systems/src/hydraulic/mod.rs @@ -71,8 +71,8 @@ use systems::{ ReservoirAirPressure, ReverserPosition, SectionPressure, TrimmableHorizontalStabilizer, }, simulation::{ - InitContext, Read, Reader, SimulationElement, SimulationElementVisitor, SimulatorReader, - SimulatorWriter, StartState, UpdateContext, VariableIdentifier, Write, + FltInitState, InitContext, Read, Reader, SimulationElement, SimulationElementVisitor, + SimulatorReader, SimulatorWriter, UpdateContext, VariableIdentifier, Write, }, }; @@ -808,8 +808,8 @@ impl A320RudderFactory { } fn new_rudder(context: &mut InitContext) -> RudderAssembly { - let init_at_center = context.start_state() == StartState::Taxi - || context.start_state() == StartState::Runway + let init_at_center = context.flt_init_state() == FltInitState::Taxi + || context.flt_init_state() == FltInitState::Runway || context.is_in_flight(); let assembly = Self::a320_rudder_assembly(context, init_at_center); @@ -6619,10 +6619,10 @@ mod tests { test_bed: SimulationTestBed, } impl A320HydraulicsTestBed { - fn new_with_start_state(start_state: StartState) -> Self { + fn new_with_flt_init_state(flt_init_state: FltInitState) -> Self { Self { - test_bed: SimulationTestBed::new_with_start_state( - start_state, + test_bed: SimulationTestBed::new_with_flt_init_state( + flt_init_state, A320HydraulicsTestAircraft::new, ), } @@ -7592,11 +7592,11 @@ mod tests { } fn test_bed_on_ground() -> A320HydraulicsTestBed { - A320HydraulicsTestBed::new_with_start_state(StartState::Apron) + A320HydraulicsTestBed::new_with_flt_init_state(FltInitState::Apron) } fn test_bed_in_flight() -> A320HydraulicsTestBed { - A320HydraulicsTestBed::new_with_start_state(StartState::Cruise) + A320HydraulicsTestBed::new_with_flt_init_state(FltInitState::Cruise) } fn test_bed_on_ground_with() -> A320HydraulicsTestBed { diff --git a/fbw-a32nx/src/wasm/systems/a320_systems_wasm/src/lib.rs b/fbw-a32nx/src/wasm/systems/a320_systems_wasm/src/lib.rs index 6dc95e07487..f0a3ee31962 100644 --- a/fbw-a32nx/src/wasm/systems/a320_systems_wasm/src/lib.rs +++ b/fbw-a32nx/src/wasm/systems/a320_systems_wasm/src/lib.rs @@ -36,14 +36,25 @@ use systems_wasm::aspects::ExecuteOn; use systems_wasm::{MsfsSimulationBuilder, Variable}; use trimmable_horizontal_stabilizer::trimmable_horizontal_stabilizer; +use ::msfs::legacy::NamedVariable; + #[msfs::gauge(name=systems)] async fn systems(mut gauge: msfs::Gauge) -> Result<(), Box> { let mut sim_connect = gauge.open_simconnect("systems")?; + while let Some(_event) = gauge.next_event().await { + // Uses deprecated method, FIXME improve + let startup_state: f64 = NamedVariable::from("A32NX_STARTUP_STATE").get_value(); + + if startup_state >= 3.0 { + break; + } + } + let key_prefix = "A32NX_"; let (mut simulation, mut handler) = MsfsSimulationBuilder::new( key_prefix, - Variable::named(&format!("{}START_STATE", key_prefix)), + Variable::named(&format!("{}FLT_INIT_STATE", key_prefix)), sim_connect.as_mut().get_mut(), ) .with_electrical_buses([ @@ -450,6 +461,9 @@ async fn systems(mut gauge: msfs::Gauge) -> Result<(), Box> { .with_aspect(trimmable_horizontal_stabilizer)? .build(A320::new)?; + // FIXME improve + NamedVariable::from("A32NX_STARTUP_STATE").set_value(4.0); + while let Some(event) = gauge.next_event().await { handler.handle(event, &mut simulation, sim_connect.as_mut().get_mut())?; } diff --git a/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/Climb.flt b/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/Climb.flt index d4088ecc560..78db792a710 100644 --- a/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/Climb.flt +++ b/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/Climb.flt @@ -241,6 +241,7 @@ FoldingWingsState=0, 0 PayloadList=1296.3,4629.7,7037.2,8703.8,7037.2,7777.9,7037.2,6296.4,7037.2,7037.2,2222.3,5370.5,4629.7,3148.2,10491.8,7456.0, 923.7, 1.0, 1.0 [LocalVars.0] +A32NX_STARTUP_STATE=1 A32NX_CARGO_FWD=4759 A32NX_CARGO_FWD_DESIRED=4759 A32NX_CARGO_AFT=3382 diff --git a/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/approach.FLT b/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/approach.FLT index 9116d6cfd33..4f59db726ab 100644 --- a/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/approach.FLT +++ b/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/approach.FLT @@ -68,8 +68,8 @@ PropellerLeverPct=0.99993896484375 MixtureLeverPct=0.99993896484375 Pct Engine RPM=1.0212241491806894889 MaxReachedEngineRPM=30977.098735072664567 -LeftMagneto=False -RightMagneto=False +LeftMagneto=True +RightMagneto=True GeneratorSwitch=True CowlFlapPct=0 FuelPumpSwitch=False @@ -108,8 +108,8 @@ PropellerLeverPct=0.99993896484375 MixtureLeverPct=0.99993896484375 Pct Engine RPM=1.0212241491806894889 MaxReachedEngineRPM=30977.098735072664567 -LeftMagneto=False -RightMagneto=False +LeftMagneto=True +RightMagneto=True GeneratorSwitch=True CowlFlapPct=0 FuelPumpSwitch=False @@ -230,6 +230,8 @@ SeatBeltsSwitch=True PayloadList=1296.3,4629.7,7037.2,8703.8,7037.2,7777.9,7037.2,6296.4,7037.2,7037.2,2222.3,5370.5,4629.7,3148.2,10491.8,7456.0, 923.7, 1.0, 1.0 [LocalVars.0] +A32NX_STARTUP_STATE=1 +A32NX_FLT_INIT_STATE=6 A320_Neo_AIRCOND_LVL_1=50 A320_Neo_AIRCOND_LVL_2=50 A320_Neo_AIRCOND_LVL_3=50 diff --git a/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/apron.FLT b/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/apron.FLT index 90b2bbcdc89..1dd908320ed 100644 --- a/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/apron.FLT +++ b/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/apron.FLT @@ -229,6 +229,8 @@ ExternalPowerSwitch=False SeatBeltsSwitch=False [LocalVars.0] +A32NX_STARTUP_STATE=1 +A32NX_FLT_INIT_STATE=1 A320_Neo_AIRCOND_LVL_1=50 A320_Neo_AIRCOND_LVL_2=50 A320_Neo_AIRCOND_LVL_3=50 @@ -398,7 +400,6 @@ A32NX_RCDR_TEST = 0 A32NX_SEC_1_PUSHBUTTON_PRESSED=1 A32NX_SEC_2_PUSHBUTTON_PRESSED=1 A32NX_SEC_3_PUSHBUTTON_PRESSED=1 -A32NX_START_STATE=2 A32NX_SVGEINT_OVRD_ON = 0 A32NX_SWITCH_TCAS_TRAFFIC_POSITION = 2 A32NX_VENTILATION_BLOWER_FAULT=0 diff --git a/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/cruise.FLT b/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/cruise.FLT index 4dd57bcbfbd..e2c957bba9d 100644 --- a/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/cruise.FLT +++ b/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/cruise.FLT @@ -68,8 +68,8 @@ PropellerLeverPct=0.99993896484375 MixtureLeverPct=0.99993896484375 Pct Engine RPM=1.0212241491806894889 MaxReachedEngineRPM=30977.098735072664567 -LeftMagneto=False -RightMagneto=False +LeftMagneto=True +RightMagneto=True GeneratorSwitch=True CowlFlapPct=0 FuelPumpSwitch=False @@ -108,8 +108,8 @@ PropellerLeverPct=0.99993896484375 MixtureLeverPct=0.99993896484375 Pct Engine RPM=1.0212241491806894889 MaxReachedEngineRPM=30977.098735072664567 -LeftMagneto=False -RightMagneto=False +LeftMagneto=True +RightMagneto=True GeneratorSwitch=True CowlFlapPct=0 FuelPumpSwitch=False @@ -241,6 +241,8 @@ FoldingWingsState=0, 0 PayloadList=1296.3,4629.7,7037.2,8703.8,7037.2,7777.9,7037.2,6296.4,7037.2,7037.2,2222.3,5370.5,4629.7,3148.2,10491.8,7456.0, 923.7, 1.0, 1.0 [LocalVars.0] +A32NX_STARTUP_STATE=1 +A32NX_FLT_INIT_STATE=5 A320_Neo_AIRCOND_LVL_1=50 A320_Neo_AIRCOND_LVL_2=50 A320_Neo_AIRCOND_LVL_3=50 @@ -445,7 +447,6 @@ A32NX_RCDR_TEST = 0 A32NX_SEC_1_PUSHBUTTON_PRESSED=1 A32NX_SEC_2_PUSHBUTTON_PRESSED=1 A32NX_SEC_3_PUSHBUTTON_PRESSED=1 -A32NX_START_STATE=6 A32NX_SVGEINT_OVRD_ON = 0 A32NX_SWITCH_RADAR_PWS_Position=1 A32NX_SWITCH_TCAS_Position=2 diff --git a/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/final.FLT b/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/final.FLT index 16356f66811..c45317dbd88 100644 --- a/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/final.FLT +++ b/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/final.FLT @@ -67,8 +67,8 @@ PropellerLeverPct=0.99993896484375 MixtureLeverPct=0.99993896484375 Pct Engine RPM=0.94985740212390790127 MaxReachedEngineRPM=30977.098735072664567 -LeftMagneto=False -RightMagneto=False +LeftMagneto=True +RightMagneto=True GeneratorSwitch=True CowlFlapPct=0 FuelPumpSwitch=False @@ -107,8 +107,8 @@ PropellerLeverPct=0.99993896484375 MixtureLeverPct=0.99993896484375 Pct Engine RPM=0.94985740212390790127 MaxReachedEngineRPM=30977.098735072664567 -LeftMagneto=False -RightMagneto=False +LeftMagneto=True +RightMagneto=True GeneratorSwitch=True CowlFlapPct=0 FuelPumpSwitch=False @@ -240,6 +240,8 @@ FoldingWingsState=0, 0 PayloadList=1296.3,4629.7,7037.2,8703.8,7037.2,7777.9,7037.2,6296.4,7037.2,7037.2,2222.3,5370.5,4629.7,3148.2,10491.8,7456.0, 923.7, 1.0, 1.0 [LocalVars.0] +A32NX_STARTUP_STATE=1 +A32NX_FLT_INIT_STATE=7 A320_NEO_CDU_START_PAGE=35 A320_Neo_AIRCOND_LVL_1=50 A320_Neo_AIRCOND_LVL_2=50 @@ -445,7 +447,6 @@ A32NX_SEC_1_PUSHBUTTON_PRESSED=1 A32NX_SEC_2_PUSHBUTTON_PRESSED=1 A32NX_SEC_3_PUSHBUTTON_PRESSED=1 A32NX_SPOILERS_ARMED=1 -A32NX_START_STATE=8 A32NX_SVGEINT_OVRD_ON = 0 A32NX_SWITCH_RADAR_PWS_Position=1 A32NX_SWITCH_TCAS_Position=2 diff --git a/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/hangar.flt b/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/hangar.flt index c71e1659bff..6443b2c99a9 100644 --- a/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/hangar.flt +++ b/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/hangar.flt @@ -222,6 +222,8 @@ FoldingWingsState=0, 0 ExternalPowerSwitch=False [LocalVars.0] +A32NX_STARTUP_STATE=1 +A32NX_FLT_INIT_STATE=0 A320_Neo_AIRCOND_LVL_1=50 A320_Neo_AIRCOND_LVL_2=50 A320_Neo_AIRCOND_LVL_3=50 @@ -366,7 +368,6 @@ A32NX_RMP_R_VHF3_STANDBY_FREQUENCY=136975000 A32NX_SEC_1_PUSHBUTTON_PRESSED=1 A32NX_SEC_2_PUSHBUTTON_PRESSED=1 A32NX_SEC_3_PUSHBUTTON_PRESSED=1 -A32NX_START_STATE=1 A32NX_SWITCH_RADAR_PWS_Position=0 A32NX_SWITCH_TCAS_TRAFFIC_POSITION = 2 A32NX_VENTILATION_BLOWER_FAULT=0 diff --git a/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/runway.FLT b/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/runway.FLT index 3ed8bf06a99..55faf57af14 100644 --- a/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/runway.FLT +++ b/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/runway.FLT @@ -76,8 +76,8 @@ Pct Engine RPM=0.64930165515681026456 MaxReachedEngineRPM=28088.712374471313524 Pct N1=21 Pct N2=55 -LeftMagneto=False -RightMagneto=False +LeftMagneto=True +RightMagneto=True GeneratorSwitch=True CowlFlapPct=0 FuelPumpSwitch=False @@ -118,8 +118,8 @@ Pct Engine RPM=0.64930165515681026456 MaxReachedEngineRPM=28088.712374471313524 Pct N1=21 Pct N2=55 -LeftMagneto=False -RightMagneto=False +LeftMagneto=True +RightMagneto=True GeneratorSwitch=True CowlFlapPct=0 FuelPumpSwitch=False @@ -250,6 +250,8 @@ FoldingWingsState=0, 0 PayloadList=1296.3,4629.7,7037.2,8703.8,7037.2,7777.9,7037.2,6296.4,7037.2,7037.2,2222.3,5370.5,4629.7,3148.2,10491.8,7456.0, 923.7, 1.0, 1.0 [LocalVars.0] +A32NX_STARTUP_STATE=1 +A32NX_FLT_INIT_STATE=3 A32NX_AIDS_PRINT_ON = 0 A32NX_AIR_DATA_SWITCHING_KNOB=1 A32NX_APU_AUTOEXITING_RESET = 0 @@ -458,7 +460,6 @@ A32NX_SEC_3_PUSHBUTTON_PRESSED=1 A32NX_FLAPS_HANDLE_INDEX=1 A32NX_FLAPS_HANDLE_PERCENT=0.25 A32NX_SPOILERS_ARMED=1 -A32NX_START_STATE=4 A32NX_SVGEINT_OVRD_ON = 0 A32NX_SWITCH_RADAR_PWS_Position=1 A32NX_SWITCH_TCAS_Position=2 diff --git a/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/taxi.flt b/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/taxi.flt index 09d5a59943c..aeecea686cf 100644 --- a/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/taxi.flt +++ b/fbw-a380x/src/base/flybywire-aircraft-a380-842/SimObjects/AirPlanes/FlyByWire_A380_842/taxi.flt @@ -71,8 +71,8 @@ PropellerLeverPct=1 MixtureLeverPct=1 Pct Engine RPM=0.64930165515681026456 MaxReachedEngineRPM=28088.712374471313524 -LeftMagneto=False -RightMagneto=False +LeftMagneto=True +RightMagneto=True GeneratorSwitch=True CowlFlapPct=0 FuelPumpSwitch=False @@ -107,8 +107,8 @@ PropellerLeverPct=1 MixtureLeverPct=1 Pct Engine RPM=0.64930165515681026456 MaxReachedEngineRPM=28088.712374471313524 -LeftMagneto=False -RightMagneto=False +LeftMagneto=True +RightMagneto=True GeneratorSwitch=True CowlFlapPct=0 FuelPumpSwitch=False @@ -243,6 +243,7 @@ Potentiometer.99=0.5 PayloadList=1296.3,4629.7,7037.2,8703.8,7037.2,7777.9,7037.2,6296.4,7037.2,7037.2,2222.3,5370.5,4629.7,3148.2,10491.8,7456.0, 923.7, 1.0, 1.0 [LocalVars.0] +A32NX_STARTUP_STATE=1 A320_Neo_AIRCOND_LVL_1=50 A320_Neo_AIRCOND_LVL_2=50 A320_Neo_AIRCOND_LVL_3=50 @@ -437,7 +438,7 @@ A32NX_RCDR_TEST = 0 A32NX_SEC_1_PUSHBUTTON_PRESSED=1 A32NX_SEC_2_PUSHBUTTON_PRESSED=1 A32NX_SEC_3_PUSHBUTTON_PRESSED=1 -A32NX_START_STATE=3 +A32NX_FLT_INIT_STATE=2 A32NX_SVGEINT_OVRD_ON = 0 A32NX_SWITCH_TCAS_TRAFFIC_POSITION = 2 A32NX_THS_GREEN_SERVO_SOLENOID_ENERGIZED=1 diff --git a/fbw-a380x/src/systems/extras-host/index.ts b/fbw-a380x/src/systems/extras-host/index.ts index 178e7003756..04231e1dc3f 100644 --- a/fbw-a380x/src/systems/extras-host/index.ts +++ b/fbw-a380x/src/systems/extras-host/index.ts @@ -1,7 +1,7 @@ // Copyright (c) 2022 FlyByWire Simulations // SPDX-License-Identifier: GPL-3.0 -import { Clock, EventBus, HEventPublisher, InstrumentBackplane } from '@microsoft/msfs-sdk'; +import { Clock, EventBus, GameStateProvider, HEventPublisher, InstrumentBackplane } from '@microsoft/msfs-sdk'; import { FlightDeckBounds, NotificationManager, @@ -12,6 +12,7 @@ import { MsfsFlightModelPublisher, MsfsMiscPublisher, GroundSupportPublisher, + trySetAircraftReadyState, } from '@flybywiresim/fbw-sdk'; import { PushbuttonCheck } from 'extras-host/modules/pushbutton_check/PushbuttonCheck'; import { KeyInterceptor } from './modules/key_interceptor/KeyInterceptor'; @@ -155,7 +156,7 @@ class ExtrasHost extends BaseInstrument { super.Update(); if (this.gameState !== GameState.ingame) { - const gs = this.getGameState(); + const gs = GameStateProvider.get().get(); if (gs === GameState.ingame) { // Start the modules this.hEventPublisher.startPublish(); @@ -163,14 +164,11 @@ class ExtrasHost extends BaseInstrument { this.keyInterceptor.startPublish(); this.aircraftSync.startPublish(); this.telexCheck.showPopup(); - - // Signal that the aircraft is ready via L:A32NX_IS_READY - SimVar.SetSimVarValue('L:A32NX_IS_READY', 'number', 1); - console.log('A380X_EXTRASHOST: Aircraft is ready'); } this.gameState = gs; } + trySetAircraftReadyState(GameStateProvider.get().get()); this.backplane.onUpdate(); } } diff --git a/fbw-a380x/src/systems/instruments/src/AtcMailbox/instrument.tsx b/fbw-a380x/src/systems/instruments/src/AtcMailbox/instrument.tsx index 21404330143..82e056e7502 100644 --- a/fbw-a380x/src/systems/instruments/src/AtcMailbox/instrument.tsx +++ b/fbw-a380x/src/systems/instruments/src/AtcMailbox/instrument.tsx @@ -7,7 +7,7 @@ import { FsBaseInstrument, ClockPublisher, } from '@microsoft/msfs-sdk'; -import { FailuresConsumer } from '@flybywiresim/fbw-sdk'; +import { FailuresConsumer, getStartupState, StartupState } from '@flybywiresim/fbw-sdk'; import { AtcMailbox } from 'instruments/src/AtcMailbox/AtcMailbox'; class AtcMailboxInstrument implements FsInstrument { @@ -45,8 +45,10 @@ class AtcMailboxInstrument implements FsInstrument { * A callback called when the instrument gets a frame update. */ public Update(): void { - this.backplane.onUpdate(); - this.failuresConsumer.update(); + if (getStartupState() >= StartupState.InstrumentsInitialized) { + this.backplane.onUpdate(); + this.failuresConsumer.update(); + } } public onInteractionEvent(args: string[]): void { diff --git a/fbw-a380x/src/systems/instruments/src/Clock/instrument.tsx b/fbw-a380x/src/systems/instruments/src/Clock/instrument.tsx index 8482b46eb40..08402567f7f 100644 --- a/fbw-a380x/src/systems/instruments/src/Clock/instrument.tsx +++ b/fbw-a380x/src/systems/instruments/src/Clock/instrument.tsx @@ -2,6 +2,7 @@ import { EventBus, FSComponent, HEventPublisher } from '@microsoft/msfs-sdk'; import { ClockRoot, ClockSimvarPublisher } from '@flybywiresim/clock'; import './Clock.scss'; +import { getStartupState, StartupState } from '@flybywiresim/fbw-sdk'; // eslint-disable-next-line camelcase class A380X_Clock extends BaseInstrument { @@ -11,13 +12,7 @@ class A380X_Clock extends BaseInstrument { private simVarPublisher: ClockSimvarPublisher; - /** - * "mainmenu" = 0 - * "loading" = 1 - * "briefing" = 2 - * "ingame" = 3 - */ - private gameState = 0; + private startupState = 0; constructor() { super(); @@ -64,13 +59,12 @@ class A380X_Clock extends BaseInstrument { public Update(): void { super.Update(); - if (this.gameState !== 3) { - const gamestate = this.getGameState(); - if (gamestate === 3) { - this.simVarPublisher.startPublish(); - } - this.gameState = gamestate; - } else { + this.startupState = getStartupState(); + if (this.startupState === StartupState.ExtrasHostInitialized) { + this.simVarPublisher.startPublish(); + } + + if (this.startupState >= StartupState.InstrumentsInitialized) { this.simVarPublisher.onUpdate(); } } diff --git a/fbw-a380x/src/systems/instruments/src/EWD/instrument.tsx b/fbw-a380x/src/systems/instruments/src/EWD/instrument.tsx index 054a5d4454e..8e8ccf36d72 100644 --- a/fbw-a380x/src/systems/instruments/src/EWD/instrument.tsx +++ b/fbw-a380x/src/systems/instruments/src/EWD/instrument.tsx @@ -9,7 +9,7 @@ import { EwdSimvarPublisher } from './shared/EwdSimvarPublisher'; import '../index.scss'; import './style.scss'; import { EngineWarningDisplay } from 'instruments/src/EWD/EWD'; -import { ArincEventBus } from '@flybywiresim/fbw-sdk'; +import { ArincEventBus, getStartupState, StartupState } from '@flybywiresim/fbw-sdk'; class A380X_EWD extends BaseInstrument { private readonly bus = new ArincEventBus(); @@ -52,7 +52,9 @@ class A380X_EWD extends BaseInstrument { public Update(): void { super.Update(); - this.backplane.onUpdate(); + if (getStartupState() >= StartupState.InstrumentsInitialized) { + this.backplane.onUpdate(); + } } } diff --git a/fbw-a380x/src/systems/instruments/src/FCU/FcuFsInstrument.tsx b/fbw-a380x/src/systems/instruments/src/FCU/FcuFsInstrument.tsx index f56c20379e1..50218d19b3e 100644 --- a/fbw-a380x/src/systems/instruments/src/FCU/FcuFsInstrument.tsx +++ b/fbw-a380x/src/systems/instruments/src/FCU/FcuFsInstrument.tsx @@ -13,7 +13,13 @@ import { Subject, SubscribableMapFunctions, } from '@microsoft/msfs-sdk'; -import { FailuresConsumer, MsfsAutopilotAssitancePublisher, MsfsRadioNavigationPublisher } from '@flybywiresim/fbw-sdk'; +import { + FailuresConsumer, + getStartupState, + MsfsAutopilotAssitancePublisher, + MsfsRadioNavigationPublisher, + StartupState, +} from '@flybywiresim/fbw-sdk'; import { FcuDisplay } from './Components/FcuDisplay'; import { AltitudeManager } from './Managers/AltitudeManager'; import { AutopilotManager } from './Managers/AutopilotManager'; @@ -92,7 +98,9 @@ export class FcuFsInstrument implements FsInstrument { this.failuresConsumer.update(); // this.isFailed.set(this.failuresConsumer.isActive(this.isFailedKey));; - this.backplane.onUpdate(); + if (getStartupState() >= StartupState.InstrumentsInitialized) { + this.backplane.onUpdate(); + } } /** @inheritdoc */ diff --git a/fbw-a380x/src/systems/instruments/src/MFD/instrument.tsx b/fbw-a380x/src/systems/instruments/src/MFD/instrument.tsx index 1a385f1afaf..34479430890 100644 --- a/fbw-a380x/src/systems/instruments/src/MFD/instrument.tsx +++ b/fbw-a380x/src/systems/instruments/src/MFD/instrument.tsx @@ -11,7 +11,7 @@ import { FmcService } from 'instruments/src/MFD/FMC/FmcService'; import { FmcServiceInterface } from 'instruments/src/MFD/FMC/FmcServiceInterface'; import { MfdComponent } from './MFD'; import { MfdSimvarPublisher } from './shared/MFDSimvarPublisher'; -import { FailuresConsumer } from '@flybywiresim/fbw-sdk'; +import { FailuresConsumer, getStartupState, StartupState } from '@flybywiresim/fbw-sdk'; import { A380Failure } from '@failures'; import { FGDataPublisher } from '../MsfsAvionicsCommon/providers/FGDataPublisher'; import { FmsMfdPublisher } from '../MsfsAvionicsCommon/providers/FmsMfdPublisher'; @@ -104,8 +104,10 @@ class MfdInstrument implements FsInstrument { * A callback called when the instrument gets a frame update. */ public Update(): void { - this.backplane.onUpdate(); - this.failuresConsumer.update(); + if (getStartupState() >= StartupState.InstrumentsInitialized) { + this.failuresConsumer.update(); + this.backplane.onUpdate(); + } } public onInteractionEvent(args: string[]): void { diff --git a/fbw-a380x/src/systems/instruments/src/ND/instrument.tsx b/fbw-a380x/src/systems/instruments/src/ND/instrument.tsx index 286a01720a1..0ff134e165e 100644 --- a/fbw-a380x/src/systems/instruments/src/ND/instrument.tsx +++ b/fbw-a380x/src/systems/instruments/src/ND/instrument.tsx @@ -24,6 +24,8 @@ import { FcuBusPublisher, FcuSimVars, FmsOansSimvarPublisher, + getStartupState, + StartupState, } from '@flybywiresim/fbw-sdk'; import { NDComponent } from '@flybywiresim/navigation-display'; import { @@ -375,10 +377,12 @@ class NDInstrument implements FsInstrument { * A callback called when the instrument gets a frame update. */ public Update(): void { - this.backplane.onUpdate(); + if (getStartupState() >= StartupState.InstrumentsInitialized) { + this.backplane.onUpdate(); - if (this.oansRef.getOrDefault()) { - this.oansRef.instance.Update(); + if (this.oansRef.getOrDefault()) { + this.oansRef.instance.Update(); + } } } diff --git a/fbw-a380x/src/systems/instruments/src/PFD/instrument.tsx b/fbw-a380x/src/systems/instruments/src/PFD/instrument.tsx index 65d2d60da84..34bcde2e2fd 100644 --- a/fbw-a380x/src/systems/instruments/src/PFD/instrument.tsx +++ b/fbw-a380x/src/systems/instruments/src/PFD/instrument.tsx @@ -1,5 +1,5 @@ import { Clock, FSComponent, HEventPublisher, InstrumentBackplane, Subject } from '@microsoft/msfs-sdk'; -import { ArincEventBus, EfisSide } from '@flybywiresim/fbw-sdk'; +import { ArincEventBus, EfisSide, getStartupState, StartupState } from '@flybywiresim/fbw-sdk'; import { getDisplayIndex } from 'instruments/src/MsfsAvionicsCommon/CdsDisplayUnit'; import { DmcPublisher } from 'instruments/src/MsfsAvionicsCommon/providers/DmcPublisher'; import { FmsDataPublisher } from 'instruments/src/MsfsAvionicsCommon/providers/FmsDataPublisher'; @@ -95,7 +95,9 @@ class A380X_PFD extends BaseInstrument { public Update(): void { super.Update(); - this.backplane.onUpdate(); + if (getStartupState() >= StartupState.InstrumentsInitialized) { + this.backplane.onUpdate(); + } } } diff --git a/fbw-a380x/src/systems/instruments/src/RMP/instrument.tsx b/fbw-a380x/src/systems/instruments/src/RMP/instrument.tsx index 6a2639a7fe7..3d96f3af841 100644 --- a/fbw-a380x/src/systems/instruments/src/RMP/instrument.tsx +++ b/fbw-a380x/src/systems/instruments/src/RMP/instrument.tsx @@ -11,7 +11,7 @@ import { Subject, } from '@microsoft/msfs-sdk'; -import { ArincEventBus, VhfComIndices } from '@flybywiresim/fbw-sdk'; +import { ArincEventBus, getStartupState, StartupState, VhfComIndices } from '@flybywiresim/fbw-sdk'; import { RmpState, RmpStateControllerEvents, VhfComManager } from '@flybywiresim/rmp'; import { RmpMessages } from './Components/RmpMessages'; @@ -121,7 +121,9 @@ class RmpInstrument implements FsInstrument { * A callback called when the instrument gets a frame update. */ public Update(): void { - this.backplane.onUpdate(); + if (getStartupState() >= StartupState.InstrumentsInitialized) { + this.backplane.onUpdate(); + } } public onInteractionEvent(args: string[]): void { diff --git a/fbw-a380x/src/systems/shared/src/flightphase.ts b/fbw-a380x/src/systems/shared/src/flightphase.ts index 493f377692e..24078c487af 100644 --- a/fbw-a380x/src/systems/shared/src/flightphase.ts +++ b/fbw-a380x/src/systems/shared/src/flightphase.ts @@ -1,4 +1,5 @@ import { VerticalMode } from '@shared/autopilot'; +import { getStartupState, StartupState } from '../../../../../fbw-common/src/systems/shared/src'; export enum FmgcFlightPhase { Preflight, @@ -12,7 +13,7 @@ export enum FmgcFlightPhase { } export function isReady(): boolean { - return SimVar.GetSimVarValue('L:A32NX_IS_READY', 'number') === 1; + return getStartupState() >= StartupState.InstrumentsInitialized; } export function isSlewActive(): boolean { diff --git a/fbw-a380x/src/systems/systems-host/index.ts b/fbw-a380x/src/systems/systems-host/index.ts index 1d93a2a0f3d..405765498d9 100644 --- a/fbw-a380x/src/systems/systems-host/index.ts +++ b/fbw-a380x/src/systems/systems-host/index.ts @@ -22,7 +22,9 @@ import { ArincEventBus, BtvSimvarPublisher, FailuresConsumer, + getStartupState, PilotSeatPublisher, + StartupState, VhfComIndices, } from '@flybywiresim/fbw-sdk'; import { AudioManagementUnit } from 'systems-host/systems/Communications/AudioManagementUnit'; @@ -102,13 +104,7 @@ class SystemsHost extends BaseInstrument { //FIXME add some deltatime functionality to backplane instruments so we dont have to pass SystemHost private readonly legacyFuel = new LegacyFuel(this.bus, this); - /** - * "mainmenu" = 0 - * "loading" = 1 - * "briefing" = 2 - * "ingame" = 3 - */ - private gameState = 0; + private startupState = 0; constructor() { super(); @@ -188,15 +184,14 @@ class SystemsHost extends BaseInstrument { this.failuresConsumer.update(); - if (this.gameState !== 3) { - const gamestate = this.getGameState(); - if (gamestate === 3) { - this.hEventPublisher.startPublish(); - } - this.gameState = gamestate; + this.startupState = getStartupState(); + if (this.startupState === StartupState.ExtrasHostInitialized) { + this.hEventPublisher.startPublish(); } - this.backplane.onUpdate(); + if (this.startupState >= StartupState.InstrumentsInitialized) { + this.backplane.onUpdate(); + } } } diff --git a/fbw-a380x/src/wasm/fadec_a380x/src/Fadec/EngineControl_A380X.cpp b/fbw-a380x/src/wasm/fadec_a380x/src/Fadec/EngineControl_A380X.cpp index dfaf4830fdc..64c661cc15b 100644 --- a/fbw-a380x/src/wasm/fadec_a380x/src/Fadec/EngineControl_A380X.cpp +++ b/fbw-a380x/src/wasm/fadec_a380x/src/Fadec/EngineControl_A380X.cpp @@ -206,7 +206,7 @@ void EngineControl_A380X::initializeEngineControlData() { const double weightLbsPerGallon = simData.simVarsDataPtr->data().fuelWeightLbsPerGallon; // only loads saved fuel quantity on C/D spawn - if (simData.startState->updateFromSim(timeStamp, tickCounter) == 2) { + if (simData.fltInitState->updateFromSim(timeStamp, tickCounter) == 2) { // Load fuel configuration from file fuelConfiguration.setConfigFilename(FILENAME_FADEC_CONF_DIRECTORY + atcId + FILENAME_FADEC_CONF_FILE_EXTENSION); fuelConfiguration.loadConfigurationFromIni(); diff --git a/fbw-a380x/src/wasm/fadec_a380x/src/Fadec/FadecSimData_A380X.hpp b/fbw-a380x/src/wasm/fadec_a380x/src/Fadec/FadecSimData_A380X.hpp index 6941f0cf6a3..2721164f1a7 100644 --- a/fbw-a380x/src/wasm/fadec_a380x/src/Fadec/FadecSimData_A380X.hpp +++ b/fbw-a380x/src/wasm/fadec_a380x/src/Fadec/FadecSimData_A380X.hpp @@ -228,7 +228,7 @@ class FadecSimData_A380X { NamedVariablePtr packsState[2]; NamedVariablePtr refuelRate; NamedVariablePtr refuelStartedByUser; - NamedVariablePtr startState; + NamedVariablePtr fltInitState; NamedVariablePtr thrustLimitClimb; NamedVariablePtr thrustLimitFlex; NamedVariablePtr thrustLimitIdle; @@ -334,7 +334,7 @@ class FadecSimData_A380X { void initLvars(DataManager* dm) { // TODO: consider DataDefinition for the groups tha are read/write each tick - startState = dm->make_named_var("A32NX_START_STATE", UNITS.Number, NO_AUTO_UPDATE); + fltInitState = dm->make_named_var("A32NX_FLT_INIT_STATE", UNITS.Number, NO_AUTO_UPDATE); engineIdleN1 = dm->make_named_var("A32NX_ENGINE_IDLE_N1", UNITS.Number, AUTO_READ_WRITE); engineIdleN3 = dm->make_named_var("A32NX_ENGINE_IDLE_N3", UNITS.Number, AUTO_READ_WRITE); diff --git a/fbw-a380x/src/wasm/fbw_a380/src/FlyByWireInterface.cpp b/fbw-a380x/src/wasm/fbw_a380/src/FlyByWireInterface.cpp index 10c137cb3ce..0af66c9b620 100644 --- a/fbw-a380x/src/wasm/fbw_a380/src/FlyByWireInterface.cpp +++ b/fbw-a380x/src/wasm/fbw_a380/src/FlyByWireInterface.cpp @@ -76,6 +76,10 @@ bool FlyByWireInterface::update(double sampleTime) { // get sim data SimData simData = simConnectInterface.getSimData(); + if (idStartupState->get() < 3) { + // return result; + } + // update performance monitoring result &= updatePerformanceMonitoring(sampleTime); @@ -92,7 +96,7 @@ bool FlyByWireInterface::update(double sampleTime) { if (simData.slew_on) { wasInSlew = true; return result; - } else if (pauseDetected || simData.cameraState >= 10.0 || !idIsReady->get() || simData.simulationTime < 2) { + } else if (pauseDetected || simData.cameraState >= 10.0 || simData.simulationTime < 2) { return result; } @@ -281,8 +285,8 @@ void FlyByWireInterface::loadConfiguration() { void FlyByWireInterface::setupLocalVariables() { // regsiter L variable for init state and ready signal - idIsReady = std::make_unique("A32NX_IS_READY"); - idStartState = std::make_unique("A32NX_START_STATE"); + idStartupState = std::make_unique("A32NX_STARTUP_STATE"); + idFltInitState = std::make_unique("A32NX_FLT_INIT_STATE"); // regsiter L variable for logging idLoggingFlightControlsEnabled = std::make_unique("A32NX_LOGGING_FLIGHT_CONTROLS_ENABLED"); @@ -758,7 +762,7 @@ void FlyByWireInterface::setupLocalVariables() { bool FlyByWireInterface::handleFcuInitialization(double sampleTime) { // init should be run only once and only when is ready is signaled - if (wasFcuInitialized || !idIsReady->get()) { + if (wasFcuInitialized || idStartupState->get() < 3) { return true; } @@ -774,7 +778,7 @@ bool FlyByWireInterface::handleFcuInitialization(double sampleTime) { auto timeSinceReady = simData.simulationTime - simulationTimeReady; // determine if we need to run init code - if (idStartState->get() >= 5 && timeSinceReady > 6.0) { + if (idFltInitState->get() >= 5 && timeSinceReady > 6.0) { // init FCU for in flight configuration double targetAltitude = std::round(simData.H_ind_ft / 1000.0) * 1000.0; double targetHeading = std::fmod(std::round(simData.Psi_magnetic_deg / 10.0) * 10.0, 360.0); @@ -790,7 +794,7 @@ bool FlyByWireInterface::handleFcuInitialization(double sampleTime) { idFcuModeReversionActive->set(0); idFcuModeReversionTargetFpm->set(simData.H_ind_ft < targetAltitude ? 1000 : -1000); wasFcuInitialized = true; - } else if (idStartState->get() == 4 && timeSinceReady > 1.0) { + } else if (idFltInitState->get() == 4 && timeSinceReady > 1.0) { // init FCU for on runway -> ready for take-off double targetHeading = std::fmod(std::round(simData.Psi_magnetic_deg), 360.0); simConnectInterface.sendEvent(SimConnectInterface::A32NX_FCU_SPD_SET, 150); @@ -799,7 +803,7 @@ bool FlyByWireInterface::handleFcuInitialization(double sampleTime) { simConnectInterface.sendEvent(SimConnectInterface::A32NX_FCU_HDG_PULL); simConnectInterface.sendEvent(SimConnectInterface::A32NX_FCU_ALT_SET, 15000); wasFcuInitialized = true; - } else if (idStartState->get() < 4 && timeSinceReady > 1.0) { + } else if (idFltInitState->get() < 4 && timeSinceReady > 1.0) { // init FCU for on ground -> default FCU values after power-on simConnectInterface.sendEvent(SimConnectInterface::A32NX_FCU_SPD_SET, 100); simConnectInterface.sendEvent(SimConnectInterface::A32NX_FCU_SPD_PULL); diff --git a/fbw-a380x/src/wasm/fbw_a380/src/FlyByWireInterface.h b/fbw-a380x/src/wasm/fbw_a380/src/FlyByWireInterface.h index cb3bd784941..0fb0d62b854 100644 --- a/fbw-a380x/src/wasm/fbw_a380/src/FlyByWireInterface.h +++ b/fbw-a380x/src/wasm/fbw_a380/src/FlyByWireInterface.h @@ -158,8 +158,8 @@ class FlyByWireInterface { bool wasFcuInitialized = false; double simulationTimeReady = 0.0; - std::unique_ptr idIsReady; - std::unique_ptr idStartState; + std::unique_ptr idStartupState; + std::unique_ptr idFltInitState; std::unique_ptr idLeftWingWheelSpeed_rpm; std::unique_ptr idRightWingWheelSpeed_rpm; diff --git a/fbw-a380x/src/wasm/systems/a380_systems/src/hydraulic/heading_control_steering.rs b/fbw-a380x/src/wasm/systems/a380_systems/src/hydraulic/heading_control_steering.rs index 03321ccbd33..71197080f18 100644 --- a/fbw-a380x/src/wasm/systems/a380_systems/src/hydraulic/heading_control_steering.rs +++ b/fbw-a380x/src/wasm/systems/a380_systems/src/hydraulic/heading_control_steering.rs @@ -136,9 +136,7 @@ impl HeadingControlFunction { } fn should_reset(&self, context: &UpdateContext) -> bool { - !self.heading_refresh_is_valid() - || context.is_sim_initialiazing() - || !context.is_sim_ready() + !self.heading_refresh_is_valid() || context.is_sim_initializing() || !context.is_sim_ready() } pub fn update( diff --git a/fbw-a380x/src/wasm/systems/a380_systems/src/hydraulic/mod.rs b/fbw-a380x/src/wasm/systems/a380_systems/src/hydraulic/mod.rs index 9277a6f934e..91a57564b02 100644 --- a/fbw-a380x/src/wasm/systems/a380_systems/src/hydraulic/mod.rs +++ b/fbw-a380x/src/wasm/systems/a380_systems/src/hydraulic/mod.rs @@ -56,8 +56,8 @@ use systems::{ SurfacesPositions, }, simulation::{ - InitContext, Read, SimulationElement, SimulationElementVisitor, SimulatorReader, - SimulatorWriter, StartState, UpdateContext, VariableIdentifier, Write, + FltInitState, InitContext, Read, SimulationElement, SimulationElementVisitor, + SimulatorReader, SimulatorWriter, UpdateContext, VariableIdentifier, Write, }, }; @@ -1014,8 +1014,8 @@ impl A380RudderFactory { } fn new_rudder(context: &mut InitContext) -> RudderAssembly { - let init_at_center = context.start_state() == StartState::Taxi - || context.start_state() == StartState::Runway + let init_at_center = context.flt_init_state() == FltInitState::Taxi + || context.flt_init_state() == FltInitState::Runway || context.is_in_flight(); let upper_assembly = Self::a380_rudder_assembly( @@ -7590,10 +7590,10 @@ mod tests { test_bed: SimulationTestBed, } impl A380HydraulicsTestBed { - fn new_with_start_state(start_state: StartState) -> Self { + fn flt_init_state(flt_init_state: FltInitState) -> Self { Self { - test_bed: SimulationTestBed::new_with_start_state( - start_state, + test_bed: SimulationTestBed::new_with_flt_init_state( + flt_init_state, A380HydraulicsTestAircraft::new, ), } @@ -8714,11 +8714,11 @@ mod tests { } fn test_bed_on_ground() -> A380HydraulicsTestBed { - A380HydraulicsTestBed::new_with_start_state(StartState::Apron) + A380HydraulicsTestBed::new_with_flt_init_state(FltInitState::Apron) } fn test_bed_in_flight() -> A380HydraulicsTestBed { - A380HydraulicsTestBed::new_with_start_state(StartState::Cruise) + A380HydraulicsTestBed::new_with_flt_init_state(FltInitState::Cruise) } fn test_bed_on_ground_with() -> A380HydraulicsTestBed { diff --git a/fbw-a380x/src/wasm/systems/a380_systems_wasm/src/lib.rs b/fbw-a380x/src/wasm/systems/a380_systems_wasm/src/lib.rs index e1946cd2860..e6a89d1b799 100644 --- a/fbw-a380x/src/wasm/systems/a380_systems_wasm/src/lib.rs +++ b/fbw-a380x/src/wasm/systems/a380_systems_wasm/src/lib.rs @@ -43,14 +43,25 @@ use systems::shared::{ use systems_wasm::{MsfsSimulationBuilder, Variable}; use trimmable_horizontal_stabilizer::trimmable_horizontal_stabilizer; +use ::msfs::legacy::NamedVariable; + #[msfs::gauge(name=systems)] async fn systems(mut gauge: msfs::Gauge) -> Result<(), Box> { let mut sim_connect = gauge.open_simconnect("systems")?; + while let Some(_event) = gauge.next_event().await { + // Uses deprecated method, FIXME improve + let startup_state: f64 = NamedVariable::from("A32NX_STARTUP_STATE").get_value(); + + if startup_state >= 3.0 { + break; + } + } + let key_prefix = "A32NX_"; let (mut simulation, mut handler) = MsfsSimulationBuilder::new( key_prefix, - Variable::named(&format!("{}START_STATE", key_prefix)), + Variable::named(&format!("{}FLT_INIT_STATE", key_prefix)), sim_connect.as_mut().get_mut(), ) .with_electrical_buses([ @@ -613,6 +624,9 @@ async fn systems(mut gauge: msfs::Gauge) -> Result<(), Box> { .with_aspect(trimmable_horizontal_stabilizer)? .build(A380::new)?; + // FIXME improve + NamedVariable::from("A32NX_STARTUP_STATE").set_value(4.0); + while let Some(event) = gauge.next_event().await { handler.handle(event, &mut simulation, sim_connect.as_mut().get_mut())?; } diff --git a/fbw-common/src/systems/shared/src/AircraftReadyState.ts b/fbw-common/src/systems/shared/src/AircraftReadyState.ts new file mode 100644 index 00000000000..8fcc24de9a4 --- /dev/null +++ b/fbw-common/src/systems/shared/src/AircraftReadyState.ts @@ -0,0 +1,38 @@ +// Copyright (c) 2023-2024 FlyByWire Simulations +// SPDX-License-Identifier: GPL-3.0 + +import { SimVarValueType } from '@microsoft/msfs-sdk'; + +export function trySetAircraftReadyState(gameState: GameState) { + if (gameState === GameState.ingame) { + // Haven't really thought about the transition here yet, whether it should be a fixed time or in the next frame (as it is here) + if (getStartupState() === StartupState.ExtrasHostInitialized) { + setStartupState(StartupState.InstrumentsInitialized); + } + + if (getStartupState() === StartupState.FltFileLoaded) { + setStartupState(StartupState.ExtrasHostInitialized); + console.log(`EXTRASHOST: Instruments are ready at ${new Date().toLocaleString()}`); + } + } else if (gameState < GameState.briefing && getStartupState() > StartupState.FltFileLoaded) { + // This is dangerous, since this state can only be left by loading in StartupState.FltFileLoaded from the *.flt files + // Disable for now, all Vars should be set to 0 on reload anyways + // setStartupState(StartupState.Uninitialized); + } +} + +export enum StartupState { + Uninitialized, + FltFileLoaded, + ExtrasHostInitialized, + InstrumentsInitialized, + WasmInitialized, +} + +export function getStartupState(): StartupState { + return SimVar.GetSimVarValue('L:A32NX_STARTUP_STATE', SimVarValueType.Enum); +} + +function setStartupState(state: number) { + return SimVar.SetSimVarValue('L:A32NX_STARTUP_STATE', SimVarValueType.Enum, state); +} diff --git a/fbw-common/src/systems/shared/src/index.ts b/fbw-common/src/systems/shared/src/index.ts index 22439dfe5b1..67c8fb87e32 100644 --- a/fbw-common/src/systems/shared/src/index.ts +++ b/fbw-common/src/systems/shared/src/index.ts @@ -1,4 +1,5 @@ export * from './AircraftGithubVersionChecker'; +export * from './AircraftReadyState'; export * from './amdb'; export * from './ApproachUtils'; export * from './Arinc429ConsumerSubject'; diff --git a/fbw-common/src/wasm/cpp-msfs-framework/Example/ExampleModule.cpp b/fbw-common/src/wasm/cpp-msfs-framework/Example/ExampleModule.cpp index 82c1124a818..30c752039a8 100644 --- a/fbw-common/src/wasm/cpp-msfs-framework/Example/ExampleModule.cpp +++ b/fbw-common/src/wasm/cpp-msfs-framework/Example/ExampleModule.cpp @@ -338,7 +338,7 @@ bool ExampleModule::update([[maybe_unused]] sGaugeDrawData* pData) { std::cout << "==== tickCounter = " << tickCounter << " timeStamp = " << timeStamp << " =============================" << std::endl; - LOG_DEBUG("A32NX_IS_READY = " + std::string(msfsHandler.getAircraftIsReadyVar() ? "true" : "false") + + LOG_DEBUG("A32NX_STARTUP_STATE = " + std::string(msfsHandler.getAircraftIsReadyVar()) + " A32NX_DEVELOPER_STATE = " + std::to_string(msfsHandler.getAircraftDevelopmentStateVar())); #ifdef CUSTOM_EVENT_EXAMPLE @@ -517,4 +517,4 @@ bool ExampleModule::shutdown() { return true; } -#endif +#endif \ No newline at end of file diff --git a/fbw-common/src/wasm/cpp-msfs-framework/MsfsHandler/MsfsHandler.cpp b/fbw-common/src/wasm/cpp-msfs-framework/MsfsHandler/MsfsHandler.cpp index 8fdd28cede0..91eeae17d1f 100644 --- a/fbw-common/src/wasm/cpp-msfs-framework/MsfsHandler/MsfsHandler.cpp +++ b/fbw-common/src/wasm/cpp-msfs-framework/MsfsHandler/MsfsHandler.cpp @@ -56,7 +56,7 @@ bool MsfsHandler::initialize() { {"SIMULATION TIME", 0, UNITS.Number}, {"SIMULATION RATE", 0, UNITS.Number}, {"SIM ON GROUND", 0, UNITS.Bool }, - {"L:" + NamedVariable::getAircraftPrefix() + "IS_READY", 0, UNITS.Number}, + {"L:" + NamedVariable::getAircraftPrefix() + "STARTUP_STATE", 0, UNITS.Number}, {"L:" + NamedVariable::getAircraftPrefix() + "DEVELOPER_STATE", 0, UNITS.Number} }; baseSimData = dataManager.make_datadefinition_var("BASE DATA", baseDataDef); diff --git a/fbw-common/src/wasm/cpp-msfs-framework/MsfsHandler/MsfsHandler.h b/fbw-common/src/wasm/cpp-msfs-framework/MsfsHandler/MsfsHandler.h index 02889badc84..f3ffa454e26 100644 --- a/fbw-common/src/wasm/cpp-msfs-framework/MsfsHandler/MsfsHandler.h +++ b/fbw-common/src/wasm/cpp-msfs-framework/MsfsHandler/MsfsHandler.h @@ -189,9 +189,9 @@ class MsfsHandler { [[nodiscard]] bool getSimOnGround() const { return baseSimData->data().simOnGround != 0.0; } /** - * @return value of LVAR A32NX_IS_READY + * @return value of LVAR A32NX_STARTUP_STATE */ - [[nodiscard]] bool getAircraftIsReadyVar() const { return baseSimData->data().aircraftIsReady != 0.0; } + [[nodiscard]] bool getAircraftIsReadyVar() const { return baseSimData->data().aircraftIsReady >= 1; } /** * diff --git a/fbw-common/src/wasm/systems/systems/src/hydraulic/brake_circuit.rs b/fbw-common/src/wasm/systems/systems/src/hydraulic/brake_circuit.rs index 72971494956..00ee180b989 100644 --- a/fbw-common/src/wasm/systems/systems/src/hydraulic/brake_circuit.rs +++ b/fbw-common/src/wasm/systems/systems/src/hydraulic/brake_circuit.rs @@ -5,7 +5,7 @@ use crate::{ pid::PidController, random_from_normal_distribution, random_from_range, HydraulicColor, }, simulation::{ - SimulationElement, SimulationElementVisitor, SimulatorWriter, StartState, UpdateContext, + SimulationElement, SimulationElementVisitor, SimulatorWriter, FltInitState, UpdateContext, Write, }, }; @@ -45,9 +45,9 @@ impl BrakeActuator { base_speed: BrakeActuator::ACTUATOR_BASE_SPEED, // Here we consider brakes are applied on spawn where park brake should be applied // This avoids actuator movement on spawn that would mess hydraulic quantities on init - current_position: if context.start_state() == StartState::Hangar - || context.start_state() == StartState::Apron - || context.start_state() == StartState::Runway + current_position: if context.flt_init_state() == FltInitState::Hangar + || context.flt_init_state() == FltInitState::Apron + || context.flt_init_state() == FltInitState::Runway { 1. } else { diff --git a/fbw-common/src/wasm/systems/systems/src/landing_gear/mod.rs b/fbw-common/src/wasm/systems/systems/src/landing_gear/mod.rs index e9db2aa6c41..a41f2a5fcb8 100644 --- a/fbw-common/src/wasm/systems/systems/src/landing_gear/mod.rs +++ b/fbw-common/src/wasm/systems/systems/src/landing_gear/mod.rs @@ -1516,7 +1516,7 @@ mod tests { use std::time::Duration; use crate::simulation::{ - Aircraft, InitContext, SimulationElement, SimulationElementVisitor, StartState, + Aircraft, FltInitState, InitContext, SimulationElement, SimulationElementVisitor, UpdateContext, }; @@ -1667,10 +1667,10 @@ mod tests { test_bed: SimulationTestBed, } impl LgciusTestBed { - fn new(start_state: StartState) -> Self { + fn new(flt_init_state: FltInitState) -> Self { Self { - test_bed: SimulationTestBed::new_with_start_state( - start_state, + test_bed: SimulationTestBed::new_with_flt_init_state( + flt_init_state, TestGearAircraft::new, ), } @@ -1734,16 +1734,16 @@ mod tests { } } - fn test_bed(start_state: StartState) -> LgciusTestBed { - LgciusTestBed::new(start_state) + fn test_bed(flt_init_state: FltInitState) -> LgciusTestBed { + LgciusTestBed::new(flt_init_state) } fn test_bed_on_ground_with() -> LgciusTestBed { - test_bed(StartState::Apron) + test_bed(FltInitState::Apron) } fn test_bed_in_flight_with() -> LgciusTestBed { - test_bed(StartState::Cruise) + test_bed(FltInitState::Cruise) } #[test] diff --git a/fbw-common/src/wasm/systems/systems/src/navigation/ala52b.rs b/fbw-common/src/wasm/systems/systems/src/navigation/ala52b.rs index 3f95e40fca0..6a76195d9c8 100644 --- a/fbw-common/src/wasm/systems/systems/src/navigation/ala52b.rs +++ b/fbw-common/src/wasm/systems/systems/src/navigation/ala52b.rs @@ -477,7 +477,7 @@ mod tests { use crate::electrical::{ElectricalBus, Electricity}; use crate::shared::{PotentialOrigin, PowerConsumptionReport}; use crate::simulation::test::{ReadByName, SimulationTestBed, TestBed, WriteByName}; - use crate::simulation::{Aircraft, InitContext, SimulationElementVisitor, StartState}; + use crate::simulation::{Aircraft, FltInitState, InitContext, SimulationElementVisitor}; use ntest::assert_about_eq; use uom::si::electric_potential::volt; use uom::si::f64::ElectricPotential; @@ -585,8 +585,8 @@ mod tests { impl RadioAltimeterTestBed { fn new() -> Self { let mut ra_test_bed = Self { - test_bed: SimulationTestBed::new_with_start_state( - StartState::Cruise, + test_bed: SimulationTestBed::new_with_flt_init_state( + FltInitState::Cruise, TestAircraft::new, ), }; diff --git a/fbw-common/src/wasm/systems/systems/src/simulation/mod.rs b/fbw-common/src/wasm/systems/systems/src/simulation/mod.rs index cd3b1bf80cf..9b844d936eb 100644 --- a/fbw-common/src/wasm/systems/systems/src/simulation/mod.rs +++ b/fbw-common/src/wasm/systems/systems/src/simulation/mod.rs @@ -62,7 +62,7 @@ impl VariableIdentifier { } #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd)] -pub enum StartState { +pub enum FltInitState { Hangar, Apron, Taxi, @@ -73,58 +73,57 @@ pub enum StartState { Final, } -impl From for StartState { +impl From for FltInitState { fn from(value: f64) -> Self { match value { - x if x < 0.9 => Default::default(), - x if x < 1.9 => Self::Hangar, - x if x < 2.9 => Self::Apron, - x if x < 3.9 => Self::Taxi, - x if x < 4.9 => Self::Runway, - x if x < 5.9 => Self::Climb, - x if x < 6.9 => Self::Cruise, - x if x < 7.9 => Self::Approach, - x if x < 8.9 => Self::Final, + x if x < 0.9 => Self::Hangar, + x if x < 1.9 => Self::Apron, + x if x < 2.9 => Self::Taxi, + x if x < 3.9 => Self::Runway, + x if x < 4.9 => Self::Climb, + x if x < 5.9 => Self::Cruise, + x if x < 6.9 => Self::Approach, + x if x < 7.9 => Self::Final, _ => Default::default(), } } } -impl From for f64 { - fn from(state: StartState) -> Self { +impl From for f64 { + fn from(state: FltInitState) -> Self { match state { - StartState::Hangar => 1., - StartState::Apron => 2., - StartState::Taxi => 3., - StartState::Runway => 4., - StartState::Climb => 5., - StartState::Cruise => 6., - StartState::Approach => 7., - StartState::Final => 8., + FltInitState::Hangar => 0., + FltInitState::Apron => 1., + FltInitState::Taxi => 2., + FltInitState::Runway => 3., + FltInitState::Climb => 4., + FltInitState::Cruise => 5., + FltInitState::Approach => 6., + FltInitState::Final => 7., } } } -impl Default for StartState { +impl Default for FltInitState { fn default() -> Self { Self::Cruise } } pub struct InitContext<'a> { - start_state: StartState, + flt_init_state: FltInitState, electrical_identifier_provider: &'a mut dyn ElectricalElementIdentifierProvider, registry: &'a mut dyn VariableRegistry, } impl<'a> InitContext<'a> { pub fn new( - start_state: StartState, + flt_init_state: FltInitState, electricity: &'a mut impl ElectricalElementIdentifierProvider, registry: &'a mut impl VariableRegistry, ) -> Self { Self { - start_state, + flt_init_state, electrical_identifier_provider: electricity, registry, } @@ -134,18 +133,21 @@ impl<'a> InitContext<'a> { self.registry.get(name) } - pub fn start_state(&self) -> StartState { - self.start_state + pub fn flt_init_state(&self) -> FltInitState { + self.flt_init_state } pub fn start_gear_down(&self) -> bool { - self.is_on_ground() || self.start_state == StartState::Final + self.is_on_ground() || self.flt_init_state == FltInitState::Final } pub fn is_in_flight(&self) -> bool { matches!( - self.start_state, - StartState::Climb | StartState::Cruise | StartState::Approach | StartState::Final + self.flt_init_state, + FltInitState::Climb + | FltInitState::Cruise + | FltInitState::Approach + | FltInitState::Final ) } @@ -155,13 +157,13 @@ impl<'a> InitContext<'a> { pub fn has_engines_running(&self) -> bool { matches!( - self.start_state, - StartState::Taxi - | StartState::Runway - | StartState::Climb - | StartState::Cruise - | StartState::Approach - | StartState::Final + self.flt_init_state, + FltInitState::Taxi + | FltInitState::Runway + | FltInitState::Climb + | FltInitState::Cruise + | FltInitState::Approach + | FltInitState::Final ) } } @@ -363,12 +365,12 @@ pub struct Simulation { } impl Simulation { pub fn new T>( - start_state: StartState, + flt_init_state: FltInitState, aircraft_ctor_fn: U, registry: &mut impl VariableRegistry, ) -> Self { let mut electricity = Electricity::new(); - let mut context = InitContext::new(start_state, &mut electricity, registry); + let mut context = InitContext::new(flt_init_state, &mut electricity, registry); let update_context = UpdateContext::new_for_simulation(&mut context); Self { aircraft: (aircraft_ctor_fn)(&mut context), @@ -434,9 +436,10 @@ impl Simulation { simulation_time: f64, reader_writer: &mut impl SimulatorReaderWriter, ) { + let mut reader = SimulatorReader::new(reader_writer); + self.electricity.pre_tick(); - let mut reader = SimulatorReader::new(reader_writer); self.update_context .update(&mut reader, delta, simulation_time); @@ -796,7 +799,7 @@ read_write_uom!(AngularVelocity, revolution_per_minute); read_write_uom!(MassDensity, slug_per_cubic_foot); read_write_into!(MachNumber); -read_write_into!(StartState); +read_write_into!(FltInitState); impl Read> for T { fn convert(&mut self, value: f64) -> Arinc429Word { @@ -863,50 +866,50 @@ mod tests { use super::*; use rstest::rstest; - mod start_state { + mod flt_init_state { use super::*; use fxhash::FxHashMap; use ntest::assert_about_eq; #[rstest] - #[case(1., StartState::Hangar)] - #[case(2., StartState::Apron)] - #[case(3., StartState::Taxi)] - #[case(4., StartState::Runway)] - #[case(5., StartState::Climb)] - #[case(6., StartState::Cruise)] - #[case(7., StartState::Approach)] - #[case(8., StartState::Final)] - fn converts_to_and_from_f64(#[case] value: f64, #[case] expected: StartState) { + #[case(1., FltInitState::Hangar)] + #[case(2., FltInitState::Apron)] + #[case(3., FltInitState::Taxi)] + #[case(4., FltInitState::Runway)] + #[case(5., FltInitState::Climb)] + #[case(6., FltInitState::Cruise)] + #[case(7., FltInitState::Approach)] + #[case(8., FltInitState::Final)] + fn converts_to_and_from_f64(#[case] value: f64, #[case] expected: FltInitState) { assert_eq!(expected, value.into()); assert_about_eq!(value, f64::from(expected)); } #[test] fn default_is_cruise() { - assert_eq!(StartState::Cruise, Default::default()); + assert_eq!(FltInitState::Cruise, Default::default()); } #[test] fn converts_0_f64_to_default() { - assert_eq!(StartState::default(), (0.).into()) + assert_eq!(FltInitState::default(), (0.).into()) } #[test] fn converts_greater_than_8_point_9_f64_to_default() { - assert_eq!(StartState::default(), (9.).into()); - assert_eq!(StartState::default(), (f64::MAX).into()); + assert_eq!(FltInitState::default(), (9.).into()); + assert_eq!(FltInitState::default(), (f64::MAX).into()); } #[test] fn includes_partial_ord_operators() { - assert!(StartState::Climb < StartState::Cruise); + assert!(FltInitState::Climb < FltInitState::Cruise); } #[test] fn includes_hash() { - let mut hashmap: FxHashMap = FxHashMap::default(); - hashmap.insert(StartState::Climb, true); + let mut hashmap: FxHashMap = FxHashMap::default(); + hashmap.insert(FltInitState::Climb, true); } } @@ -915,74 +918,74 @@ mod tests { use test::TestVariableRegistry; #[rstest] - #[case(StartState::Climb)] - #[case(StartState::Cruise)] - #[case(StartState::Approach)] - #[case(StartState::Final)] - fn is_in_flight_when(#[case] start_state: StartState) { + #[case(FltInitState::Climb)] + #[case(FltInitState::Cruise)] + #[case(FltInitState::Approach)] + #[case(FltInitState::Final)] + fn is_in_flight_when(#[case] flt_init_state: FltInitState) { let mut electricity = Electricity::new(); let mut registry: TestVariableRegistry = Default::default(); - let context = InitContext::new(start_state, &mut electricity, &mut registry); + let context = InitContext::new(flt_init_state, &mut electricity, &mut registry); assert!(context.is_in_flight()); } #[rstest] - #[case(StartState::Hangar)] - #[case(StartState::Apron)] - #[case(StartState::Taxi)] - #[case(StartState::Runway)] - fn is_not_in_flight_when(#[case] start_state: StartState) { + #[case(FltInitState::Hangar)] + #[case(FltInitState::Apron)] + #[case(FltInitState::Taxi)] + #[case(FltInitState::Runway)] + fn is_not_in_flight_when(#[case] flt_init_state: FltInitState) { let mut electricity = Electricity::new(); let mut registry: TestVariableRegistry = Default::default(); - let context = InitContext::new(start_state, &mut electricity, &mut registry); + let context = InitContext::new(flt_init_state, &mut electricity, &mut registry); assert!(!context.is_in_flight()); } #[rstest] - #[case(StartState::Hangar)] - #[case(StartState::Apron)] - #[case(StartState::Taxi)] - #[case(StartState::Runway)] - fn is_on_ground_when(#[case] start_state: StartState) { + #[case(FltInitState::Hangar)] + #[case(FltInitState::Apron)] + #[case(FltInitState::Taxi)] + #[case(FltInitState::Runway)] + fn is_on_ground_when(#[case] flt_init_state: FltInitState) { let mut electricity = Electricity::new(); let mut registry: TestVariableRegistry = Default::default(); - let context = InitContext::new(start_state, &mut electricity, &mut registry); + let context = InitContext::new(flt_init_state, &mut electricity, &mut registry); assert!(context.is_on_ground()); } #[rstest] - #[case(StartState::Climb)] - #[case(StartState::Cruise)] - #[case(StartState::Approach)] - #[case(StartState::Final)] - fn is_not_on_ground_when(#[case] start_state: StartState) { + #[case(FltInitState::Climb)] + #[case(FltInitState::Cruise)] + #[case(FltInitState::Approach)] + #[case(FltInitState::Final)] + fn is_not_on_ground_when(#[case] flt_init_state: FltInitState) { let mut electricity = Electricity::new(); let mut registry: TestVariableRegistry = Default::default(); - let context = InitContext::new(start_state, &mut electricity, &mut registry); + let context = InitContext::new(flt_init_state, &mut electricity, &mut registry); assert!(!context.is_on_ground()); } #[rstest] - #[case(StartState::Taxi)] - #[case(StartState::Runway)] - #[case(StartState::Climb)] - #[case(StartState::Cruise)] - #[case(StartState::Approach)] - #[case(StartState::Final)] - fn has_engines_running_when(#[case] start_state: StartState) { + #[case(FltInitState::Taxi)] + #[case(FltInitState::Runway)] + #[case(FltInitState::Climb)] + #[case(FltInitState::Cruise)] + #[case(FltInitState::Approach)] + #[case(FltInitState::Final)] + fn has_engines_running_when(#[case] flt_init_state: FltInitState) { let mut electricity = Electricity::new(); let mut registry: TestVariableRegistry = Default::default(); - let context = InitContext::new(start_state, &mut electricity, &mut registry); + let context = InitContext::new(flt_init_state, &mut electricity, &mut registry); assert!(context.has_engines_running()); } #[rstest] - #[case(StartState::Hangar)] - #[case(StartState::Apron)] - fn does_not_have_engines_running_when(#[case] start_state: StartState) { + #[case(FltInitState::Hangar)] + #[case(FltInitState::Apron)] + fn does_not_have_engines_running_when(#[case] flt_init_state: FltInitState) { let mut electricity = Electricity::new(); let mut registry: TestVariableRegistry = Default::default(); - let context = InitContext::new(start_state, &mut electricity, &mut registry); + let context = InitContext::new(flt_init_state, &mut electricity, &mut registry); assert!(!context.has_engines_running()); } } diff --git a/fbw-common/src/wasm/systems/systems/src/simulation/test.rs b/fbw-common/src/wasm/systems/systems/src/simulation/test.rs index 0835a7454a6..521f956ca0e 100644 --- a/fbw-common/src/wasm/systems/systems/src/simulation/test.rs +++ b/fbw-common/src/wasm/systems/systems/src/simulation/test.rs @@ -26,7 +26,7 @@ use crate::landing_gear::LandingGear; use crate::shared::arinc429::{from_arinc429, to_arinc429, Arinc429Word, SignStatus}; use crate::simulation::update_context::Delta; use crate::simulation::{ - DeltaContext, InitContext, StartState, VariableIdentifier, VariableRegistry, + DeltaContext, FltInitState, InitContext, VariableIdentifier, VariableRegistry, }; pub trait TestBed { @@ -240,17 +240,17 @@ pub struct SimulationTestBed { } impl SimulationTestBed { pub fn new T>(aircraft_ctor_fn: U) -> Self { - Self::new_with_start_state(Default::default(), aircraft_ctor_fn) + Self::new_with_flt_init_state(Default::default(), aircraft_ctor_fn) } - pub fn new_with_start_state T>( - start_state: StartState, + pub fn new_with_flt_init_state T>( + flt_init_state: FltInitState, aircraft_ctor_fn: U, ) -> Self { let mut variable_registry = TestVariableRegistry::default(); let mut test_bed = Self { reader_writer: TestReaderWriter::new(), - simulation: Simulation::new(start_state, aircraft_ctor_fn, &mut variable_registry), + simulation: Simulation::new(flt_init_state, aircraft_ctor_fn, &mut variable_registry), variable_registry, }; @@ -357,7 +357,10 @@ impl SimulationTestBed { } fn set_is_ready(&mut self, is_ready: bool) { - self.write_by_name(UpdateContext::IS_READY_KEY, is_ready); + self.write_by_name( + UpdateContext::STARTUP_STATE_KEY, + if is_ready == true { 3 } else { 0 }, + ); } fn set_indicated_airspeed(&mut self, indicated_airspeed: Velocity) { diff --git a/fbw-common/src/wasm/systems/systems/src/simulation/update_context.rs b/fbw-common/src/wasm/systems/systems/src/simulation/update_context.rs index fb663042de6..f12994bc1b1 100644 --- a/fbw-common/src/wasm/systems/systems/src/simulation/update_context.rs +++ b/fbw-common/src/wasm/systems/systems/src/simulation/update_context.rs @@ -199,7 +199,7 @@ impl Velocity3D { /// for the purpose of handling a simulation tick. #[derive(Clone, Copy, Debug)] pub struct UpdateContext { - is_ready_id: VariableIdentifier, + startup_state_id: VariableIdentifier, ambient_temperature_id: VariableIdentifier, indicated_airspeed_id: VariableIdentifier, true_airspeed_id: VariableIdentifier, @@ -287,7 +287,7 @@ pub struct UpdateContext { } impl UpdateContext { pub(crate) const GROUND_SPEED_KEY: &'static str = "GPS GROUND SPEED"; - pub(crate) const IS_READY_KEY: &'static str = "IS_READY"; + pub(crate) const STARTUP_STATE_KEY: &'static str = "STARTUP_STATE"; pub(crate) const AMBIENT_DENSITY_KEY: &'static str = "AMBIENT DENSITY"; pub(crate) const IN_CLOUD_KEY: &'static str = "AMBIENT IN CLOUD"; pub(crate) const AMBIENT_PRECIP_RATE_KEY: &'static str = "AMBIENT PRECIP RATE"; @@ -359,7 +359,7 @@ impl UpdateContext { latitude: Angle, ) -> UpdateContext { UpdateContext { - is_ready_id: context.get_identifier(Self::IS_READY_KEY.to_owned()), + startup_state_id: context.get_identifier(Self::STARTUP_STATE_KEY.to_owned()), ambient_temperature_id: context .get_identifier(Self::AMBIENT_TEMPERATURE_KEY.to_owned()), indicated_airspeed_id: context.get_identifier(Self::INDICATED_AIRSPEED_KEY.to_owned()), @@ -469,7 +469,7 @@ impl UpdateContext { pub(super) fn new_for_simulation(context: &mut InitContext) -> UpdateContext { UpdateContext { - is_ready_id: context.get_identifier("IS_READY".to_owned()), + startup_state_id: context.get_identifier("STARTUP_STATE".to_owned()), ambient_temperature_id: context.get_identifier("AMBIENT TEMPERATURE".to_owned()), indicated_airspeed_id: context.get_identifier("AIRSPEED INDICATED".to_owned()), true_airspeed_id: context.get_identifier("AIRSPEED TRUE".to_owned()), @@ -590,7 +590,9 @@ impl UpdateContext { self.delta = delta.into(); self.simulation_time = simulation_time; - self.is_ready = reader.read(&self.is_ready_id); + + let raw_startup_state_read: f64 = reader.read(&self.startup_state_id); + self.is_ready = raw_startup_state_read >= 3.0; self.local_acceleration = LocalAcceleration::new( reader.read(&self.accel_body_x_id), @@ -741,7 +743,7 @@ impl UpdateContext { self.simulation_time >= 2.0 && self.is_ready } - pub fn is_sim_initialiazing(&self) -> bool { + pub fn is_sim_initializing(&self) -> bool { self.simulation_time < 2.0 || !self.is_ready } diff --git a/fbw-common/src/wasm/systems/systems_wasm/src/lib.rs b/fbw-common/src/wasm/systems/systems_wasm/src/lib.rs index 6e5e1982efb..a22b068ed8f 100644 --- a/fbw-common/src/wasm/systems/systems_wasm/src/lib.rs +++ b/fbw-common/src/wasm/systems/systems_wasm/src/lib.rs @@ -22,7 +22,7 @@ use fxhash::FxHashMap; use std::fmt::{Display, Formatter}; use std::{error::Error, time::Duration}; use systems::shared::ElectricalBusType; -use systems::simulation::{InitContext, StartState}; +use systems::simulation::{FltInitState, InitContext}; use systems::{ failures::FailureType, simulation::{ @@ -35,7 +35,7 @@ use systems::{ pub struct MsfsSimulationBuilder<'a, 'b> { variable_registry: Option, key_prefix: String, - start_state: StartState, + flt_init_state: FltInitState, sim_connect: &'a mut SimConnect<'b>, failures: Option, aspects: Vec>, @@ -44,14 +44,14 @@ pub struct MsfsSimulationBuilder<'a, 'b> { impl<'a, 'b> MsfsSimulationBuilder<'a, 'b> { pub fn new( key_prefix: &str, - start_state_variable: Variable, + flt_init_state_variable: Variable, sim_connect: &'a mut SimConnect<'b>, ) -> Self { - let start_state_variable_value: VariableValue = (&start_state_variable).into(); + let flt_init_state_variable_value: VariableValue = (&flt_init_state_variable).into(); Self { variable_registry: Some(MsfsVariableRegistry::new(key_prefix.into())), - start_state: start_state_variable_value.read().into(), + flt_init_state: flt_init_state_variable_value.read().into(), key_prefix: key_prefix.into(), sim_connect, failures: None, @@ -64,7 +64,7 @@ impl<'a, 'b> MsfsSimulationBuilder<'a, 'b> { aircraft_ctor_fn: U, ) -> Result<(Simulation, MsfsHandler), Box> { let mut registry = self.variable_registry.unwrap(); - let simulation = Simulation::new(self.start_state, aircraft_ctor_fn, &mut registry); + let simulation = Simulation::new(self.flt_init_state, aircraft_ctor_fn, &mut registry); Ok(( simulation,