From 023765eb48f277168ea4e937f153b3333361d534 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Sat, 17 Jan 2009 05:36:58 +0000 Subject: 2.5 - AnimData fixes * Made AnimData blocks be stored as pointer instead of directly in the ID-datablock, so that fewer files will need to be recompiled everytime some animation settings change. * Tried to fix some of the compiler errors that pop up in Yafray code. If this commit doesn't fix it, just disable Yafray code for now (WITH_BF_YAFRAY=0 for scons)... --- source/blender/blenkernel/BKE_animsys.h | 3 ++ source/blender/blenkernel/intern/anim_sys.c | 45 ++++++++++++++++++++++++--- source/blender/blenkernel/intern/library.c | 1 + source/blender/editors/animation/keyframing.c | 39 ++++++++++++++--------- source/blender/makesdna/DNA_anim_types.h | 10 +++++- source/blender/makesdna/DNA_camera_types.h | 3 +- source/blender/makesdna/DNA_key_types.h | 4 +-- source/blender/makesdna/DNA_lamp_types.h | 4 +-- source/blender/makesdna/DNA_material_types.h | 4 +-- source/blender/makesdna/DNA_object_types.h | 4 +-- source/blender/makesdna/DNA_scene_types.h | 4 +-- source/blender/makesdna/DNA_texture_types.h | 4 +-- source/blender/makesdna/DNA_world_types.h | 4 +-- 13 files changed, 92 insertions(+), 37 deletions(-) diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h index bdb39cd5982..f8a5d91bfa5 100644 --- a/source/blender/blenkernel/BKE_animsys.h +++ b/source/blender/blenkernel/BKE_animsys.h @@ -16,6 +16,9 @@ struct AnimData; /* Get AnimData from the given ID-block. */ struct AnimData *BKE_animdata_from_id(struct ID *id); +/* Add AnimData to the given ID-block */ +struct AnimData *BKE_id_add_animdata(struct ID *id); + /* ************************************* */ // TODO: overrides, remapping, and path-finding api's diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index d377ce044fd..18172488908 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -25,7 +25,7 @@ /* AnimData API */ /* Get AnimData from the given ID-block. In order for this to work, we assume that - * the AnimData block is stored immediately after the given ID-block in the struct, + * the AnimData pointer is stored immediately after the given ID-block in the struct, * as per IdAdtTemplate. */ AnimData *BKE_animdata_from_id (ID *id) @@ -36,7 +36,7 @@ AnimData *BKE_animdata_from_id (ID *id) /* only some ID-blocks have this info for now, so we cast the * types that do to be of type IdAdtTemplate, and extract the - * animdata that way + * AnimData that way */ // TODO: finish adding this for the other blocktypes switch (GS(id->name)) { @@ -47,7 +47,7 @@ AnimData *BKE_animdata_from_id (ID *id) case ID_SCE: { IdAdtTemplate *iat= (IdAdtTemplate *)id; - return &(iat->adt); + return iat->adt; } break; } @@ -56,6 +56,41 @@ AnimData *BKE_animdata_from_id (ID *id) return NULL; } +/* Add AnimData to the given ID-block. In order for this to work, we assume that + * the AnimData pointer is stored immediately after the given ID-block in the struct, + * as per IdAdtTemplate. Also note that + */ +AnimData *BKE_id_add_animdata (ID *id) +{ + /* sanity check */ + if (id == NULL) + return NULL; + + /* only some ID-blocks have this info for now, so we cast the + * types that do to be of type IdAdtTemplate, and add AnimData that + * way + */ + // TODO: finish adding this for the other blocktypes + switch (GS(id->name)) { + case ID_OB: + case ID_KE: + case ID_MA: case ID_TE: + case ID_LA: case ID_CA: case ID_WO: + case ID_SCE: + { + IdAdtTemplate *iat= (IdAdtTemplate *)id; + + iat->adt= MEM_callocN(sizeof(AnimData), "AnimData"); + return iat->adt; + } + break; + } + + /* no AnimData (ID-block does not contain this data) */ + return NULL; +} + + /* Obtain an RNA-Path from the given ID-block to the property of interest * - id: ID block that will be used as the 'root' of the path * - ptr: pointer to struct where setting is stored @@ -541,8 +576,8 @@ void BKE_animsys_evaluate_all_animation (Main *main, float ctime) /* objects */ for (id= main->object.first; id; id= id->next) { - IdAdtTemplate *iat= (IdAdtTemplate *)id; - BKE_animsys_evaluate_animdata(id, &iat->adt, ctime, ADT_RECALC_ANIM); + AnimData *adt= BKE_animdata_from_id(id); + BKE_animsys_evaluate_animdata(id, adt, ctime, ADT_RECALC_ANIM); } } diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index fa728f1a951..d0e5da5f936 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -78,6 +78,7 @@ #include "DNA_particle_types.h" #include "DNA_space_types.h" #include "DNA_windowmanager_types.h" +#include "DNA_anim_types.h" #include "BLI_blenlib.h" #include "BLI_dynstr.h" diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index 4f62368c2b2..9dbf38066a0 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -97,14 +97,24 @@ typedef struct bKeyingContext { * for the given Animation Data block */ // TODO: should we check if path is valid? For now, assume that it's already set OK by caller... -FCurve *verify_fcurve (AnimData *adt, const char rna_path[], const int array_index, short add) +FCurve *verify_fcurve (ID *id, const char rna_path[], const int array_index, short add) { + AnimData *adt; nAction *act; FCurve *fcu; /* sanity checks */ - if ELEM(NULL, adt, rna_path) + if ELEM(NULL, id, rna_path) + return NULL; + + /* init animdata if none available yet */ + adt= BKE_animdata_from_id(id); + if ((adt == NULL) && (add)) + adt= BKE_id_add_animdata(id); + if (adt == NULL) { + /* if still none (as not allowed to add, or ID doesn't have animdata for some reason) */ return NULL; + } /* init action if none available yet */ // TODO: need some wizardry to handle NLA stuff correct @@ -704,7 +714,6 @@ short insertkey (ID *id, const char rna_path[], int array_index, float cfra, sho { PointerRNA id_ptr, ptr; PropertyRNA *prop; - AnimData *adt; FCurve *fcu; /* validate pointer first - exit if failure*/ @@ -715,8 +724,7 @@ short insertkey (ID *id, const char rna_path[], int array_index, float cfra, sho } /* get F-Curve */ - adt= BKE_animdata_from_id(id); - fcu= verify_fcurve(adt, rna_path, array_index, 1); + fcu= verify_fcurve(id, rna_path, array_index, 1); /* only continue if we have an F-Curve to add keyframe to */ if (fcu) { @@ -802,8 +810,7 @@ short insertkey (ID *id, const char rna_path[], int array_index, float cfra, sho */ short deletekey (ID *id, const char rna_path[], int array_index, float cfra, short flag) { - AnimData *adt= BKE_animdata_from_id(id); - nAction *act; + AnimData *adt; FCurve *fcu; /* get F-Curve @@ -811,11 +818,12 @@ short deletekey (ID *id, const char rna_path[], int array_index, float cfra, sho * so 'add' var must be 0 */ // XXX we don't check the validity of the path here yet, but it should be ok... - fcu= verify_fcurve(adt, rna_path, array_index, 0); - act= adt->action; + fcu= verify_fcurve(id, rna_path, array_index, 0); + adt= BKE_animdata_from_id(id); /* only continue if we have an ipo-curve to remove keyframes from */ - if (act && fcu) { + if (adt && adt->action && fcu) { + nAction *act= adt->action; short found = -1; int i; @@ -2107,12 +2115,13 @@ static int delete_key_exec (bContext *C, wmOperator *op) { Object *ob= base->object; ID *id= (ID *)ob; - nAction *act= ob->adt.action; FCurve *fcu, *fcn; short success= 0; /* loop through all curves in animdata and delete keys on this frame */ - if (act) { + if (ob->adt) { + nAction *act= ob->adt->action; + for (fcu= act->curves.first; fcu; fcu= fcn) { fcn= fcu->next; success+= deletekey(id, fcu->rna_path, fcu->array_index, cfra, 0); @@ -2197,12 +2206,12 @@ short action_frame_has_keyframe (nAction *act, float frame, short filter) short object_frame_has_keyframe (Object *ob, float frame, short filter) { /* error checking */ - if (ob == NULL) + if (ELEM(NULL, ob, ob->adt)) return 0; /* check own animation data - specifically, the action it contains */ - if (ob->adt.action) { - if (action_frame_has_keyframe(ob->adt.action, frame, filter)) + if (ob->adt->action) { + if (action_frame_has_keyframe(ob->adt->action, frame, filter)) return 1; } diff --git a/source/blender/makesdna/DNA_anim_types.h b/source/blender/makesdna/DNA_anim_types.h index 71c71f905a2..98ec0da8f21 100644 --- a/source/blender/makesdna/DNA_anim_types.h +++ b/source/blender/makesdna/DNA_anim_types.h @@ -5,6 +5,10 @@ #ifndef DNA_ANIM_TYPES_H #define DNA_ANIM_TYPES_H +#ifdef __cplusplus +extern "C" { +#endif + #include "DNA_ID.h" #include "DNA_listBase.h" #include "DNA_curve_types.h" @@ -579,9 +583,13 @@ enum { */ typedef struct IdAdtTemplate { ID id; - AnimData adt; + AnimData *adt; } IdAdtTemplate; /* ************************************************ */ +#ifdef __cplusplus +}; +#endif + #endif /* DNA_ANIM_TYPES_H */ diff --git a/source/blender/makesdna/DNA_camera_types.h b/source/blender/makesdna/DNA_camera_types.h index 2e79d9c5a42..7a504efdd2a 100644 --- a/source/blender/makesdna/DNA_camera_types.h +++ b/source/blender/makesdna/DNA_camera_types.h @@ -32,7 +32,6 @@ #define DNA_CAMERA_TYPES_H #include "DNA_ID.h" -#include "DNA_anim_types.h" #include "DNA_scriptlink_types.h" #ifdef __cplusplus @@ -45,7 +44,7 @@ struct Ipo; typedef struct Camera { ID id; - struct AnimData adt; /* animation data (must be immediately after id for utilities to use it) */ + struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */ short type, flag; float passepartalpha, angle; diff --git a/source/blender/makesdna/DNA_key_types.h b/source/blender/makesdna/DNA_key_types.h index 4487c0c3247..c42e555d562 100644 --- a/source/blender/makesdna/DNA_key_types.h +++ b/source/blender/makesdna/DNA_key_types.h @@ -33,8 +33,8 @@ #include "DNA_listBase.h" #include "DNA_ID.h" -#include "DNA_anim_types.h" +struct AnimData; struct Ipo; typedef struct KeyBlock { @@ -57,7 +57,7 @@ typedef struct KeyBlock { typedef struct Key { ID id; - struct AnimData adt; /* animation data (must be immediately after id for utilities to use it) */ + struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */ KeyBlock *refkey; char elemstr[32]; diff --git a/source/blender/makesdna/DNA_lamp_types.h b/source/blender/makesdna/DNA_lamp_types.h index cfedb9cc0ac..c6a1a2b45e2 100644 --- a/source/blender/makesdna/DNA_lamp_types.h +++ b/source/blender/makesdna/DNA_lamp_types.h @@ -32,7 +32,6 @@ #define DNA_LAMP_TYPES_H #include "DNA_ID.h" -#include "DNA_anim_types.h" #include "DNA_scriptlink_types.h" #ifndef MAX_MTEX @@ -41,11 +40,12 @@ struct MTex; struct CurveMapping; +struct AnimData; struct Ipo; typedef struct Lamp { ID id; - struct AnimData adt; /* animation data (must be immediately after id for utilities to use it) */ + struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */ short type, flag; int mode; diff --git a/source/blender/makesdna/DNA_material_types.h b/source/blender/makesdna/DNA_material_types.h index 655d10a5310..4ffd2060568 100644 --- a/source/blender/makesdna/DNA_material_types.h +++ b/source/blender/makesdna/DNA_material_types.h @@ -32,7 +32,6 @@ #define DNA_MATERIAL_TYPES_H #include "DNA_ID.h" -#include "DNA_anim_types.h" #include "DNA_scriptlink_types.h" #include "DNA_listBase.h" @@ -44,13 +43,14 @@ struct MTex; struct ColorBand; struct Group; struct bNodeTree; +struct AnimData; struct Ipo; /* WATCH IT: change type? also make changes in ipo.h */ typedef struct Material { ID id; - struct AnimData adt; /* animation data (must be immediately after id for utilities to use it) */ + struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */ short colormodel, flag; /* note, keep this below synced with render_types.h */ diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h index 69291c1e025..eba1bde0b6f 100644 --- a/source/blender/makesdna/DNA_object_types.h +++ b/source/blender/makesdna/DNA_object_types.h @@ -35,7 +35,6 @@ #include "DNA_listBase.h" #include "DNA_ID.h" -#include "DNA_anim_types.h" #include "DNA_scriptlink_types.h" #ifdef __cplusplus @@ -44,6 +43,7 @@ extern "C" { struct bPose; struct Object; +struct AnimData; struct Ipo; struct BoundBox; struct Path; @@ -91,7 +91,7 @@ typedef struct BoundBox { typedef struct Object { ID id; - AnimData adt; /* animation data (must be immediately after id for utilities to use it) */ + struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */ short type, partype; int par1, par2, par3; /* can be vertexnrs */ diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index f9359ac61fa..4e9dfada96c 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -38,7 +38,6 @@ extern "C" { #include "DNA_listBase.h" #include "DNA_scriptlink_types.h" #include "DNA_ID.h" -#include "DNA_anim_types.h" struct Radio; struct Object; @@ -47,6 +46,7 @@ struct Scene; struct Image; struct Group; struct bNodeTree; +struct AnimData; typedef struct Base { struct Base *next, *prev; @@ -524,7 +524,7 @@ typedef struct bStats { typedef struct Scene { ID id; - struct AnimData adt; /* animation data (must be immediately after id for utilities to use it) */ + struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */ struct Object *camera; struct World *world; diff --git a/source/blender/makesdna/DNA_texture_types.h b/source/blender/makesdna/DNA_texture_types.h index c8cfc31cc3e..f37d9eca282 100644 --- a/source/blender/makesdna/DNA_texture_types.h +++ b/source/blender/makesdna/DNA_texture_types.h @@ -32,9 +32,9 @@ #define DNA_TEXTURE_TYPES_H #include "DNA_ID.h" -#include "DNA_anim_types.h" #include "DNA_image_types.h" +struct AnimData; struct Ipo; struct PluginTex; struct ColorBand; @@ -130,7 +130,7 @@ typedef struct EnvMap { typedef struct Tex { ID id; - struct AnimData adt; /* animation data (must be immediately after id for utilities to use it) */ + struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */ float noisesize, turbul; float bright, contrast, rfac, gfac, bfac; diff --git a/source/blender/makesdna/DNA_world_types.h b/source/blender/makesdna/DNA_world_types.h index 14947ec3b2d..39d8d38ec54 100644 --- a/source/blender/makesdna/DNA_world_types.h +++ b/source/blender/makesdna/DNA_world_types.h @@ -32,9 +32,9 @@ #define DNA_WORLD_TYPES_H #include "DNA_ID.h" -#include "DNA_anim_types.h" #include "DNA_scriptlink_types.h" +struct AnimData; struct Ipo; struct MTex; @@ -49,7 +49,7 @@ struct MTex; * data and modeling data. */ typedef struct World { ID id; - struct AnimData adt; /* animation data (must be immediately after id for utilities to use it) */ + struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */ short colormodel, totex; short texact, mistype; -- cgit v1.2.3