Fix FPS issue

This commit is contained in:
Bill 2022-11-09 17:05:12 -05:00
parent 3086a8446f
commit 7f0164c176
10 changed files with 28 additions and 43 deletions

View File

@ -1,5 +1,4 @@
import { Application } from '@pixi/app'; import { Application } from '@pixi/app';
import { Ticker } from '@pixi/ticker';
import { IAvatarRenderManager, IEventDispatcher, ILinkEventTracker, INitroCommunicationManager, INitroCore, INitroLocalizationManager, IRoomCameraWidgetManager, IRoomEngine, IRoomManager, IRoomSessionManager, ISessionDataManager, ISoundManager, IWorkerEventTracker } from '../api'; import { IAvatarRenderManager, IEventDispatcher, ILinkEventTracker, INitroCommunicationManager, INitroCore, INitroLocalizationManager, IRoomCameraWidgetManager, IRoomEngine, IRoomManager, IRoomSessionManager, ISessionDataManager, ISoundManager, IWorkerEventTracker } from '../api';
export interface INitro export interface INitro
@ -32,8 +31,6 @@ export interface INitro
soundManager: ISoundManager; soundManager: ISoundManager;
width: number; width: number;
height: number; height: number;
ticker: Ticker;
time: number;
isReady: boolean; isReady: boolean;
isDisposed: boolean; isDisposed: boolean;
} }

View File

