1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-12-04 11:40:10 +00:00

Update dynamic LOD

This commit is contained in:
hawkeye 2024-09-05 22:58:59 -04:00
parent 8f82f9a785
commit 06f0636c83
5 changed files with 80 additions and 79 deletions

View file

@ -26,6 +26,12 @@ namespace MSFSPopoutPanelManager.MainApp.AppWindow
StateChanged += AppWindow_StateChanged; StateChanged += AppWindow_StateChanged;
WindowActionManager.OnPopOutManagerAlwaysOnTopChanged += (_, e) => { Topmost = e; }; WindowActionManager.OnPopOutManagerAlwaysOnTopChanged += (_, e) => { Topmost = e; };
MouseLeftButtonDown += (_, _) => DragMove(); MouseLeftButtonDown += (_, _) => DragMove();
GotFocus += (_, _) =>
{
if (_viewModel.AppSettingData.ApplicationSetting.GeneralSetting.AlwaysOnTop)
WindowActionManager.ApplyAlwaysOnTop(_viewModel.ApplicationHandle, PanelType.PopOutManager, true);
};
} }
private void AppWindow_Loaded(object sender, RoutedEventArgs e) private void AppWindow_Loaded(object sender, RoutedEventArgs e)

View file

@ -1,7 +1,6 @@
using MSFSPopoutPanelManager.DomainModel.DynamicLod; using MSFSPopoutPanelManager.DomainModel.DynamicLod;
using MSFSPopoutPanelManager.DomainModel.Setting; using MSFSPopoutPanelManager.DomainModel.Setting;
using MSFSPopoutPanelManager.Shared; using MSFSPopoutPanelManager.Shared;
using MSFSPopoutPanelManager.SimConnectAgent;
using MSFSPopoutPanelManager.WindowsAgent; using MSFSPopoutPanelManager.WindowsAgent;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
@ -17,12 +16,9 @@ namespace MSFSPopoutPanelManager.Orchestration
private const int PROCESS_VM_WRITE = 0x0020; private const int PROCESS_VM_WRITE = 0x0020;
private const long OFFSET_MODULE_BASE =0x004B2368; private const long OFFSET_MODULE_BASE =0x004B2368;
private const long OFFSET_POINTER_MAIN = 0x3D0; private const long OFFSET_POINTER_MAIN = 0x3D0;
private const long OFFSET_POINTER_TLOD_VR = 0x114;
private const long OFFSET_POINTER_TLOD = 0xC; private const long OFFSET_POINTER_TLOD = 0xC;
private const long OFFSET_POINTER_OLOD = 0xC; private const long OFFSET_POINTER_OLOD = 0xC;
private const long OFFSET_POINTER_CLOUDQ = 0x44; private const long OFFSET_POINTER_CLOUD_QUALITY = 0x44;
private const long OFFSET_POINTER_CLOUDQ_VR = 0x108;
private const long OFFSET_POINTER_VR_MODE = 0x1C;
private const long OFFSET_POINTER_FG_MODE = 0x4A; private const long OFFSET_POINTER_FG_MODE = 0x4A;
private const long OFFSET_POINTER_ANSIO_FILTER = -0x18; private const long OFFSET_POINTER_ANSIO_FILTER = -0x18;
private const long OFFSET_POINTER_WATER_WAVES = 0x3C; private const long OFFSET_POINTER_WATER_WAVES = 0x3C;
@ -34,19 +30,15 @@ namespace MSFSPopoutPanelManager.Orchestration
private long _addressTlod; private long _addressTlod;
private long _addressOlod; private long _addressOlod;
private long _addressTlodVr;
private long _addressOlodVr;
private long _addressCloudQ; private long _addressCloudQ;
private long _addressCloudQVr;
private long _addressVrMode;
private long _addressFgMode; private long _addressFgMode;
private DynamicLodSetting DynamicLodSetting => AppSettingData.ApplicationSetting.DynamicLodSetting; private DynamicLodSetting DynamicLodSetting => AppSettingData.ApplicationSetting.DynamicLodSetting;
private DynamicLodSimData SimData => FlightSimData.DynamicLodSimData; private DynamicLodSimData DynamicLodSimData => FlightSimData.DynamicLodSimData;
private DateTime _lastLodUpdateTime = DateTime.Now; private DateTime _lastLodUpdateTime = DateTime.Now;
private bool _isDecreasedCloudQualityActive = false; private bool _isDecreasedCloudQualityActive;
public DynamicLodOrchestrator(SharedStorage sharedStorage) : base(sharedStorage) {} public DynamicLodOrchestrator(SharedStorage sharedStorage) : base(sharedStorage) {}
@ -70,13 +62,9 @@ namespace MSFSPopoutPanelManager.Orchestration
if (_addressTlod > 0) if (_addressTlod > 0)
{ {
_addressTlodVr = ReadMemory<long>(_addressTlod) + OFFSET_POINTER_TLOD_VR;
_addressTlod = ReadMemory<long>(_addressTlod) + OFFSET_POINTER_TLOD; _addressTlod = ReadMemory<long>(_addressTlod) + OFFSET_POINTER_TLOD;
_addressOlod = _addressTlod + OFFSET_POINTER_OLOD; _addressOlod = _addressTlod + OFFSET_POINTER_OLOD;
_addressOlodVr = _addressTlodVr + OFFSET_POINTER_OLOD; _addressCloudQ = _addressTlod + OFFSET_POINTER_CLOUD_QUALITY;
_addressCloudQ = _addressTlod + OFFSET_POINTER_CLOUDQ;
_addressCloudQVr = _addressCloudQ + OFFSET_POINTER_CLOUDQ_VR;
_addressVrMode = _addressTlod - OFFSET_POINTER_VR_MODE;
_addressFgMode = _addressTlod - OFFSET_POINTER_FG_MODE; _addressFgMode = _addressTlod - OFFSET_POINTER_FG_MODE;
if (!MemoryBoundaryTest()) if (!MemoryBoundaryTest())
@ -99,9 +87,8 @@ namespace MSFSPopoutPanelManager.Orchestration
if (DynamicLodSetting.ResetEnabled) if (DynamicLodSetting.ResetEnabled)
{ {
var isVr = ReadIsVr(); WriteMemory(_addressTlod, DynamicLodSetting.ResetTlod / 100.0f);
WriteMemory(isVr ? _addressTlodVr : _addressTlod, DynamicLodSetting.ResetTlod / 100.0f); WriteMemory(_addressOlod, DynamicLodSetting.ResetOlod / 100.0f);
WriteMemory(isVr ? _addressOlodVr : _addressOlod, DynamicLodSetting.ResetOlod / 100.0f);
} }
_isActive = false; _isActive = false;
@ -109,19 +96,19 @@ namespace MSFSPopoutPanelManager.Orchestration
Debug.WriteLine($"Reset to custom LOD: TLOD: {DynamicLodSetting.ResetTlod}, OLOD: {DynamicLodSetting.ResetOlod}"); Debug.WriteLine($"Reset to custom LOD: TLOD: {DynamicLodSetting.ResetTlod}, OLOD: {DynamicLodSetting.ResetOlod}");
} }
public int ReadTlod(bool isVr = false) public int ReadTlod()
{ {
return Convert.ToInt32(ReadMemory<float>(isVr ? _addressTlodVr : _addressTlod) * 100.0f); return Convert.ToInt32(ReadMemory<float>(_addressTlod) * 100.0f);
} }
public int ReadOlod(bool isVr = false) public int ReadOlod()
{ {
return Convert.ToInt32(ReadMemory<float>(isVr ? _addressOlodVr : _addressOlod) * 100.0f); return Convert.ToInt32(ReadMemory<float>(_addressOlod) * 100.0f);
} }
public string ReadCloudQuality(bool isVr = false) public string ReadCloudQuality()
{ {
return ReadCloudQualitySimValue(isVr) switch return ReadCloudQualitySimValue() switch
{ {
0 => "Low", 0 => "Low",
1 => "Medium", 1 => "Medium",
@ -131,33 +118,25 @@ namespace MSFSPopoutPanelManager.Orchestration
}; };
} }
public int ReadCloudQualitySimValue(bool isVr = false) public int ReadCloudQualitySimValue()
{ {
return Convert.ToInt32(ReadMemory<int>(isVr ? _addressCloudQVr : _addressCloudQ)); return Convert.ToInt32(ReadMemory<int>(_addressCloudQ));
} }
public bool ReadIsVr() public bool ReadIsFg()
{ {
return ReadMemory<int>(_addressVrMode) == 1;
}
public bool ReadIsFg(bool isVr)
{
if (isVr)
return false;
return ReadMemory<byte>(_addressFgMode) == 1; return ReadMemory<byte>(_addressFgMode) == 1;
} }
public void UpdateLod(bool isVr) public void UpdateLod()
{ {
if (!FlightSimData.IsFlightStarted || !FlightSimData.IsInCockpit)
return;
if (DateTime.Now - _lastLodUpdateTime <= TimeSpan.FromSeconds(1)) if (DateTime.Now - _lastLodUpdateTime <= TimeSpan.FromSeconds(1))
return; return;
if (!FlightSimData.IsFlightStarted || !FlightSimData.IsInCockpit || (DynamicLodSetting.PauseOutsideCockpitView && FlightSimData.CameraState != CameraState.Cockpit)) var deltaFps = DynamicLodSimData.Fps - DynamicLodSetting.TargetedFps;
return;
var deltaFps = SimData.Fps - DynamicLodSetting.TargetedFps;
if (Math.Abs(deltaFps) < DynamicLodSetting.TargetedFps * DynamicLodSetting.FpsTolerance / 100.0) // within FPS tolerance if (Math.Abs(deltaFps) < DynamicLodSetting.TargetedFps * DynamicLodSetting.FpsTolerance / 100.0) // within FPS tolerance
return; return;
@ -246,10 +225,9 @@ namespace MSFSPopoutPanelManager.Orchestration
private bool MemoryBoundaryTest() private bool MemoryBoundaryTest()
{ {
// Boundary check a few known setting memory addresses to see if any fail which likely indicates MSFS memory map has changed // Boundary check a few known setting memory addresses to see if any fail which likely indicates MSFS memory map has changed
if (ReadTlod() < 10 || ReadTlod() > 1000 || ReadTlod(true) < 10 || ReadTlod(true) > 1000 if (ReadTlod() < 10 || ReadTlod() > 1000 || ReadTlod() < 10 || ReadTlod() > 1000
|| ReadOlod() < 10 || ReadOlod() > 1000 || ReadOlod(true) < 10 || ReadOlod(true) > 1000 || ReadOlod() < 10 || ReadOlod() > 1000 || ReadOlod() < 10 || ReadOlod() > 1000
|| ReadCloudQuality() == "N/A" || ReadCloudQuality(true) == "N/A" || ReadCloudQuality() == "N/A" || ReadCloudQuality() == "N/A"
|| ReadMemory<int>(_addressVrMode) < 0 || ReadMemory<int>(_addressVrMode) > 1
|| ReadMemory<int>(_addressTlod + OFFSET_POINTER_ANSIO_FILTER) < 1 || ReadMemory<int>(_addressTlod + OFFSET_POINTER_ANSIO_FILTER) > 16 || ReadMemory<int>(_addressTlod + OFFSET_POINTER_ANSIO_FILTER) < 1 || ReadMemory<int>(_addressTlod + OFFSET_POINTER_ANSIO_FILTER) > 16
|| !(ReadMemory<int>(_addressTlod + OFFSET_POINTER_WATER_WAVES) == 128 || ReadMemory<int>(_addressTlod + OFFSET_POINTER_WATER_WAVES) == 256 || ReadMemory<int>(_addressTlod + OFFSET_POINTER_WATER_WAVES) == 512)) || !(ReadMemory<int>(_addressTlod + OFFSET_POINTER_WATER_WAVES) == 128 || ReadMemory<int>(_addressTlod + OFFSET_POINTER_WATER_WAVES) == 256 || ReadMemory<int>(_addressTlod + OFFSET_POINTER_WATER_WAVES) == 512))
{ {
@ -259,12 +237,12 @@ namespace MSFSPopoutPanelManager.Orchestration
return true; return true;
} }
private void SetTlod(int deltaFps, bool isVr = false) private void SetTlod(int deltaFps)
{ {
var tlodStep = Math.Max(5, Math.Abs(deltaFps / 2)); var tlodStep = Math.Max(5, Math.Abs(deltaFps / 2));
var newTlod = SimData.Tlod + Math.Sign(deltaFps) * tlodStep; var newTlod = DynamicLodSimData.Tlod + Math.Sign(deltaFps) * tlodStep;
if (DynamicLodSetting.TlodMinOnGround && SimData.AltAboveGround <= DynamicLodSetting.AltTlodBase) if (DynamicLodSetting.TlodMinOnGround && DynamicLodSimData.AltAboveGround <= DynamicLodSetting.AltTlodBase)
{ {
newTlod = DynamicLodSetting.TlodMin; newTlod = DynamicLodSetting.TlodMin;
} }
@ -277,17 +255,17 @@ namespace MSFSPopoutPanelManager.Orchestration
newTlod = DynamicLodSetting.TlodMax; newTlod = DynamicLodSetting.TlodMax;
} }
if (ReadTlod(isVr) == newTlod) if (ReadTlod() == newTlod)
return; return;
// Adjust cloud quality if applicable // Adjust cloud quality if applicable
if (DynamicLodSetting.DecreaseCloudQuality && (!DynamicLodSetting.TlodMinOnGround && !(SimData.AltAboveGround <= DynamicLodSetting.AltTlodBase))) if (DynamicLodSetting.DecreaseCloudQuality && (!DynamicLodSetting.TlodMinOnGround && !(DynamicLodSimData.AltAboveGround <= DynamicLodSetting.AltTlodBase)))
{ {
switch (deltaFps) switch (deltaFps)
{ {
case < 0 when newTlod < DynamicLodSetting.CloudRecoveryTlod && !_isDecreasedCloudQualityActive: case < 0 when newTlod < DynamicLodSetting.CloudRecoveryTlod && !_isDecreasedCloudQualityActive:
_isDecreasedCloudQualityActive = true; _isDecreasedCloudQualityActive = true;
WriteMemory(isVr ? _addressCloudQVr : _addressCloudQ, ReadCloudQualitySimValue(isVr) - 1); WriteMemory(_addressCloudQ, ReadCloudQualitySimValue() - 1);
_lastLodUpdateTime = _lastLodUpdateTime =
_lastLodUpdateTime.AddSeconds(2); // Add extra delay for cloud setting to take effect _lastLodUpdateTime.AddSeconds(2); // Add extra delay for cloud setting to take effect
@ -296,7 +274,7 @@ namespace MSFSPopoutPanelManager.Orchestration
return; return;
case > 0 when newTlod >= DynamicLodSetting.CloudRecoveryTlod && _isDecreasedCloudQualityActive: case > 0 when newTlod >= DynamicLodSetting.CloudRecoveryTlod && _isDecreasedCloudQualityActive:
_isDecreasedCloudQualityActive = false; _isDecreasedCloudQualityActive = false;
WriteMemory(isVr ? _addressCloudQVr : _addressCloudQ, ReadCloudQualitySimValue(isVr) + 1); WriteMemory(_addressCloudQ, ReadCloudQualitySimValue() + 1);
_lastLodUpdateTime = _lastLodUpdateTime.AddSeconds(2); _lastLodUpdateTime = _lastLodUpdateTime.AddSeconds(2);
Debug.WriteLine("New Cloud Quality written - 3."); Debug.WriteLine("New Cloud Quality written - 3.");
@ -306,31 +284,31 @@ namespace MSFSPopoutPanelManager.Orchestration
} }
Debug.WriteLine($"New TLOD written - {newTlod}."); Debug.WriteLine($"New TLOD written - {newTlod}.");
WriteMemory(isVr ? _addressTlodVr : _addressTlod, newTlod / 100.0f); WriteMemory(_addressTlod, newTlod / 100.0f);
} }
private void SetOlod(bool isVr = false) private void SetOlod()
{ {
int newOlod; int newOlod;
if (SimData.AltAboveGround < DynamicLodSetting.AltOlodBase) if (DynamicLodSimData.AltAboveGround < DynamicLodSetting.AltOlodBase)
{ {
newOlod = DynamicLodSetting.OlodBase; newOlod = DynamicLodSetting.OlodBase;
} }
else if (SimData.AltAboveGround > DynamicLodSetting.AltOlodTop) else if (DynamicLodSimData.AltAboveGround > DynamicLodSetting.AltOlodTop)
{ {
newOlod = DynamicLodSetting.OlodTop; newOlod = DynamicLodSetting.OlodTop;
} }
else else
{ {
newOlod = Convert.ToInt32(DynamicLodSetting.OlodBase - (DynamicLodSetting.OlodBase - DynamicLodSetting.OlodTop) * (SimData.AltAboveGround - DynamicLodSetting.AltOlodBase) / (DynamicLodSetting.AltOlodTop - DynamicLodSetting.AltOlodBase)); newOlod = Convert.ToInt32(DynamicLodSetting.OlodBase - (DynamicLodSetting.OlodBase - DynamicLodSetting.OlodTop) * (DynamicLodSimData.AltAboveGround - DynamicLodSetting.AltOlodBase) / (DynamicLodSetting.AltOlodTop - DynamicLodSetting.AltOlodBase));
} }
if (ReadOlod(isVr) == newOlod) if (ReadOlod() == newOlod)
return; return;
Debug.WriteLine($"New OLOD written - {newOlod}."); Debug.WriteLine($"New OLOD written - {newOlod}.");
WriteMemory(isVr ? _addressOlodVr : _addressOlod, newOlod / 100.0f); WriteMemory(_addressOlod, newOlod / 100.0f);
} }
} }
} }

View file

@ -15,7 +15,7 @@ namespace MSFSPopoutPanelManager.Orchestration
private System.Timers.Timer _msfsGameExitDetectionTimer; private System.Timers.Timer _msfsGameExitDetectionTimer;
private SimConnectProvider _simConnectProvider; private SimConnectProvider _simConnectProvider;
private DynamicLodOrchestrator _dynamicLodOrchestrator; private readonly DynamicLodOrchestrator _dynamicLodOrchestrator;
private bool _isTurnedOnPower; private bool _isTurnedOnPower;
private bool _isTurnedOnAvionics; private bool _isTurnedOnAvionics;
@ -77,17 +77,14 @@ namespace MSFSPopoutPanelManager.Orchestration
if (!AppSettingData.ApplicationSetting.DynamicLodSetting.IsEnabled || !FlightSimData.IsFlightStarted) if (!AppSettingData.ApplicationSetting.DynamicLodSetting.IsEnabled || !FlightSimData.IsFlightStarted)
return; return;
var isVr = _dynamicLodOrchestrator.ReadIsVr();
MapDynamicLodSimConnectData(e, isVr);
var isPaused = (AppSettingData.ApplicationSetting.DynamicLodSetting.PauseWhenMsfsLoseFocus && !WindowActionManager.IsMsfsInFocus()) || var isPaused = (AppSettingData.ApplicationSetting.DynamicLodSetting.PauseWhenMsfsLoseFocus && !WindowActionManager.IsMsfsInFocus()) ||
(AppSettingData.ApplicationSetting.DynamicLodSetting.PauseOutsideCockpitView && FlightSimData.CameraState != CameraState.Cockpit); (AppSettingData.ApplicationSetting.DynamicLodSetting.PauseOutsideCockpitView && FlightSimData.CameraState != CameraState.Cockpit);
if (isPaused) if (isPaused)
return; return;
FlightSimData.DynamicLodSimData.Fps = FpsCalc.GetAverageFps(_dynamicLodOrchestrator.ReadIsFg(isVr) ? _currentFps * 2 : _currentFps); MapDynamicLodSimConnectData(e);
_dynamicLodOrchestrator.UpdateLod(isVr); _dynamicLodOrchestrator.UpdateLod();
}; };
_simConnectProvider.OnSimConnectDataEventFrameRefreshed += (_, e) => _simConnectProvider.OnSimConnectDataEventFrameRefreshed += (_, e) =>
@ -393,6 +390,7 @@ namespace MSFSPopoutPanelManager.Orchestration
FlightSimData.IsFlightStarted = false; FlightSimData.IsFlightStarted = false;
StopDynamicLod(); StopDynamicLod();
FpsCalc.Reset();
FlightSimData.DynamicLodSimData.Clear(); FlightSimData.DynamicLodSimData.Clear();
} }
@ -492,7 +490,7 @@ namespace MSFSPopoutPanelManager.Orchestration
FlightSimData.HudBarData.SimRate = newValue; FlightSimData.HudBarData.SimRate = newValue;
} }
private void MapDynamicLodSimConnectData(List<SimDataItem> simData, bool isVr) private void MapDynamicLodSimConnectData(List<SimDataItem> simData)
{ {
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.PlaneAltAboveGround, FlightSimData.DynamicLodSimData.Agl, out var newValue)) if (CompareSimConnectData(simData, SimDataDefinitions.PropName.PlaneAltAboveGround, FlightSimData.DynamicLodSimData.Agl, out var newValue))
FlightSimData.DynamicLodSimData.Agl = newValue; FlightSimData.DynamicLodSimData.Agl = newValue;
@ -509,17 +507,19 @@ namespace MSFSPopoutPanelManager.Orchestration
if (CompareSimConnectData(simData, SimDataDefinitions.PropName.SimOnGround, 1.0f, out newValue)) if (CompareSimConnectData(simData, SimDataDefinitions.PropName.SimOnGround, 1.0f, out newValue))
FlightSimData.DynamicLodSimData.PlaneOnGround = Convert.ToBoolean(newValue); FlightSimData.DynamicLodSimData.PlaneOnGround = Convert.ToBoolean(newValue);
var tlod = _dynamicLodOrchestrator.ReadTlod(isVr); var tlod = _dynamicLodOrchestrator.ReadTlod();
if (FlightSimData.DynamicLodSimData.Tlod != tlod) if (FlightSimData.DynamicLodSimData.Tlod != tlod)
FlightSimData.DynamicLodSimData.Tlod = tlod; FlightSimData.DynamicLodSimData.Tlod = tlod;
var olod = _dynamicLodOrchestrator.ReadOlod(isVr); var olod = _dynamicLodOrchestrator.ReadOlod();
if (FlightSimData.DynamicLodSimData.Olod != olod) if (FlightSimData.DynamicLodSimData.Olod != olod)
FlightSimData.DynamicLodSimData.Olod = olod; FlightSimData.DynamicLodSimData.Olod = olod;
var cloudQuality = _dynamicLodOrchestrator.ReadCloudQuality(isVr); var cloudQuality = _dynamicLodOrchestrator.ReadCloudQuality();
if (FlightSimData.DynamicLodSimData.CloudQuality != cloudQuality) if (FlightSimData.DynamicLodSimData.CloudQuality != cloudQuality)
FlightSimData.DynamicLodSimData.CloudQuality = cloudQuality; FlightSimData.DynamicLodSimData.CloudQuality = cloudQuality;
FlightSimData.DynamicLodSimData.Fps = FpsCalc.GetAverageFps(_dynamicLodOrchestrator.ReadIsFg() ? _currentFps * 2 : _currentFps);
} }
private int _currentFps; private int _currentFps;

