Page MenuHome

BKE UndoSys refactor: deduplicate and simplify code, sanitize naming.
ClosedPublic

Authored by Bastien Montagne (mont29) on Jan 27 2021, 6:29 PM.

Details

Summary

Now we only use 'undo' or 'redo' in function names when the direction is
clear (and we assert about it). Otherwise, use 'load' instead.

When passing an undo step to BKE functions, consider calling code has
done its work and is actually passing the target step (i.e. the final
step intended to be loaded), instead of assuming we have to load the
step before/after it.

Also deduplicate and simplify a lot of core undo code in BKE, now
BKE_undosys_step_load_data_ex is the only place where all the complex
logic of undo/redo loop (to handle several steps in a row) is placed. We also
only use a single loop there, instead of the two existing ones in
previous code.

Note that here we consider that when we are loading the current active
step, we are undoing. This makes sense in that doing so may undo
some changes (ideally it should never do so), but should never, ever
redo anything.

BKE_undosys_step_load_from_index also gets heavily simplified, it's
not basically a shallow wrapper around
BKE_undosys_step_load_from_index.

And some general update of variable names, commenting, etc.

Part of T83806.


NOTE: We have to move eUndoStepDir to BKE_undo_system.c, so that we can get rid of 'magical' values everywhere, including in all the lower-level implementations of actual undo types. Will do in a separate cleanup commit though.

Diff Detail

Repository
rB Blender

Event Timeline

Bastien Montagne (mont29) requested review of this revision.Jan 27 2021, 6:29 PM

Looks good, noted minor issues in patch (fine to commit once their handled).

Ran undo tests, one is failing (tsk) but this isn't caused by this patch.

source/blender/blenkernel/intern/undo_system.c
680–682

*picky* prefer the name BKE_undosys_step_calc_direction, as finding is typically finding a thing and returning it (needle/haystack ... etc), where is this calculates value instead.

696–720

Early returns could be used here (since it seems unlikely we ever want to perform any special cleanup's at the end).

Then we could assert if end is ever reached, since this points to corrupt undo data.

846

More phab syntax in doxy, see related comment (also double space).

887

*picky*: the comment could say if the step it's self is loaded or not, these kinds of fence post errors can trip us up. Better note in code comments (same for other top-level functions that load until a given step).

889

Mixing phab syntax highlighting in doxy! **after** or _after_ can be used instead.

source/blender/editors/undo/ed_undo.c
326

Missing bracket.

This revision is now accepted and ready to land.Feb 3 2021, 10:14 AM
Bastien Montagne (mont29) marked 6 inline comments as done.Feb 3 2021, 10:49 AM