|
|
|
@ -93,8 +93,8 @@ void Map::make_room(size_t origin_x, size_t origin_y, size_t w, size_t h) { |
|
|
|
|
println("MAKE ROOM x={}, y={}, w={}, h={}", origin_x, origin_y, w, h); |
|
|
|
|
dbc::pre("x out of bounds", origin_x < width()); |
|
|
|
|
dbc::pre("y out of bounds", origin_y < height()); |
|
|
|
|
dbc::pre("w out of bounds", w < width()); |
|
|
|
|
dbc::pre("h out of bounds", h < height()); |
|
|
|
|
dbc::pre("w out of bounds", w <= width()); |
|
|
|
|
dbc::pre("h out of bounds", h <= height()); |
|
|
|
|
|
|
|
|
|
for(size_t y = origin_y; y < origin_y + h; ++y) { |
|
|
|
|
dbc::check(y < m_walls.size(), "y is out of bounds"); |
|
|
|
@ -117,28 +117,18 @@ struct Partition { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
inline int make_split(std::mt19937 &gen, Partition &cur, bool horiz) { |
|
|
|
|
if(horiz) { |
|
|
|
|
println("MAKE SPLIT HORIZ, y={}, y+h={}, h={}", |
|
|
|
|
cur.y, cur.y + cur.height, cur.height); |
|
|
|
|
|
|
|
|
|
size_t quarter = cur.height / 4; |
|
|
|
|
// vertical split, pick a random horizontal location
|
|
|
|
|
std::uniform_int_distribution<int> rhoriz(cur.y + quarter, cur.y + cur.height - quarter); |
|
|
|
|
|
|
|
|
|
return rhoriz(gen); |
|
|
|
|
} else { |
|
|
|
|
// horizontal split, pick a random vertical location
|
|
|
|
|
println("MAKE SPLIT VERT, x={}, x+w={}, w={}", |
|
|
|
|
cur.x, cur.x + cur.width, cur.width); |
|
|
|
|
|
|
|
|
|
size_t quarter = cur.width / 4; |
|
|
|
|
std::uniform_int_distribution<int> rvert(cur.x + quarter, cur.x + cur.width - quarter); |
|
|
|
|
return rvert(gen); |
|
|
|
|
} |
|
|
|
|
println("MAKE SPLIT horiz={}, y={}, w={}, h={}", horiz, |
|
|
|
|
cur.y, cur.width, cur.height); |
|
|
|
|
size_t dimension = horiz ? cur.height : cur.width; |
|
|
|
|
int min = dimension / 4; // 25% of the dimension
|
|
|
|
|
int max = dimension - min; // 25% off the other side
|
|
|
|
|
println("dimension={}, min={}, max={}", dimension, min, max); |
|
|
|
|
std::uniform_int_distribution<int> rand_dim(min, max); |
|
|
|
|
return rand_dim(gen); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void partition_map(std::mt19937 &gen, Partition &cur, int depth) { |
|
|
|
|
|
|
|
|
|
println(">>>> DEPTH: {}", depth); |
|
|
|
|
std::uniform_int_distribution<int> rsplit(0, 1); |
|
|
|
|
bool horiz = rsplit(gen); |
|
|
|
|
int split = make_split(gen, cur, horiz); |
|
|
|
@ -150,7 +140,7 @@ void partition_map(std::mt19937 &gen, Partition &cur, int depth) { |
|
|
|
|
split, cur.x, cur.y, cur.width, cur.height); |
|
|
|
|
|
|
|
|
|
dbc::check(split > 0, "split is not > 0"); |
|
|
|
|
dbc::check(split < int(cur.y + cur.height), "split is too big!"); |
|
|
|
|
dbc::check(split < int(cur.height), "split is too big!"); |
|
|
|
|
|
|
|
|
|
left = { |
|
|
|
|
.x = cur.x, |
|
|
|
@ -163,13 +153,13 @@ void partition_map(std::mt19937 &gen, Partition &cur, int depth) { |
|
|
|
|
.x = cur.x, |
|
|
|
|
.y = cur.y + split, |
|
|
|
|
.width = cur.width, |
|
|
|
|
.height = size_t(cur.y + cur.height - split) |
|
|
|
|
.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.x + cur.width), "split is too big!"); |
|
|
|
|
dbc::check(split < int(cur.width), "split is too big!"); |
|
|
|
|
|
|
|
|
|
left = { |
|
|
|
|
.x = cur.x, |
|
|
|
@ -186,31 +176,28 @@ void partition_map(std::mt19937 &gen, Partition &cur, int depth) { |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
println("CUR NEXT SIZE={}", cur.next.size()); |
|
|
|
|
|
|
|
|
|
if(depth > 0 && left.width > 10 && left.height > 10) { |
|
|
|
|
if(depth > 0 && left.width > 5 && left.height > 5) { |
|
|
|
|
println("### LEFT h={}, w={}", left.width, left.height); |
|
|
|
|
partition_map(gen, left, depth-1); |
|
|
|
|
cur.next.push_back(left); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(depth > 0 && right.width > 10 && right.height > 10) { |
|
|
|
|
if(depth > 0 && right.width > 5 && right.height > 5) { |
|
|
|
|
println("### RIGHT h={}, w={}", right.width, right.height); |
|
|
|
|
partition_map(gen, right, depth-1); |
|
|
|
|
cur.next.push_back(right); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
println("PUSH CHILD!"); |
|
|
|
|
cur.next.push_back(left); |
|
|
|
|
println("PUSH CHILD!"); |
|
|
|
|
cur.next.push_back(right); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void draw_map(Map *map, Partition &root, Partition &cur) { |
|
|
|
|
void draw_map(Map *map, Partition &cur) { |
|
|
|
|
if(cur.x + cur.width <= map->width() |
|
|
|
|
&& cur.y + cur.height <= map->height()) |
|
|
|
|
{ |
|
|
|
|
map->make_room(cur.x, cur.y, cur.width, cur.height); |
|
|
|
|
|
|
|
|
|
if(cur.next.size() == 2) { |
|
|
|
|
draw_map(map, root, cur.next[0]); // left
|
|
|
|
|
draw_map(map, root, cur.next[1]); // right
|
|
|
|
|
draw_map(map, cur.next[0]); // left
|
|
|
|
|
draw_map(map, cur.next[1]); // right
|
|
|
|
|
} else { |
|
|
|
|
println("LEAF NODE NO CHILDREN"); |
|
|
|
|
} |
|
|
|
@ -225,15 +212,12 @@ void Map::generate() { |
|
|
|
|
std::mt19937 gen(rd()); |
|
|
|
|
|
|
|
|
|
Partition root{ |
|
|
|
|
.x = 1, |
|
|
|
|
.y = 1, |
|
|
|
|
.width = width() - 2, |
|
|
|
|
.height = height() - 2 |
|
|
|
|
.x = 0, |
|
|
|
|
.y = 0, |
|
|
|
|
.width = width(), |
|
|
|
|
.height = height() |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
partition_map(gen, root, 3); |
|
|
|
|
println("ROOT LEFT HAS {} CHILD", root.next[0].next.size()); |
|
|
|
|
draw_map(this, root, root.next[0]); // left
|
|
|
|
|
println("ROOT RIGHT HAS {} CHILD", root.next[1].next.size()); |
|
|
|
|
draw_map(this, root, root.next[1]); // right
|
|
|
|
|
partition_map(gen, root, 5); |
|
|
|
|
draw_map(this, root); // left
|
|
|
|
|
} |
|
|
|
|