Compare commits

..

1 Commits

Author SHA1 Message Date
AncTe
c60b1dd726
Merge 7fcefd62c4 into 820dc5bf4c 2025-11-25 09:49:18 +00:00
7 changed files with 36 additions and 104 deletions

View File

@ -1,7 +1,6 @@
import { ITexture } from '@motajs/render-assets';
import { materials } from './ins';
import { IBlockIdentifier, IIndexedIdentifier } from './types';
import { isNil } from 'lodash-es';
function extractClsBlocks<C extends Exclude<Cls, 'tileset'>>(
cls: C,
@ -9,10 +8,9 @@ function extractClsBlocks<C extends Exclude<Cls, 'tileset'>>(
icons: Record<string, number>
): IBlockIdentifier[] {
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)) {
// 样板编辑器 bug 可能会导致多个 id 使用一个偏移,因此要判断下
if (!(key in map) || !isNil(arr[value])) continue;
if (!(key in map)) continue;
const id = key as AllIdsOf<C>;
const num = map[id] as keyof NumberToId;
const identifier: IBlockIdentifier = {
@ -54,11 +52,7 @@ export function fallbackLoad() {
const idNumMap: Record<string, number> = {};
for (const [key, value] of Object.entries(core.maps.blocksInfo)) {
const num = Number(key);
idNumMap[value.id] = Number(num);
if (!isNil(value.animate)) {
materials.setDefaultFrame(num, value.animate - 1);
}
idNumMap[value.id] = Number(key);
}
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 clsMap: Map<number, BlockCls> = new Map();
/** 图块的默认帧数 */
readonly defaultFrames: Map<number, number> = new Map();
/** 网格切分器 */
readonly gridSplitter: TextureGridSplitter = new TextureGridSplitter();
@ -220,19 +218,7 @@ export class MaterialManager implements IMaterialManager {
return data;
}
setDefaultFrame(identifier: number, defaultFrame: number): void {
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 {
getTile(identifier: number): IMaterialFramedData | null {
if (identifier < 10000) {
const cls = this.clsMap.get(identifier) ?? BlockCls.Unknown;
if (
@ -247,8 +233,7 @@ export class MaterialManager implements IMaterialManager {
texture,
cls,
offset: 32,
frames: getTextureFrame(cls, texture),
defaultFrame: this.defaultFrames.get(identifier) ?? -1
frames: getTextureFrame(cls, texture)
};
} else {
const texture = this.cacheTileset(identifier);
@ -257,8 +242,7 @@ export class MaterialManager implements IMaterialManager {
texture,
cls: BlockCls.Tileset,
offset: 32,
frames: 1,
defaultFrame: -1
frames: 1
};
}
}
@ -271,7 +255,7 @@ export class MaterialManager implements IMaterialManager {
return this.imageStore.getTexture(identifier);
}
getTileByAlias(alias: string): Readonly<IMaterialFramedData> | null {
getTileByAlias(alias: string): IMaterialFramedData | null {
if (/X\d{5,}/.test(alias)) {
return this.getTile(parseInt(alias.slice(1)));
} else {
@ -553,8 +537,7 @@ export class MaterialManager implements IMaterialManager {
texture: image,
cls,
offset: image.width / 4,
frames,
defaultFrame: this.defaultFrames.get(identifier) ?? -1
frames
};
this.bigImageData.set(identifier, store);
const data: IBigImageReturn = {
@ -568,17 +551,17 @@ export class MaterialManager implements IMaterialManager {
return this.bigImageData.has(identifier);
}
getBigImage(identifier: number): Readonly<IMaterialFramedData> | null {
getBigImage(identifier: number): IMaterialFramedData | null {
return this.bigImageData.get(identifier) ?? null;
}
getBigImageByAlias(alias: string): Readonly<IMaterialFramedData> | null {
getBigImageByAlias(alias: string): IMaterialFramedData | null {
const identifier = this.idNumMap.get(alias);
if (isNil(identifier)) return null;
return this.bigImageData.get(identifier) ?? null;
}
getIfBigImage(identifier: number): Readonly<IMaterialFramedData> | null {
getIfBigImage(identifier: number): IMaterialFramedData | null {
const bigImage = this.bigImageData.get(identifier);
if (bigImage) return bigImage;
else return this.getTile(identifier);

View File

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

View File

@ -256,12 +256,6 @@ export class MovingBlock extends DynamicBlockStatus implements IMovingBlock {
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 {
this.renderer.deleteMoving(this);
}

View File

@ -14,4 +14,5 @@ void main() {
// 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);
}

View File

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

View File

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