Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use cached beatmap instead of opening it each time #90

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading