Compare commits

...

4 Commits

6 changed files with 53 additions and 71 deletions

View File

@ -10,7 +10,7 @@
"type": "vue-tsc --noEmit",
"lines": "tsx script/lines.ts packages packages-user",
"build:packages": "vue-tsc --noEmit && tsx script/build-packages.ts",
"build:game": "vue-tsc --noEmit && tsx script/build-game.ts",
"build:game": "tsx script/declare.ts && vue-tsc --noEmit && tsx script/build-game.ts",
"build:lib": "vue-tsc --noEmit && tsx script/build-lib.ts",
"docs:dev": "concurrently -k -n SIDEBAR,VITEPRESS -c blue,green \"tsx docs/.vitepress/api.ts\" \"vitepress dev docs\"",
"docs:build": "vitepress build docs",

View File

@ -3,12 +3,20 @@ import { create } from './create';
import { patchAll } from '@user/data-fallback';
import { loading } from '@user/data-base';
import { Patch } from '@motajs/legacy-common';
import { logger } from '@motajs/common';
export function createData() {
createMota();
patchAll();
create();
if (main.replayChecking) {
logger.log(
`如果需要调试录像验证,请在 script/build-game.ts 中将 DEBUG_REPLAY 设为 true` +
`此时录像验证中可以看到完整正确的报错栈。调试完毕后,记得将它重新设为 false`
);
}
loading.once('coreInit', () => {
Patch.patchAll();
});

View File

@ -21,7 +21,7 @@ import { isNil } from 'lodash-es';
interface IndexMarkedComposedData {
/** 组合数据 */
readonly data: ITextureComposedData;
readonly asset: ITextureComposedData;
/** 组合时最后一个用到的贴图的索引 */
readonly index: number;
}
@ -33,75 +33,37 @@ type TranslatedComposer<D, T> = ITextureComposer<
>;
export interface IGridComposerData {
/** 单张图集的最大宽度 */
readonly maxWidth: number;
/** 单张图集的最大高度 */
readonly maxHeight: number;
/** 单个贴图的宽度,与之不同的贴图将会被剔除并警告 */
readonly width: number;
/** 单个贴图的宽度,与之不同的贴图将会被剔除并警告 */
readonly height: number;
}
interface GridNeededSize {
/** 图集宽度 */
readonly width: number;
/** 图集高度 */
readonly height: number;
/** 一共有多少行 */
readonly rows: number;
/** 一共有多少列 */
readonly cols: number;
}
/**
*
*
*/
export class TextureGridComposer<T>
implements TranslatedComposer<IGridComposerData, T>
{
private getNeededSize(
tex: ITexture[],
start: number,
data: IGridComposerData
): GridNeededSize {
const maxRows = Math.floor(data.maxWidth / data.width);
const maxCols = Math.floor(data.maxHeight / data.height);
const rest = tex.length - start;
if (rest >= maxRows * maxCols) {
const size: GridNeededSize = {
width: data.maxWidth,
height: data.maxHeight,
rows: maxRows,
cols: maxCols
};
return size;
} else {
const aspect = data.height / data.width;
const cols = Math.ceil(Math.sqrt(rest * aspect));
const rows = Math.ceil(rest / cols);
const size: GridNeededSize = {
width: cols * data.width,
height: rows * data.height,
rows,
cols
};
return size;
}
}
/**
*
*
* @param maxWidth
* @param maxHeight
*/
constructor(
readonly maxWidth: number,
readonly maxHeight: number
) {}
private nextAsset(
tex: ITexture[],
start: number,
data: IGridComposerData
data: IGridComposerData,
rows: number,
cols: number
): IndexMarkedComposedData {
const size = this.getNeededSize(tex, start, data);
const { width, height, rows, cols } = size;
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d')!;
canvas.width = width;
canvas.height = height;
canvas.width = this.maxWidth;
canvas.height = this.maxHeight;
const count = Math.min(rows * cols, tex.length - start);
const map = new Map<ITexture, IRect>();
@ -131,7 +93,7 @@ export class TextureGridComposer<T>
assetMap: map
};
return { data: composed, index: start + count };
return { asset: composed, index: start + count };
}
*compose(
@ -140,10 +102,13 @@ export class TextureGridComposer<T>
): Generator<ITextureComposedData> {
const arr = [...input];
const rows = Math.floor(this.maxWidth / data.width);
const cols = Math.floor(this.maxHeight / data.height);
let i = 0;
while (i < arr.length) {
const { data: asset, index } = this.nextAsset(arr, i, data);
const { asset, index } = this.nextAsset(arr, i, data, rows, cols);
i = index + 1;
yield asset;
}
@ -160,13 +125,15 @@ interface MaxRectsRectangle extends IRectangle {
readonly data: ITexture;
}
/**
* 使 Max Rects {@link IMaxRectsComposerData}
* {@link TextureMaxRectsWebGL2Composer}
*/
export class TextureMaxRectsComposer<T>
implements TranslatedComposer<IMaxRectsComposerData, T>
{
/**
* 使 Max Rects {@link IMaxRectsComposerData}
* {@link TextureMaxRectsWebGL2Composer}
* @param maxWidth
* @param maxHeight
*/
constructor(
public readonly maxWidth: number,
public readonly maxHeight: number
@ -195,8 +162,8 @@ export class TextureMaxRectsComposer<T>
const map = new Map<ITexture, IRect>();
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d')!;
canvas.width = bin.width;
canvas.height = bin.height;
canvas.width = this.maxWidth;
canvas.height = this.maxHeight;
ctx.imageSmoothingEnabled = false;
bin.rects.forEach(v => {
const rect: IRect = { x: v.x, y: v.y, w: v.width, h: v.height };
@ -226,12 +193,6 @@ interface RectProcessed {
readonly attrib: Float32Array;
}
/**
* 使 Max Rects {@link IMaxRectsComposerData}
*
* `compose`
* 使 `toBitmap`
*/
export class TextureMaxRectsWebGL2Composer<T>
implements TranslatedComposer<IMaxRectsComposerData, T>
{
@ -257,6 +218,15 @@ export class TextureMaxRectsWebGL2Composer<T>
/** 本次处理的贴图高度 */
private opHeight: number = 0;
/**
* 使 Max Rects 使 WebGL2
* {@link IMaxRectsComposerData}
* `compose`
* 使 `toBitmap`,
* `next`
* @param maxWidth
* @param maxHeight
*/
constructor(
public readonly maxWidth: number,
public readonly maxHeight: number

View File

@ -50,7 +50,7 @@ export class Texture<T = unknown, A = unknown> implements ITexture<T, A> {
async toBitmap(): Promise<void> {
if (this.source instanceof ImageBitmap) return;
this.source = await createImageBitmap(this.source as any);
this.source = await createImageBitmap(this.source);
}
split<U>(splitter: ITextureSplitter<U>, data: U): Generator<ITexture> {

View File

@ -13,6 +13,9 @@ import { RequiredData, RequiredIconsData, ResourceType } from './types';
import { splitResource, SplittedResource } from './build-resource';
import { formatSize } from './utils';
/** 打包调试 */
const DEBUG_BUILD = false;
/** 录像验证调试 */
const DEBUG_REPLAY = false;
const ansi = {
@ -52,6 +55,7 @@ async function buildClient(outDir: string) {
build: {
outDir,
copyPublicDir: true,
minify: !DEBUG_BUILD,
rollupOptions: {
external: ['@wasm-audio-decoders/opus-ml'],
output: {

View File

@ -559,7 +559,7 @@ async function doDeclaration(type: string, data: string) {
num2id += '}';
await writeFile('src/types/source/cls.d.ts', id2cls, 'utf-8');
await writeFile(
'src/source/maps.d.ts',
'src/types/source/maps.d.ts',
`${id2num}\n${num2id}`,
'utf-8'
);