0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-23 09:26:51 -05:00

tidy and refactor

This commit is contained in:
liabru 2022-01-04 14:18:35 +00:00
parent fda962f2dc
commit fe985288d6
3 changed files with 16 additions and 12 deletions

View file

@ -323,7 +323,8 @@ module.exports = Common;
* - 2 = Info * - 2 = Info
* - 3 = Warn * - 3 = Warn
* - 4 = Error * - 4 = Error
* @property Common.logLevel * @static
* @property logLevel
* @type {Number} * @type {Number}
* @default 1 * @default 1
*/ */

View file

@ -107,13 +107,12 @@ var Body = require('../body/Body');
var allBodies = Composite.allBodies(world), var allBodies = Composite.allBodies(world),
allConstraints = Composite.allConstraints(world); allConstraints = Composite.allConstraints(world);
// update the detector bodies if they have changed // if the world has changed
if (world.isModified) { if (world.isModified) {
// update the detector bodies
Detector.setBodies(detector, allBodies); Detector.setBodies(detector, allBodies);
}
// reset all composite modified flags // reset all composite modified flags
if (world.isModified) {
Composite.setModified(world, false, false, true); Composite.setModified(world, false, false, true);
} }
@ -232,7 +231,9 @@ var Body = require('../body/Body');
* @param {body[]} bodies * @param {body[]} bodies
*/ */
Engine._bodiesClearForces = function(bodies) { Engine._bodiesClearForces = function(bodies) {
for (var i = 0; i < bodies.length; i++) { var bodiesLength = bodies.length;
for (var i = 0; i < bodiesLength; i++) {
var body = bodies[i]; var body = bodies[i];
// reset force buffers // reset force buffers
@ -243,20 +244,21 @@ var Body = require('../body/Body');
}; };
/** /**
* Applys a mass dependant force to all given bodies. * Applies a mass dependant force to all given bodies.
* @method _bodiesApplyGravity * @method _bodiesApplyGravity
* @private * @private
* @param {body[]} bodies * @param {body[]} bodies
* @param {vector} gravity * @param {vector} gravity
*/ */
Engine._bodiesApplyGravity = function(bodies, gravity) { Engine._bodiesApplyGravity = function(bodies, gravity) {
var gravityScale = typeof gravity.scale !== 'undefined' ? gravity.scale : 0.001; var gravityScale = typeof gravity.scale !== 'undefined' ? gravity.scale : 0.001,
bodiesLength = bodies.length;
if ((gravity.x === 0 && gravity.y === 0) || gravityScale === 0) { if ((gravity.x === 0 && gravity.y === 0) || gravityScale === 0) {
return; return;
} }
for (var i = 0; i < bodies.length; i++) { for (var i = 0; i < bodiesLength; i++) {
var body = bodies[i]; var body = bodies[i];
if (body.isStatic || body.isSleeping) if (body.isStatic || body.isSleeping)
@ -269,14 +271,16 @@ var Body = require('../body/Body');
}; };
/** /**
* Applys `Body.update` to all given `bodies`. * Applies `Body.update` to all given `bodies`.
* @method _bodiesUpdate * @method _bodiesUpdate
* @private * @private
* @param {body[]} bodies * @param {body[]} bodies
* @param {number} delta The amount of time elapsed between updates * @param {number} delta The amount of time elapsed between updates
*/ */
Engine._bodiesUpdate = function(bodies, delta) { Engine._bodiesUpdate = function(bodies, delta) {
for (var i = 0; i < bodies.length; i++) { var bodiesLength = bodies.length;
for (var i = 0; i < bodiesLength; i++) {
var body = bodies[i]; var body = bodies[i];
if (body.isStatic || body.isSleeping) if (body.isStatic || body.isSleeping)

View file

@ -25,8 +25,7 @@ var Common = require('./Common');
*/ */
Sleeping.update = function(bodies, delta) { Sleeping.update = function(bodies, delta) {
var timeScale = delta / Common._timeUnit, var timeScale = delta / Common._timeUnit,
timeScaleSquared = timeScale * timeScale, motionSleepThreshold = Sleeping._motionSleepThreshold * timeScale * timeScale;
motionSleepThreshold = Sleeping._motionSleepThreshold * timeScaleSquared;
// update bodies sleeping status // update bodies sleeping status
for (var i = 0; i < bodies.length; i++) { for (var i = 0; i < bodies.length; i++) {