mirror of
https://github.com/motajs/template.git
synced 2026-11-22 04:54:30 +08:00
refactor: 存档系统挪至渲染端
This commit is contained in:
1 parent
89434537c8
commit
94ceb50cfe
12 files changed
+212
-215
No files matched your search
@@ -78,9 +78,9 @@ export class MapRenderer
|
||||
assetWidth: number = 4096;
|
||||
assetHeight: number = 4096;
|
||||
|
||||
layerState: IGameMap;
|
||||
map: IGameMap | null = null;
|
||||
/** 地图状态钩子控制器 */
|
||||
private layerStateHook: IHookController<IGameMapHooks>;
|
||||
private mapHook: IHookController<IGameMapHooks> | null = null;
|
||||
|
||||
/** 排序后的图层 */
|
||||
private sortedLayers: IMapLayer[] = [];
|
||||
@@ -205,13 +205,8 @@ export class MapRenderer
|
||||
/**
|
||||
* 创建地图渲染器
|
||||
* @param manager 素材管理器
|
||||
* @param gl 画布 WebGL2 上下文
|
||||
* @param transform 视角变换矩阵
|
||||
*/
|
||||
constructor(
|
||||
readonly manager: IMaterialManager,
|
||||
layerState: IGameMap
|
||||
) {
|
||||
constructor(readonly manager: IMaterialManager) {
|
||||
this.movingIndexPool.push(
|
||||
...Array.from({ length: this.movingCount }, (_, i) => i).reverse()
|
||||
);
|
||||
@@ -219,11 +214,6 @@ export class MapRenderer
|
||||
this.gl = this.canvas.getContext('webgl2')!;
|
||||
this.transform = new Transform();
|
||||
this.transform.bind(this);
|
||||
this.layerState = layerState;
|
||||
this.layerStateHook = layerState.addHook(
|
||||
new RendererLayerStateHook(this)
|
||||
);
|
||||
this.layerStateHook.load();
|
||||
// 上下文初始化要依赖于 offsetPool,因此提前调用
|
||||
const offsetPool = this.getOffsetPool();
|
||||
this.offsetPool = offsetPool;
|
||||
@@ -414,40 +404,42 @@ export class MapRenderer
|
||||
* 图层排序
|
||||
*/
|
||||
private sortLayer() {
|
||||
this.sortedLayers = [...this.layerState.layerList].sort((a, b) => {
|
||||
if (!this.map) return;
|
||||
this.sortedLayers = [...this.map.layerList].sort((a, b) => {
|
||||
return a.zIndex - b.zIndex;
|
||||
});
|
||||
this.sortedLayers.forEach((v, i) => this.layerIndexMap.set(v, i));
|
||||
}
|
||||
|
||||
updateLayerList() {
|
||||
if (!this.map) return;
|
||||
this.sortLayer();
|
||||
this.resizeLayer();
|
||||
this.layerCount = this.layerState.layerList.size;
|
||||
this.layerCount = this.map.layerList.size;
|
||||
this.vertex.updateLayerArray();
|
||||
}
|
||||
|
||||
setLayerState(layerState: IGameMap): void {
|
||||
if (layerState === this.layerState) return;
|
||||
this.layerStateHook.unload();
|
||||
this.layerState = layerState;
|
||||
this.layerStateHook = layerState.addHook(
|
||||
new RendererLayerStateHook(this)
|
||||
);
|
||||
this.layerStateHook.load();
|
||||
setLayerState(map: IGameMap): void {
|
||||
if (map === this.map) return;
|
||||
this.mapHook?.unload();
|
||||
this.map = map;
|
||||
this.mapHook = map.addHook(new RendererLayerStateHook(this));
|
||||
this.mapHook.load();
|
||||
this.sortLayer();
|
||||
this.resizeLayer();
|
||||
this.layerCount = layerState.layerList.size;
|
||||
this.layerCount = map.layerList.size;
|
||||
this.vertex.updateLayerArray();
|
||||
this.vertex.resizeMap();
|
||||
}
|
||||
|
||||
getLayer(identifier: string): IMapLayer | null {
|
||||
return this.layerState.getLayerByAlias(identifier) ?? null;
|
||||
if (!this.map) return null;
|
||||
return this.map.getLayerByAlias(identifier) ?? null;
|
||||
}
|
||||
|
||||
hasLayer(layer: IMapLayer): boolean {
|
||||
return this.layerState.hasLayer(layer);
|
||||
if (!this.map) return false;
|
||||
return this.map.hasLayer(layer);
|
||||
}
|
||||
|
||||
getSortedLayer(): IMapLayer[] {
|
||||
|
||||
@@ -339,7 +339,7 @@ export interface IMapRenderer {
|
||||
/** 顶点数组生成器 */
|
||||
readonly vertex: IMapVertexGenerator;
|
||||
/** 使用的地图状态对象 */
|
||||
readonly layerState: IGameMap;
|
||||
readonly map: IGameMap | null;
|
||||
|
||||
/** 地图宽度 */
|
||||
readonly mapWidth: number;
|
||||
|
||||
Reference in new issue
Block a user