summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-01 13:17:50 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-01 13:17:50 +0100
commitd478c37fc03c7590823f003a3b326e79ae8012f9 (patch)
treed64f164bc4b5922324bd88bfe809d7dea2dde2ba
parent7ebee3863c061b1d0b64839b56bbc70ff4e5d924 (diff)
draw: skip clickables fully off the screen
-rw-r--r--draw/anim.cpp23
-rw-r--r--editor/app.hpp1
-rw-r--r--editor/draw.cpp15
-rw-r--r--editor/update.cpp28
-rw-r--r--main/clickable.hpp3
5 files changed, 39 insertions, 31 deletions
diff --git a/draw/anim.cpp b/draw/anim.cpp
index 591d3801..03718fcb 100644
--- a/draw/anim.cpp
+++ b/draw/anim.cpp
@@ -34,16 +34,19 @@ void anim_mesh::add_clickable(tile_shader& shader, const Vector2i& win_size,
const auto& g = a.group(s.r);
const auto& f = a.frame(s.r, s.frame);
const auto world_pos = TILE_SIZE20 * Vector3(xy) + Vector3(g.offset) + Vector3(Vector2(s.offset), 0);
- const Vector2ui offset((Vector2(shader.camera_offset()) + Vector2(win_size)*.5f)
- + shader.project(world_pos) - Vector2(f.ground));
- clickable item = {
- { f.offset, f.offset + f.size }, { offset, offset + f.size },
- a.bitmask(), tile_shader::depth_value(xy, tile_shader::scenery_depth_offset),
- a.info().pixel_size[0],
- c, xy,
- !g.mirror_from.isEmpty(),
- };
- list.push_back(item);
+ const Vector2i offset((Vector2(shader.camera_offset()) + Vector2(win_size)*.5f)
+ + shader.project(world_pos) - Vector2(f.ground));
+ if (offset < win_size && offset + Vector2i(f.size) >= Vector2i())
+ {
+ clickable item = {
+ { f.offset, f.offset + f.size }, { offset, offset + Vector2i(f.size) },
+ a.bitmask(), tile_shader::depth_value(xy, tile_shader::scenery_depth_offset),
+ a.info().pixel_size[0],
+ c, xy,
+ !g.mirror_from.isEmpty(),
+ };
+ list.push_back(item);
+ }
}
void anim_mesh::draw(tile_shader& shader, chunk& c)
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();
}
diff --git a/main/clickable.hpp b/main/clickable.hpp
index 92b8dd49..3ca8ccb6 100644
--- a/main/clickable.hpp
+++ b/main/clickable.hpp
@@ -6,7 +6,8 @@
namespace floormat {
struct clickable final {
- Math::Range2D<UnsignedInt> src, dest;
+ Math::Range2D<unsigned> src;
+ Math::Range2D<int> dest;
BitArrayView bitmask;
float depth = 0;
std::uint32_t stride;