diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-07 22:17:12 +0200 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-10-07 22:21:14 +0200 |
commit | 0b21b9fcf0a01574cf1be84dd9900e32d95a1e79 (patch) | |
tree | 6c5258d598068ab30cb9446555430113b9a573e8 /crawl-ref/source/test | |
parent | ed0614af8d97a0ffd10f6d55017ca0ee8f6c5175 (diff) | |
download | crawl-ref-0b21b9fcf0a01574cf1be84dd9900e32d95a1e79.tar.gz crawl-ref-0b21b9fcf0a01574cf1be84dd9900e32d95a1e79.zip |
Add test to compare LOS against sample maps.
New test cases can be added by adding appropriate maps to
debug-los.des.
Also separate the LOS tests into three separate files.
Diffstat (limited to 'crawl-ref/source/test')
-rw-r--r-- | crawl-ref/source/test/los_gsg.lua | 58 | ||||
-rw-r--r-- | crawl-ref/source/test/los_maps.lua | 56 | ||||
-rw-r--r-- | crawl-ref/source/test/los_symm.lua (renamed from crawl-ref/source/test/los.lua) | 44 |
3 files changed, 114 insertions, 44 deletions
diff --git a/crawl-ref/source/test/los_gsg.lua b/crawl-ref/source/test/los_gsg.lua new file mode 100644 index 0000000000..69b86d1da7 --- /dev/null +++ b/crawl-ref/source/test/los_gsg.lua @@ -0,0 +1,58 @@ +-- Vet LOS for symmetry. + +local FAILMAP = 'losfail.map' +local checks = 0 + +local function test_gridseegrid_symmetry() + -- Clear messages to prevent them accumulating and forcing a --more-- + crawl.mesclr() + -- Send the player to a random spot on the level. + you.random_teleport() + + checks = checks + 1 + local you_x, you_y = you.pos() + + for y = -9, 9 do + for x = -9, 9 do + local px, py = x + you_x, y + you_y + if (x ~= 0 or y ~= 0) and dgn.in_bounds(px, py) then + local foreward = dgn.grid_see_grid(you_x, you_y, px, py) + local backward = dgn.grid_see_grid(px, py, you_x, you_y) + this_p = dgn.point(you_x, you_y) + other_p = dgn.point(px, py) + if not forward then + you.moveto(px, py) + local temp = this_p + this_p = other_p + other_p = temp + end + if forward ~= backward then + dgn.grid(other_p.x, other_p.y, "floor_special") + dgn.dbg_dump_map(FAILMAP) + assert(false, + "grid_see_grid asymmetry detected (iter #" .. checks .. "): " + .. this_p .. " sees " .. other_p .. ", but not vice versa." + .. " Map saved to " .. FAILMAP) + end + end + end + end +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) + + for lev_i = 1, nlevels do + dgn.dbg_flush_map_memory() + dgn.dbg_generate_level() + for t_i = 1, tests_per_level do + test_gridseegrid_symmetry() + end + end +end + +for depth = 1, 27 do + run_los_tests(depth, 1, 10) +end diff --git a/crawl-ref/source/test/los_maps.lua b/crawl-ref/source/test/los_maps.lua new file mode 100644 index 0000000000..769cd251ec --- /dev/null +++ b/crawl-ref/source/test/los_maps.lua @@ -0,0 +1,56 @@ +-- check LOS according to pre-defined maps + +local checks = 0 + +-- visible: +local rock_wall = dgn.find_feature_number("rock_wall") +local floor = dgn.find_feature_number("floor") +-- invisible (not needed): +local stone_wall = dgn.find_feature_number("stone_wall") +local water = dgn.find_feature_number("deep_water") + +local function test_los_map(map) + crawl.mesclr() + -- choose random debug map; better choose all + dgn.tags(map, "no_rotate no_vmirror no_hmirror no_pool_fixup") + local name = dgn.name(map) + -- local width, height = dgn.mapsize(map) -- returns (0,0) + local function place_map() + return dgn.place_map(map, true, true) + end + dgn.with_map_anchors(30, 30, place_map) + you.moveto(30, 30) + you.losight() + crawl.redraw_view() + for x = 0, 9 do + for y = 0, 9 do + local xa = 30 + x + local ya = 30 + y + local p = dgn.point(x, y) + local should_see = ((x == 0 and y == 0) or + dgn.grid(xa, ya) == rock_wall or + dgn.grid(xa, ya) == floor) + local can_see = you.see_grid(xa, ya) + if can_see and (not should_see) then + assert(false, "los error in " .. name .."(iter #" .. checks .. + "): can see " .. p .. " but shouldn't.") + elseif (not can_see) and should_see then + assert(false, "los error in " .. name .. "(iter #" .. checks .. + "): should see " .. p .. " but can't.") + end + end + end +end + +local function test_los_maps() + dgn.load_des_file("debug-los.des") + local map = dgn.map_by_tag("debug_los") + while map do + test_los_map(map) + checks = checks + 1 + map = dgn.map_by_tag("debug_los") + end +end + +test_los_maps() + diff --git a/crawl-ref/source/test/los.lua b/crawl-ref/source/test/los_symm.lua index 8feb0bc7f4..beb809beee 100644 --- a/crawl-ref/source/test/los.lua +++ b/crawl-ref/source/test/los_symm.lua @@ -48,42 +48,6 @@ local function test_losight_symmetry() end end -local function test_gridseegrid_symmetry() - -- Clear messages to prevent them accumulating and forcing a --more-- - crawl.mesclr() - -- Send the player to a random spot on the level. - you.random_teleport() - - checks = checks + 1 - local you_x, you_y = you.pos() - - for y = -9, 9 do - for x = -9, 9 do - local px, py = x + you_x, y + you_y - if (x ~= 0 or y ~= 0) and dgn.in_bounds(px, py) then - local foreward = dgn.grid_see_grid(you_x, you_y, px, py) - local backward = dgn.grid_see_grid(px, py, you_x, you_y) - this_p = dgn.point(you_x, you_y) - other_p = dgn.point(px, py) - if not forward then - you.moveto(px, py) - local temp = this_p - this_p = other_p - other_p = temp - end - if forward ~= backward then - dgn.grid(other_p.x, other_p.y, "floor_special") - dgn.dbg_dump_map(FAILMAP) - assert(false, - "grid_see_grid asymmetry detected (iter #" .. checks .. "): " - .. this_p .. " sees " .. other_p .. ", but not vice versa." - .. " Map saved to " .. FAILMAP) - end - end - end - end -end - local function run_los_tests(depth, nlevels, tests_per_level) local place = "D:" .. depth crawl.mpr("Running LOS tests on " .. place) @@ -96,14 +60,6 @@ local function run_los_tests(depth, nlevels, tests_per_level) test_losight_symmetry() end end - - for lev_i = 1, nlevels do - dgn.dbg_flush_map_memory() - dgn.dbg_generate_level() - for t_i = 1, tests_per_level do - test_gridseegrid_symmetry() - end - end end for depth = 1, 27 do |