From 3eb63260012291a758ccad503d88f40510101af9 Mon Sep 17 00:00:00 2001 From: dank074 Date: Sun, 31 Oct 2021 15:38:56 -0500 Subject: [PATCH] floor packet changes + tilemap library added --- package.json | 1 + src/core/utils/proxy/index.ts | 1 + src/core/utils/proxy/tilemap/NitroTilemap.ts | 6 + src/core/utils/proxy/tilemap/index.ts | 2 + src/nitro/Plugins.ts | 2 + src/nitro/communication/NitroMessages.ts | 16 +- .../room/mapping/FloorHeightMapEvent.ts | 16 + .../room/mapping/RoomBlockedTilesEvent.ts | 16 - .../incoming/room/mapping/RoomDoorEvent.ts | 16 - .../room/mapping/RoomEntryTileMessageEvent.ts | 16 + .../incoming/room/mapping/RoomModelEvent.ts | 16 - .../mapping/RoomOccupiedTilesMessageEvent.ts | 16 + .../room/mapping/RoomThicknessEvent.ts | 16 - .../mapping/RoomVisualizationSettingsEvent.ts | 16 + .../messages/incoming/room/mapping/index.ts | 8 +- ...rser.ts => FloorHeightMapMessageParser.ts} | 2 +- ...arser.ts => RoomEntryTileMessageParser.ts} | 2 +- ...r.ts => RoomOccupiedTilesMessageParser.ts} | 2 +- ....ts => RoomVisualizationSettingsParser.ts} | 2 +- .../messages/parser/room/mapping/index.ts | 8 +- src/nitro/room/RoomMessageHandler.ts | 30 +- src/nitro/room/preview/RoomPreviewer.ts | 8 +- src/room/floorplan/index.ts | 1 - .../pixi-tilemap/CanvasTileRenderer.ts | 22 - .../pixi-tilemap/CompositeRectTileLayer.ts | 287 ---------- src/room/floorplan/pixi-tilemap/Constant.ts | 11 - .../pixi-tilemap/MultiTextureResource.ts | 68 --- .../floorplan/pixi-tilemap/RectTileLayer.ts | 495 ------------------ .../floorplan/pixi-tilemap/RectTileShader.ts | 111 ---- .../floorplan/pixi-tilemap/TileRenderer.ts | 166 ------ src/room/floorplan/pixi-tilemap/index.ts | 8 - .../floorplan/pixi-tilemap/shaderGenerator.ts | 57 -- src/room/index.ts | 1 - 33 files changed, 115 insertions(+), 1330 deletions(-) create mode 100644 src/core/utils/proxy/tilemap/NitroTilemap.ts create mode 100644 src/core/utils/proxy/tilemap/index.ts create mode 100644 src/nitro/communication/messages/incoming/room/mapping/FloorHeightMapEvent.ts delete mode 100644 src/nitro/communication/messages/incoming/room/mapping/RoomBlockedTilesEvent.ts delete mode 100644 src/nitro/communication/messages/incoming/room/mapping/RoomDoorEvent.ts create mode 100644 src/nitro/communication/messages/incoming/room/mapping/RoomEntryTileMessageEvent.ts delete mode 100644 src/nitro/communication/messages/incoming/room/mapping/RoomModelEvent.ts create mode 100644 src/nitro/communication/messages/incoming/room/mapping/RoomOccupiedTilesMessageEvent.ts delete mode 100644 src/nitro/communication/messages/incoming/room/mapping/RoomThicknessEvent.ts create mode 100644 src/nitro/communication/messages/incoming/room/mapping/RoomVisualizationSettingsEvent.ts rename src/nitro/communication/messages/parser/room/mapping/{RoomModelParser.ts => FloorHeightMapMessageParser.ts} (98%) rename src/nitro/communication/messages/parser/room/mapping/{RoomDoorParser.ts => RoomEntryTileMessageParser.ts} (92%) rename src/nitro/communication/messages/parser/room/mapping/{RoomBlockedTilesParser.ts => RoomOccupiedTilesMessageParser.ts} (91%) rename src/nitro/communication/messages/parser/room/mapping/{RoomThicknessParser.ts => RoomVisualizationSettingsParser.ts} (94%) delete mode 100644 src/room/floorplan/index.ts delete mode 100644 src/room/floorplan/pixi-tilemap/CanvasTileRenderer.ts delete mode 100644 src/room/floorplan/pixi-tilemap/CompositeRectTileLayer.ts delete mode 100644 src/room/floorplan/pixi-tilemap/Constant.ts delete mode 100644 src/room/floorplan/pixi-tilemap/MultiTextureResource.ts delete mode 100644 src/room/floorplan/pixi-tilemap/RectTileLayer.ts delete mode 100644 src/room/floorplan/pixi-tilemap/RectTileShader.ts delete mode 100644 src/room/floorplan/pixi-tilemap/TileRenderer.ts delete mode 100644 src/room/floorplan/pixi-tilemap/index.ts delete mode 100644 src/room/floorplan/pixi-tilemap/shaderGenerator.ts diff --git a/package.json b/package.json index ace00f84..229ebcbf 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "@pixi/canvas-renderer": "^6.1.0", "@pixi/extract": "^6.1.0", "@pixi/filter-adjustment": "^4.1.3", + "@pixi/tilemap": "^3.2.2", "pako": "^2.0.4", "pixi.js": "^6.1.0", "tslib": "^2.3.0" diff --git a/src/core/utils/proxy/index.ts b/src/core/utils/proxy/index.ts index b3b95d07..594d75f3 100644 --- a/src/core/utils/proxy/index.ts +++ b/src/core/utils/proxy/index.ts @@ -13,3 +13,4 @@ export * from './NitroTexture'; export * from './PixiApplicationProxy'; export * from './PixiInteractionEventProxy'; export * from './PixiLoaderProxy'; +export * from './tilemap'; diff --git a/src/core/utils/proxy/tilemap/NitroTilemap.ts b/src/core/utils/proxy/tilemap/NitroTilemap.ts new file mode 100644 index 00000000..00477776 --- /dev/null +++ b/src/core/utils/proxy/tilemap/NitroTilemap.ts @@ -0,0 +1,6 @@ +import { Tilemap } from '@pixi/tilemap'; + +export class NitroTilemap extends Tilemap +{ + +} diff --git a/src/core/utils/proxy/tilemap/index.ts b/src/core/utils/proxy/tilemap/index.ts new file mode 100644 index 00000000..d14e1ff8 --- /dev/null +++ b/src/core/utils/proxy/tilemap/index.ts @@ -0,0 +1,2 @@ +export { POINT_STRUCT_SIZE } from '@pixi/tilemap'; +export * from './NitroTilemap'; diff --git a/src/nitro/Plugins.ts b/src/nitro/Plugins.ts index a630cc61..fd7ae350 100644 --- a/src/nitro/Plugins.ts +++ b/src/nitro/Plugins.ts @@ -12,6 +12,7 @@ import { TilingSpriteRenderer } from '@pixi/sprite-tiling'; import { SpritesheetLoader } from '@pixi/spritesheet'; import { BitmapFontLoader } from '@pixi/text-bitmap'; import { TickerPlugin } from '@pixi/ticker'; +import { TileRenderer } from '@pixi/tilemap'; Renderer.registerPlugin('accessibility', AccessibilityManager); Renderer.registerPlugin('extract', Extract); @@ -20,6 +21,7 @@ Renderer.registerPlugin('particle', ParticleRenderer); Renderer.registerPlugin('prepare', Prepare); Renderer.registerPlugin('batch', BatchRenderer); Renderer.registerPlugin('tilingSprite', TilingSpriteRenderer); +Renderer.registerPlugin('tilemap', TileRenderer); Loader.registerPlugin(BitmapFontLoader); Loader.registerPlugin(CompressedTextureLoader); diff --git a/src/nitro/communication/NitroMessages.ts b/src/nitro/communication/NitroMessages.ts index d3cc3e77..e9dd2af4 100644 --- a/src/nitro/communication/NitroMessages.ts +++ b/src/nitro/communication/NitroMessages.ts @@ -167,14 +167,14 @@ import { FurnitureWallUpdateEvent } from './messages/incoming/room/furniture/wal import { YoutubeControlVideoMessageEvent } from './messages/incoming/room/furniture/youtube/YoutubeControlVideoMessageEvent'; import { YoutubeDisplayPlaylistsEvent } from './messages/incoming/room/furniture/youtube/YoutubeDisplayPlaylistsEvent'; import { YoutubeDisplayVideoMessageEvent } from './messages/incoming/room/furniture/youtube/YoutubeDisplayVideoMessageEvent'; -import { RoomBlockedTilesEvent } from './messages/incoming/room/mapping/RoomBlockedTilesEvent'; -import { RoomDoorEvent } from './messages/incoming/room/mapping/RoomDoorEvent'; +import { FloorHeightMapEvent } from './messages/incoming/room/mapping/FloorHeightMapEvent'; +import { RoomEntryTileMessageEvent } from './messages/incoming/room/mapping/RoomEntryTileMessageEvent'; import { RoomHeightMapEvent } from './messages/incoming/room/mapping/RoomHeightMapEvent'; import { RoomHeightMapUpdateEvent } from './messages/incoming/room/mapping/RoomHeightMapUpdateEvent'; -import { RoomModelEvent } from './messages/incoming/room/mapping/RoomModelEvent'; import { RoomModelNameEvent } from './messages/incoming/room/mapping/RoomModelNameEvent'; +import { RoomOccupiedTilesMessageEvent } from './messages/incoming/room/mapping/RoomOccupiedTilesMessageEvent'; import { RoomPaintEvent } from './messages/incoming/room/mapping/RoomPaintEvent'; -import { RoomThicknessEvent } from './messages/incoming/room/mapping/RoomThicknessEvent'; +import { RoomVisualizationSettingsEvent } from './messages/incoming/room/mapping/RoomVisualizationSettingsEvent'; import { PetFigureUpdateEvent } from './messages/incoming/room/pet/PetFigureUpdateEvent'; import { PetInfoEvent } from './messages/incoming/room/pet/PetInfoEvent'; import { YouArePlayingGameEvent } from './messages/incoming/room/session/YouArePlayingGameEvent'; @@ -760,14 +760,14 @@ export class NitroMessages implements IMessageConfiguration this._events.set(IncomingHeader.FURNITURE_POSTIT_STICKY_POLE_OPEN, FurniturePostItStickyPoleOpenEvent); // MAPPING - this._events.set(IncomingHeader.ROOM_MODEL_DOOR, RoomDoorEvent); + this._events.set(IncomingHeader.ROOM_MODEL_DOOR, RoomEntryTileMessageEvent); this._events.set(IncomingHeader.ROOM_HEIGHT_MAP, RoomHeightMapEvent); this._events.set(IncomingHeader.ROOM_HEIGHT_MAP_UPDATE, RoomHeightMapUpdateEvent); - this._events.set(IncomingHeader.ROOM_MODEL, RoomModelEvent); + this._events.set(IncomingHeader.ROOM_MODEL, FloorHeightMapEvent); this._events.set(IncomingHeader.ROOM_MODEL_NAME, RoomModelNameEvent); this._events.set(IncomingHeader.ROOM_PAINT, RoomPaintEvent); - this._events.set(IncomingHeader.ROOM_THICKNESS, RoomThicknessEvent); - this._events.set(IncomingHeader.ROOM_MODEL_BLOCKED_TILES, RoomBlockedTilesEvent); + this._events.set(IncomingHeader.ROOM_THICKNESS, RoomVisualizationSettingsEvent); + this._events.set(IncomingHeader.ROOM_MODEL_BLOCKED_TILES, RoomOccupiedTilesMessageEvent); this._events.set(IncomingHeader.PET_FIGURE_UPDATE, PetFigureUpdateEvent); this._events.set(IncomingHeader.PET_INFO, PetInfoEvent); this._events.set(IncomingHeader.PET_EXPERIENCE, PetExperienceEvent); diff --git a/src/nitro/communication/messages/incoming/room/mapping/FloorHeightMapEvent.ts b/src/nitro/communication/messages/incoming/room/mapping/FloorHeightMapEvent.ts new file mode 100644 index 00000000..3d063798 --- /dev/null +++ b/src/nitro/communication/messages/incoming/room/mapping/FloorHeightMapEvent.ts @@ -0,0 +1,16 @@ +import { IMessageEvent } from '../../../../../../core/communication/messages/IMessageEvent'; +import { MessageEvent } from '../../../../../../core/communication/messages/MessageEvent'; +import { FloorHeightMapMessageParser } from '../../../parser/room/mapping/FloorHeightMapMessageParser'; + +export class FloorHeightMapEvent extends MessageEvent implements IMessageEvent +{ + constructor(callBack: Function) + { + super(callBack, FloorHeightMapMessageParser); + } + + public getParser(): FloorHeightMapMessageParser + { + return this.parser as FloorHeightMapMessageParser; + } +} diff --git a/src/nitro/communication/messages/incoming/room/mapping/RoomBlockedTilesEvent.ts b/src/nitro/communication/messages/incoming/room/mapping/RoomBlockedTilesEvent.ts deleted file mode 100644 index dcdec600..00000000 --- a/src/nitro/communication/messages/incoming/room/mapping/RoomBlockedTilesEvent.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { IMessageEvent } from '../../../../../../core/communication/messages/IMessageEvent'; -import { MessageEvent } from '../../../../../../core/communication/messages/MessageEvent'; -import { RoomBlockedTilesParser } from '../../../parser/room/mapping/RoomBlockedTilesParser'; - -export class RoomBlockedTilesEvent extends MessageEvent implements IMessageEvent -{ - constructor(callBack: Function) - { - super(callBack, RoomBlockedTilesParser); - } - - public getParser(): RoomBlockedTilesParser - { - return this.parser as RoomBlockedTilesParser; - } -} diff --git a/src/nitro/communication/messages/incoming/room/mapping/RoomDoorEvent.ts b/src/nitro/communication/messages/incoming/room/mapping/RoomDoorEvent.ts deleted file mode 100644 index 7e3433e8..00000000 --- a/src/nitro/communication/messages/incoming/room/mapping/RoomDoorEvent.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { IMessageEvent } from '../../../../../../core/communication/messages/IMessageEvent'; -import { MessageEvent } from '../../../../../../core/communication/messages/MessageEvent'; -import { RoomDoorParser } from '../../../parser/room/mapping/RoomDoorParser'; - -export class RoomDoorEvent extends MessageEvent implements IMessageEvent -{ - constructor(callBack: Function) - { - super(callBack, RoomDoorParser); - } - - public getParser(): RoomDoorParser - { - return this.parser as RoomDoorParser; - } -} diff --git a/src/nitro/communication/messages/incoming/room/mapping/RoomEntryTileMessageEvent.ts b/src/nitro/communication/messages/incoming/room/mapping/RoomEntryTileMessageEvent.ts new file mode 100644 index 00000000..2e8edb9b --- /dev/null +++ b/src/nitro/communication/messages/incoming/room/mapping/RoomEntryTileMessageEvent.ts @@ -0,0 +1,16 @@ +import { IMessageEvent } from '../../../../../../core/communication/messages/IMessageEvent'; +import { MessageEvent } from '../../../../../../core/communication/messages/MessageEvent'; +import { RoomEntryTileMessageParser } from '../../../parser/room/mapping/RoomEntryTileMessageParser'; + +export class RoomEntryTileMessageEvent extends MessageEvent implements IMessageEvent +{ + constructor(callBack: Function) + { + super(callBack, RoomEntryTileMessageParser); + } + + public getParser(): RoomEntryTileMessageParser + { + return this.parser as RoomEntryTileMessageParser; + } +} diff --git a/src/nitro/communication/messages/incoming/room/mapping/RoomModelEvent.ts b/src/nitro/communication/messages/incoming/room/mapping/RoomModelEvent.ts deleted file mode 100644 index f236b419..00000000 --- a/src/nitro/communication/messages/incoming/room/mapping/RoomModelEvent.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { IMessageEvent } from '../../../../../../core/communication/messages/IMessageEvent'; -import { MessageEvent } from '../../../../../../core/communication/messages/MessageEvent'; -import { RoomModelParser } from '../../../parser/room/mapping/RoomModelParser'; - -export class RoomModelEvent extends MessageEvent implements IMessageEvent -{ - constructor(callBack: Function) - { - super(callBack, RoomModelParser); - } - - public getParser(): RoomModelParser - { - return this.parser as RoomModelParser; - } -} diff --git a/src/nitro/communication/messages/incoming/room/mapping/RoomOccupiedTilesMessageEvent.ts b/src/nitro/communication/messages/incoming/room/mapping/RoomOccupiedTilesMessageEvent.ts new file mode 100644 index 00000000..c37a591b --- /dev/null +++ b/src/nitro/communication/messages/incoming/room/mapping/RoomOccupiedTilesMessageEvent.ts @@ -0,0 +1,16 @@ +import { IMessageEvent } from '../../../../../../core/communication/messages/IMessageEvent'; +import { MessageEvent } from '../../../../../../core/communication/messages/MessageEvent'; +import { RoomOccupiedTilesMessageParser } from '../../../parser/room/mapping/RoomOccupiedTilesMessageParser'; + +export class RoomOccupiedTilesMessageEvent extends MessageEvent implements IMessageEvent +{ + constructor(callBack: Function) + { + super(callBack, RoomOccupiedTilesMessageParser); + } + + public getParser(): RoomOccupiedTilesMessageParser + { + return this.parser as RoomOccupiedTilesMessageParser; + } +} diff --git a/src/nitro/communication/messages/incoming/room/mapping/RoomThicknessEvent.ts b/src/nitro/communication/messages/incoming/room/mapping/RoomThicknessEvent.ts deleted file mode 100644 index f5df9b3f..00000000 --- a/src/nitro/communication/messages/incoming/room/mapping/RoomThicknessEvent.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { IMessageEvent } from '../../../../../../core/communication/messages/IMessageEvent'; -import { MessageEvent } from '../../../../../../core/communication/messages/MessageEvent'; -import { RoomThicknessParser } from '../../../parser/room/mapping/RoomThicknessParser'; - -export class RoomThicknessEvent extends MessageEvent implements IMessageEvent -{ - constructor(callBack: Function) - { - super(callBack, RoomThicknessParser); - } - - public getParser(): RoomThicknessParser - { - return this.parser as RoomThicknessParser; - } -} diff --git a/src/nitro/communication/messages/incoming/room/mapping/RoomVisualizationSettingsEvent.ts b/src/nitro/communication/messages/incoming/room/mapping/RoomVisualizationSettingsEvent.ts new file mode 100644 index 00000000..82e7b4cf --- /dev/null +++ b/src/nitro/communication/messages/incoming/room/mapping/RoomVisualizationSettingsEvent.ts @@ -0,0 +1,16 @@ +import { IMessageEvent } from '../../../../../../core/communication/messages/IMessageEvent'; +import { MessageEvent } from '../../../../../../core/communication/messages/MessageEvent'; +import { RoomVisualizationSettingsParser } from '../../../parser/room/mapping/RoomVisualizationSettingsParser'; + +export class RoomVisualizationSettingsEvent extends MessageEvent implements IMessageEvent +{ + constructor(callBack: Function) + { + super(callBack, RoomVisualizationSettingsParser); + } + + public getParser(): RoomVisualizationSettingsParser + { + return this.parser as RoomVisualizationSettingsParser; + } +} diff --git a/src/nitro/communication/messages/incoming/room/mapping/index.ts b/src/nitro/communication/messages/incoming/room/mapping/index.ts index a47f592e..038f1df4 100644 --- a/src/nitro/communication/messages/incoming/room/mapping/index.ts +++ b/src/nitro/communication/messages/incoming/room/mapping/index.ts @@ -1,8 +1,8 @@ -export * from './RoomBlockedTilesEvent'; -export * from './RoomDoorEvent'; +export * from './FloorHeightMapEvent'; +export * from './RoomEntryTileMessageEvent'; export * from './RoomHeightMapEvent'; export * from './RoomHeightMapUpdateEvent'; -export * from './RoomModelEvent'; export * from './RoomModelNameEvent'; +export * from './RoomOccupiedTilesMessageEvent'; export * from './RoomPaintEvent'; -export * from './RoomThicknessEvent'; +export * from './RoomVisualizationSettingsEvent'; diff --git a/src/nitro/communication/messages/parser/room/mapping/RoomModelParser.ts b/src/nitro/communication/messages/parser/room/mapping/FloorHeightMapMessageParser.ts similarity index 98% rename from src/nitro/communication/messages/parser/room/mapping/RoomModelParser.ts rename to src/nitro/communication/messages/parser/room/mapping/FloorHeightMapMessageParser.ts index bde2694f..a86b29e4 100644 --- a/src/nitro/communication/messages/parser/room/mapping/RoomModelParser.ts +++ b/src/nitro/communication/messages/parser/room/mapping/FloorHeightMapMessageParser.ts @@ -1,7 +1,7 @@ import { IMessageDataWrapper, IMessageParser } from '../../../../../../core'; import { RoomPlaneParser } from '../../../../../room/object/RoomPlaneParser'; -export class RoomModelParser implements IMessageParser +export class FloorHeightMapMessageParser implements IMessageParser { private _model: string; private _width: number; diff --git a/src/nitro/communication/messages/parser/room/mapping/RoomDoorParser.ts b/src/nitro/communication/messages/parser/room/mapping/RoomEntryTileMessageParser.ts similarity index 92% rename from src/nitro/communication/messages/parser/room/mapping/RoomDoorParser.ts rename to src/nitro/communication/messages/parser/room/mapping/RoomEntryTileMessageParser.ts index 43338aec..2407027f 100644 --- a/src/nitro/communication/messages/parser/room/mapping/RoomDoorParser.ts +++ b/src/nitro/communication/messages/parser/room/mapping/RoomEntryTileMessageParser.ts @@ -1,6 +1,6 @@ import { IMessageDataWrapper, IMessageParser } from '../../../../../../core'; -export class RoomDoorParser implements IMessageParser +export class RoomEntryTileMessageParser implements IMessageParser { private _x: number; private _y: number; diff --git a/src/nitro/communication/messages/parser/room/mapping/RoomBlockedTilesParser.ts b/src/nitro/communication/messages/parser/room/mapping/RoomOccupiedTilesMessageParser.ts similarity index 91% rename from src/nitro/communication/messages/parser/room/mapping/RoomBlockedTilesParser.ts rename to src/nitro/communication/messages/parser/room/mapping/RoomOccupiedTilesMessageParser.ts index 3a07dccb..4881df21 100644 --- a/src/nitro/communication/messages/parser/room/mapping/RoomBlockedTilesParser.ts +++ b/src/nitro/communication/messages/parser/room/mapping/RoomOccupiedTilesMessageParser.ts @@ -1,6 +1,6 @@ import { IMessageDataWrapper, IMessageParser } from '../../../../../../core'; -export class RoomBlockedTilesParser implements IMessageParser +export class RoomOccupiedTilesMessageParser implements IMessageParser { private _blockedTilesMap: boolean[][]; diff --git a/src/nitro/communication/messages/parser/room/mapping/RoomThicknessParser.ts b/src/nitro/communication/messages/parser/room/mapping/RoomVisualizationSettingsParser.ts similarity index 94% rename from src/nitro/communication/messages/parser/room/mapping/RoomThicknessParser.ts rename to src/nitro/communication/messages/parser/room/mapping/RoomVisualizationSettingsParser.ts index f682e1fa..899b5b90 100644 --- a/src/nitro/communication/messages/parser/room/mapping/RoomThicknessParser.ts +++ b/src/nitro/communication/messages/parser/room/mapping/RoomVisualizationSettingsParser.ts @@ -1,6 +1,6 @@ import { IMessageDataWrapper, IMessageParser } from '../../../../../../core'; -export class RoomThicknessParser implements IMessageParser +export class RoomVisualizationSettingsParser implements IMessageParser { private _hideWalls: boolean; private _thicknessWall: number; diff --git a/src/nitro/communication/messages/parser/room/mapping/index.ts b/src/nitro/communication/messages/parser/room/mapping/index.ts index 3b6c2914..155d6846 100644 --- a/src/nitro/communication/messages/parser/room/mapping/index.ts +++ b/src/nitro/communication/messages/parser/room/mapping/index.ts @@ -1,8 +1,8 @@ -export * from './RoomBlockedTilesParser'; -export * from './RoomDoorParser'; +export * from './FloorHeightMapMessageParser'; +export * from './RoomEntryTileMessageParser'; export * from './RoomHeightMapParser'; export * from './RoomHeightMapUpdateParser'; export * from './RoomModelNameParser'; -export * from './RoomModelParser'; +export * from './RoomOccupiedTilesMessageParser'; export * from './RoomPaintParser'; -export * from './RoomThicknessParser'; +export * from './RoomVisualizationSettingsParser'; diff --git a/src/nitro/room/RoomMessageHandler.ts b/src/nitro/room/RoomMessageHandler.ts index c85824aa..b9e06c38 100644 --- a/src/nitro/room/RoomMessageHandler.ts +++ b/src/nitro/room/RoomMessageHandler.ts @@ -18,13 +18,13 @@ import { FurnitureWallAddEvent } from '../communication/messages/incoming/room/f import { FurnitureWallEvent } from '../communication/messages/incoming/room/furniture/wall/FurnitureWallEvent'; import { FurnitureWallRemoveEvent } from '../communication/messages/incoming/room/furniture/wall/FurnitureWallRemoveEvent'; import { FurnitureWallUpdateEvent } from '../communication/messages/incoming/room/furniture/wall/FurnitureWallUpdateEvent'; -import { RoomDoorEvent } from '../communication/messages/incoming/room/mapping/RoomDoorEvent'; +import { FloorHeightMapEvent } from '../communication/messages/incoming/room/mapping/FloorHeightMapEvent'; +import { RoomEntryTileMessageEvent } from '../communication/messages/incoming/room/mapping/RoomEntryTileMessageEvent'; import { RoomHeightMapEvent } from '../communication/messages/incoming/room/mapping/RoomHeightMapEvent'; import { RoomHeightMapUpdateEvent } from '../communication/messages/incoming/room/mapping/RoomHeightMapUpdateEvent'; -import { RoomModelEvent } from '../communication/messages/incoming/room/mapping/RoomModelEvent'; import { RoomModelNameEvent } from '../communication/messages/incoming/room/mapping/RoomModelNameEvent'; import { RoomPaintEvent } from '../communication/messages/incoming/room/mapping/RoomPaintEvent'; -import { RoomThicknessEvent } from '../communication/messages/incoming/room/mapping/RoomThicknessEvent'; +import { RoomVisualizationSettingsEvent } from '../communication/messages/incoming/room/mapping/RoomVisualizationSettingsEvent'; import { PetFigureUpdateEvent } from '../communication/messages/incoming/room/pet/PetFigureUpdateEvent'; import { YouArePlayingGameEvent } from '../communication/messages/incoming/room/session/YouArePlayingGameEvent'; import { RoomUnitChatEvent } from '../communication/messages/incoming/room/unit/chat/RoomUnitChatEvent'; @@ -47,7 +47,7 @@ import { FurnitureAliasesComposer } from '../communication/messages/outgoing/roo import { GetRoomEntryDataMessageComposer } from '../communication/messages/outgoing/room/layout/GetRoomEntryDataMessageComposer'; import { FurnitureFloorDataParser } from '../communication/messages/parser/room/furniture/floor/FurnitureFloorDataParser'; import { FurnitureWallDataParser } from '../communication/messages/parser/room/furniture/wall/FurnitureWallDataParser'; -import { RoomDoorParser } from '../communication/messages/parser/room/mapping/RoomDoorParser'; +import { RoomEntryTileMessageParser } from '../communication/messages/parser/room/mapping/RoomEntryTileMessageParser'; import { IRoomCreator } from './IRoomCreator'; import { LegacyDataType } from './object/data/type/LegacyDataType'; import { RoomObjectUserType } from './object/RoomObjectUserType'; @@ -63,7 +63,7 @@ export class RoomMessageHandler extends Disposable private _connection: IConnection; private _roomCreator: IRoomCreator; private _planeParser: RoomPlaneParser; - private _latestEntryTileEvent: RoomDoorEvent; + private _latestEntryTileEvent: RoomEntryTileMessageEvent; private _currentRoomId: number; private _ownUserId: number; @@ -108,11 +108,11 @@ export class RoomMessageHandler extends Disposable this._connection.addMessageEvent(new UserInfoEvent(this.onUserInfoEvent.bind(this))); this._connection.addMessageEvent(new RoomModelNameEvent(this.onRoomModelNameEvent.bind(this))); this._connection.addMessageEvent(new RoomPaintEvent(this.onRoomPaintEvent.bind(this))); - this._connection.addMessageEvent(new RoomModelEvent(this.onRoomModelEvent.bind(this))); + this._connection.addMessageEvent(new FloorHeightMapEvent(this.onRoomModelEvent.bind(this))); this._connection.addMessageEvent(new RoomHeightMapEvent(this.onRoomHeightMapEvent.bind(this))); this._connection.addMessageEvent(new RoomHeightMapUpdateEvent(this.onRoomHeightMapUpdateEvent.bind(this))); - this._connection.addMessageEvent(new RoomThicknessEvent(this.onRoomThicknessEvent.bind(this))); - this._connection.addMessageEvent(new RoomDoorEvent(this.onRoomDoorEvent.bind(this))); + this._connection.addMessageEvent(new RoomVisualizationSettingsEvent(this.onRoomThicknessEvent.bind(this))); + this._connection.addMessageEvent(new RoomEntryTileMessageEvent(this.onRoomDoorEvent.bind(this))); this._connection.addMessageEvent(new ObjectsRollingEvent(this.onRoomRollingEvent.bind(this))); this._connection.addMessageEvent(new ObjectsDataUpdateEvent(this.onObjectsDataUpdateEvent.bind(this))); this._connection.addMessageEvent(new FurnitureAliasesEvent(this.onFurnitureAliasesEvent.bind(this))); @@ -220,9 +220,9 @@ export class RoomMessageHandler extends Disposable } } - private onRoomModelEvent(event: RoomModelEvent): void + private onRoomModelEvent(event: FloorHeightMapEvent): void { - if(!(event instanceof RoomModelEvent) || !event.connection || !this._roomCreator) return; + if(!(event instanceof FloorHeightMapEvent) || !event.connection || !this._roomCreator) return; const parser = event.getParser(); @@ -239,7 +239,7 @@ export class RoomMessageHandler extends Disposable this._planeParser.initializeTileMap(width, height); - let entryTile: RoomDoorParser = null; + let entryTile: RoomEntryTileMessageParser = null; if(this._latestEntryTileEvent) entryTile = this._latestEntryTileEvent.getParser(); @@ -387,9 +387,9 @@ export class RoomMessageHandler extends Disposable this._roomCreator.refreshTileObjectMap(this._currentRoomId, 'RoomMessageHandler.onRoomHeightMapUpdateEvent()'); } - private onRoomThicknessEvent(event: RoomThicknessEvent): void + private onRoomThicknessEvent(event: RoomVisualizationSettingsEvent): void { - if(!(event instanceof RoomThicknessEvent)) return; + if(!(event instanceof RoomVisualizationSettingsEvent)) return; const parser = event.getParser(); @@ -407,9 +407,9 @@ export class RoomMessageHandler extends Disposable } } - private onRoomDoorEvent(event: RoomDoorEvent): void + private onRoomDoorEvent(event: RoomEntryTileMessageEvent): void { - if(!(event instanceof RoomDoorEvent)) return; + if(!(event instanceof RoomEntryTileMessageEvent)) return; this._latestEntryTileEvent = event; } diff --git a/src/nitro/room/preview/RoomPreviewer.ts b/src/nitro/room/preview/RoomPreviewer.ts index 1f84935d..1dbefffa 100644 --- a/src/nitro/room/preview/RoomPreviewer.ts +++ b/src/nitro/room/preview/RoomPreviewer.ts @@ -8,8 +8,8 @@ import { IRoomRenderingCanvas } from '../../../room/renderer/IRoomRenderingCanva import { IVector3D } from '../../../room/utils/IVector3D'; import { RoomId } from '../../../room/utils/RoomId'; import { Vector3d } from '../../../room/utils/Vector3d'; -import { RoomDoorParser } from '../../communication/messages/parser/room/mapping/RoomDoorParser'; -import { RoomModelParser } from '../../communication/messages/parser/room/mapping/RoomModelParser'; +import { FloorHeightMapMessageParser } from '../../communication/messages/parser/room/mapping/FloorHeightMapMessageParser'; +import { RoomEntryTileMessageParser } from '../../communication/messages/parser/room/mapping/RoomEntryTileMessageParser'; import { Nitro } from '../../Nitro'; import { RoomEngineEvent } from '../events/RoomEngineEvent'; import { RoomEngineObjectEvent } from '../events/RoomEngineObjectEvent'; @@ -155,7 +155,7 @@ export class RoomPreviewer public updatePreviewModel(model: string, wallHeight: number, scale: boolean = true): void { - const parser = new RoomModelParser(); + const parser = new FloorHeightMapMessageParser(); parser.flush(); parser.parseModel(model, wallHeight, scale); @@ -172,7 +172,7 @@ export class RoomPreviewer this._planeParser.initializeTileMap(width, height); - const entryTile: RoomDoorParser = null; + const entryTile: RoomEntryTileMessageParser = null; let doorX = -1; let doorY = -1; diff --git a/src/room/floorplan/index.ts b/src/room/floorplan/index.ts deleted file mode 100644 index f4352cef..00000000 --- a/src/room/floorplan/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './pixi-tilemap'; diff --git a/src/room/floorplan/pixi-tilemap/CanvasTileRenderer.ts b/src/room/floorplan/pixi-tilemap/CanvasTileRenderer.ts deleted file mode 100644 index 8d490134..00000000 --- a/src/room/floorplan/pixi-tilemap/CanvasTileRenderer.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { CanvasRenderer } from '@pixi/canvas-renderer'; -import { IRendererPlugin } from '@pixi/core'; - -export class CanvasTileRenderer implements IRendererPlugin -{ - renderer: CanvasRenderer; - tileAnim = [0, 0]; - dontUseTransform = false; - - constructor(renderer: CanvasRenderer, options: any = null) - { - this.renderer = renderer; - this.tileAnim = [0, 0]; - } - - public destroy(): void - { - - } -} - -CanvasRenderer.registerPlugin('tilemap', CanvasTileRenderer); diff --git a/src/room/floorplan/pixi-tilemap/CompositeRectTileLayer.ts b/src/room/floorplan/pixi-tilemap/CompositeRectTileLayer.ts deleted file mode 100644 index 60cab12c..00000000 --- a/src/room/floorplan/pixi-tilemap/CompositeRectTileLayer.ts +++ /dev/null @@ -1,287 +0,0 @@ -import { Renderer, Resource, Texture } from '@pixi/core'; -import { Container } from '@pixi/display'; -import { Matrix } from '@pixi/math'; -import { Constant } from './Constant'; -import { RectTileLayer } from './RectTileLayer'; - -export class CompositeRectTileLayer extends Container -{ - constructor(zIndex?: number, bitmaps?: Texture[], texPerChild?: number, alpha?: number) - { - super(); - // eslint-disable-next-line prefer-spread,prefer-rest-params - this.initialize.apply(this, arguments); - } - - z: number; - modificationMarker = 0; - shadowColor = new Float32Array([0.0, 0.0, 0.0, 0.5]); - _globalMat: Matrix = null; - _lastLayer: RectTileLayer = null; - - texPerChild: number; - - initialize(zIndex?: number, bitmaps?: Array, texPerChild?: number, alpha?: number) - { - if(texPerChild as any === true) - { - //old format, ignore it! - texPerChild = 0; - } - this.z = this.zIndex = zIndex; - this.alpha = alpha ?? 1.0; - this.texPerChild = texPerChild || Constant.boundCountPerBuffer * Constant.maxTextures; - if(bitmaps) - { - this.setBitmaps(bitmaps); - } - } - - setBitmaps(bitmaps: Array) - { - for(let i=0;i 5.2.1, it does not exist there.'); - } - } - const texPerChild = this.texPerChild; - const len1 = this.children.length; - const len2 = Math.ceil(bitmaps.length / texPerChild); - let i: number; - for(i = 0; i < len1; i++) - { - (this.children[i] as RectTileLayer).textures = bitmaps.slice(i * texPerChild, (i + 1) * texPerChild); - } - for(i = len1; i < len2; i++) - { - const layer = new RectTileLayer(this.zIndex, bitmaps.slice(i * texPerChild, (i + 1) * texPerChild)); - layer.compositeParent = true; - layer.offsetX = Constant.boundSize; - layer.offsetY = Constant.boundSize; - this.addChild(layer); - } - } - - clear() - { - for(let i = 0; i < this.children.length; i++) - { - (this.children[i] as RectTileLayer).clear(); - } - this.modificationMarker = 0; - } - - addRect(textureIndex: number, u: number, v: number, x: number, y: number, tileWidth: number, tileHeight: number, animX?: number, animY?: number, rotate?: number, animWidth?: number, animHeight?: number, alpha?: number): this - { - const childIndex: number = textureIndex / this.texPerChild >> 0; - const textureId: number = textureIndex % this.texPerChild; - - if(this.children[childIndex] && (this.children[childIndex] as RectTileLayer).textures) - { - this._lastLayer = (this.children[childIndex] as RectTileLayer); - const tileAlpha = this.worldAlpha * (alpha ?? 1.0); - this._lastLayer.addRect(textureId, u, v, x, y, tileWidth, tileHeight, animX, animY, rotate, animWidth, animHeight, tileAlpha); - } - else - { - this._lastLayer = null; - } - - return this; - } - - tileRotate(rotate: number): this - { - if(this._lastLayer) - { - this._lastLayer.tileRotate(rotate); - } - return this; - } - - tileAnimX(offset: number, count: number): this - { - if(this._lastLayer) - { - this._lastLayer.tileAnimX(offset, count); - } - return this; - } - - tileAnimY(offset: number, count: number): this - { - if(this._lastLayer) - { - this._lastLayer.tileAnimY(offset, count); - } - return this; - } - - addFrame(texture_: Texture | string | number, x: number, y: number, animX?: number, animY?: number, animWidth?: number, animHeight?: number, alpha?: number, yaxis?: number, xaxis?: number): this - { - let texture: Texture; - let layer: RectTileLayer = null; - let ind = 0; - const children = this.children; - - this._lastLayer = null; - if(typeof texture_ === 'number') - { - const childIndex = texture_ / this.texPerChild >> 0; - layer = children[childIndex] as RectTileLayer; - - if(!layer) - { - layer = children[0] as RectTileLayer; - if(!layer) - { - return this; - } - ind = 0; - } - else - { - ind = texture_ % this.texPerChild; - } - - texture = layer.textures[ind]; - } - else - { - if(typeof texture_ === 'string') - { - texture = Texture.from(texture_); - } - else - { - texture = texture_ as Texture; - } - - for(let i = 0; i < children.length; i++) - { - const child = children[i] as RectTileLayer; - const tex = child.textures; - for(let j = 0; j < tex.length; j++) - { - if(tex[j].baseTexture === texture.baseTexture) - { - layer = child; - ind = j; - break; - } - } - if(layer) - { - break; - } - } - - if(!layer) - { - for(let i = 0; i < children.length; i++) - { - const child = children[i] as RectTileLayer; - if(child.textures.length < this.texPerChild) - { - layer = child; - ind = child.textures.length; - child.textures.push(texture); - break; - } - } - if(!layer) - { - layer = new RectTileLayer(this.zIndex, texture); - layer.compositeParent = true; - layer.offsetX = Constant.boundSize; - layer.offsetY = Constant.boundSize; - this.addChild(layer); - ind = 0; - } - } - } - - this._lastLayer = layer; - const tileAlpha = this.worldAlpha * (alpha?? 1.0); - layer.addRect(ind, texture.frame.x, texture.frame.y, x, y, texture.orig.width, texture.orig.height, animX, animY, texture.rotate, animWidth, animHeight, tileAlpha, yaxis, xaxis); - return this; - } - - // renderCanvas(renderer: CanvasRenderer) - // { - // if(!this.visible || this.worldAlpha <= 0 || !this.renderable) - // { - // return; - // } - // const plugin = renderer.plugins.tilemap; - // if(!plugin.dontUseTransform) - // { - // const wt = this.worldTransform; - // renderer.context.setTransform( - // wt.a, - // wt.b, - // wt.c, - // wt.d, - // wt.tx * renderer.resolution, - // wt.ty * renderer.resolution - // ); - // } - // const layers = this.children; - // for(let i = 0; i < layers.length; i++) - // { - // (layers[i] as RectTileLayer).renderCanvasCore(renderer); - // } - // } - - render(renderer: Renderer) - { - if(!this.visible || this.worldAlpha <= 0 || !this.renderable) - { - return; - } - const plugin = (renderer.plugins as any)['tilemap']; - const shader = plugin.getShader(); - renderer.batch.setObjectRenderer(plugin); - //TODO: dont create new array, please - this._globalMat = shader.uniforms.projTransMatrix; - renderer.globalUniforms.uniforms.projectionMatrix.copyTo(this._globalMat).append(this.worldTransform); - shader.uniforms.shadowColor = this.shadowColor; - shader.uniforms.animationFrame = plugin.tileAnim; - renderer.shader.bind(shader, false); - const layers = this.children; - for(let i = 0; i < layers.length; i++) - { - (layers[i] as RectTileLayer).renderWebGLCore(renderer, plugin); - } - } - - isModified(anim: boolean) - { - const layers = this.children; - if(this.modificationMarker !== layers.length) - { - return true; - } - for(let i = 0; i < layers.length; i++) - { - if((layers[i] as RectTileLayer).isModified(anim)) - { - return true; - } - } - return false; - } - - clearModify() - { - const layers = this.children; - this.modificationMarker = layers.length; - for(let i = 0; i < layers.length; i++) - { - (layers[i] as RectTileLayer).clearModify(); - } - } -} diff --git a/src/room/floorplan/pixi-tilemap/Constant.ts b/src/room/floorplan/pixi-tilemap/Constant.ts deleted file mode 100644 index 103b2199..00000000 --- a/src/room/floorplan/pixi-tilemap/Constant.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { SCALE_MODES } from '@pixi/constants'; - -export const Constant = { - maxTextures: 16, - bufferSize: 2048, - boundSize: 1024, - boundCountPerBuffer: 1, - use32bitIndex: false, - SCALE_MODE: SCALE_MODES.LINEAR, - DO_CLEAR: true -}; diff --git a/src/room/floorplan/pixi-tilemap/MultiTextureResource.ts b/src/room/floorplan/pixi-tilemap/MultiTextureResource.ts deleted file mode 100644 index 1b14b354..00000000 --- a/src/room/floorplan/pixi-tilemap/MultiTextureResource.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { BaseTexture, GLTexture, IAutoDetectOptions, Renderer, Resource, Texture } from '@pixi/core'; -import { Sprite } from '@pixi/sprite'; -import { NitroSprite } from '../../../core'; - -export interface IMultiTextureOptions { - boundCountPerBuffer: number; - boundSize: number; - bufferSize: number; - DO_CLEAR?: boolean; -} - -export class MultiTextureResource extends Resource -{ - constructor(options: IMultiTextureOptions) - { - super(options.bufferSize, options.bufferSize); - - const bounds = this.boundSprites; - const dirties = this.dirties; - this.boundSize = options.boundSize; - for(let j = 0; j < options.boundCountPerBuffer; j++) - { - const spr = new NitroSprite(); - spr.position.x = options.boundSize * (j & 1); - spr.position.y = options.boundSize * (j >> 1); - bounds.push(spr); - dirties.push(0); - } - this.DO_CLEAR = !!options.DO_CLEAR; - } - - DO_CLEAR = false; - boundSize: number = 0; - _clearBuffer: Uint8Array = null; - - bind(baseTexture: BaseTexture) - { - if(this.baseTex) - { - throw new Error('Only one baseTexture is allowed for this resource!'); - } - this.baseTex = baseTexture; - super.bind(baseTexture); - } - - baseTex: BaseTexture = null; - boundSprites: Array = []; - dirties: Array = []; - - setTexture(ind: number, texture: Texture) - { - const spr = this.boundSprites[ind]; - if(spr.texture.baseTexture === texture.baseTexture) - { - return; - } - spr.texture = texture; - this.baseTex.update(); - this.dirties[ind] = (this.baseTex as any).dirtyId; - } - - // required ??? - public upload(renderer: Renderer, baseTexture: BaseTexture, glTexture: GLTexture): boolean - { - return false; - } - -} diff --git a/src/room/floorplan/pixi-tilemap/RectTileLayer.ts b/src/room/floorplan/pixi-tilemap/RectTileLayer.ts deleted file mode 100644 index 66692837..00000000 --- a/src/room/floorplan/pixi-tilemap/RectTileLayer.ts +++ /dev/null @@ -1,495 +0,0 @@ -import { DRAW_MODES } from '@pixi/constants'; -import { Renderer, Resource, Texture } from '@pixi/core'; -import { Bounds, Container } from '@pixi/display'; -import { groupD8, Matrix, Rectangle } from '@pixi/math'; -import { Constant } from './Constant'; -import { RectTileGeom } from './RectTileShader'; -import { TileRenderer } from './TileRenderer'; - -class PointStruct -{ - public static U = 0; - public static V = 1; - public static X = 2; - public static Y = 3; - public static TileWidth = 4; - public static TileHeight = 5; - public static Rotate = 6; - public static AnimX = 7; - public static AnimY = 8; - public static TextureIndex = 9; - public static AnimCountX = 10; - public static AnimCountY = 11; - public static Alpha = 12; - public static YAxis = 13; - public static XAxis = 14; -} -export const POINT_STRUCT_SIZE_TWO = (Object.keys(PointStruct).length / 2); -//export const POINT_STRUCT_SIZE = 12; -export class RectTileLayer extends Container -{ - constructor(zIndex: number, texture: Texture | Texture[]) - { - super(); - this.initialize(zIndex, texture); - } - - //zIndex = 0; - modificationMarker = 0; - _$_localBounds = new Bounds(); - shadowColor = new Float32Array([0.0, 0.0, 0.0, 0.5]); - _globalMat: Matrix = null; - - pointsBuf: Array = []; - hasAnim = false; - textures: Array; - - offsetX = 0; - offsetY = 0; - compositeParent = false; - - initialize(zIndex: number, textures: Texture | Array) - { - if(!textures) - { - textures = []; - } - else if(!(textures instanceof Array) && (textures as Texture).baseTexture) - { - textures = [textures as Texture]; - } - this.textures = textures as Array; - this.zIndex = zIndex; - // this.visible = false; - } - - clear() - { - this.pointsBuf.length = 0; - this.modificationMarker = 0; - this._$_localBounds.clear(); - this.hasAnim = false; - } - - addFrame(texture_: Texture | string | number, x: number, y: number, animX: number, animY: number) - { - let texture: Texture; - let textureIndex = 0; - - if(typeof texture_ === 'number') - { - textureIndex = texture_; - texture = this.textures[textureIndex]; - } - else - { - if(typeof texture_ === 'string') - { - texture = Texture.from(texture_); - } - else - { - texture = texture_ as Texture; - } - - let found = false; - const textureList = this.textures; - for(let i = 0; i < textureList.length; i++) - { - if(textureList[i].baseTexture === texture.baseTexture) - { - textureIndex = i; - found = true; - break; - } - } - - if(!found) - { - // textureIndex = this.textures.length; - // this.textures.push(texture); - return false; - } - } - - this.addRect(textureIndex, texture.frame.x, texture.frame.y, x, y, texture.orig.width, texture.orig.height, animX, animY, texture.rotate); - return true; - } - - addRect(textureIndex: number, u: number, v: number, x: number, y: number, tileWidth: number, tileHeight: number, - animX: number = 0, animY: number = 0, rotate: number = 0, animCountX: number = 1024, animCountY: number = 1024, alpha: number = 1, yaxis?: number, xaxis?: number): this - { - const pb = this.pointsBuf; - this.hasAnim = this.hasAnim || animX > 0 || animY > 0; - pb.push(u); - pb.push(v); - pb.push(x); - pb.push(y); - pb.push(tileWidth); - pb.push(tileHeight); - pb.push(rotate); - pb.push(animX | 0); - pb.push(animY | 0); - pb.push(textureIndex); - pb.push(animCountX); - pb.push(animCountY); - pb.push(alpha); - pb.push(yaxis); - pb.push(xaxis); - - this._$_localBounds.addFramePad(x, y, x+tileWidth, y+tileHeight, 0, 0); - - return this; - } - - tileRotate(rotate: number) - { - const pb = this.pointsBuf; - pb[pb.length - (POINT_STRUCT_SIZE_TWO - PointStruct.TextureIndex)] = rotate; - } - - tileAnimX(offset: number, count: number) - { - const pb = this.pointsBuf; - - pb[pb.length - (POINT_STRUCT_SIZE_TWO - PointStruct.AnimX)] = offset; - pb[pb.length - (POINT_STRUCT_SIZE_TWO - PointStruct.AnimCountX)] = count; - } - - tileAnimY(offset: number, count: number) - { - const pb = this.pointsBuf; - - pb[pb.length - (POINT_STRUCT_SIZE_TWO - PointStruct.AnimY)] = offset; - pb[pb.length - (POINT_STRUCT_SIZE_TWO - PointStruct.AnimCountY)] = count; - } - - tileAlpha(alpha: number) - { - const pb = this.pointsBuf; - pb[pb.length - (POINT_STRUCT_SIZE_TWO - PointStruct.Alpha)] = alpha; - } - - // renderCanvas(renderer: any) - // { - // const plugin = renderer.plugins.tilemap; - // if(!plugin.dontUseTransform) - // { - // const wt = this.worldTransform; - // renderer.context.setTransform( - // wt.a, - // wt.b, - // wt.c, - // wt.d, - // wt.tx * renderer.resolution, - // wt.ty * renderer.resolution - // ); - // } - // this.renderCanvasCore(renderer); - // } - - renderCanvasCore(renderer: any) - { - if(this.textures.length === 0) return; - const points = this.pointsBuf; - renderer.context.fillStyle = '#000000'; - for(let i = 0, n = points.length; i < n; i += POINT_STRUCT_SIZE_TWO) - { - let x1 = points[i + PointStruct.U], y1 = points[i + PointStruct.V]; - const x2 = points[i + PointStruct.X], y2 = points[i + PointStruct.Y]; - const w = points[i + PointStruct.TileWidth]; - const h = points[i + PointStruct.TileHeight]; - const rotate = points[i + PointStruct.Rotate]; - x1 += points[i + PointStruct.AnimX] * renderer.plugins.tilemap.tileAnim[0]; - y1 += points[i + PointStruct.AnimY] * renderer.plugins.tilemap.tileAnim[1]; - const textureIndex = points[i + PointStruct.TextureIndex]; - const alpha = points[i + PointStruct.Alpha]; - // canvas does not work with rotate yet - if(textureIndex >= 0) - { - renderer.context.globalAlpha = alpha; - renderer.context.drawImage((this.textures[textureIndex].baseTexture as any).getDrawableSource(), x1, y1, w, h, x2, y2, w, h); - } - else - { - renderer.context.globalAlpha = 0.5; - renderer.context.fillRect(x2, y2, w, h); - renderer.context.globalAlpha = 1; - } - renderer.context.globalAlpha = 1; - } - } - - vbId = 0; - vb: RectTileGeom = null; - vbBuffer: ArrayBuffer = null; - vbArray: Float32Array = null; - vbInts: Uint32Array = null; - - destroyVb() - { - if(this.vb) - { - this.vb.destroy(); - this.vb = null; - } - } - - render(renderer: Renderer) - { - const plugin = (renderer.plugins as any)['tilemap']; - const shader = plugin.getShader(); - renderer.batch.setObjectRenderer(plugin); - this._globalMat = shader.uniforms.projTransMatrix; - renderer.globalUniforms.uniforms.projectionMatrix.copyTo(this._globalMat).append(this.worldTransform); - shader.uniforms.shadowColor = this.shadowColor; - shader.uniforms.animationFrame = plugin.tileAnim; - this.renderWebGLCore(renderer, plugin); - } - - renderWebGLCore(renderer: Renderer, plugin: TileRenderer) - { - const points = this.pointsBuf; - if(points.length === 0) return; - const rectsCount = points.length / POINT_STRUCT_SIZE_TWO; - - const shader = plugin.getShader(); - const textures = this.textures; - if(textures.length === 0) return; - - plugin.bindTextures(renderer, shader, textures); - renderer.shader.bind(shader, false); - - //lost context! recover! - let vb = this.vb; - if(!vb) - { - vb = plugin.createVb(); - this.vb = vb; - this.vbId = (vb as any).id; - this.vbBuffer = null; - this.modificationMarker = 0; - } - - plugin.checkIndexBuffer(rectsCount, vb); - const boundCountPerBuffer = Constant.boundCountPerBuffer; - - const vertexBuf = vb.getBuffer('aVertexPosition'); - //if layer was changed, re-upload vertices - const vertices = rectsCount * vb.vertPerQuad; - if(vertices === 0) return; - if(this.modificationMarker !== vertices) - { - this.modificationMarker = vertices; - const vs = vb.stride * vertices; - if(!this.vbBuffer || this.vbBuffer.byteLength < vs) - { - //!@#$ happens, need resize - let bk = vb.stride; - while(bk < vs) - { - bk *= 2; - } - this.vbBuffer = new ArrayBuffer(bk); - this.vbArray = new Float32Array(this.vbBuffer); - this.vbInts = new Uint32Array(this.vbBuffer); - vertexBuf.update(this.vbBuffer); - } - - const arr = this.vbArray, ints = this.vbInts; - //upload vertices! - let sz = 0; - //let tint = 0xffffffff; - let textureId = 0; - let shiftU: number = this.offsetX; - let shiftV: number = this.offsetY; - - //let tint = 0xffffffff; - const tint = -1; - - - for(let i = 0; i < points.length; i += POINT_STRUCT_SIZE_TWO) - { - const eps = 0.5; - if(this.compositeParent) - { - const textureIndex = points[i + PointStruct.TextureIndex]; - if(boundCountPerBuffer > 1) - { - //TODO: what if its more than 4? - textureId = (textureIndex >> 2); - shiftU = this.offsetX * (textureIndex & 1); - shiftV = this.offsetY * ((textureIndex >> 1) & 1); - } - else - { - textureId = textureIndex; - shiftU = 0; - shiftV = 0; - } - } - const x = points[i + PointStruct.X], y = points[i + PointStruct.Y]; - const w = points[i + PointStruct.TileWidth], h = points[i + PointStruct.TileHeight]; - const u = points[i + PointStruct.U] + shiftU, v = points[i + PointStruct.V] + shiftV; - let rotate = points[i + PointStruct.Rotate]; - - const animX = points[i + PointStruct.AnimX], animY = points[i + PointStruct.AnimY]; - const animWidth = points[i + PointStruct.AnimCountX] || 1024, animHeight = points[i + PointStruct.AnimCountY] || 1024; - const animXEncoded = animX + (animWidth * 2048); - const animYEncoded = animY + (animHeight * 2048); - const alpha = points[i + PointStruct.Alpha]; - - let u0: number, v0: number, u1: number, v1: number, u2: number, v2: number, u3: number, v3: number; - if(rotate === 0) - { - u0 = u; - v0 = v; - u1 = u + w; - v1 = v; - u2 = u + w; - v2 = v + h; - u3 = u; - v3 = v + h; - } - else - { - let w2 = w / 2; - let h2 = h / 2; - if(rotate % 4 !== 0) - { - w2 = h / 2; - h2 = w / 2; - } - const cX = u + w2; - const cY = v + h2; - - rotate = groupD8.add(rotate, groupD8.NW); - u0 = cX + (w2 * groupD8.uX(rotate)); - v0 = cY + (h2 * groupD8.uY(rotate)); - - rotate = groupD8.add(rotate, 2); // rotate 90 degrees clockwise - u1 = cX + (w2 * groupD8.uX(rotate)); - v1 = cY + (h2 * groupD8.uY(rotate)); - - rotate = groupD8.add(rotate, 2); - u2 = cX + (w2 * groupD8.uX(rotate)); - v2 = cY + (h2 * groupD8.uY(rotate)); - - rotate = groupD8.add(rotate, 2); - u3 = cX + (w2 * groupD8.uX(rotate)); - v3 = cY + (h2 * groupD8.uY(rotate)); - } - - const test= true; - arr[sz++] = x; - arr[sz++] = y; - arr[sz++] = u0; - arr[sz++] = v0; - arr[sz++] = u + eps; - arr[sz++] = v + eps; - arr[sz++] = u + w - eps; - arr[sz++] = v + h - eps; - arr[sz++] = animXEncoded; - arr[sz++] = animYEncoded; - arr[sz++] = textureId; - - if(test) - { - arr[sz++] = alpha; - } - arr[sz++] = x + w; - arr[sz++] = y; - arr[sz++] = u1; - arr[sz++] = v1; - arr[sz++] = u + eps; - arr[sz++] = v + eps; - arr[sz++] = u + w - eps; - arr[sz++] = v + h - eps; - arr[sz++] = animXEncoded; - arr[sz++] = animYEncoded; - arr[sz++] = textureId; - if(test) - { - arr[sz++] = alpha; - } - - - arr[sz++] = x + w; - arr[sz++] = y + h; - arr[sz++] = u2; - arr[sz++] = v2; - arr[sz++] = u + eps; - arr[sz++] = v + eps; - arr[sz++] = u + w - eps; - arr[sz++] = v + h - eps; - arr[sz++] = animXEncoded; - arr[sz++] = animYEncoded; - arr[sz++] = textureId; - if(test) - { - arr[sz++] = alpha; - } - - arr[sz++] = x; - arr[sz++] = y + h; - arr[sz++] = u3; - arr[sz++] = v3; - arr[sz++] = u + eps; - arr[sz++] = v + eps; - arr[sz++] = u + w - eps; - arr[sz++] = v + h - eps; - arr[sz++] = animXEncoded; - arr[sz++] = animYEncoded; - arr[sz++] = textureId; - if(test) - { - arr[sz++] = alpha; - } - } - - vertexBuf.update(arr); - } - - (renderer.geometry as any).bind(vb, shader); - renderer.geometry.draw(DRAW_MODES.TRIANGLES, rectsCount * 6, 0); - } - - isModified(anim: boolean) - { - if(this.modificationMarker !== this.pointsBuf.length || - anim && this.hasAnim) - { - return true; - } - return false; - } - - clearModify() - { - this.modificationMarker = this.pointsBuf.length; - } - - protected _calculateBounds(): void - { - const { minX, minY, maxX, maxY } = this._$_localBounds; - - this._bounds.addFrame(this.transform, minX, minY, maxX, maxY); - } - - public getLocalBounds(rect?: Rectangle): Rectangle - { - // we can do a fast local bounds if the sprite has no children! - if(this.children.length === 0) - { - return this._$_localBounds.getRectangle(rect); - } - - return super.getLocalBounds.call(this, rect); - } - - destroy(options?: any) - { - super.destroy(options); - this.destroyVb(); - } -} diff --git a/src/room/floorplan/pixi-tilemap/RectTileShader.ts b/src/room/floorplan/pixi-tilemap/RectTileShader.ts deleted file mode 100644 index 9ee325a9..00000000 --- a/src/room/floorplan/pixi-tilemap/RectTileShader.ts +++ /dev/null @@ -1,111 +0,0 @@ -import { Buffer, Geometry, Program, Shader } from '@pixi/core'; -import { Matrix } from '@pixi/math'; -import * as shaderGenerator from './shaderGenerator'; - -const rectShaderFrag = ` -varying vec2 vTextureCoord; -varying vec4 vFrame; -varying float vTextureId; -varying float vAlpha; -uniform vec4 shadowColor; -uniform sampler2D uSamplers[%count%]; -uniform vec2 uSamplerSize[%count%]; - -void main(void){ - - - vec2 textureCoord = clamp(vTextureCoord, vFrame.xy, vFrame.zw); - float textureId = floor(vTextureId + 0.5); - - vec4 color; - vec3 tint = vec3(1, 0.8, 0.5); // reddish - %forloop% - gl_FragColor = (color * vAlpha) + (gl_FragColor * (1.0 - vAlpha)); -} -`; - -const rectShaderVert = ` -attribute vec2 aVertexPosition; -attribute vec2 aTextureCoord; -attribute vec4 aFrame; -attribute vec2 aAnim; -attribute float aTextureId; -attribute float aAlpha; - -uniform mat3 projTransMatrix; -uniform vec2 animationFrame; - -varying vec2 vTextureCoord; -varying float vTextureId; -varying vec4 vFrame; -varying float vAlpha; - -void main(void){ - gl_Position = vec4((projTransMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0); - vec2 animCount = floor((aAnim + 0.5) / 2048.0); - vec2 animFrameOffset = aAnim - animCount * 2048.0; - vec2 animOffset = animFrameOffset * floor(mod(animationFrame + 0.5, animCount)); - - vTextureCoord = aTextureCoord + animOffset; - vFrame = aFrame + vec4(animOffset, animOffset); - vTextureId = aTextureId; - vAlpha = aAlpha; -} -`; - -export abstract class TilemapShader extends Shader -{ - maxTextures = 0; - - constructor(maxTextures: number, shaderVert: string, shaderFrag: string) - { - super( - new Program( - shaderVert, - shaderFrag), - { - animationFrame: new Float32Array(2), - uSamplers: [], - uSamplerSize: [], - projTransMatrix: new Matrix() - } - ); - this.maxTextures = maxTextures; - shaderGenerator.fillSamplers(this, this.maxTextures); - } -} - -export class RectTileShader extends TilemapShader -{ - constructor(maxTextures: number) - { - super( - maxTextures, - rectShaderVert, - shaderGenerator.generateFragmentSrc(maxTextures, rectShaderFrag) - ); - shaderGenerator.fillSamplers(this, this.maxTextures); - } -} - -export class RectTileGeom extends Geometry -{ - vertSize = 12; - vertPerQuad = 4; - stride = this.vertSize * 4; - lastTimeAccess = 0; - buf: Buffer; - - constructor() - { - super(); - const buf = this.buf = new Buffer(new Float32Array(2), true, false); - this.addAttribute('aVertexPosition', buf, 0, false, 0, this.stride, 0) - .addAttribute('aTextureCoord', buf, 0, false, 0, this.stride, 2 * 4) - .addAttribute('aFrame', buf, 0, false, 0, this.stride, 4 * 4) - .addAttribute('aAnim', buf, 0, false, 0, this.stride, 8 * 4) - .addAttribute('aTextureId', buf, 0, false, 0, this.stride, 10 * 4) - .addAttribute('aTextureId', buf, 0, false, 0, this.stride, 10 * 4) - .addAttribute('aAlpha', buf, 0, false, 0, this.stride, 11 * 4); - } -} diff --git a/src/room/floorplan/pixi-tilemap/TileRenderer.ts b/src/room/floorplan/pixi-tilemap/TileRenderer.ts deleted file mode 100644 index d4e0e6f8..00000000 --- a/src/room/floorplan/pixi-tilemap/TileRenderer.ts +++ /dev/null @@ -1,166 +0,0 @@ -import { WRAP_MODES } from '@pixi/constants'; -import { Buffer, ObjectRenderer, Renderer, Resource, Texture } from '@pixi/core'; -import { createIndicesForQuads } from '@pixi/utils'; -import { Constant } from './Constant'; -import { MultiTextureResource } from './MultiTextureResource'; -import type { TilemapShader } from './RectTileShader'; -import { RectTileGeom, RectTileShader } from './RectTileShader'; - -/** - * Renderer for rectangle tiles. - */ -export class TileRenderer extends ObjectRenderer -{ - renderer: Renderer; - gl: WebGLRenderingContext; - sn: number = -1; - indexBuffer: Buffer = null; - ibLen: number = 0; - tileAnim = [0, 0]; - texLoc: Array = []; - - rectShader: RectTileShader; - texResources: Array = []; - - constructor(renderer: Renderer) - { - super(renderer); - this.rectShader = new RectTileShader(Constant.maxTextures); - this.indexBuffer = new Buffer(undefined, true, true); - this.checkIndexBuffer(2000); - this.initBounds(); - } - - initBounds() - { - if(Constant.boundCountPerBuffer <= 1) - { - return; - } - - const maxTextures = Constant.maxTextures; - for(let i = 0; i < maxTextures; i++) - { - const resource = new MultiTextureResource(Constant); - // @ts-ignore - const baseTex = new BaseTexture(resource); - baseTex.scaleMode = Constant.SCALE_MODE; - baseTex.wrapMode = WRAP_MODES.CLAMP; - this.texResources.push(resource); - } - } - - bindTexturesWithoutRT(renderer: Renderer, shader: TilemapShader, textures: Texture[]) - { - const samplerSize: Array = (shader as any).uniforms.uSamplerSize; - this.texLoc.length = 0; - for(let i = 0; i < textures.length; i++) - { - const texture = textures[i]; - if(!texture || !texture.valid) - { - return; - } - renderer.texture.bind(textures[i], i); - //TODO: add resolution here - samplerSize[i * 2] = 1.0 / textures[i].baseTexture.width; - samplerSize[i * 2 + 1] = 1.0 / textures[i].baseTexture.height; - } - (shader as any).uniforms.uSamplerSize = samplerSize; - } - - bindTextures(renderer: Renderer, shader: TilemapShader, textures: Array) - { - const len = textures.length; - const maxTextures = Constant.maxTextures; - if(len > Constant.boundCountPerBuffer * maxTextures) - { - return; - } - if(Constant.boundCountPerBuffer <= 1) - { - this.bindTexturesWithoutRT(renderer, shader, textures); - return; - } - - let i = 0; - for(; i < len; i++) - { - const texture = textures[i]; - if(!texture || !texture.valid) continue; - const multi = this.texResources[i >> 2]; - multi.setTexture(i & 3, texture); - } - - const gltsUsed = (i + 3) >> 2; - for(i = 0; i < gltsUsed; i++) - { - //remove "i, true" after resolving a bug - renderer.texture.bind(this.texResources[i].baseTex, i); - } - } - - start() - { - //sorry, nothing - } - - createVb() - { - const geom = new RectTileGeom(); - geom.addIndex(this.indexBuffer); - geom.lastTimeAccess = Date.now(); - return geom; - } - - checkIndexBuffer(size: number, vb: RectTileGeom = null) - { - const totalIndices = size * 6; - - if(totalIndices <= this.ibLen) - { - return; - } - - let len = totalIndices; - while(len < totalIndices) - { - len <<= 1; - } - - this.ibLen = totalIndices; - this.indexBuffer.update(createIndicesForQuads(size, Constant.use32bitIndex ? new Uint32Array(size * 6) : undefined)); - - // TODO: create new index buffer instead? - // if (vb) { - // const curIndex = vb.getIndex(); - // if (curIndex !== this.indexBuffer && (curIndex.data as any).length < totalIndices) { - // this.swapIndex(vb, this.indexBuffer); - // } - // } - } - - // swapIndex(geom: PIXI.Geometry, indexBuf: PIXI.Buffer) { - // let buffers = (geom as any).buffers; - // const oldIndex = geom.getIndex(); - // let ind = buffers.indexOf(oldIndex); - // if (ind >= 0) { - // buffers.splice(ind, 1); - // } - // geom.addIndex(indexBuf); - // } - - getShader(): TilemapShader - { - return this.rectShader; - } - - destroy() - { - super.destroy(); - // this.rectShader.destroy(); - this.rectShader = null; - } -} - -Renderer.registerPlugin('tilemap', TileRenderer as any); diff --git a/src/room/floorplan/pixi-tilemap/index.ts b/src/room/floorplan/pixi-tilemap/index.ts deleted file mode 100644 index 38e72430..00000000 --- a/src/room/floorplan/pixi-tilemap/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -export * from './CanvasTileRenderer'; -export * from './CompositeRectTileLayer'; -export * from './Constant'; -export * from './MultiTextureResource'; -export * from './RectTileLayer'; -export * from './RectTileShader'; -export * from './shaderGenerator'; -export * from './TileRenderer'; diff --git a/src/room/floorplan/pixi-tilemap/shaderGenerator.ts b/src/room/floorplan/pixi-tilemap/shaderGenerator.ts deleted file mode 100644 index c7fe15ef..00000000 --- a/src/room/floorplan/pixi-tilemap/shaderGenerator.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { Constant } from './Constant'; -import type { TilemapShader } from './RectTileShader'; - -export function fillSamplers(shader: TilemapShader, maxTextures: number) -{ - const sampleValues: Array = []; - for(let i = 0; i < maxTextures; i++) - { - sampleValues[i] = i; - } - shader.uniforms.uSamplers = sampleValues; - - const samplerSize: Array = []; - for(let i = 0; i < maxTextures; i++) - { - samplerSize.push(1.0 / Constant.bufferSize); - samplerSize.push(1.0 / Constant.bufferSize); - } - shader.uniforms.uSamplerSize = samplerSize; -} - -export function generateFragmentSrc(maxTextures: number, fragmentSrc: string) -{ - return fragmentSrc.replace(/%count%/gi, maxTextures + '') - .replace(/%forloop%/gi, generateSampleSrc(maxTextures)); -} - -export function generateSampleSrc(maxTextures: number) -{ - let src = ''; - - src += '\n'; - src += '\n'; - - src += 'if(vTextureId <= -1.0) {'; - src += '\n\tcolor = shadowColor;'; - src += '\n}'; - - for(let i = 0; i < maxTextures; i++) - { - src += '\nelse '; - - if(i < maxTextures-1) - { - src += 'if(textureId == ' + i + '.0)'; - } - - src += '\n{'; - src += '\n\tcolor = texture2D(uSamplers['+i+'], textureCoord * uSamplerSize['+i+']);'; - src += '\n}'; - } - - src += '\n'; - src += '\n'; - - return src; -} diff --git a/src/room/index.ts b/src/room/index.ts index 563d1355..b5b45eac 100644 --- a/src/room/index.ts +++ b/src/room/index.ts @@ -1,6 +1,5 @@ export * from './data'; export * from './events'; -export * from './floorplan'; export * from './IRoomInstance'; export * from './IRoomInstanceContainer'; export * from './IRoomManager';