mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-29 21:44:31 +08:00
feat: WebGL2 地图渲染
This commit is contained in:
1 parent
ad469cf1ff
commit
0d9bef70b1
45 files changed
+5851
-691
No files matched your search
@@ -0,0 +1,133 @@
|
||||
import { isNil } from 'lodash-es';
|
||||
import { IDirtyTracker } from './types';
|
||||
|
||||
/**
|
||||
* 布尔类型的脏标记追踪器。当传入 `dirtySince` 的标记不属于当前的追踪器时,会返回 `true`
|
||||
*/
|
||||
export class PrivateBooleanDirtyTracker implements IDirtyTracker<boolean> {
|
||||
/** 标记映射 */
|
||||
private markMap: WeakMap<symbol, number> = new WeakMap();
|
||||
/** 脏标记 */
|
||||
private dirtyFlag: number = 0;
|
||||
|
||||
mark(): symbol {
|
||||
const symbol = Symbol();
|
||||
this.markMap.set(symbol, this.dirtyFlag);
|
||||
return symbol;
|
||||
}
|
||||
|
||||
unmark(mark: symbol): void {
|
||||
this.markMap.delete(mark);
|
||||
}
|
||||
|
||||
dirtySince(mark: symbol): boolean {
|
||||
const num = this.markMap.get(mark);
|
||||
if (isNil(num)) return true;
|
||||
return num < this.dirtyFlag;
|
||||
}
|
||||
|
||||
hasMark(symbol: symbol): boolean {
|
||||
return this.markMap.has(symbol);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数据标记为脏
|
||||
*/
|
||||
protected dirty() {
|
||||
this.dirtyFlag++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表的脏标记追踪器。当传入 `dirtySince` 的标记不属于当前的追踪器时,会返回空集合
|
||||
*/
|
||||
export class PrivateListDirtyTracker<T extends number>
|
||||
implements IDirtyTracker<Set<T>>
|
||||
{
|
||||
/** 标记映射,键表示在索引,值表示其对应的标记数字 */
|
||||
private readonly markMap: Map<T, number> = new Map();
|
||||
/** 标记 symbol 映射,值表示这个 symbol 对应的标记数字 */
|
||||
private readonly symbolMap: WeakMap<symbol, number> = new WeakMap();
|
||||
|
||||
/** 脏标记数字 */
|
||||
private dirtyFlag: number = 0;
|
||||
|
||||
constructor(protected length: number) {}
|
||||
|
||||
mark(): symbol {
|
||||
const symbol = Symbol();
|
||||
this.symbolMap.set(symbol, this.dirtyFlag);
|
||||
return symbol;
|
||||
}
|
||||
|
||||
unmark(mark: symbol): void {
|
||||
this.symbolMap.delete(mark);
|
||||
}
|
||||
|
||||
dirtySince(mark: symbol): Set<T> {
|
||||
const num = this.symbolMap.get(mark);
|
||||
const res = new Set<T>();
|
||||
if (isNil(num)) return res;
|
||||
this.markMap.forEach((v, k) => {
|
||||
if (v > num) res.add(k);
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
hasMark(symbol: symbol): boolean {
|
||||
return this.symbolMap.has(symbol);
|
||||
}
|
||||
|
||||
protected dirty(data: T): void {
|
||||
if (data >= this.length) return;
|
||||
this.dirtyFlag++;
|
||||
this.markMap.set(data, this.dirtyFlag);
|
||||
}
|
||||
|
||||
protected updateLength(length: number) {
|
||||
this.length = length;
|
||||
}
|
||||
}
|
||||
|
||||
export class PrivateMapDirtyTracker<T extends string>
|
||||
implements IDirtyTracker<Record<T, boolean>>
|
||||
{
|
||||
/** 标记映射,键表示名称,值表示其对应的标记数字 */
|
||||
private readonly markMap: Map<T, number> = new Map();
|
||||
/** 标记 symbol 映射,值表示这个 symbol 对应的标记数字 */
|
||||
private readonly symbolMap: WeakMap<symbol, number> = new WeakMap();
|
||||
|
||||
/** 脏标记数字 */
|
||||
private dirtyFlag: number = 0;
|
||||
|
||||
constructor(protected length: number) {}
|
||||
|
||||
mark(): symbol {
|
||||
const symbol = Symbol();
|
||||
this.symbolMap.set(symbol, this.dirtyFlag);
|
||||
return symbol;
|
||||
}
|
||||
|
||||
unmark(mark: symbol): void {
|
||||
this.symbolMap.delete(mark);
|
||||
}
|
||||
|
||||
dirtySince(mark: symbol): Record<T, boolean> {
|
||||
const num = this.symbolMap.get(mark) ?? 0;
|
||||
const obj: Partial<Record<T, boolean>> = {};
|
||||
this.markMap.forEach((v, k) => {
|
||||
if (v > num) obj[k] = true;
|
||||
else obj[k] = false;
|
||||
});
|
||||
return obj as Record<T, boolean>;
|
||||
}
|
||||
|
||||
hasMark(symbol: symbol): boolean {
|
||||
return this.symbolMap.has(symbol);
|
||||
}
|
||||
|
||||
protected dirty(data: T): void {
|
||||
this.dirtyFlag++;
|
||||
this.markMap.set(data, this.dirtyFlag);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,4 @@
|
||||
export * from './dirtyTracker';
|
||||
export * from './logger';
|
||||
export * from './utils';
|
||||
export * from './types';
|
||||
@@ -27,6 +27,21 @@
|
||||
"25": "Unknown audio type. Header: '$1'",
|
||||
"26": "Uncaught error when fetching stream data from '$1'. Error info: $2.",
|
||||
"27": "No autotile connection data, please ensure you have created autotile connection map.",
|
||||
"28": "Cannot compile map render shader.",
|
||||
"29": "Cannot get uniform location of map render shader.",
|
||||
"30": "",
|
||||
"31": "No asset data is specified when rending map.",
|
||||
"32": "Every layer added to map renderer must share the same size. Different layer: $1.",
|
||||
"33": "Map layer transfered to vertex generator must belong to the renderer that the generator use.",
|
||||
"34": "The texture of moving block must be a part of built asset.",
|
||||
"35": "Tile background transfered to map renderer does not exists.",
|
||||
"36": "Tile background transfered to map renderer has no frame data.",
|
||||
"37": "Frame of tile background transfered to map renderer must share the same size.",
|
||||
"38": "Cached texture cannot be convert to asset. This is likely an internal bug, please contact us.",
|
||||
"39": "Offset pool size exceeds WebGL2 limitation, ensure size type of your big image is less than $1.",
|
||||
"40": "Material used by map block $1 is not found in built asset. Please ensure you have pack it into asset.",
|
||||
"41": "You are trying to use a texture on moving block whose offset is not in the offset pool, please build it into asset after loading.",
|
||||
"42": "The layerList property of map-render element is required.",
|
||||
"1101": "Shadow extension needs 'floor-hero' extension as dependency.",
|
||||
"1201": "Floor-damage extension needs 'floor-binder' extension as dependency.",
|
||||
"1301": "Portal extension need 'floor-binder' extension as dependency.",
|
||||
@@ -112,6 +127,10 @@
|
||||
"77": "Texture is clipped to an area of 0. Ensure that the texture contains your clip rect and clip rect's area is not zero.",
|
||||
"78": "Adding tileset source must follow index order.",
|
||||
"79": "Assets can only be built once.",
|
||||
"80": "Parameter count of MapLayer.getMapData must be 0 or 4.",
|
||||
"81": "Map data to get is partially (or totally) out of range. Overflowed area will be filled with zero.",
|
||||
"82": "Big image offset size is larger than 64. Considier reduce big image offset bucket.",
|
||||
"83": "It seems that you call 'updateBlock' too frequently. This will extremely affect game's performance, so considering integrate them into one 'updateArea' or 'updateBlockList' call.",
|
||||
"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."
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
export interface IDirtyMarker<T> {
|
||||
/**
|
||||
* 标记为脏,即进行了一次更新
|
||||
* @param data 传递给追踪器的数据
|
||||
*/
|
||||
dirty(data: T): void;
|
||||
}
|
||||
|
||||
export interface IDirtyTracker<T> {
|
||||
/**
|
||||
* 对状态进行标记
|
||||
*/
|
||||
mark(): symbol;
|
||||
|
||||
/**
|
||||
* 取消指定标记符号
|
||||
* @param mark 标记符号
|
||||
*/
|
||||
unmark(mark: symbol): void;
|
||||
|
||||
/**
|
||||
* 从指定标记符号开始,数据是否发生了变动
|
||||
* @param mark 标记符号
|
||||
*/
|
||||
dirtySince(mark: symbol): T;
|
||||
|
||||
/**
|
||||
* 当前追踪器是否包含指定标记符号
|
||||
* @param symbol 标记符号
|
||||
*/
|
||||
hasMark(symbol: symbol): boolean;
|
||||
}
|
||||
Reference in new issue
Block a user