savevars optimization

This commit is contained in:
p.kosyh 2010-08-31 18:37:49 +00:00
parent 34715f4074
commit 9c79407d69
3 changed files with 10 additions and 7 deletions

1
debian/changelog vendored
View file

@ -4,6 +4,7 @@ instead (1.2.1) unstable; urgency=low
* fading fix;
* fix in disable autosave;
* disp fix;
* savevars optimization;
-- Peter Kosyh <p.kosyh@gmail.com> Sat, 28 Aug 2010 19:47:00 +0300

View file

@ -1701,6 +1701,7 @@ function gamefile(file, forget)
set_music();
set_sound();
timer:stop();
variables = nil
init = function() -- null init function
end
for_each_object(function(k, o) -- destroy all objects

View file

@ -1,11 +1,8 @@
function isForSave(k, v, s) -- k - key, v - value, s -- parent table
local i,o
if type(s.variables) == 'table' then
for i,o in ipairs(s.variables) do
if o == k then
return true
end
end
if type(s.variables_save) == 'table' and
s.variables_save[k] then
return true
end
if type(k) == 'function' then
return false
@ -24,7 +21,7 @@ function __vars_add(s, v, set)
elseif s.variables[k] then
error ("Variable overwrites variables object: "..tostring(k))
elseif k ~= 'variable_type' then
if set and (type(o) == 'string' or type(o) == 'boolean' or type(o) == 'number') then
if set and not isObject(o) then
if s[k] then
error ("Global variable conflict: "..tostring(k));
end
@ -52,6 +49,7 @@ function __vars_fill(v)
if type(v.variables) == 'table' then
local k,o
local vars = {}
v.variables_save = {}
for k,o in pairs(v.variables) do
if tonumber(k) and type(o) == 'string' then
stead.table.insert(vars, o)
@ -63,6 +61,9 @@ function __vars_fill(v)
stead.table.insert(vars, k);
end
end
for k,o in ipairs(vars) do
v.variables_save[o] = true
end
v.variables = vars;
end
end