+ chart leaderboard caching
This commit is contained in:
parent
d6dbee6316
commit
bd0a3c1005
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue