Fix/refactor foreach_id handling of animdata.

Now callbacks for animdata, nla strip and fcurve are in their own proper
BKE files (mimicking `foreach_id` callback of `IDTypeInfo`).

This commit also fixes some missing handling of ID pointers (text ID and
IDProperties of script fcurve modifier...).
This commit is contained in:
2020-05-26 11:53:00 +02:00
parent 825d5c9992
commit 13b10ab852
8 changed files with 84 additions and 34 deletions

View File

@@ -32,6 +32,7 @@ extern "C" {
struct AnimData; struct AnimData;
struct ID; struct ID;
struct LibraryForeachIDData;
struct Main; struct Main;
struct ReportList; struct ReportList;
struct bAction; struct bAction;
@@ -58,6 +59,8 @@ void BKE_animdata_free(struct ID *id, const bool do_id_user);
/* Return true if the ID-block has non-empty AnimData. */ /* Return true if the ID-block has non-empty AnimData. */
bool BKE_animdata_id_is_animated(const struct ID *id); bool BKE_animdata_id_is_animated(const struct ID *id);
void BKE_animdata_foreach_id(struct AnimData *adt, struct LibraryForeachIDData *data);
/* Copy AnimData */ /* Copy AnimData */
struct AnimData *BKE_animdata_copy(struct Main *bmain, struct AnimData *adt, const int flag); struct AnimData *BKE_animdata_copy(struct Main *bmain, struct AnimData *adt, const int flag);

View File

@@ -37,6 +37,7 @@ struct FModifier;
struct AnimData; struct AnimData;
struct BezTriple; struct BezTriple;
struct LibraryForeachIDData;
struct PathResolvedRNA; struct PathResolvedRNA;
struct PointerRNA; struct PointerRNA;
struct PropertyRNA; struct PropertyRNA;
@@ -185,6 +186,8 @@ struct FCurve *copy_fcurve(const struct FCurve *fcu);
void free_fcurves(ListBase *list); void free_fcurves(ListBase *list);
void copy_fcurves(ListBase *dst, ListBase *src); void copy_fcurves(ListBase *dst, ListBase *src);
void BKE_fcurve_foreach_id(struct FCurve *fcu, struct LibraryForeachIDData *data);
/* find matching F-Curve in the given list of F-Curves */ /* find matching F-Curve in the given list of F-Curves */
struct FCurve *list_find_fcurve(ListBase *list, const char rna_path[], const int array_index); struct FCurve *list_find_fcurve(ListBase *list, const char rna_path[], const int array_index);

View File

@@ -29,6 +29,7 @@ extern "C" {
#endif #endif
struct AnimData; struct AnimData;
struct LibraryForeachIDData;
struct Main; struct Main;
struct NlaStrip; struct NlaStrip;
struct NlaTrack; struct NlaTrack;
@@ -63,6 +64,8 @@ struct NlaStrip *BKE_nla_add_soundstrip(struct Main *bmain,
struct Scene *scene, struct Scene *scene,
struct Speaker *spk); struct Speaker *spk);
void BKE_nla_strip_foreach_id(struct NlaStrip *strip, struct LibraryForeachIDData *data);
/* ----------------------------- */ /* ----------------------------- */
/* API */ /* API */

View File

@@ -159,6 +159,10 @@ static void action_foreach_id(ID *id, LibraryForeachIDData *data)
{ {
bAction *act = (bAction *)id; bAction *act = (bAction *)id;
LISTBASE_FOREACH (FCurve *, fcu, &act->curves) {
BKE_fcurve_foreach_id(fcu, data);
}
LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) {
BKE_LIB_FOREACHID_PROCESS(data, marker->camera, IDWALK_CB_NOP); BKE_LIB_FOREACHID_PROCESS(data, marker->camera, IDWALK_CB_NOP);
} }

View File

@@ -32,6 +32,7 @@
#include "BKE_fcurve_driver.h" #include "BKE_fcurve_driver.h"
#include "BKE_global.h" #include "BKE_global.h"
#include "BKE_lib_id.h" #include "BKE_lib_id.h"
#include "BKE_lib_query.h"
#include "BKE_main.h" #include "BKE_main.h"
#include "BKE_nla.h" #include "BKE_nla.h"
#include "BKE_node.h" #include "BKE_node.h"
@@ -289,6 +290,24 @@ bool BKE_animdata_id_is_animated(const struct ID *id)
!BLI_listbase_is_empty(&adt->overrides); !BLI_listbase_is_empty(&adt->overrides);
} }
/** Callback used by lib_query to walk over all ID usages (mimics `foreach_id` callback of
* `IDTypeInfo` structure). */
void BKE_animdata_foreach_id(AnimData *adt, LibraryForeachIDData *data)
{
LISTBASE_FOREACH (FCurve *, fcu, &adt->drivers) {
BKE_fcurve_foreach_id(fcu, data);
}
BKE_LIB_FOREACHID_PROCESS(data, adt->action, IDWALK_CB_USER);
BKE_LIB_FOREACHID_PROCESS(data, adt->tmpact, IDWALK_CB_USER);
LISTBASE_FOREACH (NlaTrack *, nla_track, &adt->nla_tracks) {
LISTBASE_FOREACH (NlaStrip *, nla_strip, &nla_track->strips) {
BKE_nla_strip_foreach_id(nla_strip, data);
}
}
}
/* Copying -------------------------------------------- */ /* Copying -------------------------------------------- */
/** /**

View File

@@ -31,6 +31,7 @@
#include "DNA_anim_types.h" #include "DNA_anim_types.h"
#include "DNA_object_types.h" #include "DNA_object_types.h"
#include "DNA_text_types.h"
#include "BLI_blenlib.h" #include "BLI_blenlib.h"
#include "BLI_easing.h" #include "BLI_easing.h"
@@ -43,6 +44,8 @@
#include "BKE_fcurve.h" #include "BKE_fcurve.h"
#include "BKE_fcurve_driver.h" #include "BKE_fcurve_driver.h"
#include "BKE_global.h" #include "BKE_global.h"
#include "BKE_idprop.h"
#include "BKE_lib_query.h"
#include "BKE_nla.h" #include "BKE_nla.h"
#include "RNA_access.h" #include "RNA_access.h"
@@ -158,6 +161,38 @@ void copy_fcurves(ListBase *dst, ListBase *src)
} }
} }
/** Callback used by lib_query to walk over all ID usages (mimics `foreach_id` callback of
* `IDTypeInfo` structure). */
void BKE_fcurve_foreach_id(FCurve *fcu, LibraryForeachIDData *data)
{
ChannelDriver *driver = fcu->driver;
if (driver != NULL) {
LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) {
/* only used targets */
DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) {
BKE_LIB_FOREACHID_PROCESS_ID(data, dtar->id, IDWALK_CB_NOP);
}
DRIVER_TARGETS_LOOPER_END;
}
}
LISTBASE_FOREACH (FModifier *, fcm, &fcu->modifiers) {
switch (fcm->type) {
case FMODIFIER_TYPE_PYTHON: {
FMod_Python *fcm_py = (FMod_Python *)fcm->data;
BKE_LIB_FOREACHID_PROCESS(data, fcm_py->script, IDWALK_CB_NOP);
IDP_foreach_property(fcm_py->prop,
IDP_TYPE_FILTER_ID,
BKE_lib_query_idpropertiesForeachIDLink_callback,
data);
break;
}
}
}
}
/* ----------------- Finding F-Curves -------------------------- */ /* ----------------- Finding F-Curves -------------------------- */
/* high level function to get an fcurve from C without having the rna */ /* high level function to get an fcurve from C without having the rna */

