fix: 大地图会一次性把所有伤害渲染完

This commit is contained in:
unanmed 2024-10-19 21:18:54 +08:00
parent 5685efd4d5
commit a05981e675
5 changed files with 36 additions and 41 deletions

View File

@ -431,8 +431,7 @@ events.prototype.trigger = function (x, y, callback) {
if ( if (
trigger == 'changeFloor' && trigger == 'changeFloor' &&
!noPass && !noPass &&
this._trigger_ignoreChangeFloor(block) && this._trigger_ignoreChangeFloor(block)
!loop
) )
return _executeCallback(); return _executeCallback();
// @ts-ignore // @ts-ignore

View File

@ -156,10 +156,8 @@ export class Damage extends Sprite<EDamageEvent> {
/** 默认描边宽度 */ /** 默认描边宽度 */
strokeWidth: number = 2; strokeWidth: number = 2;
/** 单个点的懒更新 */
private needUpdateBlock: boolean = false;
/** 要懒更新的所有分块 */ /** 要懒更新的所有分块 */
private needUpdateBlocks: Set<number> = new Set(); private dirtyBlocks: Set<number> = new Set();
constructor() { constructor() {
super('absolute', false, true); super('absolute', false, true);
@ -203,6 +201,7 @@ export class Damage extends Sprite<EDamageEvent> {
for (let i = 0; i < num; i++) { for (let i = 0; i < num; i++) {
this.blockData.set(i, new Map()); this.blockData.set(i, new Map());
this.renderable.set(i, new Set()); this.renderable.set(i, new Set());
this.dirtyBlocks.add(i);
} }
this.emit('setMapSize', width, height); this.emit('setMapSize', width, height);
@ -221,13 +220,19 @@ export class Damage extends Sprite<EDamageEvent> {
this.blockData.forEach(v => v.clear()); this.blockData.forEach(v => v.clear());
this.renderable.forEach(v => v.clear()); this.renderable.forEach(v => v.clear());
this.block.clearAllCache(); this.block.clearAllCache();
const w = this.block.blockData.width;
const h = this.block.blockData.height;
const num = w * h;
for (let i = 0; i < num; i++) {
this.dirtyBlocks.add(i);
}
enemy.list.forEach(v => { enemy.list.forEach(v => {
if (isNil(v.x) || isNil(v.y)) return; if (isNil(v.x) || isNil(v.y)) return;
const index = this.block.getIndexByLoc(v.x, v.y); const index = this.block.getIndexByLoc(v.x, v.y);
this.blockData.get(index)?.set(v.y * this.mapWidth + v.x, v); this.blockData.get(index)?.set(v.y * this.mapWidth + v.x, v);
}); });
this.updateBlocks(); // this.updateBlocks();
this.update(this); this.update(this);
} }
@ -248,13 +253,14 @@ export class Damage extends Sprite<EDamageEvent> {
* @param blocks * @param blocks
* @param map * @param map
*/ */
updateBlocks(blocks?: Set<number>, map: boolean = true) { updateBlocks(blocks?: Set<number>) {
if (blocks) { if (blocks) {
blocks.forEach(v => this.updateBlock(v, map)); blocks.forEach(v => this.dirtyBlocks.add(v));
this.emit('updateBlocks', blocks); this.emit('updateBlocks', blocks);
} else { } else {
this.blockData.forEach((_, k) => this.updateBlock(k, false)); this.blockData.forEach((v, i) => {
if (map) this.extractAllMapDamage(); this.dirtyBlocks.add(i);
});
this.emit('updateBlocks', new Set(this.blockData.keys())); this.emit('updateBlocks', new Set(this.blockData.keys()));
} }
this.update(this); this.update(this);
@ -278,18 +284,7 @@ export class Damage extends Sprite<EDamageEvent> {
this.update(this); this.update(this);
// 渲染懒更新,优化性能表现 // 渲染懒更新,优化性能表现
if (!this.needUpdateBlock) { this.dirtyBlocks.add(block);
this.needUpdateBlocks.add(block);
this.requestBeforeFrame(() => {
this.needUpdateBlock = false;
this.updateBlocks(this.needUpdateBlocks, false);
this.needUpdateBlocks.clear();
// this.needUpdateBlocks.forEach(v => this.updateBlock(v, false));
// todo: 阻击夹域等地图伤害检测是否必要更新,例如不包含阻击夹域的怪就不必要更新这个怪物信息
// this.extractAllMapDamage();
});
this.needUpdateBlock = true;
}
} }
/** /**
@ -487,6 +482,7 @@ export class Damage extends Sprite<EDamageEvent> {
const size = cell * block.blockSize; const size = cell * block.blockSize;
this.emit('beforeDamageRender', render, transform); this.emit('beforeDamageRender', render, transform);
render.forEach(v => { render.forEach(v => {
const [x, y] = block.getBlockXYByIndex(v); const [x, y] = block.getBlockXYByIndex(v);
const bx = x * block.blockSize; const bx = x * block.blockSize;
@ -502,7 +498,9 @@ export class Damage extends Sprite<EDamageEvent> {
return; return;
} }
if (this.dirtyBlocks.has(v)) {
this.updateBlock(v, true); this.updateBlock(v, true);
}
this.emit('dirtyUpdate', v); this.emit('dirtyUpdate', v);
// 否则依次渲染并写入缓存 // 否则依次渲染并写入缓存

View File

@ -62,19 +62,19 @@ function getRealStatus(
): any { ): any {
const { getSkillLevel } = Mota.Plugin.require('skillTree_g'); const { getSkillLevel } = Mota.Plugin.require('skillTree_g');
if (name instanceof Array) { if (name instanceof Array) {
return Object.fromEntries( const res: any = {};
name.map(v => [v, getRealStatus(status, v, floorId)]) name.forEach(v => {
); res[v] = getRealStatus(status, v, floorId);
});
return res;
} }
if (name === 'all') { if (name === 'all') {
return Object.fromEntries( const res: any = {};
Object.keys(core.status.hero).map(v => [ Object.keys(core.status.hero).forEach(v => {
v, res[v] = getRealStatus(status, v as keyof HeroStatus, floorId);
v !== 'all' && });
getRealStatus(status, v as keyof HeroStatus, floorId) return res;
])
);
} }
let s = (status?.[name] ?? core.status.hero[name]) as number; let s = (status?.[name] ?? core.status.hero[name]) as number;
@ -109,7 +109,7 @@ function getRealStatus(
// buff // buff
if (typeof s === 'number') { if (typeof s === 'number') {
s *= core.getBuff(name as keyof NumbericHeroStatus); s *= flags[`__${name}_buff__`] ?? 1;
s = Math.floor(s); s = Math.floor(s);
} }

View File

@ -66,8 +66,8 @@ export class FloorItemDetail implements ILayerGroupRenderExtends {
if (!mainSetting.getValue('screen.itemDetail')) return; if (!mainSetting.getValue('screen.itemDetail')) return;
if (this.dirtyBlock.has(block)) { if (this.dirtyBlock.has(block)) {
this.sprite.block.clearCache(block, 1); this.sprite.block.clearCache(block, 1);
this.render(block);
} }
this.render(block);
}; };
private onUpdateMapSize = (width: number, height: number) => { private onUpdateMapSize = (width: number, height: number) => {
@ -216,14 +216,13 @@ export class FloorItemDetail implements ILayerGroupRenderExtends {
* @param block * @param block
*/ */
render(block: number) { render(block: number) {
if (this.dirtyBlock.has(block)) {
this.calAllItems(new Set([block])); this.calAllItems(new Set([block]));
}
const data = this.detailData; const data = this.detailData;
if (!this.dirtyBlock.has(block)) return;
this.dirtyBlock.delete(block); this.dirtyBlock.delete(block);
const info = data.get(block); const info = data.get(block);
if (!info) return; if (!info) return;
info.forEach(({ x, y, diff }) => { info.forEach(({ x, y, diff }) => {
let n = 0; let n = 0;
for (const [key, value] of Object.entries(diff)) { for (const [key, value] of Object.entries(diff)) {

View File

@ -217,10 +217,9 @@ export function getSkillFromIndex(index: number) {
/** /**
* *
* @param {number} skill
*/ */
export function getSkillLevel(skill: number) { export function getSkillLevel(skill: number) {
return (levels[skill] ??= 0); return levels[skill] ?? 0;
} }
export function getSkillConsume(skill: number) { export function getSkillConsume(skill: number) {