fixed the map generator doing paths that hit the edge which made it look like the map was out of bounds.

main
Zed A. Shaw 10 months ago
parent 194cc6664b
commit 6b4bc6cc11
  1. 3
      lights.cpp
  2. 19
      map.cpp
  3. 2
      map.hpp
  4. 1
      tests/worldbuilder.cpp
  5. 2
      worldbuilder.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});
}

@ -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);
}

@ -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();

@ -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);

@ -152,6 +152,7 @@ void WorldBuilder::generate() {
$map.$walls[it.y][it.x] = is_wall;
}
$map.expand();
$map.load_tiles();
std::array<string, 6> room_types{
@ -164,6 +165,7 @@ void WorldBuilder::generate() {
int room_size = Random::uniform<int>(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) {