summaryrefslogtreecommitdiffhomepage
path: root/draw
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-04-02 05:31:06 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-04-02 05:31:06 +0200
commitab16b95656fbcf719604072263f8375cd80213c2 (patch)
tree41b52d7a95126e85c8f44adc6d7138a319746cb8 /draw
parent93880a5b068239768ba8b6e562a21e3d9103c124 (diff)
a
Diffstat (limited to 'draw')
-rw-r--r--draw/anim.cpp32
-rw-r--r--draw/anim.hpp6
2 files changed, 25 insertions, 13 deletions
diff --git a/draw/anim.cpp b/draw/anim.cpp
index ff0914c8..e8aa4e3b 100644
--- a/draw/anim.cpp
+++ b/draw/anim.cpp
@@ -26,31 +26,41 @@ std::array<UnsignedShort, 6> anim_mesh::make_index_array()
}};
}
-void anim_mesh::add_clickable(tile_shader& shader, const Vector2i& win_size, const std::shared_ptr<entity>& s, std::vector<clickable>& list)
+void anim_mesh::add_clickable(tile_shader& shader, const Vector2i& win_size,
+ entity* s_, const chunk::topo_sort_data& data,
+ std::vector<clickable>& list)
{
- const auto& a = *s->atlas;
- const auto& g = a.group(s->r);
- const auto& f = a.frame(s->r, s->frame);
- const auto world_pos = TILE_SIZE20 * Vector3(s->coord.local()) + Vector3(g.offset) + Vector3(Vector2(s->offset), 0);
+ const auto& s = *s_;
+ const auto& a = *s.atlas;
+ const auto& g = a.group(s.r);
+ const auto& f = a.frame(s.r, s.frame);
+ const auto world_pos = TILE_SIZE20 * Vector3(s.coord.local()) + Vector3(g.offset) + Vector3(Vector2(s.offset), 0);
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(), &*s, s->ordinal(),
- a.info().pixel_size[0],
- !g.mirror_from.isEmpty(),
+ .src = { f.offset, f.offset + f.size },
+ .dest = { offset, offset + Vector2i(f.size) },
+ .bitmask = a.bitmask(),
+ .e = s_,
+ .depth = s.ordinal(),
+ .slope = data.slope,
+ .stride = a.info().pixel_size[0],
+ .mirrored = !g.mirror_from.isEmpty(),
};
list.push_back(item);
}
}
-void anim_mesh::draw(tile_shader& shader, chunk& c)
+void anim_mesh::draw(tile_shader& shader, const Vector2i& win_size, chunk& c, std::vector<clickable>& list)
{
constexpr auto quad_index_count = 6;
auto [mesh_, es, size] = c.ensure_scenery_mesh(_draw_array);
+ for (const auto& x : es)
+ add_clickable(shader, win_size, x.data.in, x.data, list);
+
GL::MeshView mesh{mesh_};
[[maybe_unused]] size_t draw_count = 0;
const auto max_index = uint32_t(size*quad_index_count - 1);
@@ -75,7 +85,7 @@ void anim_mesh::draw(tile_shader& shader, chunk& c)
for (auto k = 0uz; k < size; k++)
{
fm_assert(es[k].e);
- const auto& e = *es[k].e;
+ auto& e = *es[k].e;
auto& atlas = *e.atlas;
if (last && &atlas != last.atlas)
{
diff --git a/draw/anim.hpp b/draw/anim.hpp
index 9574f1d1..96c1de7e 100644
--- a/draw/anim.hpp
+++ b/draw/anim.hpp
@@ -26,10 +26,12 @@ struct anim_mesh final
{
anim_mesh();
- void draw(tile_shader& shader, chunk& c);
+ void draw(tile_shader& shader, const Vector2i& win_size, chunk& c, std::vector<clickable>& list);
void draw(tile_shader& shader, anim_atlas& atlas, rotation r, size_t frame, const Vector3& pos, float depth);
void draw(tile_shader& shader, anim_atlas& atlas, rotation r, size_t frame, local_coords xy, Vector2b offset, float depth_offset);
- static void add_clickable(tile_shader& shader, const Vector2i& win_size, const std::shared_ptr<entity>& s, std::vector<clickable>& list);
+ static void add_clickable(tile_shader& shader, const Vector2i& win_size,
+ entity* s_, const chunk::topo_sort_data& data,
+ std::vector<clickable>& list);
private:
static std::array<UnsignedShort, 6> make_index_array();