[Bf-blender-cvs] [e535ff44ffd] master: Undo System: remove accumulate/store modes
Campbell Barton
noreply at git.blender.org
Wed Feb 6 02:48:33 CET 2019
Commit: e535ff44ffd686def7aafec401acec657f5a614c
Author: Campbell Barton
Date: Tue Feb 5 14:24:11 2019 +1100
Branches: master
https://developer.blender.org/rBe535ff44ffd686def7aafec401acec657f5a614c
Undo System: remove accumulate/store modes
This complicated handling of undo steps in a generic way
especially switching between undo systems that stored data to ones
that accumulated changes.
Now each undo system must treat it's steps as check-point,
internally it can apply/rewind changes.
This commit also fixes projection paint where the object mode wasn't
following the undo steps.
===================================================================
M source/blender/blenkernel/BKE_undo_system.h
M source/blender/blenkernel/intern/undo_system.c
M source/blender/editors/armature/editarmature_undo.c
M source/blender/editors/curve/editcurve_undo.c
M source/blender/editors/curve/editfont_undo.c
M source/blender/editors/include/ED_paint.h
M source/blender/editors/lattice/editlattice_undo.c
M source/blender/editors/mesh/editmesh_undo.c
M source/blender/editors/metaball/editmball_undo.c
M source/blender/editors/physics/particle_edit_undo.c
M source/blender/editors/sculpt_paint/paint_curve_undo.c
M source/blender/editors/sculpt_paint/paint_image.c
M source/blender/editors/sculpt_paint/paint_image_proj.c
M source/blender/editors/sculpt_paint/paint_image_undo.c
M source/blender/editors/sculpt_paint/sculpt_undo.c
M source/blender/editors/space_image/image_ops.c
M source/blender/editors/space_text/text_undo.c
M source/blender/editors/undo/memfile_undo.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_undo_system.h b/source/blender/blenkernel/BKE_undo_system.h
index 2b1c67f372b..15f4bac17a9 100644
--- a/source/blender/blenkernel/BKE_undo_system.h
+++ b/source/blender/blenkernel/BKE_undo_system.h
@@ -72,24 +72,11 @@ typedef struct UndoStep {
bool skip;
/** Some situations require the global state to be stored, edge cases when exiting modes. */
bool use_memfile_step;
+ /** For use by undo systems that accumulate changes (text editor, painting). */
+ bool is_applied;
/* Over alloc 'type->struct_size'. */
} UndoStep;
-typedef enum eUndoTypeMode {
- /**
- * Each undo step stores a version of the state.
- * This means we can simply load in a previous state at any time.
- */
- BKE_UNDOTYPE_MODE_STORE = 1,
- /**
- * Each undo step is a series of edits.
- * This means to change states we need to apply each edit.
- * It also means the 'step_decode' callback needs to detect the difference between undo and redo.
- * (Currently used for text edit and image & sculpt painting).
- */
- BKE_UNDOTYPE_MODE_ACCUMULATE = 2,
-} eUndoTypeMode;
-
typedef void (*UndoTypeForEachIDRefFn)(void *user_data, struct UndoRefID *id_ref);
typedef struct UndoType {
@@ -122,7 +109,6 @@ typedef struct UndoType {
void (*step_foreach_ID_ref)(UndoStep *us, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data);
- eUndoTypeMode mode;
bool use_context;
int step_size;
@@ -136,6 +122,9 @@ extern const UndoType *BKE_UNDOSYS_TYPE_PARTICLE;
extern const UndoType *BKE_UNDOSYS_TYPE_SCULPT;
extern const UndoType *BKE_UNDOSYS_TYPE_TEXT;
+#define BKE_UNDOSYS_TYPE_IS_MEMFILE_SKIP(ty) \
+ ELEM(ty, BKE_UNDOSYS_TYPE_IMAGE)
+
UndoStack *BKE_undosys_stack_create(void);
void BKE_undosys_stack_destroy(UndoStack *ustack);
void BKE_undosys_stack_clear(UndoStack *ustack);
diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c
index f56dd953283..b0836f822a6 100644
--- a/source/blender/blenkernel/intern/undo_system.c
+++ b/source/blender/blenkernel/intern/undo_system.c
@@ -337,7 +337,7 @@ void BKE_undosys_stack_init_from_main(UndoStack *ustack, struct Main *bmain)
void BKE_undosys_stack_init_from_context(UndoStack *ustack, bContext *C)
{
const UndoType *ut = BKE_undosys_type_from_context(C);
- if ((ut != NULL) && (ut != BKE_UNDOSYS_TYPE_MEMFILE) && (ut->mode == BKE_UNDOTYPE_MODE_STORE)) {
+ if ((ut != NULL) && (ut != BKE_UNDOSYS_TYPE_MEMFILE)) {
BKE_undosys_step_push_with_type(ustack, C, "original mode", ut);
}
}
@@ -657,16 +657,17 @@ bool BKE_undosys_step_undo_with_data_ex(
if (ustack->step_active) {
UndoStep *us_iter = ustack->step_active;
while (us_iter != us) {
- if (us_iter->type->mode == BKE_UNDOTYPE_MODE_ACCUMULATE) {
- undosys_step_decode(C, G_MAIN, ustack, us_iter, -1);
- }
+ /* TODO:
+ * - skip successive steps that store the same data, eg: memfile steps.
+ * - or steps that include another steps data, eg: a memfile step includes text undo data.
+ */
+ undosys_step_decode(C, G_MAIN, ustack, us_iter, -1);
us_iter = us_iter->prev;
}
}
- if (us->type->mode != BKE_UNDOTYPE_MODE_ACCUMULATE) {
- undosys_step_decode(C, G_MAIN, ustack, us, -1);
- }
+ undosys_step_decode(C, G_MAIN, ustack, us, -1);
+
ustack->step_active = us_prev;
undosys_stack_validate(ustack, true);
if (use_skip) {
@@ -712,14 +713,11 @@ bool BKE_undosys_step_redo_with_data_ex(
if (ustack->step_active && ustack->step_active->next) {
UndoStep *us_iter = ustack->step_active->next;
while (us_iter != us) {
- if (us_iter->type->mode == BKE_UNDOTYPE_MODE_ACCUMULATE) {
- undosys_step_decode(C, G_MAIN, ustack, us_iter, 1);
- }
+ undosys_step_decode(C, G_MAIN, ustack, us_iter, 1);
us_iter = us_iter->next;
}
}
- /* Unlike undo, always redo accumulation state. */
undosys_step_decode(C, G_MAIN, ustack, us, 1);
ustack->step_active = us_next;
if (use_skip) {
@@ -793,8 +791,6 @@ UndoType *BKE_undosys_type_append(void (*undosys_fn)(UndoType *))
undosys_fn(ut);
- BLI_assert(ut->mode != 0);
-
BLI_addtail(&g_undo_types, ut);
return ut;
@@ -1010,14 +1006,15 @@ ID *BKE_undosys_ID_map_lookup_with_prev(const UndoIDPtrMap *map, ID *id_src, ID
void BKE_undosys_print(UndoStack *ustack)
{
- printf("Undo %d Steps (A: active, M=memfile-active, S=skip)\n",
+ printf("Undo %d Steps (*: active, #=applied, M=memfile-active, S=skip)\n",
BLI_listbase_count(&ustack->steps));
int index = 0;
for (UndoStep *us = ustack->steps.first; us; us = us->next) {
- printf("[%c%c%c] %3d type='%s', name='%s'\n",
- (us == ustack->step_active) ? 'A' : '_',
- (us == ustack->step_active_memfile) ? 'M' : '_',
- us->skip ? 'S' : '_',
+ printf("[%c%c%c%c] %3d type='%s', name='%s'\n",
+ (us == ustack->step_active) ? '*' : ' ',
+ us->is_applied ? '#' : ' ',
+ (us == ustack->step_active_memfile) ? 'M' : ' ',
+ us->skip ? 'S' : ' ',
index,
us->type->name,
us->name);
diff --git a/source/blender/editors/armature/editarmature_undo.c b/source/blender/editors/armature/editarmature_undo.c
index 597e0ab0891..e6b794f047d 100644
--- a/source/blender/editors/armature/editarmature_undo.c
+++ b/source/blender/editors/armature/editarmature_undo.c
@@ -227,7 +227,6 @@ void ED_armature_undosys_type(UndoType *ut)
ut->step_foreach_ID_ref = armature_undosys_foreach_ID_ref;
- ut->mode = BKE_UNDOTYPE_MODE_STORE;
ut->use_context = true;
ut->step_size = sizeof(ArmatureUndoStep);
diff --git a/source/blender/editors/curve/editcurve_undo.c b/source/blender/editors/curve/editcurve_undo.c
index 1a66ae33508..2099a509342 100644
--- a/source/blender/editors/curve/editcurve_undo.c
+++ b/source/blender/editors/curve/editcurve_undo.c
@@ -294,7 +294,6 @@ void ED_curve_undosys_type(UndoType *ut)
ut->step_foreach_ID_ref = curve_undosys_foreach_ID_ref;
- ut->mode = BKE_UNDOTYPE_MODE_STORE;
ut->use_context = true;
ut->step_size = sizeof(CurveUndoStep);
diff --git a/source/blender/editors/curve/editfont_undo.c b/source/blender/editors/curve/editfont_undo.c
index d0d00150447..02539dd4dbe 100644
--- a/source/blender/editors/curve/editfont_undo.c
+++ b/source/blender/editors/curve/editfont_undo.c
@@ -383,7 +383,6 @@ void ED_font_undosys_type(UndoType *ut)
ut->step_foreach_ID_ref = font_undosys_foreach_ID_ref;
- ut->mode = BKE_UNDOTYPE_MODE_STORE;
ut->use_context = true;
ut->step_size = sizeof(FontUndoStep);
diff --git a/source/blender/editors/include/ED_paint.h b/source/blender/editors/include/ED_paint.h
index 0c414366484..7608f2c7a13 100644
--- a/source/blender/editors/include/ED_paint.h
+++ b/source/blender/editors/include/ED_paint.h
@@ -40,7 +40,7 @@ void ED_imapaint_dirty_region(struct Image *ima, struct ImBuf *ibuf, int x, int
void ED_imapaint_bucket_fill(struct bContext *C, float color[3], struct wmOperator *op);
/* paint_image_undo.c */
-void ED_image_undo_push_begin(const char *name);
+void ED_image_undo_push_begin(const char *name, int paint_mode);
void ED_image_undo_push_end(void);
void ED_image_undo_restore(struct UndoStep *us);
diff --git a/source/blender/editors/lattice/editlattice_undo.c b/source/blender/editors/lattice/editlattice_undo.c
index 95087060536..aa37ff2df42 100644
--- a/source/blender/editors/lattice/editlattice_undo.c
+++ b/source/blender/editors/lattice/editlattice_undo.c
@@ -230,7 +230,6 @@ void ED_lattice_undosys_type(UndoType *ut)
ut->step_foreach_ID_ref = lattice_undosys_foreach_ID_ref;
- ut->mode = BKE_UNDOTYPE_MODE_STORE;
ut->use_context = true;
ut->step_size = sizeof(LatticeUndoStep);
diff --git a/source/blender/editors/mesh/editmesh_undo.c b/source/blender/editors/mesh/editmesh_undo.c
index cfaa3da2f9b..f1b57c8143f 100644
--- a/source/blender/editors/mesh/editmesh_undo.c
+++ b/source/blender/editors/mesh/editmesh_undo.c
@@ -794,7 +794,6 @@ void ED_mesh_undosys_type(UndoType *ut)
ut->step_foreach_ID_ref = mesh_undosys_foreach_ID_ref;
- ut->mode = BKE_UNDOTYPE_MODE_STORE;
ut->use_context = true;
ut->step_size = sizeof(MeshUndoStep);
diff --git a/source/blender/editors/metaball/editmball_undo.c b/source/blender/editors/metaball/editmball_undo.c
index c20c61f5a06..91af12c08a2 100644
--- a/source/blender/editors/metaball/editmball_undo.c
+++ b/source/blender/editors/metaball/editmball_undo.c
@@ -237,7 +237,6 @@ void ED_mball_undosys_type(UndoType *ut)
ut->step_foreach_ID_ref = mball_undosys_foreach_ID_ref;
- ut->mode = BKE_UNDOTYPE_MODE_STORE;
ut->use_context = true;
ut->step_size = sizeof(MBallUndoStep);
diff --git a/source/blender/editors/physics/particle_edit_undo.c b/source/blender/editors/physics/particle_edit_undo.c
index 983397a51fc..0ffd6fb5a94 100644
--- a/source/blender/editors/physics/particle_edit_undo.c
+++ b/source/blender/editors/physics/particle_edit_undo.c
@@ -283,7 +283,6 @@ void ED_particle_undosys_type(UndoType *ut)
ut->step_foreach_ID_ref = particle_undosys_foreach_ID_ref;
- ut->mode = BKE_UNDOTYPE_MODE_STORE;
ut->use_context = true;
ut->step_size = sizeof(ParticleUndoStep);
diff --git a/source/blender/editors/sculpt_paint/paint_curve_undo.c b/source/blender/editors/sculpt_paint/paint_curve_undo.c
index fbd2d0153a1..02d95ed54f8 100644
--- a/source/blender/editors/sculpt_paint/paint_curve_undo.c
+++ b/source/blender/editors/sculpt_paint/paint_curve_undo.c
@@ -134,7 +134,6 @@ void ED_paintcurve_undosys_type(UndoType *ut)
ut->step_decode = paintcurve_undosys_step_decode;
ut->step_free = paintcurve_undosys_step_free;
- ut->mode = BKE_UNDOTYPE_MODE_STORE;
ut->use_context = false;
ut->step_size = sizeof(PaintCurveUndoStep);
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index 8bd83900439..92b00a1505f 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -489,7 +489,7 @@ static PaintOperation *texture_paint_init(bContext *C, wmOperator *op, const flo
}
settings->imapaint.flag |= IMAGEPAINT_DRAWING;
- ED_image_undo_push_begin(op->type->name);
+ ED_image
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list