* speedup for animating bones, in one scene with sintel and a dragon animated its over 4x faster.

* utility function BLI_findstring to avoid listbase lookup loops everywhere.
  eg: 
    ListBase *lb= objects= &CTX_data_main(C)->object;
    Object *ob= BLI_findstring(lb, name, offsetof(ID, name) + 2);

* made some more math functions use const's, (fix warnings I made in previous commits)
This commit is contained in:
2009-12-29 15:40:26 +00:00
parent d5cef9a30d
commit 5cd837a562
12 changed files with 81 additions and 167 deletions

View File

@@ -220,8 +220,6 @@ const struct ListBase *BKE_spacetypes_list(void);
void BKE_spacetype_register(struct SpaceType *st); void BKE_spacetype_register(struct SpaceType *st);
void BKE_spacetypes_free(void); /* only for quitting blender */ void BKE_spacetypes_free(void); /* only for quitting blender */
// MenuType *BKE_spacemenu_find(const char *idname, int spacetype);
/* spacedata */ /* spacedata */
void BKE_spacedata_freelist(ListBase *lb); void BKE_spacedata_freelist(ListBase *lb);
void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2); void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2);

View File

@@ -379,19 +379,10 @@ bActionGroup *action_groups_find_named (bAction *act, const char name[])
/* usually used within a loop, so we got a N^2 slowdown */ /* usually used within a loop, so we got a N^2 slowdown */
bPoseChannel *get_pose_channel(const bPose *pose, const char *name) bPoseChannel *get_pose_channel(const bPose *pose, const char *name)
{ {
bPoseChannel *chan;
if (ELEM(NULL, pose, name) || (name[0] == 0)) if (ELEM(NULL, pose, name) || (name[0] == 0))
return NULL; return NULL;
for (chan=pose->chanbase.first; chan; chan=chan->next) { return BLI_findstring(&pose->chanbase, name, offsetof(bPoseChannel, name));
if (chan->name[0] == name[0]) {
if (!strcmp (chan->name, name))
return chan;
}
}
return NULL;
} }
/* Use with care, not on Armature poses but for temporal ones */ /* Use with care, not on Armature poses but for temporal ones */

View File

@@ -38,6 +38,7 @@
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h>
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
@@ -844,18 +845,8 @@ void free_main(Main *mainvar)
ID *find_id(char *type, char *name) /* type: "OB" or "MA" etc */ ID *find_id(char *type, char *name) /* type: "OB" or "MA" etc */
{ {
ID *id; ListBase *lb= wich_libbase(G.main, GS(type));
ListBase *lb; return BLI_findstring(lb, name, offsetof(ID, name) + 2);
lb= wich_libbase(G.main, GS(type));
id= lb->first;
while(id) {
if(id->name[2]==name[0] && strcmp(id->name+2, name)==0 )
return id;
id= id->next;
}
return 0;
} }
static void get_flags_for_id(ID *id, char *buf) static void get_flags_for_id(ID *id, char *buf)
@@ -1336,11 +1327,7 @@ void test_idbutton(char *name)
if(lb==0) return; if(lb==0) return;
/* search for id */ /* search for id */
idtest= lb->first; idtest= BLI_findstring(lb, name, offsetof(ID, name) + 2);
while(idtest) {
if( strcmp(idtest->name+2, name)==0) break;
idtest= idtest->next;
}
if(idtest) if( new_id(lb, idtest, name)==0 ) sort_alpha_id(lb, idtest); if(idtest) if( new_id(lb, idtest, name)==0 ) sort_alpha_id(lb, idtest);
} }

View File

