mirror of
https://github.com/liabru/matter-js.git
synced 2024-12-26 13:49:01 -05:00
now only fps metrics by default, set metrics.extended true for full metrics
This commit is contained in:
parent
00feed5272
commit
123d391d00
2 changed files with 45 additions and 35 deletions
|
@ -15,6 +15,7 @@ var Metrics = {};
|
|||
*/
|
||||
Metrics.create = function() {
|
||||
return {
|
||||
extended: false,
|
||||
narrowDetections: 0,
|
||||
narrowphaseTests: 0,
|
||||
narrowReuse: 0,
|
||||
|
@ -37,19 +38,21 @@ var Metrics = {};
|
|||
* @param {metrics} metrics
|
||||
*/
|
||||
Metrics.reset = function(metrics) {
|
||||
metrics.narrowDetections = 0;
|
||||
metrics.narrowphaseTests = 0;
|
||||
metrics.narrowReuse = 0;
|
||||
metrics.narrowReuseCount = 0;
|
||||
metrics.midphaseTests = 0;
|
||||
metrics.broadphaseTests = 0;
|
||||
metrics.narrowEff = 0;
|
||||
metrics.midEff = 0;
|
||||
metrics.broadEff = 0;
|
||||
metrics.collisions = 0;
|
||||
metrics.buckets = 0;
|
||||
metrics.pairs = 0;
|
||||
metrics.bodies = 0;
|
||||
if (metrics.extended) {
|
||||
metrics.narrowDetections = 0;
|
||||
metrics.narrowphaseTests = 0;
|
||||
metrics.narrowReuse = 0;
|
||||
metrics.narrowReuseCount = 0;
|
||||
metrics.midphaseTests = 0;
|
||||
metrics.broadphaseTests = 0;
|
||||
metrics.narrowEff = 0;
|
||||
metrics.midEff = 0;
|
||||
metrics.broadEff = 0;
|
||||
metrics.collisions = 0;
|
||||
metrics.buckets = 0;
|
||||
metrics.pairs = 0;
|
||||
metrics.bodies = 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -59,18 +62,20 @@ var Metrics = {};
|
|||
* @param {engine} engine
|
||||
*/
|
||||
Metrics.update = function(metrics, engine) {
|
||||
var world = engine.world,
|
||||
broadphase = engine.broadphase[engine.broadphase.current];
|
||||
|
||||
metrics.collisions = metrics.narrowDetections;
|
||||
metrics.pairs = engine.pairs.list.length;
|
||||
metrics.bodies = world.bodies.length;
|
||||
metrics.midEff = (metrics.narrowDetections / (metrics.midphaseTests || 1)).toFixed(2);
|
||||
metrics.narrowEff = (metrics.narrowDetections / (metrics.narrowphaseTests || 1)).toFixed(2);
|
||||
metrics.broadEff = (1 - (metrics.broadphaseTests / (world.bodies.length || 1))).toFixed(2);
|
||||
metrics.narrowReuse = (metrics.narrowReuseCount / (metrics.narrowphaseTests || 1)).toFixed(2);
|
||||
//if (broadphase.instance)
|
||||
// metrics.buckets = Common.keys(broadphase.instance.buckets).length;
|
||||
if (metrics.extended) {
|
||||
var world = engine.world,
|
||||
broadphase = engine.broadphase[engine.broadphase.current];
|
||||
|
||||
metrics.collisions = metrics.narrowDetections;
|
||||
metrics.pairs = engine.pairs.list.length;
|
||||
metrics.bodies = world.bodies.length;
|
||||
metrics.midEff = (metrics.narrowDetections / (metrics.midphaseTests || 1)).toFixed(2);
|
||||
metrics.narrowEff = (metrics.narrowDetections / (metrics.narrowphaseTests || 1)).toFixed(2);
|
||||
metrics.broadEff = (1 - (metrics.broadphaseTests / (world.bodies.length || 1))).toFixed(2);
|
||||
metrics.narrowReuse = (metrics.narrowReuseCount / (metrics.narrowphaseTests || 1)).toFixed(2);
|
||||
//if (broadphase.instance)
|
||||
// metrics.buckets = Common.keys(broadphase.instance.buckets).length;
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
|
@ -86,16 +86,21 @@ var Gui = {};
|
|||
|
||||
var metrics = datGui.addFolder('Metrics');
|
||||
metrics.add(engine.timing, 'fps').listen();
|
||||
metrics.add(engine.timing, 'delta').listen();
|
||||
metrics.add(engine.timing, 'correction').listen();
|
||||
metrics.add(engine.metrics, 'bodies').listen();
|
||||
metrics.add(engine.metrics, 'collisions').listen();
|
||||
metrics.add(engine.metrics, 'pairs').listen();
|
||||
metrics.add(engine.metrics, 'broadEff').listen();
|
||||
metrics.add(engine.metrics, 'midEff').listen();
|
||||
metrics.add(engine.metrics, 'narrowEff').listen();
|
||||
metrics.add(engine.metrics, 'narrowReuse').listen();
|
||||
metrics.close();
|
||||
|
||||
if (engine.metrics.extended) {
|
||||
metrics.add(engine.timing, 'delta').listen();
|
||||
metrics.add(engine.timing, 'correction').listen();
|
||||
metrics.add(engine.metrics, 'bodies').listen();
|
||||
metrics.add(engine.metrics, 'collisions').listen();
|
||||
metrics.add(engine.metrics, 'pairs').listen();
|
||||
metrics.add(engine.metrics, 'broadEff').listen();
|
||||
metrics.add(engine.metrics, 'midEff').listen();
|
||||
metrics.add(engine.metrics, 'narrowEff').listen();
|
||||
metrics.add(engine.metrics, 'narrowReuse').listen();
|
||||
metrics.close();
|
||||
} else {
|
||||
metrics.open();
|
||||
}
|
||||
|
||||
var controls = datGui.addFolder('Add Body');
|
||||
controls.add(gui, 'amount', 1, 5).step(1);
|
||||
|
|
Loading…
Reference in a new issue