From d0d62836e3190448c3bc18d336ffc8acef66cade Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 29 Nov 2024 11:24:23 -0500 Subject: [PATCH] Now have good coverage on map but need to actually confirm results in the test. --- Makefile | 2 +- map.cpp | 8 ++++---- map.hpp | 2 +- status.txt | 2 ++ tests/map.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 61 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index bc3ef5a..736e35d 100644 --- a/Makefile +++ b/Makefile @@ -30,4 +30,4 @@ debug: gdb --nx -x .gdbinit builddir/roguish.exe cover: - gcovr --html coverage/coverage_report.html --gcov-ignore-errors=no_working_dir_found --exclude "scratchpad.*" --exclude "subprojects.*" --html-nested coverage/ + gcovr --html coverage/index.html --gcov-ignore-errors=no_working_dir_found --exclude "scratchpad.*" --exclude "subprojects.*" --html-nested coverage/ diff --git a/map.cpp b/map.cpp index 2ab5302..4357f09 100644 --- a/map.cpp +++ b/map.cpp @@ -295,10 +295,6 @@ void Map::set_target(const Point &at, int value) { $input_map[at.y][at.x] = 0; } -void Map::clear_light_target(const Point &at) { - $input_map[at.y][at.x] = 1; -} - void Map::clear_target(const Point &at) { $input_map[at.y][at.x] = 1; } @@ -386,6 +382,10 @@ void Map::reset_light() { } } +void Map::clear_light_target(const Point &at) { + $input_map[at.y][at.x] = 1; +} + void Map::set_light_target(const Point &at, int value) { set_target(at, value); } diff --git a/map.hpp b/map.hpp index 87e39be..378efb9 100644 --- a/map.hpp +++ b/map.hpp @@ -69,6 +69,7 @@ public: void add_door(Room &room); bool can_move(Point move_to); void generate(); + void set_door(Room &room, int value); void place_rooms(Room &root); Point place_entity(size_t room_index); @@ -79,7 +80,6 @@ public: void set_target(const Point &at, int value=0); void clear_target(const Point &at); bool walk(Point &src, Point &target); - void set_door(Room &room, int value); Point map_to_camera(const Point &loc, const Point &cam_orig); Point center_camera(const Point &around, size_t view_x, size_t view_y); diff --git a/status.txt b/status.txt index 4ac69b2..64babc6 100644 --- a/status.txt +++ b/status.txt @@ -7,6 +7,8 @@ TODAY'S GOAL: * Doxygen? Other docs tool? TODO: +* I can do headless windows in renderer for testing. + - renderer.$window.setVisible(false); * Think up an enemy system. * Revisit map generation. * Write a method for renderer that can translate coordinates. diff --git a/tests/map.cpp b/tests/map.cpp index 4f2674b..f04747d 100644 --- a/tests/map.cpp +++ b/tests/map.cpp @@ -36,6 +36,58 @@ TEST_CASE("dijkstra algo test", "[map]") { } TEST_CASE("bsp algo test", "[map]") { - Map map(50, 20); + Map map(20, 20); map.generate(); } + +TEST_CASE("dumping and debugging", "[map]") { + Map map(20, 20); + map.generate(); + + dump_map("GENERATED", map.paths()); + map.dump(); +} + +TEST_CASE("lighting test", "[map]") { + Map map(20,20); + map.generate(); + Point light1 = map.place_entity(0); + Point light2 = map.place_entity(1); + LightSource source1{7,1}; + LightSource source2{3,2}; + + map.reset_light(); + + map.set_light_target(light1); + map.set_light_target(light2); + + map.path_light(); + + map.render_light(source1, light1); + map.render_light(source2, light2); + + map.clear_light_target(light1); + map.clear_light_target(light2); +} + +TEST_CASE("camera control", "[map]") { + Map map(20,20); + map.generate(); + + Point center = map.center_camera({10,10}, 5, 5); + + REQUIRE(center.x == 8); + REQUIRE(center.y == 8); + + Point translation = map.map_to_camera({10,10}, center); + + REQUIRE(translation.x == 2); + REQUIRE(translation.y == 2); +} + +TEST_CASE("pathing", "[map]") { + Map map(20,20); + map.generate(); + REQUIRE(map.can_move({0,0}) == false); + REQUIRE(map.iswall(0,0) == true); +}