Lots of code cleanup. Start implementing mod buffer culling.
This commit is contained in:
parent
16bcbc8e00
commit
1e9c456f78
4 changed files with 56 additions and 81 deletions
27
world.lua
27
world.lua
|
@ -85,15 +85,15 @@ function init_world()
|
|||
-- 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
|
||||
-- coordinates. this is to flatten the buffer so that #mod_cache is useful
|
||||
-- for checking against max_mod_entries.
|
||||
max_mod_entries = 4096
|
||||
-- for checking against the number of allowed entries
|
||||
mod_buffer = {}
|
||||
mod_queue = {}
|
||||
end
|
||||
|
||||
-- draw the sprites for this part of the world to the screen
|
||||
-- this calculates everything about the world fresh every frame,
|
||||
-- but pico-8 handles this just fine!
|
||||
function draw_world_segment(start_x, start_y)
|
||||
function draw_world(start_x, start_y)
|
||||
for x=0,15 do
|
||||
for y=0,15 do
|
||||
spr(get_tile(start_x-8+x, start_y-8+y), x*8, y*8)
|
||||
|
@ -172,16 +172,25 @@ function get_mod_key(x, 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
|
||||
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)
|
||||
mod_buffer[key] = new_sprite
|
||||
|
||||
mod_buffer[get_mod_key(global_x, global_y)] = new_sprite
|
||||
-- the queue gives us a time-ordered list of items to delete.
|
||||
-- anything that should persist is simply not added to the queue,
|
||||
-- making it un-deletable.
|
||||
-- obviously if we end up with a *very large number* of persistent
|
||||
-- objects we can run into trouble, but this is functionally a design
|
||||
-- limitation.
|
||||
if not perm then
|
||||
add(mod_queue, key)
|
||||
end
|
||||
end
|
||||
|
||||
function cull_mod_buffer()
|
||||
-- we cull 10% of the mod buffer at a time
|
||||
-- todo: implement this
|
||||
-- we cull 512 entries at a time.
|
||||
-- stub: implement me!
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue