Merge branch 'fix/variable-cleanup' of https://git.krews.org/nitro/nitro-renderer into fix/variable-cleanup

This commit is contained in:
Dank074 2021-06-17 18:35:11 -05:00
commit 35850e1bb2
19 changed files with 327 additions and 50 deletions

View File

@ -6,6 +6,7 @@ import { INitroCore } from '../core/INitroCore';
import { NitroTimer } from '../core/utils/NitroTimer'; import { NitroTimer } from '../core/utils/NitroTimer';
import { IRoomManager } from '../room/IRoomManager'; import { IRoomManager } from '../room/IRoomManager';
import { IAvatarRenderManager } from './avatar/IAvatarRenderManager'; import { IAvatarRenderManager } from './avatar/IAvatarRenderManager';
import { IRoomCameraWidgetManager } from './camera/IRoomCameraWidgetManager';
import { INitroCommunicationManager } from './communication/INitroCommunicationManager'; import { INitroCommunicationManager } from './communication/INitroCommunicationManager';
import { INitroLocalizationManager } from './localization/INitroLocalizationManager'; import { INitroLocalizationManager } from './localization/INitroLocalizationManager';
import { IRoomEngine } from './room/IRoomEngine'; import { IRoomEngine } from './room/IRoomEngine';
@ -38,6 +39,7 @@ export interface INitro extends Application
sessionDataManager: ISessionDataManager; sessionDataManager: ISessionDataManager;
roomSessionManager: IRoomSessionManager; roomSessionManager: IRoomSessionManager;
roomManager: IRoomManager; roomManager: IRoomManager;
cameraManager: IRoomCameraWidgetManager;
width: number; width: number;
height: number; height: number;
time: number; time: number;

View File

@ -12,6 +12,8 @@ import { IRoomManager } from '../room/IRoomManager';
import { RoomManager } from '../room/RoomManager'; import { RoomManager } from '../room/RoomManager';
import { AvatarRenderManager } from './avatar/AvatarRenderManager'; import { AvatarRenderManager } from './avatar/AvatarRenderManager';
import { IAvatarRenderManager } from './avatar/IAvatarRenderManager'; import { IAvatarRenderManager } from './avatar/IAvatarRenderManager';
import { IRoomCameraWidgetManager } from './camera/IRoomCameraWidgetManager';
import { RoomCameraWidgetManager } from './camera/RoomCameraWidgetManager';
import { INitroCommunicationManager } from './communication/INitroCommunicationManager'; import { INitroCommunicationManager } from './communication/INitroCommunicationManager';
import { NitroCommunicationManager } from './communication/NitroCommunicationManager'; import { NitroCommunicationManager } from './communication/NitroCommunicationManager';
import { LegacyExternalInterface } from './externalInterface/LegacyExternalInterface'; import { LegacyExternalInterface } from './externalInterface/LegacyExternalInterface';
@ -53,6 +55,7 @@ export class Nitro extends Application implements INitro
private _sessionDataManager: ISessionDataManager; private _sessionDataManager: ISessionDataManager;
private _roomSessionManager: IRoomSessionManager; private _roomSessionManager: IRoomSessionManager;
private _roomManager: IRoomManager; private _roomManager: IRoomManager;
private _cameraManager: IRoomCameraWidgetManager;
private _linkTrackers: ILinkEventTracker[]; private _linkTrackers: ILinkEventTracker[];
private _workerTrackers: IWorkerEventTracker[]; private _workerTrackers: IWorkerEventTracker[];
@ -93,6 +96,7 @@ export class Nitro extends Application implements INitro
this._sessionDataManager = new SessionDataManager(this._communication); this._sessionDataManager = new SessionDataManager(this._communication);
this._roomSessionManager = new RoomSessionManager(this._communication, this._roomEngine); this._roomSessionManager = new RoomSessionManager(this._communication, this._roomEngine);
this._roomManager = new RoomManager(this._roomEngine, this._roomEngine.visualizationFactory, this._roomEngine.logicFactory); this._roomManager = new RoomManager(this._roomEngine, this._roomEngine.visualizationFactory, this._roomEngine.logicFactory);
this._cameraManager = new RoomCameraWidgetManager();
this._linkTrackers = []; this._linkTrackers = [];
this._workerTrackers = []; this._workerTrackers = [];
@ -391,6 +395,11 @@ export class Nitro extends Application implements INitro
return this._roomManager; return this._roomManager;
} }
public get cameraManager(): IRoomCameraWidgetManager
{
return this._cameraManager;
}
public get width(): number public get width(): number
{ {
return (this.renderer.width / this.renderer.resolution); return (this.renderer.width / this.renderer.resolution);

View File

@ -0,0 +1,9 @@
import { Texture } from 'pixi.js';
export interface IRoomCameraWidgetEffect
{
name: string;
minLevel: number;
texture: Texture;
colorMatrix: number[];
}

View File

@ -0,0 +1,12 @@
import { IEventDispatcher } from '../../core';
import { IRoomCameraWidgetEffect } from './IRoomCameraWidgetEffect';
import { IRoomCameraWidgetSelectedEffect } from './IRoomCameraWidgetSelectedEffect';
export interface IRoomCameraWidgetManager
{
init(): void;
applyEffects(image: HTMLImageElement, selectedEffects: IRoomCameraWidgetSelectedEffect[]): HTMLImageElement;
events: IEventDispatcher;
effects: Map<string, IRoomCameraWidgetEffect>;
isLoaded: boolean;
}

View File

@ -0,0 +1,7 @@
import { IRoomCameraWidgetEffect } from './IRoomCameraWidgetEffect';
export interface IRoomCameraWidgetSelectedEffect
{
effect: IRoomCameraWidgetEffect;
alpha: number;
}

View File

@ -0,0 +1,48 @@
import { Texture } from 'pixi.js';
import { IRoomCameraWidgetEffect } from './IRoomCameraWidgetEffect';
export class RoomCameraWidgetEffect implements IRoomCameraWidgetEffect
{
private _name: string;
private _minLevel: number = -1;
private _texture: Texture = null;
private _colorMatrix: number[] = null;
constructor(name: string, minLevel: number = -1, texture: Texture = null, colorMatrix: number[] = null)
{
this._name = name;
this._minLevel = minLevel;
this._texture = texture;
this._colorMatrix = colorMatrix;
}
public get name(): string
{
return this._name;
}
public get texture(): Texture
{
return this._texture;
}
public set texture(texture: Texture)
{
this._texture = texture;
}
public get colorMatrix(): number[]
{
return this._colorMatrix;
}
public set colorMatrix(colorMatrix: number[])
{
this._colorMatrix = colorMatrix;
}
public get minLevel(): number
{
return this._minLevel;
}
}

View File

@ -0,0 +1,105 @@
import { Container, filters, Sprite, Texture } from 'pixi.js';
import { EventDispatcher, IEventDispatcher } from '../../core';
import { TextureUtils } from '../../room';
import { Nitro } from '../Nitro';
import { RoomCameraWidgetManagerEvent } from './events/RoomCameraWidgetManagerEvent';
import { IRoomCameraWidgetEffect } from './IRoomCameraWidgetEffect';
import { IRoomCameraWidgetManager } from './IRoomCameraWidgetManager';
import { IRoomCameraWidgetSelectedEffect } from './IRoomCameraWidgetSelectedEffect';
import { RoomCameraWidgetEffect } from './RoomCameraWidgetEffect';
export class RoomCameraWidgetManager implements IRoomCameraWidgetManager
{
private _effects: Map<string, IRoomCameraWidgetEffect>;
private _events: IEventDispatcher;
private _isLoaded: boolean;
constructor()
{
this._effects = new Map();
this._events = new EventDispatcher();
this._isLoaded = false;
}
public init(): void
{
if(this._isLoaded) return;
this._isLoaded = true;
const imagesUrl = Nitro.instance.getConfiguration<string>('image.library.url') + 'Habbo-Stories/';
const effects = Nitro.instance.getConfiguration<{ name: string, colorMatrix?: number[], minLevel: number, enabled: boolean }[]>('camera.available.effects');
for(const effect of effects)
{
if(!effect.enabled) continue;
const cameraEffect = new RoomCameraWidgetEffect(effect.name, effect.minLevel);
if(effect.colorMatrix.length)
{
cameraEffect.colorMatrix = effect.colorMatrix;
}
else
{
cameraEffect.texture = Texture.from(imagesUrl + effect.name + '.png');
}
this._effects.set(cameraEffect.name, cameraEffect);
}
this.events.dispatchEvent(new RoomCameraWidgetManagerEvent(RoomCameraWidgetManagerEvent.INITIALIZED));
}
public applyEffects(image: HTMLImageElement, selectedEffects: IRoomCameraWidgetSelectedEffect[]): HTMLImageElement
{
const container = new Container();
const texture = Texture.from(image);
const sprite = new Sprite(texture);
container.addChild(sprite);
for(const selectedEffect of selectedEffects)
{
const effect = selectedEffect.effect;
if(!effect) continue;
if(effect.colorMatrix)
{
const filter = new filters.ColorMatrixFilter();
filter.matrix = effect.colorMatrix;
filter.alpha = selectedEffect.alpha;
if(!sprite.filters) sprite.filters = [];
sprite.filters.push(filter);
}
else
{
const effectSprite = new Sprite(effect.texture);
effectSprite.alpha = selectedEffect.alpha;
container.addChild(effectSprite);
}
}
return TextureUtils.generateImage(container);
}
public get effects(): Map<string, IRoomCameraWidgetEffect>
{
return this._effects;
}
public get events(): IEventDispatcher
{
return this._events;
}
public get isLoaded(): boolean
{
return this._isLoaded;
}
}

View File

@ -0,0 +1,23 @@
import { IRoomCameraWidgetEffect } from './IRoomCameraWidgetEffect';
export class RoomCameraWidgetSelectedEffect
{
private _effect: IRoomCameraWidgetEffect;
private _alpha: number;
constructor(effect: IRoomCameraWidgetEffect, alpha: number)
{
this._effect = effect;
this._alpha = alpha;
}
public get effect(): IRoomCameraWidgetEffect
{
return this._effect;
}
public get alpha(): number
{
return this._alpha;
}
}

View File

@ -0,0 +1,11 @@
import { NitroEvent } from '../../../core/events/NitroEvent';
export class RoomCameraWidgetManagerEvent extends NitroEvent
{
public static INITIALIZED: string = 'RCWM_INITIALIZED';
constructor(type: string)
{
super(type);
}
}

View File

@ -1,5 +1,5 @@
import { IMessageConfiguration } from '../../core/communication/messages/IMessageConfiguration'; import { IMessageConfiguration } from '../../core/communication/messages/IMessageConfiguration';
import { ApproveNameMessageComposer, CatalogApproveNameResultEvent, SellablePetPalettesEvent } from './messages'; import { ApproveNameMessageComposer, CatalogApproveNameResultEvent, RoomUnitGiveHandItemPetComposer, SellablePetPalettesEvent } from './messages';
import { AvailabilityStatusMessageEvent } from './messages/incoming/availability/AvailabilityStatusMessageEvent'; import { AvailabilityStatusMessageEvent } from './messages/incoming/availability/AvailabilityStatusMessageEvent';
import { CatalogClubEvent } from './messages/incoming/catalog/CatalogClubEvent'; import { CatalogClubEvent } from './messages/incoming/catalog/CatalogClubEvent';
import { CatalogClubGiftsEvent } from './messages/incoming/catalog/CatalogClubGiftsEvent'; import { CatalogClubGiftsEvent } from './messages/incoming/catalog/CatalogClubGiftsEvent';
@ -918,6 +918,7 @@ export class NitroMessages implements IMessageConfiguration
this._composers.set(OutgoingHeader.UNIT_DANCE, RoomUnitDanceComposer); this._composers.set(OutgoingHeader.UNIT_DANCE, RoomUnitDanceComposer);
this._composers.set(OutgoingHeader.UNIT_DROP_HAND_ITEM, RoomUnitDropHandItemComposer); this._composers.set(OutgoingHeader.UNIT_DROP_HAND_ITEM, RoomUnitDropHandItemComposer);
this._composers.set(OutgoingHeader.UNIT_GIVE_HANDITEM, RoomUnitGiveHandItemComposer); this._composers.set(OutgoingHeader.UNIT_GIVE_HANDITEM, RoomUnitGiveHandItemComposer);
this._composers.set(OutgoingHeader.UNIT_GIVE_HANDITEM_PET, RoomUnitGiveHandItemPetComposer);
this._composers.set(OutgoingHeader.UNIT_LOOK, RoomUnitLookComposer); this._composers.set(OutgoingHeader.UNIT_LOOK, RoomUnitLookComposer);
this._composers.set(OutgoingHeader.UNIT_SIGN, RoomUnitSignComposer); this._composers.set(OutgoingHeader.UNIT_SIGN, RoomUnitSignComposer);
this._composers.set(OutgoingHeader.UNIT_POSTURE, RoomUnitPostureComposer); this._composers.set(OutgoingHeader.UNIT_POSTURE, RoomUnitPostureComposer);

View File

@ -232,4 +232,5 @@ export class OutgoingHeader
public static MARKETPLACE_BUY_OFFER = 1603; public static MARKETPLACE_BUY_OFFER = 1603;
public static CATALOG_REQUESET_PET_BREEDS = 1756; public static CATALOG_REQUESET_PET_BREEDS = 1756;
public static APPROVE_NAME = 2109; public static APPROVE_NAME = 2109;
public static UNIT_GIVE_HANDITEM_PET = 2768;
} }

View File

@ -0,0 +1,21 @@
import { IMessageComposer } from '../../../../../../core/communication/messages/IMessageComposer';
export class RoomUnitGiveHandItemPetComposer implements IMessageComposer<ConstructorParameters<typeof RoomUnitGiveHandItemPetComposer>>
{
private _data: ConstructorParameters<typeof RoomUnitGiveHandItemPetComposer>;
constructor(unitId: number)
{
this._data = [ unitId ];
}
public getMessageArray()
{
return this._data;
}
public dispose(): void
{
return;
}
}

View File

@ -3,6 +3,7 @@ export * from './RoomUnitActionComposer';
export * from './RoomUnitDanceComposer'; export * from './RoomUnitDanceComposer';
export * from './RoomUnitDropHandItemComposer'; export * from './RoomUnitDropHandItemComposer';
export * from './RoomUnitGiveHandItemComposer'; export * from './RoomUnitGiveHandItemComposer';
export * from './RoomUnitGiveHandItemPetComposer';
export * from './RoomUnitLookComposer'; export * from './RoomUnitLookComposer';
export * from './RoomUnitPostureComposer'; export * from './RoomUnitPostureComposer';
export * from './RoomUnitSignComposer'; export * from './RoomUnitSignComposer';

View File

@ -86,7 +86,7 @@ export interface IRoomEngine extends INitroManager
processRoomObjectOperation(objectId: number, category: number, operation: string): boolean; processRoomObjectOperation(objectId: number, category: number, operation: string): boolean;
processRoomObjectPlacement(placementSource: string, id: number, category: number, typeId: number, legacyString?: string, stuffData?: IObjectData, state?: number, frameNumber?: number, posture?: string): boolean; processRoomObjectPlacement(placementSource: string, id: number, category: number, typeId: number, legacyString?: string, stuffData?: IObjectData, state?: number, frameNumber?: number, posture?: string): boolean;
dispatchMouseEvent(canvasId: number, x: number, y: number, type: string, altKey: boolean, ctrlKey: boolean, shiftKey: boolean, buttonDown: boolean): void; dispatchMouseEvent(canvasId: number, x: number, y: number, type: string, altKey: boolean, ctrlKey: boolean, shiftKey: boolean, buttonDown: boolean): void;
createRoomScreenshot(roomId: number, canvasId: number): void; createRoomScreenshot(roomId: number, canvasId?: number, bounds?: Rectangle): HTMLImageElement;
modifyRoomObjectData(objectId: number, objectCategory: number, colorHex: string, text: string): boolean; modifyRoomObjectData(objectId: number, objectCategory: number, colorHex: string, text: string): boolean;
deleteRoomObject(objectId: number, objectCategory: number): boolean; deleteRoomObject(objectId: number, objectCategory: number): boolean;
sessionDataManager: ISessionDataManager; sessionDataManager: ISessionDataManager;

View File

@ -6,6 +6,7 @@ import { NitroManager } from '../../core/common/NitroManager';
import { IConnection } from '../../core/communication/connections/IConnection'; import { IConnection } from '../../core/communication/connections/IConnection';
import { IMessageComposer } from '../../core/communication/messages/IMessageComposer'; import { IMessageComposer } from '../../core/communication/messages/IMessageComposer';
import { NitroEvent } from '../../core/events/NitroEvent'; import { NitroEvent } from '../../core/events/NitroEvent';
import { TextureUtils } from '../../room';
import { RoomObjectEvent } from '../../room/events/RoomObjectEvent'; import { RoomObjectEvent } from '../../room/events/RoomObjectEvent';
import { RoomObjectMouseEvent } from '../../room/events/RoomObjectMouseEvent'; import { RoomObjectMouseEvent } from '../../room/events/RoomObjectMouseEvent';
import { IRoomInstance } from '../../room/IRoomInstance'; import { IRoomInstance } from '../../room/IRoomInstance';
@ -3437,22 +3438,39 @@ export class RoomEngine extends NitroManager implements IRoomEngine, IRoomCreato
return null; return null;
} }
public createRoomScreenshot(roomId: number, canvasId: number): void public createRoomScreenshot(roomId: number, canvasId: number = -1, bounds: Rectangle = null): HTMLImageElement
{ {
const canvas = this.getRoomInstanceRenderingCanvas(roomId, canvasId); let canvas: IRoomRenderingCanvas = null;
if(!canvas) return; if(canvasId > -1)
{
canvas = this.getRoomInstanceRenderingCanvas(this._activeRoomId, canvasId);
}
else
{
canvas = this.getActiveRoomInstanceRenderingCanvas();
}
const texture = canvas.getDisplayAsTexture(); let texture: RenderTexture = null;
const base64 = Nitro.instance.renderer.extract.base64(texture); if(bounds)
{
texture = TextureUtils.generateTexture(canvas.master, bounds);
}
else
{
texture = canvas.getDisplayAsTexture();
}
const image = new Image(); const base64 = TextureUtils.generateImageUrl(texture);
const image = new Image();
image.src = base64; image.src = base64;
const newWindow = window.open(''); /*const newWindow = window.open('');
newWindow.document.write(image.outerHTML); newWindow.document.write(image.outerHTML);*/
return image;
} }
public objectsInitialized(k: string): void public objectsInitialized(k: string): void

