From b9d21d58ee5d3197d8aadf89a69a38389397b260 Mon Sep 17 00:00:00 2001 From: hawkeye Date: Fri, 15 Mar 2024 08:55:55 -0400 Subject: [PATCH] Update dynamic lod --- .../PublishProfiles/FolderProfile.pubxml | 2 +- Orchestration/DynamicLodOrchestrator.cs | 36 ++++++++++--------- Orchestration/FlightSimOrchestrator.cs | 15 ++++---- SimconnectAgent/FpsCalc.cs | 2 +- WindowsAgent/GameRefocusManager.cs | 2 ++ WindowsAgent/TouchEventManager.cs | 2 ++ WindowsAgent/WindowActionManager.cs | 11 +++++- 7 files changed, 44 insertions(+), 26 deletions(-) diff --git a/MainApp/Properties/PublishProfiles/FolderProfile.pubxml b/MainApp/Properties/PublishProfiles/FolderProfile.pubxml index 18dfaa2..118e0a6 100644 --- a/MainApp/Properties/PublishProfiles/FolderProfile.pubxml +++ b/MainApp/Properties/PublishProfiles/FolderProfile.pubxml @@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> - Release + Local x64 ..\..\..\publish\master FileSystem diff --git a/Orchestration/DynamicLodOrchestrator.cs b/Orchestration/DynamicLodOrchestrator.cs index 1253473..75b2d92 100644 --- a/Orchestration/DynamicLodOrchestrator.cs +++ b/Orchestration/DynamicLodOrchestrator.cs @@ -283,28 +283,30 @@ namespace MSFSPopoutPanelManager.Orchestration return; // Adjust cloud quality if applicable - if (deltaFps < 0 && newTlod < DynamicLodSetting.CloudRecoveryTlod && !_isDecreasedCloudQualityActive) + if (DynamicLodSetting.DecreaseCloudQuality && (!DynamicLodSetting.TlodMinOnGround && !(SimData.AltAboveGround <= DynamicLodSetting.AltTlodBase))) { - _isDecreasedCloudQualityActive = true; - WriteMemory(isVr ? _addressCloudQVr : _addressCloudQ, ReadCloudQualitySimValue(isVr) - 1); // High + switch (deltaFps) + { + case < 0 when newTlod < DynamicLodSetting.CloudRecoveryTlod && !_isDecreasedCloudQualityActive: + _isDecreasedCloudQualityActive = true; + WriteMemory(isVr ? _addressCloudQVr : _addressCloudQ, ReadCloudQualitySimValue(isVr) - 1); - _lastLodUpdateTime = _lastLodUpdateTime.AddSeconds(2); // Add extra delay for cloud setting to take effect - Debug.WriteLine("New Cloud Quality written - 2."); + _lastLodUpdateTime = + _lastLodUpdateTime.AddSeconds(2); // Add extra delay for cloud setting to take effect + Debug.WriteLine("New Cloud Quality written - 2."); - return; + return; + case > 0 when newTlod >= DynamicLodSetting.CloudRecoveryTlod && _isDecreasedCloudQualityActive: + _isDecreasedCloudQualityActive = false; + WriteMemory(isVr ? _addressCloudQVr : _addressCloudQ, ReadCloudQualitySimValue(isVr) + 1); + + _lastLodUpdateTime = _lastLodUpdateTime.AddSeconds(2); + Debug.WriteLine("New Cloud Quality written - 3."); + + return; + } } - if (deltaFps > 0 && newTlod >= DynamicLodSetting.CloudRecoveryTlod && _isDecreasedCloudQualityActive) - { - _isDecreasedCloudQualityActive = false; - WriteMemory(isVr ? _addressCloudQVr : _addressCloudQ, ReadCloudQualitySimValue(isVr) + 1); // Ultra - - _lastLodUpdateTime = _lastLodUpdateTime.AddSeconds(2); - Debug.WriteLine("New Cloud Quality written - 3."); - - return; - } - Debug.WriteLine($"New TLOD written - {newTlod}."); WriteMemory(isVr ? _addressTlodVr : _addressTlod, newTlod / 100.0f); } diff --git a/Orchestration/FlightSimOrchestrator.cs b/Orchestration/FlightSimOrchestrator.cs index 202c7a8..b195575 100644 --- a/Orchestration/FlightSimOrchestrator.cs +++ b/Orchestration/FlightSimOrchestrator.cs @@ -74,12 +74,19 @@ namespace MSFSPopoutPanelManager.Orchestration _simConnectProvider.OnSimConnectDataDynamicLodRefreshed += (_, e) => { - if (!AppSettingData.ApplicationSetting.DynamicLodSetting.IsEnabled || !FlightSimData.IsFlightStarted || !WindowActionManager.IsMsfsInFocus()) + if (!AppSettingData.ApplicationSetting.DynamicLodSetting.IsEnabled || !FlightSimData.IsFlightStarted) return; var isVr = _dynamicLodOrchestrator.ReadIsVr(); - MapDynamicLodSimConnectData(e, isVr); + + var isPaused = (AppSettingData.ApplicationSetting.DynamicLodSetting.PauseWhenMsfsLoseFocus && !WindowActionManager.IsMsfsInFocus()) || + (AppSettingData.ApplicationSetting.DynamicLodSetting.PauseOutsideCockpitView && FlightSimData.CameraState != CameraState.Cockpit); + + if (isPaused) + return; + + FlightSimData.DynamicLodSimData.Fps = FpsCalc.GetAverageFps(_dynamicLodOrchestrator.ReadIsFg(isVr) ? _currentFps * 2 : _currentFps); _dynamicLodOrchestrator.UpdateLod(isVr); }; @@ -513,10 +520,6 @@ namespace MSFSPopoutPanelManager.Orchestration var cloudQuality = _dynamicLodOrchestrator.ReadCloudQuality(isVr); if (FlightSimData.DynamicLodSimData.CloudQuality != cloudQuality) FlightSimData.DynamicLodSimData.CloudQuality = cloudQuality; - - if (FlightSimData.IsFlightStarted && FlightSimData.IsInCockpit && - (!AppSettingData.ApplicationSetting.DynamicLodSetting.PauseOutsideCockpitView || (AppSettingData.ApplicationSetting.DynamicLodSetting.PauseOutsideCockpitView && FlightSimData.CameraState == CameraState.Cockpit))) - FlightSimData.DynamicLodSimData.Fps = FpsCalc.GetAverageFps(_dynamicLodOrchestrator.ReadIsFg(isVr) ? _currentFps * 2 : _currentFps); } private int _currentFps; diff --git a/SimconnectAgent/FpsCalc.cs b/SimconnectAgent/FpsCalc.cs index 903616f..6aff9e5 100644 --- a/SimconnectAgent/FpsCalc.cs +++ b/SimconnectAgent/FpsCalc.cs @@ -5,7 +5,7 @@ namespace MSFSPopoutPanelManager.SimConnectAgent { public class FpsCalc { - private const int FpsLen = 50; + private const int FpsLen = 25; private static readonly float[] FpsStatistic = new float[FpsLen]; private static int _fpsIndex = -1; diff --git a/WindowsAgent/GameRefocusManager.cs b/WindowsAgent/GameRefocusManager.cs index 7261c48..a8fb8af 100644 --- a/WindowsAgent/GameRefocusManager.cs +++ b/WindowsAgent/GameRefocusManager.cs @@ -86,6 +86,8 @@ namespace MSFSPopoutPanelManager.WindowsAgent if (_isHookMouseDown) return; + PInvoke.SetForegroundWindow(WindowProcessManager.SimulatorProcess.Handle); + var rect = WindowActionManager.GetWindowRectangle(WindowProcessManager.SimulatorProcess.Handle); PInvoke.SetCursorPos(rect.X + rect.Width / 2, rect.Y + rect.Height / 2); } diff --git a/WindowsAgent/TouchEventManager.cs b/WindowsAgent/TouchEventManager.cs index a5fe372..99c7640 100644 --- a/WindowsAgent/TouchEventManager.cs +++ b/WindowsAgent/TouchEventManager.cs @@ -192,6 +192,8 @@ namespace MSFSPopoutPanelManager.WindowsAgent if (currentRefocusIndex == _refocusedTaskIndex) { + PInvoke.SetForegroundWindow(WindowProcessManager.SimulatorProcess.Handle); + var rect = WindowActionManager.GetWindowRectangle(WindowProcessManager.SimulatorProcess.Handle); PInvoke.SetCursorPos(rect.X + rect.Width / 2, rect.Y + rect.Height / 2); } diff --git a/WindowsAgent/WindowActionManager.cs b/WindowsAgent/WindowActionManager.cs index 337b1da..ffd5a8c 100644 --- a/WindowsAgent/WindowActionManager.cs +++ b/WindowsAgent/WindowActionManager.cs @@ -298,7 +298,16 @@ namespace MSFSPopoutPanelManager.WindowsAgent public static bool IsMsfsInFocus() { var handle = PInvoke.GetForegroundWindow(); - return PInvoke.GetWindowText(handle).Substring(0, 26).Equals("Microsoft Flight Simulator", StringComparison.InvariantCultureIgnoreCase); + + var text = PInvoke.GetWindowText(handle); + + if (text == null) + return false; + + if (text.Length < 26) + return false; + + return text.Substring(0, 26).Equals("Microsoft Flight Simulator", StringComparison.InvariantCultureIgnoreCase); } } }