[Bf-blender-cvs] [3028de9527a] master: UndoType: Refactor: replace `use_context` boolean by a bitflag.

Bastien Montagne noreply at git.blender.org
Wed Jan 6 18:07:15 CET 2021


Commit: 3028de9527a0a7e2772fd87fcf1abbf823698371
Author: Bastien Montagne
Date:   Wed Jan 6 18:06:11 2021 +0100
Branches: master
https://developer.blender.org/rB3028de9527a0a7e2772fd87fcf1abbf823698371

UndoType: Refactor: replace `use_context`  boolean by a bitflag.

We will soon need more options here, sinmpler and cleaner to use a
bitflag then.

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

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/sculpt_undo.c
M	source/blender/editors/space_image/image_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 9af4c07a4dc..0603ef85cc1 100644
--- a/source/blender/blenkernel/BKE_undo_system.h
+++ b/source/blender/blenkernel/BKE_undo_system.h
@@ -140,11 +140,8 @@ typedef struct UndoType {
                               UndoTypeForEachIDRefFn foreach_ID_ref_fn,
                               void *user_data);
 
-  /**
-   * This undo type `encode` callback needs a valid context, it will fail otherwise.
-   * \note Callback is still supposed to properly deal with a NULL context pointer.
-   */
-  bool use_context_for_encode;
+  /** Information for the generic undo system to refine handling of this specific undo type. */
+  uint flags;
 
   /**
    * The size of the undo struct 'inherited' from #UndoStep for that specific type. Used for
@@ -152,6 +149,15 @@ typedef struct UndoType {
   size_t step_size;
 } UndoType;
 
+/** #UndoType.flag bitflags. */
+typedef enum UndoTypeFlags {
+  /**
+   * This undo type `encode` callback needs a valid context, it will fail otherwise.
+   * \note Callback is still supposed to properly deal with a NULL context pointer.
+   */
+  UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE = 1 << 0,
+} UndoTypeFlags;
+
 /* Expose since we need to perform operations on specific undo types (rarely). */
 extern const UndoType *BKE_UNDOSYS_TYPE_IMAGE;
 extern const UndoType *BKE_UNDOSYS_TYPE_MEMFILE;
diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c
index 0713a2d6729..5544e151ddb 100644
--- a/source/blender/blenkernel/intern/undo_system.c
+++ b/source/blender/blenkernel/intern/undo_system.c
@@ -501,7 +501,7 @@ UndoPushReturn BKE_undosys_step_push_with_type(UndoStack *ustack,
                                                const char *name,
                                                const UndoType *ut)
 {
-  BLI_assert(ut->use_context_for_encode == false || C != NULL);
+  BLI_assert((ut->flags & UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE) == 0 || C != NULL);
 
   UNDO_NESTED_ASSERT(false);
   undosys_stack_validate(ustack, false);
diff --git a/source/blender/editors/armature/editarmature_undo.c b/source/blender/editors/armature/editarmature_undo.c
index d6b80909247..c6d7d2eb869 100644
--- a/source/blender/editors/armature/editarmature_undo.c
+++ b/source/blender/editors/armature/editarmature_undo.c
@@ -249,7 +249,7 @@ void ED_armature_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = armature_undosys_foreach_ID_ref;
 
-  ut->use_context_for_encode = true;
+  ut->flags = UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE;
 
   ut->step_size = sizeof(ArmatureUndoStep);
 }
diff --git a/source/blender/editors/curve/editcurve_undo.c b/source/blender/editors/curve/editcurve_undo.c
index 3fd3a348426..534d29c0cc7 100644
--- a/source/blender/editors/curve/editcurve_undo.c
+++ b/source/blender/editors/curve/editcurve_undo.c
@@ -309,7 +309,7 @@ void ED_curve_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = curve_undosys_foreach_ID_ref;
 
-  ut->use_context_for_encode = true;
+  ut->flags = UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE;
 
   ut->step_size = sizeof(CurveUndoStep);
 }
diff --git a/source/blender/editors/curve/editfont_undo.c b/source/blender/editors/curve/editfont_undo.c
index 895db2b4ad1..8559234b62f 100644
--- a/source/blender/editors/curve/editfont_undo.c
+++ b/source/blender/editors/curve/editfont_undo.c
@@ -398,7 +398,7 @@ void ED_font_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = font_undosys_foreach_ID_ref;
 
-  ut->use_context_for_encode = true;
+  ut->flags = UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE;
 
   ut->step_size = sizeof(FontUndoStep);
 }
diff --git a/source/blender/editors/lattice/editlattice_undo.c b/source/blender/editors/lattice/editlattice_undo.c
index 393b9858e1d..3a5734706f1 100644
--- a/source/blender/editors/lattice/editlattice_undo.c
+++ b/source/blender/editors/lattice/editlattice_undo.c
@@ -283,7 +283,7 @@ void ED_lattice_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = lattice_undosys_foreach_ID_ref;
 
