[Bf-blender-cvs] [51bba03b319] master: Undo System: add Main argument to encode/decode

Campbell Barton noreply at git.blender.org
Thu Jan 31 02:04:29 CET 2019


Commit: 51bba03b319319d59f739673c3fafb71bc308e0d
Author: Campbell Barton
Date:   Thu Jan 31 11:34:57 2019 +1100
Branches: master
https://developer.blender.org/rB51bba03b319319d59f739673c3fafb71bc308e0d

Undo System: add Main argument to encode/decode

Needed since we don't always have the context,
and avoids adding G_MAIN into undo callbacks.

===================================================================

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/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_undo.c
M	source/blender/editors/sculpt_paint/sculpt_undo.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 2863642a3e0..33eefcf6085 100644
--- a/source/blender/blenkernel/BKE_undo_system.h
+++ b/source/blender/blenkernel/BKE_undo_system.h
@@ -29,6 +29,7 @@ struct UndoStep;
 struct bContext;
 
 /* ID's */
+struct Main;
 struct Mesh;
 struct Object;
 struct Scene;
@@ -115,8 +116,8 @@ typedef struct UndoType {
 	 */
 	void (*step_encode_init)(struct bContext *C, UndoStep *us);
 
-	bool (*step_encode)(struct bContext *C, UndoStep *us);
-	void (*step_decode)(struct bContext *C, UndoStep *us, int dir);
+	bool (*step_encode)(struct bContext *C, struct Main *bmain, UndoStep *us);
+	void (*step_decode)(struct bContext *C, struct Main *bmain, UndoStep *us, int dir);
 
 	/**
 	 * \note When freeing all steps,
diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c
index d16f0569a57..ab375da0925 100644
--- a/source/blender/blenkernel/intern/undo_system.c
+++ b/source/blender/blenkernel/intern/undo_system.c
@@ -146,16 +146,15 @@ static void undosys_id_ref_resolve(void *user_data, UndoRefID *id_ref)
 	}
 }
 
-static bool undosys_step_encode(bContext *C, UndoStack *ustack, UndoStep *us)
+static bool undosys_step_encode(bContext *C, Main *bmain, UndoStack *ustack, UndoStep *us)
 {
 	CLOG_INFO(&LOG, 2, "addr=%p, name='%s', type='%s'", us, us->name, us->type->name);
 	UNDO_NESTED_CHECK_BEGIN;
-	bool ok = us->type->step_encode(C, us);
+	bool ok = us->type->step_encode(C, bmain, us);
 	UNDO_NESTED_CHECK_END;
 	if (ok) {
 		if (us->type->step_foreach_ID_ref != NULL) {
 			/* Don't use from context yet because sometimes context is fake and not all members are filled in. */
-			Main *bmain = G.main;
 			us->type->step_foreach_ID_ref(us, undosys_id_ref_store, bmain);
 		}
 #ifdef WITH_GLOBAL_UNDO_CORRECT_ORDER
@@ -170,7 +169,7 @@ static bool undosys_step_encode(bContext *C, UndoStack *ustack, UndoStep *us)
 	return ok;
 }
 
-static void undosys_step_decode(bContext *C, UndoStack *ustack, UndoStep *us, int dir)
+static void undosys_step_decode(bContext *C, Main *bmain, UndoStack *ustack, UndoStep *us, int dir)
 {
 	CLOG_INFO(&LOG, 2, "addr=%p, name='%s', type='%s'", us, us->name, us->type->name);
 
@@ -185,7 +184,7 @@ static void undosys_step_decode(bContext *C, UndoStack *ustack, UndoStep *us, in
 					else {
 						/* Load the previous memfile state so any ID's referenced in this
 						 * undo step will be correctly resolved, see: T56163. */
-						undosys_step_decode(C, ustack, us_iter, dir);
+						undosys_step_decode(C, bmain, ustack, us_iter, dir);
 					}
 					break;
 				}
@@ -193,12 +192,11 @@ static void undosys_step_decode(bContext *C, UndoStack *ustack, UndoStep *us, in
 		}
 #endif
 		/* Don't use from context yet because sometimes context is fake and not all members are filled in. */
-		Main *bmain = G.main;
 		us->type->step_foreach_ID_ref(us, undosys_id_ref_resolve, bmain);
 	}
 
 	UNDO_NESTED_CHECK_BEGIN;
-	us->type->step_decode(C, us, dir);
+	us->type->step_decode(C, bmain, us, dir);
 	UNDO_NESTED_CHECK_END;
 
 #ifdef WITH_GLOBAL_UNDO_CORRECT_ORDER
@@ -487,6 +485,7 @@ UndoStep *BKE_undosys_step_push_init(UndoStack *ustack, bContext *C, const char
  */
 bool BKE_undosys_step_push_with_type(UndoStack *ustack, bContext *C, const char *name, const UndoType *ut)
 {
+	Main *bmain = G.main;
 	UNDO_NESTED_ASSERT(false);
 	undosys_stack_validate(ustack, false);
 	bool is_not_empty = ustack->step_active != NULL;
@@ -510,7 +509,6 @@ bool BKE_undosys_step_push_with_type(UndoStack *ustack, bContext *C, const char
 
 #ifdef WITH_GLOBAL_UNDO_ENSURE_UPDATED
 	if (ut->step_foreach_ID_ref != NULL) {
-		Main *bmain = G.main;
 		if (bmain->is_memfile_undo_written == false) {
 			const char *name_internal = "MemFile Internal (pre)";
 			/* Don't let 'step_init' cause issues when adding memfile undo step. */
@@ -541,7 +539,7 @@ bool BKE_undosys_step_push_with_type(UndoStack *ustack, bContext *C, const char
 		us->type = ut;
 		/* initialized, not added yet. */
 
-		if (!undosys_step_encode(C, ustack, us)) {
+		if (!undosys_step_encode(C, bmain, ustack, us)) {
 			MEM_freeN(us);
 			undosys_stack_validate(ustack, true);
 			return false;
@@ -552,7 +550,6 @@ bool BKE_undosys_step_push_with_type(UndoStack *ustack, bContext *C, const char
 	}
 
 	if (use_memfile_step) {
-		Main *bmain = G.main;
 		const char *name_internal = "MemFile Internal (post)";
 		const bool ok = undosys_stack_push_main(ustack, name_internal, bmain);
 		if (ok) {
@@ -647,6 +644,7 @@ bool BKE_undosys_step_undo_with_data_ex(
         bool use_skip)
 {
 	UNDO_NESTED_ASSERT(false);
+	Main *bmain = G.main;
 	if (us) {
 		undosys_stack_validate(ustack, true);
 	}
@@ -664,14 +662,14 @@ bool BKE_undosys_step_undo_with_data_ex(
 			UndoStep *us_iter = ustack->step_active;
 			while (us_iter != us) {
 				if (us_iter->type->mode == BKE_UNDOTYPE_MODE_ACCUMULATE) {
-					undosys_step_decode(C, ustack, us_iter, -1);
+					undosys_step_decode(C, bmain, ustack, us_iter, -1);
 				}
 				us_iter = us_iter->prev;
 			}
 		}
 
 		if (us->type->mode != BKE_UNDOTYPE_MODE_ACCUMULATE) {
-			undosys_step_decode(C, ustack, us, -1);
+			undosys_step_decode(C, bmain, ustack, us, -1);
 		}
 		ustack->step_active = us_prev;
 		undosys_stack_validate(ustack, true);
@@ -706,6 +704,7 @@ bool BKE_undosys_step_redo_with_data_ex(
         UndoStack *ustack, bContext *C, UndoStep *us,
         bool use_skip)
 {
+	Main *bmain = G.main;
 	UNDO_NESTED_ASSERT(false);
 	UndoStep *us_next = us ? us->next : NULL;
 	/* Unlike undo accumulate, we always use the next. */
@@ -719,14 +718,14 @@ bool BKE_undosys_step_redo_with_data_ex(
 			UndoStep *us_iter = ustack->step_active->next;
 			while (us_iter != us) {
 				if (us_iter->type->mode == BKE_UNDOTYPE_MODE_ACCUMULATE) {
-					undosys_step_decode(C, ustack, us_iter, 1);
+					undosys_step_decode(C, bmain, ustack, us_iter, 1);
 				}
 				us_iter = us_iter->next;
 			}
 		}
 
 		/* Unlike undo, always redo accumulation state. */
-		undosys_step_decode(C, ustack, us, 1);
+		undosys_step_decode(C, bmain, ustack, us, 1);
 		ustack->step_active = us_next;
 		if (use_skip) {
 			if (ustack->step_active && ustack->step_active->skip) {
diff --git a/source/blender/editors/armature/editarmature_undo.c b/source/blender/editors/armature/editarmature_undo.c
index 3119c303801..9cd96db7bdf 100644
--- a/source/blender/editors/armature/editarmature_undo.c
+++ b/source/blender/editors/armature/editarmature_undo.c
@@ -149,7 +149,7 @@ static bool armature_undosys_poll(bContext *C)
 	return editarm_object_from_context(C) != NULL;
 }
 
-static bool armature_undosys_step_encode(struct bContext *C, UndoStep *us_p)
+static bool armature_undosys_step_encode(struct bContext *C, struct Main *UNUSED(bmain), UndoStep *us_p)
 {
 	ArmatureUndoStep *us = (ArmatureUndoStep *)us_p;
 
@@ -173,7 +173,7 @@ static bool armature_undosys_step_encode(struct bContext *C, UndoStep *us_p)
 	return true;
 }
 
-static void armature_undosys_step_decode(struct bContext *C, UndoStep *us_p, int UNUSED(dir))
+static void armature_undosys_step_decode(struct bContext *C, struct Main *UNUSED(bmain), UndoStep *us_p, int UNUSED(dir))
 {
 	/* TODO(campbell): undo_system: use low-level API to set mode. */
 	ED_object_mode_set(C, OB_MODE_EDIT);
diff --git a/source/blender/editors/curve/editcurve_undo.c b/source/blender/editors/curve/editcurve_undo.c
index 9163272fbf2..282b3722d3b 100644
--- a/source/blender/editors/curve/editcurve_undo.c
+++ b/source/blender/editors/curve/editcurve_undo.c
@@ -214,7 +214,7 @@ static bool curve_undosys_poll(bContext *C)
 	return (obedit != NULL);
 }
 
-static bool curve_undosys_step_encode(struct bContext *C, UndoStep *us_p)
+static bool curve_undosys_step_encode(struct bContext *C, struct Main *UNUSED(bmain), UndoStep *us_p)
 {
 	CurveUndoStep *us = (CurveUndoStep *)us_p;
 
@@ -237,7 +237,7 @@ static bool curve_undosys_step_encode(struct bContext *C, UndoStep *us_p)
 	return true;
 }
 
-static void curve_undosys_step_decode(struct bContext *C, UndoStep *us_p, int UNUSED(dir))
+static void curve_undosys_step_decode(struct bContext *C, struct Main *UNUSED(bmain), UndoStep *us_p, int UNUSED(dir))
 {
 	/* TODO(campbell): undo_system: use low-level API to set mode. */
 	ED_object_mode_set(C, OB_MODE_EDIT);
diff --git a/source/blender/editors/curve/editfont_undo.c b/source/blender/editors/curve/editfont_undo.c
index 85e361b495f..ab6ef4b4728 100644
--- a/source/blender/editors/curve/editfont_undo.c
+++ b/source/blender/editors/curve/editfont_undo.c
@@ -339,7 +339,7 @@ static bool font_undosys_poll(bContext *C)
 	return editfont_object_from_context(C) != NULL;
 }
 
-static bool font_undosys_step_encode(struct bContext *C, UndoStep *us_p)
+static bool font_undosys_step_encode(struct bContext *C, struct Main *UNUSED(bmain), UndoStep *us_p)
 {
 	FontUndoStep *us = (FontUndoStep *)us_p;
 	us->obedit_ref.ptr = editfont_object_from_context(C);
@@ -349,7 +349,7 @@ static bool font_undosys_step_encode(struct bContext *C, UndoStep *us_p)
 	return true;
 }
 
-static void font_undosys_step_decode(struct bContext *C, UndoStep *us_p, int UNUSED(dir))
+static void font_undosys_step_decode(struct bContext *C, struct Main *UNUSED(bmain), UndoStep *us_p, int UNUSED(dir))
 {
 	/* TODO(campbell): undo_system: use low-level API to set mode. */
 	ED_object_mode_set(C, OB_MODE_EDIT);
diff --git a/source/blender/editors/lattice/editlattice_undo.c b/source/blender/editors/lattice/editlattice_undo.c
index 744f353f129..7ca28906861 100644
--- a/source/blender/editors/lattice/editlattice_undo.c
+++ b/source/blender/editors/lattice/editlattice_undo.c
@@ -151,7 +151,7 @@ static bool lattice_undosys_poll(bContext *C)
 	return editlatt_object_from_context(C) != NULL;
 }
 
-static bool lattice_undosys_step_encode(struct bContext *C, UndoStep *us_p)
+static bool lattice_undosys_step_encode(struct bContext *C, struct Main *UNUSED(bmain), UndoStep *us_p)
 {
 	LatticeUndoStep *us = (LatticeUndoStep *)us_p;
 
@@ -175,7 +175,7 @@ static bool lattice_undosys_step_encode(struct bContext *C, UndoStep *us_p)
 	return true;
 }
 
-static void lattice_undosys_step_decode(struct bContext *C, UndoStep *us_p, int UNUSED(d

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list