diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-20 23:52:36 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-20 23:52:36 +0200 |
commit | 394f6fedbbafe905bdb10c998b0d2b476a1d710f (patch) | |
tree | 222a18dbadb213f962bc620eecce4443e2ca5f9b | |
parent | 3c4a9458dd06868fa9bbaab1742ef91816bcd8ac (diff) |
fix tile_atlas::num_tiles() snafu
-rw-r--r-- | main/editor.cpp | 6 | ||||
-rw-r--r-- | main/imgui.cpp | 4 | ||||
-rw-r--r-- | main/update.cpp | 2 | ||||
-rw-r--r-- | serialize/tile-atlas.cpp | 2 | ||||
-rw-r--r-- | src/tile-atlas.hpp | 3 | ||||
-rw-r--r-- | test/json.cpp | 2 |
6 files changed, 10 insertions, 9 deletions
diff --git a/main/editor.cpp b/main/editor.cpp index cfe793b9..4ac16024 100644 --- a/main/editor.cpp +++ b/main/editor.cpp @@ -29,7 +29,7 @@ void tile_type::load_atlases() if (auto x = name.findLast('.'); x) name = name.prefix(x.data()); auto& [_, vec] = _permutation; - vec.reserve((std::size_t)atlas->num_tiles().product()); + vec.reserve((std::size_t)atlas->num_tiles()); _atlases[name] = std::move(atlas); } } @@ -66,7 +66,7 @@ void tile_type::select_tile(const std::shared_ptr<tile_atlas>& atlas, std::uint8 fm_assert(atlas); clear_selection(); _selection_mode = sel_tile; - _selected_tile = { atlas, variant }; + _selected_tile = { atlas, variant % atlas->num_tiles() }; } void tile_type::select_tile_permutation(const std::shared_ptr<tile_atlas>& atlas) @@ -104,7 +104,7 @@ void fisher_yates(T begin, T end) std::tuple<std::shared_ptr<tile_atlas>, std::uint8_t> tile_type::get_selected_perm() { auto& [atlas, vec] = _permutation; - const std::size_t N = atlas->num_tiles().product(); + const std::size_t N = atlas->num_tiles(); if (N == 0) return {}; if (vec.empty()) diff --git a/main/imgui.cpp b/main/imgui.cpp index 6f0d7c11..e202fd08 100644 --- a/main/imgui.cpp +++ b/main/imgui.cpp @@ -103,11 +103,11 @@ void app::draw_editor_pane(tile_type& type, float main_menu_height) _editor.floor().select_tile_permutation(v_); }; const auto add_tile_count = [&] { - snprintf(buf, sizeof(buf), "%zu", (std::size_t)v_->num_tiles().product()); + snprintf(buf, sizeof(buf), "%zu", (std::size_t)v_->num_tiles()); ImGui::SameLine(window_width - ImGui::CalcTextSize(buf).x - style.FramePadding.x - 4); ImGui::Text("%s", buf); }; - const std::size_t N = v->num_tiles().product(); + const std::size_t N = v->num_tiles(); if (const auto flags = ImGuiTreeNodeFlags_(ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_Framed); auto b = tree_node(k.data(), flags)) { diff --git a/main/update.cpp b/main/update.cpp index 0d93b0c2..8b0e221f 100644 --- a/main/update.cpp +++ b/main/update.cpp @@ -7,7 +7,7 @@ void app::make_test_chunk(chunk& c) constexpr auto N = TILE_MAX_DIM; for (auto [x, k, pt] : c) { const auto& atlas = pt.x != pt.y && (pt.x == N/2 || pt.y == N/2) ? floor2 : floor1; - x.ground_image = { atlas, (std::uint8_t)(k % atlas->num_tiles().product()) }; + x.ground_image = { atlas, (std::uint8_t)(k % atlas->num_tiles()) }; } constexpr auto K = N/2; c[{K, K }].wall_north = { wall1, 0 }; diff --git a/serialize/tile-atlas.cpp b/serialize/tile-atlas.cpp index ab72fc43..896d29a4 100644 --- a/serialize/tile-atlas.cpp +++ b/serialize/tile-atlas.cpp @@ -20,7 +20,7 @@ void adl_serializer<shared_atlas>::to_json(json& j, const shared_atlas& x) j = nullptr; else { using nlohmann::to_json; - to_json(j, proxy_atlas{x->name(), x->num_tiles()}); + to_json(j, proxy_atlas{x->name(), x->num_tiles2()}); } } diff --git a/src/tile-atlas.hpp b/src/tile-atlas.hpp index 5fb0f899..a24ea96f 100644 --- a/src/tile-atlas.hpp +++ b/src/tile-atlas.hpp @@ -22,7 +22,8 @@ struct tile_atlas final static constexpr quad wall_quad_W(Vector3 center, Vector3 size); static constexpr std::array<UnsignedShort, 6> indices(std::size_t N); [[maybe_unused]] Vector2ui pixel_size() const { return size_; } - Vector2ui num_tiles() const { return dims_; } + std::size_t num_tiles() const { return dims_.product(); } + Vector2ui num_tiles2() const { return dims_; } GL::Texture2D& texture() { return tex_; } Containers::StringView name() const { return name_; } diff --git a/test/json.cpp b/test/json.cpp index 73958b5e..afdee3a2 100644 --- a/test/json.cpp +++ b/test/json.cpp @@ -19,7 +19,7 @@ static chunk make_test_chunk() constexpr auto N = TILE_MAX_DIM; chunk c; for (auto& [x, k, pt] : c) { - x.ground_image = { tiles, (std::uint8_t)(k % tiles->num_tiles().product()) }; + x.ground_image = { tiles, (std::uint8_t)(k % tiles->num_tiles()) }; } constexpr auto K = N/2; c[{K, K }].wall_north = { metal1, 0 }; |