66using System . Diagnostics ;
77using System . Linq ;
88using osu . Framework . Configuration ;
9+ using osu . Framework . Development ;
910using osu . Framework . Graphics . Rendering . Dummy ;
1011using osu . Framework . Input . Handlers ;
1112using osu . Framework . Logging ;
@@ -79,7 +80,8 @@ protected override void SetupForRun()
7980
8081 if ( ! realtime )
8182 {
82- customClock = new FramedClock ( new FastClock ( CLOCK_RATE , Threads . ToArray ( ) ) ) ;
83+ DebugUtils . RealtimeClock = new FastClock ( CLOCK_RATE , Threads . ToArray ( ) ) ;
84+ customClock = new FramedClock ( DebugUtils . RealtimeClock ) ;
8385
8486 // time is incremented per frame, rather than based on the real-world time.
8587 // therefore our goal is to run frames as fast as possible.
@@ -106,6 +108,12 @@ protected override void UpdateFrame()
106108
107109 protected override IEnumerable < InputHandler > CreateAvailableInputHandlers ( ) => Array . Empty < InputHandler > ( ) ;
108110
111+ protected override void Dispose ( bool isDisposing )
112+ {
113+ base . Dispose ( isDisposing ) ;
114+ DebugUtils . RealtimeClock = null ;
115+ }
116+
109117 private class FastClock : IClock
110118 {
111119 private readonly double increment ;
@@ -134,20 +142,23 @@ public double CurrentTime
134142 {
135143 get
136144 {
137- double realElapsedTime = stopwatch . Elapsed . TotalMilliseconds ;
138- stopwatch . Restart ( ) ;
139-
140- if ( allThreadsHaveProgressed )
145+ lock ( stopwatch )
141146 {
142- for ( int i = 0 ; i < gameThreads . Length ; i ++ )
143- gameThreadLastFrames [ i ] = gameThreads [ i ] . FrameIndex ;
147+ double realElapsedTime = stopwatch . Elapsed . TotalMilliseconds ;
148+ stopwatch . Restart ( ) ;
144149
145- // Increment time at the expedited rate.
146- return time += increment ;
147- }
150+ if ( allThreadsHaveProgressed )
151+ {
152+ for ( int i = 0 ; i < gameThreads . Length ; i ++ )
153+ gameThreadLastFrames [ i ] = gameThreads [ i ] . FrameIndex ;
154+
155+ // Increment time at the expedited rate.
156+ return time += increment ;
157+ }
148158
149- // Fall back to real time to ensure we don't break random tests that expect threads to be running.
150- return time += realElapsedTime ;
159+ // Fall back to real time to ensure we don't break random tests that expect threads to be running.
160+ return time += realElapsedTime ;
161+ }
151162 }
152163 }
153164
0 commit comments