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)...
This commit is contained in:
Joshua Leung
2009-01-17 05:36:58 +00:00
parent ee180ff5ac
commit 023765eb48
13 changed files with 92 additions and 37 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -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 */

View File

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

View File

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

View File

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

View File

@@ -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 */

View File

@@ -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 */

View File

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

View File

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

View File

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