Slightly better parition and map_drawing.
This commit is contained in:
parent
44f11d5ddd
commit
a37a40d45f
2 changed files with 27 additions and 66 deletions
85
map.cpp
85
map.cpp
|
@ -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) {
|
||||
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);
|
||||
bool horiz = cur.width > cur.height ? false : true;
|
||||
int split = make_split(gen, cur, horiz);
|
||||
Room left;
|
||||
Room right;
|
||||
Room left = cur;
|
||||
Room right = cur;
|
||||
|
||||
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 < int(cur.height), "split is too big!");
|
||||
|
||||
left = {
|
||||
.x = cur.x,
|
||||
.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)
|
||||
};
|
||||
left.height = size_t(split - 1);
|
||||
right.y = cur.y + split;
|
||||
right.height = size_t(cur.height - split);
|
||||
} 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 < int(cur.width), "split is too big!");
|
||||
|
||||
left = {
|
||||
.x = cur.x,
|
||||
.y = cur.y,
|
||||
.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
|
||||
};
|
||||
left.width = size_t(split-1);
|
||||
right.x = cur.x + split,
|
||||
right.width = size_t(cur.width - split);
|
||||
}
|
||||
|
||||
if(depth > 0 && left.width > 4 && left.height > 4) {
|
||||
println("DOWN LEFT h={}, w={}", left.height, left.width);
|
||||
if(depth > 0 && left.width > 5 && left.height > 5) {
|
||||
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) {
|
||||
println("DOWN RIGHT h={}, w={}", right.height, right.width);
|
||||
if(depth > 0 && right.width > 5 && right.height > 5) {
|
||||
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) {
|
||||
if(cur.x + cur.width <= width()
|
||||
&& 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);
|
||||
for(auto cur : m_rooms) {
|
||||
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);
|
||||
draw_map(root); // left
|
||||
}
|
||||
|
||||
|
||||
void Map::dump() {
|
||||
dump_map("PATHS", m_paths);
|
||||
dump_map("WALLS", m_walls);
|
||||
dump_map("INPUT", m_input_map);
|
||||
}
|
||||
|
|
8
map.hpp
8
map.hpp
|
@ -31,6 +31,7 @@ class Map {
|
|||
Matrix m_input_map;
|
||||
Matrix m_walls;
|
||||
Matrix m_paths;
|
||||
std::vector<Room> m_rooms;
|
||||
int m_limit = 0;
|
||||
public:
|
||||
|
||||
|
@ -59,10 +60,5 @@ public:
|
|||
void draw_map(Room &root);
|
||||
void make_paths();
|
||||
void partition_map(std::mt19937 &gen, Room &cur, int depth);
|
||||
|
||||
void dump() {
|
||||
dump_map("PATHS", m_paths);
|
||||
dump_map("WALLS", m_walls);
|
||||
dump_map("INPUT", m_input_map);
|
||||
}
|
||||
void dump();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue