Skip to content

Commit

Permalink
expose pools via docs, added pool prefill example in circles demo
Browse files Browse the repository at this point in the history
  • Loading branch information
schteppe committed Apr 6, 2015
1 parent 3437134 commit 0b2a648
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
7 changes: 7 additions & 0 deletions demos/circles.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
gravity : [0,-5]
});

// Pre-fill object pools. Completely optional but good for performance!
world.overlapKeeper.recordPool.resize(16);
world.islandManager.islandPool.resize(128);
world.islandManager.nodePool.resize(1024);
world.narrowphase.contactEquationPool.resize(1024);
world.narrowphase.frictionEquationPool.resize(1024);

this.setWorld(world);

// Set stiffness of all contacts and constraints
Expand Down
2 changes: 1 addition & 1 deletion src/collision/Narrowphase.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function Narrowphase(){
* // Allocate a few equations before starting the simulation.
* // This way, no contact objects need to be created on the fly in the game loop.
* world.narrowphase.contactEquationPool.resize(1024);
* world.narrowphase.contactFrictionPool.resize(1024);
* world.narrowphase.frictionEquationPool.resize(1024);
*/
this.contactEquationPool = new ContactEquationPool({ size: 32 });

Expand Down
26 changes: 17 additions & 9 deletions src/world/IslandManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@ module.exports = IslandManager;
*/
function IslandManager(options){

// Pooling of node objects saves some GC load
this._nodePool = new IslandNodePool({ size: 16 });
this._islandPool = new IslandPool({ size: 8 });
/**
* @property nodePool
* @type {IslandNodePool}
*/
this.nodePool = new IslandNodePool({ size: 16 });

/**
* @property islandPool
* @type {IslandPool}
*/
this.islandPool = new IslandPool({ size: 8 });

/**
* The equations to split. Manually fill this array before running .split().
Expand Down Expand Up @@ -134,16 +142,16 @@ IslandManager.prototype.split = function(world){

// Move old nodes to the node pool
while(nodes.length){
this._nodePool.release(nodes.pop());
this.nodePool.release(nodes.pop());
}

// Create needed nodes, reuse if possible
for(var i=0; i!==bodies.length; i++){
var node = this._nodePool.get();
var node = this.nodePool.get();
node.body = bodies[i];
nodes.push(node);
// if(this._nodePool.length){
// var node = this._nodePool.pop();
// if(this.nodePool.length){
// var node = this.nodePool.pop();
// node.reset();
// node.body = bodies[i];
// nodes.push(node);
Expand All @@ -168,7 +176,7 @@ IslandManager.prototype.split = function(world){
// Move old islands to the island pool
var islands = this.islands;
for(var i=0; i<islands.length; i++){
this._islandPool.release(islands[i]);
this.islandPool.release(islands[i]);
}
islands.length = 0;

Expand All @@ -177,7 +185,7 @@ IslandManager.prototype.split = function(world){
while((child = IslandManager.getUnvisitedNode(nodes))){

// Create new island
var island = this._islandPool.get();
var island = this.islandPool.get();

// Get all equations and bodies in this island
this.bfs(child, island.bodies, island.equations);
Expand Down

0 comments on commit 0b2a648

Please sign in to comment.