diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-22 18:46:52 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-22 18:46:52 +0100 |
commit | 51ebc370743b07926ce0a50232a1a65c6b6b27b5 (patch) | |
tree | 9c38ee65e32c6a760065ef33fe078847d7ea2d48 /main | |
parent | a917bb7c28b383c3c684bf75732188bfff0060bb (diff) |
finally it works
Diffstat (limited to 'main')
-rw-r--r-- | main/clickable.hpp | 20 | ||||
-rw-r--r-- | main/draw.cpp | 28 | ||||
-rw-r--r-- | main/main-impl.cpp | 12 | ||||
-rw-r--r-- | main/main-impl.hpp | 19 |
4 files changed, 64 insertions, 15 deletions
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 <Corrade/Containers/BitArrayView.h> +#include <Magnum/Math/Range.h> + +namespace floormat { + +template<typename Atlas, typename T> +struct clickable final { + + Atlas& atlas; + T& item; + Math::Range2D<UnsignedInt> 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 <Corrade/Containers/ArrayView.h> #include <Magnum/GL/DefaultFramebuffer.h> #include <Magnum/GL/Renderer.h> #include <Magnum/Math/Color.h> @@ -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<anim_atlas, scenery> 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<const clickable<anim_atlas, scenery>> main_impl::clickable_scenery() const noexcept +{ + return { _clickable_scenery.data(), _clickable_scenery.size() }; +} + +ArrayView<clickable<anim_atlas, scenery>> 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 <Magnum/Platform/Sdl2Application.h> 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<App*>(const_cast<main_impl*>(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 <vector> #include <Corrade/Containers/String.h> #include <Magnum/Timeline.h> @@ -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<typename Atlas, typename T> 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<const clickable<anim_atlas, scenery>> clickable_scenery() const noexcept override; + ArrayView<clickable<anim_atlas, scenery>> 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> _clickable_scenery; + std::vector<clickable<anim_atlas, scenery>> _clickable_scenery; struct world _world{}; Magnum::Timeline timeline; floor_mesh _floor_mesh; |