mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 13:43:26 +00:00
Merge branch 'master' of https://github.com/photonstorm/phaser
This commit is contained in:
commit
35ecba702b
5 changed files with 112 additions and 7 deletions
|
@ -558,7 +558,7 @@ var Body = new Class({
|
|||
var y = pos.y + this.halfHeight;
|
||||
|
||||
graphic.lineStyle(1, this.world.defaults.velocityDebugColor, 1);
|
||||
graphic.lineBetween(x, y, x + this.velocity.x, y + this.velocity.y);
|
||||
graphic.lineBetween(x, y, x + this.velocity.x / 2, y + this.velocity.y / 2);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -38,6 +38,8 @@ var Collider = new Class({
|
|||
{
|
||||
this.world.removeCollider(this);
|
||||
|
||||
this.active = false;
|
||||
|
||||
this.world = null;
|
||||
|
||||
this.object1 = null;
|
||||
|
|
|
@ -8,6 +8,7 @@ var GetValue = require('../../utils/object/GetValue');
|
|||
var Rectangle = require('../../geom/rectangle/Rectangle');
|
||||
var RTree = require('../../structs/RTree');
|
||||
var Set = require('../../structs/Set');
|
||||
var ProcessQueue = require('../../structs/ProcessQueue');
|
||||
var StaticBody = require('./StaticBody');
|
||||
var Vector2 = require('../../math/Vector2');
|
||||
|
||||
|
@ -27,7 +28,7 @@ var World = new Class({
|
|||
// Static Bodies
|
||||
this.staticBodies = new Set();
|
||||
|
||||
this.colliders = [];
|
||||
this.colliders = new ProcessQueue();
|
||||
|
||||
this.gravity = new Vector2(GetValue(config, 'gravity.x', 0), GetValue(config, 'gravity.y', 0));
|
||||
|
||||
|
@ -231,7 +232,7 @@ var World = new Class({
|
|||
|
||||
var collider = new Collider(this, false, object1, object2, collideCallback, processCallback, callbackContext);
|
||||
|
||||
this.colliders.push(collider);
|
||||
this.colliders.add(collider);
|
||||
|
||||
return collider;
|
||||
},
|
||||
|
@ -244,14 +245,14 @@ var World = new Class({
|
|||
|
||||
var collider = new Collider(this, true, object1, object2, collideCallback, processCallback, callbackContext);
|
||||
|
||||
this.colliders.push(collider);
|
||||
this.colliders.add(collider);
|
||||
|
||||
return collider;
|
||||
},
|
||||
|
||||
removeCollider: function (collider)
|
||||
{
|
||||
// TODO
|
||||
this.colliders.remove(collider);
|
||||
},
|
||||
|
||||
update: function (time, delta)
|
||||
|
@ -288,10 +289,11 @@ var World = new Class({
|
|||
this.tree.load(bodies);
|
||||
|
||||
// Process any colliders
|
||||
var colliders = this.colliders.update();
|
||||
|
||||
for (i = 0; i < this.colliders.length; i++)
|
||||
for (i = 0; i < colliders.length; i++)
|
||||
{
|
||||
var collider = this.colliders[i];
|
||||
var collider = colliders[i];
|
||||
|
||||
if (collider.active)
|
||||
{
|
||||
|
|
99
v3/src/structs/ProcessQueue.js
Normal file
99
v3/src/structs/ProcessQueue.js
Normal file
|
@ -0,0 +1,99 @@
|
|||
// Phaser.Structs.ProcessQueue
|
||||
|
||||
var Class = require('../utils/Class');
|
||||
|
||||
var ProcessQueue = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
function ProcessQueue ()
|
||||
{
|
||||
this._pending = [];
|
||||
this._active = [];
|
||||
this._destroy = [];
|
||||
|
||||
this._toProcess = 0;
|
||||
},
|
||||
|
||||
add: function (item)
|
||||
{
|
||||
this._pending.push(item);
|
||||
|
||||
this._toProcess++;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
remove: function (item)
|
||||
{
|
||||
this._destroy.push(item);
|
||||
|
||||
this._toProcess++;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
update: function ()
|
||||
{
|
||||
if (this._toProcess === 0)
|
||||
{
|
||||
// Quick bail
|
||||
return this._active;
|
||||
}
|
||||
|
||||
var list = this._destroy;
|
||||
var active = this._active;
|
||||
var i;
|
||||
var item;
|
||||
|
||||
// Clear the 'destroy' list
|
||||
for (i = 0; i < list.length; i++)
|
||||
{
|
||||
item = list[i];
|
||||
|
||||
// Remove from the 'active' array
|
||||
var idx = active.indexOf(item);
|
||||
|
||||
if (idx !== -1)
|
||||
{
|
||||
active.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
|
||||
list.length = 0;
|
||||
|
||||
// Process the pending addition list
|
||||
// This stops callbacks and out of sync events from populating the active array mid-way during an update
|
||||
|
||||
list = this._pending;
|
||||
|
||||
for (i = 0; i < list.length; i++)
|
||||
{
|
||||
item = list[i];
|
||||
|
||||
this._active.push(item);
|
||||
}
|
||||
|
||||
list.length = 0;
|
||||
|
||||
this._toProcess = 0;
|
||||
|
||||
// The owner of this queue can now safely do whatever it needs to with the active list
|
||||
return this._active;
|
||||
},
|
||||
|
||||
getActive: function ()
|
||||
{
|
||||
return this._active;
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
this._pending = [];
|
||||
this._active = [];
|
||||
this._destroy = [];
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = ProcessQueue;
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
module.exports = {
|
||||
|
||||
List: require('./List'),
|
||||
Map: require('./Map'),
|
||||
ProcessQueue: require('./ProcessQueue'),
|
||||
RTree: require('./RTree'),
|
||||
Set: require('./Set')
|
||||
|
||||
|
|
Loading…
Reference in a new issue