Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2021-02-05 00:03:39 +0300
committerBastien Montagne <bastien@blender.org>2021-02-05 00:03:39 +0300
commit94cf74afbb1329a9ff099e2ebd7f43ed8313f9ec (patch)
tree6859715425521345f93993ecdcf7182b060ac236 /source/blender/blenkernel/intern
parent7d5640ee101e6b9ddbd9f534539ae939f68bfd9b (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/blenkernel/intern')
-rw-r--r--source/blender/blenkernel/intern/blender_undo.c5
-rw-r--r--source/blender/blenkernel/intern/blendfile.c3
-rw-r--r--source/blender/blenkernel/intern/undo_system.c28
3 files changed, 21 insertions, 15 deletions
diff --git a/source/blender/blenkernel/intern/blender_undo.c b/source/blender/blenkernel/intern/blender_undo.c
index 9e061b1ac69..d826aaf24e3 100644
--- a/source/blender/blenkernel/intern/blender_undo.c
+++ b/source/blender/blenkernel/intern/blender_undo.c
@@ -48,6 +48,7 @@
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_main.h"
+#include "BKE_undo_system.h"
#include "BLO_readfile.h"
#include "BLO_undofile.h"
@@ -62,7 +63,7 @@
#define UNDO_DISK 0
bool BKE_memfile_undo_decode(MemFileUndoData *mfu,
- const int undo_direction,
+ const eUndoStepDir undo_direction,
const bool use_old_bmain_data,
bContext *C)
{
@@ -80,7 +81,7 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu,
}
else {
struct BlendFileReadParams params = {0};
- params.undo_direction = undo_direction > 0 ? 1 : -1;
+ params.undo_direction = undo_direction;
if (!use_old_bmain_data) {
params.skip_flags |= BLO_READ_SKIP_UNDO_OLD_MAIN;
}
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index 49475c014cd..32710c4fa60 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -57,6 +57,7 @@
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_studiolight.h"
+#include "BKE_undo_system.h"
#include "BKE_workspace.h"
#include "BLO_readfile.h"
@@ -148,7 +149,7 @@ static void setup_app_data(bContext *C,
LOAD_UNDO,
} mode;
- if (params->undo_direction != 0) {
+ if (params->undo_direction != STEP_INVALID) {
BLI_assert(bfd->curscene != NULL);
mode = LOAD_UNDO;
}
diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c
index 643510cf652..07e7d07f1ef 100644
--- a/source/blender/blenkernel/intern/undo_system.c
+++ b/source/blender/blenkernel/intern/undo_system.c
@@ -176,8 +176,12 @@ static bool undosys_step_encode(bContext *C, Main *bmain, UndoStack *ustack, Und
return ok;
}
-static void undosys_step_decode(
- bContext *C, Main *bmain, UndoStack *ustack, UndoStep *us, int dir, bool is_final)
+static void undosys_step_decode(bContext *C,
+ Main *bmain,
+ UndoStack *ustack,
+ UndoStep *us,
+ const eUndoStepDir dir,
+ bool is_final)
{
CLOG_INFO(&LOG, 2, "addr=%p, name='%s', type='%s'", us, us->name, us->type->name);
@@ -677,9 +681,9 @@ UndoStep *BKE_undosys_step_find_by_type(UndoStack *ustack, const UndoType *ut)
*
* \return -1 for undo, 1 for redo, 0 in case of error.
*/
-int BKE_undosys_step_calc_direction(const UndoStack *ustack,
- const UndoStep *us_target,
- const UndoStep *us_reference)
+eUndoStepDir BKE_undosys_step_calc_direction(const UndoStack *ustack,
+ const UndoStep *us_target,
+ const UndoStep *us_reference)
{
if (us_reference == NULL) {
us_reference = ustack->step_active;
@@ -694,26 +698,26 @@ int BKE_undosys_step_calc_direction(const UndoStack *ustack,
* to the end of the list, rather than its start. */
/* NOTE: in case target step is the active one, we assume we are in an undo case... */
if (ELEM(us_target, us_reference, us_reference->prev)) {
- return -1;
+ return STEP_UNDO;
}
if (us_target == us_reference->next) {
- return 1;
+ return STEP_REDO;
}
/* Search forward, and then backward. */
for (UndoStep *us_iter = us_reference->next; us_iter != NULL; us_iter = us_iter->next) {
if (us_iter == us_target) {
- return 1;
+ return STEP_REDO;
}
}
for (UndoStep *us_iter = us_reference->prev; us_iter != NULL; us_iter = us_iter->prev) {
if (us_iter == us_target) {
- return -1;
+ return STEP_UNDO;
}
}
BLI_assert(!"Target undo step not found, this should not happen and may indicate an undo stack corruption");
- return 0;
+ return STEP_INVALID;
}
/**
@@ -752,8 +756,8 @@ bool BKE_undosys_step_load_data_ex(UndoStack *ustack,
}
/* This considers we are in undo case if both `us_target` and `us_reference` are the same. */
- const int undo_dir = BKE_undosys_step_calc_direction(ustack, us_target, us_reference);
- BLI_assert(undo_dir != 0);
+ const eUndoStepDir undo_dir = BKE_undosys_step_calc_direction(ustack, us_target, us_reference);
+ BLI_assert(undo_dir != STEP_INVALID);
/* This will be the active step once the undo process is complete.
*