diff --git a/game/engines/default/engine/PlayerProfile.lua b/game/engines/default/engine/PlayerProfile.lua index b84c17727575ad5792a2a1e522d1cd0bf69168ee..5293ce2fb8ad92e65fa96a55d7e7b35f57f8b12c 100644 --- a/game/engines/default/engine/PlayerProfile.lua +++ b/game/engines/default/engine/PlayerProfile.lua @@ -134,6 +134,9 @@ end --- Loads profile generic profile from disk -- Generic profile is always read from the "online" profile function _M:loadGenericProfile() + -- Delay when we are currently saving + if savefile_pipe and savefile_pipe.saving then savefile_pipe:pushGeneric("loadGenericProfile", function() self:loadGenericProfile() end) return end + local pop = self:mountProfile(true) local d = "/current-profile/generic/" for i, file in ipairs(fs.list(d)) do @@ -207,6 +210,9 @@ end function _M:loadModuleProfile(short_name) if short_name == "boot" then return end + -- Delay when we are currently saving + if savefile_pipe and savefile_pipe.saving then savefile_pipe:pushGeneric("loadModuleProfile", function() self:loadModuleProfile(short_name) end) return end + local function load(online) local pop = self:mountProfile(online, short_name) local d = "/current-profile/modules/"..short_name.."/" @@ -241,6 +247,9 @@ end --- Saves a profile data function _M:saveGenericProfile(name, data, nosync) + -- Delay when we are currently saving + if savefile_pipe and savefile_pipe.saving then savefile_pipe:pushGeneric("saveGenericProfile", function() self:saveGenericProfile(name, data, nosync) end) return end + data = serialize(data) -- Check for readability @@ -263,6 +272,9 @@ end function _M:saveModuleProfile(name, data, module, nosync) if module == "boot" then return end + -- Delay when we are currently saving + if savefile_pipe and savefile_pipe.saving then savefile_pipe:pushGeneric("saveModuleProfile", function() self:saveModuleProfile(name, data, module, nosync) end) return end + data = serialize(data) module = module or self.mod_name diff --git a/game/engines/default/engine/SavefilePipe.lua b/game/engines/default/engine/SavefilePipe.lua index 730126438a2615844698174995509f7f1e626116..9564354729ca389fd6ce7051c62dc77d035f4b6c 100644 --- a/game/engines/default/engine/SavefilePipe.lua +++ b/game/engines/default/engine/SavefilePipe.lua @@ -37,6 +37,7 @@ function _M:init(class, max_before_wait) self.saveclass = class or "engine.Savefile" self.pipe = {} + self.on_done = {} self.max_before_wait = max_before_wait or 4 self.co = nil self.current_nb = 0 @@ -73,6 +74,11 @@ function _M:push(savename, type, object, class) end end +--- Push a generic action to be done once saves complete +function _M:pushGeneric(name, fct) + self.on_done[#self.on_done+1] = {name=name, fct=fct} +end + --- Actually do the saves -- This should run in a coroutine.<br/> -- Do not call this, this is automatic! @@ -99,6 +105,14 @@ function _M:doThread() -- collectgarbage("restart") self.saving = false if game:getPlayer() then game:getPlayer().changed = true end + + -- Run the generic stuff + while #self.on_done > 0 do + local p = self.on_done[1] + print("[SAVEFILE PIPE] on end", p.name) + p.fct() + table.remove(self.on_done, 1) + end end --- Force to wait for the saves