Skip to content

Commit 9a5b8c8

Browse files
authored
scoreboard: Fix performance regression in getCursorScoreboardPosition (#411)
1 parent c142886 commit 9a5b8c8

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

[gameplay]/scoreboard/dxscoreboard_rt.lua

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,35 @@ local rt
88
local lastUpdateTime = 0
99
local savedRowsNext = {}
1010
local savedRows = {}
11+
local cursorCache = {}
1112

1213
-- Adjust cursor position if using rt
1314

1415
local function getCursorScoreboardPosition(rtPass)
15-
local cX, cY = getCursorPosition()
16-
local sX, sY = SCREEN_X, SCREEN_Y
17-
18-
cX, cY = cX * sX, cY * sY
19-
20-
if rtPass then
21-
local x, y = scoreboardGetTopCornerPosition()
16+
if #cursorCache == 0 then
17+
local cX, cY = getCursorPosition()
18+
local sX, sY = SCREEN_X, SCREEN_Y
19+
20+
cX, cY = cX * sX, cY * sY
21+
22+
if rtPass then
23+
local x, y = scoreboardGetTopCornerPosition()
2224

23-
cX, cY = cX - x, cY - y
25+
cX, cY = cX - x, cY - y
26+
end
27+
28+
cursorCache = {cX, cY}
2429
end
2530

26-
return cX, cY
31+
return cursorCache[1], cursorCache[2]
2732
end
2833

2934
-- drawScoreboard
3035
-- Do things depending on things
3136

3237
function drawScoreboard()
38+
cursorCache = {}
39+
3340
if #savedRowsNext > 0 then
3441
savedRows = savedRowsNext
3542
savedRowsNext = {}

0 commit comments

Comments
 (0)