From 1a2801f6751f1baf52d5d989b9cccab97b3c921b Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 12 Nov 2022 04:18:32 +0100 Subject: use Optional's destructuring bind --- editor/app.hpp | 2 +- editor/camera.cpp | 4 ++-- editor/draw.cpp | 6 ++---- editor/editor.hpp | 2 +- editor/update.cpp | 4 ++-- 5 files changed, 8 insertions(+), 10 deletions(-) (limited to 'editor') 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 #include -#include +#include #include 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& 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 #include -#include +#include #include 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) -- cgit v1.2.3