@ -1,11 +1,10 @@
import { Application, IApplicationOptions } from '@pixi/app'; import { Application, IApplicationOptions } from '@pixi/app';
import { SCALE_MODES } from '@pixi/constants'; import { SCALE_MODES } from '@pixi/constants';
import { settings } from '@pixi/settings'; import { settings } from '@pixi/settings';
import { Ticker } from '@pixi/ticker';
import { IAvatarRenderManager, IEventDispatcher, ILinkEventTracker, INitroCommunicationManager, INitroCore, INitroLocalizationManager, IRoomCameraWidgetManager, IRoomEngine, IRoomManager, IRoomSessionManager, ISessionDataManager, ISoundManager, IWorkerEventTracker, NitroConfiguration } from '../api'; import { IAvatarRenderManager, IEventDispatcher, ILinkEventTracker, INitroCommunicationManager, INitroCore, INitroLocalizationManager, IRoomCameraWidgetManager, IRoomEngine, IRoomManager, IRoomSessionManager, ISessionDataManager, ISoundManager, IWorkerEventTracker, NitroConfiguration } from '../api';
import { ConfigurationEvent, EventDispatcher, NitroCore } from '../core'; import { ConfigurationEvent, EventDispatcher, NitroCore } from '../core';
import { NitroEvent, RoomEngineEvent } from '../events'; import { NitroEvent, RoomEngineEvent } from '../events';
import { PixiApplicationProxy } from '../pixi-proxy'; import { GetTicker, PixiApplicationProxy } from '../pixi-proxy';
import { RoomManager } from '../room'; import { RoomManager } from '../room';
import { AvatarRenderManager } from './avatar'; import { AvatarRenderManager } from './avatar';
import { RoomCameraWidgetManager } from './camera'; import { RoomCameraWidgetManager } from './camera';
@ -200,9 +199,9 @@ export class Nitro implements INitro
private onConfigurationLoadedEvent(event: ConfigurationEvent): void private onConfigurationLoadedEvent(event: ConfigurationEvent): void
{ {
const animationFPS = NitroConfiguration.getValue<number>('system.animation.fps', 24); const animationFPS = NitroConfiguration.getValue<number>('system.animation.fps', 24);
const limitsFPS = NitroConfiguration.getValue<boolean>('system.limits.fps', true); const limitsFPS = NitroConfiguration.getValue<boolean>('system.limits.fps', false);
if(limitsFPS) Nitro.instance.ticker.maxFPS = animationFPS; if(limitsFPS) GetTicker().maxFPS = animationFPS;
} }
private onRoomEngineReady(event: RoomEngineEvent): void private onRoomEngineReady(event: RoomEngineEvent): void
@ -392,16 +391,6 @@ export class Nitro implements INitro
return this._application.renderer.height; return this._application.renderer.height;
} }
public get ticker(): Ticker
{
return Ticker.shared;
}
public get time(): number
{
return this.ticker.lastTime;
}
public get isReady(): boolean public get isReady(): boolean
{ {
return this._isReady; return this._isReady;

View File

@ -4,11 +4,10 @@ import { Matrix, Point, Rectangle } from '@pixi/math';
import { IConnection, IDisposable, IFurnitureStackingHeightMap, IGetImageListener, IImageResult, ILegacyWallGeometry, IMessageComposer, INitroCommunicationManager, INitroEvent, IObjectData, IPetColorResult, IPetCustomPart, IRoomContentListener, IRoomContentLoader, IRoomCreator, IRoomEngine, IRoomEngineServices, IRoomGeometry, IRoomInstance, IRoomManager, IRoomManagerListener, IRoomObject, IRoomObjectController, IRoomObjectLogicFactory, IRoomObjectVisualizationFactory, IRoomRenderer, IRoomRendererFactory, IRoomRenderingCanvas, IRoomSessionManager, ISelectedRoomObjectData, ISessionDataManager, ITileObjectMap, IUpdateReceiver, IVector3D, LegacyDataType, MouseEventType, NitroConfiguration, NitroLogger, ObjectDataFactory, RoomControllerLevel, RoomObjectCategory, RoomObjectUserType, RoomObjectVariable, ToolbarIconEnum, Vector3d } from '../../api'; import { IConnection, IDisposable, IFurnitureStackingHeightMap, IGetImageListener, IImageResult, ILegacyWallGeometry, IMessageComposer, INitroCommunicationManager, INitroEvent, IObjectData, IPetColorResult, IPetCustomPart, IRoomContentListener, IRoomContentLoader, IRoomCreator, IRoomEngine, IRoomEngineServices, IRoomGeometry, IRoomInstance, IRoomManager, IRoomManagerListener, IRoomObject, IRoomObjectController, IRoomObjectLogicFactory, IRoomObjectVisualizationFactory, IRoomRenderer, IRoomRendererFactory, IRoomRenderingCanvas, IRoomSessionManager, ISelectedRoomObjectData, ISessionDataManager, ITileObjectMap, IUpdateReceiver, IVector3D, LegacyDataType, MouseEventType, NitroConfiguration, NitroLogger, ObjectDataFactory, RoomControllerLevel, RoomObjectCategory, RoomObjectUserType, RoomObjectVariable, ToolbarIconEnum, Vector3d } from '../../api';
import { NitroManager } from '../../core'; import { NitroManager } from '../../core';
import { BadgeImageReadyEvent, NitroToolbarAnimateIconEvent, RoomBackgroundColorEvent, RoomDragEvent, RoomEngineEvent, RoomEngineObjectEvent, RoomObjectFurnitureActionEvent, RoomSessionEvent, RoomToObjectOwnAvatarMoveEvent } from '../../events'; import { BadgeImageReadyEvent, NitroToolbarAnimateIconEvent, RoomBackgroundColorEvent, RoomDragEvent, RoomEngineEvent, RoomEngineObjectEvent, RoomObjectFurnitureActionEvent, RoomSessionEvent, RoomToObjectOwnAvatarMoveEvent } from '../../events';
import { GetTickerTime, NitroSprite, TextureUtils } from '../../pixi-proxy'; import { GetTicker, GetTickerTime, NitroSprite, TextureUtils } from '../../pixi-proxy';
import { NumberBank, RoomEnterEffect, RoomGeometry, RoomInstance, RoomObjectEvent, RoomObjectMouseEvent, RoomObjectUpdateMessage, RoomRendererFactory } from '../../room'; import { NumberBank, RoomEnterEffect, RoomGeometry, RoomInstance, RoomObjectEvent, RoomObjectMouseEvent, RoomObjectUpdateMessage, RoomRendererFactory } from '../../room';
import { PetFigureData } from '../avatar'; import { PetFigureData } from '../avatar';
import { RenderRoomMessageComposer, RenderRoomThumbnailMessageComposer } from '../communication'; import { RenderRoomMessageComposer, RenderRoomThumbnailMessageComposer } from '../communication';
import { Nitro } from '../Nitro';
import { FurniId } from '../utils'; import { FurniId } from '../utils';
import { ImageResult } from './ImageResult'; import { ImageResult } from './ImageResult';
import { ObjectAvatarCarryObjectUpdateMessage, ObjectAvatarChatUpdateMessage, ObjectAvatarDanceUpdateMessage, ObjectAvatarEffectUpdateMessage, ObjectAvatarExperienceUpdateMessage, ObjectAvatarExpressionUpdateMessage, ObjectAvatarFigureUpdateMessage, ObjectAvatarFlatControlUpdateMessage, ObjectAvatarGestureUpdateMessage, ObjectAvatarGuideStatusUpdateMessage, ObjectAvatarMutedUpdateMessage, ObjectAvatarOwnMessage, ObjectAvatarPetGestureUpdateMessage, ObjectAvatarPlayerValueUpdateMessage, ObjectAvatarPlayingGameUpdateMessage, ObjectAvatarPostureUpdateMessage, ObjectAvatarSignUpdateMessage, ObjectAvatarSleepUpdateMessage, ObjectAvatarTypingUpdateMessage, ObjectAvatarUpdateMessage, ObjectAvatarUseObjectUpdateMessage, ObjectDataUpdateMessage, ObjectGroupBadgeUpdateMessage, ObjectHeightUpdateMessage, ObjectItemDataUpdateMessage, ObjectModelDataUpdateMessage, ObjectMoveUpdateMessage, ObjectRoomColorUpdateMessage, ObjectRoomFloorHoleUpdateMessage, ObjectRoomMaskUpdateMessage, ObjectRoomPlanePropertyUpdateMessage, ObjectRoomPlaneVisibilityUpdateMessage, ObjectRoomUpdateMessage, ObjectStateUpdateMessage } from './messages'; import { ObjectAvatarCarryObjectUpdateMessage, ObjectAvatarChatUpdateMessage, ObjectAvatarDanceUpdateMessage, ObjectAvatarEffectUpdateMessage, ObjectAvatarExperienceUpdateMessage, ObjectAvatarExpressionUpdateMessage, ObjectAvatarFigureUpdateMessage, ObjectAvatarFlatControlUpdateMessage, ObjectAvatarGestureUpdateMessage, ObjectAvatarGuideStatusUpdateMessage, ObjectAvatarMutedUpdateMessage, ObjectAvatarOwnMessage, ObjectAvatarPetGestureUpdateMessage, ObjectAvatarPlayerValueUpdateMessage, ObjectAvatarPlayingGameUpdateMessage, ObjectAvatarPostureUpdateMessage, ObjectAvatarSignUpdateMessage, ObjectAvatarSleepUpdateMessage, ObjectAvatarTypingUpdateMessage, ObjectAvatarUpdateMessage, ObjectAvatarUseObjectUpdateMessage, ObjectDataUpdateMessage, ObjectGroupBadgeUpdateMessage, ObjectHeightUpdateMessage, ObjectItemDataUpdateMessage, ObjectModelDataUpdateMessage, ObjectMoveUpdateMessage, ObjectRoomColorUpdateMessage, ObjectRoomFloorHoleUpdateMessage, ObjectRoomMaskUpdateMessage, ObjectRoomPlanePropertyUpdateMessage, ObjectRoomPlaneVisibilityUpdateMessage, ObjectRoomUpdateMessage, ObjectStateUpdateMessage } from './messages';
@ -151,7 +150,7 @@ export class RoomEngine extends NitroManager implements IRoomEngine, IRoomCreato
this.events.addEventListener(RoomContentLoader.LOADER_READY, this.onRoomContentLoaderReadyEvent); this.events.addEventListener(RoomContentLoader.LOADER_READY, this.onRoomContentLoaderReadyEvent);
Nitro.instance.ticker.add(this.update, this); GetTicker().add(this.update, this);
document.addEventListener('visibilitychange', this.runVisibilityUpdate); document.addEventListener('visibilitychange', this.runVisibilityUpdate);
} }
@ -167,7 +166,7 @@ export class RoomEngine extends NitroManager implements IRoomEngine, IRoomCreato
document.removeEventListener('visibilitychange', this.runVisibilityUpdate); document.removeEventListener('visibilitychange', this.runVisibilityUpdate);
Nitro.instance.ticker.remove(this.update, this); GetTicker().remove(this.update, this);
if(this._roomObjectEventHandler) this._roomObjectEventHandler.dispose(); if(this._roomObjectEventHandler) this._roomObjectEventHandler.dispose();
@ -787,12 +786,12 @@ export class RoomEngine extends NitroManager implements IRoomEngine, IRoomCreato
{ {
if(flag) if(flag)
{ {
Nitro.instance.ticker.remove(this.update, this); GetTicker().remove(this.update, this);
} }
else else
{ {
Nitro.instance.ticker.remove(this.update, this); GetTicker().remove(this.update, this);
Nitro.instance.ticker.add(this.update, this); GetTicker().add(this.update, this);
} }
} }