View File

@@ -183,39 +183,6 @@ void BKE_lib_query_idpropertiesForeachIDLink_callback(IDProperty *id_prop, void
BKE_LIB_FOREACHID_PROCESS_ID(data, id_prop->data.pointer, IDWALK_CB_USER); BKE_LIB_FOREACHID_PROCESS_ID(data, id_prop->data.pointer, IDWALK_CB_USER);
} }
static void library_foreach_nla_strip(LibraryForeachIDData *data, NlaStrip *strip)
{
BKE_LIB_FOREACHID_PROCESS(data, strip->act, IDWALK_CB_USER);
LISTBASE_FOREACH (NlaStrip *, substrip, &strip->strips) {
library_foreach_nla_strip(data, substrip);
}
}
static void library_foreach_animationData(LibraryForeachIDData *data, AnimData *adt)
{
LISTBASE_FOREACH (FCurve *, fcu, &adt->drivers) {
ChannelDriver *driver = fcu->driver;
LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) {
/* only used targets */
DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) {
BKE_LIB_FOREACHID_PROCESS_ID(data, dtar->id, IDWALK_CB_NOP);
}
DRIVER_TARGETS_LOOPER_END;
}
}
BKE_LIB_FOREACHID_PROCESS(data, adt->action, IDWALK_CB_USER);
BKE_LIB_FOREACHID_PROCESS(data, adt->tmpact, IDWALK_CB_USER);
LISTBASE_FOREACH (NlaTrack *, nla_track, &adt->nla_tracks) {
LISTBASE_FOREACH (NlaStrip *, nla_strip, &nla_track->strips) {
library_foreach_nla_strip(data, nla_strip);
}
}
}
bool BKE_library_foreach_ID_embedded(LibraryForeachIDData *data, ID **id_pp) bool BKE_library_foreach_ID_embedded(LibraryForeachIDData *data, ID **id_pp)
{ {
/* Needed e.g. for callbacks handling relationships... This call shall be absolutely readonly. */ /* Needed e.g. for callbacks handling relationships... This call shall be absolutely readonly. */
@@ -342,7 +309,7 @@ static void library_foreach_ID_link(Main *bmain,
AnimData *adt = BKE_animdata_from_id(id); AnimData *adt = BKE_animdata_from_id(id);
if (adt) { if (adt) {
library_foreach_animationData(&data, adt); BKE_animdata_foreach_id(adt, &data);
} }
const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id); const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id);

View File

@@ -49,6 +49,7 @@
#include "BKE_fcurve.h" #include "BKE_fcurve.h"
#include "BKE_global.h" #include "BKE_global.h"
#include "BKE_lib_id.h" #include "BKE_lib_id.h"
#include "BKE_lib_query.h"
#include "BKE_main.h" #include "BKE_main.h"
#include "BKE_nla.h" #include "BKE_nla.h"
#include "BKE_sound.h" #include "BKE_sound.h"
@@ -425,6 +426,21 @@ NlaStrip *BKE_nla_add_soundstrip(Main *bmain, Scene *scene, Speaker *speaker)
return strip; return strip;
} }
/** Callback used by lib_query to walk over all ID usages (mimics `foreach_id` callback of
* `IDTypeInfo` structure). */
void BKE_nla_strip_foreach_id(NlaStrip *strip, LibraryForeachIDData *data)
{
BKE_LIB_FOREACHID_PROCESS(data, strip->act, IDWALK_CB_USER);
LISTBASE_FOREACH (FCurve *, fcu, &strip->fcurves) {
BKE_fcurve_foreach_id(fcu, data);
}
LISTBASE_FOREACH (NlaStrip *, substrip, &strip->strips) {
BKE_nla_strip_foreach_id(substrip, data);
}
}
/* *************************************************** */ /* *************************************************** */
/* NLA Evaluation <-> Editing Stuff */ /* NLA Evaluation <-> Editing Stuff */