From fef47ae73952bc4ec0bfa8ca3fa563521c02c64d Mon Sep 17 00:00:00 2001 From: Mikhail Babynichev Date: Wed, 6 Mar 2024 06:03:00 +0300 Subject: [PATCH] fix: use cached beatmap instead of opening it each time --- packages/tosu/package.json | 2 +- .../tosu/src/entities/BeatmapPpData/index.ts | 16 +++++---- .../tosu/src/entities/GamePlayData/index.ts | 34 +++++++------------ 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/packages/tosu/package.json b/packages/tosu/package.json index b84efc1b..fabd910e 100644 --- a/packages/tosu/package.json +++ b/packages/tosu/package.json @@ -9,7 +9,7 @@ "ts:compile": "ncc build src/index.ts -o dist -m -d", "run:dev": "pnpm run genver && pnpm run ts:run src/index.ts", "compile:prepare-htmls": "cp -rf node_modules/@tosu/server/assets ./dist", - "compile": "pnpm run genver && pnpm run ts:compile && pnpm run compile:prepare-htmls && pkg -t node18-win-x64 --output dist/tosu.exe --debug --config pkg.json --compress brotli dist/index.js && pnpm run ts:run src/postBuild.ts" + "compile": "pnpm run genver && pnpm run ts:compile && pnpm run compile:prepare-htmls && pkg -t node18-win-x64 --output dist/tosu.exe --debug --config pkg.json --compress brotli dist/index.js --options max-old-space-size=512 && pnpm run ts:run src/postBuild.ts" }, "dependencies": { "@kotrikd/rosu-pp": "^0.10.0", diff --git a/packages/tosu/src/entities/BeatmapPpData/index.ts b/packages/tosu/src/entities/BeatmapPpData/index.ts index c522077a..8d7ecc5f 100644 --- a/packages/tosu/src/entities/BeatmapPpData/index.ts +++ b/packages/tosu/src/entities/BeatmapPpData/index.ts @@ -55,6 +55,7 @@ interface BeatmapPPTimings { } export class BeatmapPPData extends AbstractEntity { + beatmap?: Beatmap; strains: number[]; strainsAll: BeatmapStrains; commonBPM: number; @@ -181,6 +182,10 @@ export class BeatmapPPData extends AbstractEntity { }; } + getCurrentBeatmap() { + return this.beatmap; + } + async updateMapMetadata(currentMods: number) { const start_time = performance.now(); @@ -195,9 +200,8 @@ export class BeatmapPPData extends AbstractEntity { menuData.Folder, menuData.Path ); - let beatmap: Beatmap; try { - beatmap = new Beatmap({ + this.beatmap = new Beatmap({ path: mapPath, ar: menuData.AR, od: menuData.OD, @@ -219,14 +223,14 @@ export class BeatmapPPData extends AbstractEntity { const calc = new Calculator(); const currAttrs = calc.mods(currentMods).mode(menuData.MenuGameMode); - const strains = currAttrs.strains(beatmap); - const mapAttributes = currAttrs.acc(100).mapAttributes(beatmap); - const fcPerformance = currAttrs.acc(100).performance(beatmap); + const strains = currAttrs.strains(this.beatmap); + const mapAttributes = currAttrs.acc(100).mapAttributes(this.beatmap); + const fcPerformance = currAttrs.acc(100).performance(this.beatmap); const ppAcc = {}; for (const acc of [100, 99, 98, 97, 96, 95]) { - const performance = currAttrs.acc(acc).performance(beatmap); + const performance = currAttrs.acc(acc).performance(this.beatmap); ppAcc[acc] = fixDecimals(performance.pp); } diff --git a/packages/tosu/src/entities/GamePlayData/index.ts b/packages/tosu/src/entities/GamePlayData/index.ts index 4bdca693..59bd21de 100644 --- a/packages/tosu/src/entities/GamePlayData/index.ts +++ b/packages/tosu/src/entities/GamePlayData/index.ts @@ -436,9 +436,10 @@ export class GamePlayData extends AbstractEntity { return; } - const { settings, menuData, beatmapPpData } = this.services.getServices( - ['settings', 'menuData', 'beatmapPpData'] - ); + const { settings, beatmapPpData } = this.services.getServices([ + 'settings', + 'beatmapPpData' + ]); if (!settings.gameFolder) { wLogger.debug( @@ -447,22 +448,11 @@ export class GamePlayData extends AbstractEntity { return; } - const mapPath = path.join( - settings.songsFolder, - menuData.Folder, - menuData.Path - ); - let beatmap; - try { - beatmap = new Beatmap({ - path: mapPath, - ar: menuData.AR, - od: menuData.OD, - cs: menuData.CS, - hp: menuData.HP - }); - } catch (exc) { - wLogger.error("GD(updateStarsAndPerformance) Can't get map", exc); + const currentBeatmap = beatmapPpData.getCurrentBeatmap(); + if (!currentBeatmap) { + wLogger.debug( + `GD(updateStarsAndPerformance) can't get current map` + ); return; } @@ -484,14 +474,16 @@ export class GamePlayData extends AbstractEntity { n300: this.Hit300 }; - const curPerformance = new Calculator(scoreParams).performance(beatmap); + const curPerformance = new Calculator(scoreParams).performance( + currentBeatmap + ); const fcPerformance = new Calculator({ mods: this.Mods, nMisses: this.HitMiss, n50: this.Hit50, n100: this.Hit100, n300: this.Hit300 - }).performance(beatmap); + }).performance(currentBeatmap); beatmapPpData.updateCurrentAttributes( curPerformance.difficulty.stars,