Skip to content

Commit 961997a

Browse files
committed
Debugging the loop.
1 parent 48f90fe commit 961997a

1 file changed

Lines changed: 49 additions & 1 deletion

File tree

src/states/MainLoop.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ Phaser.State.MainLoop = function (state, framerate)
9191
// A function that runs at the end of the main loop.
9292
// See `MainLoop.setEnd()` for details.
9393
this.end = Phaser.NOOP;
94+
95+
this.bob = 0;
96+
9497
};
9598

9699
Phaser.State.MainLoop.prototype.constructor = Phaser.State.MainLoop;
@@ -136,15 +139,31 @@ Phaser.State.MainLoop.prototype = {
136139
this.lastFrameTimeMs = this.getTime();
137140
this.lastFpsUpdate = this.getTime();
138141
this.framesThisSecond = 0;
142+
143+
console.log('MainLoop.start', this.lastFrameTimeMs);
144+
139145
},
140146

141147
// timestamp = DOMHighResTimeStamp
142148
step: function (timestamp)
143149
{
150+
this.bob++;
151+
152+
if (this.bob > 500 && this.bob < 550)
153+
{
154+
console.log('%c MainLoop.step : ' + (this.bob - 500) + ' ', 'color: #000000; background: #00ff00;');
155+
console.log('timestamp', timestamp);
156+
console.log('lastFrameTimeMs', this.lastFrameTimeMs);
157+
}
158+
144159
// Throttle the frame rate (if minFrameDelay is set to a non-zero value by
145160
// `MainLoop.setMaxAllowedFPS()`).
146161
if (timestamp < this.lastFrameTimeMs + this.minFrameDelay)
147162
{
163+
if (this.bob > 500 && this.bob < 550)
164+
{
165+
console.log('exit');
166+
}
148167
return;
149168
}
150169

@@ -156,6 +175,14 @@ Phaser.State.MainLoop.prototype = {
156175
this.frameDelta += timestamp - this.lastFrameTimeMs;
157176
this.lastFrameTimeMs = timestamp;
158177

178+
if (this.bob > 500 && this.bob < 550)
179+
{
180+
console.log('frameDelta', this.frameDelta);
181+
console.log('lastFrameTimeMs', this.lastFrameTimeMs);
182+
console.log('lastFpsUpdate', this.lastFpsUpdate);
183+
console.log('ts', timestamp, '>', (this.lastFpsUpdate + 1000), (timestamp > this.lastFpsUpdate + 1000));
184+
}
185+
159186
// Run any updates that are not dependent on time in the simulation.
160187

161188
// Here we'll need to run things like tween.update, input.update, etc.
@@ -168,12 +195,22 @@ Phaser.State.MainLoop.prototype = {
168195
// older seconds.
169196
if (timestamp > this.lastFpsUpdate + 1000)
170197
{
198+
if (this.bob > 500 && this.bob < 550)
199+
{
200+
console.log('compute new exponential');
201+
}
202+
171203
// Compute the new exponential moving average with an alpha of 0.25.
172204
// Using constants inline is okay here.
173-
this.fps = 0.25 * this.framesThisSecond + 0.75 * this.fps;
205+
this.fps = (0.25 * this.framesThisSecond) + (0.75 * this.fps);
174206

175207
this.lastFpsUpdate = timestamp;
176208
this.framesThisSecond = 0;
209+
210+
if (this.bob > 500 && this.bob < 550)
211+
{
212+
console.log('fps', this.fps);
213+
}
177214
}
178215

179216
this.framesThisSecond++;
@@ -186,6 +223,12 @@ Phaser.State.MainLoop.prototype = {
186223

187224
this.frameDelta -= this.timestep;
188225

226+
if (this.bob > 500 && this.bob < 550)
227+
{
228+
console.log('%c update ', 'color: #ffffff; background: #ffff00;');
229+
console.log('update', this.frameDelta);
230+
}
231+
189232
if (++this.numUpdateSteps >= 240)
190233
{
191234
this.panic = true;
@@ -206,6 +249,11 @@ Phaser.State.MainLoop.prototype = {
206249
this.end(this.fps, this.panic);
207250

208251
this.panic = false;
252+
253+
if (this.bob > 500 && this.bob < 550)
254+
{
255+
console.log('%c MainLoop.step ', 'color: #ffffff; background: #ff0000;');
256+
}
209257
},
210258

211259
update: function (timestep)

0 commit comments

Comments
 (0)