diff --git a/animate2.cpp b/animate2.cpp index 66f0e47..8ccf469 100644 --- a/animate2.cpp +++ b/animate2.cpp @@ -206,6 +206,10 @@ namespace animate2 { transform.motion_func = ease2::get_motion(transform.motion); } + void Animate2::apply(sf::View& view_out, sf::Vector2f pos, sf::Vector2f size) { + + } + Animate2 load(const std::string &file, const std::string &anim_name) { using nlohmann::json; std::ifstream infile(file); diff --git a/animate2.hpp b/animate2.hpp index 09f439d..8d19933 100644 --- a/animate2.hpp +++ b/animate2.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -117,6 +118,7 @@ namespace animate2 { bool has_form(const std::string& as_form); void set_form(const std::string& form); void apply(sf::Sprite& sprite); + void apply(sf::View& view_out, sf::Vector2f pos, sf::Vector2f size); void apply_effect(std::shared_ptr effect); void update(); void motion(sf::Sprite& sprite, sf::Vector2f pos, sf::Vector2f scale); diff --git a/assets/cameras.json b/assets/cameras.json index 4e971ed..f3a1519 100644 --- a/assets/cameras.json +++ b/assets/cameras.json @@ -1,74 +1,84 @@ { - "pan": { - "_type": "Animation", - "easing": 7, - "motion": 7, - "ease_rate": 0.001, - "min_x": 0.0, - "min_y": 0.0, - "max_x": 0.0, - "max_y": 0.0, - "simple": true, - "frames": 1, - "speed": 0.01, - "scaled": false, - "stationary": true, - "toggled": false, - "flipped": false, - "looped": false - }, - "shake": { - "_type": "Animation", - "easing": 6, - "motion": 1, - "ease_rate": 0.05, - "min_x": -10.0, - "min_y": -10.0, - "max_x": 10.0, - "max_y": 10.0, - "simple": true, - "frames": 1, - "speed": 0.01, - "scaled": false, - "stationary": true, - "toggled": false, - "flipped": false, - "looped": false - }, - "dolly": { - "_type": "Animation", - "easing": 1, - "motion": 0, - "ease_rate": 1.0, - "min_x": 0.8, - "min_y": 0.8, - "max_x": 1.0, - "max_y": 1.0, - "simple": true, - "frames": 1, - "speed": 0.1, - "scaled": true, - "stationary": true, - "toggled": false, - "flipped": false, - "looped": false - }, - "bounce": { - "_type": "Animation", - "easing": 4, - "motion": 2, - "ease_rate": 0.001, - "min_x": 0, - "min_y": -20, - "max_x": 0, - "max_y": 0, - "simple": true, - "frames": 1, - "speed": 0.01, - "scaled": false, - "stationary": true, - "toggled": false, - "flipped": false, - "looped": false + "cameras": { + "sheet": { + "frames": 1, + "frame_width": 1024, + "frame_height": 768 + }, + "sequences": { + "idle": {"frames": [0], "durations": [800] }, + "pan": {"frames": [0], "durations": [800] }, + "shake": {"frames": [0], "durations": [800] }, + "dolly": {"frames": [0], "durations": [800] }, + "bounce": {"frames": [0], "durations": [800] } + }, + "transforms": { + "pan": { + "min_x": 0.0, + "min_y": 0.0, + "max_x": 0.0, + "max_y": 0.0, + "flipped": false, + "ease_rate": 5.0, + "scaled": false, + "toggled": false, + "looped": false, + "easing": "linear", + "motion": "move_slide" + }, + "shake": { + "min_x": -10.0, + "min_y": -10.0, + "max_x": 10.0, + "max_y": 10.0, + "flipped": false, + "ease_rate": 5.0, + "scaled": false, + "toggled": false, + "looped": false, + "easing": "normal_dist", + "motion": "move_shake" + }, + "dolly": { + "min_x": 0.8, + "min_y": 0.8, + "max_x": 1.0, + "max_y": 1.0, + "flipped": false, + "ease_rate": 3.0, + "scaled": false, + "toggled": false, + "looped": false, + "easing": "sine", + "motion": "move_rush" + }, + "bounce": { + "min_x": 0, + "min_y": -20, + "max_x": 0, + "max_y": 0, + "flipped": false, + "ease_rate": 3.0, + "scaled": false, + "toggled": false, + "looped": false, + "easing": "in_out_back", + "motion": "move_bounce" + } + }, + "forms": { + "idle": ["idle", "idle"], + "pan": ["pan", "pan"], + "dolly": ["dolly", "dolly"], + "shake": ["shake", "shake"], + "bounce": ["bounce", "bounce"] + }, + "sounds": { + "idle": [], + "pan": [], + "dolly": [], + "shake": [], + "bounce": [] + } } } diff --git a/camera.cpp b/camera.cpp index 033635c..3647cfa 100644 --- a/camera.cpp +++ b/camera.cpp @@ -1,16 +1,16 @@ #include "camera.hpp" #include -#include "animation.hpp" #include #include "components.hpp" #include "config.hpp" #include +#include namespace cinematic { - using components::Animation, std::string, std::min, std::clamp; + using animate2::Animate2, std::string, std::min, std::clamp; struct CameraManager { - std::unordered_map animations; + std::unordered_map animations; }; static CameraManager MGR; @@ -18,18 +18,15 @@ namespace cinematic { void init() { if(!initialized) { - auto cameras = settings::get("cameras"); - for(auto &[name, data] : cameras.json().items()) { - auto anim = components::convert(data); - MGR.animations.try_emplace(name, anim); - } - + auto data = settings::get("cameras"); + auto anim = components::convert(data["cameras"]); + MGR.animations.try_emplace("main", anim); initialized = true; } } Camera::Camera(sf::Vector2f size) : - anim(MGR.animations.at("pan")), + anim(MGR.animations.at("main")), size(size), base_size(size), aimed_at{size.x/2, size.y/2}, @@ -63,7 +60,7 @@ namespace cinematic { } void Camera::style(const std::string &name) { - anim = MGR.animations.at(name); + anim.set_form(name); } void Camera::position(float x, float y) { @@ -76,12 +73,12 @@ namespace cinematic { going_to.y = clamp(y, camera_bounds.position.y, camera_bounds.size.y); // BUG: annoying special case - if(anim.motion == ease::SLIDE) { - anim.min_x = aimed_at.x; - anim.min_y = aimed_at.y; - anim.max_x = going_to.x; - anim.max_y = going_to.y; - } + //if(anim.motion == ease::SLIDE) { + // anim.min_x = aimed_at.x; + // anim.min_y = aimed_at.y; + // anim.max_x = going_to.x; + // anim.max_y = going_to.y; + //} } void Camera::reset(sf::RenderTexture& target) { diff --git a/camera.hpp b/camera.hpp index c9b6169..f7d1e67 100644 --- a/camera.hpp +++ b/camera.hpp @@ -1,10 +1,11 @@ #pragma once -#include "components.hpp" +#include "animate2.hpp" +#include "constants.hpp" #include namespace cinematic { struct Camera { - components::Animation anim; + animate2::Animate2 anim; sf::Vector2f size{SCREEN_WIDTH, SCREEN_HEIGHT}; sf::Vector2f base_size{SCREEN_WIDTH, SCREEN_HEIGHT}; sf::Vector2f aimed_at{0,0}; diff --git a/ease2.cpp b/ease2.cpp index 7e08149..1217c12 100644 --- a/ease2.cpp +++ b/ease2.cpp @@ -12,6 +12,10 @@ namespace ease2 { return 0.0; } + double linear(float tick) { + return tick; + } + double sine(double x) { // old one? return std::abs(std::sin(seq.subframe * ease_rate)); return (std::sin(x) + 1.0) / 2.0; @@ -107,6 +111,7 @@ namespace ease2 { {"random", random}, {"normal_dist", normal_dist}, {"none", none}, + {"linear", linear}, }; std::unordered_map map_of_motions{ diff --git a/scene.hpp b/scene.hpp index 54bb555..2831b98 100644 --- a/scene.hpp +++ b/scene.hpp @@ -8,6 +8,7 @@ #include "camera.hpp" #include #include "animate2.hpp" +#include "components.hpp" namespace scene { using std::shared_ptr; diff --git a/storyboard/ui.hpp b/storyboard/ui.hpp index 06ad6c4..4339197 100644 --- a/storyboard/ui.hpp +++ b/storyboard/ui.hpp @@ -3,6 +3,7 @@ #include #include "camera.hpp" #include +#include "components.hpp" namespace storyboard {