mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-11 16:18:10 +00:00
core/Window: implement getActualFrameRate, update monitorFramePeriod accordingly
This commit is contained in:
parent
523dc2d006
commit
5408f4c2dd
@ -41,7 +41,7 @@ export class Window extends PsychObject
|
||||
*/
|
||||
get monitorFramePeriod()
|
||||
{
|
||||
return this._monitorFramePeriod;
|
||||
return 1.0 / this.getActualFrameRate();
|
||||
}
|
||||
|
||||
constructor({
|
||||
@ -69,9 +69,6 @@ export class Window extends PsychObject
|
||||
// setup PIXI:
|
||||
this._setupPixi();
|
||||
|
||||
// monitor frame period:
|
||||
this._monitorFramePeriod = 1.0 / this.getActualFrameRate();
|
||||
|
||||
this._frameCount = 0;
|
||||
|
||||
this._flipCallbacks = [];
|
||||
@ -145,14 +142,18 @@ export class Window extends PsychObject
|
||||
* @name module:core.Window#getActualFrameRate
|
||||
* @function
|
||||
* @public
|
||||
* @return {number} always returns 60.0 at the moment
|
||||
*
|
||||
* @todo estimate the actual frame rate.
|
||||
* @return {number} rAF based delta time based approximation, 60.0 by default
|
||||
*/
|
||||
getActualFrameRate()
|
||||
{
|
||||
// TODO
|
||||
return 60.0;
|
||||
// gets updated frame by frame
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user