[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16800] trunk/blender/source/blender: Second try at committing IPO code cleanups...

Joshua Leung aligorith at gmail.com
Mon Sep 29 01:17:44 CEST 2008


Revision: 16800
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16800
Author:   aligorith
Date:     2008-09-29 01:17:44 +0200 (Mon, 29 Sep 2008)

Log Message:
-----------
Second try at committing IPO code cleanups...

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_ipo.h
    trunk/blender/source/blender/blenkernel/intern/curve.c
    trunk/blender/source/blender/blenkernel/intern/ipo.c
    trunk/blender/source/blender/makesdna/DNA_ipo_types.h
    trunk/blender/source/blender/src/drawobject.c

Modified: trunk/blender/source/blender/blenkernel/BKE_ipo.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_ipo.h	2008-09-28 20:49:16 UTC (rev 16799)
+++ trunk/blender/source/blender/blenkernel/BKE_ipo.h	2008-09-28 23:17:44 UTC (rev 16800)
@@ -54,41 +54,71 @@
 struct bActionChannel;
 struct rctf;
 
+/* ------------ Time Management ------------ */
+
 float frame_to_float(int cfra);
 
+/* ------------ IPO Management ---------- */
+
 void free_ipo_curve(struct IpoCurve *icu);
 void free_ipo(struct Ipo *ipo);
+
 void ipo_default_v2d_cur(int blocktype, struct rctf *cur);
+
 struct Ipo *add_ipo(char *name, int idcode);
 struct Ipo *copy_ipo(struct Ipo *ipo);
+
 void ipo_idnew(struct Ipo *ipo);
+
+struct IpoCurve *find_ipocurve(struct Ipo *ipo, int adrcode);
+short has_ipo_code(struct Ipo *ipo, int code);
+
+/* -------------- Make Local -------------- */
+
 void make_local_obipo(struct Ipo *ipo);
 void make_local_matipo(struct Ipo *ipo);
 void make_local_keyipo(struct Ipo *ipo);
 void make_local_ipo(struct Ipo *ipo);
-struct IpoCurve *find_ipocurve(struct Ipo *ipo, int adrcode);
 
+/* ------------ IPO-Curve Sanity ---------------- */
+
 void calchandles_ipocurve(struct IpoCurve *icu);
 void testhandles_ipocurve(struct IpoCurve *icu);
 void sort_time_ipocurve(struct IpoCurve *icu);
 int test_time_ipocurve(struct IpoCurve *icu);
+
+/* -------- IPO-Curve (Bezier) Calculations ---------- */
+
 void correct_bezpart(float *v1, float *v2, float *v3, float *v4);
 int findzero(float x, float q0, float q1, float q2, float q3, float *o);
 void berekeny(float f1, float f2, float f3, float f4, float *o, int b);
 void berekenx(float *f, float *o, int b);
+
+/* -------- IPO Curve Calculation and Evaluation --------- */
+
 float eval_icu(struct IpoCurve *icu, float ipotime);
 void calc_icu(struct IpoCurve *icu, float ctime);
 float calc_ipo_time(struct Ipo *ipo, float ctime);
 void calc_ipo(struct Ipo *ipo, float ctime);
+
+/* ------------ Keyframe Column Tools -------------- */
+
+void add_to_cfra_elem(struct ListBase *lb, struct BezTriple *bezt);
+void make_cfra_list(struct Ipo *ipo, struct ListBase *elems);
+
+/* ---------------- IPO DataAPI ----------------- */
+
 void write_ipo_poin(void *poin, int type, float val);
 float read_ipo_poin(void *poin, int type);
+
 void *give_mtex_poin(struct MTex *mtex, int adrcode );
-
+void *get_pchan_ipo_poin(struct bPoseChannel *pchan, int adrcode);
 void *get_ipo_poin(struct ID *id, struct IpoCurve *icu, int *type);
-void *get_pchan_ipo_poin(struct bPoseChannel *pchan, int adrcode);
 
 void set_icu_vars(struct IpoCurve *icu);
 
+/* ---------------- IPO Execution --------------- */
+
 void execute_ipo(struct ID *id, struct Ipo *ipo);
 void execute_action_ipo(struct bActionChannel *achan, struct bPoseChannel *pchan);
 
@@ -99,22 +129,17 @@
 void do_seq_ipo(struct Sequence *seq, int cfra);
 void do_ob_ipodrivers(struct Object *ob, struct Ipo *ipo, float ctime);
 
-int has_ipo_code(struct Ipo *ipo, int code);
 void do_all_data_ipos(void);
-int calc_ipo_spec(struct Ipo *ipo, int adrcode, float *ctime);
+short calc_ipo_spec(struct Ipo *ipo, int adrcode, float *ctime);
 void clear_delta_obipo(struct Ipo *ipo);
-void add_to_cfra_elem(struct ListBase *lb, struct BezTriple *bezt);
-void make_cfra_list(struct Ipo *ipo, struct ListBase *elems);
 
-/* the sort is an IPO_Channel... */
-int IPO_GetChannels(struct Ipo *ipo, short *channels);
+/* ----------- IPO <-> GameEngine API ---------------- */
 
