From 51ebc370743b07926ce0a50232a1a65c6b6b27b5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 22 Nov 2022 18:46:52 +0100 Subject: finally it works --- main/clickable.hpp | 20 ++++++++++++++++++++ main/draw.cpp | 28 +++++++++++++++++++++------- main/main-impl.cpp | 12 ++++++++++++ main/main-impl.hpp | 19 +++++++++++-------- 4 files changed, 64 insertions(+), 15 deletions(-) create mode 100644 main/clickable.hpp (limited to 'main') diff --git a/main/clickable.hpp b/main/clickable.hpp new file mode 100644 index 00000000..efc1a7fa --- /dev/null +++ b/main/clickable.hpp @@ -0,0 +1,20 @@ +#pragma once +#include "src/global-coords.hpp" +#include +#include + +namespace floormat { + +template +struct clickable final { + + Atlas& atlas; + T& item; + Math::Range2D src, dest; + BitArrayView bitmask; + float depth = 0; + chunk_coords chunk; + local_coords pos; +}; + +} // namespace floormat diff --git a/main/draw.cpp b/main/draw.cpp index 6b6c39a4..ba15b365 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -2,6 +2,8 @@ #include "floormat/app.hpp" #include "src/camera-offset.hpp" #include "src/anim-atlas.hpp" +#include "main/clickable.hpp" +#include #include #include #include @@ -111,17 +113,19 @@ void main_impl::draw_anim() noexcept const local_coords xy{i}; if (auto [atlas, s] = c[xy].scenery(); atlas) { + _anim_mesh.draw(_shader, *atlas, s.r, s.frame, xy); const auto& g = atlas->group(s.r); const auto& f = atlas->frame(s.r, s.frame); - const auto& mask = atlas->bitmask(); - Vector2 offset; constexpr Vector2 pixel88 = tile_shader::project(TILE_MAX_DIM*TILE_SIZE20*.5f); const auto world_pos = TILE_SIZE20 * Vector3(xy.x, xy.y, 0) + Vector3(g.offset); - offset += (Vector2(_shader.camera_offset()) + Vector2(sz))*.5f; - //offset += _shader.project(world_pos); - //offset -= Vector2(f.ground); - Debug{} << "offset" << offset.x() << offset.y(); - _anim_mesh.draw(_shader, *atlas, s.r, s.frame, xy); + const Vector2ui offset((Vector2(_shader.camera_offset()) + Vector2(sz) - pixel88)*.5f + + _shader.project(world_pos) - Vector2(f.ground)); + clickable item = { + *atlas, s, + { f.offset, f.offset + f.size }, { offset, offset + f.size }, + atlas->bitmask(), tile_shader::depth_value(xy, 0.25f), pos, xy + }; + _clickable_scenery.push_back(item); } } } @@ -217,4 +221,14 @@ void main_impl::drawEvent() timeline.nextFrame(); } +ArrayView> main_impl::clickable_scenery() const noexcept +{ + return { _clickable_scenery.data(), _clickable_scenery.size() }; +} + +ArrayView> main_impl::clickable_scenery() noexcept +{ + return { _clickable_scenery.data(), _clickable_scenery.size() }; +} + } // namespace floormat diff --git a/main/main-impl.cpp b/main/main-impl.cpp index dec3948f..0790a0d2 100644 --- a/main/main-impl.cpp +++ b/main/main-impl.cpp @@ -1,5 +1,6 @@ #include "main-impl.hpp" #include "compat/assert.hpp" +#include namespace floormat { @@ -33,4 +34,15 @@ floormat_main* floormat_main::create(floormat_app& app, fm_settings&& options) return ret; } +void main_impl::set_cursor(std::uint32_t cursor) noexcept +{ + setCursor(Cursor(cursor)); +} + +std::uint32_t main_impl::cursor() const noexcept +{ + using App = Platform::Sdl2Application; + return (std::uint32_t)static_cast(const_cast(this))->cursor(); +} + } // namespace floormat diff --git a/main/main-impl.hpp b/main/main-impl.hpp index d54b7f92..7adaeaec 100644 --- a/main/main-impl.hpp +++ b/main/main-impl.hpp @@ -6,6 +6,7 @@ #include "draw/wall.hpp" #include "draw/anim.hpp" #include "shaders/tile.hpp" +#include "main/clickable.hpp" #include #include #include @@ -19,13 +20,9 @@ namespace floormat { struct floormat_app; - -struct clickable final { - - float depth = 0; - chunk_coords chunk; - local_coords pos; -}; +struct scenery; +struct anim_atlas; +template struct clickable; struct main_impl final : Platform::Sdl2Application, floormat_main { @@ -47,6 +44,9 @@ struct main_impl final : Platform::Sdl2Application, floormat_main global_coords pixel_to_tile(Vector2d position) const noexcept override; + ArrayView> clickable_scenery() const noexcept override; + ArrayView> clickable_scenery() noexcept override; + [[maybe_unused]] void viewportEvent(ViewportEvent& event) override; [[maybe_unused]] void mousePressEvent(MouseEvent& event) override; [[maybe_unused]] void mouseReleaseEvent(MouseEvent& event) override; @@ -68,12 +68,15 @@ struct main_impl final : Platform::Sdl2Application, floormat_main void debug_callback(unsigned src, unsigned type, unsigned id, unsigned severity, const std::string& str) const; + void set_cursor(std::uint32_t cursor) noexcept override; + std::uint32_t cursor() const noexcept override; + private: fm_settings s; [[maybe_unused]] char _dummy = maybe_register_debug_callback(s.gpu_debug); floormat_app& app; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) tile_shader _shader; - std::vector _clickable_scenery; + std::vector> _clickable_scenery; struct world _world{}; Magnum::Timeline timeline; floor_mesh _floor_mesh; -- cgit v1.2.3