diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-21 21:11:33 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-21 21:11:33 +0200 |
commit | df2073a5692c991e4fc43c926334983997d272af (patch) | |
tree | 60d959c0e1dd97f0b4e63eacc60c162fc4a3e670 /main | |
parent | 04ee43ea683f5b9b591e10409b5e5a622e8a198a (diff) |
lots of refactoring types crap
Diffstat (limited to 'main')
-rw-r--r-- | main/editor.cpp | 22 | ||||
-rw-r--r-- | main/editor.hpp | 22 | ||||
-rw-r--r-- | main/imgui.cpp | 6 | ||||
-rw-r--r-- | main/update.cpp | 2 |
4 files changed, 27 insertions, 25 deletions
diff --git a/main/editor.cpp b/main/editor.cpp index 5658a785..709ab13b 100644 --- a/main/editor.cpp +++ b/main/editor.cpp @@ -61,7 +61,7 @@ void tile_type::clear_selection() _selection_mode = sel_none; } -void tile_type::select_tile(const std::shared_ptr<tile_atlas>& atlas, std::uint8_t variant) +void tile_type::select_tile(const std::shared_ptr<tile_atlas>& atlas, std::size_t variant) { fm_assert(atlas); clear_selection(); @@ -77,13 +77,14 @@ void tile_type::select_tile_permutation(const std::shared_ptr<tile_atlas>& atlas _permutation = { atlas, {} }; } -bool tile_type::is_tile_selected(const std::shared_ptr<tile_atlas>& atlas, std::uint8_t variant) const +bool tile_type::is_tile_selected(const std::shared_ptr<const tile_atlas>& atlas, std::size_t variant) const { fm_assert(atlas); - return _selection_mode == sel_tile && _selected_tile == std::make_tuple(atlas, variant); + return _selection_mode == sel_tile && _selected_tile && + atlas == _selected_tile.atlas && variant == _selected_tile.variant; } -bool tile_type::is_permutation_selected(const std::shared_ptr<tile_atlas>& atlas) const +bool tile_type::is_permutation_selected(const std::shared_ptr<const tile_atlas>& atlas) const { fm_assert(atlas); return _selection_mode == sel_perm && std::get<0>(_permutation) == atlas; @@ -101,7 +102,7 @@ void fisher_yates(T begin, T end) } } -std::tuple<std::shared_ptr<tile_atlas>, std::uint8_t> tile_type::get_selected_perm() +tile_image tile_type::get_selected_perm() { auto& [atlas, vec] = _permutation; const std::size_t N = atlas->num_tiles(); @@ -109,7 +110,7 @@ std::tuple<std::shared_ptr<tile_atlas>, std::uint8_t> tile_type::get_selected_pe return {}; if (vec.empty()) { - for (std::uint8_t i = 0; i < N; i++) + for (std::size_t i = 0; i < N; i++) vec.push_back(i); fisher_yates(vec.begin(), vec.end()); } @@ -118,12 +119,12 @@ std::tuple<std::shared_ptr<tile_atlas>, std::uint8_t> tile_type::get_selected_pe return {atlas, idx}; } -std::optional<std::tuple<std::shared_ptr<tile_atlas>, std::uint8_t>> tile_type::get_selected() +tile_image tile_type::get_selected() { switch (_selection_mode) { case sel_none: - return std::nullopt; + return {}; case sel_tile: return _selected_tile; case sel_perm: @@ -134,8 +135,7 @@ std::optional<std::tuple<std::shared_ptr<tile_atlas>, std::uint8_t>> tile_type:: } } -void tile_type::place_tile(world& world, global_coords pos, - const std::tuple<std::shared_ptr<tile_atlas>, std::uint8_t>& img) +void tile_type::place_tile(world& world, global_coords pos, tile_image& img) { const auto& [c, t] = world[pos]; const auto& [atlas, variant] = img; @@ -211,7 +211,7 @@ void editor::on_click(world& world, global_coords pos) if (opt) { _last_pos = pos; - mode->place_tile(world, pos, *opt); + mode->place_tile(world, pos, opt); } else on_release(); diff --git a/main/editor.hpp b/main/editor.hpp index 34a6671c..a308c437 100644 --- a/main/editor.hpp +++ b/main/editor.hpp @@ -2,12 +2,14 @@ #include "compat/defs.hpp" #include "tile-atlas.hpp" #include "global-coords.hpp" +#include "tile.hpp" + #include <cstdint> -#include <map> -#include <memory> #include <tuple> #include <optional> #include <vector> +#include <map> +#include <memory> #include <Corrade/Containers/StringView.h> namespace floormat { @@ -33,12 +35,12 @@ struct tile_type final editor_mode mode() const { return _mode; } void clear_selection(); - void select_tile(const std::shared_ptr<tile_atlas>& atlas, std::uint8_t variant); + void select_tile(const std::shared_ptr<tile_atlas>& atlas, std::size_t variant); void select_tile_permutation(const std::shared_ptr<tile_atlas>& atlas); - bool is_tile_selected(const std::shared_ptr<tile_atlas>& atlas, std::uint8_t variant) const; - bool is_permutation_selected(const std::shared_ptr<tile_atlas>& atlas) const; - std::optional<std::tuple<std::shared_ptr<tile_atlas>, std::uint8_t>> get_selected(); - void place_tile(world& world, global_coords pos, const std::tuple<std::shared_ptr<tile_atlas>, std::uint8_t>& img); + bool is_tile_selected(const std::shared_ptr<const tile_atlas>& atlas, std::size_t variant) const; + bool is_permutation_selected(const std::shared_ptr<const tile_atlas>& atlas) const; + tile_image get_selected(); + void place_tile(world& world, global_coords pos, tile_image& img); private: enum selection_mode : std::uint8_t { @@ -50,14 +52,14 @@ private: std::string _name; std::map<std::string, std::shared_ptr<tile_atlas>> _atlases; - std::tuple<std::shared_ptr<tile_atlas>, std::uint8_t> _selected_tile; - std::tuple<std::shared_ptr<tile_atlas>, std::vector<std::uint8_t>> _permutation; + tile_image _selected_tile; + std::tuple<std::shared_ptr<tile_atlas>, std::vector<std::size_t>> _permutation; selection_mode _selection_mode = sel_none; editor_mode _mode; rotation _rotation{}; void load_atlases(); - std::tuple<std::shared_ptr<tile_atlas>, std::uint8_t> get_selected_perm(); + tile_image get_selected_perm(); }; struct editor final diff --git a/main/imgui.cpp b/main/imgui.cpp index 2911d849..ea64cd85 100644 --- a/main/imgui.cpp +++ b/main/imgui.cpp @@ -113,7 +113,7 @@ void app::draw_editor_pane(tile_type& type, float main_menu_height) ImGui::SameLine(window_width - ImGui::CalcTextSize(buf).x - style.FramePadding.x - 4); ImGui::Text("%s", buf); }; - const auto N = (std::uint8_t)v->num_tiles(); + const auto N = v->num_tiles(); if (const auto flags = ImGuiTreeNodeFlags_(ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_Framed); auto b = tree_node(k.data(), flags)) { @@ -125,7 +125,7 @@ void app::draw_editor_pane(tile_type& type, float main_menu_height) }; const bool perm_selected = ed ? ed->is_permutation_selected(v) : false; constexpr std::size_t per_row = 5; - for (std::uint8_t i = 0; i < N; i++) + for (std::size_t i = 0; i < N; i++) { const bool selected = ed ? ed->is_tile_selected(v, i) : false; @@ -139,7 +139,7 @@ void app::draw_editor_pane(tile_type& type, float main_menu_height) perm_selected ? push_style_color(ImGuiCol_ButtonHovered, color_perm_selected) : raii_wrapper{}, }; - snprintf(buf, sizeof(buf), "##item_%hhu", i); + snprintf(buf, sizeof(buf), "##item_%zu", i); const auto uv = v->texcoords_for_id(i); ImGui::ImageButton(buf, (void*)&v->texture(), {TILE_SIZE[0]/2, TILE_SIZE[1]/2}, { uv[3][0], uv[3][1] }, { uv[0][0], uv[0][1] }); diff --git a/main/update.cpp b/main/update.cpp index fac359e8..00e59434 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()) }; + x.ground_image = { atlas, k % atlas->num_tiles() }; } constexpr auto K = N/2; c[{K, K }].wall_north = { wall1, 0 }; |