diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-20 11:19:41 +0200 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-10-20 11:19:41 +0200 |
commit | e4018b3ebf7d7e14787a04420014acf581d69978 (patch) | |
tree | 743aeabfc897ac9eac50334aefdd55254173a2d9 | |
parent | b00943ff50ceecafa35b13e6286f04b4e4e30070 (diff) | |
download | crawl-ref-e4018b3ebf7d7e14787a04420014acf581d69978.tar.gz crawl-ref-e4018b3ebf7d7e14787a04420014acf581d69978.zip |
Split debug lua bindings out to new library "debug".
-rw-r--r-- | crawl-ref/source/dlua.cc | 3 | ||||
-rw-r--r-- | crawl-ref/source/l_debug.cc | 82 | ||||
-rw-r--r-- | crawl-ref/source/l_dgn.cc | 66 | ||||
-rw-r--r-- | crawl-ref/source/l_libs.h | 1 | ||||
-rw-r--r-- | crawl-ref/source/makefile.obj | 1 | ||||
-rw-r--r-- | crawl-ref/source/test/findray.lua | 10 | ||||
-rw-r--r-- | crawl-ref/source/test/los_csc.lua | 8 | ||||
-rw-r--r-- | crawl-ref/source/test/los_symm.lua | 8 |
8 files changed, 99 insertions, 80 deletions
diff --git a/crawl-ref/source/dlua.cc b/crawl-ref/source/dlua.cc index c5a2b04bb2..4461a99748 100644 --- a/crawl-ref/source/dlua.cc +++ b/crawl-ref/source/dlua.cc @@ -314,8 +314,9 @@ void init_dungeon_lua() luaL_openlib(dlua, "dgn", dgn_level_lib, 0); luaL_openlib(dlua, "dgn", dgn_mons_lib, 0); luaL_openlib(dlua, "dgn", dgn_tile_lib, 0); - // Add additional function to the Crawl module. + luaL_openlib(dlua, "crawl", crawl_lib, 0); + luaL_openlib(dlua, "debug", debug_lib, 0); luaL_openlib(dlua, "file", file_lib, 0); luaL_openlib(dlua, "you", you_lib, 0); luaL_openlib(dlua, "los", los_lib, 0); diff --git a/crawl-ref/source/l_debug.cc b/crawl-ref/source/l_debug.cc new file mode 100644 index 0000000000..4a52860822 --- /dev/null +++ b/crawl-ref/source/l_debug.cc @@ -0,0 +1,82 @@ +/* + * File: l_debug.cc + * Summary: Various debugging bindings. + */ + +#include "AppHdr.h" + +#include "dlua.h" +#include "l_libs.h" + +#include "chardump.h" +#include "dungeon.h" +#include "message.h" +#include "place.h" + +// WARNING: This is a very low-level call. +LUAFN(debug_goto_place) +{ + try + { + const level_id id = level_id::parse_level_id(luaL_checkstring(ls, 1)); + you.level_type = id.level_type; + if (id.level_type == LEVEL_DUNGEON) + { + you.where_are_you = static_cast<branch_type>(id.branch); + you.your_level = absdungeon_depth(id.branch, id.depth); + } + } + catch (const std::string &err) + { + luaL_error(ls, err.c_str()); + } + return (0); +} + +LUAFN(debug_flush_map_memory) +{ + dgn_flush_map_memory(); + init_level_connectivity(); + return (0); +} + +LUAFN(debug_generate_level) +{ + no_messages mx; + env.show.init(0); + env.map.init(map_cell()); +#ifdef USE_TILE + tile_init_default_flavour(); + tile_clear_flavour(); + TileNewLevel(true); +#endif + builder(you.your_level, you.level_type); + return (0); +} + +LUAFN(debug_dump_map) +{ + const int pos = lua_isuserdata(ls, 1) ? 2 : 1; + if (lua_isstring(ls, pos)) + dump_map(lua_tostring(ls, pos), true); + return (0); +} + +LUAFN(_debug_test_explore) +{ +#ifdef WIZARD + debug_test_explore(); +#endif + return (0); +} + +const struct luaL_reg debug_lib[] = +{ +{ "goto_place", debug_goto_place }, +{ "flush_map_memory", debug_flush_map_memory }, +{ "generate_level", debug_generate_level }, +{ "dump_map", debug_dump_map }, +{ "test_explore", _debug_test_explore }, + +{ NULL, NULL } +}; diff --git a/crawl-ref/source/l_dgn.cc b/crawl-ref/source/l_dgn.cc index fc34cee72c..3555c541b8 100644 --- a/crawl-ref/source/l_dgn.cc +++ b/crawl-ref/source/l_dgn.cc @@ -6,13 +6,10 @@ #include <cmath> #include "branch.h" -#include "chardump.h" #include "cloud.h" #include "initfile.h" #include "mapmark.h" #include "maps.h" -#include "message.h" -#include "place.h" #include "spl-util.h" #include "view.h" @@ -100,47 +97,6 @@ static int dgn_depth(lua_State *ls) return dgn_depth_proc(ls, map->depths, 2); } -// WARNING: This is a very low-level call. -LUAFN(dgn_dbg_goto_place) -{ - try - { - const level_id id = level_id::parse_level_id(luaL_checkstring(ls, 1)); - you.level_type = id.level_type; - if (id.level_type == LEVEL_DUNGEON) - { - you.where_are_you = static_cast<branch_type>(id.branch); - you.your_level = absdungeon_depth(id.branch, id.depth); - } - } - catch (const std::string &err) - { - luaL_error(ls, err.c_str()); - } - return (0); -} - -LUAFN(dgn_dbg_flush_map_memory) -{ - dgn_flush_map_memory(); - init_level_connectivity(); - return (0); -} - -LUAFN(dgn_dbg_generate_level) -{ - no_messages mx; - env.show.init(0); - env.map.init(map_cell()); -#ifdef USE_TILE - tile_init_default_flavour(); - tile_clear_flavour(); - TileNewLevel(true); -#endif - builder(you.your_level, you.level_type); - return (0); -} - static int dgn_place(lua_State *ls) { MAP(ls, 1, map); @@ -1533,32 +1489,10 @@ LUAFN(_dgn_reuse_map) return (0); } -LUAFN(dgn_dbg_dump_map) -{ - const int pos = lua_isuserdata(ls, 1) ? 2 : 1; - if (lua_isstring(ls, pos)) - dump_map(lua_tostring(ls, pos), true); - return (0); -} - -LUAFN(dgn_dbg_test_explore) -{ -#ifdef WIZARD - debug_test_explore(); -#endif - return (0); -} - LUAWRAP(_dgn_reset_level, dgn_reset_level()) const struct luaL_reg dgn_lib[] = { -{ "dbg_goto_place", dgn_dbg_goto_place }, -{ "dbg_flush_map_memory", dgn_dbg_flush_map_memory }, -{ "dbg_generate_level", dgn_dbg_generate_level }, -{ "dbg_dump_map", dgn_dbg_dump_map }, -{ "dbg_test_explore", dgn_dbg_test_explore }, - { "reset_level", _dgn_reset_level }, { "default_depth", dgn_default_depth }, diff --git a/crawl-ref/source/l_libs.h b/crawl-ref/source/l_libs.h index 7b1b60ad89..aca91d8699 100644 --- a/crawl-ref/source/l_libs.h +++ b/crawl-ref/source/l_libs.h @@ -13,6 +13,7 @@ */ extern const struct luaL_reg crawl_lib[]; +extern const struct luaL_reg debug_lib[]; extern const struct luaL_reg dgn_lib[]; extern const struct luaL_reg dgn_build_lib[]; extern const struct luaL_reg dgn_event_lib[]; diff --git a/crawl-ref/source/makefile.obj b/crawl-ref/source/makefile.obj index 021d731015..f7fc638b3a 100644 --- a/crawl-ref/source/makefile.obj +++ b/crawl-ref/source/makefile.obj @@ -39,6 +39,7 @@ items.o \ lev-pand.o \ libutil.o \ l_crawl.o \ +l_debug.o \ l_dgn.o \ l_dgnbld.o \ l_dgnevt.o \ diff --git a/crawl-ref/source/test/findray.lua b/crawl-ref/source/test/findray.lua index 1b0248494b..9f66461d4e 100644 --- a/crawl-ref/source/test/findray.lua +++ b/crawl-ref/source/test/findray.lua @@ -36,7 +36,7 @@ local function test_findray() local ray = los.findray(you_x, you_y, x, y) if not ray then dgn.grid(x, y, "floor_special") - dgn.dbg_dump_map(FAILMAP) + debug.dump_map(FAILMAP) assert(false, "Can't find ray to " .. p .. " although it's in unobstructed view. (#" .. checks .. ")") @@ -52,7 +52,7 @@ local function test_findray() while(ray_p ~= p) do if dgn.is_opaque(rx, ry) then dgn.grid(x, y, "floor_special") - dgn.dbg_dump_map(FAILMAP) + debug.dump_map(FAILMAP) assert(false, "Ray from " .. you_p .. " to " .. p .. " passes through opaque cell " .. ray_p @@ -68,11 +68,11 @@ end local function run_findray_tests(depth, nlevels, tests_per_level) local place = "D:" .. depth crawl.mpr("Running find_ray tests on " .. place) - dgn.dbg_goto_place(place) + debug.goto_place(place) for lev_i = 1, nlevels do - dgn.dbg_flush_map_memory() - dgn.dbg_generate_level() + debug.flush_map_memory() + debug.generate_level() for t_i = 1, tests_per_level do test_findray() end diff --git a/crawl-ref/source/test/los_csc.lua b/crawl-ref/source/test/los_csc.lua index b54d251d8f..04a1ac2aeb 100644 --- a/crawl-ref/source/test/los_csc.lua +++ b/crawl-ref/source/test/los_csc.lua @@ -30,7 +30,7 @@ local function test_cellseecell_symmetry() end if (forward and backward) or (not forward and not backward) then dgn.grid(other_p.x, other_p.y, "floor_special") - dgn.dbg_dump_map(FAILMAP) + debug.dump_map(FAILMAP) assert(false, "cell_see_cell asymmetry detected (iter #" .. checks .. "): " .. this_p .. " sees " .. other_p .. ", but not vice versa." @@ -44,11 +44,11 @@ end local function run_los_tests(depth, nlevels, tests_per_level) local place = "D:" .. depth crawl.mpr("Running LOS tests on " .. place) - dgn.dbg_goto_place(place) + debug.goto_place(place) for lev_i = 1, nlevels do - dgn.dbg_flush_map_memory() - dgn.dbg_generate_level() + debug.flush_map_memory() + debug.generate_level() for t_i = 1, tests_per_level do test_cellseecell_symmetry() end diff --git a/crawl-ref/source/test/los_symm.lua b/crawl-ref/source/test/los_symm.lua index eac1db7577..400c4a2356 100644 --- a/crawl-ref/source/test/los_symm.lua +++ b/crawl-ref/source/test/los_symm.lua @@ -39,7 +39,7 @@ local function test_losight_symmetry() local this_p = dgn.point(x, y) local you_p = dgn.point(you_x, you_y) dgn.grid(you_x, you_y, "floor_special") - dgn.dbg_dump_map(FAILMAP) + debug.dump_map(FAILMAP) assert(false, "LOS asymmetry detected (iter #" .. checks .. "): " .. you_p .. " sees " .. this_p .. ", but not vice versa." .. @@ -51,11 +51,11 @@ end local function run_los_tests(depth, nlevels, tests_per_level) local place = "D:" .. depth crawl.mpr("Running LOS tests on " .. place) - dgn.dbg_goto_place(place) + debug.goto_place(place) for lev_i = 1, nlevels do - dgn.dbg_flush_map_memory() - dgn.dbg_generate_level() + debug.flush_map_memory() + debug.generate_level() for t_i = 1, tests_per_level do test_losight_symmetry() end |