0ad/binaries/data/mods/public/gui/common/OverlayCounterFPS.js
elexis 38e06fce7e Rewrite FPS/Realtime/Gametime/Ceasefire counters to use object semantics using class notation, refs #5387.
Rebuild the counters every 250ms instead of every frame and minimize
object creation.

Differential Revision: https://code.wildfiregames.com/D2391
Comments By: Stan
This was SVN commit r23096.
2019-10-27 12:39:28 +00:00

32 lines
776 B
JavaScript

/**
* This counter displays the current framerate in the screen corner.
*/
OverlayCounterTypes.prototype.FPS = class extends OverlayCounter
{
constructor(overlayCounterManager)
{
super(overlayCounterManager);
// Tiny performance improvement
this.caption = translate(this.Caption);
// Minimize object construction
this.fpsObject = {};
}
/**
* This function is called frequently and thus minimized.
*/
get()
{
this.fpsObject.fps = Engine.GetFPS();
return sprintf(this.caption, this.fpsObject);
}
};
// dennis-ignore: *
OverlayCounterTypes.prototype.FPS.prototype.Caption = markForTranslation("FPS: %(fps)4s");
OverlayCounterTypes.prototype.FPS.prototype.Config = "overlay.fps";
OverlayCounterTypes.prototype.FPS.prototype.Hotkey = "fps.toggle";