@@ -44,6 +44,7 @@ void addlisttolist(struct ListBase *list1, struct ListBase *list2);
void BLI_insertlink(struct ListBase *listbase, void *vprevlink, void *vnewlink); void BLI_insertlink(struct ListBase *listbase, void *vprevlink, void *vnewlink);
void *BLI_findlink(struct ListBase *listbase, int number); void *BLI_findlink(struct ListBase *listbase, int number);
int BLI_findindex(struct ListBase *listbase, void *vlink); int BLI_findindex(struct ListBase *listbase, void *vlink);
void *BLI_findstring(struct ListBase *listbase, const char *id, int offset);
void BLI_freelistN(struct ListBase *listbase); void BLI_freelistN(struct ListBase *listbase);
void BLI_addtail(struct ListBase *listbase, void *vlink); void BLI_addtail(struct ListBase *listbase, void *vlink);
void BLI_remlink(struct ListBase *listbase, void *vlink); void BLI_remlink(struct ListBase *listbase, void *vlink);

View File

@@ -81,22 +81,22 @@ MINLINE void madd_v3_v3v3fl(float r[3], float a[3], float b[3], float f);
MINLINE void madd_v3_v3v3v3(float r[3], float a[3], float b[3], float c[3]); MINLINE void madd_v3_v3v3v3(float r[3], float a[3], float b[3], float c[3]);
MINLINE void negate_v3(float r[3]); MINLINE void negate_v3(float r[3]);
MINLINE void negate_v3_v3(float r[3], float a[3]); MINLINE void negate_v3_v3(float r[3], const float a[3]);
MINLINE float dot_v2v2(float a[2], float b[2]); MINLINE float dot_v2v2(const float a[2], const float b[2]);
MINLINE float dot_v3v3(float a[3], float b[3]); MINLINE float dot_v3v3(const float a[3], const float b[3]);
MINLINE float cross_v2v2(float a[2], float b[2]); MINLINE float cross_v2v2(const float a[2], const float b[2]);
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3]); MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3]);
MINLINE void star_m3_v3(float R[3][3],float a[3]); MINLINE void star_m3_v3(float R[3][3],float a[3]);
/*********************************** Length **********************************/ /*********************************** Length **********************************/
MINLINE float len_v2(float a[2]); MINLINE float len_v2(const float a[2]);
MINLINE float len_v2v2(float a[2], float b[2]); MINLINE float len_v2v2(const float a[2], const float b[2]);
MINLINE float len_v3(float a[3]); MINLINE float len_v3(const float a[3]);
MINLINE float len_v3v3(float a[3], float b[3]); MINLINE float len_v3v3(const float a[3], const float b[3]);
MINLINE float normalize_v2(float r[2]); MINLINE float normalize_v2(float r[2]);
MINLINE float normalize_v3(float r[3]); MINLINE float normalize_v3(float r[3]);

View File

