From b3220cf3e8ff6d8b55ea0056238d022073bc0e97 Mon Sep 17 00:00:00 2001 From: Brice Chevalier Date: Sat, 25 Nov 2017 00:32:46 +0900 Subject: [PATCH] Optimized Body's hidden class --- src/body/Body.js | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/body/Body.js b/src/body/Body.js index 39ba0d3..abd7811 100644 --- a/src/body/Body.js +++ b/src/body/Body.js @@ -20,6 +20,7 @@ var Common = require('../core/Common'); var Bounds = require('../geometry/Bounds'); var Axes = require('../geometry/Axes'); + (function() { Body._inertiaScale = 4; @@ -82,7 +83,22 @@ var Axes = require('../geometry/Axes'); yOffset: 0 }, lineWidth: 0 - } + }, + + events: null, + bounds: null, + chamfer: null, + circleRadius: 0, + positionPrev: null, + anglePrev: 0, + parent: null, + + axes: null, + area: 0, + mass: 0, + inertia: 0, + + _original: null }; var body = Common.extend(defaults, options); @@ -166,24 +182,18 @@ var Axes = require('../geometry/Axes'); * Prefer to use the actual setter functions in performance critical situations. * @method set * @param {body} body - * @param {} settings A property name (or map of properties and values) to set on the body. - * @param {} value The value to set if `settings` is a single property name. + * @param {object} settings A map of properties and values to set on the body. */ - Body.set = function(body, settings, value) { - var property; - - if (typeof settings === 'string') { - property = settings; - settings = {}; - settings[property] = value; - } + Body.set = function(body, settings) { + var property, + value; for (property in settings) { - value = settings[property]; if (!settings.hasOwnProperty(property)) continue; + value = settings[property]; switch (property) { case 'isStatic': @@ -269,7 +279,7 @@ var Axes = require('../geometry/Axes'); part.inverseMass = part._original.inverseMass; part.inverseInertia = part._original.inverseInertia; - delete part._original; + part._original = null; } } };