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

We will soon need more options here, sinmpler and cleaner to use a
bitflag then.
This commit is contained in:
Bastien Montagne 2021-01-06 18:06:11 +01:00
parent 5cdf279ef4
commit 3028de9527
14 changed files with 27 additions and 19 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}