mirror of
				https://github.com/unanmed/HumanBreak.git
				synced 2025-11-04 07:02:58 +08:00 
			
		
		
		
	fix: 大地图会一次性把所有伤害渲染完
This commit is contained in:
		
							parent
							
								
									5685efd4d5
								
							
						
					
					
						commit
						a05981e675
					
				@ -431,8 +431,7 @@ events.prototype.trigger = function (x, y, callback) {
 | 
			
		||||
        if (
 | 
			
		||||
            trigger == 'changeFloor' &&
 | 
			
		||||
            !noPass &&
 | 
			
		||||
            this._trigger_ignoreChangeFloor(block) &&
 | 
			
		||||
            !loop
 | 
			
		||||
            this._trigger_ignoreChangeFloor(block)
 | 
			
		||||
        )
 | 
			
		||||
            return _executeCallback();
 | 
			
		||||
        // @ts-ignore
 | 
			
		||||
 | 
			
		||||
@ -156,10 +156,8 @@ export class Damage extends Sprite<EDamageEvent> {
 | 
			
		||||
    /** 默认描边宽度 */
 | 
			
		||||
    strokeWidth: number = 2;
 | 
			
		||||
 | 
			
		||||
    /** 单个点的懒更新 */
 | 
			
		||||
    private needUpdateBlock: boolean = false;
 | 
			
		||||
    /** 要懒更新的所有分块 */
 | 
			
		||||
    private needUpdateBlocks: Set<number> = new Set();
 | 
			
		||||
    private dirtyBlocks: Set<number> = new Set();
 | 
			
		||||
 | 
			
		||||
    constructor() {
 | 
			
		||||
        super('absolute', false, true);
 | 
			
		||||
@ -203,6 +201,7 @@ export class Damage extends Sprite<EDamageEvent> {
 | 
			
		||||
        for (let i = 0; i < num; i++) {
 | 
			
		||||
            this.blockData.set(i, new Map());
 | 
			
		||||
            this.renderable.set(i, new Set());
 | 
			
		||||
            this.dirtyBlocks.add(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        this.emit('setMapSize', width, height);
 | 
			
		||||
@ -221,13 +220,19 @@ export class Damage extends Sprite<EDamageEvent> {
 | 
			
		||||
        this.blockData.forEach(v => v.clear());
 | 
			
		||||
        this.renderable.forEach(v => v.clear());
 | 
			
		||||
        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 => {
 | 
			
		||||
            if (isNil(v.x) || isNil(v.y)) return;
 | 
			
		||||
            const index = this.block.getIndexByLoc(v.x, v.y);
 | 
			
		||||
            this.blockData.get(index)?.set(v.y * this.mapWidth + v.x, v);
 | 
			
		||||
        });
 | 
			
		||||
        this.updateBlocks();
 | 
			
		||||
        // this.updateBlocks();
 | 
			
		||||
 | 
			
		||||
        this.update(this);
 | 
			
		||||
    }
 | 
			
		||||
@ -248,13 +253,14 @@ export class Damage extends Sprite<EDamageEvent> {
 | 
			
		||||
     * @param blocks 要更新的分块集合
 | 
			
		||||
     * @param map 是否更新地图伤害
 | 
			
		||||
     */
 | 
			
		||||
    updateBlocks(blocks?: Set<number>, map: boolean = true) {
 | 
			
		||||
    updateBlocks(blocks?: Set<number>) {
 | 
			
		||||
        if (blocks) {
 | 
			
		||||
            blocks.forEach(v => this.updateBlock(v, map));
 | 
			
		||||
            blocks.forEach(v => this.dirtyBlocks.add(v));
 | 
			
		||||
            this.emit('updateBlocks', blocks);
 | 
			
		||||
        } else {
 | 
			
		||||
            this.blockData.forEach((_, k) => this.updateBlock(k, false));
 | 
			
		||||
            if (map) this.extractAllMapDamage();
 | 
			
		||||
            this.blockData.forEach((v, i) => {
 | 
			
		||||
                this.dirtyBlocks.add(i);
 | 
			
		||||
            });
 | 
			
		||||
            this.emit('updateBlocks', new Set(this.blockData.keys()));
 | 
			
		||||
        }
 | 
			
		||||
        this.update(this);
 | 
			
		||||
@ -278,18 +284,7 @@ export class Damage extends Sprite<EDamageEvent> {
 | 
			
		||||
        this.update(this);
 | 
			
		||||
 | 
			
		||||
        // 渲染懒更新,优化性能表现
 | 
			
		||||
        if (!this.needUpdateBlock) {
 | 
			
		||||
            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;
 | 
			
		||||
        }
 | 
			
		||||
        this.dirtyBlocks.add(block);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@ -487,6 +482,7 @@ export class Damage extends Sprite<EDamageEvent> {
 | 
			
		||||
        const size = cell * block.blockSize;
 | 
			
		||||
 | 
			
		||||
        this.emit('beforeDamageRender', render, transform);
 | 
			
		||||
 | 
			
		||||
        render.forEach(v => {
 | 
			
		||||
            const [x, y] = block.getBlockXYByIndex(v);
 | 
			
		||||
            const bx = x * block.blockSize;
 | 
			
		||||
@ -502,7 +498,9 @@ export class Damage extends Sprite<EDamageEvent> {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (this.dirtyBlocks.has(v)) {
 | 
			
		||||
                this.updateBlock(v, true);
 | 
			
		||||
            }
 | 
			
		||||
            this.emit('dirtyUpdate', v);
 | 
			
		||||
 | 
			
		||||
            // 否则依次渲染并写入缓存
 | 
			
		||||
 | 
			
		||||
@ -62,19 +62,19 @@ function getRealStatus(
 | 
			
		||||
): any {
 | 
			
		||||
    const { getSkillLevel } = Mota.Plugin.require('skillTree_g');
 | 
			
		||||
    if (name instanceof Array) {
 | 
			
		||||
        return Object.fromEntries(
 | 
			
		||||
            name.map(v => [v, getRealStatus(status, v, floorId)])
 | 
			
		||||
        );
 | 
			
		||||
        const res: any = {};
 | 
			
		||||
        name.forEach(v => {
 | 
			
		||||
            res[v] = getRealStatus(status, v, floorId);
 | 
			
		||||
        });
 | 
			
		||||
        return res;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (name === 'all') {
 | 
			
		||||
        return Object.fromEntries(
 | 
			
		||||
            Object.keys(core.status.hero).map(v => [
 | 
			
		||||
                v,
 | 
			
		||||
                v !== 'all' &&
 | 
			
		||||
                    getRealStatus(status, v as keyof HeroStatus, floorId)
 | 
			
		||||
            ])
 | 
			
		||||
        );
 | 
			
		||||
        const res: any = {};
 | 
			
		||||
        Object.keys(core.status.hero).forEach(v => {
 | 
			
		||||
            res[v] = getRealStatus(status, v as keyof HeroStatus, floorId);
 | 
			
		||||
        });
 | 
			
		||||
        return res;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let s = (status?.[name] ?? core.status.hero[name]) as number;
 | 
			
		||||
@ -109,7 +109,7 @@ function getRealStatus(
 | 
			
		||||
 | 
			
		||||
    // buff
 | 
			
		||||
    if (typeof s === 'number') {
 | 
			
		||||
        s *= core.getBuff(name as keyof NumbericHeroStatus);
 | 
			
		||||
        s *= flags[`__${name}_buff__`] ?? 1;
 | 
			
		||||
        s = Math.floor(s);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -66,8 +66,8 @@ export class FloorItemDetail implements ILayerGroupRenderExtends {
 | 
			
		||||
        if (!mainSetting.getValue('screen.itemDetail')) return;
 | 
			
		||||
        if (this.dirtyBlock.has(block)) {
 | 
			
		||||
            this.sprite.block.clearCache(block, 1);
 | 
			
		||||
            this.render(block);
 | 
			
		||||
        }
 | 
			
		||||
        this.render(block);
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    private onUpdateMapSize = (width: number, height: number) => {
 | 
			
		||||
@ -216,14 +216,13 @@ export class FloorItemDetail implements ILayerGroupRenderExtends {
 | 
			
		||||
     * @param block 需要渲染的格子
 | 
			
		||||
     */
 | 
			
		||||
    render(block: number) {
 | 
			
		||||
        if (this.dirtyBlock.has(block)) {
 | 
			
		||||
            this.calAllItems(new Set([block]));
 | 
			
		||||
        }
 | 
			
		||||
        const data = this.detailData;
 | 
			
		||||
 | 
			
		||||
        if (!this.dirtyBlock.has(block)) return;
 | 
			
		||||
        this.dirtyBlock.delete(block);
 | 
			
		||||
        const info = data.get(block);
 | 
			
		||||
        if (!info) return;
 | 
			
		||||
 | 
			
		||||
        info.forEach(({ x, y, diff }) => {
 | 
			
		||||
            let n = 0;
 | 
			
		||||
            for (const [key, value] of Object.entries(diff)) {
 | 
			
		||||
 | 
			
		||||
@ -217,10 +217,9 @@ export function getSkillFromIndex(index: number) {
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 获取技能等级
 | 
			
		||||
 * @param {number} skill
 | 
			
		||||
 */
 | 
			
		||||
export function getSkillLevel(skill: number) {
 | 
			
		||||
    return (levels[skill] ??= 0);
 | 
			
		||||
    return levels[skill] ?? 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function getSkillConsume(skill: number) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user