Skip to content

Commit 79fce42

Browse files
committed
Trying to squeeze the last second of possible time form the loarding by pumping up Unity FPS to the maximum possible - restoring the user settings after.
1 parent 75240ec commit 79fce42

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

Source/ModuleManager/ModuleManager.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using ModuleManager.Extensions;
1515
using ModuleManager.Logging;
1616
using ModuleManager.UnityLogHandle;
17+
using ModuleManager.Utils;
1718

1819
namespace ModuleManager
1920
{
@@ -68,8 +69,6 @@ internal void OnRnDCenterDeSpawn()
6869
inRnDCenter = false;
6970
}
7071

71-
private readonly Stopwatch totalTime = new Stopwatch();
72-
7372
internal void Awake()
7473
{
7574
if (LoadingScreen.Instance == null)
@@ -87,8 +86,8 @@ internal void Awake()
8786
return;
8887
}
8988

90-
totalTime.Start();
91-
89+
PerformanceMetrics.Instance.Start();
90+
9291
interceptLogHandler = new InterceptLogHandler();
9392

9493
// Allow loading the background in the loading screen
@@ -235,10 +234,10 @@ internal void Update()
235234
this.menu = this.menu.Dismiss();
236235
}
237236

238-
if (totalTime.IsRunning && HighLogic.LoadedScene == GameScenes.MAINMENU)
237+
if (PerformanceMetrics.Instance.IsRunning && HighLogic.LoadedScene == GameScenes.MAINMENU)
239238
{
240-
totalTime.Stop();
241-
Log("Total loading Time = " + ((float)totalTime.ElapsedMilliseconds / 1000).ToString("F3") + "s");
239+
PerformanceMetrics.Instance.Stop();
240+
Log("Total loading Time = " + PerformanceMetrics.Instance.ElapsedTimeInSecs.ToString("F3") + "s");
242241

243242
Application.runInBackground = GameSettings.SIMULATE_IN_BACKGROUND;
244243
QualitySettings.vSyncCount = GameSettings.SYNC_VBL;

Source/ModuleManager/ModuleManager.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
<Compile Include="GUI\ReloadingDatabase.cs" />
135135
<Compile Include="GUI\Menu.12.cs" />
136136
<Compile Include="GUI\ReloadingDatabase.12.cs" />
137+
<Compile Include="Utils\PerformanceMetrics.cs" />
137138
</ItemGroup>
138139
<ItemGroup>
139140
<Reference Include="System" />
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Diagnostics;
3+
using UnityEngine;
4+
5+
namespace ModuleManager.Utils
6+
{
7+
internal class PerformanceMetrics
8+
{
9+
private static PerformanceMetrics INSTANCE;
10+
internal static PerformanceMetrics Instance => INSTANCE ?? (INSTANCE = new PerformanceMetrics());
11+
12+
private readonly Stopwatch totalTime = new Stopwatch();
13+
private readonly int vSyncCount;
14+
private readonly int targetFrameRate;
15+
16+
internal bool IsRunning => this.totalTime.IsRunning;
17+
internal float ElapsedTimeInSecs => ((float)this.totalTime.ElapsedMilliseconds / 1000);
18+
19+
private PerformanceMetrics()
20+
{
21+
this.vSyncCount = QualitySettings.vSyncCount;
22+
this.targetFrameRate = Application.targetFrameRate;
23+
}
24+
25+
internal void Start()
26+
{
27+
Application.targetFrameRate = 99999; // What the heck, why not? :D
28+
QualitySettings.vSyncCount = 0;
29+
this.totalTime.Start();
30+
}
31+
32+
internal void Stop()
33+
{
34+
this.totalTime.Stop();
35+
Application.targetFrameRate = this.targetFrameRate;
36+
QualitySettings.vSyncCount = this.vSyncCount;
37+
}
38+
39+
}
40+
}

0 commit comments

Comments
 (0)