Skip to content

Add smooth-movement plugin - #5875

Open
notliad wants to merge 6 commits into
DFHack:developfrom
notliad:plugin/smooth-movement
Open

Add smooth-movement plugin#5875
notliad wants to merge 6 commits into
DFHack:developfrom
notliad:plugin/smooth-movement

Conversation

@notliad

@notliad notliad commented Aug 13, 2026

Copy link
Copy Markdown

Summary

Adds the smooth-movement plugin to DFHack. It provides smooth visual interpolation for creatures, items, vehicles, and related overlays in the fortress viewport.

Notes

I closed the previous PR in favor of this version, which preserves the original code structure that was already reviewed by humans in the standalone repository.

Standalone repository: https://github.com/notliad/df-smooth-movement

Testing

  • Built the smooth-movement plugin through the DFHack build system.
  • Built and ran smooth-movement-test.
  • All regression assertions passed.

Comment thread plugins/smooth-movement/smooth-movement.cpp Outdated
Comment thread plugins/smooth-movement/smooth-movement.cpp Outdated
Comment thread plugins/smooth-movement/smooth-movement.cpp Outdated
Comment thread plugins/smooth-movement/smooth-movement.cpp Outdated
Comment thread plugins/smooth-movement/visual_animation.h
@ab9rf

ab9rf commented Aug 13, 2026

Copy link
Copy Markdown
Member

A general comment as this is a pervasive issue and I do not wish to pepper the review with dozens if not hundreds of comments: there are a lot of operations in here that work on (x,y) coordinate pairs that involve effectively duplicated code. DFHack has a 2d coordinate type df::coord2d that can be used to store a coordinate pair as a unit and operate on both components in parallel. Consider using df::coord2d in lieu of separate x and y variables wherever possible as this provides clearer indication of intention as well as reducing the risk of updating one but not the other resulting in inconsistent behavior.

I've made some other specific comments but this should not be considered a full review.

@notliad

notliad commented Aug 13, 2026

Copy link
Copy Markdown
Author

A general comment as this is a pervasive issue and I do not wish to pepper the review with dozens if not hundreds of comments: there are a lot of operations in here that work on (x,y) coordinate pairs that involve effectively duplicated code. DFHack has a 2d coordinate type df::coord2d that can be used to store a coordinate pair as a unit and operate on both components in parallel. Consider using df::coord2d in lieu of separate x and y variables wherever possible as this provides clearer indication of intention as well as reducing the risk of updating one but not the other resulting in inconsistent behavior.

I've made some other specific comments but this should not be considered a full review.

This will be a substantial refactor. I will look into it and the others comments as well.
I'm bit worried making lots of changes cause I can't reproduce (on both of my machines) the most common bug and need someone to test it for me, this can take a day or two.

@notliad

notliad commented Aug 14, 2026

Copy link
Copy Markdown
Author

Camera feature was not working properly and introduced a mouse click bug so I opted to remove it.

Edit: forgot to tag @ab9rf

@ab9rf ab9rf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this is not a complete review - i'll make another pass after these comments are addressed


bool operator==(const visual_contextst &) const = default;
};
visual_contextst previous_visual_context{};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line here please

}
}

constexpr uint32_t fire_bits = 0x70000000U;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a magic number. please construct this out of published constants

// On a pure pan the reset signature is unchanged, but last frame's blackout
// coverage is in the old viewport frame, so discard it (the engine repaints
// the whole scrolled viewport anyway).
const int32_t pan_x = window_x ? *window_x : 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be const coord2d pan with an appropriate initializer?

previous_coverage.clear();
previous_pan_x = pan_x;
previous_pan_y = pan_y;
previous_pan.x = pan_x;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previous_pan = pan with pan initialized as mentioned above

float source_y;
int32_t target_x;
int32_t target_y;
point2dst<float> source;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toady likes the silly nonsense of putting st after structure names, but imo it detracts from readability here. consider renaming the point2d template class without toady's st suffix on types, which DFHack has no love for and is absolutely not required for DFHack-defined types

// hypothesis-tested each frame to find where it lands. Detection stays
// suppressed until then: a shifted buffer makes every panned creature look
// like a real move.
if (state.has_pan && (state.pan.x != input.pan.x || state.pan.y != input.pan.y)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state.pan == input.pan

reset_facing(state);
}
state.pending.push_back({input.pan_x - state.pan_x, input.pan_y - state.pan_y});
state.pending.emplace_back(input.pan.x - state.pan.x, input.pan.y - state.pan.y);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably be emplace_back(input.pan - state.pan) but might need to be emplace instead, in any case use the operator overloads, that's what they're for

// changes, and while paused hardly at all. Re-reading a landed scroll steps
// every sprite by a tile.
const uint64_t signature = compute_buffer_signature(input);
const bool buffers_advanced =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this to me advertise that buffer_signature should be a std::optional

// A prefix netting to zero is indistinguishable from "nothing landed yet".
// Accepting it would retire shifts the buffers have still to apply.
if (shift[0] == 0 && shift[1] == 0)
shift.x += state.pending[count - 1].x;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use coord2d operator overload here

// A prefix netting to zero is indistinguishable from "nothing landed
// yet". Accepting it would retire shifts the buffers have still to
// apply.
if (shift.x == 0 && shift.y == 0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (shift == {0,0})

@ab9rf

ab9rf commented Aug 18, 2026

Copy link
Copy Markdown
Member

Edit: forgot to tag @ab9rf

not necessary to tag me, i'm notified on all activity on dfhack repositories

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants