From 83f62e3f45a234dcceaaae2ad05438e299dff0b2 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Tue, 24 Feb 2026 11:14:16 -0500 Subject: [PATCH] Move the step_animation out of the animate2 module since it's only used in raycaster.cpp. --- animate2.cpp | 13 +++---------- animate2.hpp | 3 --- raycaster.cpp | 20 ++++++++++++++++---- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/animate2.cpp b/animate2.cpp index fce2e06..77e3017 100644 --- a/animate2.cpp +++ b/animate2.cpp @@ -289,17 +289,10 @@ namespace animate2 { } } - void step_animation(DinkyECS::World& world, DinkyECS::Entity entity, sf::Sprite& sprite) { - if(auto anim = world.get_if(entity)) { - if(anim->playing) { - anim->update(); - anim->apply(sprite); - } - } - } - void animate_entity(DinkyECS::World &world, DinkyECS::Entity entity) { - if(auto anim = world.get_if(entity)) { + auto anim = world.get_if(entity); + + if(anim != nullptr && !anim->playing) { anim->play(); } } diff --git a/animate2.hpp b/animate2.hpp index a63b54d..bb81447 100644 --- a/animate2.hpp +++ b/animate2.hpp @@ -138,11 +138,8 @@ namespace animate2 { void configure(DinkyECS::World& world, DinkyECS::Entity entity); - void step_animation(DinkyECS::World& world, DinkyECS::Entity entity, sf::Sprite& sprite); - void animate_entity(DinkyECS::World &world, DinkyECS::Entity entity); - ENROLL_COMPONENT(Sheet, frames, frame_width, frame_height); ENROLL_COMPONENT(Sequence, frames, durations); ENROLL_COMPONENT(Transform, min_x, min_y, max_x, max_y, diff --git a/raycaster.cpp b/raycaster.cpp index 048f6b0..b62804b 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -101,6 +101,20 @@ void Raycaster::apply_sprite_effect(shared_ptr effect, float width, 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) { + auto anim = world.get_if(entity); + + if(anim != nullptr && anim->playing) { + anim->update(); + anim->apply(sprite); + anim->motion(sprite, position, scale); + } + + sprite.setScale(scale); + sprite.setPosition(position); +} + + void Raycaster::sprite_casting(sf::RenderTarget &target) { auto& lights = $level.lights->lighting(); auto world = $level.world; @@ -202,10 +216,7 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) { effect->setUniform("darkness", level); } - sf_sprite->setScale(scale); - sf_sprite->setPosition(position); - - animate2::step_animation(*world, rec.entity, *sf_sprite); + step_animation(*world, rec.entity, *sf_sprite, position, scale); sf_sprite->setOrigin(origin); sf_sprite->setTextureRect(in_texture); @@ -215,6 +226,7 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) { } } + void Raycaster::cast_rays() { constexpr static const int texture_width = TEXTURE_WIDTH; constexpr static const int texture_height = TEXTURE_HEIGHT;