-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6712b1d
commit 1c3528c
Showing
3 changed files
with
45 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import destroyObject from "../Core/destroyObject.js"; | ||
import getTimestamp from "../Core/getTimestamp.js"; | ||
|
||
/** | ||
* @private | ||
*/ | ||
function FpsTracker(options) { | ||
this._timeStamps = []; | ||
} | ||
|
||
/** | ||
* Calculates average fps based on timeStamps of recently rendered frames | ||
*/ | ||
FpsTracker.prototype.getAverageFps = function () { | ||
if (this._timeStamps.length !== 10) { | ||
return; | ||
} | ||
const elapsedTime = (this._timeStamps[0] - this._timeStamps[9]) / 9; | ||
const fps = 1 / (elapsedTime / 1000); | ||
return fps; | ||
}; | ||
|
||
/** | ||
* Adds the timestamp for the current frame to the queue | ||
*/ | ||
FpsTracker.prototype.updateFrameTimeStamp = function () { | ||
const time = getTimestamp(); | ||
this._timeStamps.unshift(time); | ||
if (this._timeStamps.length > 10) { | ||
this._timeStamps.pop(); | ||
} | ||
}; | ||
|
||
/** | ||
* Destroys the WebGL resources held by this object. | ||
*/ | ||
FpsTracker.prototype.destroy = function () { | ||
return destroyObject(this); | ||
}; | ||
export default FpsTracker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters