Skip to content

Commit

Permalink
Fixed an issue where the Tile.physicsElapsed would go insane if the g…
Browse files Browse the repository at this point in the history
…ame has been paused for a long time.
  • Loading branch information
photonstorm committed Sep 12, 2013
1 parent 92e8649 commit 336de31
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 43 deletions.
6 changes: 3 additions & 3 deletions src/core/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ Phaser.Group.prototype = {

forEach: function (callback, callbackContext, checkExists) {

checkExists = checkExists || false;
if (typeof checkExists == 'undefined') { checkExists = false; }

if (this._container.first._iNext)
{
Expand All @@ -470,7 +470,7 @@ Phaser.Group.prototype = {

},

forEachAlive: function () {
forEachAlive: function (callback, callbackContext) {

if (this._container.first._iNext)
{
Expand All @@ -491,7 +491,7 @@ Phaser.Group.prototype = {

},

forEachDead: function () {
forEachDead: function (callback, callbackContext) {

if (this._container.first._iNext)
{
Expand Down
26 changes: 12 additions & 14 deletions src/tilemap/Tilemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ Phaser.Tilemap.prototype.setCollisionRange = function (start, end, left, right,

for (var i = start; i < end; i++)
{
//setCollision: function (left, right, up, down, reset, separateX, separateY) {
this.tiles[i].setCollision(left, right, up, down, resetCollisions, separateX, separateY);
}

Expand All @@ -231,16 +230,15 @@ Phaser.Tilemap.prototype.setCollisionRange = function (start, end, left, right,
* @param separateX {bool} Enable seprate at x-axis.
* @param separateY {bool} Enable seprate at y-axis.
*/
Phaser.Tilemap.prototype.setCollisionByIndex = function (values, collision, resetCollisions, separateX, separateY) {
Phaser.Tilemap.prototype.setCollisionByIndex = function (values, left, right, up, down, resetCollisions, separateX, separateY) {

if (typeof collision === "undefined") { collision = Phaser.Types.ANY; }
if (typeof resetCollisions === "undefined") { resetCollisions = false; }
if (typeof separateX === "undefined") { separateX = true; }
if (typeof separateY === "undefined") { separateY = true; }

for (var i = 0; i < values.length; i++)
{
this.tiles[values[i]].setCollision(collision, resetCollisions, separateX, separateY);
this.tiles[values[i]].setCollision(left, right, up, down, resetCollisions, separateX, separateY);
}

};
Expand Down Expand Up @@ -328,25 +326,20 @@ Phaser.Tilemap.prototype.getTileOverlaps = function (object) {
*/
Phaser.Tilemap.prototype.collide = function (objectOrGroup, callback, context) {

if (typeof objectOrGroup === "undefined") { objectOrGroup = null; }
if (typeof callback === "undefined") { callback = null; }
if (typeof context === "undefined") { context = null; }
objectOrGroup = objectOrGroup || this.game.world.group;
callback = callback || null;
context = context || null;

if (callback !== null && context !== null)
if (callback && context)
{
this.collisionCallback = callback;
this.collisionCallbackContext = context;
}

if (objectOrGroup == null)
{
objectOrGroup = this.game.world.group;
}

// Group?
if (objectOrGroup instanceof Phaser.Group)
{
// objectOrGroup.forEachAlive(this, this.collideGameObject, true);
objectOrGroup.forEachAlive(this.collideGameObject, this);
}
else
{
Expand All @@ -362,6 +355,11 @@ Phaser.Tilemap.prototype.collide = function (objectOrGroup, callback, context) {
*/
Phaser.Tilemap.prototype.collideGameObject = function (object) {

if (object instanceof Phaser.Group || object instanceof Phaser.Tilemap)
{
return false;
}

if (object.exists && object.body.allowCollision.none == false)
{
this._tempCollisionData = this.collisionLayer.getTileOverlaps(object);
Expand Down
41 changes: 15 additions & 26 deletions src/time/Time.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,27 @@ Phaser.Time.prototype = {
update: function (time) {

this.now = time;
this.timeToCall = Math.max(0, 16 - (time - this.lastTime));

if (this._justResumed)
{
this.time = this.now;
this._justResumed = false;
}

this.timeToCall = this.game.math.max(0, 16 - (time - this.lastTime));

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

this.msMin = Math.min(this.msMin, this.elapsed);
this.msMax = Math.max(this.msMax, this.elapsed);
this.msMin = this.game.math.min(this.msMin, this.elapsed);
this.msMax = this.game.math.max(this.msMax, this.elapsed);

this.frames++;

if (this.now > this._timeLastSecond + 1000)
{
this.fps = Math.round((this.frames * 1000) / (this.now - this._timeLastSecond));
this.fpsMin = Math.min(this.fpsMin, this.fps);
this.fpsMax = Math.max(this.fpsMax, this.fps);
this.fpsMin = this.game.math.min(this.fpsMin, this.fps);
this.fpsMax = this.game.math.max(this.fpsMax, this.fps);
this._timeLastSecond = this.now;
this.frames = 0;
}
Expand All @@ -214,18 +221,6 @@ Phaser.Time.prototype = {
this.pausedTime = this.now - this._pauseStarted;
}

if (this._justResumed)
{
console.log('Time just resumed');
console.log('now', this.now);
console.log('timeToCall', this.timeToCall);
console.log('elapsed', this.elapsed);
console.log('lastTime', this.lastTime);
console.log('physicsElapsed', this.physicsElapsed);

this._justResumed = false;
}

},

/**
Expand All @@ -234,13 +229,9 @@ Phaser.Time.prototype = {
* @private
*/
gamePaused: function () {

this._pauseStarted = this.now;
console.log('Time paused');
console.log('now', this.now);
console.log('timeToCall', this.timeToCall);
console.log('elapsed', this.elapsed);
console.log('lastTime', this.lastTime);
console.log('physicsElapsed', this.physicsElapsed);

},

/**
Expand All @@ -251,10 +242,8 @@ Phaser.Time.prototype = {
gameResumed: function () {

// Level out the elapsed timer to avoid spikes
this.elapsed = 0;
this.physicsElapsed = 0;
this.time = Date.now();
this.pauseDuration = this.pausedTime;

this._justResumed = true;

},
Expand Down

0 comments on commit 336de31

Please sign in to comment.