wall merging
This commit is contained in:
@@ -1,4 +1,50 @@
|
||||
#include "maps.hpp"
|
||||
#include "globals.hpp"
|
||||
#ifdef __APPLE__
|
||||
#include <range/v3/view/iota.hpp>
|
||||
#include <range/v3/view/cartesian_product.hpp>
|
||||
#else
|
||||
#include <ranges>
|
||||
#endif
|
||||
|
||||
void merged_walls(Entity* wall_list[MAX_ROWS][MAX_COLS]) {
|
||||
#ifdef __APPLE__
|
||||
for(auto[j, i] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
#else
|
||||
for(auto[j, i] : std::views::cartesian_product(std::views::iota(0, MAX_COLS), std::views::iota(0, MAX_ROWS))) {
|
||||
#endif
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
if(wall_list[i][j]->rect.getSize().x != TILESIZE) continue;
|
||||
int start = i, end = i;
|
||||
|
||||
while(end + 1 < MAX_ROWS && wall_list[end + 1][j] != nullptr) {
|
||||
delete wall_list[end + 1][j];
|
||||
wall_list[end + 1][j] = nullptr;
|
||||
end++;
|
||||
}
|
||||
int merged_height = (end - start + 1) * TILESIZE;
|
||||
wall_list[start][j]->rect.setSize({ wall_list[start][j]->rect.getSize().x, static_cast<float>(merged_height) });
|
||||
i = end;
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
for(auto[i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
#else
|
||||
for(auto[i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) {
|
||||
#endif
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
if(wall_list[i][j]->rect.getSize().y != TILESIZE) continue;
|
||||
int start = j, end = j;
|
||||
|
||||
while(end + 1 < MAX_COLS && wall_list[i][end + 1] != nullptr && wall_list[i][end + 1]->rect.getSize().y == TILESIZE) {
|
||||
delete wall_list[i][end + 1];
|
||||
wall_list[i][end + 1] = nullptr;
|
||||
end++;
|
||||
}
|
||||
int merged_width = (end - start + 1) * TILESIZE;
|
||||
wall_list[i][start]->rect.setSize({ static_cast<float>(merged_width), wall_list[i][start]->rect.getSize().y });
|
||||
j = end;
|
||||
}
|
||||
}
|
||||
|
||||
int map_data[MAX_ROWS][MAX_COLS] = {
|
||||
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
|
||||
|
||||
Reference in New Issue
Block a user