Compare commits

..

No commits in common. "42a7e15ed86ef9a9a9bbf1310096de9452987180" and "7fcefd62c49eba7f6e5d33f181e7b59e05b1ef03" have entirely different histories.

7 changed files with 36 additions and 104 deletions

View File

@ -1,7 +1,6 @@
import { ITexture } from '@motajs/render-assets'; import { ITexture } from '@motajs/render-assets';
import { materials } from './ins'; import { materials } from './ins';
import { IBlockIdentifier, IIndexedIdentifier } from './types'; import { IBlockIdentifier, IIndexedIdentifier } from './types';
import { isNil } from 'lodash-es';
function extractClsBlocks<C extends Exclude<Cls, 'tileset'>>( function extractClsBlocks<C extends Exclude<Cls, 'tileset'>>(
cls: C, cls: C,
@ -9,10 +8,9 @@ function extractClsBlocks<C extends Exclude<Cls, 'tileset'>>(
icons: Record<string, number> icons: Record<string, number>
): IBlockIdentifier[] { ): IBlockIdentifier[] {
const max = Math.max(...Object.values(icons)); const max = Math.max(...Object.values(icons));
const arr = Array(max).fill(void 0); const arr = Array(max).fill(0);
for (const [key, value] of Object.entries(icons)) { for (const [key, value] of Object.entries(icons)) {
// 样板编辑器 bug 可能会导致多个 id 使用一个偏移,因此要判断下 if (!(key in map)) continue;
if (!(key in map) || !isNil(arr[value])) continue;
const id = key as AllIdsOf<C>; const id = key as AllIdsOf<C>;
const num = map[id] as keyof NumberToId; const num = map[id] as keyof NumberToId;
const identifier: IBlockIdentifier = { const identifier: IBlockIdentifier = {
@ -54,11 +52,7 @@ export function fallbackLoad() {
const idNumMap: Record<string, number> = {}; const idNumMap: Record<string, number> = {};
for (const [key, value] of Object.entries(core.maps.blocksInfo)) { for (const [key, value] of Object.entries(core.maps.blocksInfo)) {
const num = Number(key); idNumMap[value.id] = Number(key);
idNumMap[value.id] = Number(num);
if (!isNil(value.animate)) {
materials.setDefaultFrame(num, value.animate - 1);
}
} }
const terrains = extractClsBlocks('terrains', idNumMap, icons.terrains); const terrains = extractClsBlocks('terrains', idNumMap, icons.terrains);

View File

@ -65,8 +65,6 @@ export class MaterialManager implements IMaterialManager {
readonly numIdMap: Map<number, string> = new Map(); readonly numIdMap: Map<number, string> = new Map();
/** 图块数字到图块类型的映射 */ /** 图块数字到图块类型的映射 */
readonly clsMap: Map<number, BlockCls> = new Map(); readonly clsMap: Map<number, BlockCls> = new Map();
/** 图块的默认帧数 */
readonly defaultFrames: Map<number, number> = new Map();
/** 网格切分器 */ /** 网格切分器 */
readonly gridSplitter: TextureGridSplitter = new TextureGridSplitter(); readonly gridSplitter: TextureGridSplitter = new TextureGridSplitter();
@ -220,19 +218,7 @@ export class MaterialManager implements IMaterialManager {
return data; return data;
} }
setDefaultFrame(identifier: number, defaultFrame: number): void { getTile(identifier: number): IMaterialFramedData | null {
this.defaultFrames.set(identifier, defaultFrame);
const bigImageData = this.bigImageData.get(identifier);
if (bigImageData) {
bigImageData.defaultFrame = defaultFrame;
}
}
getDefaultFrame(identifier: number): number {
return this.defaultFrames.get(identifier) ?? -1;
}
getTile(identifier: number): Readonly<IMaterialFramedData> | null {
if (identifier < 10000) { if (identifier < 10000) {
const cls = this.clsMap.get(identifier) ?? BlockCls.Unknown; const cls = this.clsMap.get(identifier) ?? BlockCls.Unknown;
if ( if (
@ -247,8 +233,7 @@ export class MaterialManager implements IMaterialManager {
texture, texture,
cls, cls,
offset: 32, offset: 32,
frames: getTextureFrame(cls, texture), frames: getTextureFrame(cls, texture)
defaultFrame: this.defaultFrames.get(identifier) ?? -1
}; };
} else { } else {
const texture = this.cacheTileset(identifier); const texture = this.cacheTileset(identifier);
@ -257,8 +242,7 @@ export class MaterialManager implements IMaterialManager {
texture, texture,
cls: BlockCls.Tileset, cls: BlockCls.Tileset,
offset: 32, offset: 32,
frames: 1, frames: 1
defaultFrame: -1
}; };
} }
} }
@ -271,7 +255,7 @@ export class MaterialManager implements IMaterialManager {
return this.imageStore.getTexture(identifier); return this.imageStore.getTexture(identifier);
} }
getTileByAlias(alias: string): Readonly<IMaterialFramedData> | null { getTileByAlias(alias: string): IMaterialFramedData | null {
if (/X\d{5,}/.test(alias)) { if (/X\d{5,}/.test(alias)) {
return this.getTile(parseInt(alias.slice(1))); return this.getTile(parseInt(alias.slice(1)));
} else { } else {
@ -553,8 +537,7 @@ export class MaterialManager implements IMaterialManager {
texture: image, texture: image,
cls, cls,
offset: image.width / 4, offset: image.width / 4,
frames, frames
defaultFrame: this.defaultFrames.get(identifier) ?? -1
}; };
this.bigImageData.set(identifier, store); this.bigImageData.set(identifier, store);
const data: IBigImageReturn = { const data: IBigImageReturn = {
@ -568,17 +551,17 @@ export class MaterialManager implements IMaterialManager {
return this.bigImageData.has(identifier); return this.bigImageData.has(identifier);
} }
getBigImage(identifier: number): Readonly<IMaterialFramedData> | null { getBigImage(identifier: number): IMaterialFramedData | null {
return this.bigImageData.get(identifier) ?? null; return this.bigImageData.get(identifier) ?? null;
} }
getBigImageByAlias(alias: string): Readonly<IMaterialFramedData> | null { getBigImageByAlias(alias: string): IMaterialFramedData | null {
const identifier = this.idNumMap.get(alias); const identifier = this.idNumMap.get(alias);
if (isNil(identifier)) return null; if (isNil(identifier)) return null;
return this.bigImageData.get(identifier) ?? null; return this.bigImageData.get(identifier) ?? null;
} }
getIfBigImage(identifier: number): Readonly<IMaterialFramedData> | null { getIfBigImage(identifier: number): IMaterialFramedData | null {
const bigImage = this.bigImageData.get(identifier); const bigImage = this.bigImageData.get(identifier);
if (bigImage) return bigImage; if (bigImage) return bigImage;
else return this.getTile(identifier); else return this.getTile(identifier);

View File

@ -90,15 +90,13 @@ export interface IBigImageReturn {
export interface IMaterialFramedData { export interface IMaterialFramedData {
/** 贴图对象 */ /** 贴图对象 */
texture: ITexture; readonly texture: ITexture;
/** 图块类型 */ /** 图块类型 */
cls: BlockCls; readonly cls: BlockCls;
/** 贴图总帧数 */ /** 贴图总帧数 */
frames: number; readonly frames: number;
/** 每帧的横向偏移量 */ /** 每帧的横向偏移量 */
offset: number; readonly offset: number;
/** 默认帧数 */
defaultFrame: number;
} }
export interface IMaterialAsset export interface IMaterialAsset
@ -162,7 +160,7 @@ export interface IAutotileProcessor {
* @returns * @returns
*/ */
renderWith( renderWith(
tile: Readonly<IMaterialFramedData>, tile: IMaterialFramedData,
connection: number connection: number
): ITextureRenderable | null; ): ITextureRenderable | null;
@ -173,7 +171,7 @@ export interface IAutotileProcessor {
* @returns * @returns
*/ */
renderWithoutCheck( renderWithoutCheck(
tile: Readonly<IMaterialFramedData>, tile: IMaterialFramedData,
connection: number connection: number
): ITextureRenderable | null; ): ITextureRenderable | null;
@ -195,7 +193,7 @@ export interface IAutotileProcessor {
* @returns * @returns
*/ */
renderAnimatedWith( renderAnimatedWith(
tile: Readonly<IMaterialFramedData>, tile: IMaterialFramedData,
connection: number connection: number
): Generator<ITextureRenderable, void>; ): Generator<ITextureRenderable, void>;
} }
@ -205,7 +203,7 @@ export interface IMaterialGetter {
* *
* @param identifier * @param identifier
*/ */
getTile(identifier: number): Readonly<IMaterialFramedData> | null; getTile(identifier: number): IMaterialFramedData | null;
/** /**
* *
@ -223,14 +221,14 @@ export interface IMaterialGetter {
* `bigImage` * `bigImage`
* @param identifier * @param identifier
*/ */
getBigImage(identifier: number): Readonly<IMaterialFramedData> | null; getBigImage(identifier: number): IMaterialFramedData | null;
/** /**
* `bigImage` `bigImage` * `bigImage` `bigImage`
* `null` * `null`
* @param identifier * @param identifier
*/ */
getIfBigImage(identifier: number): Readonly<IMaterialFramedData> | null; getIfBigImage(identifier: number): IMaterialFramedData | null;
/** /**
* *
@ -256,7 +254,7 @@ export interface IMaterialAliasGetter {
* id * id
* @param alias id * @param alias id
*/ */
getTileByAlias(alias: string): Readonly<IMaterialFramedData> | null; getTileByAlias(alias: string): IMaterialFramedData | null;
/** /**
* *
@ -286,7 +284,7 @@ export interface IMaterialAliasGetter {
* `bigImage` * `bigImage`
* @param alias id * @param alias id
*/ */
getBigImageByAlias(alias: string): Readonly<IMaterialFramedData> | null; getBigImageByAlias(alias: string): IMaterialFramedData | null;
} }
export interface IMaterialManager export interface IMaterialManager
@ -366,19 +364,6 @@ export interface IMaterialManager
identifier: IIndexedIdentifier identifier: IIndexedIdentifier
): IMaterialData; ): IMaterialData;
/**
*
* @param identifier
* @param defaultFrame
*/
setDefaultFrame(identifier: number, defaultFrame: number): void;
/**
* -1 使
* @param identifier
*/
getDefaultFrame(identifier: number): number;
/** /**
* tileset使 {@link cacheTilesetList} * tileset使 {@link cacheTilesetList}
* @param identifier tileset * @param identifier tileset

View File

@ -256,12 +256,6 @@ export class MovingBlock extends DynamicBlockStatus implements IMovingBlock {
this.posUpdated = true; this.posUpdated = true;
} }
useDefaultFrame(): void {
if (!this.renderer.manager.getTile(this.tile)) return;
const defaultFrame = this.renderer.manager.getDefaultFrame(this.tile);
this.useSpecifiedFrame(defaultFrame);
}
destroy(): void { destroy(): void {
this.renderer.deleteMoving(this); this.renderer.deleteMoving(this);
} }

View File

@ -14,4 +14,5 @@ void main() {
// todo: 透明像素应该如何解决?? // todo: 透明像素应该如何解决??
if (alpha < 0.1) discard; if (alpha < 0.1) discard;
outColor = vec4(texColor.rgb, alpha); outColor = vec4(texColor.rgb, alpha);
// outColor = vec4(texColor.a * 0.001, v_texCoord.x * 6.0, v_texCoord.y * 0.0, v_texCoord.a);
} }

View File

@ -250,11 +250,6 @@ export interface IMovingBlock extends IBlockStatus {
*/ */
endMoving(): void; endMoving(): void;
/**
* 使
*/
useDefaultFrame(): void;
/** /**
* *
*/ */

View File

@ -44,8 +44,6 @@ export interface IMapDataGetter {
} }
interface BlockMapPos { interface BlockMapPos {
/** 图块的图块数字 */
readonly num: number;
/** 地图中的横坐标 */ /** 地图中的横坐标 */
readonly mapX: number; readonly mapX: number;
/** 地图中的纵坐标 */ /** 地图中的纵坐标 */
@ -79,15 +77,11 @@ interface VertexArrayOfBlock {
const enum VertexUpdate { const enum VertexUpdate {
/** 更新顶点位置信息 */ /** 更新顶点位置信息 */
Position = 0b001, Position = 0b01,
/** 更新贴图信息 */ /** 更新贴图信息 */
Texture = 0b010, Texture = 0b10,
/** 是否更新默认帧数 */
Frame = 0b100,
/** 除帧数外全部更新 */
NoFrame = 0b011,
/** 全部更新 */ /** 全部更新 */
All = 0b111 All = 0b11
} }
/** /**
@ -159,7 +153,6 @@ export class MapVertexGenerator
staticCount * INSTANCED_COUNT, staticCount * INSTANCED_COUNT,
count * INSTANCED_COUNT count * INSTANCED_COUNT
); );
// 不透明度默认是 1帧数默认是 -1
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
const start = i * INSTANCED_COUNT; const start = i * INSTANCED_COUNT;
this.instancedArray[start + 9] = 1; this.instancedArray[start + 9] = 1;
@ -412,12 +405,6 @@ export class MapVertexGenerator
instancedArray[startIndex + 14] = offsetIndex; instancedArray[startIndex + 14] = offsetIndex;
instancedArray[startIndex + 15] = assetIndex; instancedArray[startIndex + 15] = assetIndex;
} }
if (update & VertexUpdate.Frame) {
const defaultFrame = this.renderer.manager.getDefaultFrame(
index.num
);
instancedArray[startIndex + 12] = defaultFrame;
}
} }
/** /**
@ -486,14 +473,11 @@ export class MapVertexGenerator
if (!vertex) return; if (!vertex) return;
const bx = mx - block.dataX; const bx = mx - block.dataX;
const by = my - block.dataY; const by = my - block.dataY;
const mapIndex = my * this.mapWidth + mx;
const num = mapArray[mapIndex];
const newIndex: BlockIndex = { const newIndex: BlockIndex = {
layer, layer,
num,
mapX: mx, mapX: mx,
mapY: my, mapY: my,
mapIndex, mapIndex: my * this.mapWidth + mx,
blockX: bx, blockX: bx,
blockY: by, blockY: by,
blockIndex: by * block.width + bx blockIndex: by * block.width + bx
@ -505,7 +489,6 @@ export class MapVertexGenerator
vertex, vertex,
newIndex, newIndex,
tile, tile,
// 周围一圈的自动元件应该只更新贴图,不需要更新位置和默认帧数
VertexUpdate.Texture, VertexUpdate.Texture,
false false
); );
@ -542,7 +525,6 @@ export class MapVertexGenerator
return; return;
} }
// todo: 这样的话,如果更新了指定分块,那么本来设置的帧数也会重置为默认帧数,如何修改?
if (tile.cls === BlockCls.Autotile) { if (tile.cls === BlockCls.Autotile) {
// 如果图块是自动元件 // 如果图块是自动元件
this.updateAutotile( this.updateAutotile(
@ -550,7 +532,6 @@ export class MapVertexGenerator
vertex, vertex,
index, index,
tile, tile,
// 图块变了,所以全部要更新
VertexUpdate.All, VertexUpdate.All,
dynamic dynamic
); );
@ -579,7 +560,6 @@ export class MapVertexGenerator
assetIndex, assetIndex,
offsetIndex, offsetIndex,
tile.frames, tile.frames,
// 图块变了,所以全部要更新
VertexUpdate.All, VertexUpdate.All,
dynamic dynamic
); );
@ -610,7 +590,6 @@ export class MapVertexGenerator
const dIndex = dy * block.width + dx; const dIndex = dy * block.width + dx;
const index: BlockIndex = { const index: BlockIndex = {
layer, layer,
num,
mapX: x, mapX: x,
mapY: y, mapY: y,
mapIndex: y * this.mapWidth + x, mapIndex: y * this.mapWidth + x,
@ -811,10 +790,8 @@ export class MapVertexGenerator
const mapX = nx + block.dataX; const mapX = nx + block.dataX;
const mapY = ny + block.dataY; const mapY = ny + block.dataY;
const mapIndex = mapY * this.mapWidth + mapX; const mapIndex = mapY * this.mapWidth + mapX;
const num = array[mapIndex];
const index: BlockIndex = { const index: BlockIndex = {
layer, layer,
num,
blockX: nx, blockX: nx,
blockY: ny, blockY: ny,
blockIndex: ny * block.width + nx, blockIndex: ny * block.width + nx,
@ -822,7 +799,13 @@ export class MapVertexGenerator
mapY, mapY,
mapIndex mapIndex
}; };
this.updateVertexArray(array, vertex, index, num, false); this.updateVertexArray(
array,
vertex,
index,
array[mapIndex],
false
);
} }
} }
}); });
@ -840,7 +823,6 @@ export class MapVertexGenerator
}; };
const index: IndexedBlockMapPos = { const index: IndexedBlockMapPos = {
layer: block.layer, layer: block.layer,
num: block.tile,
mapX: block.x, mapX: block.x,
mapY: block.y, mapY: block.y,
blockIndex: block.index blockIndex: block.index
@ -851,9 +833,7 @@ export class MapVertexGenerator
logger.error(40, block.tile.toString()); logger.error(40, block.tile.toString());
return; return;
} }
const update = updateTexture const update = updateTexture ? VertexUpdate.All : VertexUpdate.Position;
? VertexUpdate.NoFrame
: VertexUpdate.Position;
if (cls === BlockCls.Autotile) { if (cls === BlockCls.Autotile) {
// 自动元件使用全部不连接 // 自动元件使用全部不连接
const renderable = this.renderer.autotile.renderWithoutCheck( const renderable = this.renderer.autotile.renderWithoutCheck(