diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-02 15:29:41 +0200 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-02 15:29:41 +0200 |
| commit | 445caf6184cafbce361670ea6028ff76317976bc (patch) | |
| tree | 0ff8c2c33211f7a738de8f6f5d6cec79aa776f36 /chunk.hpp | |
| parent | f339fa747348e742859701331b529f86d7bd8453 (diff) | |
a
Diffstat (limited to 'chunk.hpp')
| -rw-r--r-- | chunk.hpp | 32 |
1 files changed, 4 insertions, 28 deletions
@@ -7,14 +7,10 @@ namespace Magnum::Examples { struct chunk final { - //using index_type = std::common_type_t<decltype(local_coords::x), decltype(local_coords::y)>; - //using tile_index_array_type = std::array<index_type, TILE_COUNT>; - //static constexpr inline local_coords center = { (index_type)(N/2), (index_type)(N/2) }; - - constexpr tile& operator[](local_coords xy); - constexpr const tile& operator[](local_coords xy) const; - constexpr tile& operator[](std::size_t i); - constexpr const tile& operator[](std::size_t i) const; + constexpr tile& operator[](local_coords xy) { return tiles[xy.to_index()]; } + constexpr const tile& operator[](local_coords xy) const { return tiles[xy.to_index()]; } + constexpr tile& operator[](std::size_t i) { return tiles[i]; } + constexpr const tile& operator[](std::size_t i) const { return tiles[i]; } template<typename F> requires std::invocable<F, tile&, std::size_t, local_coords> @@ -31,26 +27,6 @@ private: std::array<tile, TILE_COUNT> tiles = {}; }; -constexpr tile& chunk::operator[](std::size_t i) { - if (i >= TILE_COUNT) - throw OUT_OF_RANGE(i, 0, TILE_COUNT); - return tiles[i]; -} - -constexpr const tile& chunk::operator[](std::size_t i) const { - return const_cast<chunk&>(*this).operator[](i); -} - -constexpr const tile& chunk::operator[](local_coords xy) const { - return const_cast<chunk&>(*this).operator[](xy); -} - -constexpr tile& chunk::operator[](local_coords xy) -{ - auto idx = xy.to_index(); - return operator[](idx); -} - template<typename F, typename Self> constexpr void chunk::foreach_tile_(F&& fun) { |
