From 6b4bc6cc1171023e0f7f380a14c9cd8907d4330f Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 28 Dec 2024 12:37:19 -0500 Subject: [PATCH] fixed the map generator doing paths that hit the edge which made it look like the map was out of bounds. --- lights.cpp | 3 --- map.cpp | 19 +++++++++++++++++++ map.hpp | 2 ++ tests/worldbuilder.cpp | 1 - worldbuilder.cpp | 2 ++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lights.cpp b/lights.cpp index 8abb2c8..c32129b 100644 --- a/lights.cpp +++ b/lights.cpp @@ -8,9 +8,6 @@ namespace lighting { void LightRender::render_square_light(LightSource source, Point at, PointList &has_light) { for(matrix::in_box it{$lightmap, at.x, at.y, (size_t)floor(source.radius)}; it.next();) { if($paths.$paths[it.y][it.x] != WALL_PATH_LIMIT) { - if(it.x == at.x && it.y == at.y) { - println("distance at center: {}", it.distance()); - } $lightmap[it.y][it.x] = light_level(source.strength, it.distance(), it.x, it.y); has_light.push_back({it.x, it.y}); } diff --git a/map.cpp b/map.cpp index 7c3289d..48fa670 100644 --- a/map.cpp +++ b/map.cpp @@ -180,3 +180,22 @@ bool Map::INVARIANT() { void Map::load_tiles() { $tiles.load($walls); } + +void Map::expand() { + // adjust width first + for(auto &row : $walls) { + row.insert(row.begin(), WALL_VALUE); + row.push_back(WALL_VALUE); + } + $width = matrix::width($walls); + + // then add two new rows top/bottom of that new width + $walls.insert($walls.begin(), matrix::Row($width, WALL_VALUE)); + $walls.push_back(matrix::Row($width, WALL_VALUE)); + // now we have the new height + $height = matrix::height($walls); + + // reset the pathing and tiles and done + $paths = Pathing($width, $height); + $tiles = TileMap($width, $height); +} diff --git a/map.hpp b/map.hpp index 72f560b..ac430f5 100644 --- a/map.hpp +++ b/map.hpp @@ -67,6 +67,8 @@ public: 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); + void expand(); + void dump(int show_x=-1, int show_y=-1); bool INVARIANT(); diff --git a/tests/worldbuilder.cpp b/tests/worldbuilder.cpp index 45e60ed..916f60b 100644 --- a/tests/worldbuilder.cpp +++ b/tests/worldbuilder.cpp @@ -23,7 +23,6 @@ TEST_CASE("pathing", "[builder]") { matrix::dump("WALLS", map.$walls, 0,0); println("wall at 0,0=={}", map.$walls[0][0]); - for(matrix::each_cell it{map.$walls}; it.next();) { if(map.$walls[it.y][it.x] == WALL_VALUE) { REQUIRE(map.iswall(it.x, it.y) == true); diff --git a/worldbuilder.cpp b/worldbuilder.cpp index 676bd77..869ece9 100644 --- a/worldbuilder.cpp +++ b/worldbuilder.cpp @@ -152,6 +152,7 @@ void WorldBuilder::generate() { $map.$walls[it.y][it.x] = is_wall; } + $map.expand(); $map.load_tiles(); std::array room_types{ @@ -164,6 +165,7 @@ void WorldBuilder::generate() { int room_size = Random::uniform(100, 800); stylize_room(i, room_types[room_type], room_size * 0.01f); } + } void WorldBuilder::make_room(size_t origin_x, size_t origin_y, size_t w, size_t h) {