1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-21 13:20:11 +00:00

Update dynamic lod

This commit is contained in:
hawkeye 2024-03-15 08:55:55 -04:00
parent c68ec210d1
commit b9d21d58ee
7 changed files with 44 additions and 26 deletions

View file

@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
--> -->
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<Configuration>Release</Configuration> <Configuration>Local</Configuration>
<Platform>x64</Platform> <Platform>x64</Platform>
<PublishDir>..\..\..\publish\master</PublishDir> <PublishDir>..\..\..\publish\master</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol> <PublishProtocol>FileSystem</PublishProtocol>

View file

@ -283,27 +283,29 @@ namespace MSFSPopoutPanelManager.Orchestration
return; return;
// Adjust cloud quality if applicable // Adjust cloud quality if applicable
if (deltaFps < 0 && newTlod < DynamicLodSetting.CloudRecoveryTlod && !_isDecreasedCloudQualityActive) if (DynamicLodSetting.DecreaseCloudQuality && (!DynamicLodSetting.TlodMinOnGround && !(SimData.AltAboveGround <= DynamicLodSetting.AltTlodBase)))
{ {
switch (deltaFps)
{
case < 0 when newTlod < DynamicLodSetting.CloudRecoveryTlod && !_isDecreasedCloudQualityActive:
_isDecreasedCloudQualityActive = true; _isDecreasedCloudQualityActive = true;
WriteMemory(isVr ? _addressCloudQVr : _addressCloudQ, ReadCloudQualitySimValue(isVr) - 1); // High WriteMemory(isVr ? _addressCloudQVr : _addressCloudQ, ReadCloudQualitySimValue(isVr) - 1);
_lastLodUpdateTime = _lastLodUpdateTime.AddSeconds(2); // Add extra delay for cloud setting to take effect _lastLodUpdateTime =
_lastLodUpdateTime.AddSeconds(2); // Add extra delay for cloud setting to take effect
Debug.WriteLine("New Cloud Quality written - 2."); Debug.WriteLine("New Cloud Quality written - 2.");
return; return;
} case > 0 when newTlod >= DynamicLodSetting.CloudRecoveryTlod && _isDecreasedCloudQualityActive:
if (deltaFps > 0 && newTlod >= DynamicLodSetting.CloudRecoveryTlod && _isDecreasedCloudQualityActive)
{
_isDecreasedCloudQualityActive = false; _isDecreasedCloudQualityActive = false;
WriteMemory(isVr ? _addressCloudQVr : _addressCloudQ, ReadCloudQualitySimValue(isVr) + 1); // Ultra WriteMemory(isVr ? _addressCloudQVr : _addressCloudQ, ReadCloudQualitySimValue(isVr) + 1);
_lastLodUpdateTime = _lastLodUpdateTime.AddSeconds(2); _lastLodUpdateTime = _lastLodUpdateTime.AddSeconds(2);
Debug.WriteLine("New Cloud Quality written - 3."); Debug.WriteLine("New Cloud Quality written - 3.");
return; return;
} }
}
Debug.WriteLine($"New TLOD written - {newTlod}."); Debug.WriteLine($"New TLOD written - {newTlod}.");
WriteMemory(isVr ? _addressTlodVr : _addressTlod, newTlod / 100.0f); WriteMemory(isVr ? _addressTlodVr : _addressTlod, newTlod / 100.0f);

View file

@ -74,12 +74,19 @@ namespace MSFSPopoutPanelManager.Orchestration
_simConnectProvider.OnSimConnectDataDynamicLodRefreshed += (_, e) => _simConnectProvider.OnSimConnectDataDynamicLodRefreshed += (_, e) =>
{ {
if (!AppSettingData.ApplicationSetting.DynamicLodSetting.IsEnabled || !FlightSimData.IsFlightStarted || !WindowActionManager.IsMsfsInFocus()) if (!AppSettingData.ApplicationSetting.DynamicLodSetting.IsEnabled || !FlightSimData.IsFlightStarted)
return; return;
var isVr = _dynamicLodOrchestrator.ReadIsVr(); var isVr = _dynamicLodOrchestrator.ReadIsVr();
MapDynamicLodSimConnectData(e, isVr); 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); _dynamicLodOrchestrator.UpdateLod(isVr);
}; };
@ -513,10 +520,6 @@ namespace MSFSPopoutPanelManager.Orchestration
var cloudQuality = _dynamicLodOrchestrator.ReadCloudQuality(isVr); var cloudQuality = _dynamicLodOrchestrator.ReadCloudQuality(isVr);
if (FlightSimData.DynamicLodSimData.CloudQuality != cloudQuality) if (FlightSimData.DynamicLodSimData.CloudQuality != cloudQuality)
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; private int _currentFps;

View file

@ -5,7 +5,7 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
{ {
public class FpsCalc public class FpsCalc
{ {
private const int FpsLen = 50; private const int FpsLen = 25;
private static readonly float[] FpsStatistic = new float[FpsLen]; private static readonly float[] FpsStatistic = new float[FpsLen];
private static int _fpsIndex = -1; private static int _fpsIndex = -1;

View file

@ -86,6 +86,8 @@ namespace MSFSPopoutPanelManager.WindowsAgent
if (_isHookMouseDown) if (_isHookMouseDown)
return; return;
PInvoke.SetForegroundWindow(WindowProcessManager.SimulatorProcess.Handle);
var rect = WindowActionManager.GetWindowRectangle(WindowProcessManager.SimulatorProcess.Handle); var rect = WindowActionManager.GetWindowRectangle(WindowProcessManager.SimulatorProcess.Handle);
PInvoke.SetCursorPos(rect.X + rect.Width / 2, rect.Y + rect.Height / 2); PInvoke.SetCursorPos(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
} }

View file

@ -192,6 +192,8 @@ namespace MSFSPopoutPanelManager.WindowsAgent
if (currentRefocusIndex == _refocusedTaskIndex) if (currentRefocusIndex == _refocusedTaskIndex)
{ {
PInvoke.SetForegroundWindow(WindowProcessManager.SimulatorProcess.Handle);
var rect = WindowActionManager.GetWindowRectangle(WindowProcessManager.SimulatorProcess.Handle); var rect = WindowActionManager.GetWindowRectangle(WindowProcessManager.SimulatorProcess.Handle);
PInvoke.SetCursorPos(rect.X + rect.Width / 2, rect.Y + rect.Height / 2); PInvoke.SetCursorPos(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
} }

View file

@ -298,7 +298,16 @@ namespace MSFSPopoutPanelManager.WindowsAgent
public static bool IsMsfsInFocus() public static bool IsMsfsInFocus()
{ {
var handle = PInvoke.GetForegroundWindow(); 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);
} }
} }
} }