From 1e213aac5fe47107de4df618ed8674193210f2fc Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Thu, 29 Jun 2023 07:05:01 +1000 Subject: [PATCH] Decimal zoom with lerp --- .gitignore | 1 + .../windowconfig/graphicsmenu.config.patch | 45 ++++++++++++++++++- source/client/StarClientApplication.cpp | 5 ++- source/frontend/StarChatBubbleManager.cpp | 2 +- source/frontend/StarGraphicsMenu.cpp | 2 +- source/rendering/StarTextPainter.cpp | 3 +- source/rendering/StarWorldCamera.hpp | 25 ++++++++--- source/rendering/StarWorldPainter.cpp | 10 ++--- source/rendering/StarWorldPainter.hpp | 2 +- 9 files changed, 77 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 04376b0..8cd7c60 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ build/ dist/ +enc_temp_folder/ .cache/ attic/ tiled/ diff --git a/assets/opensb/interface/windowconfig/graphicsmenu.config.patch b/assets/opensb/interface/windowconfig/graphicsmenu.config.patch index 1090157..ab97f2f 100644 --- a/assets/opensb/interface/windowconfig/graphicsmenu.config.patch +++ b/assets/opensb/interface/windowconfig/graphicsmenu.config.patch @@ -1 +1,44 @@ -{ "zoomList" : [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 ] } \ No newline at end of file +{ + "paneLayout": { "panefeature": { "positionLocked": false } }, + "zoomList": [ + 1, + 1.125, + 1.25, + 1.375, + 1.5, + 1.675, + 1.75, + 1.875, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32 + ] +} \ No newline at end of file diff --git a/source/client/StarClientApplication.cpp b/source/client/StarClientApplication.cpp index be5e649..a76a527 100644 --- a/source/client/StarClientApplication.cpp +++ b/source/client/StarClientApplication.cpp @@ -866,11 +866,13 @@ void ClientApplication::updateCamera() { if (!m_universeClient->worldClient()) return; + WorldCamera& camera = m_worldPainter->camera(); + camera.update(WorldTimestep); + if (m_mainInterface->fixedCamera()) return; auto assets = m_root->assets(); - auto camera = m_worldPainter->camera(); const float triggerRadius = 100.0f; const float deadzone = 0.1f; @@ -934,7 +936,6 @@ void ClientApplication::updateCamera() { m_worldPainter->setCameraPosition(m_universeClient->worldClient()->geometry(), baseCamera + (smoothDelta + m_cameraSmoothDelta) * 0.5f); m_cameraSmoothDelta = smoothDelta; - camera = m_worldPainter->camera(); m_universeClient->worldClient()->setClientWindow(camera.worldTileRect()); } diff --git a/source/frontend/StarChatBubbleManager.cpp b/source/frontend/StarChatBubbleManager.cpp index ab45faf..b9077fe 100644 --- a/source/frontend/StarChatBubbleManager.cpp +++ b/source/frontend/StarChatBubbleManager.cpp @@ -73,7 +73,7 @@ void ChatBubbleManager::setCamera(WorldCamera const& camera) { actions.append(SayChatAction{bubble.entity, bubble.text, state.idealDestination, bubble.config}); }); m_bubbles.clear(); - for (auto portraitBubble : m_portraitBubbles) + for (auto& portraitBubble : m_portraitBubbles) actions.append(PortraitChatAction{ portraitBubble.entity, portraitBubble.portrait, diff --git a/source/frontend/StarGraphicsMenu.cpp b/source/frontend/StarGraphicsMenu.cpp index 3f0778c..852a217 100644 --- a/source/frontend/StarGraphicsMenu.cpp +++ b/source/frontend/StarGraphicsMenu.cpp @@ -159,7 +159,7 @@ void GraphicsMenu::syncGui() { } else { zoomSlider->setVal(m_zoomList.size() - 1); } - fetchChild("zoomValueLabel")->setText(strf("{}x", m_localChanges.get("zoomLevel").toInt())); + fetchChild("zoomValueLabel")->setText(strf("{}x", m_localChanges.get("zoomLevel").toFloat())); fetchChild("speechBubbleCheckbox")->setChecked(m_localChanges.get("speechBubbles").toBool()); diff --git a/source/rendering/StarTextPainter.cpp b/source/rendering/StarTextPainter.cpp index b7526bb..631000e 100644 --- a/source/rendering/StarTextPainter.cpp +++ b/source/rendering/StarTextPainter.cpp @@ -530,6 +530,7 @@ RectF TextPainter::doRenderLine(StringView text, TextPositioning const& position return true; }; + m_fontTextureGroup.switchFont(m_renderSettings.font); Text::processText(text, textCallback, commandsCallback); return bounds; @@ -538,7 +539,7 @@ RectF TextPainter::doRenderLine(StringView text, TextPositioning const& position RectF TextPainter::doRenderGlyph(String::Char c, TextPositioning const& position, bool reallyRender) { if (m_nonRenderedCharacters.find(String(c)) != NPos) return RectF(); - m_fontTextureGroup.switchFont(m_renderSettings.font); + int width = glyphWidth(c); // Offset left by width if right anchored. float hOffset = 0; diff --git a/source/rendering/StarWorldCamera.hpp b/source/rendering/StarWorldCamera.hpp index fe1dbeb..d85543a 100644 --- a/source/rendering/StarWorldCamera.hpp +++ b/source/rendering/StarWorldCamera.hpp @@ -3,6 +3,7 @@ #include "StarWorldGeometry.hpp" #include "StarGameTypes.hpp" +#include "StarInterpolation.hpp" namespace Star { @@ -11,8 +12,9 @@ public: void setScreenSize(Vec2U screenSize); Vec2U screenSize() const; - void setPixelRatio(unsigned pixelRatio); - unsigned pixelRatio() const; + void setTargetPixelRatio(float targetPixelRatio); + void setPixelRatio(float pixelRatio); + float pixelRatio() const; void setWorldGeometry(WorldGeometry geometry); WorldGeometry worldGeometry() const; @@ -42,10 +44,13 @@ public: // worldTileRect, in screen coordinates. Vec2F tileMinScreen() const; + void update(float dt); + private: WorldGeometry m_worldGeometry; Vec2U m_screenSize; - unsigned m_pixelRatio = 1; + float m_pixelRatio = 1.0f; + float m_targetPixelRatio = 1.0f; Vec2F m_worldCenter; }; @@ -57,11 +62,15 @@ inline Vec2U WorldCamera::screenSize() const { return m_screenSize; } -inline void WorldCamera::setPixelRatio(unsigned pixelRatio) { - m_pixelRatio = pixelRatio; +inline void WorldCamera::setTargetPixelRatio(float targetPixelRatio) { + m_targetPixelRatio = targetPixelRatio; } -inline unsigned WorldCamera::pixelRatio() const { +inline void WorldCamera::setPixelRatio(float pixelRatio) { + m_pixelRatio = m_targetPixelRatio = pixelRatio; +} + +inline float WorldCamera::pixelRatio() const { return m_pixelRatio; } @@ -112,6 +121,10 @@ inline Vec2F WorldCamera::tileMinScreen() const { return (Vec2F(tileRect.min()) - screenRect.min()) * (TilePixels * m_pixelRatio); } +inline void WorldCamera::update(float dt) { + m_pixelRatio = lerp(exp(-20.0f * dt), m_targetPixelRatio, m_pixelRatio); +} + } #endif diff --git a/source/rendering/StarWorldPainter.cpp b/source/rendering/StarWorldPainter.cpp index fb0641d..7cb7c72 100644 --- a/source/rendering/StarWorldPainter.cpp +++ b/source/rendering/StarWorldPainter.cpp @@ -41,13 +41,13 @@ void WorldPainter::setCameraPosition(WorldGeometry const& geometry, Vec2F const& m_camera.setCenterWorldPosition(position); } -WorldCamera const& WorldPainter::camera() const { +WorldCamera& WorldPainter::camera() { return m_camera; } void WorldPainter::render(WorldRenderData& renderData) { m_camera.setScreenSize(m_renderer->screenSize()); - m_camera.setPixelRatio(Root::singleton().configuration()->get("zoomLevel").toFloat()); + m_camera.setTargetPixelRatio(Root::singleton().configuration()->get("zoomLevel").toFloat()); m_assets = Root::singleton().assets(); @@ -159,10 +159,10 @@ void WorldPainter::renderParticles(WorldRenderData& renderData, Particle::Layer if (!particleRenderWindow.contains(position)) continue; - Vec2I size = Vec2I::filled(particle.size * m_camera.pixelRatio()); + Vec2F size = Vec2F::filled(particle.size * m_camera.pixelRatio()); if (particle.type == Particle::Type::Ember) { - m_renderer->render(renderFlatRect(RectF(position - Vec2F(size) / 2, position + Vec2F(size) / 2), particle.color.toRgba(), particle.fullbright ? 0.0f : 1.0f)); + m_renderer->render(renderFlatRect(RectF(position - size / 2, position + size / 2), particle.color.toRgba(), particle.fullbright ? 0.0f : 1.0f)); } else if (particle.type == Particle::Type::Streak) { // Draw a rotated quad streaking in the direction the particle is coming from. @@ -199,7 +199,7 @@ void WorldPainter::renderParticles(WorldRenderData& renderData, Particle::Layer } else if (particle.type == Particle::Type::Text) { Vec2F position = m_camera.worldToScreen(particle.position); - unsigned size = textParticleFontSize * m_camera.pixelRatio() * particle.size; + unsigned size = round((float)textParticleFontSize * m_camera.pixelRatio() * particle.size); if (size > 0) { m_textPainter->setFontSize(size); m_textPainter->setFontColor(particle.color.toRgba()); diff --git a/source/rendering/StarWorldPainter.hpp b/source/rendering/StarWorldPainter.hpp index ab57e48..dac94fd 100644 --- a/source/rendering/StarWorldPainter.hpp +++ b/source/rendering/StarWorldPainter.hpp @@ -21,7 +21,7 @@ public: void setCameraPosition(WorldGeometry const& worldGeometry, Vec2F const& position); - WorldCamera const& camera() const; + WorldCamera& camera(); void render(WorldRenderData& renderData);