diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-01 13:17:50 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-01 13:17:50 +0100 |
commit | d478c37fc03c7590823f003a3b326e79ae8012f9 (patch) | |
tree | d64f164bc4b5922324bd88bfe809d7dea2dde2ba /editor | |
parent | 7ebee3863c061b1d0b64839b56bbc70ff4e5d924 (diff) |
draw: skip clickables fully off the screen
Diffstat (limited to 'editor')
-rw-r--r-- | editor/app.hpp | 1 | ||||
-rw-r--r-- | editor/draw.cpp | 15 | ||||
-rw-r--r-- | editor/update.cpp | 28 |
3 files changed, 24 insertions, 20 deletions
diff --git a/editor/app.hpp b/editor/app.hpp index c958fdf4..76919533 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -61,6 +61,7 @@ private: void update(float dt) override; void update_world(float dt); void update_cursor_tile(const Optional<Vector2i>& pixel); + void set_cursor(); void maybe_initialize_chunk(const chunk_coords& pos, chunk& c) override; void maybe_initialize_chunk_(const chunk_coords& pos, chunk& c); diff --git a/editor/draw.cpp b/editor/draw.cpp index 77d3f665..329603e0 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -144,23 +144,22 @@ void app::draw() render_menu(); } -clickable* app::find_clickable_scenery(const Optional<Vector2i>& pixel_) +clickable* app::find_clickable_scenery(const Optional<Vector2i>& pixel) { - if (!pixel_ || _editor.mode() != editor_mode::none) + if (!pixel || _editor.mode() != editor_mode::none) return nullptr; - const auto pixel = Vector2ui(*pixel_); clickable* item = nullptr; float depth = -1; const auto array = M->clickable_scenery(); for (clickable& c : array) - if (c.depth > depth && c.dest.contains(pixel)) + if (c.depth > depth && c.dest.contains(*pixel)) { - const auto pos_ = pixel - c.dest.min() + c.src.min(); - const auto pos = !c.mirrored ? pos_ : Vector2ui(c.src.sizeX() - 1 - pos_[0], pos_[1]); - std::size_t idx = pos.y() * c.stride + pos.x(); - fm_debug_assert(idx < c.bitmask.size()); + const auto pos_ = *pixel - c.dest.min() + Vector2i(c.src.min()); + const auto pos = !c.mirrored ? pos_ : Vector2i(int(c.src.sizeX()) - 1 - pos_[0], pos_[1]); + std::size_t idx = unsigned(pos.y()) * c.stride + unsigned(pos.x()); + fm_assert(idx < c.bitmask.size()); if (c.bitmask[idx]) { depth = c.depth; diff --git a/editor/update.cpp b/editor/update.cpp index 35170ffc..f9afa6c9 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -178,29 +178,33 @@ void app::update_world(float dt) } } -void app::update(float dt) +void app::set_cursor() { - apply_commands(keys); - update_world(dt); - do_camera(dt, keys, get_key_modifiers()); - clear_non_repeated_keys(); - if (!cursor.in_imgui) { if (auto* cl = find_clickable_scenery(cursor.pixel)) { auto& w = M->world(); auto [c, t] = w[{cl->chunk, cl->pos}]; - if (auto sc = t.scenery()) + if (auto sc = t.scenery(); sc && sc.can_activate()) { - auto [atlas, s] = sc; - if (sc && sc.can_activate()) - M->set_cursor(std::uint32_t(Cursor::Hand)); - else - set_cursor_from_imgui(); + M->set_cursor(std::uint32_t(Cursor::Hand)); + return; } } + M->set_cursor(std::uint32_t(Cursor::Arrow)); } + else + set_cursor_from_imgui(); +} + +void app::update(float dt) +{ + apply_commands(keys); + update_world(dt); + do_camera(dt, keys, get_key_modifiers()); + clear_non_repeated_keys(); + set_cursor(); M->world().maybe_collect(); } |