Skip to content
Snippets Groups Projects
Commit 77577654 authored by dg's avatar dg
Browse files

Saving will not uselessly clone particles & suchs

git-svn-id: http://svn.net-core.org/repos/t-engine4@5683 51575b47-30f0-44d4-a5cc-537603b46e54
parent 61f96ffa
No related branches found
No related tags found
No related merge requests found
......@@ -64,7 +64,7 @@ function _M:push(savename, type, object, class, on_end)
if #self.pipe == 0 then savefile_pipe.current_nb = 0 end
local clone, nb = object:cloneFull()
local clone, nb = object:cloneForSave()
self.pipe[#self.pipe+1] = {id=id, savename = savename, type=type, object=clone, nb_objects=nb, baseobject=object, class=class, saveversion=game:saveVersion("new"), screenshot=screenshot, on_end=on_end}
local total_nb = 0
for i, p in ipairs(self.pipe) do total_nb = total_nb + p.nb_objects end
......
......@@ -160,7 +160,7 @@ function _M:clone(t)
return n
end
local function clonerecursfull(clonetable, d)
local function clonerecursfull(clonetable, d, noclonecall)
local nb = 0
local add
local n = {}
......@@ -170,18 +170,18 @@ local function clonerecursfull(clonetable, d)
while k do
local nk, ne = k, e
if clonetable[k] then nk = clonetable[k]
elseif type(k) == "table" then nk, add = clonerecursfull(clonetable, k) nb = nb + add
elseif type(k) == "table" then nk, add = clonerecursfull(clonetable, k, noclonecall) nb = nb + add
end
if clonetable[e] then ne = clonetable[e]
elseif type(e) == "table" and (type(k) ~= "string" or k ~= "__threads") then ne, add = clonerecursfull(clonetable, e) nb = nb + add
elseif type(e) == "table" and (type(k) ~= "string" or k ~= "__threads") then ne, add = clonerecursfull(clonetable, e, noclonecall) nb = nb + add
end
n[nk] = ne
k, e = next(d, k)
end
setmetatable(n, getmetatable(d))
if n.cloned and n.__CLASSNAME then n:cloned(d) end
if not noclonecall and n.cloned and n.__CLASSNAME then n:cloned(d) end
if n.__CLASSNAME then nb = nb + 1 end
return n, nb
end
......@@ -189,20 +189,20 @@ end
--- Clones the object, all subobjects without cloning twice a subobject
-- @return the clone and the number of cloned objects
function _M:cloneFull()
-- local old = core.game.getTime()
-- core.serial.cloneFull(self)
-- print("CLONE C", core.game.getTime() - old)
-- old = core.game.getTime()
-- local clonetable = {}
-- clonerecursfull(clonetable, self)
-- print("CLONE LUA", core.game.getTime() - old)
local clonetable = {}
return clonerecursfull(clonetable, self)
-- return core.serial.cloneFull(self)
end
--- Clones the object, all subobjects without cloning twice a subobject
-- Does not invoke clone methods as this is not for reloading, just for saving
-- @return the clone and the number of cloned objects
function _M:cloneForSave()
local clonetable = {}
return clonerecursfull(clonetable, self, true)
-- return core.serial.cloneFull(self)
end
--- Replaces the object with an other, by copying (not deeply)
function _M:replaceWith(t)
if self.replacedWith then self:replacedWith(false, t) end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment