File tree Expand file tree Collapse file tree 3 files changed +47
-7
lines changed Expand file tree Collapse file tree 3 files changed +47
-7
lines changed Original file line number Diff line number Diff line change 14
14
using ModuleManager . Extensions ;
15
15
using ModuleManager . Logging ;
16
16
using ModuleManager . UnityLogHandle ;
17
+ using ModuleManager . Utils ;
17
18
18
19
namespace ModuleManager
19
20
{
@@ -68,8 +69,6 @@ internal void OnRnDCenterDeSpawn()
68
69
inRnDCenter = false ;
69
70
}
70
71
71
- private readonly Stopwatch totalTime = new Stopwatch ( ) ;
72
-
73
72
internal void Awake ( )
74
73
{
75
74
if ( LoadingScreen . Instance == null )
@@ -87,8 +86,8 @@ internal void Awake()
87
86
return ;
88
87
}
89
88
90
- totalTime . Start ( ) ;
91
-
89
+ PerformanceMetrics . Instance . Start ( ) ;
90
+
92
91
interceptLogHandler = new InterceptLogHandler ( ) ;
93
92
94
93
// Allow loading the background in the loading screen
@@ -235,10 +234,10 @@ internal void Update()
235
234
this . menu = this . menu . Dismiss ( ) ;
236
235
}
237
236
238
- if ( totalTime . IsRunning && HighLogic . LoadedScene == GameScenes . MAINMENU )
237
+ if ( PerformanceMetrics . Instance . IsRunning && HighLogic . LoadedScene == GameScenes . MAINMENU )
239
238
{
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" ) ;
242
241
243
242
Application . runInBackground = GameSettings . SIMULATE_IN_BACKGROUND ;
244
243
QualitySettings . vSyncCount = GameSettings . SYNC_VBL ;
Original file line number Diff line number Diff line change 134
134
<Compile Include =" GUI\ReloadingDatabase.cs" />
135
135
<Compile Include =" GUI\Menu.12.cs" />
136
136
<Compile Include =" GUI\ReloadingDatabase.12.cs" />
137
+ <Compile Include =" Utils\PerformanceMetrics.cs" />
137
138
</ItemGroup >
138
139
<ItemGroup >
139
140
<Reference Include =" System" />
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments