cleaned AvatarImageActionCache

This commit is contained in:
Dank074 2021-06-06 22:08:56 -05:00
parent a7182c863b
commit ed772306a3
6 changed files with 147 additions and 147 deletions

View File

@ -109,7 +109,7 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener
{
this.getAvatarPartsForCamera(AvatarSetType.FULL);
return this._cache._Str_1009();
return this._cache.getServerRenderData();
}
public dispose(): void
@ -301,7 +301,7 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener
while(_local_6 >= 0)
{
_local_4 = _local_3[_local_6];
const _local_5 = this._cache._Str_1629(_local_4, this._frameCounter, true);
const _local_5 = this._cache.getImageContainer(_local_4, this._frameCounter, true);
_local_6--;
}
}
@ -343,7 +343,7 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener
while(partCount >= 0)
{
const set = _local_6[partCount];
const part = this._cache._Str_1629(set, this._frameCounter);
const part = this._cache.getImageContainer(set, this._frameCounter);
if(part)
{
@ -462,7 +462,7 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener
while(partCount >= 0)
{
const set = setTypes[partCount];
const part = this._cache._Str_1629(set, this._frameCounter);
const part = this._cache.getImageContainer(set, this._frameCounter);
if(part)
{
@ -527,7 +527,7 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener
while(partCount >= 0)
{
const set = setTypes[partCount];
const part = this._cache._Str_1629(set, this._frameCounter);
const part = this._cache.getImageContainer(set, this._frameCounter);
if(part)
{
@ -858,7 +858,7 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener
this._effectIdInUse = -1;
}
if(_local_2) this._cache._Str_1086(0);
if(_local_2) this._cache.disposeInactiveActions(0);
if(this._lastActionsString != this._currentActionsString)
{
@ -948,9 +948,9 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener
if(k.definition.isMain)
{
this._mainAction = k;
this._cache._Str_2014(k.definition.geometryType);
this._cache.setGeometryType(k.definition.geometryType);
}
this._cache._Str_1565(k, _arg_2);
this._cache.setAction(k, _arg_2);
this._changes = true;
}
@ -963,10 +963,10 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener
if(k.definition.isMain)
{
this._mainAction = k;
this._cache._Str_2014(k.definition.geometryType);
this._cache.setGeometryType(k.definition.geometryType);
}
this._cache._Str_741(k);
this._cache.resetBodyPartCache(k);
this._changes = true;
}

View File

@ -1,96 +1,57 @@
import { IActiveActionData } from '../actions/IActiveActionData';
import { AvatarImageBodyPartCache } from './AvatarImageBodyPartCache';
import { AvatarImageDirectionCache } from 'nitro-renderer/src/nitro/avatar/cache/AvatarImageDirectionCache';
import { Nitro } from 'nitro-renderer/src/nitro/Nitro';
export class AvatarImageActionCache
{
private _Str_586: Map<string, AvatarImageBodyPartCache>;
private _Str_1233: IActiveActionData;
private _Str_1188: number;
private _disposed: boolean;
private _cache: Map<string, AvatarImageDirectionCache>;
private _lastAccessTime: number;
constructor()
{
this._Str_586 = new Map();
}
this._cache = new Map();
public _Str_1565(k: IActiveActionData, _arg_2: number): void
{
if(!this._Str_1233) this._Str_1233 = k;
const _local_3 = this._Str_1961(this._Str_1233);
if(_local_3) _local_3._Str_1108(_arg_2);
this._Str_1233 = k;
this.setLastAccessTime(Nitro.instance.time);
}
public dispose(): void
{
if(!this._disposed)
this.debugInfo('[dispose]');
if(!this._cache) return;
for(const direction of this._cache.values())
{
if(!this._Str_586) return;
this._Str_2089(0, 2147483647);
this._Str_586.clear();
this._Str_586 = null;
this._disposed = true;
if(direction) direction.dispose();
}
this._cache.clear();
}
public _Str_2089(k: number, _arg_2: number): void
public getDirectionCache(k: number): AvatarImageDirectionCache
{
if(!this._Str_586 || this._disposed) return;
const existing = this._cache.get(k.toString());
for(const [ key, cache ] of this._Str_586.entries())
{
if(!cache) continue;
if(!existing) return null;
const _local_3 = cache._Str_1815();
if((_arg_2 - _local_3) >= k)
{
cache.dispose();
this._Str_586.delete(key);
}
}
return existing;
}
public getAction():IActiveActionData
public updateDirectionCache(k: number, _arg_2: AvatarImageDirectionCache): void
{
return this._Str_1233;
this._cache.set(k.toString(), _arg_2);
}
public setDirection(k: number): void
public setLastAccessTime(k: number): void
{
this._Str_1188 = k;
this._lastAccessTime = k;
}
public getDirection(): number
public getLastAccessTime(): number
{
return this._Str_1188;
return this._lastAccessTime;
}
public _Str_1961(k: IActiveActionData=null): AvatarImageBodyPartCache
{
if(!this._Str_1233) return null;
if(!k) k = this._Str_1233;
if(k.overridingAction) return this._Str_586.get(k.overridingAction);
return this._Str_586.get(k.id);
}
public _Str_1765(k: IActiveActionData, _arg_2: AvatarImageBodyPartCache): void
{
if(k.overridingAction) this._Str_586.set(k.overridingAction, _arg_2);
else this._Str_586.set(k.id, _arg_2);
}
private _Str_587(k: string): void
private debugInfo(k: string): void
{
}
}

View File

@ -1,57 +1,96 @@
import { Nitro } from '../../Nitro';
import { AvatarImageDirectionCache } from './AvatarImageDirectionCache';
import { IActiveActionData } from 'nitro-renderer/src/nitro/avatar/actions/IActiveActionData';
import { AvatarImageActionCache } from 'nitro-renderer/src/nitro/avatar/cache/AvatarImageActionCache';
export class AvatarImageBodyPartCache
{
private _Str_586: Map<string, AvatarImageDirectionCache>;
private _Str_1509: number;
private _cache: Map<string, AvatarImageActionCache>;
private _currentAction: IActiveActionData;
private _currentDirection: number;
private _disposed: boolean;
constructor()
{
this._Str_586 = new Map();
this._cache = new Map();
}
this._Str_1108(Nitro.instance.time);
public setAction(k: IActiveActionData, _arg_2: number): void
{
if(!this._currentAction) this._currentAction = k;
const _local_3 = this.getActionCache(this._currentAction);
if(_local_3) _local_3.setLastAccessTime(_arg_2);
this._currentAction = k;
}
public dispose(): void
{
this._Str_587('[dispose]');
if(!this._Str_586) return;
for(const direction of this._Str_586.values())
if(!this._disposed)
{
if(direction) direction.dispose();
if(!this._cache) return;
this.disposeActions(0, 2147483647);
this._cache.clear();
this._cache = null;
this._disposed = true;
}
this._Str_586.clear();
}
public _Str_2070(k: number): AvatarImageDirectionCache
public disposeActions(k: number, _arg_2: number): void
{
const existing = this._Str_586.get(k.toString());
if(!this._cache || this._disposed) return;
if(!existing) return null;
for(const [ key, cache ] of this._cache.entries())
{
if(!cache) continue;
return existing;
const _local_3 = cache.getLastAccessTime();
if((_arg_2 - _local_3) >= k)
{
cache.dispose();
this._cache.delete(key);
}
}
}
public _Str_2168(k: number, _arg_2: AvatarImageDirectionCache): void
public getAction():IActiveActionData
{
this._Str_586.set(k.toString(), _arg_2);
return this._currentAction;
}
public _Str_1108(k: number): void
public setDirection(k: number): void
{
this._Str_1509 = k;
this._currentDirection = k;
}
public _Str_1815(): number
public getDirection(): number
{
return this._Str_1509;
return this._currentDirection;
}
private _Str_587(k: string): void
public getActionCache(k: IActiveActionData=null): AvatarImageActionCache
{
if(!this._currentAction) return null;
if(!k) k = this._currentAction;
if(k.overridingAction) return this._cache.get(k.overridingAction);
return this._cache.get(k.id);
}
public updateActionCache(k: IActiveActionData, _arg_2: AvatarImageActionCache): void
{
if(k.overridingAction) this._cache.set(k.overridingAction, _arg_2);
else this._cache.set(k.id, _arg_2);
}
private debugInfo(k: string): void
{
}
}

View File

@ -1,3 +1,5 @@
import { AvatarImageActionCache } from 'nitro-renderer/src/nitro/avatar/cache/AvatarImageActionCache';
import { AvatarImageBodyPartCache } from 'nitro-renderer/src/nitro/avatar/cache/AvatarImageBodyPartCache';
import { Container, Matrix, Point, Rectangle, Sprite, Texture } from 'pixi.js';
import { RoomObjectSpriteData } from '../../../room/data/RoomObjectSpriteData';
import { Nitro } from '../../Nitro';
@ -13,20 +15,18 @@ import { AvatarScaleType } from '../enum/AvatarScaleType';
import { GeometryType } from '../enum/GeometryType';
import { IAvatarImage } from '../IAvatarImage';
import { AvatarCanvas } from '../structure/AvatarCanvas';
import { AvatarImageActionCache } from './AvatarImageActionCache';
import { AvatarImageBodyPartCache } from './AvatarImageBodyPartCache';
import { AvatarImageDirectionCache } from './AvatarImageDirectionCache';
import { ImageData } from './ImageData';
export class AvatarImageCache
{
private static _Str_2189: number = 60000;
private static DEFAULT_MAX_CACHE_STORAGE_TIME_MS: number = 60000;
private _structure: AvatarStructure;
private _avatar: IAvatarImage;
private _assets: AssetAliasCollection;
private _scale: string;
private _cache: Map<string, AvatarImageActionCache>;
private _cache: Map<string, AvatarImageBodyPartCache>;
private _canvas: AvatarCanvas;
private _disposed: boolean;
private _geometryType: string;
@ -83,7 +83,7 @@ export class AvatarImageCache
}
}
public _Str_1086(k: number = 60000): void
public disposeInactiveActions(k: number = 60000): void
{
const time = Nitro.instance.time;
@ -93,12 +93,12 @@ export class AvatarImageCache
{
if(!cache) continue;
cache._Str_2089(k, time);
cache.disposeActions(k, time);
}
}
}
public _Str_741(k: IActiveActionData): void
public resetBodyPartCache(k: IActiveActionData): void
{
if(this._cache)
{
@ -106,7 +106,7 @@ export class AvatarImageCache
{
if(!cache) continue;
cache._Str_1565(k, 0);
cache.setAction(k, 0);
}
}
}
@ -119,7 +119,7 @@ export class AvatarImageCache
{
for(const part of parts)
{
const actionCache = this._Str_1050(part);
const actionCache = this.getBodyPartCache(part);
if(!actionCache) continue;
@ -128,19 +128,19 @@ export class AvatarImageCache
}
}
public _Str_1565(k: IActiveActionData, _arg_2: number): void
public setAction(k: IActiveActionData, _arg_2: number): void
{
const _local_3 = this._structure.getActiveBodyPartIds(k, this._avatar);
for(const _local_4 of _local_3)
{
const _local_5 = this._Str_1050(_local_4);
const _local_5 = this.getBodyPartCache(_local_4);
if(_local_5) _local_5._Str_1565(k, _arg_2);
if(_local_5) _local_5.setAction(k, _arg_2);
}
}
public _Str_2014(k: string): void
public setGeometryType(k: string): void
{
if(this._geometryType === k) return;
@ -152,19 +152,19 @@ export class AvatarImageCache
return;
}
this._Str_1086(0);
this.disposeInactiveActions(0);
this._geometryType = k;
this._canvas = null;
}
public _Str_1629(k: string, frameNumber: number, _arg_3: boolean = false): AvatarImageBodyPartContainer
public getImageContainer(k: string, frameNumber: number, _arg_3: boolean = false): AvatarImageBodyPartContainer
{
let _local_4 = this._Str_1050(k);
let _local_4 = this.getBodyPartCache(k);
if(!_local_4)
{
_local_4 = new AvatarImageActionCache();
_local_4 = new AvatarImageBodyPartCache();
this._cache.set(k, _local_4);
}
@ -251,15 +251,15 @@ export class AvatarImageCache
}
}
let _local_12 = _local_4._Str_1961(_local_8);
let _local_12 = _local_4.getActionCache(_local_8);
if(!_local_12 || _arg_3)
{
_local_12 = new AvatarImageBodyPartCache();
_local_4._Str_1765(_local_8, _local_12);
_local_12 = new AvatarImageActionCache();
_local_4.updateActionCache(_local_8, _local_12);
}
let _local_13 = _local_12._Str_2070(_local_5);
let _local_13 = _local_12.getDirectionCache(_local_5);
if(!_local_13 || _arg_3)
{
@ -267,20 +267,20 @@ export class AvatarImageCache
_local_13 = new AvatarImageDirectionCache(_local_19);
_local_12._Str_2168(_local_5, _local_13);
_local_12.updateDirectionCache(_local_5, _local_13);
}
let _local_14 = _local_13._Str_1629(frameCount);
let _local_14 = _local_13.getImageContainer(frameCount);
if(!_local_14 || _arg_3)
{
const _local_20 = _local_13._Str_1699();
const _local_20 = _local_13.getPartList();
_local_14 = this._Str_1834(_local_5, _local_20, frameCount, _local_7, _arg_3);
_local_14 = this.renderBodyPart(_local_5, _local_20, frameCount, _local_7, _arg_3);
if(_local_14 && !_arg_3)
{
if(_local_14.isCacheable) _local_13._Str_1924(_local_14, frameCount);
if(_local_14.isCacheable) _local_13.updateImageContainer(_local_14, frameCount);
}
else
{
@ -298,20 +298,20 @@ export class AvatarImageCache
return _local_14;
}
public _Str_1009(): any[]
public getServerRenderData(): any[]
{
this._serverRenderData = [];
return this._serverRenderData;
}
public _Str_1050(k: string): AvatarImageActionCache
public getBodyPartCache(k: string): AvatarImageBodyPartCache
{
let existing = this._cache.get(k);
if(!existing)
{
existing = new AvatarImageActionCache();
existing = new AvatarImageBodyPartCache();
this._cache.set(k, existing);
}
@ -319,7 +319,7 @@ export class AvatarImageCache
return existing;
}
private _Str_1834(direction: number, containers: AvatarImagePartContainer[], frameCount: number, _arg_4: IActiveActionData, renderServerData: boolean = false): AvatarImageBodyPartContainer
private renderBodyPart(direction: number, containers: AvatarImagePartContainer[], frameCount: number, _arg_4: IActiveActionData, renderServerData: boolean = false): AvatarImageBodyPartContainer
{
if(!containers || !containers.length) return null;
@ -441,7 +441,7 @@ export class AvatarImageCache
if(!this._unionImages.length) return null;
const imageData = this._Str_1236(this._unionImages, isFlipped);
const imageData = this.createUnionImage(this._unionImages, isFlipped);
const canvasOffset = ((this._scale === AvatarScaleType.LARGE) ? (this._canvas.height - 16) : (this._canvas.height - 8));
const offset = new Point(-(imageData.regPoint.x), (canvasOffset - imageData.regPoint.y));
@ -461,7 +461,7 @@ export class AvatarImageCache
return new AvatarImageBodyPartContainer(imageData.container, offset, isCacheable);
}
private _Str_1652(k: number): string
private convertColorToHex(k: number): string
{
let _local_2: string = (k * 0xFF).toString(16);
if(_local_2.length < 2)
@ -471,11 +471,11 @@ export class AvatarImageCache
return _local_2;
}
private _Str_1236(k: ImageData[], isFlipped: boolean): ImageData
private createUnionImage(k: ImageData[], isFlipped: boolean): ImageData
{
const bounds = new Rectangle();
for(const data of k) data && bounds.enlarge(data._Str_1567);
for(const data of k) data && bounds.enlarge(data.offsetRect);
const point = new Point(-(bounds.x), -(bounds.y));
const container = new Container();
@ -492,7 +492,7 @@ export class AvatarImageCache
if(!data) continue;
const texture = data.texture;
const color = data.color;
const color = data.colorTransform;
const flipH = (!(isFlipped && data.flipH) && (isFlipped || data.flipH));
const regPoint = point.clone();

View File

@ -19,23 +19,23 @@ export class AvatarImageDirectionCache
this._images = null;
}
public _Str_1699(): AvatarImagePartContainer[]
public getPartList(): AvatarImagePartContainer[]
{
return this._partList;
}
public _Str_1629(k: number): AvatarImageBodyPartContainer
public getImageContainer(k: number): AvatarImageBodyPartContainer
{
const existing = this._images.get(this._Str_2219(k));
const existing = this._images.get(this.getCacheKey(k));
if(!existing) return null;
return existing;
}
public _Str_1924(k: AvatarImageBodyPartContainer, _arg_2: number): void
public updateImageContainer(k: AvatarImageBodyPartContainer, _arg_2: number): void
{
const name = this._Str_2219(_arg_2);
const name = this.getCacheKey(_arg_2);
const existing = this._images.get(name);
@ -44,7 +44,7 @@ export class AvatarImageDirectionCache
this._images.set(name, k);
}
private _Str_2219(k: number): string
private getCacheKey(k: number): string
{
let name = '';
@ -53,7 +53,7 @@ export class AvatarImageDirectionCache
return name;
}
private _Str_587(k: string): void
private debugInfo(k: string): void
{
}
}

View File

@ -7,7 +7,7 @@ export class ImageData
private _rect: Rectangle;
private _regPoint: Point;
private _flipH: boolean;
private _color: number;
private _colorTransform: number;
constructor(texture: Texture, rectangle: Rectangle, _arg_3: Point, flipH: boolean, color: number, container: Container = null)
{
@ -16,7 +16,7 @@ export class ImageData
this._rect = rectangle;
this._regPoint = _arg_3;
this._flipH = flipH;
this._color = color;
this._colorTransform = color;
if(flipH) this._regPoint.x = (-(this._regPoint.x) + rectangle.width);
}
@ -25,7 +25,7 @@ export class ImageData
{
this._texture = null;
this._regPoint = null;
this._color = null;
this._colorTransform = null;
}
public get texture(): Texture
@ -53,12 +53,12 @@ export class ImageData
return this._flipH;
}
public get color(): number
public get colorTransform(): number
{
return this._color;
return this._colorTransform;
}
public get _Str_1567(): Rectangle
public get offsetRect(): Rectangle
{
return new Rectangle(-(this._regPoint.x), -(this._regPoint.y), this._rect.width, this._rect.height);
}