From 63a9e988f422ca7616a9f909bd78f95182f2190a Mon Sep 17 00:00:00 2001 From: liabru Date: Sun, 21 Mar 2021 18:58:48 +0000 Subject: [PATCH] remove deprecated Matter.Metrics --- .eslintrc | 1 - src/collision/Detector.js | 17 ------- src/collision/Grid.js | 9 ---- src/core/Engine.js | 17 +------ src/core/Metrics.js | 93 --------------------------------------- src/module/main.js | 4 -- src/render/Render.js | 32 +------------- 7 files changed, 2 insertions(+), 171 deletions(-) delete mode 100644 src/core/Metrics.js diff --git a/.eslintrc b/.eslintrc index 6cc3de9..f2be9b9 100644 --- a/.eslintrc +++ b/.eslintrc @@ -62,7 +62,6 @@ "Query": false, "Runner": false, "Svg": false, - "Metrics": false, "Example": false, "__MATTER_VERSION__": false, "__MATTER_IS_DEV__": false, diff --git a/src/collision/Detector.js b/src/collision/Detector.js index dfbf5dd..041ccbd 100644 --- a/src/collision/Detector.js +++ b/src/collision/Detector.js @@ -27,10 +27,6 @@ var Bounds = require('../geometry/Bounds'); var collisions = [], 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]; @@ -41,10 +37,6 @@ var Bounds = require('../geometry/Bounds'); if (!Detector.canCollide(bodyA.collisionFilter, bodyB.collisionFilter)) continue; - // @if DEBUG - metrics.midphaseTests += 1; - // @endif - // mid phase if (Bounds.overlaps(bodyA.bounds, bodyB.bounds)) { for (var j = bodyA.parts.length > 1 ? 1 : 0; j < bodyA.parts.length; j++) { @@ -68,17 +60,8 @@ var Bounds = require('../geometry/Bounds'); // narrow phase var collision = SAT.collides(partA, partB, 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 } } } diff --git a/src/collision/Grid.js b/src/collision/Grid.js index 4acff1e..25b6865 100644 --- a/src/collision/Grid.js +++ b/src/collision/Grid.js @@ -66,11 +66,6 @@ var Common = require('../core/Common'); bucketId, gridChanged = false; - // @if DEBUG - var metrics = engine.metrics; - metrics.broadphaseTests = 0; - // @endif - for (i = 0; i < bodies.length; i++) { var body = bodies[i]; @@ -87,10 +82,6 @@ var Common = require('../core/Common'); // 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; diff --git a/src/core/Engine.js b/src/core/Engine.js index 3e439a7..69e08ec 100644 --- a/src/core/Engine.js +++ b/src/core/Engine.js @@ -17,7 +17,6 @@ var Sleeping = require('./Sleeping'); var Resolver = require('../collision/Resolver'); var Render = require('../render/Render'); var Pairs = require('../collision/Pairs'); -var Metrics = require('./Metrics'); var Grid = require('../collision/Grid'); var Events = require('./Events'); var Composite = require('../body/Composite'); @@ -59,6 +58,7 @@ var Body = require('../body/Body'); broadphase: { controller: Grid } + metrics: {} }; var engine = Common.extend(defaults, options); @@ -86,11 +86,6 @@ var Body = require('../body/Body'); engine.world = options.world || World.create(engine.world); engine.pairs = Pairs.create(); engine.broadphase = engine.broadphase.controller.create(engine.broadphase); - engine.metrics = engine.metrics || { extended: false }; - - // @if DEBUG - engine.metrics = Metrics.create(engine.metrics); - // @endif return engine; }; @@ -134,11 +129,6 @@ var Body = require('../body/Body'); 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) Sleeping.update(allBodies, timing.timeScale); @@ -219,11 +209,6 @@ var Body = require('../body/Body'); 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 Engine._bodiesClearForces(allBodies); diff --git a/src/core/Metrics.js b/src/core/Metrics.js deleted file mode 100644 index c962381..0000000 --- a/src/core/Metrics.js +++ /dev/null @@ -1,93 +0,0 @@ -// @if DEBUG -/** -* _Internal Class_, not generally used outside of the engine's internals. -* -*/ - -var Metrics = {}; - -module.exports = Metrics; - -var Composite = require('../body/Composite'); -var Common = require('./Common'); - -(function() { - - /** - * Creates a new metrics. - * @method create - * @private - * @return {metrics} A new metrics - */ - Metrics.create = function(options) { - var defaults = { - extended: false, - narrowDetections: 0, - narrowphaseTests: 0, - narrowReuse: 0, - narrowReuseCount: 0, - midphaseTests: 0, - broadphaseTests: 0, - narrowEff: 0.0001, - midEff: 0.0001, - broadEff: 0.0001, - collisions: 0, - buckets: 0, - bodies: 0, - pairs: 0 - }; - - return Common.extend(defaults, false, options); - }; - - /** - * Resets metrics. - * @method reset - * @private - * @param {metrics} metrics - */ - 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; - } - }; - - /** - * Updates metrics. - * @method update - * @private - * @param {metrics} metrics - * @param {engine} engine - */ - Metrics.update = function(metrics, engine) { - if (metrics.extended) { - var world = engine.world, - bodies = Composite.allBodies(world); - - metrics.collisions = metrics.narrowDetections; - metrics.pairs = engine.pairs.list.length; - metrics.bodies = 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 / (bodies.length || 1))).toFixed(2); - metrics.narrowReuse = (metrics.narrowReuseCount / (metrics.narrowphaseTests || 1)).toFixed(2); - //var broadphase = engine.broadphase[engine.broadphase.current]; - //if (broadphase.instance) - // metrics.buckets = Common.keys(broadphase.instance.buckets).length; - } - }; - -})(); -// @endif diff --git a/src/module/main.js b/src/module/main.js index 62f964c..d90502d 100644 --- a/src/module/main.js +++ b/src/module/main.js @@ -24,10 +24,6 @@ Matter.Runner = require('../core/Runner'); Matter.Sleeping = require('../core/Sleeping'); Matter.Plugin = require('../core/Plugin'); -// @if DEBUG -Matter.Metrics = require('../core/Metrics'); -// @endif - Matter.Bodies = require('../factory/Bodies'); Matter.Composites = require('../factory/Composites'); diff --git a/src/render/Render.js b/src/render/Render.js index 700f53a..4d54e7d 100644 --- a/src/render/Render.js +++ b/src/render/Render.js @@ -430,41 +430,11 @@ var Mouse = require('../core/Mouse'); Render.debug = function(render, context) { var c = context, engine = render.engine, - world = engine.world, - metrics = engine.metrics, - options = render.options, - bodies = Composite.allBodies(world), - space = " "; + options = render.options; if (engine.timing.timestamp - (render.debugTimestamp || 0) >= 500) { var text = ""; - if (metrics.timing) { - text += "fps: " + Math.round(metrics.timing.fps) + space; - } - - // @if DEBUG - if (metrics.extended) { - if (metrics.timing) { - text += "delta: " + metrics.timing.delta.toFixed(3) + space; - text += "correction: " + metrics.timing.correction.toFixed(3) + space; - } - - text += "bodies: " + bodies.length + space; - - if (engine.broadphase.controller === Grid) - text += "buckets: " + metrics.buckets + space; - - text += "\n"; - - text += "collisions: " + metrics.collisions + space; - text += "pairs: " + engine.pairs.list.length + space; - text += "broad: " + metrics.broadEff + space; - text += "mid: " + metrics.midEff + space; - text += "narrow: " + metrics.narrowEff + space; - } - // @endif - render.debugString = text; render.debugTimestamp = engine.timing.timestamp; }