diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-07 16:45:28 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-07 16:45:28 +0200 |
commit | 15e8cebc19bfb484ba46a3589378d52ca769769e (patch) | |
tree | cd4174c7d15671434773acdc957a6bf894d6b29d | |
parent | 7b7e0ba851189848ff1c89761a1609e6a978fb19 (diff) |
a
-rw-r--r-- | compat/assert.hpp | 4 | ||||
-rw-r--r-- | main/main.cpp | 8 | ||||
-rw-r--r-- | src/chunk.hpp | 10 | ||||
-rw-r--r-- | src/floor-mesh.cpp | 12 | ||||
-rw-r--r-- | src/local-coords.hpp | 14 | ||||
-rw-r--r-- | src/wall-mesh.cpp | 4 | ||||
-rw-r--r-- | test/json.cpp | 4 |
7 files changed, 23 insertions, 33 deletions
diff --git a/compat/assert.hpp b/compat/assert.hpp index e8335843..c2307a0c 100644 --- a/compat/assert.hpp +++ b/compat/assert.hpp @@ -7,7 +7,7 @@ namespace Magnum::Examples::detail { template<std::size_t N, std::size_t M, typename... Xs> -constexpr void emit_debug(const char(&pfx)[M], const char(&fmt)[N], Xs... xs) +constexpr void emit_debug(const char(&pfx)[M], const char(&fmt)[N], Xs... xs) noexcept { if (std::is_constant_evaluated()) return; @@ -21,7 +21,7 @@ constexpr void emit_debug(const char(&pfx)[M], const char(&fmt)[N], Xs... xs) } template<std::size_t N, typename...Xs> -constexpr inline void abort(const char (&fmt)[N], Xs... xs) +constexpr inline void abort(const char (&fmt)[N], Xs... xs) noexcept // NOLINT(bugprone-exception-escape) { if (std::is_constant_evaluated()) throw "aborting"; diff --git a/main/main.cpp b/main/main.cpp index 4476e1ef..a579f1eb 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -85,10 +85,10 @@ chunk app::make_test_chunk() { constexpr auto N = TILE_MAX_DIM; chunk c; - c.foreach_tile([&, this](tile& x, std::size_t k, local_coords pt) { - const auto& atlas = pt.x > N/2 && pt.y >= N/2 ? floor2 : floor1; - x.ground_image = { atlas, (std::uint8_t)(k % atlas->num_tiles().product()) }; - }); + for (auto [x, k, pt] : c) { + const auto& atlas = pt.x > N/2 && pt.y >= N/2 ? floor2 : floor1; + x.ground_image = { atlas, (std::uint8_t)(k % atlas->num_tiles().product()) }; + } constexpr auto K = N/2; c[{K, K }].wall_north = { wall1, 0 }; c[{K, K }].wall_west = { wall2, 0 }; diff --git a/src/chunk.hpp b/src/chunk.hpp index a22dc025..debb5983 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -22,16 +22,6 @@ struct chunk final const auto& tiles() const { return _tiles; } auto& tiles() { return _tiles; } - template<tile_iterator_fn<tile&> F> - constexpr inline void foreach_tile(F&& fun) { - foreach_tile_<F, chunk&>(std::forward<F>(fun)); - } - - 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>; diff --git a/src/floor-mesh.cpp b/src/floor-mesh.cpp index ce0a3d19..fdace9d8 100644 --- a/src/floor-mesh.cpp +++ b/src/floor-mesh.cpp @@ -33,16 +33,16 @@ void floor_mesh::set_tile(quad_data& data, tile& x) void floor_mesh::draw(tile_shader& shader, chunk& c) { std::array<quad_data, TILE_COUNT> data; - c.foreach_tile([&](tile& x, std::size_t idx, local_coords) { - set_tile(data[idx], x); - }); + for (auto [x, idx, pt] : c) { + set_tile(data[idx], x); + } _vertex_buffer.setSubData(0, data); Magnum::GL::MeshView mesh{_mesh}; mesh.setCount(quad_index_count); const tile_atlas* last_tile_atlas = nullptr; - c.foreach_tile([&](tile& x, std::size_t i, local_coords) { + for (auto [x, i, pt] : c) { if (!x.ground_image) - return; + continue; mesh.setIndexRange((int)(i*quad_index_count), 0, quad_index_count*TILE_COUNT - 1); if (auto* atlas = x.ground_image.atlas.get(); atlas != last_tile_atlas) { @@ -50,7 +50,7 @@ void floor_mesh::draw(tile_shader& shader, chunk& c) last_tile_atlas = atlas; } shader.draw(mesh); - }); + } } std::array<std::array<UnsignedShort, 6>, TILE_COUNT> floor_mesh::make_index_array() diff --git a/src/local-coords.hpp b/src/local-coords.hpp index d2520a42..b63f3db8 100644 --- a/src/local-coords.hpp +++ b/src/local-coords.hpp @@ -9,21 +9,21 @@ namespace Magnum::Examples { struct local_coords final { std::uint8_t x = 0, y = 0; - explicit constexpr local_coords(std::size_t idx); - constexpr local_coords() = default; - constexpr local_coords(std::size_t x, std::size_t y); - constexpr local_coords(std::uint8_t x, std::uint8_t y) : x{x}, y{y} {} - constexpr std::size_t to_index() const { return y*TILE_MAX_DIM + x; } + explicit constexpr local_coords(std::size_t idx) noexcept; // NOLINT(bugprone-exception-escape) + constexpr local_coords() noexcept = default; + constexpr local_coords(std::size_t x, std::size_t y) noexcept; // NOLINT(bugprone-exception-escape) + constexpr local_coords(std::uint8_t x, std::uint8_t y) noexcept : x{x}, y{y} {} + constexpr std::size_t to_index() const noexcept { return y*TILE_MAX_DIM + x; } }; -constexpr local_coords::local_coords(std::size_t index) : +constexpr local_coords::local_coords(std::size_t index) noexcept : // NOLINT(bugprone-exception-escape) x{(std::uint8_t)(index % TILE_MAX_DIM)}, y{(std::uint8_t)(index / TILE_MAX_DIM)} { ASSERT(index < TILE_COUNT); } -constexpr local_coords::local_coords(std::size_t x, std::size_t y) +constexpr local_coords::local_coords(std::size_t x, std::size_t y) noexcept // NOLINT(bugprone-exception-escape) : x{(std::uint8_t)x}, y{(std::uint8_t)y} { ASSERT(x <= 0xff && y <= 0xff); diff --git a/src/wall-mesh.cpp b/src/wall-mesh.cpp index 68d8733e..dce86dc1 100644 --- a/src/wall-mesh.cpp +++ b/src/wall-mesh.cpp @@ -42,9 +42,9 @@ void wall_mesh::draw(tile_shader& shader, chunk& c) texture_array textures = {}; { vertex_array data; - c.foreach_tile([&](tile& x, std::size_t idx, local_coords) { + for (auto [x, idx, pt] : c) { maybe_add_tile(data, textures, x, idx); - }); + } _vertex_buffer.setSubData(0, data); } diff --git a/test/json.cpp b/test/json.cpp index cec6724e..1db03d03 100644 --- a/test/json.cpp +++ b/test/json.cpp @@ -18,10 +18,10 @@ static chunk make_test_chunk() metal3 = loader.tile_atlas("share/game/images/metal3.tga", {2, 2}); constexpr auto N = TILE_MAX_DIM; chunk c; - c.foreach_tile([&](tile& x, std::size_t k, local_coords pt) { + for (auto [x, k, pt] : c) { const auto& atlas = pt.x > N/2 && pt.y >= N/2 ? metal1 : metal2; x.ground_image = { atlas, (std::uint8_t)(k % atlas->num_tiles().product()) }; - }); + } constexpr auto K = N/2; c[{K, K }].wall_north = { metal3, 0 }; c[{K, K }].wall_west = { metal3, 0 }; |