0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-27 13:59:01 -05:00

now only fps metrics by default, set metrics.extended true for full metrics

This commit is contained in:
liabru 2014-03-17 17:41:25 +00:00
parent 00feed5272
commit 123d391d00
2 changed files with 45 additions and 35 deletions

View file

@ -15,6 +15,7 @@ var Metrics = {};
*/ */
Metrics.create = function() { Metrics.create = function() {
return { return {
extended: false,
narrowDetections: 0, narrowDetections: 0,
narrowphaseTests: 0, narrowphaseTests: 0,
narrowReuse: 0, narrowReuse: 0,
@ -37,19 +38,21 @@ var Metrics = {};
* @param {metrics} metrics * @param {metrics} metrics
*/ */
Metrics.reset = function(metrics) { Metrics.reset = function(metrics) {
metrics.narrowDetections = 0; if (metrics.extended) {
metrics.narrowphaseTests = 0; metrics.narrowDetections = 0;
metrics.narrowReuse = 0; metrics.narrowphaseTests = 0;
metrics.narrowReuseCount = 0; metrics.narrowReuse = 0;
metrics.midphaseTests = 0; metrics.narrowReuseCount = 0;
metrics.broadphaseTests = 0; metrics.midphaseTests = 0;
metrics.narrowEff = 0; metrics.broadphaseTests = 0;
metrics.midEff = 0; metrics.narrowEff = 0;
metrics.broadEff = 0; metrics.midEff = 0;
metrics.collisions = 0; metrics.broadEff = 0;
metrics.buckets = 0; metrics.collisions = 0;
metrics.pairs = 0; metrics.buckets = 0;
metrics.bodies = 0; metrics.pairs = 0;
metrics.bodies = 0;
}
}; };
/** /**
@ -59,18 +62,20 @@ var Metrics = {};
* @param {engine} engine * @param {engine} engine
*/ */
Metrics.update = function(metrics, engine) { Metrics.update = function(metrics, engine) {
var world = engine.world, if (metrics.extended) {
broadphase = engine.broadphase[engine.broadphase.current]; var world = engine.world,
broadphase = engine.broadphase[engine.broadphase.current];
metrics.collisions = metrics.narrowDetections; metrics.collisions = metrics.narrowDetections;
metrics.pairs = engine.pairs.list.length; metrics.pairs = engine.pairs.list.length;
metrics.bodies = world.bodies.length; metrics.bodies = world.bodies.length;
metrics.midEff = (metrics.narrowDetections / (metrics.midphaseTests || 1)).toFixed(2); metrics.midEff = (metrics.narrowDetections / (metrics.midphaseTests || 1)).toFixed(2);
metrics.narrowEff = (metrics.narrowDetections / (metrics.narrowphaseTests || 1)).toFixed(2); metrics.narrowEff = (metrics.narrowDetections / (metrics.narrowphaseTests || 1)).toFixed(2);
metrics.broadEff = (1 - (metrics.broadphaseTests / (world.bodies.length || 1))).toFixed(2); metrics.broadEff = (1 - (metrics.broadphaseTests / (world.bodies.length || 1))).toFixed(2);
metrics.narrowReuse = (metrics.narrowReuseCount / (metrics.narrowphaseTests || 1)).toFixed(2); metrics.narrowReuse = (metrics.narrowReuseCount / (metrics.narrowphaseTests || 1)).toFixed(2);
//if (broadphase.instance) //if (broadphase.instance)
// metrics.buckets = Common.keys(broadphase.instance.buckets).length; // metrics.buckets = Common.keys(broadphase.instance.buckets).length;
}
}; };
})(); })();

View file

@ -86,16 +86,21 @@ var Gui = {};
var metrics = datGui.addFolder('Metrics'); var metrics = datGui.addFolder('Metrics');
metrics.add(engine.timing, 'fps').listen(); metrics.add(engine.timing, 'fps').listen();
metrics.add(engine.timing, 'delta').listen();
metrics.add(engine.timing, 'correction').listen(); if (engine.metrics.extended) {
metrics.add(engine.metrics, 'bodies').listen(); metrics.add(engine.timing, 'delta').listen();
metrics.add(engine.metrics, 'collisions').listen(); metrics.add(engine.timing, 'correction').listen();
metrics.add(engine.metrics, 'pairs').listen(); metrics.add(engine.metrics, 'bodies').listen();
metrics.add(engine.metrics, 'broadEff').listen(); metrics.add(engine.metrics, 'collisions').listen();
metrics.add(engine.metrics, 'midEff').listen(); metrics.add(engine.metrics, 'pairs').listen();
metrics.add(engine.metrics, 'narrowEff').listen(); metrics.add(engine.metrics, 'broadEff').listen();
metrics.add(engine.metrics, 'narrowReuse').listen(); metrics.add(engine.metrics, 'midEff').listen();
metrics.close(); metrics.add(engine.metrics, 'narrowEff').listen();
metrics.add(engine.metrics, 'narrowReuse').listen();
metrics.close();
} else {
metrics.open();
}
var controls = datGui.addFolder('Add Body'); var controls = datGui.addFolder('Add Body');
controls.add(gui, 'amount', 1, 5).step(1); controls.add(gui, 'amount', 1, 5).step(1);