diff --git a/packages/api/src/nitro/room/IRoomEngine.ts b/packages/api/src/nitro/room/IRoomEngine.ts index e7367a90..3aa3df49 100644 --- a/packages/api/src/nitro/room/IRoomEngine.ts +++ b/packages/api/src/nitro/room/IRoomEngine.ts @@ -12,8 +12,6 @@ export interface IRoomEngine { init(): Promise; setActiveRoomId(roomId: number): void; - disableUpdate(flag: boolean): void; - runUpdate(): void; createRoomInstance(roomId: number, roomMap: IRoomMapData): void; getRoomInstanceDisplay(roomId: number, id: number, width: number, height: number, scale: number): Container; setRoomInstanceRenderingCanvasScale(roomId: number, canvasId: number, scale: number, point?: Point, offsetPoint?: Point, override?: boolean, asDelta?: boolean): void; diff --git a/packages/api/src/room/object/visualization/IRoomObjectSprite.ts b/packages/api/src/room/object/visualization/IRoomObjectSprite.ts index ca60309f..64900442 100644 --- a/packages/api/src/room/object/visualization/IRoomObjectSprite.ts +++ b/packages/api/src/room/object/visualization/IRoomObjectSprite.ts @@ -2,6 +2,8 @@ import { BLEND_MODES, Filter, Texture } from 'pixi.js'; export interface IRoomObjectSprite { + dispose(): void; + increaseUpdateCounter(): void; id: number; name: string; type: string; diff --git a/packages/room/src/RoomEngine.ts b/packages/room/src/RoomEngine.ts index f026d057..cbc58ef6 100644 --- a/packages/room/src/RoomEngine.ts +++ b/packages/room/src/RoomEngine.ts @@ -3,7 +3,7 @@ import { GetCommunication, RenderRoomMessageComposer, RenderRoomThumbnailMessage import { GetConfiguration } from '@nitrots/configuration'; import { BadgeImageReadyEvent, GetEventDispatcher, NitroToolbarAnimateIconEvent, RoomBackgroundColorEvent, RoomDragEvent, RoomEngineEvent, RoomEngineObjectEvent, RoomObjectEvent, RoomObjectFurnitureActionEvent, RoomObjectMouseEvent, RoomSessionEvent, RoomToObjectOwnAvatarMoveEvent } from '@nitrots/events'; import { GetRoomSessionManager, GetSessionDataManager } from '@nitrots/session'; -import { FurniId, GetTicker, GetTickerTime, NitroLogger, NumberBank, TextureUtils, Vector3d } from '@nitrots/utils'; +import { FurniId, GetTickerTime, NitroLogger, NumberBank, TextureUtils, Vector3d } from '@nitrots/utils'; import { Container, Matrix, Point, Rectangle, RenderTexture, Sprite, Texture, Ticker } from 'pixi.js'; import { GetRoomContentLoader } from './GetRoomContentLoader'; import { GetRoomManager } from './GetRoomManager'; @@ -93,13 +93,6 @@ export class RoomEngine implements IRoomEngine, IRoomCreator, IRoomEngineService this._roomManager.addUpdateCategory(RoomObjectCategory.UNIT); this._roomManager.addUpdateCategory(RoomObjectCategory.CURSOR); this._roomManager.addUpdateCategory(RoomObjectCategory.ROOM); - - GetTicker().add(this.update, this); - - document.addEventListener('visibilitychange', event => - { - if(!document.hidden) this.update(GetTicker()); // true - }); } private onRoomSessionEvent(event: RoomSessionEvent): void @@ -633,24 +626,6 @@ export class RoomEngine implements IRoomEngine, IRoomCreator, IRoomEngineService return this.isRoomIdPlayingGame(this._activeRoomId); } - public disableUpdate(flag: boolean): void - { - if(flag) - { - GetTicker().remove(this.update, this); - } - else - { - GetTicker().remove(this.update, this); - GetTicker().add(this.update, this); - } - } - - public runUpdate(): void - { - this.update(GetTicker()); - } - public update(ticker: Ticker): void { if(!this._roomManager) return; diff --git a/packages/room/src/RoomPreviewer.ts b/packages/room/src/RoomPreviewer.ts index 8be57f98..c7c02da2 100644 --- a/packages/room/src/RoomPreviewer.ts +++ b/packages/room/src/RoomPreviewer.ts @@ -724,16 +724,6 @@ export class RoomPreviewer } } - public set disableUpdate(flag: boolean) - { - this._disableUpdate = flag; - } - - public set disableRoomEngineUpdate(flag: boolean) - { - if(this.isRoomEngineReady) this._roomEngine.disableUpdate(flag); - } - private onRoomInitializedonRoomInitialized(event: RoomEngineEvent): void { if(!event) return; @@ -771,11 +761,6 @@ export class RoomPreviewer } } - public updateRoomEngine(): void - { - if(this.isRoomEngineReady) this._roomEngine.runUpdate(); - } - public getRenderingCanvas(): IRoomRenderingCanvas { const renderingCanvas = this._roomEngine.getRoomInstanceRenderingCanvas(this._previewRoomId, RoomPreviewer.PREVIEW_CANVAS_ID); diff --git a/packages/room/src/object/visualization/RoomObjectSprite.ts b/packages/room/src/object/visualization/RoomObjectSprite.ts index 73d79a6d..51b87963 100644 --- a/packages/room/src/object/visualization/RoomObjectSprite.ts +++ b/packages/room/src/object/visualization/RoomObjectSprite.ts @@ -36,22 +36,16 @@ export class RoomObjectSprite implements IRoomObjectSprite public dispose(): void { - if(this._spriteType !== RoomObjectSpriteType.DEFAULT) - { - if(this._texture) - { - //@ts-ignore - if(this._texture?.source?.hitMap) this._texture.source.hitMap = null; - - this._texture.destroy(true); - } - } - this._texture = null; this._width = 0; this._height = 0; } + public increaseUpdateCounter(): void + { + this._updateCounter++; + } + public get id(): number { return this._id; diff --git a/packages/room/src/object/visualization/room/RoomPlane.ts b/packages/room/src/object/visualization/room/RoomPlane.ts index 932cace2..3feaa5e9 100644 --- a/packages/room/src/object/visualization/room/RoomPlane.ts +++ b/packages/room/src/object/visualization/room/RoomPlane.ts @@ -1,6 +1,6 @@ import { IAssetPlaneVisualizationLayer, IAssetRoomVisualizationData, IRoomGeometry, IRoomPlane, IVector3D } from '@nitrots/api'; import { GetAssetManager } from '@nitrots/assets'; -import { GetRenderer, PlaneMaskFilter, TextureUtils, Vector3d } from '@nitrots/utils'; +import { GetRenderer, GetTexturePool, PlaneMaskFilter, Vector3d } from '@nitrots/utils'; import { Container, Filter, Matrix, Point, Sprite, Texture, TilingSprite } from 'pixi.js'; import { RoomGeometry } from '../../../utils'; import { RoomPlaneBitmapMask } from './RoomPlaneBitmapMask'; @@ -112,10 +112,7 @@ export class RoomPlane implements IRoomPlane if(this._planeTexture) { - //@ts-ignore - if(this._planeTexture.source?.hitMap) this._planeTexture.source.hitMap = null; - - this._planeTexture.destroy(true); + GetTexturePool().putTexture(this._planeTexture); this._planeTexture = null; } @@ -337,13 +334,13 @@ export class RoomPlane implements IRoomPlane { if(this._planeTexture.width !== this._width || this._planeTexture.height !== this._height) { - this._planeTexture.destroy(true); + GetTexturePool().putTexture(this._planeTexture); this._planeTexture = null; } } - if(!this._planeTexture) this._planeTexture = TextureUtils.createRenderTexture(this._width, this._height); + if(!this._planeTexture) this._planeTexture = GetTexturePool().getTexture(this._width, this._height); this._planeTexture.source.label = `room_plane_${ this._uniqueId.toString() }`; diff --git a/packages/room/src/renderer/RoomRenderer.ts b/packages/room/src/renderer/RoomRenderer.ts index f8bd9e56..dd6f0c4f 100644 --- a/packages/room/src/renderer/RoomRenderer.ts +++ b/packages/room/src/renderer/RoomRenderer.ts @@ -124,7 +124,7 @@ export class RoomRenderer implements IRoomRenderer, IRoomSpriteCanvasContainer private createSpriteCanvas(id: number, width: number, height: number, scale: number): IRoomRenderingCanvas { - return new RoomSpriteCanvas(this, id, width, height, scale); + return new RoomSpriteCanvas(id, this, width, height, scale); } public removeCanvas(id: number): void diff --git a/packages/room/src/renderer/RoomSpriteCanvas.ts b/packages/room/src/renderer/RoomSpriteCanvas.ts index 6bdad58a..1fcab92a 100644 --- a/packages/room/src/renderer/RoomSpriteCanvas.ts +++ b/packages/room/src/renderer/RoomSpriteCanvas.ts @@ -2,48 +2,45 @@ import { IRoomCanvasMouseListener, IRoomGeometry, IRoomObject, IRoomObjectSprite import { GetConfiguration } from '@nitrots/configuration'; import { RoomSpriteMouseEvent } from '@nitrots/events'; import { GetTicker, TextureUtils, Vector3d } from '@nitrots/utils'; -import { Container, Graphics, Matrix, Point, Rectangle, Texture } from 'pixi.js'; +import { Container, Matrix, Point, Rectangle, Sprite, Texture } from 'pixi.js'; import { RoomEnterEffect, RoomGeometry, RoomRotatingEffect, RoomShakingEffect } from '../utils'; import { RoomObjectCache, RoomObjectCacheItem } from './cache'; import { ExtendedSprite, ObjectMouseData, SortableSprite } from './utils'; export class RoomSpriteCanvas implements IRoomRenderingCanvas { - private _id: number; - private _container: IRoomSpriteCanvasContainer; - private _geometry: RoomGeometry; private _animationFPS: number; - private _renderTimestamp: number; - private _totalTimeRunning: number; - private _lastFrame: number; + private _renderTimestamp: number = 0; + private _totalTimeRunning: number = 0; + private _lastFrame: number = 0; - private _master: Container; - private _display: Container; - private _mask: Graphics; + private _master: Container = null; + private _display: Container = null; + private _mask: Sprite = null; - private _sortableSprites: SortableSprite[]; - private _spriteCount: number; - private _activeSpriteCount: number; - private _spritePool: ExtendedSprite[]; - private _skipObjectUpdate: boolean; - private _runningSlow: boolean; + private _sortableSprites: SortableSprite[] = []; + private _spriteCount: number = 0; + private _activeSpriteCount: number = 0; + private _spritePool: ExtendedSprite[] = []; + private _skipObjectUpdate: boolean = false; + private _runningSlow: boolean = false; - private _width: number; - private _height: number; - private _renderedWidth: number; - private _renderedHeight: number; - private _screenOffsetX: number; - private _screenOffsetY: number; - private _mouseLocation: Point; - private _mouseOldX: number; - private _mouseOldY: number; - private _mouseCheckCount: number; - private _mouseSpriteWasHit: boolean; - private _mouseActiveObjects: Map; - private _eventCache: Map; - private _eventId: number; - private _scale: number; + private _width: number = 0; + private _height: number = 0; + private _renderedWidth: number = 0; + private _renderedHeight: number = 0; + private _screenOffsetX: number = 0; + private _screenOffsetY: number = 0; + private _mouseLocation: Point = new Point(); + private _mouseOldX: number = 0; + private _mouseOldY: number = 0; + private _mouseCheckCount: number = 0; + private _mouseSpriteWasHit: boolean = false; + private _mouseActiveObjects: Map = new Map(); + private _eventCache: Map = new Map(); + private _eventId: number = 0; + private _scale: number = 1; private _SafeStr_4507: boolean = false; private _rotation: number = 0; @@ -53,62 +50,26 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas private _effectLocation: Vector3d; private _SafeStr_795: number = 0; - private _noSpriteVisibilityChecking: boolean; - private _usesExclusionRectangles: boolean; - private _usesMask: boolean; - private _canvasUpdated: boolean; + private _noSpriteVisibilityChecking: boolean = false; + private _usesExclusionRectangles: boolean = false; + private _usesMask: boolean = true; + private _canvasUpdated: boolean = false; private _objectCache: RoomObjectCache; - private _mouseListener: IRoomCanvasMouseListener; + private _mouseListener: IRoomCanvasMouseListener = null; - constructor(container: IRoomSpriteCanvasContainer, id: number, width: number, height: number, scale: number) + constructor( + private _id: number, + private _container: IRoomSpriteCanvasContainer, + width: number, + height: number, + scale: number) { - this._id = id; - 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 = GetConfiguration().getValue('system.fps.animation', 24); - this._renderTimestamp = 0; - this._totalTimeRunning = 0; - this._lastFrame = 0; - - this._master = null; - this._display = null; - this._mask = null; - - this._sortableSprites = []; - this._spriteCount = 0; - this._activeSpriteCount = 0; - this._spritePool = []; - this._skipObjectUpdate = false; - this._runningSlow = false; - - this._width = 0; - this._height = 0; - this._renderedWidth = 0; - this._renderedHeight = 0; - this._screenOffsetX = 0; - this._screenOffsetY = 0; - this._mouseLocation = new Point; - this._mouseOldX = 0; - this._mouseOldY = 0; - this._mouseCheckCount = 0; - this._mouseSpriteWasHit = false; - this._mouseActiveObjects = new Map(); - this._eventCache = new Map(); - this._eventId = 0; - this._scale = 1; - - this._noSpriteVisibilityChecking = false; - this._usesExclusionRectangles = false; - this._usesMask = true; - this._canvasUpdated = false; - this._objectCache = new RoomObjectCache(this._container.roomObjectVariableAccurateZ); - this._mouseListener = null; - this.setupCanvas(); this.initialize(width, height); } @@ -123,8 +84,13 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas { const display = new Container(); + display.isRenderGroup = true; + display.cullableChildren = false; + display.interactive = false; + display.interactiveChildren = false; + this._master.addChild(display); this._display = display; @@ -206,9 +172,11 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas { if(!this._mask) { - this._mask = new Graphics() - .rect(0, 0, width, height) - .fill(0xFF0000); + this._mask = new Sprite(Texture.WHITE); + + this._mask.tint = 0xFF0000; + this._mask.width = width; + this._mask.height = height; if(this._master) { @@ -219,27 +187,13 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas } else { - this._mask - .clear() - .rect(0, 0, width, height) - .fill(0xFF0000); + this._mask.width = width; + this._mask.height = height; } } if(this._master) { - /* if(this._master.hitArea) - { - const hitArea = (this._master.hitArea as Rectangle); - - hitArea.width = width; - hitArea.height = height; - } - else - { - this._master.hitArea = new Rectangle(0, 0, width, height); - } */ - if(this._master.filterArea) { const filterArea = this._master.filterArea;