1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-24 14:50:10 +00:00
msfs-popout-panel-manager/Orchestration/FlightSimOrchestrator.cs

597 lines
23 KiB
C#
Raw Normal View History

2023-07-12 22:41:31 +00:00
using MSFSPopoutPanelManager.DomainModel.Profile;
using MSFSPopoutPanelManager.DomainModel.SimConnect;
using MSFSPopoutPanelManager.Shared;
2022-07-23 19:23:32 +00:00
using MSFSPopoutPanelManager.SimConnectAgent;
2023-07-12 22:41:31 +00:00
using MSFSPopoutPanelManager.WindowsAgent;
2022-07-23 19:23:32 +00:00
using System;
2023-07-12 22:41:31 +00:00
using System.Collections.Generic;
using System.Threading;
2022-07-23 19:23:32 +00:00
namespace MSFSPopoutPanelManager.Orchestration
{
2024-02-28 02:44:21 +00:00
public class FlightSimOrchestrator : BaseOrchestrator
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
private const int MSFS_GAME_EXIT_DETECTION_INTERVAL = 3000;
private System.Timers.Timer _msfsGameExitDetectionTimer;
2022-07-23 19:23:32 +00:00
private SimConnectProvider _simConnectProvider;
2024-09-06 02:58:59 +00:00
private readonly DynamicLodOrchestrator _dynamicLodOrchestrator;
2023-07-12 22:41:31 +00:00
private bool _isTurnedOnPower;
private bool _isTurnedOnAvionics;
2024-03-14 22:50:32 +00:00
public FlightSimOrchestrator(SharedStorage sharedStorage, DynamicLodOrchestrator dynamicLodOrchestrator) : base(sharedStorage)
2022-07-23 19:23:32 +00:00
{
2024-03-14 22:50:32 +00:00
_dynamicLodOrchestrator = dynamicLodOrchestrator;
2022-07-23 19:23:32 +00:00
_simConnectProvider = new SimConnectProvider();
}
2024-02-28 02:44:21 +00:00
public event EventHandler OnSimulatorExited;
2022-07-23 19:23:32 +00:00
2024-02-28 02:44:21 +00:00
public event EventHandler OnFlightStarted;
2022-07-23 19:23:32 +00:00
2024-02-28 02:44:21 +00:00
public event EventHandler OnFlightStopped;
2022-07-23 19:23:32 +00:00
public void StartSimConnectServer()
{
2024-02-28 02:44:21 +00:00
_simConnectProvider ??= new SimConnectProvider();
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
_simConnectProvider.OnConnected += (_, _) =>
2022-07-23 19:23:32 +00:00
{
2024-02-28 02:44:21 +00:00
FlightSimData.IsSimConnectActive = true;
FlightSimData.IsSimulatorStarted = true;
2023-07-12 22:41:31 +00:00
WindowProcessManager.GetSimulatorProcess(); // refresh simulator process
DetectMsfsExit();
2024-02-28 02:44:21 +00:00
2024-03-14 22:50:32 +00:00
StartDynamicLod();
2022-07-23 19:23:32 +00:00
};
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
_simConnectProvider.OnDisconnected += (_, _) =>
2022-07-23 19:23:32 +00:00
{
2024-02-28 02:44:21 +00:00
FlightSimData.IsSimConnectDataReceived = false;
FlightSimData.IsSimConnectActive = false;
2023-07-12 22:41:31 +00:00
WindowProcessManager.GetSimulatorProcess(); // refresh simulator process
2024-02-28 02:44:21 +00:00
FlightSimData.Reset();
2022-07-23 19:23:32 +00:00
};
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
_simConnectProvider.OnException += (_, _) =>
2023-08-05 03:40:29 +00:00
{
2024-02-28 02:44:21 +00:00
FlightSimData.IsSimConnectDataReceived = false;
FlightSimData.IsSimConnectActive = false;
2023-08-05 03:40:29 +00:00
};
2024-02-28 02:44:21 +00:00
_simConnectProvider.OnSimConnectDataRequiredRefreshed += (_, e) =>
2022-07-23 19:23:32 +00:00
{
2024-03-14 22:50:32 +00:00
MapRequiredSimConnectData(e);
};
2024-02-28 02:44:21 +00:00
2024-03-14 22:50:32 +00:00
_simConnectProvider.OnSimConnectDataHudBarRefreshed += (_, e) =>
{
if (!ProfileData.ActiveProfile.ProfileSetting.HudBarConfig.IsEnabled || !FlightSimData.IsFlightStarted)
return;
2023-08-14 04:35:14 +00:00
2024-03-14 22:50:32 +00:00
MapHudBarSimConnectData(e);
};
2024-02-28 02:44:21 +00:00
2024-09-19 18:30:52 +00:00
var _lastDynamicLodPause = DateTime.Now;
var _isDynamicLodPausePrevously = true;
var _lastDyanmicLodUpdatedTime = DateTime.Now;
2024-03-14 22:50:32 +00:00
_simConnectProvider.OnSimConnectDataDynamicLodRefreshed += (_, e) =>
{
2024-03-15 12:55:55 +00:00
if (!AppSettingData.ApplicationSetting.DynamicLodSetting.IsEnabled || !FlightSimData.IsFlightStarted)
2024-03-14 22:50:32 +00:00
return;
2023-08-18 21:02:03 +00:00
2024-03-15 12:55:55 +00:00
var isPaused = (AppSettingData.ApplicationSetting.DynamicLodSetting.PauseWhenMsfsLoseFocus && !WindowActionManager.IsMsfsInFocus()) ||
(AppSettingData.ApplicationSetting.DynamicLodSetting.PauseOutsideCockpitView && FlightSimData.CameraState != CameraState.Cockpit);
2024-09-19 18:30:52 +00:00
if (_isDynamicLodPausePrevously && !isPaused)
{
if (DateTime.Now - _lastDynamicLodPause <= TimeSpan.FromSeconds(3))
return;
_lastDynamicLodPause = DateTime.Now;
_isDynamicLodPausePrevously = false;
}
else if (isPaused)
{
_isDynamicLodPausePrevously = true;
2024-03-15 12:55:55 +00:00
return;
2024-09-19 18:30:52 +00:00
}
if (DateTime.Now - _lastDyanmicLodUpdatedTime <= TimeSpan.FromSeconds(0.4)) // take FPS sample every 0.4 seconds
return;
_lastDyanmicLodUpdatedTime = DateTime.Now;
2024-09-06 02:58:59 +00:00
MapDynamicLodSimConnectData(e);
_dynamicLodOrchestrator.UpdateLod();
2023-07-12 22:41:31 +00:00
};
2022-07-23 19:23:32 +00:00
2024-03-14 22:50:32 +00:00
_simConnectProvider.OnSimConnectDataEventFrameRefreshed += (_, e) =>
2023-07-12 22:41:31 +00:00
{
2024-03-14 22:50:32 +00:00
if (!AppSettingData.ApplicationSetting.DynamicLodSetting.IsEnabled || !FlightSimData.IsFlightStarted)
return;
MapEventFrameData(e);
2023-07-12 22:41:31 +00:00
};
2024-02-28 02:44:21 +00:00
_simConnectProvider.OnActiveAircraftChanged += (_, e) =>
2023-07-12 22:41:31 +00:00
{
2024-03-14 22:50:32 +00:00
var aircraftName = string.IsNullOrEmpty(e) ? null : e;
2024-02-28 02:44:21 +00:00
if (FlightSimData.AircraftName != aircraftName)
2022-07-23 19:23:32 +00:00
{
2024-02-28 02:44:21 +00:00
FlightSimData.AircraftName = aircraftName;
ProfileData.RefreshProfile();
2022-07-23 19:23:32 +00:00
}
};
2023-07-12 22:41:31 +00:00
2022-08-19 16:03:12 +00:00
_simConnectProvider.OnFlightStarted += HandleOnFlightStarted;
2022-07-23 19:23:32 +00:00
_simConnectProvider.OnFlightStopped += HandleOnFlightStopped;
2024-02-28 02:44:21 +00:00
_simConnectProvider.OnIsInCockpitChanged += (_, e) =>
{
FlightSimData.IsInCockpit = e;
if (e)
FlightSimData.IsFlightStarted = true;
};
2022-07-23 19:23:32 +00:00
_simConnectProvider.Start();
}
public void EndSimConnectServer(bool appExit)
{
_simConnectProvider.Stop(appExit);
2023-07-12 22:41:31 +00:00
_simConnectProvider = null;
2022-07-23 19:23:32 +00:00
}
2023-08-16 03:41:14 +00:00
public void TurnOnTrackIR()
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (!AppSettingData.ApplicationSetting.TrackIRSetting.AutoDisableTrackIR)
2023-07-12 22:41:31 +00:00
return;
2023-08-16 03:41:14 +00:00
WorkflowStepWithMessage.Execute("Turning on TrackIR", () =>
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
var count = 0;
2023-08-16 03:41:14 +00:00
do
{
_simConnectProvider.TurnOnTrackIR();
Thread.Sleep(500);
count++;
}
2024-02-28 02:44:21 +00:00
while (!FlightSimData.TrackIRStatus && count < 5);
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
return FlightSimData.TrackIRStatus;
2023-08-16 03:41:14 +00:00
});
2022-07-23 19:23:32 +00:00
}
2023-08-16 03:41:14 +00:00
public void TurnOffTrackIR()
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (!AppSettingData.ApplicationSetting.TrackIRSetting.AutoDisableTrackIR)
2023-07-12 22:41:31 +00:00
return;
2023-08-16 03:41:14 +00:00
WorkflowStepWithMessage.Execute("Turning off TrackIR", () =>
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
var count = 0;
2023-08-16 03:41:14 +00:00
do
{
_simConnectProvider.TurnOffTrackIR();
Thread.Sleep(500);
count++;
}
2024-02-28 02:44:21 +00:00
while (FlightSimData.TrackIRStatus && count < 5);
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
return !FlightSimData.TrackIRStatus;
2023-08-16 03:41:14 +00:00
});
2022-07-23 19:23:32 +00:00
}
public void TurnOnPower()
{
2023-07-12 22:41:31 +00:00
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (ProfileData.ActiveProfile == null || FlightSimData.ElectricalMasterBatteryStatus)
2023-07-12 22:41:31 +00:00
return;
_isTurnedOnPower = true;
2023-08-16 03:41:14 +00:00
WorkflowStepWithMessage.Execute("Turning on battery", () =>
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
var count = 0;
2023-08-16 03:41:14 +00:00
do
{
2024-02-28 02:44:21 +00:00
_simConnectProvider.TurnOnPower(ProfileData.ActiveProfile.ProfileSetting.PowerOnRequiredForColdStart);
2023-08-16 03:41:14 +00:00
Thread.Sleep(500);
count++;
}
2024-02-28 02:44:21 +00:00
while (!FlightSimData.ElectricalMasterBatteryStatus && count < 10);
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
return FlightSimData.ElectricalMasterBatteryStatus;
2023-08-16 03:41:14 +00:00
});
2022-07-23 19:23:32 +00:00
}
2023-07-12 22:41:31 +00:00
public void TurnOffPower()
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (ProfileData.ActiveProfile == null || !_isTurnedOnPower)
2023-07-12 22:41:31 +00:00
return;
2023-08-16 03:41:14 +00:00
WorkflowStepWithMessage.Execute("Turning off battery", () =>
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
var count = 0;
2023-08-16 03:41:14 +00:00
do
{
2024-02-28 02:44:21 +00:00
_simConnectProvider.TurnOffPower(ProfileData.ActiveProfile.ProfileSetting.PowerOnRequiredForColdStart);
2023-08-16 03:41:14 +00:00
Thread.Sleep(500);
count++;
}
2024-02-28 02:44:21 +00:00
while (FlightSimData.ElectricalMasterBatteryStatus && count < 10);
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
return !FlightSimData.ElectricalMasterBatteryStatus;
2023-08-16 03:41:14 +00:00
});
2023-07-12 22:41:31 +00:00
_isTurnedOnPower = false;
2022-07-23 19:23:32 +00:00
}
2023-07-12 22:41:31 +00:00
public void TurnOnAvionics()
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (ProfileData.ActiveProfile == null || FlightSimData.AvionicsMasterSwitchStatus)
2023-07-12 22:41:31 +00:00
return;
_isTurnedOnAvionics = true;
2023-08-16 03:41:14 +00:00
WorkflowStepWithMessage.Execute("Turning on avionics", () =>
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
var count = 0;
2023-08-16 03:41:14 +00:00
do
{
2024-02-28 02:44:21 +00:00
_simConnectProvider.TurnOnAvionics(ProfileData.ActiveProfile.ProfileSetting.PowerOnRequiredForColdStart);
2023-08-16 03:41:14 +00:00
Thread.Sleep(500);
count++;
}
2024-02-28 02:44:21 +00:00
while (!FlightSimData.AvionicsMasterSwitchStatus && count < 10);
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
return FlightSimData.AvionicsMasterSwitchStatus;
2023-08-16 03:41:14 +00:00
});
2022-07-23 19:23:32 +00:00
}
public void TurnOffAvionics()
{
2023-07-12 22:41:31 +00:00
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (ProfileData.ActiveProfile == null || !_isTurnedOnAvionics)
2023-07-12 22:41:31 +00:00
return;
2023-08-16 03:41:14 +00:00
WorkflowStepWithMessage.Execute("Turning off avionics", () =>
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
var count = 0;
2023-08-16 03:41:14 +00:00
do
{
2024-02-28 02:44:21 +00:00
_simConnectProvider.TurnOffAvionics(ProfileData.ActiveProfile.ProfileSetting.PowerOnRequiredForColdStart);
2023-08-16 03:41:14 +00:00
Thread.Sleep(500);
count++;
}
2024-02-28 02:44:21 +00:00
while (FlightSimData.AvionicsMasterSwitchStatus && count < 10);
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
return !FlightSimData.AvionicsMasterSwitchStatus;
2023-08-16 03:41:14 +00:00
});
2023-07-12 22:41:31 +00:00
_isTurnedOnAvionics = false;
2022-07-23 19:23:32 +00:00
}
2023-07-12 22:41:31 +00:00
public void TurnOnActivePause()
2022-07-23 19:23:32 +00:00
{
2023-07-12 22:41:31 +00:00
if (_simConnectProvider == null)
return;
2022-07-23 19:23:32 +00:00
2024-02-28 02:44:21 +00:00
if (!AppSettingData.ApplicationSetting.PopOutSetting.AutoActivePause)
2023-07-12 22:41:31 +00:00
return;
2023-08-16 03:41:14 +00:00
WorkflowStepWithMessage.Execute("Turning on active pause", () =>
{
_simConnectProvider.TurnOnActivePause();
});
2023-07-12 22:41:31 +00:00
}
public void TurnOffActivePause()
{
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (!AppSettingData.ApplicationSetting.PopOutSetting.AutoActivePause)
2023-07-12 22:41:31 +00:00
return;
2023-08-16 03:41:14 +00:00
WorkflowStepWithMessage.Execute("Turning off active pause", () =>
{
_simConnectProvider.TurnOffActivePause();
});
2023-07-12 22:41:31 +00:00
}
public void IncreaseSimRate()
{
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (Convert.ToInt32(FlightSimData.HudBarData.SimRate) == 16)
2023-07-12 22:41:31 +00:00
return;
_simConnectProvider.IncreaseSimRate();
}
public void DecreaseSimRate()
{
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
if (FlightSimData.HudBarData.SimRate.ToString("N2") == "0.25")
2023-07-12 22:41:31 +00:00
return;
_simConnectProvider.DecreaseSimRate();
}
2023-07-30 21:30:47 +00:00
public void SetCockpitCameraZoomLevel(int zoomLevel)
{
_simConnectProvider.SetCockpitCameraZoomLevel(zoomLevel);
}
2023-08-16 03:41:14 +00:00
public void ResetCameraView()
{
_simConnectProvider.SetCameraRequestAction(1);
}
2024-02-28 02:44:21 +00:00
public void SetFixedCamera(CameraType cameraType, int index)
{
2024-02-29 00:54:25 +00:00
if (FlightSimData.CameraState != CameraState.Cockpit)
{
_simConnectProvider.SetCameraState(CameraState.Cockpit);
Thread.Sleep(250);
ResetCameraView();
Thread.Sleep(250);
}
2024-02-28 02:44:21 +00:00
_simConnectProvider.SetCameraViewTypeAndIndex0(Convert.ToInt32(cameraType));
Thread.Sleep(250);
_simConnectProvider.SetCameraViewTypeAndIndex1(index);
}
2023-07-12 22:41:31 +00:00
public void SetHudBarConfig()
{
if (_simConnectProvider == null)
return;
2024-02-28 02:44:21 +00:00
var hudBarType = ProfileData.ActiveProfile.ProfileSetting.HudBarConfig.HudBarType;
2023-07-12 22:41:31 +00:00
switch (hudBarType)
{
case HudBarType.PMDG_737:
2024-02-28 02:44:21 +00:00
FlightSimData.HudBarData = new HudBarData737();
2023-07-12 22:41:31 +00:00
break;
case HudBarType.Generic_Aircraft:
default:
2024-02-28 02:44:21 +00:00
FlightSimData.HudBarData = new HudBarDataGeneric();
2023-07-12 22:41:31 +00:00
break;
}
_simConnectProvider.SetHudBarConfig(hudBarType);
}
public void StopHudBar()
{
_simConnectProvider.StopHudBar();
}
private void HandleOnFlightStarted(object sender, EventArgs e)
{
2024-02-28 02:44:21 +00:00
OnFlightStarted?.Invoke(this, EventArgs.Empty);
FlightSimData.IsFlightStarted = true;
2024-03-14 22:50:32 +00:00
StartDynamicLod();
2022-07-23 19:23:32 +00:00
}
private void HandleOnFlightStopped(object sender, EventArgs e)
{
2024-02-28 02:44:21 +00:00
ProfileData.ResetActiveProfile();
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
OnFlightStopped?.Invoke(this, EventArgs.Empty);
2023-07-12 22:41:31 +00:00
2024-03-12 13:14:17 +00:00
CloseAllPopOuts();
2024-02-28 02:44:21 +00:00
FlightSimData.HudBarData?.Clear();
FlightSimData.IsFlightStarted = false;
2024-03-14 22:50:32 +00:00
StopDynamicLod();
2024-09-06 02:58:59 +00:00
FpsCalc.Reset();
2024-03-14 22:50:32 +00:00
FlightSimData.DynamicLodSimData.Clear();
2023-07-12 22:41:31 +00:00
}
private void DetectMsfsExit()
{
_msfsGameExitDetectionTimer = new System.Timers.Timer();
_msfsGameExitDetectionTimer.Interval = MSFS_GAME_EXIT_DETECTION_INTERVAL;
_msfsGameExitDetectionTimer.Enabled = true;
2024-02-28 02:44:21 +00:00
_msfsGameExitDetectionTimer.Elapsed += (_, _) =>
2023-07-12 22:41:31 +00:00
{
WindowProcessManager.GetSimulatorProcess();
2024-02-28 02:44:21 +00:00
if (WindowProcessManager.SimulatorProcess != null)
return;
if (AppSettingData.ApplicationSetting.GeneralSetting.AutoClose)
2023-07-12 22:41:31 +00:00
{
2024-02-28 02:44:21 +00:00
OnSimulatorExited?.Invoke(this, EventArgs.Empty);
return;
2023-07-12 22:41:31 +00:00
}
2024-02-28 02:44:21 +00:00
FlightSimData.Reset();
_simConnectProvider.StopAndReconnect();
2023-07-12 22:41:31 +00:00
};
}
2024-03-14 22:50:32 +00:00
private void MapRequiredSimConnectData(List<SimDataItem> simData)
{
var electricalMasterBattery = Convert.ToBoolean(simData.Find(d => d.PropertyName == SimDataDefinitions.PropName.ElectricalMasterBattery).Value);
if (electricalMasterBattery != FlightSimData.ElectricalMasterBatteryStatus)
FlightSimData.ElectricalMasterBatteryStatus = electricalMasterBattery;
var avionicsMasterSwitch = Convert.ToBoolean(simData.Find(d => d.PropertyName == SimDataDefinitions.PropName.AvionicsMasterSwitch).Value);
if (avionicsMasterSwitch != FlightSimData.AvionicsMasterSwitchStatus)
FlightSimData.AvionicsMasterSwitchStatus = avionicsMasterSwitch;
var trackIR = Convert.ToBoolean(simData.Find(d => d.PropertyName == SimDataDefinitions.PropName.TrackIREnable).Value);
if (trackIR != FlightSimData.TrackIRStatus)
FlightSimData.TrackIRStatus = trackIR;
var cameraStateInt = Convert.ToInt32(simData.Find(d => d.PropertyName == SimDataDefinitions.PropName.CameraState).Value);
var result = Enum.TryParse<CameraState>(cameraStateInt.ToString(), out var cameraState);
if (!result)
cameraState = CameraState.Unknown;
if (cameraState != FlightSimData.CameraState)
FlightSimData.CameraState = cameraState;
var cockpitCameraZoom = Convert.ToInt32(simData.Find(d => d.PropertyName == SimDataDefinitions.PropName.CockpitCameraZoom).Value);
if (cockpitCameraZoom != FlightSimData.CockpitCameraZoom)
FlightSimData.CockpitCameraZoom = cockpitCameraZoom;
var cameraViewTypeAndIndex0 = Convert.ToInt32(simData.Find(d => d.PropertyName == SimDataDefinitions.PropName.CameraViewTypeAndIndex0).Value);
if (cameraViewTypeAndIndex0 != FlightSimData.CameraViewTypeAndIndex0)
FlightSimData.CameraViewTypeAndIndex0 = cameraViewTypeAndIndex0;
var cameraViewTypeAndIndex1 = Convert.ToInt32(simData.Find(d => d.PropertyName == SimDataDefinitions.PropName.CameraViewTypeAndIndex1).Value);
if (cameraViewTypeAndIndex1 != FlightSimData.CameraViewTypeAndIndex1)
FlightSimData.CameraViewTypeAndIndex1 = cameraViewTypeAndIndex1;
var cameraViewTypeAndIndex1Max = Convert.ToInt32(simData.Find(d => d.PropertyName == SimDataDefinitions.PropName.CameraViewTypeAndIndex1Max).Value);
if (cameraViewTypeAndIndex1Max != FlightSimData.CameraViewTypeAndIndex1Max)
FlightSimData.CameraViewTypeAndIndex1Max = cameraViewTypeAndIndex1Max;
var cameraViewTypeAndIndex2Max = Convert.ToInt32(simData.Find(d => d.PropertyName == SimDataDefinitions.PropName.CameraViewTypeAndIndex2Max).Value);
if (cameraViewTypeAndIndex2Max != FlightSimData.CameraViewTypeAndIndex2Max)
FlightSimData.CameraViewTypeAndIndex2Max = cameraViewTypeAndIndex2Max;
FlightSimData.IsSimConnectDataReceived = true;
}
2023-07-12 22:41:31 +00:00
private void MapHudBarSimConnectData(List<SimDataItem> simData)
{
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.ElevatorTrim, FlightSimData.HudBarData.ElevatorTrim, out var newValue))
FlightSimData.HudBarData.ElevatorTrim = newValue;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.AileronTrim, FlightSimData.HudBarData.AileronTrim, out newValue))
FlightSimData.HudBarData.AileronTrim = newValue;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.RudderTrim, FlightSimData.HudBarData.RudderTrim, out newValue))
FlightSimData.HudBarData.RudderTrim = newValue;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.ParkingBrake, FlightSimData.HudBarData.ParkingBrake, out newValue))
FlightSimData.HudBarData.ParkingBrake = newValue;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.Flap, FlightSimData.HudBarData.Flap, out newValue))
FlightSimData.HudBarData.Flap = newValue;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.GearLeft, FlightSimData.HudBarData.GearLeft, out newValue))
FlightSimData.HudBarData.GearLeft = newValue;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.GearCenter, FlightSimData.HudBarData.GearCenter, out newValue))
FlightSimData.HudBarData.GearCenter = newValue;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.GearRight, FlightSimData.HudBarData.GearRight, out newValue))
FlightSimData.HudBarData.GearRight = newValue;
2023-07-12 22:41:31 +00:00
2024-02-28 02:44:21 +00:00
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.SimRate, FlightSimData.HudBarData.SimRate, out newValue))
FlightSimData.HudBarData.SimRate = newValue;
2023-07-12 22:41:31 +00:00
}
2024-09-06 02:58:59 +00:00
private void MapDynamicLodSimConnectData(List<SimDataItem> simData)
2024-03-14 22:50:32 +00:00
{
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.PlaneAltAboveGround, FlightSimData.DynamicLodSimData.Agl, out var newValue))
FlightSimData.DynamicLodSimData.Agl = newValue;
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.PlaneAltAboveGround, FlightSimData.DynamicLodSimData.AltAboveGround, out newValue))
FlightSimData.DynamicLodSimData.AltAboveGround = newValue;
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.PlaneAltAboveGroundMinusCg, FlightSimData.DynamicLodSimData.AltAboveGroundMinusCg, out newValue))
FlightSimData.DynamicLodSimData.AltAboveGroundMinusCg = newValue;
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.GroundVelocity, FlightSimData.DynamicLodSimData.GroundVelocity, out newValue))
FlightSimData.DynamicLodSimData.GroundVelocity = newValue;
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.SimOnGround, 1.0f, out newValue))
FlightSimData.DynamicLodSimData.PlaneOnGround = Convert.ToBoolean(newValue);
2024-09-06 02:58:59 +00:00
var tlod = _dynamicLodOrchestrator.ReadTlod();
2024-03-14 22:50:32 +00:00
if (FlightSimData.DynamicLodSimData.Tlod != tlod)
FlightSimData.DynamicLodSimData.Tlod = tlod;
2024-09-06 02:58:59 +00:00
var olod = _dynamicLodOrchestrator.ReadOlod();
2024-03-14 22:50:32 +00:00
if (FlightSimData.DynamicLodSimData.Olod != olod)
FlightSimData.DynamicLodSimData.Olod = olod;
2024-09-06 02:58:59 +00:00
var cloudQuality = _dynamicLodOrchestrator.ReadCloudQuality();
2024-03-14 22:50:32 +00:00
if (FlightSimData.DynamicLodSimData.CloudQuality != cloudQuality)
FlightSimData.DynamicLodSimData.CloudQuality = cloudQuality;
2024-09-06 02:58:59 +00:00
FlightSimData.DynamicLodSimData.Fps = FpsCalc.GetAverageFps(_dynamicLodOrchestrator.ReadIsFg() ? _currentFps * 2 : _currentFps);
2024-03-14 22:50:32 +00:00
}
private int _currentFps;
private void MapEventFrameData(int fps)
{
if (!AppSettingData.ApplicationSetting.DynamicLodSetting.IsEnabled)
return;
_currentFps = fps;
}
2023-07-12 22:41:31 +00:00
private bool CompareSimConnectData(List<SimDataItem> simData, string propName, double source, out double newValue)
{
var propData = simData.Find(d => d.PropertyName == propName);
if (propData == null)
{
newValue = 0;
return false;
}
var value = Convert.ToDouble(simData.Find(d => d.PropertyName == propName).Value);
2024-02-28 02:44:21 +00:00
if (Math.Abs(value - source) > 0.000000000000001)
2023-07-12 22:41:31 +00:00
{
newValue = value;
return true;
}
newValue = 0;
return false;
2022-07-23 19:23:32 +00:00
}
2024-03-14 22:50:32 +00:00
private void StartDynamicLod()
{
if (_simConnectProvider != null)
{
// Attach in memory override for Dynamic LOD
if (AppSettingData != null && AppSettingData.ApplicationSetting.DynamicLodSetting.IsEnabled)
_dynamicLodOrchestrator.Attach();
_simConnectProvider.StartDynamicLod();
}
}
private void StopDynamicLod()
{
// Detach in memory override for Dynamic LOD
if (AppSettingData != null && AppSettingData.ApplicationSetting.DynamicLodSetting.IsEnabled)
_dynamicLodOrchestrator.Detach();
_simConnectProvider.StopDynamicLod();
}
2022-07-23 19:23:32 +00:00
}
}