View File

@ -135,8 +135,8 @@ export class LandscapeRasterizer extends PlaneRasterizer
const assetId = item.assetId; const assetId = item.assetId;
const x = this.getCoordinateValue(item.x || '', item.randomX || ''); const x = this.getCoordinateValue(item.x || '', item.randomX || '');
const y = this.getCoordinateValue(item.y || '', item.randomY || ''); const y = this.getCoordinateValue(item.y || '', item.randomY || '');
const speedX = item.speedX ? item.speedX / NitroConfiguration.getValue<number>('system.animation.fps') : 0; const speedX = item.speedX ? item.speedX / NitroConfiguration.getValue<number>('system.animation.fps', 24) : 0;
const speedY = item.speedY ? item.speedY / NitroConfiguration.getValue<number>('system.animation.fps') : 0; const speedY = item.speedY ? item.speedY / NitroConfiguration.getValue<number>('system.animation.fps', 24) : 0;
animationItems.push({ animationItems.push({
asset: assetId, asset: assetId,

View File

@ -1,5 +1,4 @@
import { GetTickerTime } from '../../../pixi-proxy'; import { GetTickerFPS, GetTickerTime } from '../../../pixi-proxy';
import { Nitro } from '../../Nitro';
import { Motion } from './Motion'; import { Motion } from './Motion';
export class Motions export class Motions
@ -12,7 +11,7 @@ export class Motions
public static get TIMER_TIME(): number public static get TIMER_TIME(): number
{ {
return (1000 / Nitro.instance.ticker.FPS); return (1000 / GetTickerFPS());
} }
public static runMotion(k: Motion): Motion public static runMotion(k: Motion): Motion

View File

@ -0,0 +1,3 @@
import { PixiApplicationProxy } from './PixiApplicationProxy';
export const GetTicker = () => (PixiApplicationProxy.instance?.ticker || null);

View File

@ -0,0 +1,3 @@
import { GetTicker } from './GetTicker';
export const GetTickerFPS = () => (GetTicker()?.FPS || 0);

View File

@ -1,3 +1,3 @@
import { PixiApplicationProxy } from './PixiApplicationProxy'; import { GetTicker } from './GetTicker';
export const GetTickerTime = () => (PixiApplicationProxy.instance?.ticker?.lastTime || 0); export const GetTickerTime = () => (GetTicker()?.lastTime || 0);

View File

@ -1,3 +1,5 @@
export * from './GetTicker';
export * from './GetTickerFPS';
export * from './GetTickerTime'; export * from './GetTickerTime';
export * from './INitroPoint'; export * from './INitroPoint';
export * from './NitroAdjustmentFilter'; export * from './NitroAdjustmentFilter';

View File

@ -5,7 +5,7 @@ import { Matrix, Point, Rectangle } from '@pixi/math';
import { Sprite } from '@pixi/sprite'; import { Sprite } from '@pixi/sprite';
import { IRoomCanvasMouseListener, IRoomGeometry, IRoomObject, IRoomObjectSprite, IRoomObjectSpriteVisualization, IRoomRenderingCanvas, IRoomSpriteCanvasContainer, IRoomSpriteMouseEvent, MouseEventType, RoomObjectSpriteData, RoomObjectSpriteType, Vector3d } from '../../api'; import { IRoomCanvasMouseListener, IRoomGeometry, IRoomObject, IRoomObjectSprite, IRoomObjectSpriteVisualization, IRoomRenderingCanvas, IRoomSpriteCanvasContainer, IRoomSpriteMouseEvent, MouseEventType, RoomObjectSpriteData, RoomObjectSpriteType, Vector3d } from '../../api';
import { Nitro } from '../../nitro/Nitro'; import { Nitro } from '../../nitro/Nitro';
import { NitroContainer, NitroSprite, PixiApplicationProxy } from '../../pixi-proxy'; import { GetTickerTime, NitroContainer, NitroSprite, PixiApplicationProxy } from '../../pixi-proxy';
import { RoomSpriteMouseEvent } from '../events'; import { RoomSpriteMouseEvent } from '../events';
import { RoomEnterEffect, RoomGeometry, RoomRotatingEffect, RoomShakingEffect } from '../utils'; import { RoomEnterEffect, RoomGeometry, RoomRotatingEffect, RoomShakingEffect } from '../utils';
import { RoomObjectCache, RoomObjectCacheItem } from './cache'; import { RoomObjectCache, RoomObjectCacheItem } from './cache';
@ -322,7 +322,7 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
{ {
this._canvasUpdated = false; this._canvasUpdated = false;
this._totalTimeRunning += PixiApplicationProxy.instance.ticker.deltaTime; this._totalTimeRunning = GetTickerTime();
if(this._totalTimeRunning === this._renderTimestamp) return; if(this._totalTimeRunning === this._renderTimestamp) return;
@ -334,8 +334,7 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
if((this._display.x !== this._screenOffsetX) || (this._display.y !== this._screenOffsetY)) if((this._display.x !== this._screenOffsetX) || (this._display.y !== this._screenOffsetY))
{ {
this._display.x = this._screenOffsetX; this._display.position.set(this._screenOffsetX, this._screenOffsetY);
this._display.y = this._screenOffsetY;
update = true; update = true;
} }
@ -374,15 +373,9 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
} }
} }
this._sortableSprites.sort((a, b) => this._sortableSprites.sort((a, b) => (b.z - a.z));
{
return b.z - a.z;
});
if(spriteCount < this._sortableSprites.length) if(spriteCount < this._sortableSprites.length) this._sortableSprites.splice(spriteCount);
{
this._sortableSprites.splice(spriteCount);
}
let iterator = 0; let iterator = 0;