Some debug code cleanup, change the format for the mod buffer key.

This commit is contained in:
Anna Rose Wiggins 2019-12-11 00:29:02 -05:00
parent 8e66d3c380
commit a75408fb22
3 changed files with 74 additions and 19 deletions

View file

@ -49,7 +49,7 @@ function init_data()
}
-- initialize a ring buffer of changed positions. In use, this will be keyed
-- using strings of the form mod_buffer["x+y"], using absolute world
-- using strings of the form mod_buffer["x:y"], using absolute world
-- coordinates. this is to flatten the buffer so that #mod_cache is useful
-- for checking against max_mod_entries.
max_mod_entries = 4096
@ -57,13 +57,23 @@ function init_data()
end
-- x and y are global coords
function get_mod_key(x, y)
return tostr(x) .. ":" .. tostr(y)
end
-- x and y are map-local coords
function write_map_change(new_sprite, x, y)
local global_x, global_y = calculate_world_pos(x, y)
if #mod_buffer >= max_mod_entries then
-- todo: make the buffer ring
cull_mod_buffer()
end
mod_buffer[tostr(global_x) .. "+" .. tostr(global_y)] = new_sprite
mod_buffer[get_mod_key(global_x, global_y)] = new_sprite
end
function cull_mod_buffer()
-- we cull 10% of the mod buffer at a time
-- todo: implement this
end
function calculate_world_pos(x, y)