|
|
@ -105,18 +105,7 @@ void Map::make_room(size_t origin_x, size_t origin_y, size_t w, size_t h) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
struct Partition; |
|
|
|
inline int make_split(std::mt19937 &gen, Room &cur, bool horiz) { |
|
|
|
|
|
|
|
|
|
|
|
struct Partition { |
|
|
|
|
|
|
|
size_t x = 0; |
|
|
|
|
|
|
|
size_t y = 0; |
|
|
|
|
|
|
|
size_t width = 0; |
|
|
|
|
|
|
|
size_t height = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<Partition> next; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline int make_split(std::mt19937 &gen, Partition &cur, bool horiz) { |
|
|
|
|
|
|
|
println("MAKE SPLIT horiz={}, y={}, w={}, h={}", horiz, |
|
|
|
println("MAKE SPLIT horiz={}, y={}, w={}, h={}", horiz, |
|
|
|
cur.y, cur.width, cur.height); |
|
|
|
cur.y, cur.width, cur.height); |
|
|
|
size_t dimension = horiz ? cur.height : cur.width; |
|
|
|
size_t dimension = horiz ? cur.height : cur.width; |
|
|
@ -127,13 +116,13 @@ inline int make_split(std::mt19937 &gen, Partition &cur, bool horiz) { |
|
|
|
return rand_dim(gen); |
|
|
|
return rand_dim(gen); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void partition_map(std::mt19937 &gen, Partition &cur, int depth) { |
|
|
|
void Map::partition_map(std::mt19937 &gen, Room &cur, int depth) { |
|
|
|
println(">>>> DEPTH: {}", depth); |
|
|
|
println(">>>> DEPTH: {}", depth); |
|
|
|
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); |
|
|
|
Partition left; |
|
|
|
Room left; |
|
|
|
Partition right; |
|
|
|
Room right; |
|
|
|
|
|
|
|
|
|
|
|
if(horiz) { |
|
|
|
if(horiz) { |
|
|
|
println("HORIZ split={}, x={}, y={}, w={}, h={}", |
|
|
|
println("HORIZ split={}, x={}, y={}, w={}, h={}", |
|
|
@ -193,23 +182,23 @@ void partition_map(std::mt19937 &gen, Partition &cur, int depth) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void draw_map(Map *map, Partition &cur) { |
|
|
|
void Map::draw_map(Room &cur) { |
|
|
|
if(cur.x + cur.width <= map->width() |
|
|
|
if(cur.x + cur.width <= width() |
|
|
|
&& cur.y + cur.height <= map->height()) |
|
|
|
&& cur.y + cur.height <= height()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
println("CUR NEXT SIZE: {}", cur.next.size()); |
|
|
|
println("CUR NEXT SIZE: {}", cur.next.size()); |
|
|
|
if(cur.next.size() == 1) { |
|
|
|
if(cur.next.size() == 1) { |
|
|
|
draw_map(map, cur.next[0]); // left
|
|
|
|
draw_map(cur.next[0]); // left
|
|
|
|
} else if(cur.next.size() == 2) { |
|
|
|
} else if(cur.next.size() == 2) { |
|
|
|
draw_map(map, cur.next[0]); // left
|
|
|
|
draw_map(cur.next[0]); // left
|
|
|
|
draw_map(map, cur.next[1]); // right
|
|
|
|
draw_map(cur.next[1]); // right
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
println("LEAF NODE NO CHILDREN x={}, y={}, w={}, h={}", cur.x, cur.y, cur.width, cur.height); |
|
|
|
println("LEAF NODE NO CHILDREN x={}, y={}, w={}, h={}", cur.x, cur.y, cur.width, cur.height); |
|
|
|
map->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 { |
|
|
|
} else { |
|
|
|
println("ABORT in draw_map, x={}, y={}, w={}, h={}, map.w={}, map.h={}", |
|
|
|
println("ABORT in draw_map, x={}, y={}, w={}, h={}, map.w={}, map.h={}", |
|
|
|
cur.x, cur.y, cur.width, cur.height, map->width(), map->height()); |
|
|
|
cur.x, cur.y, cur.width, cur.height, width(), height()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -217,7 +206,7 @@ void Map::generate() { |
|
|
|
std::random_device rd; |
|
|
|
std::random_device rd; |
|
|
|
std::mt19937 gen(rd()); |
|
|
|
std::mt19937 gen(rd()); |
|
|
|
|
|
|
|
|
|
|
|
Partition root{ |
|
|
|
Room root{ |
|
|
|
.x = 0, |
|
|
|
.x = 0, |
|
|
|
.y = 0, |
|
|
|
.y = 0, |
|
|
|
.width = width(), |
|
|
|
.width = width(), |
|
|
@ -225,5 +214,5 @@ void Map::generate() { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
partition_map(gen, root, 6); |
|
|
|
partition_map(gen, root, 6); |
|
|
|
draw_map(this, root); // left
|
|
|
|
draw_map(root); // left
|
|
|
|
} |
|
|
|
} |
|
|
|