summaryrefslogtreecommitdiffhomepage
path: root/main
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-02-26 21:13:17 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-02-26 21:13:17 +0100
commit988bf5d0368cb16846c02ea1482ea7b051ab97cb (patch)
tree0a353bff848f7ccbb381aabda4b6c50700840eab /main
parentf4f942e5bf9e6966f8db4f6239ee5862b0b352c6 (diff)
main: cache window size
Diffstat (limited to 'main')
-rw-r--r--main/draw.cpp9
-rw-r--r--main/events.cpp1
-rw-r--r--main/main-impl.cpp9
-rw-r--r--main/main-impl.hpp1
4 files changed, 12 insertions, 8 deletions
diff --git a/main/draw.cpp b/main/draw.cpp
index 2a3b3f7b..02f58541 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -48,7 +48,7 @@ Vector2d 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{framebufferSize()}*.5 - _shader.camera_offset();
+ const Vector2d px = position - Vector2d{window_size()}*.5 - _shader.camera_offset();
return tile_shader::unproject(px*.5) / pixel_size + half;
}
@@ -57,7 +57,7 @@ auto main_impl::get_draw_bounds() const noexcept -> draw_bounds
using limits = std::numeric_limits<std::int16_t>;
auto x0 = limits::max(), x1 = limits::min(), y0 = limits::max(), y1 = limits::min();
- const auto win = Vector2d(framebufferSize());
+ const auto win = Vector2d(window_size());
chunk_coords list[] = {
pixel_to_tile(Vector2d{0, 0}).chunk(),
@@ -79,7 +79,7 @@ auto main_impl::get_draw_bounds() const noexcept -> draw_bounds
void main_impl::draw_world() noexcept
{
const auto [minx, maxx, miny, maxy] = get_draw_bounds();
- const auto sz = framebufferSize();
+ const auto sz = window_size();
for (std::int16_t y = miny; y <= maxy; y++)
for (std::int16_t x = minx; x <= maxx; x++)
@@ -96,7 +96,6 @@ void main_impl::draw_world() noexcept
}
_clickable_scenery.clear();
- const auto window_size = framebufferSize();
GL::Renderer::enable(GL::Renderer::Feature::DepthTest);
GL::defaultFramebuffer.clearDepthStencil(0, 0);
for (std::int16_t y = miny; y <= maxy; y++)
@@ -127,7 +126,7 @@ void main_impl::draw_world() noexcept
{
const local_coords xy{i};
if (auto [atlas, s] = c[xy].scenery(); atlas)
- _anim_mesh.add_clickable(_shader, window_size, pos, std::uint8_t(i), atlas, s, _clickable_scenery);
+ _anim_mesh.add_clickable(_shader, window_size(), pos, std::uint8_t(i), atlas, s, _clickable_scenery);
}
}
}
diff --git a/main/events.cpp b/main/events.cpp
index 17db862f..6222f964 100644
--- a/main/events.cpp
+++ b/main/events.cpp
@@ -9,6 +9,7 @@ namespace floormat {
void main_impl::viewportEvent(Platform::Sdl2Application::ViewportEvent& event)
{
+ _framebuffer_size = event.framebufferSize();
recalc_viewport(event.framebufferSize(), event.windowSize());
app.on_viewport_event(event.framebufferSize());
}
diff --git a/main/main-impl.cpp b/main/main-impl.cpp
index ae3f8cfc..ba2fa3ec 100644
--- a/main/main-impl.cpp
+++ b/main/main-impl.cpp
@@ -15,7 +15,6 @@ struct world& main_impl::world() noexcept { return _world; }
SDL_Window* main_impl::window() noexcept { return Sdl2Application::window(); }
fm_settings& main_impl::settings() noexcept { return s; }
const fm_settings& main_impl::settings() const noexcept { return s; }
-Vector2i main_impl::window_size() const noexcept { return framebufferSize(); }
tile_shader& main_impl::shader() noexcept { return _shader; }
const tile_shader& main_impl::shader() const noexcept { return _shader; }
bool main_impl::is_text_input_active() const noexcept { return const_cast<main_impl&>(*this).isTextInputActive(); }
@@ -26,7 +25,8 @@ const Platform::Sdl2Application& main_impl::application() const noexcept { retur
int main_impl::exec()
{
- recalc_viewport(framebufferSize(), windowSize());
+ _framebuffer_size = framebufferSize();
+ recalc_viewport(_framebuffer_size, windowSize());
return Sdl2Application::exec();
}
@@ -37,6 +37,11 @@ floormat_main* floormat_main::create(floormat_app& app, fm_settings&& options)
return ret;
}
+Vector2i floormat_main::window_size() const noexcept
+{
+ return _framebuffer_size;
+}
+
void main_impl::set_cursor(std::uint32_t cursor) noexcept
{
setCursor(Cursor(cursor));
diff --git a/main/main-impl.hpp b/main/main-impl.hpp
index c078cb87..3ec6b8a5 100644
--- a/main/main-impl.hpp
+++ b/main/main-impl.hpp
@@ -29,7 +29,6 @@ struct main_impl final : Platform::Sdl2Application, floormat_main
int exec() override;
void quit(int status) override;
- Magnum::Math::Vector2<int> window_size() const noexcept override;
tile_shader& shader() noexcept override;
const tile_shader& shader() const noexcept override;