Compare commits

..

No commits in common. "146866d51f9538976659d2279d5742a6551cf167" and "77246b571a0b93d601701364ea0819e5b4c35088" have entirely different histories.

6 changed files with 71 additions and 53 deletions

View File

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

View File

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

View File

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

View File

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

View File

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