From 123d391d009cfc94f7dfa175fb935c834e2de832 Mon Sep 17 00:00:00 2001 From: liabru Date: Mon, 17 Mar 2014 17:41:25 +0000 Subject: [PATCH] now only fps metrics by default, set metrics.extended true for full metrics --- src/core/Metrics.js | 55 ++++++++++++++++++++++++--------------------- src/render/Gui.js | 25 ++++++++++++--------- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/src/core/Metrics.js b/src/core/Metrics.js index 5e8c3e9..99ce074 100644 --- a/src/core/Metrics.js +++ b/src/core/Metrics.js @@ -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; + } }; })(); \ No newline at end of file diff --git a/src/render/Gui.js b/src/render/Gui.js index 7e62c05..e16434f 100644 --- a/src/render/Gui.js +++ b/src/render/Gui.js @@ -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);