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
|
||||
}
|
||||
}
|
||||
},
|
||||
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-copy');
|
||||
grunt.loadNpmTasks('grunt-contrib-yuidoc');
|
||||
grunt.loadNpmTasks('grunt-preprocess');
|
||||
|
||||
grunt.registerTask('default', ['test', 'build']);
|
||||
grunt.registerTask('test', ['jshint']);
|
||||
|
@ -134,7 +147,7 @@ module.exports = function(grunt) {
|
|||
// edge build mode (default)
|
||||
if (isEdge || (!isDev && !isRelease)) {
|
||||
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": {
|
||||
"grunt": "~0.4.2",
|
||||
"grunt-contrib-jshint": "~0.6.3",
|
||||
"grunt-contrib-uglify": "~0.2.7",
|
||||
"grunt-contrib-concat": "~0.3.0",
|
||||
"grunt-contrib-connect": "~0.6.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-yuidoc": "~0.5.1"
|
||||
"grunt-contrib-yuidoc": "~0.5.1",
|
||||
"grunt-preprocess": "^4.1.0"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "npm install && grunt dev",
|
||||
|
|
|
@ -19,9 +19,12 @@ var Detector = {};
|
|||
*/
|
||||
Detector.collisions = function(broadphasePairs, engine) {
|
||||
var collisions = [],
|
||||
metrics = engine.metrics,
|
||||
pairsTable = engine.pairs.table;
|
||||
|
||||
// @if DEBUG
|
||||
var metrics = engine.metrics;
|
||||
// @endif
|
||||
|
||||
for (var i = 0; i < broadphasePairs.length; i++) {
|
||||
var bodyA = broadphasePairs[i][0],
|
||||
bodyB = broadphasePairs[i][1];
|
||||
|
@ -32,7 +35,9 @@ var Detector = {};
|
|||
if (!Detector.canCollide(bodyA.collisionFilter, bodyB.collisionFilter))
|
||||
continue;
|
||||
|
||||
// @if DEBUG
|
||||
metrics.midphaseTests += 1;
|
||||
// @endif
|
||||
|
||||
// mid phase
|
||||
if (Bounds.overlaps(bodyA.bounds, bodyB.bounds)) {
|
||||
|
@ -51,14 +56,17 @@ var Detector = {};
|
|||
// narrow phase
|
||||
var collision = SAT.collides(bodyA, bodyB, previousCollision);
|
||||
|
||||
// @if DEBUG
|
||||
metrics.narrowphaseTests += 1;
|
||||
|
||||
if (collision.reused)
|
||||
metrics.narrowReuseCount += 1;
|
||||
// @endif
|
||||
|
||||
if (collision.collided) {
|
||||
collisions.push(collision);
|
||||
// @if DEBUG
|
||||
metrics.narrowDetections += 1;
|
||||
// @endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -75,9 +83,12 @@ var Detector = {};
|
|||
*/
|
||||
Detector.bruteForce = function(bodies, engine) {
|
||||
var collisions = [],
|
||||
metrics = engine.metrics,
|
||||
pairsTable = engine.pairs.table;
|
||||
|
||||
// @if DEBUG
|
||||
var metrics = engine.metrics;
|
||||
// @endif
|
||||
|
||||
for (var i = 0; i < bodies.length; i++) {
|
||||
for (var j = i + 1; j < bodies.length; j++) {
|
||||
var bodyA = bodies[i],
|
||||
|
@ -91,7 +102,9 @@ var Detector = {};
|
|||
if (!Detector.canCollide(bodyA.collisionFilter, bodyB.collisionFilter))
|
||||
continue;
|
||||
|
||||
// @if DEBUG
|
||||
metrics.midphaseTests += 1;
|
||||
// @endif
|
||||
|
||||
// mid phase
|
||||
if (Bounds.overlaps(bodyA.bounds, bodyB.bounds)) {
|
||||
|
@ -110,14 +123,17 @@ var Detector = {};
|
|||
// narrow phase
|
||||
var collision = SAT.collides(bodyA, bodyB, previousCollision);
|
||||
|
||||
// @if DEBUG
|
||||
metrics.narrowphaseTests += 1;
|
||||
|
||||
if (collision.reused)
|
||||
metrics.narrowReuseCount += 1;
|
||||
// @endif
|
||||
|
||||
if (collision.collided) {
|
||||
collisions.push(collision);
|
||||
// @if DEBUG
|
||||
metrics.narrowDetections += 1;
|
||||
// @endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,10 +43,12 @@ var Grid = {};
|
|||
buckets = grid.buckets,
|
||||
bucket,
|
||||
bucketId,
|
||||
metrics = engine.metrics,
|
||||
gridChanged = false;
|
||||
|
||||
// @if DEBUG
|
||||
var metrics = engine.metrics;
|
||||
metrics.broadphaseTests = 0;
|
||||
// @endif
|
||||
|
||||
for (i = 0; i < bodies.length; i++) {
|
||||
var body = bodies[i];
|
||||
|
@ -64,7 +66,9 @@ var Grid = {};
|
|||
// if the body has changed grid region
|
||||
if (!body.region || newRegion.id !== body.region.id || forceUpdate) {
|
||||
|
||||
// @if DEBUG
|
||||
metrics.broadphaseTests += 1;
|
||||
// @endif
|
||||
|
||||
if (!body.region || forceUpdate)
|
||||
body.region = newRegion;
|
||||
|
|
|
@ -63,8 +63,12 @@ var Engine = {};
|
|||
engine.render = engine.render.controller.create(engine.render);
|
||||
engine.world = World.create(engine.world);
|
||||
engine.pairs = Pairs.create();
|
||||
engine.metrics = engine.metrics || Metrics.create();
|
||||
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;
|
||||
};
|
||||
|
@ -102,8 +106,10 @@ var Engine = {};
|
|||
var allBodies = Composite.allBodies(world),
|
||||
allConstraints = Composite.allConstraints(world);
|
||||
|
||||
// @if DEBUG
|
||||
// reset metrics logging
|
||||
Metrics.reset(engine.metrics);
|
||||
// @endif
|
||||
|
||||
// if sleeping enabled, call the sleeping controller
|
||||
if (engine.enableSleeping)
|
||||
|
@ -173,8 +179,10 @@ var Engine = {};
|
|||
if (pairs.collisionEnd.length > 0)
|
||||
Events.trigger(engine, 'collisionEnd', { pairs: pairs.collisionEnd });
|
||||
|
||||
// @if DEBUG
|
||||
// update metrics log
|
||||
Metrics.update(engine.metrics, engine);
|
||||
// @endif
|
||||
|
||||
// clear force buffers
|
||||
_bodiesClearForces(allBodies);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// @if DEBUG
|
||||
/**
|
||||
* _Internal Class_, not generally used outside of the engine's internals.
|
||||
*
|
||||
* @class Metrics
|
||||
*/
|
||||
|
||||
var Metrics = {};
|
||||
|
@ -11,6 +11,7 @@ var Metrics = {};
|
|||
/**
|
||||
* Description
|
||||
* @method create
|
||||
* @private
|
||||
* @return {metrics} A new metrics
|
||||
*/
|
||||
Metrics.create = function() {
|
||||
|
@ -35,6 +36,7 @@ var Metrics = {};
|
|||
/**
|
||||
* Description
|
||||
* @method reset
|
||||
* @private
|
||||
* @param {metrics} metrics
|
||||
*/
|
||||
Metrics.reset = function(metrics) {
|
||||
|
@ -58,6 +60,7 @@ var Metrics = {};
|
|||
/**
|
||||
* Description
|
||||
* @method update
|
||||
* @private
|
||||
* @param {metrics} metrics
|
||||
* @param {engine} engine
|
||||
*/
|
||||
|
@ -80,3 +83,4 @@ var Metrics = {};
|
|||
};
|
||||
|
||||
})();
|
||||
// @endif
|
|
@ -25,7 +25,6 @@ Matter.Constraint = Constraint;
|
|||
Matter.MouseConstraint = MouseConstraint;
|
||||
Matter.Common = Common;
|
||||
Matter.Engine = Engine;
|
||||
Matter.Metrics = Metrics;
|
||||
Matter.Mouse = Mouse;
|
||||
Matter.Sleeping = Sleeping;
|
||||
Matter.Bodies = Bodies;
|
||||
|
@ -40,6 +39,10 @@ Matter.Events = Events;
|
|||
Matter.Query = Query;
|
||||
Matter.Runner = Runner;
|
||||
|
||||
// @if DEBUG
|
||||
Matter.Metrics = Metrics;
|
||||
// @endif
|
||||
|
||||
// CommonJS module
|
||||
if (typeof exports !== 'undefined') {
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
|
|
|
@ -232,6 +232,7 @@ var Render = {};
|
|||
var text = "";
|
||||
text += "fps: " + Math.round(engine.timing.fps) + space;
|
||||
|
||||
// @if DEBUG
|
||||
if (engine.metrics.extended) {
|
||||
text += "delta: " + engine.timing.delta.toFixed(3) + space;
|
||||
text += "correction: " + engine.timing.correction.toFixed(3) + space;
|
||||
|
@ -248,6 +249,7 @@ var Render = {};
|
|||
text += "mid: " + engine.metrics.midEff + space;
|
||||
text += "narrow: " + engine.metrics.narrowEff + space;
|
||||
}
|
||||
// @endif
|
||||
|
||||
render.debugString = text;
|
||||
render.debugTimestamp = engine.timing.timestamp;
|
||||
|
|
Loading…
Reference in a new issue