diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-07 16:25:43 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-07 16:25:43 +0200 |
commit | 7b7e0ba851189848ff1c89761a1609e6a978fb19 (patch) | |
tree | 87c148317a39531a0636263f35f7bff56b234af4 /src/chunk.hpp | |
parent | 38440873ac8bf0862de7ba225657df09c5aee9e4 (diff) |
a
Diffstat (limited to 'src/chunk.hpp')
-rw-r--r-- | src/chunk.hpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/chunk.hpp b/src/chunk.hpp index 6c3706b8..a22dc025 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -1,15 +1,18 @@ #pragma once #include "tile.hpp" +#include "tile-iterator.hpp" #include <type_traits> #include <array> namespace Magnum::Examples { template<typename F, typename Tile> -concept tile_iterator = requires(F fn, Tile& tile) { +concept tile_iterator_fn = requires(F fn, Tile& tile) { { fn.operator()(tile, std::size_t{}, local_coords{}) } -> std::same_as<void>; }; +template<typename T> class basic_tile_iterator; + struct chunk final { constexpr tile& operator[](local_coords xy) { return _tiles[xy.to_index()]; } @@ -19,16 +22,24 @@ struct chunk final const auto& tiles() const { return _tiles; } auto& tiles() { return _tiles; } - template<tile_iterator<tile&> F> + template<tile_iterator_fn<tile&> F> constexpr inline void foreach_tile(F&& fun) { foreach_tile_<F, chunk&>(std::forward<F>(fun)); } - template<tile_iterator<const tile&> F> + template<tile_iterator_fn<const tile&> F> constexpr inline void foreach_const_tile(F&& fun) const { const_cast<chunk*>(this)->foreach_tile_<F, const chunk&>(std::forward<F>(fun)); } + using iterator = basic_tile_iterator<tile>; + using const_iterator = basic_tile_iterator<const tile>; + + constexpr iterator begin() { return iterator{_tiles.data(), 0}; } + constexpr iterator end() { return iterator{_tiles.data(), _tiles.size()}; } + constexpr const_iterator cbegin() const { return const_iterator{_tiles.data(), 0}; } + constexpr const_iterator cend() { return const_iterator{_tiles.data(), _tiles.size()}; } + private: template<typename F, typename Self> constexpr void foreach_tile_(F&& fun); |