From bd0a3c1005bb496a2cce235a9daff70188114a06 Mon Sep 17 00:00:00 2001 From: FajsiEx Date: Thu, 16 Dec 2021 18:01:33 +0100 Subject: [PATCH] + chart leaderboard caching --- scripts/songselect/songwheel.lua | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/scripts/songselect/songwheel.lua b/scripts/songselect/songwheel.lua index 25fedd0..72e4998 100644 --- a/scripts/songselect/songwheel.lua +++ b/scripts/songselect/songwheel.lua @@ -122,6 +122,7 @@ local top50diffs = {} local irRequestStatus = 1; -- 0=unused, 1=not requested, 2=loading, others are status codes local irRequestTimeout = 2 local irLeaderboard = {} +local irLeaderboardsCache = {} local transitionScrollScale = 0; local transitionScrollOffsetY = 0; @@ -578,6 +579,7 @@ function drawIrLeaderboard() end if #irLeaderboard == 0 then + gfx.Text("This chart has no scores", scoreBoardX + (sbBarWidth / 2), scoreBoardY + sbBarHeight/2); return; end @@ -667,7 +669,7 @@ function drawSearch() gfx.Text(songwheel.searchText, desw-200, 30); end -function refreshIrLeaderboard() +function refreshIrLeaderboard(deltaTime) if irRequestStatus ~= 1 then -- Only continue if the leaderboard is requesteded, but not loading or loaded. return end @@ -680,6 +682,17 @@ function refreshIrLeaderboard() return; end + if (irLeaderboardsCache[diff.hash]) then + irLeaderboard = irLeaderboardsCache[diff.hash]; + irRequestStatus = 20; + return; + end + + if (irRequestTimeout > 0) then + irRequestTimeout = irRequestTimeout - deltaTime + return; + end + irRequestStatus = 2; -- Loading -- onIrLeaderboardFetched({ -- statusCode = 20, @@ -711,6 +724,10 @@ function onIrLeaderboardFetched(res) irLeaderboard[tempScore.ranking] = tempScore end + local song = songwheel.songs[selectedIndex]; + local diff = song and song.difficulties[selectedDifficulty] or false; + irLeaderboardsCache[diff.hash] = irLeaderboard; + game.Log(dump(irLeaderboard), game.LOGGER_ERROR) else game.Log("IR error " .. res.statusCode, game.LOGGER_ERROR) @@ -921,11 +938,7 @@ render = function (deltaTime) draw_songwheel((resX - fullX) / 2, 0, fullX, fullY, deltaTime); - if (irRequestTimeout < 0) then - refreshIrLeaderboard(); -- For explantion, check where isIrLeaderboardRequested is defined - else - irRequestTimeout = irRequestTimeout - deltaTime - end + refreshIrLeaderboard(deltaTime); end songs_changed = function (withAll)