mirror of
https://github.com/motajs/template.git
synced 2026-11-25 15:34:30 +08:00
refactor: 重写缩略图组件
This commit is contained in:
1 parent
282875c956
commit
d29d0f7dbe
11 files changed
+570
-156
No files matched your search
@@ -11,3 +11,4 @@ export * from './textbox';
|
||||
export * from './textboxTyper';
|
||||
export * from './thumbnail';
|
||||
export * from './tip';
|
||||
export * from './winskin';
|
||||
@@ -1,84 +1,428 @@
|
||||
import {
|
||||
ElementLocator,
|
||||
MotaOffscreenCanvas2D,
|
||||
CustomRenderItem
|
||||
Transform
|
||||
} from '@motajs/render';
|
||||
import { CustomProps } from '@motajs/render-vue';
|
||||
import { defineComponent, ref, watch } from 'vue';
|
||||
import { DefaultProps, xywh } from '@motajs/render-vue';
|
||||
import { computed, defineComponent, watch } from 'vue';
|
||||
import { SetupComponentOptions } from '@motajs/system';
|
||||
import { IMapRenderer } from '../map';
|
||||
import { IMapState } from '@user/data-base';
|
||||
import { clamp, isNil } from 'lodash-es';
|
||||
|
||||
export interface ThumbnailProps extends CustomProps {
|
||||
/** 缩略图的位置 */
|
||||
loc: ElementLocator;
|
||||
// TODO: 显伤
|
||||
|
||||
export interface IThumbnailCellProps extends DefaultProps {
|
||||
/** 楼层 ID */
|
||||
floorId: FloorIds;
|
||||
/** 缩略图填充样式 */
|
||||
padStyle?: CanvasStyle;
|
||||
/** 楼层信息 */
|
||||
map?: Block[];
|
||||
/** 角色信息 */
|
||||
hero?: HeroStatus;
|
||||
// configs
|
||||
damage?: boolean;
|
||||
all?: boolean;
|
||||
noHD?: boolean;
|
||||
/** 缩略图的比例,1 表示与实际地图大小一致 */
|
||||
floorId?: string;
|
||||
/** 楼层存储对象 */
|
||||
maps?: IMapState;
|
||||
/** 地图渲染器,注意如果你不知道地图渲染的细节,一定永远传入 `expandMapRenderer`! */
|
||||
renderer?: IMapRenderer;
|
||||
/** 显示尺寸,1 表示与原始尺寸一致,默认为 1 */
|
||||
size?: number;
|
||||
/** 显示区域的左上角**分块坐标**,写小数会向下取整 */
|
||||
origin?: [x: number, y: number];
|
||||
/**
|
||||
* 是否自动根据 `size` 和显示区域适应元素尺寸,启用时会自动适应元素尺寸,传入尺寸无效。
|
||||
* 若未启用,地图将会画在容器的左上角位置,不会居中绘制。剩余内容会完全透明。
|
||||
*/
|
||||
autoSize?: boolean;
|
||||
/** 是否渲染伤害数字 */
|
||||
damage?: boolean;
|
||||
}
|
||||
|
||||
export type ThumbnailCellEmits = {
|
||||
/**
|
||||
* 在 `autoSize` 条件下,当元素尺寸修改时触发,未启用 `autoSize` 不会触发
|
||||
* @param width 更新后的宽度
|
||||
* @param height 更新后的高度
|
||||
*/
|
||||
updateSize: (width: number, height: number) => void;
|
||||
};
|
||||
|
||||
const thumbnailCellProps = {
|
||||
props: [
|
||||
'floorId',
|
||||
'maps',
|
||||
'renderer',
|
||||
'size',
|
||||
'origin',
|
||||
'autoSize',
|
||||
'damage',
|
||||
'loc',
|
||||
'x',
|
||||
'y',
|
||||
'width',
|
||||
'height'
|
||||
],
|
||||
emits: ['updateSize']
|
||||
} satisfies SetupComponentOptions<
|
||||
IThumbnailCellProps,
|
||||
ThumbnailCellEmits,
|
||||
keyof ThumbnailCellEmits
|
||||
>;
|
||||
|
||||
/**
|
||||
* 渲染地图缩略图的一个区块。注意,地图渲染器是一个状态机,如果频繁切换地图会导致性能严重下降,
|
||||
* 如果你需要使用此组件同时渲染多个不同地图区块,建议给同一地图缩略图添加相同的 `zIndex` 以减少地图切换,提高性能表现。
|
||||
*/
|
||||
export const ThumbnailCell = defineComponent<
|
||||
IThumbnailCellProps,
|
||||
ThumbnailCellEmits,
|
||||
keyof ThumbnailCellEmits
|
||||
>((props, { emit }) => {
|
||||
const [x, y, width, height] = xywh(props);
|
||||
|
||||
/** 渲染缩放尺寸 */
|
||||
const size = computed(() => props.size ?? 1);
|
||||
/** 当前地图 */
|
||||
const map = computed(() => {
|
||||
if (isNil(props.floorId) || !props.maps) return null;
|
||||
return props.maps.getMap(props.floorId);
|
||||
});
|
||||
/** 分块坐标 */
|
||||
const origin = computed<[number, number]>(() => {
|
||||
if (!props.origin) return [0, 0];
|
||||
const [x, y] = props.origin;
|
||||
return [Math.floor(x), Math.floor(y)];
|
||||
});
|
||||
|
||||
/** 渲染区域大小 */
|
||||
const chunkSize = computed<[number, number]>(() => {
|
||||
const renderer = props.renderer;
|
||||
if (!renderer || !props.origin || !map.value) return [0, 0];
|
||||
const [ox, oy] = props.origin;
|
||||
const { chunkWidth, chunkHeight } = renderer.vertex.block;
|
||||
const { width, height } = map.value;
|
||||
const sx = ox * chunkWidth;
|
||||
const sy = oy * chunkHeight;
|
||||
const restWidth = width - sx;
|
||||
const restHeight = height - sy;
|
||||
return [
|
||||
clamp(restWidth, 0, chunkWidth),
|
||||
clamp(restHeight, 0, chunkHeight)
|
||||
];
|
||||
});
|
||||
|
||||
/** 真实的渲染尺寸 */
|
||||
const renderSize = computed<[number, number]>(() => {
|
||||
const renderer = props.renderer;
|
||||
if (!renderer) return [1, 1];
|
||||
const [cw, ch] = chunkSize.value;
|
||||
if (cw === 0 || ch === 0) return [1, 1];
|
||||
const { cellWidth, cellHeight } = renderer;
|
||||
return [cw * cellWidth * size.value, ch * cellHeight * size.value];
|
||||
});
|
||||
|
||||
/** 元素定位 */
|
||||
const loc = computed<ElementLocator>(() => {
|
||||
if (props.autoSize) {
|
||||
const [w, h] = renderSize.value;
|
||||
return [x.value, y.value, w, h];
|
||||
} else {
|
||||
return [x.value, y.value, width.value, height.value];
|
||||
}
|
||||
});
|
||||
|
||||
watch(renderSize, ([w, h]) => {
|
||||
if (props.autoSize) {
|
||||
emit('updateSize', w, h);
|
||||
}
|
||||
});
|
||||
|
||||
const render = (canvas: MotaOffscreenCanvas2D) => {
|
||||
const [cw, ch] = chunkSize.value;
|
||||
const ctx = canvas.ctx;
|
||||
if (!props.renderer || !map.value || cw === 0 || ch === 0) {
|
||||
ctx.fillStyle = 'black';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
const hw = canvas.width / 2;
|
||||
const hh = canvas.height / 2;
|
||||
ctx.fillText('未绑定渲染器或楼层对象', hw, hh);
|
||||
return;
|
||||
}
|
||||
const renderer = props.renderer;
|
||||
// 重置激励时间戳,保证显示内容的一致性,不会因为动画导致显示内容变化
|
||||
renderer.excited(0);
|
||||
renderer.setGameMap(map.value);
|
||||
const { width, height } = renderer.canvas;
|
||||
const [rw, rh] = renderSize.value;
|
||||
const [ox, oy] = origin.value;
|
||||
/** 区块起始位置的像素横坐标 */
|
||||
const otx = ox * rw;
|
||||
/** 区块起始位置的像素纵坐标 */
|
||||
const oty = oy * rh;
|
||||
// 为了保证渲染精度正确,如果 renderSize 大于画布尺寸,那么还需要专门拼图,所以这里要取二者的较小值
|
||||
const dw = Math.min(width, rw);
|
||||
const dh = Math.min(height, rh);
|
||||
renderer.setRenderSize(dw, dh);
|
||||
const xCount = Math.ceil(rw / dw - 1e-8);
|
||||
const yCount = Math.ceil(rh / dh - 1e-8);
|
||||
const before = renderer.transform;
|
||||
const transform = new Transform();
|
||||
renderer.setTransform(transform);
|
||||
|
||||
if (xCount === 1 && yCount === 1) {
|
||||
// 若二者都是 1,说明渲染区域在画布范围内,那么好说,渲染一次足够,大多数情况下应该都走这条分支
|
||||
renderer.setViewport(0, 0, dw, dh);
|
||||
transform.translate(otx / dw, oty / dh);
|
||||
transform.scale(size.value);
|
||||
const result = renderer.render();
|
||||
ctx.drawImage(result.canvas, 0, 0, dw, dh, 0, 0, dw, dh);
|
||||
} else {
|
||||
// 如果不是的话,说明需要专门拼接
|
||||
// 拼接按照先横向再纵向的顺序
|
||||
for (let ny = 0; ny < yCount - 1; ny++) {
|
||||
renderer.setViewport(0, 0, dw, dh);
|
||||
for (let nx = 0; nx < xCount - 1; nx++) {
|
||||
/** 这个拼接位置的像素横坐标 */
|
||||
const rtx = otx / dw + nx;
|
||||
/** 这个拼接位置的像素纵坐标 */
|
||||
const rty = oty / dh + ny;
|
||||
transform.reset();
|
||||
transform.translate(rtx, rty);
|
||||
transform.scale(size.value);
|
||||
const result = renderer.render();
|
||||
const dx = dw * nx;
|
||||
const dy = dh * ny;
|
||||
ctx.drawImage(result.canvas, 0, 0, dw, dh, dx, dy, dw, dh);
|
||||
}
|
||||
// 尾部要专门处理,避免涉及下一个区块,不增加不必要的区块顶点生成
|
||||
// 算法是先获取渲染区域最右侧的坐标,然后 -1 得到对应左侧的坐标
|
||||
// 注意这里要裁剪,只取最右侧的一部分
|
||||
const rtx = (otx + rw) / dw - 1;
|
||||
const rty = oty / dh + ny;
|
||||
const sw = rw % dw;
|
||||
const sx = dw - sw;
|
||||
transform.reset();
|
||||
transform.translate(rtx, rty);
|
||||
transform.scale(size.value);
|
||||
const result = renderer.render();
|
||||
const dx = dw * (xCount - 1);
|
||||
const dy = dh * ny;
|
||||
ctx.drawImage(result.canvas, sx, 0, sw, dh, dx, dy, sw, dh);
|
||||
}
|
||||
// 纵向的尾部也要单独处理
|
||||
for (let nx = 0; nx < xCount - 1; nx++) {
|
||||
const rtx = otx / dw + nx;
|
||||
const rty = (oty + rh) / dh - 1;
|
||||
const sh = rh % dh;
|
||||
const sy = dh - sh;
|
||||
transform.reset();
|
||||
transform.translate(rtx, rty);
|
||||
transform.scale(size.value);
|
||||
const result = renderer.render();
|
||||
const dx = dw * nx;
|
||||
const dy = dh * (yCount - 1);
|
||||
ctx.drawImage(result.canvas, 0, sy, dw, sh, dx, dy, dw, sh);
|
||||
}
|
||||
// 还有最右下角的一个小块
|
||||
const rtx = (otx + rw) / dw - 1;
|
||||
const rty = (oty + rh) / dh - 1;
|
||||
const sw = rw % dw;
|
||||
const sx = dw - sw;
|
||||
const sh = rh % dh;
|
||||
const sy = dh - sh;
|
||||
transform.reset();
|
||||
transform.translate(rtx, rty);
|
||||
transform.scale(size.value);
|
||||
const result = renderer.render();
|
||||
const dx = dw * (xCount - 1);
|
||||
const dy = dh * (yCount - 1);
|
||||
ctx.drawImage(result.canvas, sx, sy, sw, sh, dx, dy, sw, sh);
|
||||
}
|
||||
|
||||
renderer.setTransform(before);
|
||||
};
|
||||
|
||||
return () => (
|
||||
<custom
|
||||
loc={loc.value}
|
||||
render={render}
|
||||
bindings={[map.value, renderSize.value]}
|
||||
noanti
|
||||
/>
|
||||
);
|
||||
}, thumbnailCellProps);
|
||||
|
||||
interface IThumbnailChunk {
|
||||
/** 这个区块的定位 */
|
||||
readonly loc: ElementLocator;
|
||||
/** 区块位置 */
|
||||
readonly origin: [number, number];
|
||||
}
|
||||
|
||||
interface IThumbnailChunkData {
|
||||
/** 每个区块的数据 */
|
||||
readonly chunks: IThumbnailChunk[];
|
||||
/** 裁切矩形的定位 */
|
||||
readonly slice: ElementLocator;
|
||||
}
|
||||
|
||||
export interface ThumbnailProps extends DefaultProps {
|
||||
/** 楼层 ID */
|
||||
floorId?: string;
|
||||
/** 楼层存储对象 */
|
||||
maps?: IMapState;
|
||||
/** 缩略图填充样式,默认为黑色 */
|
||||
padStyle?: CanvasStyle;
|
||||
/** 地图渲染器,注意如果你不知道地图渲染的细节,一定永远传入 `expandMapRenderer`! */
|
||||
renderer?: IMapRenderer;
|
||||
/**
|
||||
* 要展示的地图区域的**格子坐标**,可以写小数以显示半个格子,超出地图范围的会被忽略,
|
||||
* 地图会被正确平移,例如起始横坐标为 -1,那么地图会从 1 处开始画,最左侧一列会留空。
|
||||
*/
|
||||
area?: [x: number, y: number, w: number, h: number];
|
||||
/** 显示尺寸,1 表示与原始尺寸一致,默认为 1 */
|
||||
size?: number;
|
||||
/**
|
||||
* 是否自适应元素尺寸,启用后会根据渲染区域和尺寸等自动设置元素的尺寸,此时传入尺寸无效。
|
||||
* 不启用时,缩略图会画在容器的左上角,为包含地图的区域会使用 `padStyle` 填充。
|
||||
*/
|
||||
autoSize?: boolean;
|
||||
/** 是否启用伤害显示 */
|
||||
damage?: boolean;
|
||||
}
|
||||
|
||||
const thumbnailProps = {
|
||||
props: [
|
||||
'loc',
|
||||
'padStyle',
|
||||
'floorId',
|
||||
'map',
|
||||
'hero',
|
||||
'maps',
|
||||
'padStyle',
|
||||
'renderer',
|
||||
'area',
|
||||
'size',
|
||||
'autoSize',
|
||||
'damage',
|
||||
'all',
|
||||
'noHD',
|
||||
'size'
|
||||
'loc',
|
||||
'x',
|
||||
'y',
|
||||
'width',
|
||||
'height'
|
||||
]
|
||||
} satisfies SetupComponentOptions<ThumbnailProps>;
|
||||
|
||||
export const Thumbnail = defineComponent<ThumbnailProps>(props => {
|
||||
const spriteRef = ref<CustomRenderItem>();
|
||||
/** 空白区域填充样式 */
|
||||
const padStyle = computed(() => props.padStyle ?? 'black');
|
||||
/** 渲染尺寸比例 */
|
||||
const size = computed(() => props.size ?? 1);
|
||||
|
||||
const update = () => {
|
||||
spriteRef.value?.update();
|
||||
};
|
||||
const [x, y, width, height] = xywh(props);
|
||||
|
||||
const drawThumbnail = (canvas: MotaOffscreenCanvas2D) => {
|
||||
if (props.hidden) return;
|
||||
const ctx = canvas.ctx;
|
||||
const hero = props.hero;
|
||||
const options: Partial<DrawThumbnailConfig> = {
|
||||
damage: props.damage,
|
||||
ctx: ctx,
|
||||
x: 0,
|
||||
y: 0,
|
||||
size: props.size ?? 1,
|
||||
all: props.all,
|
||||
noHD: props.noHD,
|
||||
v2: true,
|
||||
inFlyMap: false
|
||||
};
|
||||
if (hero) {
|
||||
options.heroLoc = hero.loc;
|
||||
options.heroIcon = hero.image;
|
||||
options.flags = hero.flags;
|
||||
options.centerX = hero.loc.x;
|
||||
options.centerY = hero.loc.y;
|
||||
/** 当前地图 */
|
||||
const map = computed(() => {
|
||||
if (isNil(props.floorId) || !props.maps) return null;
|
||||
return props.maps.getMap(props.floorId);
|
||||
});
|
||||
|
||||
/** 渲染区域,考虑了区域是否超出了地图范围 */
|
||||
const area = computed<[number, number, number, number]>(() => {
|
||||
if (!props.area || !map.value) return [0, 0, 0, 0];
|
||||
const [x, y, w, h] = props.area;
|
||||
if (w <= 0 || h <= 0) return [0, 0, 0, 0];
|
||||
const { width, height } = map.value;
|
||||
const left = clamp(x, 0, width - 1);
|
||||
const top = clamp(y, 0, height - 1);
|
||||
const right = clamp(x + w, 0, width);
|
||||
const bottom = clamp(y + h, 0, height);
|
||||
return [left, top, right - left, bottom - top];
|
||||
});
|
||||
|
||||
/** 渲染尺寸 */
|
||||
const renderSize = computed(() => {
|
||||
const renderer = props.renderer;
|
||||
if (!renderer || !props.area) return [1, 1];
|
||||
const [, , w, h] = props.area;
|
||||
const { cellWidth, cellHeight } = renderer;
|
||||
return [cellWidth * w * size.value, cellHeight * h * size.value];
|
||||
});
|
||||
|
||||
/** 元素定位 */
|
||||
const loc = computed<ElementLocator>(() => {
|
||||
if (props.autoSize) {
|
||||
const [w, h] = renderSize.value;
|
||||
return [x.value, y.value, w, h];
|
||||
} else {
|
||||
return [x.value, y.value, width.value, height.value];
|
||||
}
|
||||
ctx.save();
|
||||
ctx.fillStyle = props.padStyle ?? 'black';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
core.drawThumbnail(props.floorId, props.map, options);
|
||||
ctx.restore();
|
||||
};
|
||||
});
|
||||
|
||||
watch(props, update);
|
||||
const chunks = computed<IThumbnailChunkData>(() => {
|
||||
const renderer = props.renderer;
|
||||
if (!renderer || !props.area) {
|
||||
return {
|
||||
chunks: [],
|
||||
slice: []
|
||||
};
|
||||
}
|
||||
// 原始的 area 还需要用来考虑平移,所以也要读取
|
||||
const [x, y] = props.area;
|
||||
const [nx, ny, nw, nh] = area.value;
|
||||
const { chunkWidth, chunkHeight } = renderer.vertex.block;
|
||||
const startChunkX = Math.floor(nx / chunkWidth + 1e-8);
|
||||
const startChunkY = Math.floor(ny / chunkHeight + 1e-8);
|
||||
const endChunkX = Math.ceil((nx + nw) / chunkWidth - 1e-8);
|
||||
const endChunkY = Math.ceil((ny + nh) / chunkHeight - 1e-8);
|
||||
const xCount = endChunkX - startChunkX;
|
||||
const yCount = endChunkY - startChunkY;
|
||||
const startTileX = startChunkX * chunkWidth;
|
||||
const startTileY = startChunkY * chunkHeight;
|
||||
const chunkPixelWidth = chunkWidth * renderer.cellWidth * size.value;
|
||||
const chunkPixelHeight = chunkHeight * renderer.cellHeight * size.value;
|
||||
|
||||
const chunks: IThumbnailChunk[] = [];
|
||||
for (let ny = 0; ny < yCount; ny++) {
|
||||
for (let nx = 0; nx < xCount; nx++) {
|
||||
const cx = startTileX + nx * chunkWidth - x;
|
||||
const cy = startTileY + ny * chunkHeight - y;
|
||||
const cpx = cx * renderer.cellWidth * size.value;
|
||||
const cpy = cy * renderer.cellHeight * size.value;
|
||||
chunks.push({
|
||||
loc: [cpx, cpy, chunkPixelWidth, chunkPixelHeight],
|
||||
origin: [nx + startChunkX, ny + startChunkY]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const sx = Math.max(0, (nx - x) * renderer.cellWidth * size.value);
|
||||
const sy = Math.max(0, (ny - y) * renderer.cellHeight * size.value);
|
||||
const sw = nw * renderer.cellWidth * size.value;
|
||||
const sh = nh * renderer.cellHeight * size.value;
|
||||
|
||||
return { chunks, slice: [sx, sy, sw, sh] };
|
||||
});
|
||||
|
||||
return () => (
|
||||
<custom noanti ref={spriteRef} loc={props.loc} render={drawThumbnail} />
|
||||
<container loc={loc.value} nocache>
|
||||
<g-rect
|
||||
loc={[0, 0, loc.value[2], loc.value[3]]}
|
||||
fillStyle={padStyle.value}
|
||||
zIndex={0}
|
||||
/>
|
||||
<container loc={[0, 0, loc.value[2], loc.value[3]]} zIndex={10}>
|
||||
{chunks.value.chunks.map(chunk => (
|
||||
<ThumbnailCell
|
||||
loc={chunk.loc}
|
||||
origin={chunk.origin}
|
||||
renderer={props.renderer}
|
||||
maps={props.maps}
|
||||
floorId={props.floorId}
|
||||
size={size.value}
|
||||
damage={props.damage}
|
||||
/>
|
||||
))}
|
||||
<g-rect
|
||||
loc={chunks.value.slice}
|
||||
fillStyle="#FFF"
|
||||
zIndex={10}
|
||||
composite="destination-in"
|
||||
/>
|
||||
</container>
|
||||
</container>
|
||||
);
|
||||
}, thumbnailProps);
|
||||
@@ -1,2 +1,12 @@
|
||||
/** 单个图块的实例化数据数量 */
|
||||
export const INSTANCED_COUNT = 4 + 4 + 4 + 4;
|
||||
/**
|
||||
* 覆盖层内容预留,不明白含义的话不要动。需要移动或需要半透明渲染的图块会处于覆盖层,这些内容的数量无法预测,因此需要预留数组大小,
|
||||
* 如果不够再临时扩充。如果你的游戏中有大量的移动操作或半透明图块,可以适当提高此值,避免频繁的内存扩充行为,可以一定程度上提高性能表现。
|
||||
*/
|
||||
export const OVERLAY_RESERVE = 64;
|
||||
/**
|
||||
* 覆盖层图块容忍度,不明白含义的话不要动。如果覆盖层图块的数量长期小于当前预留数量,那么将会降低预留数量,提升性能表现。
|
||||
* 调整此值可以调整频率,值越大,越不容易因为数量小于预留数量而减小预留。
|
||||
*/
|
||||
export const OVERLAY_TOLERANCE = 60;
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
IMapBackgroundConfig,
|
||||
IMapRenderConfig,
|
||||
IMapRenderer,
|
||||
IMapRendererInitConfig,
|
||||
IMapRendererPostEffect,
|
||||
IMapRenderResult,
|
||||
IMapVertexGenerator,
|
||||
@@ -43,14 +44,12 @@ import mapVert from './shader/map.vert?raw';
|
||||
import mapFrag from './shader/map.frag?raw';
|
||||
import backVert from './shader/back.vert?raw';
|
||||
import backFrag from './shader/back.frag?raw';
|
||||
import {
|
||||
CELL_HEIGHT,
|
||||
CELL_WIDTH,
|
||||
DYNAMIC_RESERVE,
|
||||
MOVING_TOLERANCE
|
||||
} from '../shared';
|
||||
import { MapViewport } from './viewport';
|
||||
import { INSTANCED_COUNT } from './constant';
|
||||
import {
|
||||
INSTANCED_COUNT,
|
||||
OVERLAY_RESERVE,
|
||||
OVERLAY_TOLERANCE
|
||||
} from './constant';
|
||||
import { OverlayBlock, StaticBlockStatus } from './status';
|
||||
import { IExcitableController, IExcitation } from '@motajs/animate';
|
||||
|
||||
@@ -63,22 +62,21 @@ const enum BackgroundType {
|
||||
export class MapRenderer implements IMapRenderer, IMapDataGetter {
|
||||
//#region 实例属性
|
||||
|
||||
/** 自动元件处理器 */
|
||||
readonly autotile: IAutotileProcessor;
|
||||
/** 顶点数组生成器 */
|
||||
readonly vertex: IMapVertexGenerator;
|
||||
/** 地图渲染的视角控制 */
|
||||
readonly viewport: IMapViewportController;
|
||||
readonly manager: ITextureManager;
|
||||
|
||||
mapWidth: number = 0;
|
||||
mapHeight: number = 0;
|
||||
layerCount: number = 0;
|
||||
renderWidth: number = 0;
|
||||
renderHeight: number = 0;
|
||||
cellWidth: number = CELL_WIDTH;
|
||||
cellHeight: number = CELL_HEIGHT;
|
||||
cellWidth: number = 0;
|
||||
cellHeight: number = 0;
|
||||
assetWidth: number = 4096;
|
||||
assetHeight: number = 4096;
|
||||
canvasSizeFreezed: boolean = false;
|
||||
|
||||
map: IGameMap | null = null;
|
||||
/** 地图状态钩子控制器 */
|
||||
@@ -152,7 +150,7 @@ export class MapRenderer implements IMapRenderer, IMapDataGetter {
|
||||
/** 移动图块对象索引池 */
|
||||
private overlayIndexPool: number[] = [];
|
||||
/** 移动图块对象数量 */
|
||||
private overlayCount: number = DYNAMIC_RESERVE;
|
||||
private overlayCount: number = OVERLAY_RESERVE;
|
||||
/** 移动索引映射 */
|
||||
private overlayIndexMap: Map<number, IOverlayBlock> = new Map();
|
||||
/** 移动容忍度,如果正在移动的图块数量长期小于预留数量的一半,那么将减少移动数组长度 */
|
||||
@@ -211,7 +209,7 @@ export class MapRenderer implements IMapRenderer, IMapDataGetter {
|
||||
* 创建地图渲染器
|
||||
* @param manager 素材管理器
|
||||
*/
|
||||
constructor(readonly manager: ITextureManager) {
|
||||
constructor(config: IMapRendererInitConfig) {
|
||||
this.overlayIndexPool.push(
|
||||
...Array.from({ length: this.overlayCount }, (_, i) => i).reverse()
|
||||
);
|
||||
@@ -227,12 +225,15 @@ export class MapRenderer implements IMapRenderer, IMapDataGetter {
|
||||
v => v / data.tileTextureWidth
|
||||
);
|
||||
this.contextData = data;
|
||||
this.vertex = new MapVertexGenerator(this, data);
|
||||
this.autotile = manager.autotile;
|
||||
this.manager = config.manager;
|
||||
this.vertex = new MapVertexGenerator(this, data, config);
|
||||
this.autotile = this.manager.autotile;
|
||||
this.viewport = new MapViewport(this);
|
||||
this.tileAnimater = new TextureColumnAnimater();
|
||||
this.initVertexPointer(this.gl, data);
|
||||
this.setViewport(0, 0, this.canvas.width, this.canvas.height);
|
||||
this.cellWidth = config.initCellWidth;
|
||||
this.cellHeight = config.initCellHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -352,6 +353,13 @@ export class MapRenderer implements IMapRenderer, IMapDataGetter {
|
||||
}
|
||||
|
||||
setCanvasSize(width: number, height: number): void {
|
||||
if (this.canvasSizeFreezed) {
|
||||
logger.warn(215);
|
||||
return;
|
||||
}
|
||||
if (width === this.canvas.width && height === this.canvas.height) {
|
||||
return;
|
||||
}
|
||||
this.canvas.width = width;
|
||||
this.canvas.height = height;
|
||||
// 更新 FBO 的纹理尺寸信息
|
||||
@@ -406,6 +414,10 @@ export class MapRenderer implements IMapRenderer, IMapDataGetter {
|
||||
this.updateRequired = true;
|
||||
}
|
||||
|
||||
freezeCanvasSize(): void {
|
||||
this.canvasSizeFreezed = true;
|
||||
}
|
||||
|
||||
setViewport(x: number, y: number, width: number, height: number): void {
|
||||
this.viewportX = x;
|
||||
this.viewportY = y;
|
||||
@@ -1718,7 +1730,7 @@ export class MapRenderer implements IMapRenderer, IMapDataGetter {
|
||||
*/
|
||||
private reduceOverlay() {
|
||||
const half = Math.round(this.overlayCount / 2);
|
||||
if (half < DYNAMIC_RESERVE) return;
|
||||
if (half < OVERLAY_RESERVE) return;
|
||||
for (const moving of this.overlayBlocks) {
|
||||
if (moving.index >= half) return;
|
||||
}
|
||||
@@ -1735,7 +1747,7 @@ export class MapRenderer implements IMapRenderer, IMapDataGetter {
|
||||
}
|
||||
const half = Math.max(
|
||||
Math.round(this.overlayCount / 2),
|
||||
DYNAMIC_RESERVE
|
||||
OVERLAY_RESERVE
|
||||
);
|
||||
if (this.overlayIndexPool.length < half) {
|
||||
this.lastExpandTime = this.getTimestamp();
|
||||
@@ -1846,7 +1858,7 @@ export class MapRenderer implements IMapRenderer, IMapDataGetter {
|
||||
excited(payload: number) {
|
||||
// 移动数组
|
||||
const expandDT = payload - this.lastExpandTime;
|
||||
if (expandDT > MOVING_TOLERANCE * 1000) {
|
||||
if (expandDT > OVERLAY_TOLERANCE * 1000) {
|
||||
this.reduceOverlay();
|
||||
this.lastExpandTime = payload;
|
||||
}
|
||||
|
||||
@@ -188,6 +188,8 @@ export interface IContextData {
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region 图块状态
|
||||
|
||||
export interface IBlockStatus {
|
||||
/** 图块所属图层 */
|
||||
readonly layer: IMapLayer;
|
||||
@@ -326,6 +328,10 @@ export interface IRenderBlockMover extends IExcitable<number> {
|
||||
endMoving(keep?: boolean): void;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region 地图渲染器
|
||||
|
||||
export interface IMapRendererPostEffect {
|
||||
/** 当前后处理对象是否启用 */
|
||||
readonly enabled: boolean;
|
||||
@@ -370,11 +376,22 @@ export interface IMapRenderResult {
|
||||
readonly area: IMapRenderData;
|
||||
}
|
||||
|
||||
export interface IMapRendererInitConfig extends IMapVertexConfig {
|
||||
/** 贴图资源管理器 */
|
||||
readonly manager: ITextureManager;
|
||||
/** 每个图块的初始像素宽度 */
|
||||
readonly initCellWidth: number;
|
||||
/** 每个图块的初始像素高度 */
|
||||
readonly initCellHeight: number;
|
||||
}
|
||||
|
||||
export interface IMapRenderer extends IExcitable<number> {
|
||||
/** 地图渲染器使用的资源管理器 */
|
||||
readonly manager: ITextureManager;
|
||||
/** 画布渲染上下文 */
|
||||
readonly gl: WebGL2RenderingContext;
|
||||
/** 画布元素 */
|
||||
readonly canvas: HTMLCanvasElement;
|
||||
|
||||
/** 自动元件处理对象 */
|
||||
readonly autotile: IAutotileProcessor;
|
||||
@@ -406,6 +423,9 @@ export interface IMapRenderer extends IExcitable<number> {
|
||||
/** 图集高度 */
|
||||
readonly assetHeight: number;
|
||||
|
||||
/** 当前是否冻结了画布尺寸,冻结后不允许修改画布尺寸与分块尺寸 */
|
||||
readonly canvasSizeFreezed: boolean;
|
||||
|
||||
/**
|
||||
* 设置地图渲染器使用的激励源对象
|
||||
* @param excitation 激励源对象
|
||||
@@ -464,6 +484,11 @@ export interface IMapRenderer extends IExcitable<number> {
|
||||
*/
|
||||
setCanvasSize(width: number, height: number): void;
|
||||
|
||||
/**
|
||||
* 冻结画布尺寸,之后不再允许修改画布尺寸与分块尺寸
|
||||
*/
|
||||
freezeCanvasSize(): void;
|
||||
|
||||
/**
|
||||
* 设置渲染区域,等于 `gl.viewport`
|
||||
* @param x 左上角横坐标
|
||||
@@ -634,21 +659,9 @@ export interface IMapRenderer extends IExcitable<number> {
|
||||
needUpdate(): boolean;
|
||||
}
|
||||
|
||||
export interface IMapVertexArray {
|
||||
/**
|
||||
* 地图渲染实例化数组,结构是一个三维张量 `[B, L, T]`,其中 `B` 代表分块,`L` 代表图层,`T` 代表图块,并按照结构顺序平铺存储。
|
||||
*
|
||||
* 语义解释就是,最内层存储图块,再外面一层存储图层,最外层存储分块。这样的话可以一次性将一个分块的所有图层渲染完毕。
|
||||
*
|
||||
* 依次存储 a_tilePos, a_texCoord, a_tileData, a_texData
|
||||
*/
|
||||
readonly tileInstanced: Float32Array;
|
||||
//#endregion
|
||||
|
||||
/** 动态内容的起始索引,以实例为单位 */
|
||||
readonly dynamicStart: number;
|
||||
/** 动态内容的数量,以实例为单位 */
|
||||
readonly dynamicCount: number;
|
||||
}
|
||||
//#region 地图分块
|
||||
|
||||
export interface IChunkIndex {
|
||||
/** 横坐标 */
|
||||
@@ -882,6 +895,10 @@ export interface IBlockSplitter<T> extends IChunkSplitterConfig {
|
||||
splitChunks(mapFn: (block: IChunkInfo) => T): void;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region 地图分块数据
|
||||
|
||||
export interface IMapVertexData {
|
||||
/** 这个分块的实例化数据数组 */
|
||||
readonly instancedArray: Float32Array;
|
||||
@@ -988,6 +1005,10 @@ export interface IMapVertexBlock extends IMapVertexData {
|
||||
deleteAttachedData(symbol: symbol): void;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region 顶点数组
|
||||
|
||||
export interface IMapBlockUpdateObject {
|
||||
/** 要更新为的图块数字 */
|
||||
readonly block: number;
|
||||
@@ -997,6 +1018,22 @@ export interface IMapBlockUpdateObject {
|
||||
readonly y: number;
|
||||
}
|
||||
|
||||
export interface IMapVertexArray {
|
||||
/**
|
||||
* 地图渲染实例化数组,结构是一个三维张量 `[B, L, T]`,其中 `B` 代表分块,`L` 代表图层,`T` 代表图块,并按照结构顺序平铺存储。
|
||||
*
|
||||
* 语义解释就是,最内层存储图块,再外面一层存储图层,最外层存储分块。这样的话可以一次性将一个分块的所有图层渲染完毕。
|
||||
*
|
||||
* 依次存储 a_tilePos, a_texCoord, a_tileData, a_texData
|
||||
*/
|
||||
readonly tileInstanced: Float32Array;
|
||||
|
||||
/** 动态内容的起始索引,以实例为单位 */
|
||||
readonly dynamicStart: number;
|
||||
/** 动态内容的数量,以实例为单位 */
|
||||
readonly dynamicCount: number;
|
||||
}
|
||||
|
||||
export interface IMapVertexStatus {
|
||||
/**
|
||||
* 设置图块的不透明度
|
||||
@@ -1059,9 +1096,13 @@ export interface IMapVertexStatus {
|
||||
getDynamicFrame(index: number): number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 脏标记表示顶点数组的长度是否发生变化
|
||||
*/
|
||||
export interface IMapVertexConfig {
|
||||
/** 初始状态下的分块宽度 */
|
||||
readonly initBlockWidth: number;
|
||||
/** 初始状态下的分块高度 */
|
||||
readonly initBlockHeight: number;
|
||||
}
|
||||
|
||||
export interface IMapVertexGenerator
|
||||
extends IDirtyTracker<boolean>, IMapVertexStatus {
|
||||
/** 地图渲染器 */
|
||||
@@ -1087,7 +1128,7 @@ export interface IMapVertexGenerator
|
||||
* @param width 分块宽度
|
||||
* @param height 分块高度
|
||||
*/
|
||||
setBlockSize(width: number, height: number): void;
|
||||
setChunkSize(width: number, height: number): void;
|
||||
|
||||
/**
|
||||
* 重设地图尺寸
|
||||
@@ -1210,6 +1251,10 @@ export interface IMapVertexGenerator
|
||||
): void;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region 视角控制
|
||||
|
||||
export interface IMapRenderArea {
|
||||
/** 顶点起始索引,从哪个顶点开始处理 */
|
||||
startIndex: number;
|
||||
@@ -1244,6 +1289,8 @@ export interface IMapViewportController {
|
||||
bindTransform(transform: Transform): void;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region 渲染元素
|
||||
|
||||
export interface IMapRenderItem extends IRenderItem {
|
||||
|
||||
@@ -15,15 +15,15 @@ import {
|
||||
IOverlayBlock,
|
||||
MapTileAlign,
|
||||
MapTileBehavior,
|
||||
MapTileSizeTestMode
|
||||
MapTileSizeTestMode,
|
||||
IMapVertexConfig
|
||||
} from './types';
|
||||
import { logger, PrivateBooleanDirtyTracker } from '@motajs/common';
|
||||
import { DYNAMIC_RESERVE, MAP_BLOCK_HEIGHT, MAP_BLOCK_WIDTH } from '../shared';
|
||||
import { BlockSplitter } from './chunk';
|
||||
import { clamp, isNil } from 'lodash-es';
|
||||
import { IMaterialFramedData } from '@user/client-base';
|
||||
import { IRect } from '@motajs/render';
|
||||
import { INSTANCED_COUNT } from './constant';
|
||||
import { INSTANCED_COUNT, OVERLAY_RESERVE } from './constant';
|
||||
|
||||
export interface IMapDataGetter {
|
||||
/** 图块缩小行为,即图块比格子大时应该如何处理 */
|
||||
@@ -102,7 +102,7 @@ export class MapVertexGenerator
|
||||
dynamicRenderDirty: boolean = true;
|
||||
|
||||
dynamicStart: number = 0;
|
||||
dynamicCount: number = DYNAMIC_RESERVE;
|
||||
dynamicCount: number = OVERLAY_RESERVE;
|
||||
|
||||
/** 空顶点数组,因为空顶点很常用,所以直接定义一个全局常量 */
|
||||
private static readonly EMPTY_VETREX: Float32Array = new Float32Array(
|
||||
@@ -139,9 +139,9 @@ export class MapVertexGenerator
|
||||
private overlayCount: number = 0;
|
||||
|
||||
/** 分块宽度 */
|
||||
private blockWidth: number = MAP_BLOCK_WIDTH;
|
||||
private blockWidth: number = 0;
|
||||
/** 分块高度 */
|
||||
private blockHeight: number = MAP_BLOCK_HEIGHT;
|
||||
private blockHeight: number = 0;
|
||||
|
||||
/** 地图宽度 */
|
||||
private mapWidth: number = 0;
|
||||
@@ -158,11 +158,14 @@ export class MapVertexGenerator
|
||||
|
||||
constructor(
|
||||
readonly renderer: IMapRenderer & IMapDataGetter,
|
||||
readonly data: IContextData
|
||||
readonly data: IContextData,
|
||||
config: IMapVertexConfig
|
||||
) {
|
||||
super();
|
||||
this.resizeMap();
|
||||
this.block = new BlockSplitter();
|
||||
this.blockWidth = config.initBlockWidth;
|
||||
this.blockHeight = config.initBlockHeight;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
@@ -224,7 +227,11 @@ export class MapVertexGenerator
|
||||
});
|
||||
}
|
||||
|
||||
setBlockSize(width: number, height: number): void {
|
||||
setChunkSize(width: number, height: number): void {
|
||||
if (this.renderer.canvasSizeFreezed) {
|
||||
logger.warn(215);
|
||||
return;
|
||||
}
|
||||
this.blockWidth = width;
|
||||
this.blockHeight = height;
|
||||
this.mallocVertexArray();
|
||||
|
||||
@@ -1,29 +1,5 @@
|
||||
//#region 地图
|
||||
|
||||
/** 每个格子的默认宽度,现阶段用处不大 */
|
||||
export const CELL_WIDTH = 32;
|
||||
/** 每个格子的默认高度,现阶段用处不大 */
|
||||
export const CELL_HEIGHT = 32;
|
||||
/** 每个格子的宽高 */
|
||||
export const CELL_SIZE = 32;
|
||||
/** 地图格子宽度,此处仅影响画面,不影响游戏内逻辑,游戏内逻辑地图大小请在 core.js 中修改 */
|
||||
export const MAP_BLOCK_WIDTH = 13;
|
||||
/** 地图格子高度,此处仅影响画面,不影响游戏内逻辑,游戏内逻辑地图大小请在 core.js 中修改 */
|
||||
export const MAP_BLOCK_HEIGHT = 13;
|
||||
/** 地图像素宽度 */
|
||||
export const MAP_WIDTH = CELL_SIZE * MAP_BLOCK_WIDTH;
|
||||
/** 地图像素高度 */
|
||||
export const MAP_HEIGHT = CELL_SIZE * MAP_BLOCK_HEIGHT;
|
||||
/**
|
||||
* 动态内容预留,不明白含义的话不要动。地图上所有正在移动的图块称为动态内容,这些内容的数量无法预测,因此需要预留数组大小,
|
||||
* 如果不够再临时扩充。如果你的塔中有大量的移动操作,可以适当提高此值,避免频繁的内存扩充行为,可以一定程度上提高性能表现。
|
||||
*/
|
||||
export const DYNAMIC_RESERVE = 64;
|
||||
/**
|
||||
* 移动图块容忍度,不明白含义的话不要动。如果移动图块的数量长期小于当前预留数量,那么将会降低预留数量,提升性能表现。
|
||||
* 调整此值可以调整频率,值越大,越不容易因为数量小于预留数量而减小预留。
|
||||
*/
|
||||
export const MOVING_TOLERANCE = 60;
|
||||
/** 开关门动画的动画时长 */
|
||||
export const DOOR_ANIMATE_INTERVAL = 50;
|
||||
|
||||
|
||||
@@ -28,9 +28,8 @@ import {
|
||||
IGameUIPropsBase,
|
||||
ClientHotkey,
|
||||
IClientHotkey,
|
||||
Icon,
|
||||
Winskin,
|
||||
MapRenderItem
|
||||
MapRenderItem,
|
||||
IMapRendererInitConfig
|
||||
} from '@user/client-base';
|
||||
import { IMapRenderer, MapRenderer } from '@user/client-base';
|
||||
import {
|
||||
@@ -90,16 +89,27 @@ export class ClientCore extends CoreState implements IClientCore {
|
||||
excitaion: this.excitationDivider
|
||||
})
|
||||
);
|
||||
this.mainMapRenderer = markRaw(new MapRenderer(this.materials));
|
||||
this.expandMapRenderer = markRaw(new MapRenderer(this.materials));
|
||||
const mapRendererConfig: IMapRendererInitConfig = {
|
||||
manager: this.materials,
|
||||
initBlockWidth: config.mapBlockWidth,
|
||||
initBlockHeight: config.mapBlockHeight,
|
||||
initCellWidth: config.mapCellWidth,
|
||||
initCellHeight: config.mapCellHeight
|
||||
};
|
||||
this.mainMapRenderer = markRaw(new MapRenderer(mapRendererConfig));
|
||||
this.expandMapRenderer = markRaw(new MapRenderer(mapRendererConfig));
|
||||
this.sceneController = new UIController<IGameUIPropsBase>();
|
||||
this.mainUIController = new UIController<IGameUIPropsBase>();
|
||||
const pbCreator = createUIPropsBase(this);
|
||||
this.sceneController.setPropsBaseCreator(pbCreator);
|
||||
this.mainUIController.setPropsBaseCreator(pbCreator);
|
||||
this.expandMapRenderer.setCanvasSize(
|
||||
config.expandMapRendererWidth,
|
||||
config.expandMapRendererHeight
|
||||
);
|
||||
// 辅助渲染器为保证跨组件引用的一致性,不允许修改画布尺寸
|
||||
this.expandMapRenderer.freezeCanvasSize();
|
||||
|
||||
this.renderer.registerElement('icon', () => new Icon());
|
||||
this.renderer.registerElement('winskin', () => new Winskin());
|
||||
this.renderer.registerElement('map-render', () => new MapRenderItem());
|
||||
|
||||
this.loader.addCoreConfig('client', config.clientURL);
|
||||
|
||||
@@ -75,6 +75,18 @@ export interface IClientCoreConfig extends ICoreStateConfig {
|
||||
readonly renderHeight: number;
|
||||
/** 渲染端插件列表 */
|
||||
readonly clientPlugins: IClientPluginDefine[];
|
||||
/** 辅助地图渲染器的固定画布宽度 */
|
||||
readonly expandMapRendererWidth: number;
|
||||
/** 辅助地图渲染器的固定画布高度 */
|
||||
readonly expandMapRendererHeight: number;
|
||||
/** 地图的初始分块宽度,后续还可以通过接口调整 */
|
||||
readonly mapBlockWidth: number;
|
||||
/** 地图的初始分块高度,后续还可以通过接口调整 */
|
||||
readonly mapBlockHeight: number;
|
||||
/** 地图的初始图块像素宽度,后续还可以通过接口调整 */
|
||||
readonly mapCellWidth: number;
|
||||
/** 地图的初始图块像素高度,后续还可以通过接口调整 */
|
||||
readonly mapCellHeight: number;
|
||||
}
|
||||
|
||||
export interface IClientCore extends IClientBase {
|
||||
|
||||
@@ -15,6 +15,14 @@ import {
|
||||
import { createCoreStateConfig } from '../data/entry';
|
||||
import { MainClientPlugin } from './initialize';
|
||||
import { clientPlugins } from './plugin';
|
||||
import {
|
||||
CELL_HEIGHT,
|
||||
CELL_WIDTH,
|
||||
MAP_BLOCK_HEIGHT,
|
||||
MAP_BLOCK_WIDTH,
|
||||
MAP_HEIGHT,
|
||||
MAP_WIDTH
|
||||
} from './uiConstant';
|
||||
|
||||
/**
|
||||
* 创建渲染端配置对象
|
||||
@@ -30,6 +38,12 @@ export function createClientCoreConfig(
|
||||
rendererCanvas: RENDER_CANVAS,
|
||||
renderWidth: RENDER_WIDTH,
|
||||
renderHeight: RENDER_HEIGHT,
|
||||
mapCellWidth: CELL_WIDTH,
|
||||
mapCellHeight: CELL_HEIGHT,
|
||||
mapBlockWidth: MAP_BLOCK_WIDTH,
|
||||
mapBlockHeight: MAP_BLOCK_HEIGHT,
|
||||
expandMapRendererWidth: MAP_WIDTH,
|
||||
expandMapRendererHeight: MAP_HEIGHT,
|
||||
clientPlugins: [new MainClientPlugin(), ...clientPlugins],
|
||||
|
||||
...createCoreStateConfig(starter)
|
||||
|
||||
@@ -8,9 +8,9 @@ import { ElementLocator, Font } from '@motajs/render';
|
||||
export const CELL_WIDTH = 32;
|
||||
/** 每个格子的高度 */
|
||||
export const CELL_HEIGHT = 32;
|
||||
/** 地图格子宽度,此处仅影响画面,不影响游戏内逻辑,游戏内逻辑地图大小请在 core.js 中修改 */
|
||||
/** 地图画面的格子宽度,即在正常情况下,游戏画面横向会显示多少格子,同时作为分块宽度使用 */
|
||||
export const MAP_BLOCK_WIDTH = 13;
|
||||
/** 地图格子高度,此处仅影响画面,不影响游戏内逻辑,游戏内逻辑地图大小请在 core.js 中修改 */
|
||||
/** 地图画面的格子高度,即在正常情况下,游戏画面纵向会显示多少格子,同时作为分块宽度使用 */
|
||||
export const MAP_BLOCK_HEIGHT = 13;
|
||||
/** 地图像素宽度 */
|
||||
export const MAP_WIDTH = CELL_WIDTH * MAP_BLOCK_WIDTH;
|
||||
@@ -20,18 +20,6 @@ export const MAP_HEIGHT = CELL_HEIGHT * MAP_BLOCK_HEIGHT;
|
||||
export const HALF_MAP_WIDTH = MAP_WIDTH / 2;
|
||||
/** 地图高度的一半 */
|
||||
export const HALF_MAP_HEIGHT = MAP_HEIGHT / 2;
|
||||
/**
|
||||
* 动态内容预留,不明白含义的话不要动。地图上所有正在移动的图块称为动态内容,这些内容的数量无法预测,因此需要预留数组大小,
|
||||
* 如果不够再临时扩充。如果你的塔中有大量的移动操作,可以适当提高此值,避免频繁的内存扩充行为,可以一定程度上提高性能表现。
|
||||
*/
|
||||
export const DYNAMIC_RESERVE = 16;
|
||||
/**
|
||||
* 移动图块容忍度,不明白含义的话不要动。如果移动图块的数量长期小于当前预留数量,那么将会降低预留数量,提升性能表现。
|
||||
* 调整此值可以调整频率,值越大,越不容易因为数量小于预留数量而减小预留。
|
||||
*/
|
||||
export const MOVING_TOLERANCE = 60;
|
||||
/** 开关门动画的动画时长 */
|
||||
export const DOOR_ANIMATE_INTERVAL = 50;
|
||||
|
||||
//#endregion
|
||||
|
||||
@@ -65,14 +53,7 @@ export const HALF_HEIGHT = MAIN_HEIGHT / 2;
|
||||
/** 全屏显示的 loc */
|
||||
export const FULL_LOC: ElementLocator = [0, 0, MAIN_WIDTH, MAIN_HEIGHT];
|
||||
/** 居中显示的 loc */
|
||||
export const CENTER_LOC: ElementLocator = [
|
||||
HALF_WIDTH,
|
||||
HALF_HEIGHT,
|
||||
void 0,
|
||||
void 0,
|
||||
0.5,
|
||||
0.5
|
||||
];
|
||||
export const CENTER_LOC: ElementLocator = [HALF_WIDTH, HALF_HEIGHT];
|
||||
|
||||
//#endregion
|
||||
|
||||
|
||||
Reference in new issue
Block a user