mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-23 09:26:51 -05:00
Added substeps feature to Matter.Runner
This commit is contained in:
parent
d7e4f585b7
commit
516494e3df
1 changed files with 21 additions and 3 deletions
|
@ -52,6 +52,7 @@ var Common = require('./Common');
|
|||
*/
|
||||
Runner.create = function(options) {
|
||||
var defaults = {
|
||||
substeps: 1,
|
||||
fps: 60,
|
||||
deltaSampleSize: 60,
|
||||
counterTimestamp: 0,
|
||||
|
@ -85,8 +86,8 @@ var Common = require('./Common');
|
|||
runner = Runner.create();
|
||||
}
|
||||
|
||||
(function render(time){
|
||||
runner.frameRequestId = _requestAnimationFrame(render);
|
||||
(function run(time){
|
||||
runner.frameRequestId = _requestAnimationFrame(run);
|
||||
|
||||
if (time && runner.enabled) {
|
||||
Runner.tick(runner, engine, time);
|
||||
|
@ -160,7 +161,14 @@ var Common = require('./Common');
|
|||
|
||||
// update
|
||||
Events.trigger(runner, 'beforeUpdate', event);
|
||||
Engine.update(engine, delta, correction);
|
||||
|
||||
var substeps = runner.substeps,
|
||||
subDelta = delta / substeps;
|
||||
|
||||
for (var i = 0; i < substeps; i += 1) {
|
||||
Engine.update(engine, subDelta);
|
||||
}
|
||||
|
||||
Events.trigger(runner, 'afterUpdate', event);
|
||||
|
||||
// render
|
||||
|
@ -291,6 +299,16 @@ var Common = require('./Common');
|
|||
* @default true
|
||||
*/
|
||||
|
||||
/**
|
||||
* A `Number` integer that specifies the number of `Engine.update` calls made per-tick.
|
||||
* Increasing the number of substeps improves accuracy at the cost of performance.
|
||||
* By default `1` update is performed per tick with time `delta`.
|
||||
* If `substeps > 1` then `substeps` updates are made with `delta` being `delta / substeps`.
|
||||
* @property substeps
|
||||
* @type number
|
||||
* @default 1
|
||||
*/
|
||||
|
||||
/**
|
||||
* A `Boolean` that specifies if the runner should use a fixed timestep (otherwise it is variable).
|
||||
* If timing is fixed, then the apparent simulation speed will change depending on the frame rate (but behaviour will be deterministic).
|
||||
|
|
Loading…
Reference in a new issue