mirror of
https://github.com/liabru/matter-js.git
synced 2025-03-08 23:03:36 -05:00
added engine.timing.isFixed option
This commit is contained in:
parent
a77a5fc626
commit
bc35c93106
1 changed files with 20 additions and 13 deletions
|
@ -48,7 +48,8 @@ var Engine = {};
|
||||||
correction: 1,
|
correction: 1,
|
||||||
deltaMin: 1000 / _fps,
|
deltaMin: 1000 / _fps,
|
||||||
deltaMax: 1000 / (_fps * 0.5),
|
deltaMax: 1000 / (_fps * 0.5),
|
||||||
timeScale: 1
|
timeScale: 1,
|
||||||
|
isFixed: false
|
||||||
},
|
},
|
||||||
render: {
|
render: {
|
||||||
element: element,
|
element: element,
|
||||||
|
@ -87,7 +88,7 @@ var Engine = {};
|
||||||
Engine.run = function(engine) {
|
Engine.run = function(engine) {
|
||||||
var timing = engine.timing,
|
var timing = engine.timing,
|
||||||
delta,
|
delta,
|
||||||
correction,
|
correction = 1,
|
||||||
counterTimestamp = 0,
|
counterTimestamp = 0,
|
||||||
frameCounter = 0,
|
frameCounter = 0,
|
||||||
deltaHistory = [],
|
deltaHistory = [],
|
||||||
|
@ -109,19 +110,25 @@ var Engine = {};
|
||||||
|
|
||||||
Events.trigger(engine, 'beforeTick', event);
|
Events.trigger(engine, 'beforeTick', event);
|
||||||
|
|
||||||
delta = (timestamp - timing.timestamp) || _delta;
|
if (timing.isFixed) {
|
||||||
|
// fixed timestep
|
||||||
|
delta = timing.delta;
|
||||||
|
} else {
|
||||||
|
// dynamic timestep
|
||||||
|
delta = (timestamp - timing.timestamp) || _delta;
|
||||||
|
|
||||||
// optimistically filter delta over a few frames, to improve stability
|
// optimistically filter delta over a few frames, to improve stability
|
||||||
deltaHistory.push(delta);
|
deltaHistory.push(delta);
|
||||||
deltaHistory = deltaHistory.slice(-_deltaSampleSize);
|
deltaHistory = deltaHistory.slice(-_deltaSampleSize);
|
||||||
delta = Math.min.apply(null, deltaHistory);
|
delta = Math.min.apply(null, deltaHistory);
|
||||||
|
|
||||||
// limit delta
|
// limit delta
|
||||||
delta = delta < timing.deltaMin ? timing.deltaMin : delta;
|
delta = delta < timing.deltaMin ? timing.deltaMin : delta;
|
||||||
delta = delta > timing.deltaMax ? timing.deltaMax : delta;
|
delta = delta > timing.deltaMax ? timing.deltaMax : delta;
|
||||||
|
|
||||||
// time correction for delta
|
// time correction for delta
|
||||||
correction = delta / timing.delta;
|
correction = delta / timing.delta;
|
||||||
|
}
|
||||||
|
|
||||||
// time correction for time scaling
|
// time correction for time scaling
|
||||||
if (timeScalePrev !== 0)
|
if (timeScalePrev !== 0)
|
||||||
|
|
Loading…
Add table
Reference in a new issue