diff --git a/scripts/verify-tiles.ts b/scripts/verify-tiles.ts index 2b976bf..463958c 100644 --- a/scripts/verify-tiles.ts +++ b/scripts/verify-tiles.ts @@ -61,7 +61,12 @@ async function main(): Promise { archives.add(name, await MpqArchive.open(await fileSource(`${DIR}/${name}`))) } const tables = await loadActTables(archives) + // 解码出来的 DT1 库很占内存(每个瓦片的块像素是 width×bitmapHeight 的 Uint8Array, + // 一个库几十 MB),无限缓存跑完 35 关会涨到数 GB。跟打包器一样加个上限: + // 16 个库比任何单一关卡类型用到的都多,所以一关之内不会重复解码,内存曲线保持平坦。 const libraryCache = new Map() + /** 同时保留解码结果的 DT1 库上限。 */ + const LIBRARY_CACHE_LIMIT = 16 let levels = 0 let floors = 0 @@ -92,6 +97,10 @@ async function main(): Promise { try { const decoded = decodeDt1(await archives.read(name)) libraryCache.set(name, decoded) + if (libraryCache.size > LIBRARY_CACHE_LIMIT) { + const oldest = libraryCache.keys().next().value + if (oldest !== undefined && oldest !== name) libraryCache.delete(oldest) + } libs.push(decoded) } catch { /* 缺库时 verify:acts 会报 */ } }