-  ut->use_context_for_encode = true;
+  ut->flags = UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE;
 
   ut->step_size = sizeof(LatticeUndoStep);
 }
diff --git a/source/blender/editors/mesh/editmesh_undo.c b/source/blender/editors/mesh/editmesh_undo.c
index 38ff58fb965..1cbbbccdfa9 100644
--- a/source/blender/editors/mesh/editmesh_undo.c
+++ b/source/blender/editors/mesh/editmesh_undo.c
@@ -819,7 +819,7 @@ void ED_mesh_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = mesh_undosys_foreach_ID_ref;
 
-  ut->use_context_for_encode = true;
+  ut->flags = UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE;
 
   ut->step_size = sizeof(MeshUndoStep);
 }
diff --git a/source/blender/editors/metaball/editmball_undo.c b/source/blender/editors/metaball/editmball_undo.c
index 64443270c96..cbc60bcc031 100644
--- a/source/blender/editors/metaball/editmball_undo.c
+++ b/source/blender/editors/metaball/editmball_undo.c
@@ -258,7 +258,7 @@ void ED_mball_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = mball_undosys_foreach_ID_ref;
 
-  ut->use_context_for_encode = true;
+  ut->flags = UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE;
 
   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 5dbbf90639d..77b8d410d81 100644
--- a/source/blender/editors/physics/particle_edit_undo.c
+++ b/source/blender/editors/physics/particle_edit_undo.c
@@ -299,7 +299,7 @@ void ED_particle_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = particle_undosys_foreach_ID_ref;
 
-  ut->use_context_for_encode = true;
+  ut->flags = UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE;
 
   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 c78af7c38c6..0ffb392f826 100644
--- a/source/blender/editors/sculpt_paint/paint_curve_undo.c
+++ b/source/blender/editors/sculpt_paint/paint_curve_undo.c
@@ -159,7 +159,7 @@ void ED_paintcurve_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = paintcurve_undosys_foreach_ID_ref;
 
-  ut->use_context_for_encode = false;
+  ut->flags = 0;
 
   ut->step_size = sizeof(PaintCurveUndoStep);
 }
diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c
index 9f2a6e305d0..443aee81696 100644
--- a/source/blender/editors/sculpt_paint/sculpt_undo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_undo.c
@@ -1576,7 +1576,7 @@ void ED_sculpt_undosys_type(UndoType *ut)
   ut->step_decode = sculpt_undosys_step_decode;
   ut->step_free = sculpt_undosys_step_free;
 
-  ut->use_context_for_encode = false;
+  ut->flags = 0;
 
   ut->step_size = sizeof(SculptUndoStep);
 }
diff --git a/source/blender/editors/space_image/image_undo.c b/source/blender/editors/space_image/image_undo.c
index 6cbebd2a959..1d5725033e0 100644
--- a/source/blender/editors/space_image/image_undo.c
+++ b/source/blender/editors/space_image/image_undo.c
@@ -997,8 +997,10 @@ void ED_image_undosys_type(UndoType *ut)
   ut->step_foreach_ID_ref = image_undosys_foreach_ID_ref;
 
   /* NOTE this is actually a confusing case, since it expects a valid context, but only in a
-   * specific case, see `image_undosys_step_encode` code. */
-  ut->use_context_for_encode = false;
+   * specific case, see `image_undosys_step_encode` code. We cannot specify
+   * `UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE` though, as it can be called with a NULL context by
+   * current code. */
+  ut->flags = 0;
 
   ut->step_size = sizeof(ImageUndoStep);
 }
diff --git a/source/blender/editors/space_text/text_undo.c b/source/blender/editors/space_text/text_undo.c
index 8bc22833502..61b786b2b13 100644
--- a/source/blender/editors/space_text/text_undo.c
+++ b/source/blender/editors/space_text/text_undo.c
@@ -260,7 +260,7 @@ void ED_text_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = text_undosys_foreach_ID_ref;
 
-  ut->use_context_for_encode = true;
+  ut->flags = UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE;
 
   ut->step_size = sizeof(TextUndoStep);
 }
diff --git a/source/blender/editors/undo/memfile_undo.c b/source/blender/editors/undo/memfile_undo.c
index 5f3381e3c9e..eea0f29d295 100644
--- a/source/blender/editors/undo/memfile_undo.c
+++ b/source/blender/editors/undo/memfile_undo.c
@@ -282,7 +282,7 @@ void ED_memfile_undosys_type(UndoType *ut)
   ut->step_decode = memfile_undosys_step_decode;
   ut->step_free = memfile_undosys_step_free;
 
-  ut->use_context_for_encode = false;
+  ut->flags = 0;
 
   ut->step_size = sizeof(MemFileUndoStep);
 }



More information about the Bf-blender-cvs mailing list