Compare commits

..

No commits in common. "7fcefd62c49eba7f6e5d33f181e7b59e05b1ef03" and "4f3154d497b3d358c5e80535e51b98221451f6ec" have entirely different histories.

11 changed files with 64 additions and 148 deletions

View File

@ -33,8 +33,6 @@ import {
import { SetupComponentOptions } from '@motajs/system-ui'; import { SetupComponentOptions } from '@motajs/system-ui';
import { texture } from '../elements'; import { texture } from '../elements';
// todo: TextContent 应该改成渲染元素?
//#region TextContent //#region TextContent
export interface TextContentProps export interface TextContentProps

View File

@ -283,6 +283,7 @@ export class MapHeroRenderer implements IMapHeroRenderer {
this.heroEntity.moving = true; this.heroEntity.moving = true;
this.heroEntity.animating = true; this.heroEntity.animating = true;
this.heroEntity.lastAnimateTime = this.ticker.timestamp; this.heroEntity.lastAnimateTime = this.ticker.timestamp;
this.heroEntity.block.useSpecifiedFrame(1);
} }
private endEntityMoving(entity: HeroRenderEntity) { private endEntityMoving(entity: HeroRenderEntity) {
@ -292,8 +293,12 @@ export class MapHeroRenderer implements IMapHeroRenderer {
entity.block.useSpecifiedFrame(0); entity.block.useSpecifiedFrame(0);
} }
async waitMoveEnd(): Promise<void> { async waitMoveEnd(waitFollower: boolean): Promise<void> {
await Promise.all(this.entities.map(v => v.promise)); if (waitFollower) {
await Promise.all(this.entities.map(v => v.promise));
return;
}
await this.heroEntity.promise;
this.entities.forEach(v => this.endEntityMoving(v)); this.entities.forEach(v => this.endEntityMoving(v));
} }
@ -376,7 +381,6 @@ export class MapHeroRenderer implements IMapHeroRenderer {
promise: Promise.resolve(), promise: Promise.resolve(),
animateDirection: HeroAnimateDirection.Forward animateDirection: HeroAnimateDirection.Forward
}; };
moving.useSpecifiedFrame(0);
this.entities.push(entity); this.entities.push(entity);
} }
@ -481,8 +485,8 @@ class MapHeroHook implements Partial<IHeroStateHooks> {
return this.hero.move(direction, time); return this.hero.move(direction, time);
} }
onEndMove(): Promise<void> { onEndMove(waitFollower: boolean): Promise<void> {
return this.hero.waitMoveEnd(); return this.hero.waitMoveEnd(waitFollower);
} }
onJumpHero( onJumpHero(

View File

@ -201,7 +201,7 @@ export class MovingBlock extends DynamicBlockStatus implements IMovingBlock {
this.y = this.targetY; this.y = this.targetY;
this.end = true; this.end = true;
this.promiseFunc(); this.promiseFunc();
return true; return false;
} else { } else {
const timeProgress = dt / this.time; const timeProgress = dt / this.time;
const progress = this.timing(timeProgress); const progress = this.timing(timeProgress);
@ -220,7 +220,7 @@ export class MovingBlock extends DynamicBlockStatus implements IMovingBlock {
} }
this.end = true; this.end = true;
this.promiseFunc(); this.promiseFunc();
return true; return false;
} else { } else {
const timeProgress = dt / this.time; const timeProgress = dt / this.time;
const progress = this.timing(timeProgress); const progress = this.timing(timeProgress);

View File

@ -18,7 +18,6 @@ import {
IMapBackgroundConfig, IMapBackgroundConfig,
IMapRenderConfig, IMapRenderConfig,
IMapRenderer, IMapRenderer,
IMapRendererPostEffect,
IMapRendererTicker, IMapRendererTicker,
IMapVertexGenerator, IMapVertexGenerator,
IMapViewportController, IMapViewportController,
@ -173,11 +172,6 @@ export class MapRenderer
/** 画布上下文数据 */ /** 画布上下文数据 */
private contextData: IContextData; private contextData: IContextData;
/** 效果对象优先级映射 */
private effectPriority: Map<IMapRendererPostEffect, number> = new Map();
/** 渲染器效果对象列表,使用数组是因为要有顺序 */
private postEffects: IMapRendererPostEffect[] = [];
/** 地图变换矩阵 */ /** 地图变换矩阵 */
transform: Transform; transform: Transform;
/** 是否需要更新变换矩阵 */ /** 是否需要更新变换矩阵 */
@ -299,40 +293,6 @@ export class MapRenderer
gl.bindVertexArray(null); 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 //#endregion
//#region 状态控制 //#region 状态控制
@ -686,7 +646,7 @@ export class MapRenderer
gl.disable(gl.CULL_FACE); gl.disable(gl.CULL_FACE);
gl.enable(gl.DEPTH_TEST); gl.enable(gl.DEPTH_TEST);
gl.enable(gl.BLEND); gl.enable(gl.BLEND);
gl.depthFunc(gl.LESS); gl.depthFunc(gl.LEQUAL);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
const data: IContextData = { const data: IContextData = {
@ -1249,7 +1209,6 @@ export class MapRenderer
} }
render(): HTMLCanvasElement { render(): HTMLCanvasElement {
// todo: 改为 FBO最后把 FBO 画到画布上
const gl = this.gl; const gl = this.gl;
const data = this.contextData; const data = this.contextData;
if (!this.assetData) { if (!this.assetData) {

View File

@ -10,9 +10,6 @@ uniform sampler2DArray u_sampler;
void main() { void main() {
vec4 texColor = texture(u_sampler, v_texCoord.xyz); vec4 texColor = texture(u_sampler, v_texCoord.xyz);
float alpha = texColor.a * v_texCoord.a; outColor = vec4(texColor.rgb, texColor.a * v_texCoord.a);
// todo: 透明像素应该如何解决??
if (alpha < 0.1) discard;
outColor = vec4(texColor.rgb, alpha);
// outColor = vec4(texColor.a * 0.001, v_texCoord.x * 6.0, v_texCoord.y * 0.0, v_texCoord.a); // outColor = vec4(texColor.a * 0.001, v_texCoord.x * 6.0, v_texCoord.y * 0.0, v_texCoord.a);
} }

View File

@ -266,29 +266,6 @@ export interface IMapRendererTicker {
remove(): void; 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 { export interface IMapRenderer {
/** 地图渲染器使用的资源管理器 */ /** 地图渲染器使用的资源管理器 */
readonly manager: IMaterialManager; readonly manager: IMaterialManager;
@ -336,29 +313,6 @@ export interface IMapRenderer {
*/ */
destroy(): void; 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;
/** /**
* *
*/ */

View File

@ -365,8 +365,7 @@ export class MapVertexGenerator
assetIndex: number, assetIndex: number,
offsetIndex: number, offsetIndex: number,
frames: number, frames: number,
update: VertexUpdate, update: VertexUpdate
dynamic: boolean
) { ) {
const { instancedArray } = vertex; const { instancedArray } = vertex;
// 顶点数组 // 顶点数组
@ -378,9 +377,8 @@ export class MapVertexGenerator
const layerIndex = this.renderer.getLayerIndex(index.layer); const layerIndex = this.renderer.getLayerIndex(index.layer);
// 避免 z 坐标是 1 的时候被裁剪,因此范围选择 [-0.9, 0.9] // 避免 z 坐标是 1 的时候被裁剪,因此范围选择 [-0.9, 0.9]
const layerStart = (layerIndex / layerCount) * 1.8 - 0.9; const layerStart = (layerIndex / layerCount) * 1.8 - 0.9;
const perBlockZ = 1 / this.mapHeight / layerCount; const zIndex =
const blockZ = index.mapY * perBlockZ; -layerStart - index.mapY / this.mapHeight / layerCount;
const zIndex = -layerStart - blockZ - (dynamic ? perBlockZ : 0);
const { x, y, w, h } = this.getTilePosition(index, width, height); const { x, y, w, h } = this.getTilePosition(index, width, height);
// 图块位置 // 图块位置
instancedArray[startIndex] = x; instancedArray[startIndex] = x;
@ -420,8 +418,7 @@ export class MapVertexGenerator
vertex: IMapVertexData, vertex: IMapVertexData,
index: BlockIndex, index: BlockIndex,
tile: IMaterialFramedData, tile: IMaterialFramedData,
update: VertexUpdate, update: VertexUpdate
dynamic: boolean
) { ) {
const autotile = this.renderer.autotile; const autotile = this.renderer.autotile;
const { connection, center } = autotile.connect( const { connection, center } = autotile.connect(
@ -445,8 +442,7 @@ export class MapVertexGenerator
assetIndex, assetIndex,
offsetIndex, offsetIndex,
tile.frames, tile.frames,
update, update
dynamic
); );
} }
@ -489,8 +485,7 @@ export class MapVertexGenerator
vertex, vertex,
newIndex, newIndex,
tile, tile,
VertexUpdate.Texture, VertexUpdate.Texture
false
); );
block.data.markRenderDirty(); block.data.markRenderDirty();
} }
@ -506,8 +501,7 @@ export class MapVertexGenerator
mapArray: Uint32Array, mapArray: Uint32Array,
vertex: IMapVertexData, vertex: IMapVertexData,
index: BlockIndex, index: BlockIndex,
num: number, num: number
dynamic: boolean
) { ) {
// 此处仅更新当前图块,不更新周围一圈的自动元件 // 此处仅更新当前图块,不更新周围一圈的自动元件
// 周围一圈的自动元件需要在更新某个图块或者某个区域时处理,不在这里处理 // 周围一圈的自动元件需要在更新某个图块或者某个区域时处理,不在这里处理
@ -532,8 +526,7 @@ export class MapVertexGenerator
vertex, vertex,
index, index,
tile, tile,
VertexUpdate.All, VertexUpdate.All
dynamic
); );
} else { } else {
// 正常图块 // 正常图块
@ -560,8 +553,7 @@ export class MapVertexGenerator
assetIndex, assetIndex,
offsetIndex, offsetIndex,
tile.frames, tile.frames,
VertexUpdate.All, VertexUpdate.All
dynamic
); );
} }
} }
@ -608,7 +600,7 @@ export class MapVertexGenerator
this.checkAutotileConnectionAround(layer, array, index, -1, 1); this.checkAutotileConnectionAround(layer, array, index, -1, 1);
this.checkAutotileConnectionAround(layer, array, index, -1, 0); this.checkAutotileConnectionAround(layer, array, index, -1, 0);
// 再更新当前图块 // 再更新当前图块
this.updateVertexArray(array, vertex, index, num, false); this.updateVertexArray(array, vertex, index, num);
block.data.markRenderDirty(); block.data.markRenderDirty();
} }
@ -803,8 +795,7 @@ export class MapVertexGenerator
array, array,
vertex, vertex,
index, index,
array[mapIndex], array[mapIndex]
false
); );
} }
} }
@ -849,8 +840,7 @@ export class MapVertexGenerator
assetIndex, assetIndex,
offset, offset,
frames, frames,
update, update
true
); );
} else { } else {
// 正常图块 // 正常图块
@ -869,8 +859,7 @@ export class MapVertexGenerator
assetIndex, assetIndex,
offset, offset,
frames, frames,
update, update
true
); );
} }

View File

@ -58,11 +58,11 @@ export class HeroState extends Hookable<IHeroStateHooks> implements IHeroState {
this.y += y; this.y += y;
} }
async endMove(): Promise<void> { async endMove(waitFollower: boolean = false): Promise<void> {
if (!this.moving) return; if (!this.moving) return;
await Promise.all( await Promise.all(
this.forEachHook(hook => { this.forEachHook(hook => {
return hook.onEndMove?.(); return hook.onEndMove?.(waitFollower);
}) })
); );
this.moving = false; this.moving = false;

View File

@ -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` * @returns `Promise`
*/ */
endMove(): Promise<void>; endMove(waitFollower?: boolean): Promise<void>;
/** /**
* *

View File

@ -171,11 +171,7 @@ export function initFallback() {
patch.add( patch.add(
'setHeroLoc', 'setHeroLoc',
function ( function (name: 'x' | 'y' | 'direction', value: number | Dir) {
name: 'x' | 'y' | 'direction',
value: number | Dir,
noGather?: boolean
) {
if (!core.status.hero) return; if (!core.status.hero) return;
// @ts-ignore // @ts-ignore
core.status.hero.loc[name] = value; core.status.hero.loc[name] = value;
@ -186,21 +182,17 @@ export function initFallback() {
} else if (name === 'x') { } else if (name === 'x') {
// 为了防止逆天样板出问题 // 为了防止逆天样板出问题
core.bigmap.posX = value as number; core.bigmap.posX = value as number;
if (!noGather) { state.hero.setPosition(
state.hero.setPosition( value as number,
value as number, core.status.hero.loc.y
core.status.hero.loc.y );
);
}
} else { } else {
// 为了防止逆天样板出问题 // 为了防止逆天样板出问题
core.bigmap.posY = value as number; core.bigmap.posY = value as number;
if (!noGather) { state.hero.setPosition(
state.hero.setPosition( core.status.hero.loc.x,
core.status.hero.loc.x, value as number
value as number );
);
}
} }
} }
); );

View File

@ -3489,12 +3489,33 @@ events.prototype.hasAsyncAnimate = function () {
////// 跟随 ////// ////// 跟随 //////
events.prototype.follow = function (name) { 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) { 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 ( events.prototype._updateValueByOperator = function (