Refactor: Anim, split up FCurve-reading/writing code
Split `BKE_fcurve_blend_write(writer, listbase)` into two functions: - `BKE_fcurve_blend_write_data(writer, fcurve)` for the data of a single F-Curve, and - `BKE_fcurve_blend_write_listbase(writer, listbase)` for writing a list of F-Curves. And the same for `BKE_fcurve_blend_read_data()`. This is necessary for the upcoming Animation data-block, which will store F-Curves as arrays instead of `ListBase`s. No functional changes.
This commit is contained in:
@@ -657,8 +657,15 @@ void BKE_fmodifiers_blend_read_data(struct BlendDataReader *reader,
|
||||
ListBase *fmodifiers,
|
||||
struct FCurve *curve);
|
||||
|
||||
void BKE_fcurve_blend_write(struct BlendWriter *writer, struct ListBase *fcurves);
|
||||
void BKE_fcurve_blend_read_data(struct BlendDataReader *reader, struct ListBase *fcurves);
|
||||
/**
|
||||
* Write the FCurve's data to the writer.
|
||||
* If this is used to write an FCurve, be sure to call `BLO_write_struct(writer, FCurve, fcurve);`
|
||||
* before calling this function.
|
||||
*/
|
||||
void BKE_fcurve_blend_write_data(struct BlendWriter *writer, struct FCurve *fcurve);
|
||||
void BKE_fcurve_blend_write_listbase(struct BlendWriter *writer, struct ListBase *fcurves);
|
||||
void BKE_fcurve_blend_read_data(BlendDataReader *reader, FCurve *fcu);
|
||||
void BKE_fcurve_blend_read_data_listbase(struct BlendDataReader *reader, struct ListBase *fcurves);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ static void action_blend_write(BlendWriter *writer, ID *id, const void *id_addre
|
||||
BLO_write_id_struct(writer, bAction, id_address, &act->id);
|
||||
BKE_id_blend_write(writer, &act->id);
|
||||
|
||||
BKE_fcurve_blend_write(writer, &act->curves);
|
||||
BKE_fcurve_blend_write_listbase(writer, &act->curves);
|
||||
|
||||
LISTBASE_FOREACH (bActionGroup *, grp, &act->groups) {
|
||||
BLO_write_struct(writer, bActionGroup, grp);
|
||||
@@ -229,7 +229,7 @@ static void action_blend_read_data(BlendDataReader *reader, ID *id)
|
||||
}
|
||||
/* >>> XXX deprecated - old animation system */
|
||||
|
||||
BKE_fcurve_blend_read_data(reader, &act->curves);
|
||||
BKE_fcurve_blend_read_data_listbase(reader, &act->curves);
|
||||
|
||||
LISTBASE_FOREACH (bActionGroup *, agrp, &act->groups) {
|
||||
BLO_read_data_address(reader, &agrp->channels.first);
|
||||
|
||||
@@ -1450,7 +1450,7 @@ void BKE_animdata_blend_write(BlendWriter *writer, ID *id)
|
||||
BLO_write_struct(writer, AnimData, adt);
|
||||
|
||||
/* write drivers */
|
||||
BKE_fcurve_blend_write(writer, &adt->drivers);
|
||||
BKE_fcurve_blend_write_listbase(writer, &adt->drivers);
|
||||
|
||||
/* write overrides */
|
||||
/* FIXME: are these needed? */
|
||||
@@ -1480,7 +1480,7 @@ void BKE_animdata_blend_read_data(BlendDataReader *reader, ID *id)
|
||||
|
||||
/* link drivers */
|
||||
BLO_read_list(reader, &adt->drivers);
|
||||
BKE_fcurve_blend_read_data(reader, &adt->drivers);
|
||||
BKE_fcurve_blend_read_data_listbase(reader, &adt->drivers);
|
||||
adt->driver_array = nullptr;
|
||||
|
||||
/* link overrides */
|
||||
|
||||
@@ -2584,98 +2584,108 @@ void BKE_fmodifiers_blend_read_data(BlendDataReader *reader, ListBase *fmodifier
|
||||
}
|
||||
}
|
||||
|
||||
void BKE_fcurve_blend_write(BlendWriter *writer, ListBase *fcurves)
|
||||
void BKE_fcurve_blend_write_data(BlendWriter *writer, FCurve *fcu)
|
||||
{
|
||||
/* curve data */
|
||||
if (fcu->bezt) {
|
||||
BLO_write_struct_array(writer, BezTriple, fcu->totvert, fcu->bezt);
|
||||
}
|
||||
if (fcu->fpt) {
|
||||
BLO_write_struct_array(writer, FPoint, fcu->totvert, fcu->fpt);
|
||||
}
|
||||
|
||||
if (fcu->rna_path) {
|
||||
BLO_write_string(writer, fcu->rna_path);
|
||||
}
|
||||
|
||||
/* driver data */
|
||||
if (fcu->driver) {
|
||||
ChannelDriver *driver = fcu->driver;
|
||||
|
||||
BLO_write_struct(writer, ChannelDriver, driver);
|
||||
|
||||
/* variables */
|
||||
BLO_write_struct_list(writer, DriverVar, &driver->variables);
|
||||
LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) {
|
||||
DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) {
|
||||
if (dtar->rna_path) {
|
||||
BLO_write_string(writer, dtar->rna_path);
|
||||
}
|
||||
}
|
||||
DRIVER_TARGETS_LOOPER_END;
|
||||
}
|
||||
}
|
||||
|
||||
/* write F-Modifiers */
|
||||
BKE_fmodifiers_blend_write(writer, &fcu->modifiers);
|
||||
}
|
||||
|
||||
void BKE_fcurve_blend_write_listbase(BlendWriter *writer, ListBase *fcurves)
|
||||
{
|
||||
BLO_write_struct_list(writer, FCurve, fcurves);
|
||||
LISTBASE_FOREACH (FCurve *, fcu, fcurves) {
|
||||
/* curve data */
|
||||
if (fcu->bezt) {
|
||||
BLO_write_struct_array(writer, BezTriple, fcu->totvert, fcu->bezt);
|
||||
}
|
||||
if (fcu->fpt) {
|
||||
BLO_write_struct_array(writer, FPoint, fcu->totvert, fcu->fpt);
|
||||
}
|
||||
|
||||
if (fcu->rna_path) {
|
||||
BLO_write_string(writer, fcu->rna_path);
|
||||
}
|
||||
|
||||
/* driver data */
|
||||
if (fcu->driver) {
|
||||
ChannelDriver *driver = fcu->driver;
|
||||
|
||||
BLO_write_struct(writer, ChannelDriver, driver);
|
||||
|
||||
/* variables */
|
||||
BLO_write_struct_list(writer, DriverVar, &driver->variables);
|
||||
LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) {
|
||||
DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) {
|
||||
if (dtar->rna_path) {
|
||||
BLO_write_string(writer, dtar->rna_path);
|
||||
}
|
||||
}
|
||||
DRIVER_TARGETS_LOOPER_END;
|
||||
}
|
||||
}
|
||||
|
||||
/* write F-Modifiers */
|
||||
BKE_fmodifiers_blend_write(writer, &fcu->modifiers);
|
||||
BKE_fcurve_blend_write_data(writer, fcu);
|
||||
}
|
||||
}
|
||||
|
||||
void BKE_fcurve_blend_read_data(BlendDataReader *reader, ListBase *fcurves)
|
||||
void BKE_fcurve_blend_read_data(BlendDataReader *reader, FCurve *fcu)
|
||||
{
|
||||
/* curve data */
|
||||
BLO_read_data_address(reader, &fcu->bezt);
|
||||
BLO_read_data_address(reader, &fcu->fpt);
|
||||
|
||||
/* rna path */
|
||||
BLO_read_data_address(reader, &fcu->rna_path);
|
||||
|
||||
/* group */
|
||||
BLO_read_data_address(reader, &fcu->grp);
|
||||
|
||||
/* clear disabled flag - allows disabled drivers to be tried again (#32155),
|
||||
* but also means that another method for "reviving disabled F-Curves" exists
|
||||
*/
|
||||
fcu->flag &= ~FCURVE_DISABLED;
|
||||
|
||||
/* driver */
|
||||
BLO_read_data_address(reader, &fcu->driver);
|
||||
if (fcu->driver) {
|
||||
ChannelDriver *driver = fcu->driver;
|
||||
|
||||
/* Compiled expression data will need to be regenerated
|
||||
* (old pointer may still be set here). */
|
||||
driver->expr_comp = nullptr;
|
||||
driver->expr_simple = nullptr;
|
||||
|
||||
/* Give the driver a fresh chance - the operating environment may be different now
|
||||
* (addons, etc. may be different) so the driver namespace may be sane now #32155. */
|
||||
driver->flag &= ~DRIVER_FLAG_INVALID;
|
||||
|
||||
/* relink variables, targets and their paths */
|
||||
BLO_read_list(reader, &driver->variables);
|
||||
LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) {
|
||||
DRIVER_TARGETS_LOOPER_BEGIN (dvar) {
|
||||
/* only relink the targets being used */
|
||||
if (tarIndex < dvar->num_targets) {
|
||||
BLO_read_data_address(reader, &dtar->rna_path);
|
||||
}
|
||||
else {
|
||||
dtar->rna_path = nullptr;
|
||||
dtar->id = nullptr;
|
||||
}
|
||||
}
|
||||
DRIVER_TARGETS_LOOPER_END;
|
||||
}
|
||||
}
|
||||
|
||||
/* modifiers */
|
||||
BLO_read_list(reader, &fcu->modifiers);
|
||||
BKE_fmodifiers_blend_read_data(reader, &fcu->modifiers, fcu);
|
||||
}
|
||||
|
||||
void BKE_fcurve_blend_read_data_listbase(BlendDataReader *reader, ListBase *fcurves)
|
||||
{
|
||||
/* Link F-Curve data to F-Curve again (non ID-libraries). */
|
||||
LISTBASE_FOREACH (FCurve *, fcu, fcurves) {
|
||||
/* curve data */
|
||||
BLO_read_data_address(reader, &fcu->bezt);
|
||||
BLO_read_data_address(reader, &fcu->fpt);
|
||||
|
||||
/* rna path */
|
||||
BLO_read_data_address(reader, &fcu->rna_path);
|
||||
|
||||
/* group */
|
||||
BLO_read_data_address(reader, &fcu->grp);
|
||||
|
||||
/* clear disabled flag - allows disabled drivers to be tried again (#32155),
|
||||
* but also means that another method for "reviving disabled F-Curves" exists
|
||||
*/
|
||||
fcu->flag &= ~FCURVE_DISABLED;
|
||||
|
||||
/* driver */
|
||||
BLO_read_data_address(reader, &fcu->driver);
|
||||
if (fcu->driver) {
|
||||
ChannelDriver *driver = fcu->driver;
|
||||
|
||||
/* Compiled expression data will need to be regenerated
|
||||
* (old pointer may still be set here). */
|
||||
driver->expr_comp = nullptr;
|
||||
driver->expr_simple = nullptr;
|
||||
|
||||
/* Give the driver a fresh chance - the operating environment may be different now
|
||||
* (addons, etc. may be different) so the driver namespace may be sane now #32155. */
|
||||
driver->flag &= ~DRIVER_FLAG_INVALID;
|
||||
|
||||
/* relink variables, targets and their paths */
|
||||
BLO_read_list(reader, &driver->variables);
|
||||
LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) {
|
||||
DRIVER_TARGETS_LOOPER_BEGIN (dvar) {
|
||||
/* only relink the targets being used */
|
||||
if (tarIndex < dvar->num_targets) {
|
||||
BLO_read_data_address(reader, &dtar->rna_path);
|
||||
}
|
||||
else {
|
||||
dtar->rna_path = nullptr;
|
||||
dtar->id = nullptr;
|
||||
}
|
||||
}
|
||||
DRIVER_TARGETS_LOOPER_END;
|
||||
}
|
||||
}
|
||||
|
||||
/* modifiers */
|
||||
BLO_read_list(reader, &fcu->modifiers);
|
||||
BKE_fmodifiers_blend_read_data(reader, &fcu->modifiers, fcu);
|
||||
BKE_fcurve_blend_read_data(reader, fcu);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2367,7 +2367,7 @@ static void blend_write_nla_strips(BlendWriter *writer, ListBase *strips)
|
||||
BLO_write_struct_list(writer, NlaStrip, strips);
|
||||
LISTBASE_FOREACH (NlaStrip *, strip, strips) {
|
||||
/* write the strip's F-Curves and modifiers */
|
||||
BKE_fcurve_blend_write(writer, &strip->fcurves);
|
||||
BKE_fcurve_blend_write_listbase(writer, &strip->fcurves);
|
||||
BKE_fmodifiers_blend_write(writer, &strip->modifiers);
|
||||
|
||||
/* write the strip's children */
|
||||
@@ -2384,7 +2384,7 @@ static void blend_data_read_nla_strips(BlendDataReader *reader, ListBase *strips
|
||||
|
||||
/* strip's F-Curves */
|
||||
BLO_read_list(reader, &strip->fcurves);
|
||||
BKE_fcurve_blend_read_data(reader, &strip->fcurves);
|
||||
BKE_fcurve_blend_read_data_listbase(reader, &strip->fcurves);
|
||||
|
||||
/* strip's F-Modifiers */
|
||||
BLO_read_list(reader, &strip->modifiers);
|
||||
|
||||
Reference in New Issue
Block a user