Implement mod_buffer culling, as well as a flag that makes some changes more persistent than others.
This commit is contained in:
parent
1e9c456f78
commit
374336ee4a
35
world.lua
35
world.lua
|
@ -1,4 +1,5 @@
|
||||||
--- Procedural generation methods
|
--- Procedural generation methods, and other aspects of generating the
|
||||||
|
--- environment
|
||||||
|
|
||||||
function init_world()
|
function init_world()
|
||||||
-- Metadata for different biomes
|
-- Metadata for different biomes
|
||||||
|
@ -156,14 +157,8 @@ end
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
--- mod buffer functions - these handle parts of the world map that have
|
--- mod buffer functions - these handle locations on the world map that have
|
||||||
--- changed from their 'default' position
|
--- changed from their 'default' state
|
||||||
---
|
|
||||||
--- todo: the mod buffer eventually needs to be a bit more elaborate.
|
|
||||||
--- we need to make it possible to cull only old and unimportant changes,
|
|
||||||
--- so each entry needs a 'critical' flag and something to indicate order
|
|
||||||
--- added. We could keep 2 buffers for the latter, one that's just keys
|
|
||||||
--- in an array... expensive though.
|
|
||||||
---
|
---
|
||||||
|
|
||||||
-- x and y are global coords
|
-- x and y are global coords
|
||||||
|
@ -173,24 +168,34 @@ end
|
||||||
|
|
||||||
-- x and y are map-local coords
|
-- x and y are map-local coords
|
||||||
function write_map_change(new_sprite, x, y, perm)
|
function write_map_change(new_sprite, x, y, perm)
|
||||||
if #mod_buffer >= 8192 then
|
|
||||||
cull_mod_buffer()
|
|
||||||
end
|
|
||||||
local key = get_mod_key(x, y)
|
local key = get_mod_key(x, y)
|
||||||
mod_buffer[key] = new_sprite
|
mod_buffer[key] = new_sprite
|
||||||
|
|
||||||
-- the queue gives us a time-ordered list of items to delete.
|
-- the queue gives us a time-ordered list of items to delete.
|
||||||
-- anything that should persist is simply not added to the queue,
|
-- anything that should persist is simply not added to the queue,
|
||||||
-- making it un-deletable.
|
-- making it un-deletable. It also doesn't count against the maximum
|
||||||
|
-- size of the mod queue before deletion, meaning it permanently inflates
|
||||||
|
-- the size of ram.
|
||||||
-- obviously if we end up with a *very large number* of persistent
|
-- obviously if we end up with a *very large number* of persistent
|
||||||
-- objects we can run into trouble, but this is functionally a design
|
-- objects we can run into trouble, but this is functionally a design
|
||||||
-- limitation.
|
-- limitation. We also only save 32 of these on exit, further limiting
|
||||||
|
-- the possible size of the 'memory leak' pool, as it were.
|
||||||
if not perm then
|
if not perm then
|
||||||
add(mod_queue, key)
|
add(mod_queue, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if #mod_queue >= 8192 then
|
||||||
|
cull_mod_buffer()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function cull_mod_buffer()
|
function cull_mod_buffer()
|
||||||
-- we cull 512 entries at a time.
|
-- we cull 512 entries at a time.
|
||||||
-- stub: implement me!
|
local count = 0
|
||||||
|
for i=1,511 do
|
||||||
|
local key = mod_queue[1]
|
||||||
|
if (not key) return -- check that we're not out of items for some reason
|
||||||
|
mod_buffer[key] = nil
|
||||||
|
del(mod_queue, key)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user