Skip to content

Commit

Permalink
Merge pull request #90 from KotRikD/fix/use_cached_beatmap
Browse files Browse the repository at this point in the history
fix: use cached beatmap instead of opening it each time
  • Loading branch information
KotRikD authored Mar 6, 2024
2 parents 5560e10 + fef47ae commit c422164
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/tosu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 10 additions & 6 deletions packages/tosu/src/entities/BeatmapPpData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface BeatmapPPTimings {
}

export class BeatmapPPData extends AbstractEntity {
beatmap?: Beatmap;
strains: number[];
strainsAll: BeatmapStrains;
commonBPM: number;
Expand Down Expand Up @@ -181,6 +182,10 @@ export class BeatmapPPData extends AbstractEntity {
};
}

getCurrentBeatmap() {
return this.beatmap;
}

async updateMapMetadata(currentMods: number) {
const start_time = performance.now();

Expand All @@ -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,
Expand All @@ -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);
}

Expand Down
34 changes: 13 additions & 21 deletions packages/tosu/src/entities/GamePlayData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
}

Expand All @@ -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,
Expand Down

0 comments on commit c422164

Please sign in to comment.