Skip to content

Commit

Permalink
refactor: remove manual rate-limiting in saveloadgame.lua
Browse files Browse the repository at this point in the history
- Prior code limited synchronous Game.SaveGameStats calls to once-per-frame
- Since the function is now async, we can dispatch as many jobs as we want and their results will be processed on completion
  • Loading branch information
sturnclaw committed Oct 16, 2024
1 parent 63c95d1 commit 6ebf296
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions data/pigui/modules/saveloadgame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ function SaveLoadWindow:makeFileList()
return a.mtime.timestamp > b.mtime.timestamp
end)

-- Cache details about each savefile
for _, file in ipairs(self.files) do
if not self.entryCache[file.name] or self.entryCache[file.name].timestamp ~= file.mtime.timestamp then
self.entryCache[file.name] = makeEntryForSave(file)
end
end

self:makeFilteredList()
-- profileEndScope()
end
Expand Down Expand Up @@ -351,21 +358,6 @@ function SaveLoadWindow:deleteSelectedSave()
end)
end

function SaveLoadWindow:update()
ModalWindow.update(self)

-- Incrementally update cache until all files are up to date
-- We don't need to manually clear the cache, as changes to the list of
-- files will trigger the cache to be updated
local uncached = utils.find_if(self.files, function(_, file)
return not self.entryCache[file.name] or self.entryCache[file.name].timestamp ~= file.mtime.timestamp
end)

if uncached then
self.entryCache[uncached.name] = makeEntryForSave(uncached)
end
end

--=============================================================================

function SaveLoadWindow:onOpen()
Expand Down

0 comments on commit 6ebf296

Please sign in to comment.