-float IPO_GetFloatValue(struct Ipo *ipo,
-/*  						struct IPO_Channel channel, */
-						/* channels are shorts... bit ugly for now*/
-						short c,
-						float ctime);
+/* the short is an IPO_Channel... */
 
+short IPO_GetChannels(struct Ipo *ipo, short *channels);
+float IPO_GetFloatValue(struct Ipo *ipo, short c, float ctime);
+
 #ifdef __cplusplus
 };
 #endif

Modified: trunk/blender/source/blender/blenkernel/intern/curve.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/curve.c	2008-09-28 20:49:16 UTC (rev 16799)
+++ trunk/blender/source/blender/blenkernel/intern/curve.c	2008-09-28 23:17:44 UTC (rev 16800)
@@ -1509,7 +1509,7 @@
 	BevList *bl, *blnew, *blnext;
 	BevPoint *bevp, *bevp2, *bevp1 = NULL, *bevp0;
 	float min, inp, x1, x2, y1, y2, vec[3];
-	float *coord_array, *tilt_array=NULL, *radius_array=NULL, *coord_fp, *tilt_fp=NULL, *radius_fp;
+	float *coord_array, *tilt_array=NULL, *radius_array=NULL, *coord_fp, *tilt_fp=NULL, *radius_fp=NULL;
 	float *v1, *v2;
 	struct bevelsort *sortdata, *sd, *sd1;
 	int a, b, nr, poly, resolu, len=0;

Modified: trunk/blender/source/blender/blenkernel/intern/ipo.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/ipo.c	2008-09-28 20:49:16 UTC (rev 16799)
+++ trunk/blender/source/blender/blenkernel/intern/ipo.c	2008-09-28 23:17:44 UTC (rev 16800)
@@ -23,7 +23,7 @@
  *
  * The Original Code is: all of this file.
  *
- * Contributor(s): none yet.
+ * Contributor(s): 2008, Joshua Leung (IPO System cleanup)
  *
  * ***** END GPL LICENSE BLOCK *****
  */
@@ -77,11 +77,16 @@
 
 #define SMALL -1.0e-10
 
+/* ***************************** Adrcode Blocktype Defines ********************************* */
+
 /* This array concept was meant to make sure that defines such as OB_LOC_X
    don't have to be enumerated, also for backward compatibility, future changes,
    and to enable it all can be accessed with a for-next loop.
+   
+   This should whole adrcode system should eventually be replaced by a proper Data API
 */
 
+
 int co_ar[CO_TOTIPO]= {
 	CO_ENFORCE, CO_HEADTAIL
 };
@@ -151,9 +156,9 @@
 };
 
 int la_ar[LA_TOTIPO]= {
-	LA_ENERGY,  LA_COL_R, LA_COL_G,  LA_COL_B, 
+	LA_ENERGY, LA_COL_R, LA_COL_G, LA_COL_B, 
 	LA_DIST, LA_SPOTSI, LA_SPOTBL, 
-	LA_QUAD1,  LA_QUAD2,  LA_HALOINT,  
+	LA_QUAD1, LA_QUAD2, LA_HALOINT,  
 
 	MA_MAP1+MAP_OFS_X, MA_MAP1+MAP_OFS_Y, MA_MAP1+MAP_OFS_Z, 
 	MA_MAP1+MAP_SIZE_X, MA_MAP1+MAP_SIZE_Y, MA_MAP1+MAP_SIZE_Z, 
@@ -187,450 +192,605 @@
 	PART_BB_TILT, PART_PD_FSTR, PART_PD_FFALL, PART_PD_FMAXD, PART_PD2_FSTR, PART_PD2_FFALL, PART_PD2_FMAXD
 };
 
+/* ************************** Data-Level Functions ************************* */
 
-float frame_to_float(int cfra)		/* see also bsystem_time in object.c */
+/* ---------------------- Freeing --------------------------- */
+
+/* frees the ipo curve itself too */
+void free_ipo_curve (IpoCurve *icu) 
 {
-	extern float bluroffs;	/* bad stuff borrowed from object.c */
-	extern float fieldoffs;
-	float ctime;
+	if (icu == NULL) 
+		return;
 	
-	ctime= (float)cfra;
-	ctime+= bluroffs+fieldoffs;
-	ctime*= G.scene->r.framelen;
+	if (icu->bezt) 
+		MEM_freeN(icu->bezt);
+	if (icu->driver) 
+		MEM_freeN(icu->driver);
 	
-	return ctime;
-}
-
-/* includes ipo curve itself */
-void free_ipo_curve(IpoCurve *icu) 
-{
-	if(icu->bezt) MEM_freeN(icu->bezt);
-	if(icu->bp) MEM_freeN(icu->bp);
-	if(icu->driver) MEM_freeN(icu->driver);
 	MEM_freeN(icu);
 }
 
 /* do not free ipo itself */
-void free_ipo(Ipo *ipo)
+void free_ipo (Ipo *ipo)
 {
-	IpoCurve *icu;
+	IpoCurve *icu, *icn;
 	
-	while( (icu= ipo->curve.first) ) {
+	if (ipo == NULL) 
+		return;
+	
+	for (icu= ipo->curve.first; icu; icu= icn) {
+		icn= icu->next;
+		
+		/* must remove the link before freeing, as the curve is freed too */
 		BLI_remlink(&ipo->curve, icu);
 		free_ipo_curve(icu);
 	}
 }
 
+/* ---------------------- Init --------------------------- */
+
 /* on adding new ipos, or for empty views */
-void ipo_default_v2d_cur(int blocktype, rctf *cur)
+void ipo_default_v2d_cur (int blocktype, rctf *cur)
 {
-	if(blocktype==ID_CA) {
+	switch (blocktype) {
+	case ID_CA:
 		cur->xmin= G.scene->r.sfra;
 		cur->xmax= G.scene->r.efra;
 		cur->ymin= 0.0;
 		cur->ymax= 100.0;
-	}
-	else if ELEM5(blocktype, ID_MA, ID_CU, ID_WO, ID_LA, ID_CO) {
+		break;
+		
+	case ID_MA: case ID_WO: case ID_LA: 
+	case ID_CU: case ID_CO:
 		cur->xmin= (float)G.scene->r.sfra-0.1;
 		cur->xmax= G.scene->r.efra;
 		cur->ymin= (float)-0.1;
 		cur->ymax= (float)+1.1;
-	}
-	else if(blocktype==ID_TE) {
+		break;
+		
+	case ID_TE:
 		cur->xmin= (float)G.scene->r.sfra-0.1;
 		cur->xmax= G.scene->r.efra;
 		cur->ymin= (float)-0.1;
 		cur->ymax= (float)+1.1;
-	}
-	else if(blocktype==ID_SEQ) {
+		break;
+		
+	case ID_SEQ:
 		cur->xmin= -5.0;
 		cur->xmax= 105.0;
 		cur->ymin= (float)-0.1;
 		cur->ymax= (float)+1.1;
-	}
-	else if(blocktype==ID_KE) {
+		break;
+		
+	case ID_KE:
 		cur->xmin= (float)G.scene->r.sfra-0.1;
 		cur->xmax= G.scene->r.efra;
 		cur->ymin= (float)-0.1;
 		cur->ymax= (float)+2.1;
-	}
-	else {  /* ID_OB and everything else */
+		break;
+		
+	default:	/* ID_OB and everything else */
 		cur->xmin= G.scene->r.sfra;
 		cur->xmax= G.scene->r.efra;
 		cur->ymin= -5.0;
 		cur->ymax= +5.0;
+		break;
 	}
 }
 
-
-Ipo *add_ipo(char *name, int idcode)
+/* create a new IPO block (allocates the block) */
+Ipo *add_ipo (char name[], int blocktype)
 {
 	Ipo *ipo;
 	
 	ipo= alloc_libblock(&G.main->ipo, ID_IP, name);
-	ipo->blocktype= idcode;
-	ipo_default_v2d_cur(idcode, &ipo->cur);
+	ipo->blocktype= blocktype;
+	ipo_default_v2d_cur(blocktype, &ipo->cur);
 
 	return ipo;
 }
 
-Ipo *copy_ipo(Ipo *ipo)
+/* ---------------------- Copy --------------------------- */
+
+/* duplicate an IPO block and all its data  */
+Ipo *copy_ipo (Ipo *src)
 {
-	Ipo *ipon;
+	Ipo *dst;
 	IpoCurve *icu;
 	
-	if(ipo==NULL) return 0;
+	if (src == NULL) 
+		return NULL;
 	
-	ipon= copy_libblock(ipo);
-	
-	duplicatelist(&(ipon->curve), &(ipo->curve));
+	dst= copy_libblock(src);
+	duplicatelist(&dst->curve, &src->curve);
 
-	for(icu= ipo->curve.first; icu; icu= icu->next) {
+	for (icu= src->curve.first; icu; icu= icu->next) {
 		icu->bezt= MEM_dupallocN(icu->bezt);
-		if(icu->driver) icu->driver= MEM_dupallocN(icu->driver);
+		
+		if (icu->driver) 
+			icu->driver= MEM_dupallocN(icu->driver);
 	}
 	
-	return ipon;
+	return dst;
 }
 
-/* uses id->newid to match pointers with other copied data */
-void ipo_idnew(Ipo *ipo)
+/* ---------------------- Relink --------------------------- */
+
+/* uses id->newid to match pointers with other copied data 
+ * 	- called after single-user or other such
+ */
+void ipo_idnew (Ipo *ipo)
 {
-	if(ipo) {
+	if (ipo) {
 		IpoCurve *icu;
 		
-		for(icu= ipo->curve.first; icu; icu= icu->next) {
-			if(icu->driver) {
+		for (icu= ipo->curve.first; icu; icu= icu->next) {
+			if (icu->driver)
 				ID_NEW(icu->driver->ob);
-			}
 		}
 	}
 }
 
-void make_local_obipo(Ipo *ipo)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list