Some debug code cleanup, change the format for the mod buffer key.
This commit is contained in:
parent
8e66d3c380
commit
a75408fb22
16
data.lua
16
data.lua
|
@ -49,7 +49,7 @@ function init_data()
|
||||||
}
|
}
|
||||||
|
|
||||||
-- initialize a ring buffer of changed positions. In use, this will be keyed
|
-- 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
|
-- coordinates. this is to flatten the buffer so that #mod_cache is useful
|
||||||
-- for checking against max_mod_entries.
|
-- for checking against max_mod_entries.
|
||||||
max_mod_entries = 4096
|
max_mod_entries = 4096
|
||||||
|
@ -57,13 +57,23 @@ function init_data()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- x and y are global coords
|
-- 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)
|
function write_map_change(new_sprite, x, y)
|
||||||
local global_x, global_y = calculate_world_pos(x, y)
|
local global_x, global_y = calculate_world_pos(x, y)
|
||||||
if #mod_buffer >= max_mod_entries then
|
if #mod_buffer >= max_mod_entries then
|
||||||
-- todo: make the buffer ring
|
cull_mod_buffer()
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
function calculate_world_pos(x, y)
|
function calculate_world_pos(x, y)
|
||||||
|
|
75
main.lua
75
main.lua
|
@ -4,7 +4,7 @@ function _init()
|
||||||
init_mapgen()
|
init_mapgen()
|
||||||
init_player(32, 32)
|
init_player(32, 32)
|
||||||
generate_map(0, 0)
|
generate_map(0, 0)
|
||||||
debug = false
|
init_debug()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,9 +18,7 @@ function _draw()
|
||||||
-- the screen is 128x128 pixels, so it fits 16x16 sprites
|
-- the screen is 128x128 pixels, so it fits 16x16 sprites
|
||||||
map(camera_pos_x, camera_pos_y, 0, 0, 16, 16)
|
map(camera_pos_x, camera_pos_y, 0, 0, 16, 16)
|
||||||
draw_player()
|
draw_player()
|
||||||
if debug then
|
debug_print()
|
||||||
render_debug_info()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- decide whether we need to regenerate the map.
|
-- decide whether we need to regenerate the map.
|
||||||
|
@ -40,24 +38,71 @@ function out_of_bounds(pos_x, pos_y)
|
||||||
pos_y < 0 or pos_y > 48
|
pos_y < 0 or pos_y > 48
|
||||||
end
|
end
|
||||||
|
|
||||||
function debug_res()
|
-- debug functions toggle debug status displays along the
|
||||||
print("mem: " + stat(0))
|
-- top of the screen
|
||||||
print("cpu: " + stat(1))
|
function init_debug()
|
||||||
print("fps: " .. stat(9) .. " / " .. stat(8))
|
debug_res = false
|
||||||
|
debug_map = false
|
||||||
|
debug_sfx = false
|
||||||
|
debug_mod_buffer = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function debug_sfx()
|
function debug_t(mode)
|
||||||
print("Music pattern: " .. stat(24))
|
if mode == "res" then
|
||||||
|
debug_res = not debug_res
|
||||||
|
elseif mode == "map" then
|
||||||
|
debug_map = not debug_map
|
||||||
|
elseif mode == "sfx" then
|
||||||
|
debug_sfx = not debug_sfx
|
||||||
|
elseif mode == "" then
|
||||||
|
debug_mod_buffer = not debug_mod_buffer
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function debug_map()
|
function debug_print()
|
||||||
print("Local: " .. camera_pos_x .. " " .. camera_pos_y)
|
if debug_res then
|
||||||
print("Global: " .. player_pos_x .. " " .. player_pos_y)
|
debug_print_res()
|
||||||
print(get_biome_name(player_pos_x, player_pos_y))
|
end
|
||||||
|
|
||||||
|
if debug_map then
|
||||||
|
debug_print_map()
|
||||||
|
end
|
||||||
|
|
||||||
|
if debug_sfx then
|
||||||
|
debug_print_sfx()
|
||||||
|
end
|
||||||
|
|
||||||
|
if debug_mod_buffer then
|
||||||
|
debug_print_mod_buffer()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function debug_mod_buffer()
|
function debug_print_res()
|
||||||
|
clip(70, 0, 16, 24)
|
||||||
|
print(stat(0), 70, 0, 15)
|
||||||
|
print(stat(1), 70, 8, 15)
|
||||||
|
print(stat(9) .. " / " .. stat(8), 70, 16, 15)
|
||||||
|
clip()
|
||||||
|
end
|
||||||
|
|
||||||
|
function debug_print_sfx()
|
||||||
|
clip(64, 0, 8, 8)
|
||||||
|
print(stat(24), 64, 0, 15)
|
||||||
|
clip()
|
||||||
|
end
|
||||||
|
|
||||||
|
function debug_print_map()
|
||||||
|
clip(24, 0, 32, 24)
|
||||||
|
print(camera_pos_x .. " " .. camera_pos_y, 24, 0, 15)
|
||||||
|
print(player_pos_x .. " " .. player_pos_y, 24, 8, 15)
|
||||||
|
print(get_biome_name(player_pos_x, player_pos_y), 24, 16, 15)
|
||||||
|
clip()
|
||||||
|
end
|
||||||
|
|
||||||
|
function debug_print_mod_buffer()
|
||||||
|
clip(0, 0, 16, 128)
|
||||||
for k,v in pairs(mod_buffer) do
|
for k,v in pairs(mod_buffer) do
|
||||||
print(k .. ": " .. tostr(v))
|
print(k .. ": " .. tostr(v))
|
||||||
end
|
end
|
||||||
|
clip()
|
||||||
end
|
end
|
||||||
|
|
|
@ -90,7 +90,7 @@ end
|
||||||
-- pos_x and pos_y are global coordinates.
|
-- pos_x and pos_y are global coordinates.
|
||||||
function get_tile(pos_x, pos_y)
|
function get_tile(pos_x, pos_y)
|
||||||
-- lookup changes in the change buffer
|
-- lookup changes in the change buffer
|
||||||
local modded_sprite = mod_buffer[tostr(pos_x) .. "+" .. tostr(pos_y)]
|
local modded_sprite = mod_buffer[get_mod_key(pos_x, pos_y)]
|
||||||
if (modded_sprite) return modded_sprite
|
if (modded_sprite) return modded_sprite
|
||||||
|
|
||||||
local biome_name = get_biome_name(pos_x, pos_y)
|
local biome_name = get_biome_name(pos_x, pos_y)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user