From 8a8a0501590e83cbc598c7491fca0b767094466f Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Mon, 8 Apr 2024 14:22:22 +1000 Subject: 2 features: multi-sample anti-aliasing & Lua patches for images --- source/rendering/StarWorldCamera.cpp | 5 +++-- source/rendering/StarWorldCamera.hpp | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'source/rendering') diff --git a/source/rendering/StarWorldCamera.cpp b/source/rendering/StarWorldCamera.cpp index 0344bd6..81e599f 100644 --- a/source/rendering/StarWorldCamera.cpp +++ b/source/rendering/StarWorldCamera.cpp @@ -2,12 +2,13 @@ namespace Star { -void WorldCamera::setCenterWorldPosition(Vec2F const& position) { +void WorldCamera::setCenterWorldPosition(Vec2F const& position, bool force) { // Only actually move the world center if a half pixel distance has been // moved in any direction. This is sort of arbitrary, but helps prevent // judder if the camera is at a boundary and floating point inaccuracy is // causing the focus to jitter back and forth across the boundary. - if (fabs(position[0] - m_worldCenter[0]) < 1.0f / (TilePixels * m_pixelRatio * 2) && fabs(position[1] - m_worldCenter[1]) < 1.0f / (TilePixels * m_pixelRatio * 2)) + if (fabs(position[0] - m_worldCenter[0]) < 1.0f / (TilePixels * m_pixelRatio * 2) + && fabs(position[1] - m_worldCenter[1]) < 1.0f / (TilePixels * m_pixelRatio * 2) && !force) return; // First, make sure the camera center position is inside the main x diff --git a/source/rendering/StarWorldCamera.hpp b/source/rendering/StarWorldCamera.hpp index e022560..6354167 100644 --- a/source/rendering/StarWorldCamera.hpp +++ b/source/rendering/StarWorldCamera.hpp @@ -20,8 +20,8 @@ public: // Set the camera center position (in world space) to as close to the given // location as possible while keeping the screen within world bounds. + void setCenterWorldPosition(Vec2F const& position, bool force = false); // Returns the actual camera position. - void setCenterWorldPosition(Vec2F const& position); Vec2F centerWorldPosition() const; // Transforms world coordinates into one set of screen coordinates. Since @@ -121,7 +121,11 @@ inline Vec2F WorldCamera::tileMinScreen() const { } inline void WorldCamera::update(float dt) { - m_pixelRatio = lerp(exp(-20.0f * dt), m_targetPixelRatio, m_pixelRatio); + float newPixelRatio = lerp(exp(-20.0f * dt), m_targetPixelRatio, m_pixelRatio); + if (m_pixelRatio != newPixelRatio) { + m_pixelRatio = newPixelRatio; + setCenterWorldPosition(m_worldCenter, true); + } } } -- cgit v1.2.3