mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-11-27 13:42:58 +08:00
feat: 图集可以动态更新,但抛出警告
This commit is contained in:
parent
cdacdc50e7
commit
efe6931799
@ -1,35 +0,0 @@
|
|||||||
import { ITextureComposedData } from '@motajs/render-assets';
|
|
||||||
import { IMaterialAsset } from './types';
|
|
||||||
import { IDirtyMark } from '@motajs/common';
|
|
||||||
|
|
||||||
export class MaterialAsset implements IMaterialAsset {
|
|
||||||
/** 标记列表 */
|
|
||||||
private readonly marks: WeakMap<IDirtyMark, number> = new WeakMap();
|
|
||||||
/** 脏标记,所有值小于此标记的都视为需要更新 */
|
|
||||||
private dirtyFlag: number = 0;
|
|
||||||
|
|
||||||
constructor(readonly data: ITextureComposedData) {}
|
|
||||||
|
|
||||||
dirty(): void {
|
|
||||||
this.dirtyFlag++;
|
|
||||||
}
|
|
||||||
|
|
||||||
mark(): IDirtyMark {
|
|
||||||
const symbol = {};
|
|
||||||
this.marks.set(symbol, this.dirtyFlag);
|
|
||||||
return symbol;
|
|
||||||
}
|
|
||||||
|
|
||||||
unmark(mark: IDirtyMark): void {
|
|
||||||
this.marks.delete(mark);
|
|
||||||
}
|
|
||||||
|
|
||||||
dirtySince(mark: IDirtyMark): boolean {
|
|
||||||
const value = this.marks.get(mark) ?? -1;
|
|
||||||
return value < this.dirtyFlag;
|
|
||||||
}
|
|
||||||
|
|
||||||
hasMark(symbol: IDirtyMark): boolean {
|
|
||||||
return this.marks.has(symbol);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -113,10 +113,16 @@ class TrackedAssetData
|
|||||||
}
|
}
|
||||||
|
|
||||||
markDirty(index: number) {
|
markDirty(index: number) {
|
||||||
|
if (index >= this.length) {
|
||||||
|
this.updateLength(index + 1);
|
||||||
|
}
|
||||||
this.dirty(index);
|
this.dirty(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateSource(index: number, source: SizedCanvasImageSource) {
|
async updateSource(index: number, source: SizedCanvasImageSource) {
|
||||||
|
if (index >= this.length) {
|
||||||
|
this.updateLength(this.length + 1);
|
||||||
|
}
|
||||||
const origin = this.originSourceMap.get(index);
|
const origin = this.originSourceMap.get(index);
|
||||||
const prev = this.sourceList.get(index);
|
const prev = this.sourceList.get(index);
|
||||||
if (origin) {
|
if (origin) {
|
||||||
|
|||||||
@ -155,21 +155,10 @@ export class MaterialManager implements IMaterialManager {
|
|||||||
addAutotile(
|
addAutotile(
|
||||||
source: SizedCanvasImageSource,
|
source: SizedCanvasImageSource,
|
||||||
identifier: IBlockIdentifier
|
identifier: IBlockIdentifier
|
||||||
): IMaterialData | null {
|
): void {
|
||||||
const frames = source.width === 96 ? 1 : 4;
|
this.autotileSource.set(identifier.num, source);
|
||||||
const flattened = AutotileProcessor.flatten({ source, frames });
|
|
||||||
if (!flattened) return null;
|
|
||||||
const texture = new Texture(flattened);
|
|
||||||
this.tileStore.addTexture(identifier.num, texture);
|
|
||||||
this.tileStore.alias(identifier.num, identifier.id);
|
this.tileStore.alias(identifier.num, identifier.id);
|
||||||
this.clsMap.set(identifier.num, BlockCls.Autotile);
|
this.clsMap.set(identifier.num, BlockCls.Autotile);
|
||||||
const data: IMaterialData = {
|
|
||||||
store: this.tileStore,
|
|
||||||
texture,
|
|
||||||
identifier: identifier.num,
|
|
||||||
alias: identifier.id
|
|
||||||
};
|
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addTileset(
|
addTileset(
|
||||||
@ -231,9 +220,15 @@ export class MaterialManager implements IMaterialManager {
|
|||||||
|
|
||||||
getTile(identifier: number): IMaterialFramedData | null {
|
getTile(identifier: number): IMaterialFramedData | null {
|
||||||
if (identifier < 10000) {
|
if (identifier < 10000) {
|
||||||
|
const cls = this.clsMap.get(identifier) ?? BlockCls.Unknown;
|
||||||
|
if (
|
||||||
|
cls === BlockCls.Autotile &&
|
||||||
|
this.autotileSource.has(identifier)
|
||||||
|
) {
|
||||||
|
this.cacheAutotile(identifier);
|
||||||
|
}
|
||||||
const texture = this.tileStore.getTexture(identifier);
|
const texture = this.tileStore.getTexture(identifier);
|
||||||
if (!texture) return null;
|
if (!texture) return null;
|
||||||
const cls = this.clsMap.get(identifier) ?? BlockCls.Unknown;
|
|
||||||
return {
|
return {
|
||||||
texture,
|
texture,
|
||||||
cls,
|
cls,
|
||||||
@ -402,6 +397,7 @@ export class MaterialManager implements IMaterialManager {
|
|||||||
this.tileStore.addTexture(identifier, tex);
|
this.tileStore.addTexture(identifier, tex);
|
||||||
const data = this.assetBuilder.addTexture(tex);
|
const data = this.assetBuilder.addTexture(tex);
|
||||||
tex.toAsset(data);
|
tex.toAsset(data);
|
||||||
|
this.autotileSource.delete(identifier);
|
||||||
this.checkAssetDirty(data);
|
this.checkAssetDirty(data);
|
||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
@ -418,6 +414,7 @@ export class MaterialManager implements IMaterialManager {
|
|||||||
const tex = new Texture(flattened);
|
const tex = new Texture(flattened);
|
||||||
this.tileStore.addTexture(v, tex);
|
this.tileStore.addTexture(v, tex);
|
||||||
toAdd.push(tex);
|
toAdd.push(tex);
|
||||||
|
this.autotileSource.delete(v);
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = this.assetBuilder.addTextureList(toAdd);
|
const data = this.assetBuilder.addTextureList(toAdd);
|
||||||
@ -542,7 +539,7 @@ export class MaterialManager implements IMaterialManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getIfBigImage(identifier: number): IMaterialFramedData | null {
|
getIfBigImage(identifier: number): IMaterialFramedData | null {
|
||||||
const bigImage = this.bigImageData.get(identifier) ?? null;
|
const bigImage = this.bigImageData.get(identifier);
|
||||||
if (bigImage) return bigImage;
|
if (bigImage) return bigImage;
|
||||||
else return this.getTile(identifier);
|
else return this.getTile(identifier);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -785,6 +785,7 @@ export class MapRenderer
|
|||||||
if (dirty.size === 0) return;
|
if (dirty.size === 0) return;
|
||||||
this.assetData.unmark(data.tileTextureMark);
|
this.assetData.unmark(data.tileTextureMark);
|
||||||
data.tileTextureMark = this.assetData.mark();
|
data.tileTextureMark = this.assetData.mark();
|
||||||
|
logger.warn(87);
|
||||||
gl.bindTexture(gl.TEXTURE_2D_ARRAY, tile);
|
gl.bindTexture(gl.TEXTURE_2D_ARRAY, tile);
|
||||||
const sizeChanged = this.checkTextureArraySize(
|
const sizeChanged = this.checkTextureArraySize(
|
||||||
gl,
|
gl,
|
||||||
|
|||||||
@ -134,6 +134,7 @@
|
|||||||
"84": "Cannot set alias '$1' for layer, since '$1' is already an alias for another layer.",
|
"84": "Cannot set alias '$1' for layer, since '$1' is already an alias for another layer.",
|
||||||
"85": "Hook to load does not belong to current hookable object.",
|
"85": "Hook to load does not belong to current hookable object.",
|
||||||
"86": "Cannot restore vertex data since delivered state does not belong to current vertex generator instance.",
|
"86": "Cannot restore vertex data since delivered state does not belong to current vertex generator instance.",
|
||||||
|
"87": "Map texture asset cache not hit. This has no effect on rendering, but may extremely affect performance, please see the following link to find solution.",
|
||||||
"1001": "Item-detail extension needs 'floor-binder' and 'floor-damage' extension as dependency.",
|
"1001": "Item-detail extension needs 'floor-binder' and 'floor-damage' extension as dependency.",
|
||||||
"1101": "Cannot add new effect to point effect instance, for there's no more reserve space for it. Please increase the max count of the instance."
|
"1101": "Cannot add new effect to point effect instance, for there's no more reserve space for it. Please increase the max count of the instance."
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user