diff options
author | Bastien Montagne <bastien@blender.org> | 2021-02-05 00:03:39 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2021-02-05 00:03:39 +0300 |
commit | 94cf74afbb1329a9ff099e2ebd7f43ed8313f9ec (patch) | |
tree | 6859715425521345f93993ecdcf7182b060ac236 /source/blender/blenloader | |
parent | 7d5640ee101e6b9ddbd9f534539ae939f68bfd9b (diff) |
Cleanup/refactor: Undosys: Get rid of the magic values for undo direction.
Move `eUndoStepDir` to `BKE_undo_system.h` and use its values
everywhere.
Note that this also introduce the `STEP_INVALID` value in that enum.
Finally, kept the matching struct members in some lower-level readfile
code as an `int` to avoid having to include `BKE_undo_system.h` in a lot
of unrelated files.
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r-- | source/blender/blenloader/BLO_readfile.h | 4 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 16 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.h | 2 |
3 files changed, 12 insertions, 10 deletions
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h index 7dbe73cbd6a..237294a6017 100644 --- a/source/blender/blenloader/BLO_readfile.h +++ b/source/blender/blenloader/BLO_readfile.h @@ -84,8 +84,8 @@ struct BlendFileReadParams { uint skip_flags : 3; /* eBLOReadSkip */ uint is_startup : 1; - /** Whether we are reading the memfile for an undo (< 0) or a redo (> 0). */ - int undo_direction : 2; + /** Whether we are reading the memfile for an undo or a redo. */ + int undo_direction; /* eUndoStepDir */ }; /* skip reading some data-block types (may want to skip screen data too). */ diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 2192e9a378f..a63d95c1823 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -94,6 +94,7 @@ #include "BKE_report.h" #include "BKE_scene.h" #include "BKE_screen.h" +#include "BKE_undo_system.h" #include "BKE_workspace.h" #include "DRW_engine.h" @@ -1294,12 +1295,12 @@ static ssize_t fd_read_from_memfile(FileData *filedata, seek += readsize; if (r_is_memchunck_identical != NULL) { /* `is_identical` of current chunk represents whether it changed compared to previous undo - * step. this is fine in redo case (filedata->undo_direction > 0), but not in undo case, - * where we need an extra flag defined when saving the next (future) step after the one we - * want to restore, as we are supposed to 'come from' that future undo step, and not the - * one before current one. */ - *r_is_memchunck_identical &= filedata->undo_direction > 0 ? chunk->is_identical : - chunk->is_identical_future; + * step. this is fine in redo case, but not in undo case, where we need an extra flag + * defined when saving the next (future) step after the one we want to restore, as we are + * supposed to 'come from' that future undo step, and not the one before current one. */ + *r_is_memchunck_identical &= filedata->undo_direction == STEP_REDO ? + chunk->is_identical : + chunk->is_identical_future; } } while (totread < size); @@ -2400,11 +2401,12 @@ static int direct_link_id_restore_recalc(const FileData *fd, /* Tags that were set between the target state and the current state, * that we need to perform again. */ - if (fd->undo_direction < 0) { + if (fd->undo_direction == STEP_UNDO) { /* Undo: tags from target to the current state. */ recalc |= id_current->recalc_up_to_undo_push; } else { + BLI_assert(fd->undo_direction == STEP_REDO); /* Redo: tags from current to the target state. */ recalc |= id_target->recalc_up_to_undo_push; } diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h index 86f05eda7b7..e007d42b283 100644 --- a/source/blender/blenloader/intern/readfile.h +++ b/source/blender/blenloader/intern/readfile.h @@ -91,7 +91,7 @@ typedef struct FileData { struct MemFile *memfile; /** Whether we are undoing (< 0) or redoing (> 0), used to choose which 'unchanged' flag to use * to detect unchanged data from memfile. */ - short undo_direction; + int undo_direction; /* eUndoStepDir */ /** Variables needed for reading from file. */ gzFile gzfiledes; |