From a44d20ac9a6bdb5eef10ed6e2cf01567b31babe1 Mon Sep 17 00:00:00 2001 From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54> Date: Tue, 22 Mar 2011 11:33:34 +0000 Subject: [PATCH] Fix bug when saving profile data would error out while saving the game git-svn-id: http://svn.net-core.org/repos/t-engine4@3046 51575b47-30f0-44d4-a5cc-537603b46e54 --- game/engines/default/engine/PlayerProfile.lua | 12 ++++++++++++ game/engines/default/engine/SavefilePipe.lua | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/game/engines/default/engine/PlayerProfile.lua b/game/engines/default/engine/PlayerProfile.lua index b84c177275..5293ce2fb8 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 730126438a..9564354729 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 -- GitLab