View File

@ -147,4 +147,4 @@ export class FurnitureThumbnailVisualization extends FurnitureAnimatedVisualizat
{ {
return [this._type, k, 'thumb', _arg_2].join('_'); return [this._type, k, 'thumb', _arg_2].join('_');
} }
} }

View File

@ -354,49 +354,53 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
const frame = Math.round(this._totalTimeRunning / (60 / this._animationFPS)); const frame = Math.round(this._totalTimeRunning / (60 / this._animationFPS));
let updateVisuals = false;
if(frame !== this._lastFrame) if(frame !== this._lastFrame)
{ {
this._lastFrame = frame; this._lastFrame = frame;
let spriteCount = 0; updateVisuals = true;
const objects = this._container.objects;
if(objects.size)
{
for(const object of objects.values())
{
if(!object) continue;
spriteCount = (spriteCount + this.renderObject(object, object.instanceId.toString(), time, update, spriteCount));
}
}
this._sortableSprites.sort((a, b) =>
{
return b.z - a.z;
});
if(spriteCount < this._sortableSprites.length)
{
this._sortableSprites.splice(spriteCount);
}
let iterator = 0;
while(iterator < spriteCount)
{
const sprite = this._sortableSprites[iterator];
if(sprite && sprite.sprite) this.renderSprite(iterator, sprite);
iterator++;
}
this.cleanSprites(spriteCount);
} }
if(update) this._canvasUpdated = true; let spriteCount = 0;
const objects = this._container.objects;
if(objects.size)
{
for(const object of objects.values())
{
if(!object) continue;
spriteCount = (spriteCount + this.renderObject(object, object.instanceId.toString(), time, update, updateVisuals, spriteCount));
}
}
this._sortableSprites.sort((a, b) =>
{
return b.z - a.z;
});
if(spriteCount < this._sortableSprites.length)
{
this._sortableSprites.splice(spriteCount);
}
let iterator = 0;
while(iterator < spriteCount)
{
const sprite = this._sortableSprites[iterator];
if(sprite && sprite.sprite) this.renderSprite(iterator, sprite);
iterator++;
}
this.cleanSprites(spriteCount);
if(update || updateVisuals) this._canvasUpdated = true;
this._renderTimestamp = this._totalTimeRunning; this._renderTimestamp = this._totalTimeRunning;
this._renderedWidth = this._width; this._renderedWidth = this._width;
@ -430,7 +434,7 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
this._objectCache.removeObjectCache(identifier); this._objectCache.removeObjectCache(identifier);
} }
private renderObject(object: IRoomObject, identifier: string, time: number, update: boolean, count: number): number private renderObject(object: IRoomObject, identifier: string, time: number, update: boolean, updateVisuals: boolean, count: number): number
{ {
if(!object) return 0; if(!object) return 0;
@ -458,7 +462,7 @@ export class RoomSpriteCanvas implements IRoomRenderingCanvas
return 0; return 0;
} }
visualization.update(this._geometry, time, (!sortableCache.isEmpty || update), (this._skipObjectUpdate && this._runningSlow)); if(updateVisuals) visualization.update(this._geometry, time, (!sortableCache.isEmpty || update), (this._skipObjectUpdate && this._runningSlow));
if(locationCache.locationChanged) update = true; if(locationCache.locationChanged) update = true;

View File

@ -0,0 +1,4 @@
import { Rectangle } from 'pixi.js';
export class NitroRectangle extends Rectangle
{}

View File

@ -3,6 +3,7 @@ export * from './INitroPoint';
export * from './IRoomGeometry'; export * from './IRoomGeometry';
export * from './IVector3D'; export * from './IVector3D';
export * from './NitroPoint'; export * from './NitroPoint';
export * from './NitroRectangle';
export * from './NumberBank'; export * from './NumberBank';
export * from './PointMath'; export * from './PointMath';
export * from './Rasterizer'; export * from './Rasterizer';