Skip to content

Commit

Permalink
Cache calculated paths
Browse files Browse the repository at this point in the history
  • Loading branch information
solstice23 committed Mar 12, 2024
1 parent b5c9305 commit 6edf9c9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/modules/Main/Playfield/Playfield.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ export function Playfield({ beatmap }) {
setCalculatingPath(false);
return;
}
const bananaPathKey = JSON.stringify([beatmap.difficulty.circleSize, hardRock, easy, derandomize]);
const cachedPath = beatmap.cachedBananaPaths?.[bananaPathKey];
if (cachedPath) {
setBestPath(cachedPath);
setCalculatingPath(false);
return;
}
const worker = new Worker(new URL('./../../../parser/AutoPathCalculatorWorker.js', import.meta.url), { type: 'module' });
worker.postMessage({
params: [beatmap.ctbObjects, beatmap.difficulty.circleSize, hardRock, easy, derandomize],
Expand All @@ -101,9 +108,10 @@ export function Playfield({ beatmap }) {
for (const index of missedBananas) beatmap.ctbObjects[index].bananaMissed = true;
setBestPath(path);
setCalculatingPath(false);
beatmap.cachedBananaPaths = beatmap.cachedBananaPaths || {};
beatmap.cachedBananaPaths[bananaPathKey] = path;
}
return () => worker.terminate();
// TODO: Cache calculated paths
}, [beatmap, hardRock, easy, derandomize, userInfo?.eligible]);


Expand Down

0 comments on commit 6edf9c9

Please sign in to comment.