FPS update

This commit is contained in:
Bill 2021-06-10 03:02:26 -04:00
parent 56ef76361b
commit c56f0d86c1
2 changed files with 49 additions and 34 deletions

View File

@ -221,7 +221,7 @@ export class Nitro extends Application implements INitro
const animationFPS = this.getConfiguration<number>('animation.fps', 24);
const limitsFPS = this.getConfiguration<boolean>('limits.fps', true);
Nitro.instance.ticker.maxFPS = animationFPS;
if(limitsFPS) Nitro.instance.ticker.maxFPS = animationFPS;
}
private onRoomEngineReady(event: RoomEngineEvent): void

View File

@ -26,7 +26,10 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
private _container: IRoomSpriteCanvasContainer;
private _geometry: RoomGeometry;
private _animationFPS: number;
private _renderTimestamp: number;
private _totalTimeRunning: number;
private _lastFrame: number;
private _master: Sprite;
private _display: Container;
@ -71,7 +74,10 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
this._container = container;
this._geometry = new RoomGeometry(scale, new Vector3d(-135, 30, 0), new Vector3d(11, 11, 5), new Vector3d(-135, 0.5, 0));
this._animationFPS = Nitro.instance.getConfiguration<number>('animation.fps', 24);
this._renderTimestamp = 0;
this._totalTimeRunning = 0;
this._lastFrame = 0;
this._master = null;
this._display = null;
@ -321,12 +327,14 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
{
this._canvasUpdated = false;
this._totalTimeRunning += Nitro.instance.ticker.deltaTime;
if(this._totalTimeRunning === this._renderTimestamp) return;
if(time === -1) time = (this._renderTimestamp + 1);
if(!this._container || !this._geometry) return;
if(time === this._renderTimestamp) return;
if((this._width !== this._renderedWidth) || (this._height !== this._renderedHeight)) update = true;
if((this._display.x !== this._screenOffsetX) || (this._display.y !== this._screenOffsetY))
@ -344,6 +352,12 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
update = true;
}
const frame = Math.round(this._totalTimeRunning / (60 / this._animationFPS));
if(frame !== this._lastFrame)
{
this._lastFrame = frame;
let spriteCount = 0;
const objects = this._container.objects;
@ -380,10 +394,11 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
}
this._Str_20677(spriteCount);
}
if(update) this._canvasUpdated = true;
this._renderTimestamp = time;
this._renderTimestamp = this._totalTimeRunning;
this._renderedWidth = this._width;
this._renderedHeight = this._height;
}