1
0
mirror of https://github.com/psychopy/psychojs.git synced 2025-05-12 08:38:10 +00:00

core/Window: implement getActualFrameRate, update monitorFramePeriod accordingly

This commit is contained in:
Sotiri Bakagiannis 2021-01-29 12:07:27 +00:00
parent 523dc2d006
commit 5408f4c2dd

View File

@ -41,7 +41,7 @@ export class Window extends PsychObject
*/ */
get monitorFramePeriod() get monitorFramePeriod()
{ {
return this._monitorFramePeriod; return 1.0 / this.getActualFrameRate();
} }
constructor({ constructor({
@ -69,9 +69,6 @@ export class Window extends PsychObject
// setup PIXI: // setup PIXI:
this._setupPixi(); this._setupPixi();
// monitor frame period:
this._monitorFramePeriod = 1.0 / this.getActualFrameRate();
this._frameCount = 0; this._frameCount = 0;
this._flipCallbacks = []; this._flipCallbacks = [];
@ -145,14 +142,18 @@ export class Window extends PsychObject
* @name module:core.Window#getActualFrameRate * @name module:core.Window#getActualFrameRate
* @function * @function
* @public * @public
* @return {number} always returns 60.0 at the moment * @return {number} rAF based delta time based approximation, 60.0 by default
*
* @todo estimate the actual frame rate.
*/ */
getActualFrameRate() getActualFrameRate()
{ {
// TODO // gets updated frame by frame
return 60.0; const lastDelta = this.psychoJS.scheduler._lastDelta;
const fpsMaybe = 1000 / lastDelta;
// NB: calling `Number.isFinite()` might skip the implicit to number conversion, but
// would also need polyfilling for IE
const fps = isFinite(fpsMaybe) ? fpsMaybe : 60.0;
return fps;
} }