mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
added lastDelta and lastElapsed to engine.timing
This commit is contained in:
parent
081645474c
commit
6dc703f9a9
1 changed files with 9 additions and 1 deletions
|
@ -54,7 +54,9 @@ var Body = require('../body/Body');
|
||||||
plugin: {},
|
plugin: {},
|
||||||
timing: {
|
timing: {
|
||||||
timestamp: 0,
|
timestamp: 0,
|
||||||
timeScale: 1
|
timeScale: 1,
|
||||||
|
lastDelta: 0,
|
||||||
|
lastElapsed: 0
|
||||||
},
|
},
|
||||||
broadphase: {
|
broadphase: {
|
||||||
controller: Grid
|
controller: Grid
|
||||||
|
@ -111,6 +113,8 @@ var Body = require('../body/Body');
|
||||||
* @param {number} [correction=1]
|
* @param {number} [correction=1]
|
||||||
*/
|
*/
|
||||||
Engine.update = function(engine, delta, correction) {
|
Engine.update = function(engine, delta, correction) {
|
||||||
|
var startTime = Common.now();
|
||||||
|
|
||||||
delta = delta || 1000 / 60;
|
delta = delta || 1000 / 60;
|
||||||
correction = correction || 1;
|
correction = correction || 1;
|
||||||
|
|
||||||
|
@ -122,6 +126,7 @@ var Body = require('../body/Body');
|
||||||
|
|
||||||
// increment timestamp
|
// increment timestamp
|
||||||
timing.timestamp += delta * timing.timeScale;
|
timing.timestamp += delta * timing.timeScale;
|
||||||
|
timing.lastDelta = delta * timing.timeScale;
|
||||||
|
|
||||||
// create an event object
|
// create an event object
|
||||||
var event = {
|
var event = {
|
||||||
|
@ -229,6 +234,9 @@ var Body = require('../body/Body');
|
||||||
|
|
||||||
Events.trigger(engine, 'afterUpdate', event);
|
Events.trigger(engine, 'afterUpdate', event);
|
||||||
|
|
||||||
|
// log the time elapsed computing this update
|
||||||
|
engine.timing.lastElapsed = Common.now() - startTime;
|
||||||
|
|
||||||
return engine;
|
return engine;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue