Slightly better parition and map_drawing.

main
Zed A. Shaw 1 week ago
parent 44f11d5ddd
commit a37a40d45f
  1. 85
      map.cpp
  2. 8
      map.hpp

@ -117,88 +117,46 @@ inline int make_split(std::mt19937 &gen, Room &cur, bool horiz) {
} }
void Map::partition_map(std::mt19937 &gen, Room &cur, int depth) { void Map::partition_map(std::mt19937 &gen, Room &cur, int depth) {
println(">>>> DEPTH: {}", depth);
if(cur.width >= 5 && cur.width <= 10 &&
cur.height >= 5 && cur.height <= 10) {
m_rooms.push_back(cur);
return;
}
std::uniform_int_distribution<int> rsplit(0, 1); std::uniform_int_distribution<int> rsplit(0, 1);
bool horiz = cur.width > cur.height ? false : true; bool horiz = cur.width > cur.height ? false : true;
int split = make_split(gen, cur, horiz); int split = make_split(gen, cur, horiz);
Room left; Room left = cur;
Room right; Room right = cur;
if(horiz) { if(horiz) {
println("HORIZ split={}, x={}, y={}, w={}, h={}",
split, cur.x, cur.y, cur.width, cur.height);
dbc::check(split > 0, "split is not > 0"); dbc::check(split > 0, "split is not > 0");
dbc::check(split < int(cur.height), "split is too big!"); dbc::check(split < int(cur.height), "split is too big!");
left.height = size_t(split - 1);
left = { right.y = cur.y + split;
.x = cur.x, right.height = size_t(cur.height - split);
.y = cur.y,
.width = cur.width,
.height = size_t(split - 1)
};
right = {
.x = cur.x,
.y = cur.y + split,
.width = cur.width,
.height = size_t(cur.height - split)
};
} else { } else {
println("VERT split={}, x={}, y={}, w={}, h={}", split, cur.x, cur.y, cur.width, cur.height);
dbc::check(split > 0, "split is not > 0"); dbc::check(split > 0, "split is not > 0");
dbc::check(split < int(cur.width), "split is too big!"); dbc::check(split < int(cur.width), "split is too big!");
left = { left.width = size_t(split-1);
.x = cur.x, right.x = cur.x + split,
.y = cur.y, right.width = size_t(cur.width - split);
.width = size_t(split-1),
.height = cur.height
};
right = {
.x = cur.x + split,
.y = cur.y,
.width = size_t(cur.width - split),
.height = cur.height
};
} }
if(depth > 0 && left.width > 4 && left.height > 4) { if(depth > 0 && left.width > 5 && left.height > 5) {
println("DOWN LEFT h={}, w={}", left.height, left.width);
partition_map(gen, left, depth-1); partition_map(gen, left, depth-1);
cur.next.push_back(left);
} else {
println("!!!!LEAF LEFT ROOM h={}, w={}", left.height, left.width);
} }
if(depth > 0 && right.width >= 4 && right.height >= 4) { if(depth > 0 && right.width > 5 && right.height > 5) {
println("DOWN RIGHT h={}, w={}", right.height, right.width);
partition_map(gen, right, depth-1); partition_map(gen, right, depth-1);
cur.next.push_back(right);
} else {
println("!!!!LEAF RIGHT ROOM h={}, w={}", right.height, right.width);
} }
} }
void Map::draw_map(Room &cur) { void Map::draw_map(Room &cur) {
if(cur.x + cur.width <= width() for(auto cur : m_rooms) {
&& cur.y + cur.height <= height())
{
println("CUR NEXT SIZE: {}", cur.next.size());
if(cur.next.size() == 1) {
draw_map(cur.next[0]); // left
} else if(cur.next.size() == 2) {
draw_map(cur.next[0]); // left
draw_map(cur.next[1]); // right
} else {
println("LEAF NODE NO CHILDREN x={}, y={}, w={}, h={}", cur.x, cur.y, cur.width, cur.height);
make_room(cur.x+1, cur.y+1, cur.width-2, cur.height-2); make_room(cur.x+1, cur.y+1, cur.width-2, cur.height-2);
}
} else {
println("ABORT in draw_map, x={}, y={}, w={}, h={}, map.w={}, map.h={}",
cur.x, cur.y, cur.width, cur.height, width(), height());
} }
} }
@ -216,3 +174,10 @@ void Map::generate() {
partition_map(gen, root, 6); partition_map(gen, root, 6);
draw_map(root); // left draw_map(root); // left
} }
void Map::dump() {
dump_map("PATHS", m_paths);
dump_map("WALLS", m_walls);
dump_map("INPUT", m_input_map);
}

@ -31,6 +31,7 @@ class Map {
Matrix m_input_map; Matrix m_input_map;
Matrix m_walls; Matrix m_walls;
Matrix m_paths; Matrix m_paths;
std::vector<Room> m_rooms;
int m_limit = 0; int m_limit = 0;
public: public:
@ -59,10 +60,5 @@ public:
void draw_map(Room &root); void draw_map(Room &root);
void make_paths(); void make_paths();
void partition_map(std::mt19937 &gen, Room &cur, int depth); void partition_map(std::mt19937 &gen, Room &cur, int depth);
void dump();
void dump() {
dump_map("PATHS", m_paths);
dump_map("WALLS", m_walls);
dump_map("INPUT", m_input_map);
}
}; };

Loading…
Cancel
Save