Can now apply a shader using the animation's timer but not sure if there should be shaders on animations or outside or both.
This commit is contained in:
parent
0d481a5ab7
commit
80f100f223
5 changed files with 29 additions and 10 deletions
|
|
@ -50,10 +50,16 @@ namespace animate2 {
|
||||||
sprite.setTextureRect(rect);
|
sprite.setTextureRect(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Animate2::apply_effect(std::shared_ptr<sf::Shader> effect) {
|
||||||
|
dbc::check(effect != nullptr, "can't apply null effect");
|
||||||
|
effect->setUniform("u_time", sequence.timer.getElapsedTime().asSeconds());
|
||||||
|
sf::Vector2f u_resolution{float(sheet.frame_width), float(sheet.frame_height)};
|
||||||
|
effect->setUniform("u_resolution", u_resolution);
|
||||||
|
}
|
||||||
|
|
||||||
void Animate2::play_sound() {
|
void Animate2::play_sound() {
|
||||||
// BUG: this can be optimized way better
|
// BUG: this can be optimized way better
|
||||||
if(sounds.contains(form_name)) {
|
if(sounds.contains(form_name)) {
|
||||||
fmt::println("Playing sound for {}", form_name);
|
|
||||||
for(auto& [at_frame, sound_name] : sounds.at(form_name)) {
|
for(auto& [at_frame, sound_name] : sounds.at(form_name)) {
|
||||||
if(sequence.current == at_frame) {
|
if(sequence.current == at_frame) {
|
||||||
sound::play(sound_name);
|
sound::play(sound_name);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
#include <SFML/Graphics/Rect.hpp>
|
||||||
#include <SFML/Graphics/Sprite.hpp>
|
#include <SFML/Graphics/Sprite.hpp>
|
||||||
|
#include <SFML/Graphics/Shader.hpp>
|
||||||
#include <SFML/System/Clock.hpp>
|
#include <SFML/System/Clock.hpp>
|
||||||
#include <SFML/System/Time.hpp>
|
#include <SFML/System/Time.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
@ -116,6 +117,7 @@ namespace animate2 {
|
||||||
bool has_form(const std::string& as_form);
|
bool has_form(const std::string& as_form);
|
||||||
void set_form(const std::string& form);
|
void set_form(const std::string& form);
|
||||||
void apply(sf::Sprite& sprite);
|
void apply(sf::Sprite& sprite);
|
||||||
|
void apply_effect(std::shared_ptr<sf::Shader> effect);
|
||||||
void update_frame();
|
void update_frame();
|
||||||
void update();
|
void update();
|
||||||
void motion(sf::Sprite& sprite, sf::Vector2f pos, sf::Vector2f scale);
|
void motion(sf::Sprite& sprite, sf::Vector2f pos, sf::Vector2f scale);
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,6 @@ namespace scene {
|
||||||
void Engine::apply_effect(const std::string& actor, const std::string& shader) {
|
void Engine::apply_effect(const std::string& actor, const std::string& shader) {
|
||||||
auto& element = actor_config(actor);
|
auto& element = actor_config(actor);
|
||||||
element.effect = shaders::get(shader);
|
element.effect = shaders::get(shader);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::attach_text(const std::string& actor, const std::string& text) {
|
void Engine::attach_text(const std::string& actor, const std::string& text) {
|
||||||
|
|
|
||||||
|
|
@ -38,11 +38,10 @@ namespace animator {
|
||||||
$window.setPosition({0,0});
|
$window.setPosition({0,0});
|
||||||
|
|
||||||
$ui.init($sprite_name, $background, new_size.x, new_size.y);
|
$ui.init($sprite_name, $background, new_size.x, new_size.y);
|
||||||
$sprite = $ui.get_sprite();
|
|
||||||
|
|
||||||
// need to keep these around
|
// need to keep these around
|
||||||
$pos = $sprite->getPosition();
|
$pos = $ui.sprite->getPosition();
|
||||||
$scale = $sprite->getScale();
|
$scale = $ui.sprite->getScale();
|
||||||
|
|
||||||
if(YES_SYNC) {
|
if(YES_SYNC) {
|
||||||
$window.setVerticalSyncEnabled(VSYNC);
|
$window.setVerticalSyncEnabled(VSYNC);
|
||||||
|
|
@ -95,6 +94,9 @@ namespace animator {
|
||||||
$ui.update_status($anim);
|
$ui.update_status($anim);
|
||||||
state(State::START);
|
state(State::START);
|
||||||
break;
|
break;
|
||||||
|
case Event::TEST_SHADER:
|
||||||
|
$ui.effect = $ui.effect == nullptr ? shaders::get("flame") : nullptr;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
state(State::START);
|
state(State::START);
|
||||||
}
|
}
|
||||||
|
|
@ -129,8 +131,9 @@ namespace animator {
|
||||||
void FSM::run_animation() {
|
void FSM::run_animation() {
|
||||||
if($anim.playing) {
|
if($anim.playing) {
|
||||||
$anim.update();
|
$anim.update();
|
||||||
$anim.apply(*$sprite);
|
$anim.apply(*$ui.sprite);
|
||||||
$anim.motion(*$sprite, $pos, $scale);
|
if($ui.effect != nullptr) $anim.apply_effect($ui.effect);
|
||||||
|
$anim.motion(*$ui.sprite, $pos, $scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -209,6 +212,8 @@ namespace animator {
|
||||||
} else if($router.scancode == KEY::M) {
|
} else if($router.scancode == KEY::M) {
|
||||||
$mute = !$mute;
|
$mute = !$mute;
|
||||||
sound::mute($mute);
|
sound::mute($mute);
|
||||||
|
} else if($router.scancode == KEY::S) {
|
||||||
|
event(Event::TEST_SHADER);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MOUSE_CLICK:
|
case MOUSE_CLICK:
|
||||||
|
|
@ -246,9 +251,13 @@ namespace animator {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto viewer = $ui.entity("viewer");
|
auto viewer = $ui.entity("viewer");
|
||||||
|
// BUG: this is some jank bullshit but it works
|
||||||
$ui.set<guecs::Sprite>(viewer, {sprite_name, 0, false});
|
$ui.set<guecs::Sprite>(viewer, {sprite_name, 0, false});
|
||||||
|
|
||||||
$ui.init();
|
$ui.init();
|
||||||
|
sprite = $ui.get<guecs::Sprite>(viewer).sprite;
|
||||||
|
dbc::check(sprite != nullptr, "failed to initialize $ui.sprite");
|
||||||
|
|
||||||
|
$ui.remove<guecs::Sprite>(viewer);
|
||||||
|
|
||||||
$overlay.position(0, 0, width/4, height/4);
|
$overlay.position(0, 0, width/4, height/4);
|
||||||
$overlay.layout(
|
$overlay.layout(
|
||||||
|
|
@ -264,6 +273,7 @@ namespace animator {
|
||||||
|
|
||||||
void UI::render(sf::RenderWindow& window, bool debug) {
|
void UI::render(sf::RenderWindow& window, bool debug) {
|
||||||
$ui.render(window);
|
$ui.render(window);
|
||||||
|
window.draw(*sprite, effect.get());
|
||||||
$overlay.render(window);
|
$overlay.render(window);
|
||||||
|
|
||||||
if(debug) {
|
if(debug) {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ namespace animator {
|
||||||
PLAY_STOP=__LINE__,
|
PLAY_STOP=__LINE__,
|
||||||
NEXT_FORM=__LINE__,
|
NEXT_FORM=__LINE__,
|
||||||
PREV_FORM=__LINE__,
|
PREV_FORM=__LINE__,
|
||||||
|
TEST_SHADER=__LINE__,
|
||||||
RELOAD=__LINE__,
|
RELOAD=__LINE__,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -26,6 +27,8 @@ namespace animator {
|
||||||
struct UI {
|
struct UI {
|
||||||
guecs::UI $ui;
|
guecs::UI $ui;
|
||||||
guecs::UI $overlay;
|
guecs::UI $overlay;
|
||||||
|
std::shared_ptr<sf::Sprite> sprite = nullptr;
|
||||||
|
std::shared_ptr<sf::Shader> effect = nullptr;
|
||||||
bool $initialized_this_sucks_ass = false;
|
bool $initialized_this_sucks_ass = false;
|
||||||
|
|
||||||
void button(const std::string& name, std::function<void(guecs::Modifiers mods)> cb);
|
void button(const std::string& name, std::function<void(guecs::Modifiers mods)> cb);
|
||||||
|
|
@ -44,7 +47,6 @@ namespace animator {
|
||||||
sf::RenderWindow $window;
|
sf::RenderWindow $window;
|
||||||
sf::Vector2f $pos{0,0};
|
sf::Vector2f $pos{0,0};
|
||||||
sf::Vector2f $scale{0,0};
|
sf::Vector2f $scale{0,0};
|
||||||
std::shared_ptr<sf::Sprite> $sprite = nullptr;
|
|
||||||
animate2::Animate2 $anim;
|
animate2::Animate2 $anim;
|
||||||
std::string $sprite_name="";
|
std::string $sprite_name="";
|
||||||
std::string $anim_name="";
|
std::string $anim_name="";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue