About to test out ranges of points

This commit is contained in:
2021-12-12 10:42:53 -05:00
parent cd37945791
commit f360be0c8d
2 changed files with 13 additions and 2 deletions

View File

@@ -7,7 +7,7 @@
#include <vector>
#include <range/v3/view.hpp>
template<typename T>
class Grid2D {
private:
@@ -28,6 +28,17 @@ public:
T get(int x, int y) {
return grid[y][x];
}
auto get_range() {
auto res = grid | ranges::views::enumerate | ranges::views::transform([](auto it) {
int index_y = std::get<0>(it);
std::vector<T> element = std::get<1>(it);
return element | ranges::views::enumerate | ranges::views::transform([&](auto pair) {
int index_x = std::get<0>(pair);
return Point{index_x, index_y};
});
});
return ranges::views::join(res);
}
};

View File

@@ -29,8 +29,8 @@ void Visualizer::render(Renderer *renderer) {
auto grass = Sprite{&tiles, 0};
auto wall = Sprite{&tiles, 497};
auto character = Sprite{&characters, this->sprite_index};
auto g = tile_map.get_range();
auto bounds = this->camera.get_bounds();
for(int ty : ranges::views::iota(bounds.y, bounds.y+bounds.height)) {
for(int tx : ranges::views::iota(bounds.x, bounds.x+bounds.width)) {
auto wp = camera.camera_coords_to_screen_coords(Point{tx, ty});