diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-12 04:18:32 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-12 05:29:31 +0100 |
commit | 1a2801f6751f1baf52d5d989b9cccab97b3c921b (patch) | |
tree | 0a9ed21f501bbea9b5088b69e7d39b1c322ec193 /editor | |
parent | 802c17175e595ddb3075465a1febc432262bcc3f (diff) |
use Optional's destructuring bind
Diffstat (limited to 'editor')
-rw-r--r-- | editor/app.hpp | 2 | ||||
-rw-r--r-- | editor/camera.cpp | 4 | ||||
-rw-r--r-- | editor/draw.cpp | 6 | ||||
-rw-r--r-- | editor/editor.hpp | 2 | ||||
-rw-r--r-- | editor/update.cpp | 4 |
5 files changed, 8 insertions, 10 deletions
diff --git a/editor/app.hpp b/editor/app.hpp index b1e8f75c..c161a2aa 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -13,7 +13,7 @@ #include <memory> #include <Corrade/Containers/Pointer.h> -#include <Corrade/Containers/Optional.h> +#include <Corrade/Containers/OptionalStl.h> #include <Magnum/ImGuiIntegration/Context.h> namespace floormat { diff --git a/editor/camera.cpp b/editor/camera.cpp index 35d24ef4..e22b20ba 100644 --- a/editor/camera.cpp +++ b/editor/camera.cpp @@ -59,8 +59,8 @@ void app::reset_camera_offset() void app::update_cursor_tile(const Optional<Vector2i>& pixel) { cursor.pixel = pixel; - if (pixel) - cursor.tile = M->pixel_to_tile(Vector2d{*pixel}); + if (const auto [p, b] = pixel; b) + cursor.tile = M->pixel_to_tile(Vector2d{p}); else cursor.tile = NullOpt; } diff --git a/editor/draw.cpp b/editor/draw.cpp index 72919794..8273fc44 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -10,11 +10,9 @@ void app::draw_cursor() { constexpr float LINE_WIDTH = 2; - if (cursor.tile && !cursor.in_imgui) + if (const auto [pos, b] = cursor.tile; b && !cursor.in_imgui) { - const auto pos = *cursor.tile; - - const auto draw = [&](auto& mesh, const auto& size) { + const auto draw = [&, pos = pos](auto& mesh, const auto& size) { const auto pt = pos.to_signed(); const Vector3 center{Vector3i(pt[0], pt[1], 0) * iTILE_SIZE}; auto& shader = M->shader(); diff --git a/editor/editor.hpp b/editor/editor.hpp index 4f667e96..e40e695a 100644 --- a/editor/editor.hpp +++ b/editor/editor.hpp @@ -10,7 +10,7 @@ #include <map> #include <memory> -#include <Corrade/Containers/Optional.h> +#include <Corrade/Containers/OptionalStl.h> #include <Corrade/Containers/StringView.h> namespace floormat { diff --git a/editor/update.cpp b/editor/update.cpp index e9207cf6..a1f5d807 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -40,8 +40,8 @@ void app::maybe_initialize_chunk([[maybe_unused]] const chunk_coords& pos, [[may void app::do_mouse_move(int mods) { - if (cursor.tile && !cursor.in_imgui) - _editor.on_mouse_move(M->world(), *cursor.tile, mods); + if (auto [tile, b] = cursor.tile; b && !cursor.in_imgui) + _editor.on_mouse_move(M->world(), tile, mods); } void app::do_mouse_up_down(std::uint8_t button, bool is_down, int mods) |