0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-01-05 15:18:39 -05:00
liabru-matter-js/src/core/Metrics.js

81 lines
2.3 KiB
JavaScript
Raw Normal View History

/**
* _Internal Class_, not generally used outside of the engine's internals.
*
* @class Metrics
*/
2014-02-19 09:15:05 -05:00
var Metrics = {};
(function() {
/**
* Description
* @method create
* @return {metrics} A new metrics
*/
2014-02-19 09:15:05 -05:00
Metrics.create = function() {
return {
extended: false,
2014-02-19 09:15:05 -05:00
narrowDetections: 0,
narrowphaseTests: 0,
narrowReuse: 0,
narrowReuseCount: 0,
2014-02-19 09:15:05 -05:00
midphaseTests: 0,
broadphaseTests: 0,
narrowEff: 0.0001,
midEff: 0.0001,
broadEff: 0.0001,
collisions: 0,
buckets: 0,
bodies: 0,
pairs: 0
};
};
/**
* Description
* @method reset
* @param {metrics} metrics
*/
2014-02-19 09:15:05 -05:00
Metrics.reset = function(metrics) {
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;
}
2014-02-19 09:15:05 -05:00
};
/**
* Description
* @method update
* @param {metrics} metrics
* @param {engine} engine
*/
2014-02-19 09:15:05 -05:00
Metrics.update = function(metrics, engine) {
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;
}
2014-02-19 09:15:05 -05:00
};
})();