Skip to content

Commit 16733ad

Browse files
committed
updated edge build
1 parent 0583cdb commit 16733ad

2 files changed

Lines changed: 112 additions & 114 deletions

File tree

build/matter.js

Lines changed: 109 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* matter.js 0.8.0-edge 2015-01-01
2+
* matter.js 0.8.0-edge 2015-01-21
33
* http://brm.io/matter-js/
44
* License: MIT
55
*/
@@ -446,68 +446,6 @@ var Body = {};
446446
Bounds.update(body.bounds, body.vertices, body.velocity);
447447
};
448448

449-
/**
450-
* Zeroes the `body.force` and `body.torque` force buffers.
451-
* @method resetForcesAll
452-
* @param {body[]} bodies
453-
*/
454-
Body.resetForcesAll = function(bodies) {
455-
for (var i = 0; i < bodies.length; i++) {
456-
var body = bodies[i];
457-
458-
// reset force buffers
459-
body.force.x = 0;
460-
body.force.y = 0;
461-
body.torque = 0;
462-
}
463-
};
464-
465-
/**
466-
* Applys a mass dependant force to all given bodies.
467-
* @method applyGravityAll
468-
* @param {body[]} bodies
469-
* @param {vector} gravity
470-
*/
471-
Body.applyGravityAll = function(bodies, gravity) {
472-
for (var i = 0; i < bodies.length; i++) {
473-
var body = bodies[i];
474-
475-
if (body.isStatic || body.isSleeping)
476-
continue;
477-
478-
// apply gravity
479-
body.force.y += body.mass * gravity.y * 0.001;
480-
body.force.x += body.mass * gravity.x * 0.001;
481-
}
482-
};
483-
484-
/**
485-
* Applys `Body.update` to all given `bodies`.
486-
* @method updateAll
487-
* @param {body[]} bodies
488-
* @param {number} deltaTime
489-
* The amount of time elapsed between updates
490-
* @param {number} timeScale
491-
* @param {number} correction
492-
* The Verlet correction factor (deltaTime / lastDeltaTime)
493-
* @param {bounds} worldBounds
494-
*/
495-
Body.updateAll = function(bodies, deltaTime, timeScale, correction, worldBounds) {
496-
for (var i = 0; i < bodies.length; i++) {
497-
var body = bodies[i];
498-
499-
if (body.isStatic || body.isSleeping)
500-
continue;
501-
502-
// don't update out of world bodies
503-
if (body.bounds.max.x < worldBounds.min.x || body.bounds.min.x > worldBounds.max.x
504-
|| body.bounds.max.y < worldBounds.min.y || body.bounds.min.y > worldBounds.max.y)
505-
continue;
506-
507-
Body.update(body, deltaTime, timeScale, correction);
508-
}
509-
};
510-
511449
/**
512450
* Performs a simulation step for the given `body`, including updating position and angle using Verlet integration.
513451
* @method update
@@ -3504,7 +3442,14 @@ var MouseConstraint = {};
35043442
* @return {MouseConstraint} A new MouseConstraint
35053443
*/
35063444
MouseConstraint.create = function(engine, options) {
3507-
var mouse = (options && options.mouse) || Mouse.create(engine.render.canvas);
3445+
var mouse = (engine ? engine.mouse : null) || (options ? options.mouse : null);
3446+
3447+
if (!mouse && engine && engine.render && engine.render.canvas) {
3448+
mouse = Mouse.create(engine.render.canvas);
3449+
} else {
3450+
mouse = Mouse.create();
3451+
Common.log('MouseConstraint.create: options.mouse was undefined, engine.render.canvas was undefined, may not function as expected', 'warn');
3452+
}
35083453

35093454
var constraint = Constraint.create({
35103455
label: 'Mouse Constraint',
@@ -3974,23 +3919,21 @@ var Common = {};
39743919
* @param {string} type
39753920
*/
39763921
Common.log = function(message, type) {
3977-
if (!console || !console.log)
3922+
if (!console || !console.log || !console.warn)
39783923
return;
39793924

39803925
var style;
39813926

39823927
switch (type) {
39833928

39843929
case 'warn':
3985-
style = 'color: coral';
3930+
console.warn('Matter.js:', message);
39863931
break;
39873932
case 'error':
3988-
style = 'color: red';
3933+
console.log('Matter.js:', message);
39893934
break;
39903935

39913936
}
3992-
3993-
console.log('%c [Matter] ' + type + ': ' + message, style);
39943937
};
39953938

39963939
/**
@@ -4145,10 +4088,10 @@ var Engine = {};
41454088
Sleeping.update(allBodies, timing.timeScale);
41464089

41474090
// applies gravity to all bodies
4148-
Body.applyGravityAll(allBodies, world.gravity);
4091+
_bodiesApplyGravity(allBodies, world.gravity);
41494092

41504093
// update all body position and rotation by integration
4151-
Body.updateAll(allBodies, delta, timing.timeScale, correction, world.bounds);
4094+
_bodiesUpdate(allBodies, delta, timing.timeScale, correction, world.bounds);
41524095

41534096
// update all constraints
41544097
for (i = 0; i < engine.constraintIterations; i++) {
@@ -4212,7 +4155,7 @@ var Engine = {};
42124155
Metrics.update(engine.metrics, engine);
42134156

42144157
// clear force buffers
4215-
Body.resetForcesAll(allBodies);
4158+
_bodiesClearForces(allBodies);
42164159

42174160
// clear all composite modified flags
42184161
if (world.isModified)
@@ -4282,6 +4225,71 @@ var Engine = {};
42824225
}
42834226
};
42844227

4228+
/**
4229+
* Zeroes the `body.force` and `body.torque` force buffers.
4230+
* @method bodiesClearForces
4231+
* @private
4232+
* @param {body[]} bodies
4233+
*/
4234+
var _bodiesClearForces = function(bodies) {
4235+
for (var i = 0; i < bodies.length; i++) {
4236+
var body = bodies[i];
4237+
4238+
// reset force buffers
4239+
body.force.x = 0;
4240+
body.force.y = 0;
4241+
body.torque = 0;
4242+
}
4243+
};
4244+
4245+
/**
4246+
* Applys a mass dependant force to all given bodies.
4247+
* @method bodiesApplyGravity
4248+
* @private
4249+
* @param {body[]} bodies
4250+
* @param {vector} gravity
4251+
*/
4252+
var _bodiesApplyGravity = function(bodies, gravity) {
4253+
for (var i = 0; i < bodies.length; i++) {
4254+
var body = bodies[i];
4255+
4256+
if (body.isStatic || body.isSleeping)
4257+
continue;
4258+
4259+
// apply gravity
4260+
body.force.y += body.mass * gravity.y * 0.001;
4261+
body.force.x += body.mass * gravity.x * 0.001;
4262+
}
4263+
};
4264+
4265+
/**
4266+
* Applys `Body.update` to all given `bodies`.
4267+
* @method updateAll
4268+
* @private
4269+
* @param {body[]} bodies
4270+
* @param {number} deltaTime
4271+
* The amount of time elapsed between updates
4272+
* @param {number} timeScale
4273+
* @param {number} correction
4274+
* The Verlet correction factor (deltaTime / lastDeltaTime)
4275+
* @param {bounds} worldBounds
4276+
*/
4277+
var _bodiesUpdate = function(bodies, deltaTime, timeScale, correction, worldBounds) {
4278+
for (var i = 0; i < bodies.length; i++) {
4279+
var body = bodies[i];
4280+
4281+
if (body.isStatic || body.isSleeping)
4282+
continue;
4283+
4284+
// don't update out of world bodies
4285+
if (body.bounds.max.x < worldBounds.min.x || body.bounds.min.x > worldBounds.max.x
4286+
|| body.bounds.max.y < worldBounds.min.y || body.bounds.min.y > worldBounds.max.y)
4287+
continue;
4288+
4289+
Body.update(body, deltaTime, timeScale, correction);
4290+
}
4291+
};
4292+
42854293
/**
42864294
* An alias for `Runner.run`, see `Matter.Runner` for more information.
42874295
* @method run
@@ -4761,6 +4769,10 @@ var Mouse = {};
47614769
*/
47624770
Mouse.create = function(element) {
47634771
var mouse = {};
4772+
4773+
if (!element) {
4774+
Common.log('Mouse.create: element was undefined, defaulting to document.body', 'warn');
4775+
}
47644776

47654777
mouse.element = element || document.body;
47664778
mouse.absolute = { x: 0, y: 0 };
@@ -4771,7 +4783,7 @@ var Mouse = {};
47714783
mouse.scale = { x: 1, y: 1 };
47724784
mouse.wheelDelta = 0;
47734785
mouse.button = -1;
4774-
mouse.pixelRatio = element.getAttribute('data-pixel-ratio') || 1;
4786+
mouse.pixelRatio = mouse.element.getAttribute('data-pixel-ratio') || 1;
47754787

47764788
mouse.sourceEvents = {
47774789
mousemove: null,
@@ -5043,7 +5055,7 @@ var Runner = {};
50435055
Events.trigger(engine, 'tick', event);
50445056

50455057
// if world has been modified, clear the render scene graph
5046-
if (engine.world.isModified)
5058+
if (engine.world.isModified && engine.render.controller.clear)
50475059
engine.render.controller.clear(engine.render);
50485060

50495061
// update
@@ -6462,31 +6474,19 @@ var Render = {};
64626474
}
64636475
};
64646476

6465-
Render.setBackground(render, render.options.background);
6466-
64676477
if (render.options.pixelRatio !== 1) {
64686478
Render.setPixelRatio(render, render.options.pixelRatio);
64696479
}
64706480

64716481
if (Common.isElement(render.element)) {
64726482
render.element.appendChild(render.canvas);
64736483
} else {
6474-
Common.log('No "render.element" passed, "render.canvas" was not inserted into document.', 'warn');
6484+
Common.log('Render.create: options.element was undefined, render.canvas was created but not appended', 'warn');
64756485
}
64766486

64776487
return render;
64786488
};
64796489

6480-
/**
6481-
* Clears the renderer. In this implementation, this is a noop.
6482-
* @method clear
6483-
* @param {render} render
6484-
*/
6485-
Render.clear = function(render) {
6486-
// nothing required to clear this renderer implentation
6487-
// if a scene graph is required, clear it here (see RenderPixi.js)
6488-
};
6489-
64906490
/**
64916491
* Sets the pixel ratio of the renderer and updates the canvas.
64926492
* To automatically detect the correct ratio, pass the string `'auto'` for `pixelRatio`.
@@ -6511,25 +6511,6 @@ var Render = {};
65116511
render.context.scale(pixelRatio, pixelRatio);
65126512
};
65136513

6514-
/**
6515-
* Sets the background CSS property of the canvas
6516-
* @method setBackground
6517-
* @param {render} render
6518-
* @param {string} background
6519-
*/
6520-
Render.setBackground = function(render, background) {
6521-
if (render.currentBackground !== background) {
6522-
var cssBackground = background;
6523-
6524-
if (/(jpg|gif|png)$/.test(background))
6525-
cssBackground = 'url(' + background + ')';
6526-
6527-
render.canvas.style.background = cssBackground;
6528-
render.canvas.style.backgroundSize = "contain";
6529-
render.currentBackground = background;
6530-
}
6531-
};
6532-
65336514
/**
65346515
* Renders the given `engine`'s `Matter.World` object.
65356516
* This is the entry point for all rendering and should be called every time the scene changes.
@@ -6544,15 +6525,14 @@ var Render = {};
65446525
options = render.options,
65456526
allBodies = Composite.allBodies(world),
65466527
allConstraints = Composite.allConstraints(world),
6528+
background = options.wireframes ? options.wireframeBackground : options.background,
65476529
bodies = [],
65486530
constraints = [],
65496531
i;
65506532

6551-
if (options.wireframes) {
6552-
Render.setBackground(render, options.wireframeBackground);
6553-
} else {
6554-
Render.setBackground(render, options.background);
6555-
}
6533+
// apply background if it has changed
6534+
if (render.currentBackground !== background)
6535+
_applyBackground(render, background);
65566536

65576537
// clear the canvas with a transparent fill, to allow the canvas background to show
65586538
context.globalCompositeOperation = 'source-in';
@@ -7321,6 +7301,24 @@ var Render = {};
73217301
return image;
73227302
};
73237303

7304+
/**
7305+
* Applies the background to the canvas using CSS.
7306+
* @method applyBackground
7307+
* @private
7308+
* @param {render} render
7309+
* @param {string} background
7310+
*/
7311+
var _applyBackground = function(render, background) {
7312+
var cssBackground = background;
7313+
7314+
if (/(jpg|gif|png)$/.test(background))
7315+
cssBackground = 'url(' + background + ')';
7316+
7317+
render.canvas.style.background = cssBackground;
7318+
render.canvas.style.backgroundSize = "contain";
7319+
render.currentBackground = background;
7320+
};
7321+
73247322
/*
73257323
*
73267324
* Properties Documentation

0 commit comments

Comments
 (0)