Skip to content

Commit

Permalink
fixup: various cleanup to saveloadgame.lua
Browse files Browse the repository at this point in the history
* Remove debug output
* Comment out profiler
* Optimise lua table access
* remove dead-code
  • Loading branch information
mwerle committed Oct 11, 2024
1 parent 1beda4d commit c0493e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 72 deletions.
91 changes: 19 additions & 72 deletions data/pigui/modules/saveloadgame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -201,32 +201,12 @@ end
-- Event callback once the savegame information has been loaded
-- Updates the entryCache with the full details of the savegame.
function SaveLoadWindow:onSaveGameStats(saveInfo)
print('onSaveGameStats : filename =', saveInfo.filename)
print('onSaveGameStats : compatible =', saveInfo.compatible)
print('onSaveGameStats : gameTime =', saveInfo.time)
print('onSaveGameStats : system =', saveInfo.system)

if not self.entryCache then
print('onSaveGameStats: self.entryCache is NIL!!')
return
end

if not self.entryCache[saveInfo.filename] then
print('onSaveGameStats: self.entryCache['.. saveInfo.filename .. '] is NIL!!')
return
end

-- local profileEndScope = utils.profile("SaveLoadWindow:onSaveGameStats()")
local location = saveInfo.system or lc.UNKNOWN
if saveInfo.docked_at then
location = location .. ", " .. saveInfo.docked_at
end

-- local saveEntry = self:getSaveEntry(saveInfo.filename)
-- saveEntry.compatible = saveInfo.compatible
-- saveEntry.gameTime = saveInfo.time
-- saveEntry.locationName = location
-- self.entryCache[saveInfo.filename] = saveEntry

-- Old saves store only the name of the ship's *model* file for some dumb reason
-- Treat the model name as the ship id and otherwise ignore it if we have proper data
local shipHull
Expand All @@ -239,14 +219,17 @@ function SaveLoadWindow:onSaveGameStats(saveInfo)
shipHull = saveInfo.shipHull
end

self.entryCache[saveInfo.filename].character = saveInfo.character
self.entryCache[saveInfo.filename].compatible = saveInfo.compatible
self.entryCache[saveInfo.filename].credits = saveInfo.credits
self.entryCache[saveInfo.filename].duration = saveInfo.duration
self.entryCache[saveInfo.filename].gameTime = saveInfo.time
self.entryCache[saveInfo.filename].locationName = location
self.entryCache[saveInfo.filename].shipName = saveInfo.shipName
self.entryCache[saveInfo.filename].shipHull = shipHull
local entry = self.entryCache[saveInfo.filename]
entry.character = saveInfo.character
entry.compatible = saveInfo.compatible
entry.credits = saveInfo.credits
entry.duration = saveInfo.duration
entry.gameTime = saveInfo.time
entry.locationName = location
entry.shipName = saveInfo.shipName
entry.shipHull = shipHull

-- profileEndScope()
end

local function onSaveGameStats(saveInfo)
Expand All @@ -255,50 +238,16 @@ end

-- Trigger load of savegame information and return bare-bones entry
local function makeEntryForSave(file)
print('makeEntryForSave : file=', file.name)
pcall(Game.SaveGameStats, file.name)
-- local profileEndScope = utils.profile("makeEntryForSave()")
Game.SaveGameStats(file.name)

local saveEntry = SaveGameEntry:clone({
name = file.name,
isAutosave = file.name:sub(1, 1) == "_",
timestamp = file.mtime.timestamp,
})

-- local compatible, saveInfo = pcall(Game.SaveGameStats, file.name)
-- if not compatible then
-- saveInfo = {}
-- end

-- local location = saveInfo.system or lc.UNKNOWN

-- if saveInfo.docked_at then
-- location = location .. ", " .. saveInfo.docked_at
-- end

-- local saveEntry = SaveGameEntry:clone({
-- name = file.name,
-- compatible = compatible,
-- isAutosave = file.name:sub(1, 1) == "_",
-- character = saveInfo.character,
-- timestamp = file.mtime.timestamp,
-- gameTime = saveInfo.time,
-- duration = saveInfo.duration,
-- locationName = location,
-- credits = saveInfo.credits,
-- shipName = saveInfo.shipName,
-- shipHull = saveInfo.shipHull,
-- })

-- -- Old saves store only the name of the ship's *model* file for some dumb reason
-- -- Treat the model name as the ship id and otherwise ignore it if we have proper data
-- if not saveInfo.shipHull then
-- local shipDef = ShipDef[saveInfo.ship]

-- if shipDef then
-- saveEntry.shipHull = shipDef.name
-- end
-- end

-- profileEndScope()
return saveEntry
end

Expand All @@ -309,6 +258,7 @@ end
--=============================================================================

function SaveLoadWindow:makeFilteredList()
local profileEndScope = utils.profile("SaveLoadWindow::makeFilteredList()")
local shouldShow = function(f)
if not self.showAutosaves and f.name:sub(1, 1) == "_" then
return false
Expand All @@ -332,9 +282,11 @@ function SaveLoadWindow:makeFilteredList()
if not utils.contains_if(self.filteredFiles, isSelectedFile) then
self.selectedFile = nil
end
profileEndScope()
end

function SaveLoadWindow:makeFileList()
-- local profileEndScope = utils.profile("SaveLoadWindow::makeFileList()")
local ok, files = pcall(Game.ListSaves)

if not ok then
Expand All @@ -349,6 +301,7 @@ function SaveLoadWindow:makeFileList()
end)

self:makeFilteredList()
-- profileEndScope()
end

function SaveLoadWindow:loadSelectedSave()
Expand Down Expand Up @@ -618,12 +571,6 @@ end

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

local function test(saveInfo)
print("saveInfo : ", saveInfo)
print("saveInfo.filename : ", saveInfo.filename)
end

-- Event.Register("onSaveGameStats", test)
Event.Register("onSaveGameStats", onSaveGameStats)

ui.saveLoadWindow = SaveLoadWindow
Expand Down
1 change: 1 addition & 0 deletions src/lua/LuaEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace LuaEvent {
{
Queue(GetEventQueue(), event);
}

} // namespace LuaEvent

#endif

0 comments on commit c0493e4

Please sign in to comment.