Refine how the raycaster.cpp uses animations so there's less back-and-forth on the intrect.

This commit is contained in:
Zed A. Shaw 2026-02-24 22:51:55 -05:00
parent cded8a937e
commit 594be65f45
3 changed files with 18 additions and 5 deletions

View file

@ -50,10 +50,23 @@ namespace animation {
dbc::check(sequence.current < $frame_rects.size(), "current frame past $frame_rects");
// NOTE: pos is not updated yet
auto& rect = $frame_rects.at(sequence.current);
fmt::println("setting texture rect: {},{}", rect.position.x, rect.position.y);
sprite.setTextureRect(rect);
}
/*
* Alternative mostly used in raycaster.cpp that
* DOES NOT setTextureRect() but just points
* the rect_io at the correct frame, but leaves
* it's size and base position alone.
*/
void Animation::apply(sf::Sprite& sprite, sf::IntRect& rect_io) {
dbc::check(sequence.current < $frame_rects.size(), "current frame past $frame_rects");
auto& rect = $frame_rects.at(sequence.current);
rect_io.position.x += rect.position.x;
rect_io.position.y += rect.position.y;
}
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(transform.flipped == false, "transform must be false, has no effect on View");
@ -246,6 +259,7 @@ namespace animation {
Animation anim;
animation::from_json(data[anim_name], anim);
anim.name = anim_name;
dbc::check(anim.forms.contains("idle"),
fmt::format("animation {} must have 'idle' form", anim_name));