Entities in the world are now animated like before using the new animation system.
This commit is contained in:
parent
594be65f45
commit
779599f030
9 changed files with 85 additions and 79 deletions
|
|
@ -67,6 +67,22 @@ namespace animation {
|
||||||
rect_io.position.y += rect.position.y;
|
rect_io.position.y += rect.position.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Animation::motion(sf::Transformable& sprite, sf::Vector2f pos, sf::Vector2f scale) {
|
||||||
|
sequence.INVARIANT();
|
||||||
|
|
||||||
|
transform.apply(sequence, pos, scale);
|
||||||
|
|
||||||
|
if(transform.flipped) {
|
||||||
|
scale.x *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprite.setPosition(pos);
|
||||||
|
|
||||||
|
if(transform.scaled) {
|
||||||
|
sprite.setScale(scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Animation::motion(sf::View& view_out, sf::Vector2f pos, sf::Vector2f size) {
|
void Animation::motion(sf::View& view_out, sf::Vector2f pos, sf::Vector2f size) {
|
||||||
dbc::check(size.x > 1.0f && size.y > 1.0f, "motion size must be above 1.0 since it's not a ratio");
|
dbc::check(size.x > 1.0f && size.y > 1.0f, "motion size must be above 1.0 since it's not a ratio");
|
||||||
dbc::check(transform.flipped == false, "transform must be false, has no effect on View");
|
dbc::check(transform.flipped == false, "transform must be false, has no effect on View");
|
||||||
|
|
@ -141,22 +157,6 @@ namespace animation {
|
||||||
if(frame_change && onFrame != nullptr) onFrame();
|
if(frame_change && onFrame != nullptr) onFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animation::motion(sf::Transformable& sprite, sf::Vector2f pos, sf::Vector2f scale) {
|
|
||||||
sequence.INVARIANT();
|
|
||||||
|
|
||||||
transform.apply(sequence, pos, scale);
|
|
||||||
|
|
||||||
if(transform.flipped) {
|
|
||||||
scale.x *= -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sprite.setPosition(pos);
|
|
||||||
|
|
||||||
if(transform.scaled) {
|
|
||||||
sprite.setScale(scale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Timer::start() {
|
void Timer::start() {
|
||||||
clock.start();
|
clock.start();
|
||||||
prev_time = clock.getElapsedTime().asSeconds();
|
prev_time = clock.getElapsedTime().asSeconds();
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#include <SFML/System/Clock.hpp>
|
#include <SFML/System/Clock.hpp>
|
||||||
#include <SFML/System/Time.hpp>
|
#include <SFML/System/Time.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "ease2.hpp"
|
#include "easing.hpp"
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include "json_mods.hpp"
|
#include "json_mods.hpp"
|
||||||
#include <source_location>
|
#include <source_location>
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
"flipped": false,
|
"flipped": false,
|
||||||
"scaled": true,
|
"scaled": true,
|
||||||
"toggled": false,
|
"toggled": false,
|
||||||
"looped": true,
|
"looped": false,
|
||||||
"relative": false,
|
"relative": false,
|
||||||
"easing": "in_out_back",
|
"easing": "in_out_back",
|
||||||
"motion": "move_rush"
|
"motion": "move_rush"
|
||||||
|
|
@ -205,7 +205,7 @@
|
||||||
"frame_height": 256
|
"frame_height": 256
|
||||||
},
|
},
|
||||||
"sequences": {
|
"sequences": {
|
||||||
"idle": {"frames": [0,1,2], "durations": [5,5,5] }
|
"idle": {"frames": [0,1,2,1,0], "durations": [5,5,5,5,5] }
|
||||||
},
|
},
|
||||||
"transforms": {
|
"transforms": {
|
||||||
"basic": {
|
"basic": {
|
||||||
|
|
@ -214,10 +214,10 @@
|
||||||
"max_x": 1.0,
|
"max_x": 1.0,
|
||||||
"max_y": 1.0,
|
"max_y": 1.0,
|
||||||
"flipped": false,
|
"flipped": false,
|
||||||
"scaled": false,
|
"scaled": true,
|
||||||
"toggled": false,
|
"toggled": false,
|
||||||
"looped": false,
|
"looped": false,
|
||||||
"relative": false,
|
"relative": true,
|
||||||
"easing": "none",
|
"easing": "none",
|
||||||
"motion": "move_none"
|
"motion": "move_none"
|
||||||
}
|
}
|
||||||
|
|
@ -280,7 +280,7 @@
|
||||||
"max_x": 1.0,
|
"max_x": 1.0,
|
||||||
"max_y": 1.0,
|
"max_y": 1.0,
|
||||||
"flipped": false,
|
"flipped": false,
|
||||||
"scaled": false,
|
"scaled": true,
|
||||||
"toggled": false,
|
"toggled": false,
|
||||||
"looped": false,
|
"looped": false,
|
||||||
"relative": false,
|
"relative": false,
|
||||||
|
|
@ -304,21 +304,21 @@
|
||||||
"frame_height": 256
|
"frame_height": 256
|
||||||
},
|
},
|
||||||
"sequences": {
|
"sequences": {
|
||||||
"idle": {"frames": [0], "durations": [5] }
|
"idle": {"frames": [0], "durations": [50] }
|
||||||
},
|
},
|
||||||
"transforms": {
|
"transforms": {
|
||||||
"basic": {
|
"basic": {
|
||||||
"min_x": 0.9,
|
"min_x": 1.0,
|
||||||
"min_y": 0.9,
|
"min_y": 1.0,
|
||||||
"max_x": 1.0,
|
"max_x": 1.22,
|
||||||
"max_y": 1.0,
|
"max_y": 1.22,
|
||||||
"flipped": false,
|
"flipped": false,
|
||||||
"scaled": true,
|
"scaled": true,
|
||||||
"toggled": false,
|
"toggled": false,
|
||||||
"looped": true,
|
"looped": false,
|
||||||
"relative": false,
|
"relative": false,
|
||||||
"easing": "sine",
|
"easing": "in_out_back",
|
||||||
"motion": "move_rush"
|
"motion": "scale_both"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"forms": {
|
"forms": {
|
||||||
|
|
@ -341,17 +341,17 @@
|
||||||
},
|
},
|
||||||
"transforms": {
|
"transforms": {
|
||||||
"basic": {
|
"basic": {
|
||||||
"min_x": 0.9,
|
"min_x": 1.0,
|
||||||
"min_y": 0.9,
|
"min_y": 1.0,
|
||||||
"max_x": 1.0,
|
"max_x": 1.22,
|
||||||
"max_y": 1.0,
|
"max_y": 1.22,
|
||||||
"flipped": false,
|
"flipped": false,
|
||||||
"scaled": true,
|
"scaled": true,
|
||||||
"toggled": false,
|
"toggled": false,
|
||||||
"looped": true,
|
"looped": false,
|
||||||
"relative": false,
|
"relative": false,
|
||||||
"easing": "sine",
|
"easing": "sine",
|
||||||
"motion": "move_rush"
|
"motion": "scale_both"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"forms": {
|
"forms": {
|
||||||
|
|
@ -370,21 +370,21 @@
|
||||||
"frame_height": 256
|
"frame_height": 256
|
||||||
},
|
},
|
||||||
"sequences": {
|
"sequences": {
|
||||||
"idle": {"frames": [0], "durations": [5] }
|
"idle": {"frames": [0], "durations": [50] }
|
||||||
},
|
},
|
||||||
"transforms": {
|
"transforms": {
|
||||||
"basic": {
|
"basic": {
|
||||||
"min_x": 0.9,
|
"min_x": 1.0,
|
||||||
"min_y": 0.9,
|
"min_y": 1.0,
|
||||||
"max_x": 1.0,
|
"max_x": 1.22,
|
||||||
"max_y": 1.0,
|
"max_y": 1.22,
|
||||||
"flipped": false,
|
"flipped": false,
|
||||||
"scaled": true,
|
"scaled": true,
|
||||||
"toggled": false,
|
"toggled": false,
|
||||||
"looped": true,
|
"looped": false,
|
||||||
"relative": false,
|
"relative": false,
|
||||||
"easing": "sine",
|
"easing": "sine",
|
||||||
"motion": "move_rush"
|
"motion": "scale_both"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"forms": {
|
"forms": {
|
||||||
|
|
@ -403,21 +403,21 @@
|
||||||
"frame_height": 256
|
"frame_height": 256
|
||||||
},
|
},
|
||||||
"sequences": {
|
"sequences": {
|
||||||
"idle": {"frames": [0], "durations": [5] }
|
"idle": {"frames": [0], "durations": [50] }
|
||||||
},
|
},
|
||||||
"transforms": {
|
"transforms": {
|
||||||
"basic": {
|
"basic": {
|
||||||
"min_x": 0.9,
|
"min_x": 1.0,
|
||||||
"min_y": 0.9,
|
"min_y": 1.0,
|
||||||
"max_x": 1.0,
|
"max_x": 1.22,
|
||||||
"max_y": 1.0,
|
"max_y": 1.22,
|
||||||
"flipped": false,
|
"flipped": false,
|
||||||
"scaled": true,
|
"scaled": true,
|
||||||
"toggled": false,
|
"toggled": false,
|
||||||
"looped": true,
|
"looped": false,
|
||||||
"relative": false,
|
"relative": false,
|
||||||
"easing": "sine",
|
"easing": "sine",
|
||||||
"motion": "move_rush"
|
"motion": "scale_both"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"forms": {
|
"forms": {
|
||||||
|
|
@ -436,21 +436,21 @@
|
||||||
"frame_height": 256
|
"frame_height": 256
|
||||||
},
|
},
|
||||||
"sequences": {
|
"sequences": {
|
||||||
"idle": {"frames": [0], "durations": [5] }
|
"idle": {"frames": [0], "durations": [50] }
|
||||||
},
|
},
|
||||||
"transforms": {
|
"transforms": {
|
||||||
"basic": {
|
"basic": {
|
||||||
"min_x": 0.9,
|
"min_x": 1.0,
|
||||||
"min_y": 0.9,
|
"min_y": 1.0,
|
||||||
"max_x": 1.0,
|
"max_x": 1.11,
|
||||||
"max_y": 1.0,
|
"max_y": 1.11,
|
||||||
"flipped": false,
|
"flipped": false,
|
||||||
"scaled": true,
|
"scaled": true,
|
||||||
"toggled": false,
|
"toggled": false,
|
||||||
"looped": true,
|
"looped": false,
|
||||||
"relative": false,
|
"relative": false,
|
||||||
"easing": "sine",
|
"easing": "in_out_back",
|
||||||
"motion": "move_rush"
|
"motion": "scale_both"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"forms": {
|
"forms": {
|
||||||
|
|
@ -469,21 +469,21 @@
|
||||||
"frame_height": 256
|
"frame_height": 256
|
||||||
},
|
},
|
||||||
"sequences": {
|
"sequences": {
|
||||||
"idle": {"frames": [0], "durations": [5] }
|
"idle": {"frames": [0], "durations": [50] }
|
||||||
},
|
},
|
||||||
"transforms": {
|
"transforms": {
|
||||||
"basic": {
|
"basic": {
|
||||||
"min_x": 1.0,
|
"min_x": 1.0,
|
||||||
"min_y": 1.0,
|
"min_y": 1.0,
|
||||||
"max_x": 1.0,
|
"max_x": 1.22,
|
||||||
"max_y": 1.0,
|
"max_y": 1.22,
|
||||||
"flipped": false,
|
"flipped": false,
|
||||||
"scaled": false,
|
"scaled": true,
|
||||||
"toggled": false,
|
"toggled": false,
|
||||||
"looped": false,
|
"looped": false,
|
||||||
"relative": false,
|
"relative": false,
|
||||||
"easing": "none",
|
"easing": "none",
|
||||||
"motion": "move_none"
|
"motion": "scale_both"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"forms": {
|
"forms": {
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ namespace ease2 {
|
||||||
void move_none(Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative) {
|
void move_none(Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void scale_only(Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative) {
|
void scale_both(Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative) {
|
||||||
scale_out.x = std::lerp(scale_out.x * tr.min_x, scale_out.x * tr.max_x, tick) + (scale_out.x * relative);
|
scale_out.x = std::lerp(scale_out.x * tr.min_x, scale_out.x * tr.max_x, tick) + (scale_out.x * relative);
|
||||||
scale_out.y = std::lerp(scale_out.y * tr.min_y, scale_out.y * tr.max_y, tick) + (scale_out.y * relative);
|
scale_out.y = std::lerp(scale_out.y * tr.min_y, scale_out.y * tr.max_y, tick) + (scale_out.y * relative);
|
||||||
}
|
}
|
||||||
|
|
@ -123,7 +123,7 @@ namespace ease2 {
|
||||||
{"scale_grow", scale_grow},
|
{"scale_grow", scale_grow},
|
||||||
{"move_slide", move_slide},
|
{"move_slide", move_slide},
|
||||||
{"move_none", move_none},
|
{"move_none", move_none},
|
||||||
{"scale_only", scale_only},
|
{"scale_both", scale_both},
|
||||||
{"move_shake", move_shake},
|
{"move_shake", move_shake},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -27,6 +27,6 @@ namespace ease2 {
|
||||||
void scale_grow(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative);
|
void scale_grow(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative);
|
||||||
void move_slide(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative);
|
void move_slide(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative);
|
||||||
void move_none(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative);
|
void move_none(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative);
|
||||||
void scale_only(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative);
|
void scale_both(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative);
|
||||||
void move_shake(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative);
|
void move_shake(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative);
|
||||||
}
|
}
|
||||||
|
|
@ -133,7 +133,7 @@ sources = [
|
||||||
'systems.cpp',
|
'systems.cpp',
|
||||||
'textures.cpp',
|
'textures.cpp',
|
||||||
'worldbuilder.cpp',
|
'worldbuilder.cpp',
|
||||||
'ease2.cpp',
|
'easing.cpp',
|
||||||
]
|
]
|
||||||
|
|
||||||
executable('runtests', sources + [
|
executable('runtests', sources + [
|
||||||
|
|
|
||||||
|
|
@ -101,15 +101,15 @@ void Raycaster::apply_sprite_effect(shared_ptr<sf::Shader> effect, float width,
|
||||||
effect->setUniform("u_resolution", u_resolution);
|
effect->setUniform("u_resolution", u_resolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void step_animation(DinkyECS::World& world, DinkyECS::Entity entity, sf::Sprite& sprite, sf::Vector2f& position, sf::Vector2f& scale, sf::IntRect& in_texture, sf::Vector2f& origin) {
|
inline void step_animation(animation::Animation& anim, sf::Sprite& sprite, sf::Vector2f& position, sf::Vector2f& scale, sf::IntRect& in_texture, sf::Vector2f& origin) {
|
||||||
auto anim = world.get_if<animation::Animation>(entity);
|
anim.update();
|
||||||
|
anim.apply(sprite, in_texture);
|
||||||
if(anim != nullptr && anim->playing) {
|
anim.motion(sprite, position, scale);
|
||||||
anim->update();
|
sprite.setOrigin(origin);
|
||||||
anim->apply(sprite, in_texture);
|
sprite.setTextureRect(in_texture);
|
||||||
anim->motion(sprite, position, scale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void set_scale_position(sf::Sprite& sprite, sf::Vector2f& position, sf::Vector2f& scale, sf::IntRect& in_texture, sf::Vector2f& origin) {
|
||||||
sprite.setScale(scale);
|
sprite.setScale(scale);
|
||||||
sprite.setPosition(position);
|
sprite.setPosition(position);
|
||||||
sprite.setOrigin(origin);
|
sprite.setOrigin(origin);
|
||||||
|
|
@ -218,7 +218,13 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) {
|
||||||
effect->setUniform("darkness", level);
|
effect->setUniform("darkness", level);
|
||||||
}
|
}
|
||||||
|
|
||||||
step_animation(*world, rec.entity, *sf_sprite, position, scale, in_texture, origin);
|
auto anim = world->get_if<animation::Animation>(rec.entity);
|
||||||
|
|
||||||
|
if(anim != nullptr && anim->playing) {
|
||||||
|
step_animation(*anim, *sf_sprite, position, scale, in_texture, origin);
|
||||||
|
} else {
|
||||||
|
set_scale_position(*sf_sprite, position, scale, in_texture, origin);
|
||||||
|
}
|
||||||
|
|
||||||
target.draw(*sf_sprite, effect.get());
|
target.draw(*sf_sprite, effect.get());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ namespace animator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSM::check_update() {
|
void FSM::check_changed() {
|
||||||
if($timer.getElapsedTime().toDuration() > 500ms) {
|
if($timer.getElapsedTime().toDuration() > 500ms) {
|
||||||
try {
|
try {
|
||||||
auto mod_time = std::filesystem::last_write_time("assets/animation.json");
|
auto mod_time = std::filesystem::last_write_time("assets/animation.json");
|
||||||
|
|
@ -339,7 +339,7 @@ int main(int argc, char* argv[]) {
|
||||||
while(main.active()) {
|
while(main.active()) {
|
||||||
main.update();
|
main.update();
|
||||||
main.render();
|
main.render();
|
||||||
main.check_update();
|
main.check_changed();
|
||||||
main.handle_keyboard_mouse();
|
main.handle_keyboard_mouse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ namespace animator {
|
||||||
bool active();
|
bool active();
|
||||||
void update();
|
void update();
|
||||||
void reload();
|
void reload();
|
||||||
void check_update();
|
void check_changed();
|
||||||
void change_form(int direction);
|
void change_form(int direction);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue