Static override: Add basic two-passes system needed for apply insert op.

And a dummy placeholder for object constraints... All this is WIP of
course!
This commit is contained in:
Bastien Montagne
2018-05-01 17:41:44 +02:00
parent 429c1d60a4
commit c7947b2115
2 changed files with 68 additions and 22 deletions

View File

@@ -7684,12 +7684,20 @@ bool RNA_struct_override_store(
static void rna_property_override_apply_ex(
PointerRNA *ptr_local, PointerRNA *ptr_override, PointerRNA *ptr_storage,
PropertyRNA *prop_local, PropertyRNA *prop_override, PropertyRNA *prop_storage,
IDOverrideStaticProperty *op)
IDOverrideStaticProperty *op, const bool do_insert)
{
for (IDOverrideStaticPropertyOperation *opop = op->operations.first; opop; opop = opop->next) {
if (!do_insert != !ELEM(opop->operation, IDOVERRIDESTATIC_OP_INSERT_AFTER, IDOVERRIDESTATIC_OP_INSERT_BEFORE)) {
if (!do_insert) {
printf("Skipping insert override operations in first pass (%s)!\n", op->rna_path);
}
continue;
}
if (!rna_property_override_operation_apply(ptr_local, ptr_override, ptr_storage,
prop_local, prop_override, prop_storage, opop))
{
/* TODO No assert here, would be much much better to just report as warning,
* failing override applications will probably be fairly common! */
BLI_assert(0);
}
}
@@ -7703,32 +7711,38 @@ void RNA_struct_override_apply(
#ifdef DEBUG_OVERRIDE_TIMEIT
TIMEIT_START_AVERAGED(RNA_struct_override_apply);
#endif
for (IDOverrideStaticProperty *op = override->properties.first; op; op = op->next) {
/* Simplified for now! */
PointerRNA data_override, data_local;
PropertyRNA *prop_override, *prop_local;
/* Note: Applying insert operations in a separate pass is mandatory.
* We could optimize this later, but for now, as inneficient as it is, don't think this is a critical point.
*/
bool do_insert = false;
for (int i = 0; i < 2; i++, do_insert = true) {
for (IDOverrideStaticProperty *op = override->properties.first; op; op = op->next) {
/* Simplified for now! */
PointerRNA data_override, data_local;
PropertyRNA *prop_override, *prop_local;
if (RNA_path_resolve_property(ptr_local, op->rna_path, &data_local, &prop_local) &&
RNA_path_resolve_property(ptr_override, op->rna_path, &data_override, &prop_override))
{
PointerRNA data_storage;
PropertyRNA *prop_storage = NULL;
if (RNA_path_resolve_property(ptr_local, op->rna_path, &data_local, &prop_local) &&
RNA_path_resolve_property(ptr_override, op->rna_path, &data_override, &prop_override))
{
PointerRNA data_storage;
PropertyRNA *prop_storage = NULL;
/* It is totally OK if this does not success, only a subset of override operations actually need storage. */
if (ptr_storage && (ptr_storage->id.data != NULL)) {
RNA_path_resolve_property(ptr_storage, op->rna_path, &data_storage, &prop_storage);
/* It is totally OK if this does not success, only a subset of override operations actually need storage. */
if (ptr_storage && (ptr_storage->id.data != NULL)) {
RNA_path_resolve_property(ptr_storage, op->rna_path, &data_storage, &prop_storage);
}
rna_property_override_apply_ex(
&data_local, &data_override, prop_storage ? &data_storage : NULL,
prop_local, prop_override, prop_storage, op, do_insert);
}
rna_property_override_apply_ex(
&data_local, &data_override, prop_storage ? &data_storage : NULL,
prop_local, prop_override, prop_storage, op);
}
#ifndef NDEBUG
else {
printf("Failed to apply static override operation to '%s.%s' (could not resolve some properties)\n",
((ID *)ptr_override->id.data)->name, op->rna_path);
}
else {
printf("Failed to apply static override operation to '%s.%s' (could not resolve some properties)\n",
((ID *)ptr_override->id.data)->name, op->rna_path);
}
#endif
}
}
#ifdef DEBUG_OVERRIDE_TIMEIT
TIMEIT_END_AVERAGED(RNA_struct_override_apply);

View File

@@ -1133,6 +1133,37 @@ static void rna_Object_constraints_clear(Object *object)
WM_main_add_notifier(NC_OBJECT | ND_CONSTRAINT | NA_REMOVED, object);
}
bool rna_Object_constraints_override_apply(
PointerRNA *ptr_dst, PointerRNA *ptr_src, PointerRNA *UNUSED(ptr_storage),
PropertyRNA *UNUSED(prop_dst), PropertyRNA *UNUSED(prop_src), PropertyRNA *UNUSED(prop_storage),
const int UNUSED(len_dst), const int UNUSED(len_src), const int UNUSED(len_storage),
IDOverrideStaticPropertyOperation *opop)
{
BLI_assert(opop->operation == IDOVERRIDESTATIC_OP_INSERT_AFTER &&
"Unsupported RNA override operation on constraints collection");
printf("%s: We are supposed to insert a constraint...\n", __func__);
return false;
#if 0
/* AnimData is a special case, since you cannot edit/replace it, it's either existent or not. */
AnimData *adt_dst = RNA_property_pointer_get(ptr_dst, prop_dst).data;
AnimData *adt_src = RNA_property_pointer_get(ptr_src, prop_src).data;
if (adt_dst == NULL && adt_src != NULL) {
/* Copy anim data from reference into final local ID. */
BKE_animdata_copy_id(NULL, ptr_dst->id.data, ptr_src->id.data, false, true);
return true;
}
else if (adt_dst != NULL && adt_src == NULL) {
/* Override has cleared/removed anim data from its reference. */
BKE_animdata_free(ptr_dst->id.data, true);
return true;
}
return false;
#endif
}
static ModifierData *rna_Object_modifier_new(Object *object, bContext *C, ReportList *reports,
const char *name, int type)
{
@@ -2075,6 +2106,7 @@ static void rna_def_object(BlenderRNA *brna)
RNA_def_property_struct_type(prop, "Constraint");
RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC | PROP_OVERRIDABLE_STATIC_INSERTION);
RNA_def_property_ui_text(prop, "Constraints", "Constraints affecting the transformation of the object");
RNA_def_property_override_funcs(prop, NULL, NULL, "rna_Object_constraints_override_apply");
/* RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "constraints__add", "constraints__remove"); */
rna_def_object_constraints(brna, prop);