mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-11-28 22:42:59 +08:00
Compare commits
No commits in common. "7fcefd62c49eba7f6e5d33f181e7b59e05b1ef03" and "4f3154d497b3d358c5e80535e51b98221451f6ec" have entirely different histories.
7fcefd62c4
...
4f3154d497
@ -33,8 +33,6 @@ import {
|
||||
import { SetupComponentOptions } from '@motajs/system-ui';
|
||||
import { texture } from '../elements';
|
||||
|
||||
// todo: TextContent 应该改成渲染元素?
|
||||
|
||||
//#region TextContent
|
||||
|
||||
export interface TextContentProps
|
||||
|
||||
@ -283,6 +283,7 @@ export class MapHeroRenderer implements IMapHeroRenderer {
|
||||
this.heroEntity.moving = true;
|
||||
this.heroEntity.animating = true;
|
||||
this.heroEntity.lastAnimateTime = this.ticker.timestamp;
|
||||
this.heroEntity.block.useSpecifiedFrame(1);
|
||||
}
|
||||
|
||||
private endEntityMoving(entity: HeroRenderEntity) {
|
||||
@ -292,8 +293,12 @@ export class MapHeroRenderer implements IMapHeroRenderer {
|
||||
entity.block.useSpecifiedFrame(0);
|
||||
}
|
||||
|
||||
async waitMoveEnd(): Promise<void> {
|
||||
await Promise.all(this.entities.map(v => v.promise));
|
||||
async waitMoveEnd(waitFollower: boolean): Promise<void> {
|
||||
if (waitFollower) {
|
||||
await Promise.all(this.entities.map(v => v.promise));
|
||||
return;
|
||||
}
|
||||
await this.heroEntity.promise;
|
||||
this.entities.forEach(v => this.endEntityMoving(v));
|
||||
}
|
||||
|
||||
@ -376,7 +381,6 @@ export class MapHeroRenderer implements IMapHeroRenderer {
|
||||
promise: Promise.resolve(),
|
||||
animateDirection: HeroAnimateDirection.Forward
|
||||
};
|
||||
moving.useSpecifiedFrame(0);
|
||||
this.entities.push(entity);
|
||||
}
|
||||
|
||||
@ -481,8 +485,8 @@ class MapHeroHook implements Partial<IHeroStateHooks> {
|
||||
return this.hero.move(direction, time);
|
||||
}
|
||||
|
||||
onEndMove(): Promise<void> {
|
||||
return this.hero.waitMoveEnd();
|
||||
onEndMove(waitFollower: boolean): Promise<void> {
|
||||
return this.hero.waitMoveEnd(waitFollower);
|
||||
}
|
||||
|
||||
onJumpHero(
|
||||
|
||||
@ -201,7 +201,7 @@ export class MovingBlock extends DynamicBlockStatus implements IMovingBlock {
|
||||
this.y = this.targetY;
|
||||
this.end = true;
|
||||
this.promiseFunc();
|
||||
return true;
|
||||
return false;
|
||||
} else {
|
||||
const timeProgress = dt / this.time;
|
||||
const progress = this.timing(timeProgress);
|
||||
@ -220,7 +220,7 @@ export class MovingBlock extends DynamicBlockStatus implements IMovingBlock {
|
||||
}
|
||||
this.end = true;
|
||||
this.promiseFunc();
|
||||
return true;
|
||||
return false;
|
||||
} else {
|
||||
const timeProgress = dt / this.time;
|
||||
const progress = this.timing(timeProgress);
|
||||
|
||||
@ -18,7 +18,6 @@ import {
|
||||
IMapBackgroundConfig,
|
||||
IMapRenderConfig,
|
||||
IMapRenderer,
|
||||
IMapRendererPostEffect,
|
||||
IMapRendererTicker,
|
||||
IMapVertexGenerator,
|
||||
IMapViewportController,
|
||||
@ -173,11 +172,6 @@ export class MapRenderer
|
||||
/** 画布上下文数据 */
|
||||
private contextData: IContextData;
|
||||
|
||||
/** 效果对象优先级映射 */
|
||||
private effectPriority: Map<IMapRendererPostEffect, number> = new Map();
|
||||
/** 渲染器效果对象列表,使用数组是因为要有顺序 */
|
||||
private postEffects: IMapRendererPostEffect[] = [];
|
||||
|
||||
/** 地图变换矩阵 */
|
||||
transform: Transform;
|
||||
/** 是否需要更新变换矩阵 */
|
||||
@ -299,40 +293,6 @@ export class MapRenderer
|
||||
gl.bindVertexArray(null);
|
||||
}
|
||||
|
||||
private sortPostEffect() {
|
||||
this.postEffects.sort((a, b) => {
|
||||
const pa = this.effectPriority.get(a) ?? 0;
|
||||
const pb = this.effectPriority.get(b) ?? 0;
|
||||
return pb - pa;
|
||||
});
|
||||
}
|
||||
|
||||
addPostEffect(effect: IMapRendererPostEffect, priority: number): void {
|
||||
this.postEffects.push(effect);
|
||||
this.effectPriority.set(effect, priority);
|
||||
this.sortPostEffect();
|
||||
this.updateRequired = true;
|
||||
}
|
||||
|
||||
removePostEffect(effect: IMapRendererPostEffect): void {
|
||||
const index = this.postEffects.indexOf(effect);
|
||||
if (index === -1) return;
|
||||
this.postEffects.splice(index);
|
||||
this.effectPriority.delete(effect);
|
||||
this.sortPostEffect();
|
||||
this.updateRequired = true;
|
||||
}
|
||||
|
||||
setPostEffectPriority(
|
||||
effect: IMapRendererPostEffect,
|
||||
priority: number
|
||||
): void {
|
||||
if (!this.effectPriority.has(effect)) return;
|
||||
this.effectPriority.set(effect, priority);
|
||||
this.sortPostEffect();
|
||||
this.updateRequired = true;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region 状态控制
|
||||
@ -686,7 +646,7 @@ export class MapRenderer
|
||||
gl.disable(gl.CULL_FACE);
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
gl.enable(gl.BLEND);
|
||||
gl.depthFunc(gl.LESS);
|
||||
gl.depthFunc(gl.LEQUAL);
|
||||
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
const data: IContextData = {
|
||||
@ -1249,7 +1209,6 @@ export class MapRenderer
|
||||
}
|
||||
|
||||
render(): HTMLCanvasElement {
|
||||
// todo: 改为 FBO,最后把 FBO 画到画布上
|
||||
const gl = this.gl;
|
||||
const data = this.contextData;
|
||||
if (!this.assetData) {
|
||||
|
||||
@ -10,9 +10,6 @@ uniform sampler2DArray u_sampler;
|
||||
|
||||
void main() {
|
||||
vec4 texColor = texture(u_sampler, v_texCoord.xyz);
|
||||
float alpha = texColor.a * v_texCoord.a;
|
||||
// todo: 透明像素应该如何解决??
|
||||
if (alpha < 0.1) discard;
|
||||
outColor = vec4(texColor.rgb, alpha);
|
||||
outColor = vec4(texColor.rgb, texColor.a * v_texCoord.a);
|
||||
// outColor = vec4(texColor.a * 0.001, v_texCoord.x * 6.0, v_texCoord.y * 0.0, v_texCoord.a);
|
||||
}
|
||||
|
||||
@ -266,29 +266,6 @@ export interface IMapRendererTicker {
|
||||
remove(): void;
|
||||
}
|
||||
|
||||
export interface IMapRendererPostEffect {
|
||||
/**
|
||||
* 初始化渲染器效果对象,一般是编译着色器、准备数据缓冲区等
|
||||
* @param gl WebGL2 画布上下文
|
||||
* @param data 地图渲染的上下文数据
|
||||
*/
|
||||
init(gl: WebGL2RenderingContext, data: IContextData): void;
|
||||
|
||||
/**
|
||||
* 渲染效果对象,将内容渲染到输出 FBO 上
|
||||
* @param gl WebGL2 画布上下文
|
||||
* @param data 地图渲染的上下文数据
|
||||
* @param input 输入 FBO
|
||||
* @param output 输出 FBO,内容要画到这个 FBO 上
|
||||
*/
|
||||
render(
|
||||
gl: WebGL2RenderingContext,
|
||||
data: IContextData,
|
||||
input: WebGLFramebuffer,
|
||||
output: WebGLFramebuffer
|
||||
): void;
|
||||
}
|
||||
|
||||
export interface IMapRenderer {
|
||||
/** 地图渲染器使用的资源管理器 */
|
||||
readonly manager: IMaterialManager;
|
||||
@ -336,29 +313,6 @@ export interface IMapRenderer {
|
||||
*/
|
||||
destroy(): void;
|
||||
|
||||
/**
|
||||
* 添加一个地图渲染器效果对象,一般是对地图渲染的后处理,可以是一些特效和自定义绘制等
|
||||
* @param effect 地图渲染器效果对象
|
||||
* @param priority 效果对象优先级
|
||||
*/
|
||||
addPostEffect(effect: IMapRendererPostEffect, priority: number): void;
|
||||
|
||||
/**
|
||||
* 移除指定的效果对象
|
||||
* @param effect 地图渲染器效果对象
|
||||
*/
|
||||
removePostEffect(effect: IMapRendererPostEffect): void;
|
||||
|
||||
/**
|
||||
* 设置效果对象的优先级
|
||||
* @param effect 地图渲染器效果对象
|
||||
* @param priority 效果对象优先级
|
||||
*/
|
||||
setPostEffectPriority(
|
||||
effect: IMapRendererPostEffect,
|
||||
priority: number
|
||||
): void;
|
||||
|
||||
/**
|
||||
* 渲染地图
|
||||
*/
|
||||
|
||||
@ -365,8 +365,7 @@ export class MapVertexGenerator
|
||||
assetIndex: number,
|
||||
offsetIndex: number,
|
||||
frames: number,
|
||||
update: VertexUpdate,
|
||||
dynamic: boolean
|
||||
update: VertexUpdate
|
||||
) {
|
||||
const { instancedArray } = vertex;
|
||||
// 顶点数组
|
||||
@ -378,9 +377,8 @@ export class MapVertexGenerator
|
||||
const layerIndex = this.renderer.getLayerIndex(index.layer);
|
||||
// 避免 z 坐标是 1 的时候被裁剪,因此范围选择 [-0.9, 0.9]
|
||||
const layerStart = (layerIndex / layerCount) * 1.8 - 0.9;
|
||||
const perBlockZ = 1 / this.mapHeight / layerCount;
|
||||
const blockZ = index.mapY * perBlockZ;
|
||||
const zIndex = -layerStart - blockZ - (dynamic ? perBlockZ : 0);
|
||||
const zIndex =
|
||||
-layerStart - index.mapY / this.mapHeight / layerCount;
|
||||
const { x, y, w, h } = this.getTilePosition(index, width, height);
|
||||
// 图块位置
|
||||
instancedArray[startIndex] = x;
|
||||
@ -420,8 +418,7 @@ export class MapVertexGenerator
|
||||
vertex: IMapVertexData,
|
||||
index: BlockIndex,
|
||||
tile: IMaterialFramedData,
|
||||
update: VertexUpdate,
|
||||
dynamic: boolean
|
||||
update: VertexUpdate
|
||||
) {
|
||||
const autotile = this.renderer.autotile;
|
||||
const { connection, center } = autotile.connect(
|
||||
@ -445,8 +442,7 @@ export class MapVertexGenerator
|
||||
assetIndex,
|
||||
offsetIndex,
|
||||
tile.frames,
|
||||
update,
|
||||
dynamic
|
||||
update
|
||||
);
|
||||
}
|
||||
|
||||
@ -489,8 +485,7 @@ export class MapVertexGenerator
|
||||
vertex,
|
||||
newIndex,
|
||||
tile,
|
||||
VertexUpdate.Texture,
|
||||
false
|
||||
VertexUpdate.Texture
|
||||
);
|
||||
block.data.markRenderDirty();
|
||||
}
|
||||
@ -506,8 +501,7 @@ export class MapVertexGenerator
|
||||
mapArray: Uint32Array,
|
||||
vertex: IMapVertexData,
|
||||
index: BlockIndex,
|
||||
num: number,
|
||||
dynamic: boolean
|
||||
num: number
|
||||
) {
|
||||
// 此处仅更新当前图块,不更新周围一圈的自动元件
|
||||
// 周围一圈的自动元件需要在更新某个图块或者某个区域时处理,不在这里处理
|
||||
@ -532,8 +526,7 @@ export class MapVertexGenerator
|
||||
vertex,
|
||||
index,
|
||||
tile,
|
||||
VertexUpdate.All,
|
||||
dynamic
|
||||
VertexUpdate.All
|
||||
);
|
||||
} else {
|
||||
// 正常图块
|
||||
@ -560,8 +553,7 @@ export class MapVertexGenerator
|
||||
assetIndex,
|
||||
offsetIndex,
|
||||
tile.frames,
|
||||
VertexUpdate.All,
|
||||
dynamic
|
||||
VertexUpdate.All
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -608,7 +600,7 @@ export class MapVertexGenerator
|
||||
this.checkAutotileConnectionAround(layer, array, index, -1, 1);
|
||||
this.checkAutotileConnectionAround(layer, array, index, -1, 0);
|
||||
// 再更新当前图块
|
||||
this.updateVertexArray(array, vertex, index, num, false);
|
||||
this.updateVertexArray(array, vertex, index, num);
|
||||
block.data.markRenderDirty();
|
||||
}
|
||||
|
||||
@ -803,8 +795,7 @@ export class MapVertexGenerator
|
||||
array,
|
||||
vertex,
|
||||
index,
|
||||
array[mapIndex],
|
||||
false
|
||||
array[mapIndex]
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -849,8 +840,7 @@ export class MapVertexGenerator
|
||||
assetIndex,
|
||||
offset,
|
||||
frames,
|
||||
update,
|
||||
true
|
||||
update
|
||||
);
|
||||
} else {
|
||||
// 正常图块
|
||||
@ -869,8 +859,7 @@ export class MapVertexGenerator
|
||||
assetIndex,
|
||||
offset,
|
||||
frames,
|
||||
update,
|
||||
true
|
||||
update
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -58,11 +58,11 @@ export class HeroState extends Hookable<IHeroStateHooks> implements IHeroState {
|
||||
this.y += y;
|
||||
}
|
||||
|
||||
async endMove(): Promise<void> {
|
||||
async endMove(waitFollower: boolean = false): Promise<void> {
|
||||
if (!this.moving) return;
|
||||
await Promise.all(
|
||||
this.forEachHook(hook => {
|
||||
return hook.onEndMove?.();
|
||||
return hook.onEndMove?.(waitFollower);
|
||||
})
|
||||
);
|
||||
this.moving = false;
|
||||
|
||||
@ -47,8 +47,9 @@ export interface IHeroStateHooks extends IHookBase {
|
||||
|
||||
/**
|
||||
* 当停止移动时触发
|
||||
* @param waitFollower 是否等待跟随者
|
||||
*/
|
||||
onEndMove(): Promise<void>;
|
||||
onEndMove(waitFollower: boolean): Promise<void>;
|
||||
|
||||
/**
|
||||
* 当勇士跳跃时触发
|
||||
@ -145,9 +146,10 @@ export interface IHeroState extends IHookable<IHeroStateHooks> {
|
||||
|
||||
/**
|
||||
* 结束勇士移动
|
||||
* @param waitFollower 是否等待跟随者,默认不等待
|
||||
* @returns 当移动动画结束后兑现的 `Promise`
|
||||
*/
|
||||
endMove(): Promise<void>;
|
||||
endMove(waitFollower?: boolean): Promise<void>;
|
||||
|
||||
/**
|
||||
* 跳跃勇士至目标点
|
||||
|
||||
@ -171,11 +171,7 @@ export function initFallback() {
|
||||
|
||||
patch.add(
|
||||
'setHeroLoc',
|
||||
function (
|
||||
name: 'x' | 'y' | 'direction',
|
||||
value: number | Dir,
|
||||
noGather?: boolean
|
||||
) {
|
||||
function (name: 'x' | 'y' | 'direction', value: number | Dir) {
|
||||
if (!core.status.hero) return;
|
||||
// @ts-ignore
|
||||
core.status.hero.loc[name] = value;
|
||||
@ -186,21 +182,17 @@ export function initFallback() {
|
||||
} else if (name === 'x') {
|
||||
// 为了防止逆天样板出问题
|
||||
core.bigmap.posX = value as number;
|
||||
if (!noGather) {
|
||||
state.hero.setPosition(
|
||||
value as number,
|
||||
core.status.hero.loc.y
|
||||
);
|
||||
}
|
||||
state.hero.setPosition(
|
||||
value as number,
|
||||
core.status.hero.loc.y
|
||||
);
|
||||
} else {
|
||||
// 为了防止逆天样板出问题
|
||||
core.bigmap.posY = value as number;
|
||||
if (!noGather) {
|
||||
state.hero.setPosition(
|
||||
core.status.hero.loc.x,
|
||||
value as number
|
||||
);
|
||||
}
|
||||
state.hero.setPosition(
|
||||
core.status.hero.loc.x,
|
||||
value as number
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@ -3489,12 +3489,33 @@ events.prototype.hasAsyncAnimate = function () {
|
||||
|
||||
////// 跟随 //////
|
||||
events.prototype.follow = function (name) {
|
||||
// Deprecated. Use state.hero.addFollower instead.
|
||||
name = core.getMappedName(name);
|
||||
if (core.material.images.images[name]) {
|
||||
core.status.hero.followers.push({ name: name });
|
||||
core.gatherFollowers();
|
||||
core.clearMap('hero');
|
||||
core.drawHero();
|
||||
}
|
||||
core.clearRouteFolding();
|
||||
};
|
||||
|
||||
////// 取消跟随 //////
|
||||
events.prototype.unfollow = function (name) {
|
||||
// Deprecated. Use state.hero.removeFollower instead.
|
||||
if (!name) {
|
||||
core.status.hero.followers = [];
|
||||
} else {
|
||||
name = core.getMappedName(name);
|
||||
for (var i = 0; i < core.status.hero.followers.length; i++) {
|
||||
if (core.status.hero.followers[i].name == name) {
|
||||
core.status.hero.followers.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
core.gatherFollowers();
|
||||
core.clearMap('hero');
|
||||
core.drawHero();
|
||||
core.clearRouteFolding();
|
||||
};
|
||||
|
||||
events.prototype._updateValueByOperator = function (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user