mirror of
https://github.com/liabru/matter-js.git
synced 2024-12-26 13:49:01 -05:00
removed Matter.Metrics from release builds (now dev only)
This commit is contained in:
parent
0849773b25
commit
968bba265a
8 changed files with 64 additions and 13 deletions
15
Gruntfile.js
15
Gruntfile.js
|
@ -95,6 +95,18 @@ module.exports = function(grunt) {
|
||||||
linkNatives: true
|
linkNatives: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
preprocess: {
|
||||||
|
options: {
|
||||||
|
inline: true,
|
||||||
|
context : {
|
||||||
|
DEBUG: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
js: {
|
||||||
|
src: 'build/<%= buildName %>.js',
|
||||||
|
dest: 'build/<%= buildName %>.js'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -105,6 +117,7 @@ module.exports = function(grunt) {
|
||||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||||
grunt.loadNpmTasks('grunt-contrib-copy');
|
grunt.loadNpmTasks('grunt-contrib-copy');
|
||||||
grunt.loadNpmTasks('grunt-contrib-yuidoc');
|
grunt.loadNpmTasks('grunt-contrib-yuidoc');
|
||||||
|
grunt.loadNpmTasks('grunt-preprocess');
|
||||||
|
|
||||||
grunt.registerTask('default', ['test', 'build']);
|
grunt.registerTask('default', ['test', 'build']);
|
||||||
grunt.registerTask('test', ['jshint']);
|
grunt.registerTask('test', ['jshint']);
|
||||||
|
@ -134,7 +147,7 @@ module.exports = function(grunt) {
|
||||||
// edge build mode (default)
|
// edge build mode (default)
|
||||||
if (isEdge || (!isDev && !isRelease)) {
|
if (isEdge || (!isDev && !isRelease)) {
|
||||||
grunt.config.set('buildVersion', pkg.version + '-edge');
|
grunt.config.set('buildVersion', pkg.version + '-edge');
|
||||||
grunt.task.run('concat', 'uglify:min');
|
grunt.task.run('concat', 'preprocess', 'uglify:min');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -21,13 +21,14 @@
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"grunt": "~0.4.2",
|
"grunt": "~0.4.2",
|
||||||
"grunt-contrib-jshint": "~0.6.3",
|
|
||||||
"grunt-contrib-uglify": "~0.2.7",
|
|
||||||
"grunt-contrib-concat": "~0.3.0",
|
"grunt-contrib-concat": "~0.3.0",
|
||||||
"grunt-contrib-connect": "~0.6.0",
|
"grunt-contrib-connect": "~0.6.0",
|
||||||
"grunt-contrib-copy": "~0.5.0",
|
"grunt-contrib-copy": "~0.5.0",
|
||||||
|
"grunt-contrib-jshint": "~0.6.3",
|
||||||
|
"grunt-contrib-uglify": "~0.2.7",
|
||||||
"grunt-contrib-watch": "~0.5.3",
|
"grunt-contrib-watch": "~0.5.3",
|
||||||
"grunt-contrib-yuidoc": "~0.5.1"
|
"grunt-contrib-yuidoc": "~0.5.1",
|
||||||
|
"grunt-preprocess": "^4.1.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "npm install && grunt dev",
|
"dev": "npm install && grunt dev",
|
||||||
|
|
|
@ -19,9 +19,12 @@ var Detector = {};
|
||||||
*/
|
*/
|
||||||
Detector.collisions = function(broadphasePairs, engine) {
|
Detector.collisions = function(broadphasePairs, engine) {
|
||||||
var collisions = [],
|
var collisions = [],
|
||||||
metrics = engine.metrics,
|
|
||||||
pairsTable = engine.pairs.table;
|
pairsTable = engine.pairs.table;
|
||||||
|
|
||||||
|
// @if DEBUG
|
||||||
|
var metrics = engine.metrics;
|
||||||
|
// @endif
|
||||||
|
|
||||||
for (var i = 0; i < broadphasePairs.length; i++) {
|
for (var i = 0; i < broadphasePairs.length; i++) {
|
||||||
var bodyA = broadphasePairs[i][0],
|
var bodyA = broadphasePairs[i][0],
|
||||||
bodyB = broadphasePairs[i][1];
|
bodyB = broadphasePairs[i][1];
|
||||||
|
@ -32,7 +35,9 @@ var Detector = {};
|
||||||
if (!Detector.canCollide(bodyA.collisionFilter, bodyB.collisionFilter))
|
if (!Detector.canCollide(bodyA.collisionFilter, bodyB.collisionFilter))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// @if DEBUG
|
||||||
metrics.midphaseTests += 1;
|
metrics.midphaseTests += 1;
|
||||||
|
// @endif
|
||||||
|
|
||||||
// mid phase
|
// mid phase
|
||||||
if (Bounds.overlaps(bodyA.bounds, bodyB.bounds)) {
|
if (Bounds.overlaps(bodyA.bounds, bodyB.bounds)) {
|
||||||
|
@ -51,14 +56,17 @@ var Detector = {};
|
||||||
// narrow phase
|
// narrow phase
|
||||||
var collision = SAT.collides(bodyA, bodyB, previousCollision);
|
var collision = SAT.collides(bodyA, bodyB, previousCollision);
|
||||||
|
|
||||||
|
// @if DEBUG
|
||||||
metrics.narrowphaseTests += 1;
|
metrics.narrowphaseTests += 1;
|
||||||
|
|
||||||
if (collision.reused)
|
if (collision.reused)
|
||||||
metrics.narrowReuseCount += 1;
|
metrics.narrowReuseCount += 1;
|
||||||
|
// @endif
|
||||||
|
|
||||||
if (collision.collided) {
|
if (collision.collided) {
|
||||||
collisions.push(collision);
|
collisions.push(collision);
|
||||||
|
// @if DEBUG
|
||||||
metrics.narrowDetections += 1;
|
metrics.narrowDetections += 1;
|
||||||
|
// @endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,9 +83,12 @@ var Detector = {};
|
||||||
*/
|
*/
|
||||||
Detector.bruteForce = function(bodies, engine) {
|
Detector.bruteForce = function(bodies, engine) {
|
||||||
var collisions = [],
|
var collisions = [],
|
||||||
metrics = engine.metrics,
|
|
||||||
pairsTable = engine.pairs.table;
|
pairsTable = engine.pairs.table;
|
||||||
|
|
||||||
|
// @if DEBUG
|
||||||
|
var metrics = engine.metrics;
|
||||||
|
// @endif
|
||||||
|
|
||||||
for (var i = 0; i < bodies.length; i++) {
|
for (var i = 0; i < bodies.length; i++) {
|
||||||
for (var j = i + 1; j < bodies.length; j++) {
|
for (var j = i + 1; j < bodies.length; j++) {
|
||||||
var bodyA = bodies[i],
|
var bodyA = bodies[i],
|
||||||
|
@ -91,7 +102,9 @@ var Detector = {};
|
||||||
if (!Detector.canCollide(bodyA.collisionFilter, bodyB.collisionFilter))
|
if (!Detector.canCollide(bodyA.collisionFilter, bodyB.collisionFilter))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// @if DEBUG
|
||||||
metrics.midphaseTests += 1;
|
metrics.midphaseTests += 1;
|
||||||
|
// @endif
|
||||||
|
|
||||||
// mid phase
|
// mid phase
|
||||||
if (Bounds.overlaps(bodyA.bounds, bodyB.bounds)) {
|
if (Bounds.overlaps(bodyA.bounds, bodyB.bounds)) {
|
||||||
|
@ -110,14 +123,17 @@ var Detector = {};
|
||||||
// narrow phase
|
// narrow phase
|
||||||
var collision = SAT.collides(bodyA, bodyB, previousCollision);
|
var collision = SAT.collides(bodyA, bodyB, previousCollision);
|
||||||
|
|
||||||
|
// @if DEBUG
|
||||||
metrics.narrowphaseTests += 1;
|
metrics.narrowphaseTests += 1;
|
||||||
|
|
||||||
if (collision.reused)
|
if (collision.reused)
|
||||||
metrics.narrowReuseCount += 1;
|
metrics.narrowReuseCount += 1;
|
||||||
|
// @endif
|
||||||
|
|
||||||
if (collision.collided) {
|
if (collision.collided) {
|
||||||
collisions.push(collision);
|
collisions.push(collision);
|
||||||
|
// @if DEBUG
|
||||||
metrics.narrowDetections += 1;
|
metrics.narrowDetections += 1;
|
||||||
|
// @endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,10 +43,12 @@ var Grid = {};
|
||||||
buckets = grid.buckets,
|
buckets = grid.buckets,
|
||||||
bucket,
|
bucket,
|
||||||
bucketId,
|
bucketId,
|
||||||
metrics = engine.metrics,
|
|
||||||
gridChanged = false;
|
gridChanged = false;
|
||||||
|
|
||||||
|
// @if DEBUG
|
||||||
|
var metrics = engine.metrics;
|
||||||
metrics.broadphaseTests = 0;
|
metrics.broadphaseTests = 0;
|
||||||
|
// @endif
|
||||||
|
|
||||||
for (i = 0; i < bodies.length; i++) {
|
for (i = 0; i < bodies.length; i++) {
|
||||||
var body = bodies[i];
|
var body = bodies[i];
|
||||||
|
@ -64,7 +66,9 @@ var Grid = {};
|
||||||
// if the body has changed grid region
|
// if the body has changed grid region
|
||||||
if (!body.region || newRegion.id !== body.region.id || forceUpdate) {
|
if (!body.region || newRegion.id !== body.region.id || forceUpdate) {
|
||||||
|
|
||||||
|
// @if DEBUG
|
||||||
metrics.broadphaseTests += 1;
|
metrics.broadphaseTests += 1;
|
||||||
|
// @endif
|
||||||
|
|
||||||
if (!body.region || forceUpdate)
|
if (!body.region || forceUpdate)
|
||||||
body.region = newRegion;
|
body.region = newRegion;
|
||||||
|
|
|
@ -63,8 +63,12 @@ var Engine = {};
|
||||||
engine.render = engine.render.controller.create(engine.render);
|
engine.render = engine.render.controller.create(engine.render);
|
||||||
engine.world = World.create(engine.world);
|
engine.world = World.create(engine.world);
|
||||||
engine.pairs = Pairs.create();
|
engine.pairs = Pairs.create();
|
||||||
engine.metrics = engine.metrics || Metrics.create();
|
|
||||||
engine.broadphase = engine.broadphase.controller.create(engine.broadphase);
|
engine.broadphase = engine.broadphase.controller.create(engine.broadphase);
|
||||||
|
engine.metrics = engine.metrics || { extended: false };
|
||||||
|
|
||||||
|
// @if DEBUG
|
||||||
|
engine.metrics = engine.metrics || Metrics.create();
|
||||||
|
// @endif
|
||||||
|
|
||||||
return engine;
|
return engine;
|
||||||
};
|
};
|
||||||
|
@ -102,8 +106,10 @@ var Engine = {};
|
||||||
var allBodies = Composite.allBodies(world),
|
var allBodies = Composite.allBodies(world),
|
||||||
allConstraints = Composite.allConstraints(world);
|
allConstraints = Composite.allConstraints(world);
|
||||||
|
|
||||||
|
// @if DEBUG
|
||||||
// reset metrics logging
|
// reset metrics logging
|
||||||
Metrics.reset(engine.metrics);
|
Metrics.reset(engine.metrics);
|
||||||
|
// @endif
|
||||||
|
|
||||||
// if sleeping enabled, call the sleeping controller
|
// if sleeping enabled, call the sleeping controller
|
||||||
if (engine.enableSleeping)
|
if (engine.enableSleeping)
|
||||||
|
@ -173,8 +179,10 @@ var Engine = {};
|
||||||
if (pairs.collisionEnd.length > 0)
|
if (pairs.collisionEnd.length > 0)
|
||||||
Events.trigger(engine, 'collisionEnd', { pairs: pairs.collisionEnd });
|
Events.trigger(engine, 'collisionEnd', { pairs: pairs.collisionEnd });
|
||||||
|
|
||||||
|
// @if DEBUG
|
||||||
// update metrics log
|
// update metrics log
|
||||||
Metrics.update(engine.metrics, engine);
|
Metrics.update(engine.metrics, engine);
|
||||||
|
// @endif
|
||||||
|
|
||||||
// clear force buffers
|
// clear force buffers
|
||||||
_bodiesClearForces(allBodies);
|
_bodiesClearForces(allBodies);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
// @if DEBUG
|
||||||
/**
|
/**
|
||||||
* _Internal Class_, not generally used outside of the engine's internals.
|
* _Internal Class_, not generally used outside of the engine's internals.
|
||||||
*
|
*
|
||||||
* @class Metrics
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Metrics = {};
|
var Metrics = {};
|
||||||
|
@ -11,6 +11,7 @@ var Metrics = {};
|
||||||
/**
|
/**
|
||||||
* Description
|
* Description
|
||||||
* @method create
|
* @method create
|
||||||
|
* @private
|
||||||
* @return {metrics} A new metrics
|
* @return {metrics} A new metrics
|
||||||
*/
|
*/
|
||||||
Metrics.create = function() {
|
Metrics.create = function() {
|
||||||
|
@ -35,6 +36,7 @@ var Metrics = {};
|
||||||
/**
|
/**
|
||||||
* Description
|
* Description
|
||||||
* @method reset
|
* @method reset
|
||||||
|
* @private
|
||||||
* @param {metrics} metrics
|
* @param {metrics} metrics
|
||||||
*/
|
*/
|
||||||
Metrics.reset = function(metrics) {
|
Metrics.reset = function(metrics) {
|
||||||
|
@ -58,6 +60,7 @@ var Metrics = {};
|
||||||
/**
|
/**
|
||||||
* Description
|
* Description
|
||||||
* @method update
|
* @method update
|
||||||
|
* @private
|
||||||
* @param {metrics} metrics
|
* @param {metrics} metrics
|
||||||
* @param {engine} engine
|
* @param {engine} engine
|
||||||
*/
|
*/
|
||||||
|
@ -80,3 +83,4 @@ var Metrics = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
// @endif
|
|
@ -25,7 +25,6 @@ Matter.Constraint = Constraint;
|
||||||
Matter.MouseConstraint = MouseConstraint;
|
Matter.MouseConstraint = MouseConstraint;
|
||||||
Matter.Common = Common;
|
Matter.Common = Common;
|
||||||
Matter.Engine = Engine;
|
Matter.Engine = Engine;
|
||||||
Matter.Metrics = Metrics;
|
|
||||||
Matter.Mouse = Mouse;
|
Matter.Mouse = Mouse;
|
||||||
Matter.Sleeping = Sleeping;
|
Matter.Sleeping = Sleeping;
|
||||||
Matter.Bodies = Bodies;
|
Matter.Bodies = Bodies;
|
||||||
|
@ -40,6 +39,10 @@ Matter.Events = Events;
|
||||||
Matter.Query = Query;
|
Matter.Query = Query;
|
||||||
Matter.Runner = Runner;
|
Matter.Runner = Runner;
|
||||||
|
|
||||||
|
// @if DEBUG
|
||||||
|
Matter.Metrics = Metrics;
|
||||||
|
// @endif
|
||||||
|
|
||||||
// CommonJS module
|
// CommonJS module
|
||||||
if (typeof exports !== 'undefined') {
|
if (typeof exports !== 'undefined') {
|
||||||
if (typeof module !== 'undefined' && module.exports) {
|
if (typeof module !== 'undefined' && module.exports) {
|
||||||
|
|
|
@ -232,6 +232,7 @@ var Render = {};
|
||||||
var text = "";
|
var text = "";
|
||||||
text += "fps: " + Math.round(engine.timing.fps) + space;
|
text += "fps: " + Math.round(engine.timing.fps) + space;
|
||||||
|
|
||||||
|
// @if DEBUG
|
||||||
if (engine.metrics.extended) {
|
if (engine.metrics.extended) {
|
||||||
text += "delta: " + engine.timing.delta.toFixed(3) + space;
|
text += "delta: " + engine.timing.delta.toFixed(3) + space;
|
||||||
text += "correction: " + engine.timing.correction.toFixed(3) + space;
|
text += "correction: " + engine.timing.correction.toFixed(3) + space;
|
||||||
|
@ -248,6 +249,7 @@ var Render = {};
|
||||||
text += "mid: " + engine.metrics.midEff + space;
|
text += "mid: " + engine.metrics.midEff + space;
|
||||||
text += "narrow: " + engine.metrics.narrowEff + space;
|
text += "narrow: " + engine.metrics.narrowEff + space;
|
||||||
}
|
}
|
||||||
|
// @endif
|
||||||
|
|
||||||
render.debugString = text;
|
render.debugString = text;
|
||||||
render.debugTimestamp = engine.timing.timestamp;
|
render.debugTimestamp = engine.timing.timestamp;
|
||||||
|
|
Loading…
Reference in a new issue