summaryrefslogtreecommitdiffhomepage
path: root/main
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-11-22 03:19:29 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-11-22 03:19:29 +0100
commit0fa4a8542bf9eda8bd9c28da199b3e90e04279b9 (patch)
tree8a91894a3b9eebdb8a7ef3c4b3e94d169efcf8ea /main
parent966ac722d72c8d89e621987090b19f2bde0cb58c (diff)
wip
Diffstat (limited to 'main')
-rw-r--r--main/draw.cpp25
-rw-r--r--main/main-impl.hpp14
-rw-r--r--main/setup.cpp3
3 files changed, 35 insertions, 7 deletions
diff --git a/main/draw.cpp b/main/draw.cpp
index 1b441650..4366fd9b 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -1,6 +1,7 @@
#include "main-impl.hpp"
#include "floormat/app.hpp"
#include "src/camera-offset.hpp"
+#include "src/anim-atlas.hpp"
#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/GL/Renderer.h>
#include <Magnum/Math/Color.h>
@@ -56,8 +57,8 @@ global_coords main_impl::pixel_to_tile(Vector2d position) const noexcept
{
constexpr Vector2d pixel_size(TILE_SIZE2);
constexpr Vector2d half{.5, .5};
- const Vector2d px = position - Vector2d{windowSize()}*.5 - _shader.camera_offset()*.5;
- const Vector2d vec = tile_shader::unproject(px) / pixel_size + half;
+ const Vector2d px = position - Vector2d{windowSize()}*.5 - _shader.camera_offset();
+ const Vector2d vec = tile_shader::unproject(px*.5) / pixel_size + half;
const auto x = (std::int32_t)std::floor(vec[0]), y = (std::int32_t)std::floor(vec[1]);
return { x, y };
}
@@ -119,6 +120,7 @@ void main_impl::draw_anim() noexcept
{
const auto sz = windowSize();
const auto [minx, maxx, miny, maxy] = get_draw_bounds();
+ _clickable_scenery.clear();
GL::Renderer::enable(GL::Renderer::Feature::DepthTest);
@@ -129,7 +131,24 @@ void main_impl::draw_anim() noexcept
auto& c = _world[pos];
const with_shifted_camera_offset o{_shader, pos};
if (check_chunk_visible(_shader.camera_offset(), sz))
- _anim_mesh.draw(_shader, c);
+ for (std::size_t i = 0; i < TILE_COUNT; i++)
+ {
+ const local_coords xy{i};
+ if (auto [atlas, s] = c[xy].scenery(); atlas)
+ {
+ 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);
+ }
+ }
}
GL::Renderer::disable(GL::Renderer::Feature::DepthTest);
diff --git a/main/main-impl.hpp b/main/main-impl.hpp
index 93d0966e..63239a74 100644
--- a/main/main-impl.hpp
+++ b/main/main-impl.hpp
@@ -6,10 +6,10 @@
#include "draw/wall.hpp"
#include "draw/anim.hpp"
#include "shaders/tile.hpp"
-
+#include <vector>
#include <Corrade/Containers/String.h>
-
#include <Magnum/Timeline.h>
+#include <Magnum/Math/Range.h>
#include <Magnum/GL/DebugOutput.h>
#include <Magnum/GL/Framebuffer.h>
#include <Magnum/GL/Renderbuffer.h>
@@ -20,6 +20,13 @@ namespace floormat {
struct floormat_app;
+struct clickable final {
+
+ float depth = 0;
+ chunk_coords chunk;
+ local_coords pos;
+};
+
struct main_impl final : Platform::Sdl2Application, floormat_main
{
explicit main_impl(floormat_app& app, fm_settings&& opts, int& fake_argc) noexcept;
@@ -66,11 +73,12 @@ private:
[[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;
struct world _world{};
+ Magnum::Timeline timeline;
floor_mesh _floor_mesh;
wall_mesh _wall_mesh;
anim_mesh _anim_mesh;
- Magnum::Timeline timeline;
struct {
float value = 0;
float jitter = 0;
diff --git a/main/setup.cpp b/main/setup.cpp
index 1329374a..040c9bdd 100644
--- a/main/setup.cpp
+++ b/main/setup.cpp
@@ -21,6 +21,7 @@ main_impl::main_impl(floormat_app& app, fm_settings&& s, int& fake_argc) noexcep
(void)setSwapInterval(0);
set_fp_mask();
fm_assert(framebufferSize() == windowSize());
+ _clickable_scenery.reserve(128);
timeline.start();
}
@@ -57,7 +58,7 @@ auto main_impl::make_conf(const fm_settings& s) -> Configuration
}
return Configuration{}
.setTitle(s.title)
- .setSize(s.resolution)
+ .setSize(s.resolution, Vector2(1, 1))
.setWindowFlags(make_window_flags(s));
}