Skip to content

Commit 3a86d3c

Browse files
committed
Timer resume catch-up moved out of the core Time loop.
1 parent 174bfa9 commit 3a86d3c

2 files changed

Lines changed: 3 additions & 71 deletions

File tree

src/time/Time.js

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -218,25 +218,12 @@ Phaser.Time.prototype = {
218218

219219
this.now = time;
220220

221-
if (this._justResumed)
222-
{
223-
this.time = this.now;
224-
this._justResumed = false;
225-
226-
this.events.resume();
227-
228-
for (var i = 0; i < this._timers.length; i++)
229-
{
230-
this._timers[i]._resume();
231-
}
232-
}
233-
234221
this.timeToCall = this.game.math.max(0, 16 - (time - this.lastTime));
235222

236223
this.elapsed = this.now - this.time;
237224

238-
//calculate physics elapsed, ensure it's > 0, use 1/60 as a fallback
239-
this.physicsElapsed = this.elapsed / 1000 || 1/60;
225+
// Calculate physics elapsed, ensure it's > 0, use 1/60 as a fallback
226+
this.physicsElapsed = this.elapsed / 1000 || 1 / 60;
240227

241228
if (this.deltaCap > 0 && this.physicsElapsed > this.deltaCap)
242229
{
@@ -324,18 +311,15 @@ Phaser.Time.prototype = {
324311

325312
this.pauseDuration = this.time - this._pauseStarted;
326313

327-
this._justResumed = true;
328-
329314
this.events.resume();
330315

331316
var i = this._timers.length;
332317

333318
while (i--)
334319
{
335-
// this._timers[i]._resume();
320+
this._timers[i]._resume();
336321
}
337322

338-
339323
},
340324

341325
/**

src/time/Timer.js

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,6 @@ Phaser.Timer.prototype = {
382382
return true;
383383
}
384384

385-
if (time < this._now)
386-
{
387-
console.log('time travel?', time, this._now = time);
388-
}
389385
this._now = time;
390386
this._marked = 0;
391387

@@ -461,18 +457,13 @@ Phaser.Timer.prototype = {
461457
*/
462458
pause: function () {
463459

464-
console.log('Timer.pause called');
465-
466460
if (this.paused)
467461
{
468-
console.log('Already paused, aborting');
469462
return;
470463
}
471464

472465
this._pauseStarted = this.game.time.now;
473466

474-
console.log('paused duration', this.duration);
475-
476467
this.paused = true;
477468
this._codePaused = true;
478469

@@ -485,11 +476,8 @@ Phaser.Timer.prototype = {
485476
*/
486477
_pause: function () {
487478

488-
console.log('Timer._pause called');
489-
490479
if (this.paused)
491480
{
492-
console.log('Already paused, aborting');
493481
return;
494482
}
495483

@@ -506,23 +494,14 @@ Phaser.Timer.prototype = {
506494
*/
507495
resume: function () {
508496

509-
console.log('Timer.resume called');
510-
511497
if (!this.paused)
512498
{
513-
console.log('No longer paused, aborting');
514499
return;
515500
}
516501

517-
// var durationBeforePause = this.duration;
518-
519-
// console.log('old duration', durationBeforePause);
520-
521502
this._pauseTotal += this.game.time.pauseDuration;
522503
this._now = this.game.time.time;
523504

524-
console.log('paused for', this.game.time.pauseDuration);
525-
526505
for (var i = 0; i < this.events.length; i++)
527506
{
528507
if (!this.events[i].pendingDelete)
@@ -537,13 +516,9 @@ Phaser.Timer.prototype = {
537516

538517
// Add the difference on to the time now
539518
this.events[i].tick = this._now + t;
540-
541-
console.log('event increased by', t);
542519
}
543520
}
544521

545-
// this.nextTick = this._now + durationBeforePause;
546-
547522
var d = this.nextTick - this._pauseStarted;
548523

549524
if (d < 0)
@@ -555,29 +530,6 @@ Phaser.Timer.prototype = {
555530
this.nextTick = this._now + d;
556531
}
557532

558-
console.log('nextTick +', d);
559-
560-
561-
// if (this.nextTick > this._now)
562-
// {
563-
// // event was going to tick in the future, but we need to add the time it was paused to it
564-
// d = this.nextTick - this._now;
565-
// t = this.game.time.pauseDuration;
566-
// this.nextTick += t;
567-
// console.log('next tick was going to tick in the future', t);
568-
// }
569-
// else
570-
// {
571-
// // event tick time has elapsed due to pause
572-
// d = this._now - this.nextTick; //
573-
// // t = this.game.time.pauseDuration - d;
574-
// t = this.game.time.pauseDuration;
575-
// this.nextTick += t;
576-
// console.log('next tick has elapsed behind game time by', t);
577-
// }
578-
579-
console.log('new duration', this.duration);
580-
581533
this.paused = false;
582534
this._codePaused = false;
583535

@@ -590,16 +542,12 @@ Phaser.Timer.prototype = {
590542
*/
591543
_resume: function () {
592544

593-
console.log('Timer._resume called');
594-
595545
if (this._codePaused)
596546
{
597-
console.log('code paused');
598547
return;
599548
}
600549
else
601550
{
602-
console.log('normal resume');
603551
this.resume();
604552
}
605553

0 commit comments

Comments
 (0)