From 0d326089f7530937fdaa8563c398fa6bdf3eec9a Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sun, 9 Nov 2025 01:40:15 -0500 Subject: [PATCH] Movement is now much smoother for the easing functions and I can pan around better, but it's hard coded to only do pan at the moment. --- animation.cpp | 14 +++++++++----- assets/animations.json | 22 ++-------------------- assets/cameras.json | 14 +++++++------- camera.cpp | 7 +++++++ camera.hpp | 1 + easings.hpp | 3 ++- storyboard/ui.cpp | 20 ++++++++------------ storyboard/ui.hpp | 3 +-- 8 files changed, 37 insertions(+), 47 deletions(-) diff --git a/animation.cpp b/animation.cpp index 4f063c7..49ffb3a 100644 --- a/animation.cpp +++ b/animation.cpp @@ -1,7 +1,9 @@ #include "animation.hpp" #include "rand.hpp" +#include namespace components { + void Animation::play() { if(!playing) { current = 0; @@ -11,7 +13,7 @@ namespace components { } float Animation::twitching() { - float tick = ease::sine(float(frames) / (subframe + 0.0001) * ease_rate); + float tick = 1 - std::powf(ease_rate, subframe + 0.0001); switch(easing) { case ease::NONE: @@ -21,13 +23,15 @@ namespace components { case ease::OUT_CIRC: return ease::out_circ(tick); case ease::OUT_BOUNCE: - return ease::sine(ease::out_bounce(tick)); + return ease::out_bounce(tick); case ease::IN_OUT_BACK: - return ease::sine(ease::in_out_back(tick)); + return ease::in_out_back(tick); case ease::RANDOM: return Random::uniform_real(0.0001f, 1.0f); case ease::NORM_DIST: return Random::normal(0.5f, 0.1f); + case ease::LINEAR: + return tick; default: dbc::sentinel( fmt::format("Invalid easing {} given to animation", @@ -65,8 +69,8 @@ namespace components { scale_out.y = std::lerp(min_y, max_y, tick); } break; case ease::SLIDE: { - pos_out.x += std::lerp(pos_out.x, pos_out.x + max_x, tick); - pos_out.y += std::lerp(pos_out.y, pos_out.y + max_y, tick); + pos_out.x = std::lerp(min_x, max_x, tick); + pos_out.y = std::lerp(min_y, max_y, tick); } break; default: dbc::sentinel("Unknown animation.motion setting."); diff --git a/assets/animations.json b/assets/animations.json index 7b02df7..a33e88d 100644 --- a/assets/animations.json +++ b/assets/animations.json @@ -156,7 +156,7 @@ "max_y": 1.2, "simple": true, "frames": 1, - "speed": 0.6, + "speed": 0.2, "scaled": true, "stationary": false, "toggled": false, @@ -192,7 +192,7 @@ "max_y": 1.1, "simple": true, "frames": 10, - "speed": 1.0, + "speed": 0.2, "scaled": true, "stationary": false, "toggled": false, @@ -235,24 +235,6 @@ "flipped": false, "looped": false }, - "rat_king_boss": { - "_type": "Animation", - "easing": 4, - "motion": 0, - "ease_rate": 0.5, - "min_x": 0.6, - "min_y": 0.6, - "max_x": 0.8, - "max_y": 0.8, - "simple": false, - "frames": 2, - "speed": 0.02, - "scaled": true, - "stationary": true, - "toggled": false, - "flipped": false, - "looped": false - }, "torch_fixture": { "_type": "Animation", "easing": 0, diff --git a/assets/cameras.json b/assets/cameras.json index 7af78eb..466c5ef 100644 --- a/assets/cameras.json +++ b/assets/cameras.json @@ -1,12 +1,12 @@ { "pan": { "_type": "Animation", - "easing": 2, + "easing": 7, "motion": 7, - "ease_rate": 0.05, - "min_x": 0, - "min_y": 0, - "max_x": 150.0, + "ease_rate": 0.001, + "min_x": 0.0, + "min_y": 0.0, + "max_x": 0.0, "max_y": 0.0, "simple": true, "frames": 1, @@ -40,8 +40,8 @@ "easing": 1, "motion": 0, "ease_rate": 0.5, - "min_x": 1.3, - "min_y": 1.3, + "min_x": 0.8, + "min_y": 0.8, "max_x": 1.0, "max_y": 1.0, "simple": true, diff --git a/camera.cpp b/camera.cpp index 0b7cf09..dae878e 100644 --- a/camera.cpp +++ b/camera.cpp @@ -40,8 +40,15 @@ namespace cinematic { anim = MGR.animations.at(name); } + void Camera::position(float x, float y) { + anim.min_x = x; + anim.min_y = y; + } + void Camera::move(sf::RenderTexture& target, sf::Vector2f pos) { sf::View zoom; + anim.max_x = pos.x; + anim.max_y = pos.y; anim.apply(zoom, pos, size); target.setView(zoom); } diff --git a/camera.hpp b/camera.hpp index 38d5757..9db2c46 100644 --- a/camera.hpp +++ b/camera.hpp @@ -14,6 +14,7 @@ namespace cinematic { void move(sf::RenderTexture& target, sf::Vector2f pos); bool playing(); void play(); + void position(float x, float y); void style(const std::string &name); }; diff --git a/easings.hpp b/easings.hpp index 11cb862..fb1d60d 100644 --- a/easings.hpp +++ b/easings.hpp @@ -10,7 +10,8 @@ namespace ease { OUT_BOUNCE=3, IN_OUT_BACK=4, RANDOM=5, - NORM_DIST=6 + NORM_DIST=6, + LINEAR=7 }; enum Motion { diff --git a/storyboard/ui.cpp b/storyboard/ui.cpp index 87d5e95..6d4cc48 100644 --- a/storyboard/ui.cpp +++ b/storyboard/ui.cpp @@ -3,13 +3,12 @@ #include "animation.hpp" namespace storyboard { - UI::UI() : $view_texture({SCREEN_WIDTH, SCREEN_HEIGHT}), $view_sprite($view_texture.getTexture()) { $view_sprite.setPosition({0, 0}); - $camera.style("dolly"); + $camera.style("pan"); } void UI::init() { @@ -31,6 +30,7 @@ namespace storyboard { zoom($zoom_target); } + $view_texture.clear(); $ui.render($view_texture); $ui.debug_layout($view_texture); $view_texture.display(); @@ -38,17 +38,13 @@ namespace storyboard { } bool UI::mouse(float x, float y, guecs::Modifiers mods) { + auto& cell = $ui.cell_for($zoom_target); + $camera.position(cell.mid_x, cell.mid_y); - if(zoomed) { - zoomed = false; - reset(); - } else { - zoomed = true; - auto target = $ui.$parser.hit(x, y); - $zoom_target = *target; - zoom($zoom_target); - $camera.play(); - } + $zoom_target = *$ui.$parser.hit(x, y); + + zoom($zoom_target); + $camera.play(); return $ui.mouse(x, y, mods); } diff --git a/storyboard/ui.hpp b/storyboard/ui.hpp index 17f17ab..e819d0a 100644 --- a/storyboard/ui.hpp +++ b/storyboard/ui.hpp @@ -10,8 +10,7 @@ namespace storyboard { sf::RenderTexture $view_texture; sf::Sprite $view_sprite; cinematic::Camera $camera; - std::string $zoom_target; - bool zoomed = false; + std::string $zoom_target = "a"; UI();