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
* - 3 = Warn
* - 4 = Error
* @property Common.logLevel
* @static
* @property logLevel
* @type {Number}
* @default 1
*/

View file

@ -107,13 +107,12 @@ var Body = require('../body/Body');
var allBodies = Composite.allBodies(world),
allConstraints = Composite.allConstraints(world);
// update the detector bodies if they have changed
// if the world has changed
if (world.isModified) {
// update the detector bodies
Detector.setBodies(detector, allBodies);
}
// reset all composite modified flags
if (world.isModified) {
Composite.setModified(world, false, false, true);
}
@ -232,7 +231,9 @@ var Body = require('../body/Body');
* @param {body[]} 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];
// 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
* @private
* @param {body[]} bodies
* @param {vector} 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) {
return;
}
for (var i = 0; i < bodies.length; i++) {
for (var i = 0; i < bodiesLength; i++) {
var body = bodies[i];
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
* @private
* @param {body[]} bodies
* @param {number} delta The amount of time elapsed between updates
*/
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];
if (body.isStatic || body.isSleeping)

View file

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