Skip to content

Commit 6e302a8

Browse files
committed
improve Matter.Runner docs
1 parent 2c91e74 commit 6e302a8

1 file changed

Lines changed: 31 additions & 30 deletions

File tree

src/core/Runner.js

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ var Common = require('./Common');
6868
* This runner favours a smoother user experience over perfect time keeping.
6969
* The number of updates per frame is kept within limits specified by `runner.maxFrameTime`, `runner.maxUpdates` and `runner.maxFrameDelta`.
7070
* When device performance is too limited the simulation may appear to slow down compared to real time.
71-
* As an alternative, to directly step the engine in your own game loop implementation, see `Engine.update`.
71+
* As an alternative see `Engine.update` to directly step the engine in your own game loop implementation.
7272
* @method run
7373
* @param {runner} runner
7474
* @param {engine} [engine]
@@ -92,7 +92,7 @@ var Common = require('./Common');
9292
/**
9393
* Used by the game loop inside `Runner.run`.
9494
*
95-
* As an alternative to directly step the engine in your own game loop implementation, see `Engine.update`.
95+
* As an alternative see `Engine.update` to directly step the engine in your own game loop implementation.
9696
* @method tick
9797
* @param {runner} runner
9898
* @param {engine} engine
@@ -218,7 +218,7 @@ var Common = require('./Common');
218218
/**
219219
* Ends execution of `Runner.run` on the given `runner`, by canceling the frame loop.
220220
*
221-
* To temporarily pause the runner, see `runner.enabled`.
221+
* Alternatively to temporarily pause the runner, see `runner.enabled`.
222222
* @method stop
223223
* @param {runner} runner
224224
*/
@@ -227,7 +227,7 @@ var Common = require('./Common');
227227
};
228228

229229
/**
230-
* Schedules a `callback` on this `runner` for the next animation frame.
230+
* Schedules `callback` on this `runner` for the next animation frame.
231231
* @private
232232
* @method _onNextFrame
233233
* @param {runner} runner
@@ -343,37 +343,37 @@ var Common = require('./Common');
343343
/**
344344
* The fixed timestep size used for `Engine.update` calls in milliseconds.
345345
*
346-
* This `delta` value is recommended to be `16.666` ms or lower (equivalent to at least 60hz).
346+
* This `delta` value is recommended to be `1000 / 60` ms or smaller (i.e. equivalent to at least 60hz).
347347
*
348-
* Lower `delta` values provide a higher quality results at the cost of performance.
348+
* Smaller `delta` values provide higher quality results at the cost of performance.
349349
*
350-
* This value should be held fixed during running, otherwise quality may be affected.
350+
* You should avoid changing `delta` during running, otherwise quality may be affected.
351351
*
352-
* For smoothest results choose an evenly divisible factor of your target framerates, this helps provide an equal number of updates per frame.
352+
* For smoothest results choose a `delta` using an integer multiple of display FPS, i.e. `1000 / (n * fps)` as this helps distribute an equal number of updates over each display frame.
353353
*
354-
* Rounding to the nearest 1 Hz is recommended for smoother results (see `runner.frameDeltaSnapping`).
354+
* For example with a 60 Hz `delta` i.e. `1000 / 60` the runner will on average perform one update per frame on displays running 60 FPS, or one update every two frames on displays running 120 FPS, etc.
355355
*
356-
* For example with a `delta` of `1000 / 60` the runner will on average perform one update per frame for displays at 60 FPS, or one update every two frames for displays at 120 FPS.
356+
* Where as e.g. using a 240 Hz `delta` i.e. `1000 / 240` the runner will on average perform four updates per frame on displays running 60 FPS, or two updates per frame on displays running 120 FPS, etc.
357357
*
358-
* `Runner.run` will call multiple engine updates to simulate the time elapsed between frames, but the number of allowed calls may be limited by the runner's performance budgets.
358+
* Therefore note that `Runner.run` can call multiple engine updates to simulate the time elapsed between frames, but the number of actual updates in any particular frame may be restricted by the runner's performance budgets.
359+
*
360+
* These performance budgets are specified by `runner.maxFrameTime` and `runner.maxUpdates`. See those properties for details.
359361
*
360-
* These performance budgets are specified by `runner.maxFrameTime`, `runner.maxUpdates`, `runner.maxFrameDelta`. See those properties for details.
361-
*
362362
* @property delta
363363
* @type number
364364
* @default 1000 / 60
365365
*/
366366

367367
/**
368-
* A flag that can be toggled to enable or disable tick calls on this runner, therefore pausing engine updates while the loop remains running.
368+
* A flag that can be toggled to enable or disable tick calls on this runner, therefore pausing engine updates while the runner loop remains running.
369369
*
370370
* @property enabled
371371
* @type boolean
372372
* @default true
373373
*/
374374

375375
/**
376-
* The accumulated time elapsed that has yet to be simulated, in milliseconds.
376+
* The accumulated time elapsed that has yet to be simulated in milliseconds.
377377
* This value is clamped within some limits (see `Runner.tick` code).
378378
*
379379
* @private
@@ -383,51 +383,53 @@ var Common = require('./Common');
383383
*/
384384

385385
/**
386-
* The measured time elapsed between the last two browser frames in milliseconds.
386+
* The measured time elapsed between the last two browser frames measured in milliseconds.
387387
* This value is clamped inside `runner.maxFrameDelta`.
388388
*
389-
* You may use this to estimate the browser FPS (for the current instant) whilst running use `1000 / runner.frameDelta`.
389+
* You may use this to estimate the browser FPS (for the current frame) whilst running as `1000 / runner.frameDelta`.
390390
*
391391
* @readonly
392392
* @property frameDelta
393393
* @type number
394394
*/
395395

396396
/**
397-
* This option applies averaging to the frame delta to smooth noisy frame rates.
397+
* Applies averaging to smooth frame rate measurements and therefore stabilise play rate.
398398
*
399399
* @property frameDeltaSmoothing
400400
* @type boolean
401401
* @default true
402402
*/
403403

404404
/**
405-
* Rounds frame delta to the nearest 1 Hz.
406-
* It follows that your choice of `runner.delta` should be rounded to the nearest 1 Hz for best results.
407-
* This option helps smooth noisy refresh rates and simplify hardware differences e.g. 59.94Hz vs 60Hz display refresh rates.
405+
* Rounds measured frame delta to the nearest 1 Hz.
406+
* Your choice of `runner.delta` should be rounded to the nearest 1 Hz for best results.
407+
* This option helps smooth frame rate measurements and unify display hardware differences e.g. 59.94Hz vs 60Hz refresh rates.
408408
*
409409
* @property frameDeltaSnapping
410410
* @type boolean
411411
* @default true
412412
*/
413413

414414
/**
415-
* Clamps the maximum `runner.frameDelta` in milliseconds.
416-
* This is to avoid simulating periods where the browser thread is paused e.g. whilst minimised.
415+
* Clamps the maximum measured `runner.frameDelta` in milliseconds.
416+
* Therefore avoids simulating long periods measured between frames e.g. periods the thread is frozen whilst the browser has been minimised.
417417
*
418418
* @property maxFrameDelta
419419
* @type number
420420
* @default 500
421421
*/
422422

423423
/**
424-
* The runner will attempt to limit engine update rate should the browser frame rate drop below a set level (50 FPS using the default `runner.maxFrameTime` value `1000 / 50` milliseconds).
424+
* A performance budget that limits execution time allowed for this runner per display frame in milliseconds.
425+
*
426+
* To calculate the display FPS at which this throttle is applied use `1000 / maxFrameTime`.
425427
*
426-
* This budget is intended to help maintain browser interactivity and help improve framerate recovery during temporary high CPU spikes.
428+
* This performance budget is intended to help maintain browser interactivity and help improve framerate recovery during temporary high CPU usage.
427429
*
428-
* It will only cover time elapsed whilst executing the functions called in the scope of this runner, including `Engine.update` etc. and its related event callbacks.
430+
* This only covers the measured time elapsed executing the functions called in the scope of the runner tick, including `Engine.update` etc. and its related user event callbacks.
429431
*
430-
* For any significant additional processing you perform on the same thread but outside the scope of this runner e.g. rendering time, you may wish to reduce this budget.
432+
* You may wish to reduce this budget to allow for any significant additional processing you perform on the same thread outside the scope of this runner, e.g. rendering time.
431433
*
432434
* See also `runner.maxUpdates`.
433435
*
@@ -437,10 +439,9 @@ var Common = require('./Common');
437439
*/
438440

439441
/**
440-
* A hard limit for maximum engine updates allowed per frame.
442+
* An optional hard limit for maximum engine updates allowed per frame tick in addition to `runner.maxFrameTime`.
441443
*
442-
* If not provided, it is automatically set by `Runner.create` based on `runner.delta` and `runner.maxFrameTime`.
443-
* If you change `runner.delta` or `runner.maxFrameTime`, you may need to manually update this value afterwards.
444+
* Unless you set a value it is automatically chosen based on `runner.delta` and `runner.maxFrameTime`.
444445
*
445446
* See also `runner.maxFrameTime`.
446447
*

0 commit comments

Comments
 (0)