View file

@ -419,6 +419,9 @@ namespace MSFSPopoutPanelManager.Orchestration
WindowActionManager.SetWindowTitleBarColor(panelConfig.PanelHandle, AppSettingData.ApplicationSetting.PopOutSetting.PopOutTitleBarCustomization.HexColor); WindowActionManager.SetWindowTitleBarColor(panelConfig.PanelHandle, AppSettingData.ApplicationSetting.PopOutSetting.PopOutTitleBarCustomization.HexColor);
} }
} }
if(ActiveProfile.PanelConfigs.Any(p => p.AlwaysOnTop))
WindowActionManager.ApplyAlwaysOnTop(WindowProcessManager.SimulatorProcess.Handle, PanelType.FlightSimMainWindow, true);
} }
private async Task StepPostPopout() private async Task StepPostPopout()

View file

@ -5,32 +5,46 @@ namespace MSFSPopoutPanelManager.SimConnectAgent
{ {
public class FpsCalc public class FpsCalc
{ {
private const int FpsLen = 25; private const int FPS_LEN = 20;
private static readonly float[] FpsStatistic = new float[FpsLen]; private static readonly float[] FpsStatistic = new float[FPS_LEN];
private static int _fpsIndex = -1; private static int _fpsIndex = -1;
private static int _avgFps;
public static int GetAverageFps(int newValue) public static int GetAverageFps(int newValue)
{ {
if (_fpsIndex == -1) if (_fpsIndex == -1)
{ {
for (var i = 0; i < FpsLen; i++) // initialize FpsStatistic array
for (var i = 0; i < FPS_LEN; i++)
FpsStatistic[i] = newValue; FpsStatistic[i] = newValue;
_avgFps = Convert.ToInt32(newValue);
_fpsIndex = 1; _fpsIndex = 1;
} }
else else
{ {
var deltaFps = newValue - _avgFps;
if (deltaFps < 0 && Math.Abs(deltaFps) > _avgFps * 0.1) // FPS suddenly drops more than 10%
{
newValue += Math.Abs(deltaFps) / 2; // Let the new FPS to be only half the delta drop
}
FpsStatistic[_fpsIndex] = newValue; FpsStatistic[_fpsIndex] = newValue;
_fpsIndex++; _fpsIndex++;
if (_fpsIndex >= FpsLen) if (_fpsIndex >= FPS_LEN)
_fpsIndex = 0; _fpsIndex = 0;
_avgFps = Convert.ToInt32(FpsStatistic.Sum() / FPS_LEN);
} }
var fps = 0; return _avgFps;
if (_fpsIndex != -1) }
fps = Convert.ToInt32(FpsStatistic.Sum() / FpsLen);
return fps; public static void Reset()
{
_fpsIndex = -1;
_avgFps = 0;
} }
} }
} }