@@ -343,6 +343,26 @@ int BLI_findindex(ListBase *listbase, void *vlink)
return -1; return -1;
} }
void *BLI_findstring(ListBase *listbase, const char *id, int offset)
{
Link *link= NULL;
const char *id_iter;
if (listbase == NULL) return NULL;
link= listbase->first;
while (link) {
id_iter= ((const char *)link) + offset;
printf("ASS '%s'\n", id_iter);
if(id[0] == id_iter[0] && strcmp(id, id_iter)==0)
return link;
link= link->next;
}
return NULL;
}
void BLI_duplicatelist(ListBase *list1, const ListBase *list2) void BLI_duplicatelist(ListBase *list1, const ListBase *list2)
{ {
struct Link *link1, *link2; struct Link *link1, *link2;

View File

@@ -194,24 +194,24 @@ MINLINE void negate_v3(float r[3])
r[2]= -r[2]; r[2]= -r[2];
} }
MINLINE void negate_v3_v3(float r[3], float a[3]) MINLINE void negate_v3_v3(float r[3], const float a[3])
{ {
r[0]= -a[0]; r[0]= -a[0];
r[1]= -a[1]; r[1]= -a[1];
r[2]= -a[2]; r[2]= -a[2];
} }
MINLINE float dot_v2v2(float *a, float *b) MINLINE float dot_v2v2(const float a[2], const float b[2])
{ {
return a[0]*b[0] + a[1]*b[1]; return a[0]*b[0] + a[1]*b[1];
} }
MINLINE float dot_v3v3(float a[3], float b[3]) MINLINE float dot_v3v3(const float a[3], const float b[3])
{ {
return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]; return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];
} }
MINLINE float cross_v2v2(float a[2], float b[2]) MINLINE float cross_v2v2(const float a[2], const float b[2])
{ {
return a[0]*b[1] - a[1]*b[0]; return a[0]*b[1] - a[1]*b[0];
} }
@@ -236,12 +236,12 @@ MINLINE void star_m3_v3(float mat[][3], float *vec)
/*********************************** Length **********************************/ /*********************************** Length **********************************/
MINLINE float len_v2(float *v) MINLINE float len_v2(const float v[2])
{ {
return (float)sqrt(v[0]*v[0] + v[1]*v[1]); return (float)sqrt(v[0]*v[0] + v[1]*v[1]);
} }
MINLINE float len_v2v2(float *v1, float *v2) MINLINE float len_v2v2(const float v1[2], const float v2[2])
{ {
float x, y; float x, y;
@@ -250,12 +250,12 @@ MINLINE float len_v2v2(float *v1, float *v2)
return (float)sqrt(x*x+y*y); return (float)sqrt(x*x+y*y);
} }
MINLINE float len_v3(float a[3]) MINLINE float len_v3(const float a[3])
{ {
return sqrtf(dot_v3v3(a, a)); return sqrtf(dot_v3v3(a, a));
} }
MINLINE float len_v3v3(float a[3], float b[3]) MINLINE float len_v3v3(const float a[3], const float b[3])
{ {
float d[3]; float d[3];

View File

@@ -23,6 +23,7 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h>
#include <string.h> #include <string.h>
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
@@ -920,18 +921,11 @@ static void draw_constraint_spaceselect (uiBlock *block, bConstraint *con, short
static void test_obpoin_but(bContext *C, char *name, ID **idpp) static void test_obpoin_but(bContext *C, char *name, ID **idpp)
{ {
ID *id; ID *id= BLI_findstring(&CTX_data_main(C)->object, name, offsetof(ID, name) + 2);
*idpp= id; /* can be NULL */
id= CTX_data_main(C)->object.first; if(id)
while(id) { id_lib_extern(id); /* checks lib data, sets correct flag for saving then */
if( strcmp(name, id->name+2)==0 ) {
*idpp= id;
id_lib_extern(id); /* checks lib data, sets correct flag for saving then */
return;
}
id= id->next;
}
*idpp= NULL;
} }
/* draw panel showing settings for a constraint */ /* draw panel showing settings for a constraint */

View File

@@ -975,107 +975,45 @@ static void verify_logicbutton_func(bContext *C, void *data1, void *data2)
static void test_scriptpoin_but(struct bContext *C, char *name, ID **idpp) static void test_scriptpoin_but(struct bContext *C, char *name, ID **idpp)
{ {
ID *id; *idpp= BLI_findstring(&CTX_data_main(C)->text, name, offsetof(ID, name) + 2);
id= CTX_data_main(C)->text.first;
while(id) {
if( strcmp(name, id->name+2)==0 ) {
*idpp= id;
return;
}
id= id->next;
}
*idpp= NULL;
} }
static void test_actionpoin_but(struct bContext *C, char *name, ID **idpp) static void test_actionpoin_but(struct bContext *C, char *name, ID **idpp)
{ {
ID *id; *idpp= BLI_findstring(&CTX_data_main(C)->text, name, offsetof(ID, name) + 2);
if(*idpp)
id= CTX_data_main(C)->action.first; id_us_plus(*idpp);
while(id) {
if( strcmp(name, id->name+2)==0 ) {
id_us_plus(id);
*idpp= id;
return;
}
id= id->next;
}
*idpp= NULL;
} }
static void test_obpoin_but(struct bContext *C, char *name, ID **idpp) static void test_obpoin_but(struct bContext *C, char *name, ID **idpp)
{ {
ID *id; *idpp= BLI_findstring(&CTX_data_main(C)->object, name, offsetof(ID, name) + 2);
if(*idpp)
id= CTX_data_main(C)->object.first; id_lib_extern(*idpp); /* checks lib data, sets correct flag for saving then */
while(id) {
if( strcmp(name, id->name+2)==0 ) {
*idpp= id;
id_lib_extern(id); /* checks lib data, sets correct flag for saving then */
return;
}
id= id->next;
}
*idpp= NULL;
} }
static void test_meshpoin_but(struct bContext *C, char *name, ID **idpp) static void test_meshpoin_but(struct bContext *C, char *name, ID **idpp)
{ {
ID *id; *idpp= BLI_findstring(&CTX_data_main(C)->mesh, name, offsetof(ID, name) + 2);
if(*idpp)
if( *idpp ) (*idpp)->us--; id_us_plus(*idpp);
id= CTX_data_main(C)->mesh.first;
while(id) {
if( strcmp(name, id->name+2)==0 ) {
*idpp= id;
id_us_plus(id);
return;
}
id= id->next;
}
*idpp= NULL;
} }
static void test_matpoin_but(struct bContext *C, char *name, ID **idpp) static void test_matpoin_but(struct bContext *C, char *name, ID **idpp)
{ {
ID *id; *idpp= BLI_findstring(&CTX_data_main(C)->mat, name, offsetof(ID, name) + 2);
if(*idpp)
if( *idpp ) (*idpp)->us--; id_us_plus(*idpp);
id= CTX_data_main(C)->mat.first;
while(id) {
if( strcmp(name, id->name+2)==0 ) {
*idpp= id;
id_us_plus(id);
return;
}
id= id->next;
}
*idpp= NULL;
} }
static void test_scenepoin_but(struct bContext *C, char *name, ID **idpp) static void test_scenepoin_but(struct bContext *C, char *name, ID **idpp)
{ {
ID *id; *idpp= BLI_findstring(&CTX_data_main(C)->scene, name, offsetof(ID, name) + 2);
if(*idpp)
if( *idpp ) (*idpp)->us--; id_us_plus(*idpp);
id= CTX_data_main(C)->scene.first;
while(id) {
if( strcmp(name, id->name+2)==0 ) {
*idpp= id;
id_us_plus(id);
return;
}
id= id->next;
}
*idpp= NULL;
} }
static void test_keyboard_event(struct bContext *C, void *arg_ks, void *arg_unused) static void test_keyboard_event(struct bContext *C, void *arg_ks, void *arg_unused)
{ {
bKeyboardSensor *ks= (bKeyboardSensor*)arg_ks; bKeyboardSensor *ks= (bKeyboardSensor*)arg_ks;

View File

@@ -58,6 +58,8 @@
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
#include "RNA_access.h"
static void rna_Pose_update(Main *bmain, Scene *scene, PointerRNA *ptr) static void rna_Pose_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{ {
// XXX when to use this? ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK); // XXX when to use this? ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
@@ -509,6 +511,16 @@ static int rna_PoseChannel_rotation_4d_editable(PointerRNA *ptr, int index)
return PROP_EDITABLE; return PROP_EDITABLE;
} }
/* not essential, but much faster then the default lookup function */
PointerRNA rna_PoseBones_lookup_string(PointerRNA *ptr, const char *key)
{
PointerRNA rptr;
bPose *pose= (bPose*)ptr->data;
bPoseChannel *pchan= BLI_findstring(&pose->chanbase, key, offsetof(bPoseChannel, name));
RNA_pointer_create(ptr->id.data, &RNA_PoseBone, pchan, &rptr);
return rptr;
}
#else #else
static void rna_def_bone_group(BlenderRNA *brna) static void rna_def_bone_group(BlenderRNA *brna)
@@ -1077,7 +1089,7 @@ static void rna_def_pose(BlenderRNA *brna)
RNA_def_property_collection_sdna(prop, NULL, "chanbase", NULL); RNA_def_property_collection_sdna(prop, NULL, "chanbase", NULL);
RNA_def_property_struct_type(prop, "PoseBone"); RNA_def_property_struct_type(prop, "PoseBone");
RNA_def_property_ui_text(prop, "Pose Bones", "Individual pose bones for the armature."); RNA_def_property_ui_text(prop, "Pose Bones", "Individual pose bones for the armature.");
RNA_def_property_collection_funcs(prop, 0, 0, 0, 0, 0, 0, "rna_PoseBones_lookup_string"); /* can be removed, only for fast lookup */
/* bone groups */ /* bone groups */
prop= RNA_def_property(srna, "bone_groups", PROP_COLLECTION, PROP_NONE); prop= RNA_def_property(srna, "bone_groups", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "agroups", NULL); RNA_def_property_collection_sdna(prop, NULL, "agroups", NULL);

View File

@@ -33,6 +33,8 @@
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
#include "BKE_text.h" /* txt_to_buf */ #include "BKE_text.h" /* txt_to_buf */
#include "BKE_main.h" #include "BKE_main.h"
#include "BLI_listbase.h"
#include <stddef.h>
static Main *bpy_import_main= NULL; static Main *bpy_import_main= NULL;
@@ -100,10 +102,7 @@ PyObject *bpy_text_import_name( char *name, int *found )
memcpy( txtname, name, namelen ); memcpy( txtname, name, namelen );
memcpy( &txtname[namelen], ".py", 4 ); memcpy( &txtname[namelen], ".py", 4 );
for(text = maggie->text.first; text; text = text->id.next) { text= BLI_findstring(&maggie->text, txtname, offsetof(ID, name) + 2);
if( !strcmp( txtname, text->id.name+2 ) )
break;
}
if( !text ) if( !text )
return NULL; return NULL;
@@ -142,12 +141,7 @@ PyObject *bpy_text_reimport( PyObject *module, int *found )
return NULL; return NULL;
/* look up the text object */ /* look up the text object */
text = ( Text * ) & ( maggie->text.first ); text= BLI_findstring(&maggie->text, txtname, offsetof(ID, name) + 2);
while( text ) {
if( !strcmp( txtname, text->id.name+2 ) )
break;
text = text->id.next;
}
/* uh-oh.... didn't find it */ /* uh-oh.... didn't find it */
if( !text ) if( !text )

View File

@@ -675,23 +675,6 @@ IpoCurve* findIpoCurve(IpoCurve* first, const char* searchName)
return 0; return 0;
} }
// this is not longer necesary //rcruiz
/*Ipo* KX_BlenderSceneConverter::findIpoForName(char* objName)
{
Ipo* ipo_iter = (Ipo*)m_maggie->ipo.first;
while( ipo_iter )
{
if( strcmp( objName, ipo_iter->id.name + 2 ) == 0 )
{
return ipo_iter;
}
ipo_iter = (Ipo*)ipo_iter->id.next;
}
return 0;
}
*/
void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo) void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo)
{ {
@@ -1374,12 +1357,8 @@ bool KX_BlenderSceneConverter::MergeScene(KX_Scene *to, KX_Scene *from)
* it does not convert */ * it does not convert */
RAS_MeshObject *KX_BlenderSceneConverter::ConvertMeshSpecial(KX_Scene* kx_scene, Main *maggie, const char *name) RAS_MeshObject *KX_BlenderSceneConverter::ConvertMeshSpecial(KX_Scene* kx_scene, Main *maggie, const char *name)
{ {
ID *me;
/* Find a mesh in the current main */ /* Find a mesh in the current main */
for(me = (ID *)m_maggie->mesh.first; me; me= (ID *)me->next) ID *me= static_cast<ID *>(BLI_findstring(&m_maggie->mesh, name, offsetof(ID, name) + 2));
if(strcmp(name, me->name+2)==0)
break;
if(me==NULL) { if(me==NULL) {
printf("Could not be found \"%s\"\n", name); printf("Could not be found \"%s\"\n", name);