44* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License }
55*/
66
7- // My thanks to Isaac Sukin for some of the concepts used in this class
7+ // My thanks to Isaac Sukin for creating MainLoop.js, on which lots of this is based.
88
99Phaser . State . MainLoop = function ( state , framerate )
1010{
11- console . log ( 'MainLoop FPS' , framerate ) ;
12-
1311 /**
1412 * @property {Phaser.State } state
1513 */
@@ -20,20 +18,6 @@ Phaser.State.MainLoop = function (state, framerate)
2018 */
2119 this . game = state . game ;
2220
23- this . getTime = Date . now ;
24-
25- if ( window . performance )
26- {
27- if ( window . performance . now )
28- {
29- this . getTime = function ( ) { return window . performance . now ( ) ; } ;
30- }
31- else if ( window . performance . webkitNow )
32- {
33- this . getTime = function ( ) { return window . performance . webkitNow ( ) ; } ;
34- }
35- }
36-
3721 // The amount of time (in milliseconds) to simulate each time update() runs.
3822 this . timestep = 1000 / framerate ;
3923
@@ -93,9 +77,6 @@ Phaser.State.MainLoop = function (state, framerate)
9377 // A function that runs at the end of the main loop.
9478 // See `MainLoop.setEnd()` for details.
9579 this . end = Phaser . NOOP ;
96-
97- window . bob = 0 ;
98-
9980} ;
10081
10182Phaser . State . MainLoop . prototype . constructor = Phaser . State . MainLoop ;
@@ -138,34 +119,18 @@ Phaser.State.MainLoop.prototype = {
138119 this . started = true ;
139120 this . running = true ;
140121
141- this . lastFrameTimeMs = this . getTime ( ) ;
142- this . lastFpsUpdate = this . getTime ( ) ;
122+ this . lastFrameTimeMs = window . performance . now ( ) ;
123+ this . lastFpsUpdate = window . performance . now ( ) ;
143124 this . framesThisSecond = 0 ;
144-
145- console . log ( 'MainLoop.start' , this . lastFrameTimeMs ) ;
146-
147125 } ,
148126
149127 // timestamp = DOMHighResTimeStamp
150128 step : function ( timestamp )
151129 {
152- window . bob ++ ;
153-
154- if ( window . bob > 200 && window . bob < 300 )
155- {
156- console . log ( '%c MainLoop.step : ' + ( window . bob - 200 ) + ' ' , 'color: #000000; background: #00ff00;' ) ;
157- console . log ( 'timestamp' , timestamp ) ;
158- console . log ( 'lastFrameTimeMs' , this . lastFrameTimeMs ) ;
159- }
160-
161130 // Throttle the frame rate (if minFrameDelay is set to a non-zero value by
162131 // `MainLoop.setMaxAllowedFPS()`).
163132 if ( timestamp < this . lastFrameTimeMs + this . minFrameDelay )
164133 {
165- if ( window . bob > 200 && window . bob < 300 )
166- {
167- console . log ( 'exit' ) ;
168- }
169134 return ;
170135 }
171136
@@ -177,12 +142,6 @@ Phaser.State.MainLoop.prototype = {
177142 this . frameDelta += timestamp - this . lastFrameTimeMs ;
178143 this . lastFrameTimeMs = timestamp ;
179144
180- if ( window . bob > 200 && window . bob < 300 )
181- {
182- console . log ( 'frameDelta' , this . frameDelta ) ;
183- console . log ( 'lastFrameTimeMs' , this . lastFrameTimeMs ) ;
184- }
185-
186145 // Run any updates that are not dependent on time in the simulation.
187146
188147 // Here we'll need to run things like tween.update, input.update, etc.
@@ -195,25 +154,12 @@ Phaser.State.MainLoop.prototype = {
195154 // older seconds.
196155 if ( timestamp > this . lastFpsUpdate + 1000 )
197156 {
198- if ( window . bob > 200 && window . bob < 300 )
199- {
200- console . log ( 'compute new exponential' ) ;
201- console . log ( 'timestamp' , timestamp , '>' , ( this . lastFpsUpdate + 1000 ) , ( timestamp > this . lastFpsUpdate + 1000 ) ) ;
202- }
203-
204157 // Compute the new exponential moving average with an alpha of 0.25.
205158 // Using constants inline is okay here.
206159 this . fps = 0.25 * this . framesThisSecond + 0.75 * this . fps ;
207160
208161 this . lastFpsUpdate = timestamp ;
209162 this . framesThisSecond = 0 ;
210-
211- if ( window . bob > 200 && window . bob < 300 )
212- {
213- console . log ( 'lastFpsUpdate' , this . lastFpsUpdate ) ;
214- console . log ( 'framesThisSecond' , this . framesThisSecond ) ;
215- console . log ( 'fps' , this . fps ) ;
216- }
217163 }
218164
219165 this . framesThisSecond ++ ;
@@ -226,12 +172,6 @@ Phaser.State.MainLoop.prototype = {
226172
227173 this . frameDelta -= this . timestep ;
228174
229- if ( window . bob > 200 && window . bob < 300 )
230- {
231- console . log ( '%c update ' , 'color: #ffffff; background: #ffff00;' ) ;
232- console . log ( 'update' , this . frameDelta ) ;
233- }
234-
235175 if ( ++ this . numUpdateSteps >= 240 )
236176 {
237177 this . panic = true ;
@@ -243,11 +183,6 @@ Phaser.State.MainLoop.prototype = {
243183
244184 if ( this . state . settings . visible && this . state . sys . color . alpha !== 0 && this . state . sys . children . list . length > 0 )
245185 {
246- if ( window . bob > 200 && window . bob < 300 )
247- {
248- console . log ( '%c render ' + ( this . frameDelta / this . timestep ) + '% ' , 'color: #ffffff; background: #0f0f0f;' ) ;
249- }
250-
251186 this . game . renderer . render ( this . state , this . frameDelta / this . timestep ) ;
252187 }
253188
@@ -257,11 +192,6 @@ Phaser.State.MainLoop.prototype = {
257192 this . end ( this . fps , this . panic ) ;
258193
259194 this . panic = false ;
260-
261- if ( window . bob > 200 && window . bob < 300 )
262- {
263- console . log ( '%c MainLoop.step ' , 'color: #ffffff; background: #ff0000;' ) ;
264- }
265195 } ,
266196
267197 update : function ( timestep )
0 commit comments