[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27728] branches/render25/source/blender: Render Branch: Optimization for pose channel name lookups using a hash, makes

Brecht Van Lommel brecht at blender.org
Wed Mar 24 19:15:30 CET 2010


Revision: 27728
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27728
Author:   blendix
Date:     2010-03-24 19:15:29 +0100 (Wed, 24 Mar 2010)

Log Message:
-----------
Render Branch: Optimization for pose channel name lookups using a hash, makes
playback in one particular scene with 3 characters go from 10 to 13 fps.

Modified Paths:
--------------
    branches/render25/source/blender/blenkernel/BKE_action.h
    branches/render25/source/blender/blenkernel/intern/action.c
    branches/render25/source/blender/blenkernel/intern/armature.c
    branches/render25/source/blender/blenkernel/intern/object.c
    branches/render25/source/blender/blenloader/intern/readfile.c
    branches/render25/source/blender/editors/armature/editarmature.c
    branches/render25/source/blender/makesdna/DNA_action_types.h
    branches/render25/source/blender/makesrna/intern/rna_pose.c

Modified: branches/render25/source/blender/blenkernel/BKE_action.h
===================================================================
--- branches/render25/source/blender/blenkernel/BKE_action.h	2010-03-24 18:14:57 UTC (rev 27727)
+++ branches/render25/source/blender/blenkernel/BKE_action.h	2010-03-24 18:15:29 UTC (rev 27728)
@@ -129,6 +129,13 @@
  */
 void free_pose_channels(struct bPose *pose);
 
+/**
+ * Removes the hash for quick lookup of channels, must
+ * be done when adding/removing channels.
+ */
+void make_pose_channels_hash(struct bPose *pose);
+void free_pose_channels_hash(struct bPose *pose);
+
 /** 
  * Removes and deallocates all data from a pose, and also frees the pose.
  */

Modified: branches/render25/source/blender/blenkernel/intern/action.c
===================================================================
--- branches/render25/source/blender/blenkernel/intern/action.c	2010-03-24 18:14:57 UTC (rev 27727)
+++ branches/render25/source/blender/blenkernel/intern/action.c	2010-03-24 18:15:29 UTC (rev 27728)
@@ -56,8 +56,9 @@
 
 #include "BIK_api.h"
 
+#include "BLI_blenlib.h"
+#include "BLI_ghash.h"
 #include "BLI_math.h"
-#include "BLI_blenlib.h"
 
 #include "RNA_access.h"
 
@@ -370,6 +371,9 @@
 	if (ELEM(NULL, pose, name) || (name[0] == 0))
 		return NULL;
 	
+	if(pose->chanhash)
+		return BLI_ghash_lookup(pose->chanhash, name);
+	
 	return BLI_findstring(&((bPose *)pose)->chanbase, name, offsetof(bPoseChannel, name));
 }
 
@@ -405,6 +409,7 @@
 	chan->protectflag = OB_LOCK_ROT4D;	/* lock by components by default */
 	
 	BLI_addtail(&pose->chanbase, chan);
+	free_pose_channels_hash(pose);
 	
 	return chan;
 }
@@ -519,6 +524,26 @@
 	}
 }
 
+void make_pose_channels_hash(bPose *pose) 
+{
+	if(!pose->chanhash) {
+		bPoseChannel *pchan;
+
+		pose->chanhash= BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp);
+		for(pchan=pose->chanbase.first; pchan; pchan=pchan->next)
+			BLI_ghash_insert(pose->chanhash, pchan->name, pchan);
+	}
+}
+
+void free_pose_channels_hash(bPose *pose) 
+{
+	if(pose->chanhash) {
+		BLI_ghash_free(pose->chanhash, NULL, NULL);
+		pose->chanhash= NULL;
+	}
+}
+
+
 void free_pose_channel(bPoseChannel *pchan)
 {
 	// XXX this case here will need to be removed when the new motionpaths are ready
@@ -550,6 +575,8 @@
 		
 		BLI_freelistN(&pose->chanbase);
 	}
+
+	free_pose_channels_hash(pose);
 }
 
 void free_pose(bPose *pose)

Modified: branches/render25/source/blender/blenkernel/intern/armature.c
===================================================================
--- branches/render25/source/blender/blenkernel/intern/armature.c	2010-03-24 18:14:57 UTC (rev 27727)
+++ branches/render25/source/blender/blenkernel/intern/armature.c	2010-03-24 18:15:29 UTC (rev 27728)
@@ -1675,6 +1675,7 @@
 		next= pchan->next;
 		if(pchan->bone==NULL) {
 			free_pose_channel(pchan);
+			free_pose_channels_hash(pose);
 			BLI_freelinkN(&pose->chanbase, pchan);
 		}
 	}

Modified: branches/render25/source/blender/blenkernel/intern/object.c
===================================================================
--- branches/render25/source/blender/blenkernel/intern/object.c	2010-03-24 18:14:57 UTC (rev 27727)
+++ branches/render25/source/blender/blenkernel/intern/object.c	2010-03-24 18:15:29 UTC (rev 27728)
@@ -2485,6 +2485,10 @@
 void object_handle_update(Scene *scene, Object *ob)
 {
 	if(ob->recalc & OB_RECALC) {
+		/* speed optimization for animation lookups */
+		if(ob->pose)
+			make_pose_channels_hash(ob->pose);
+
 		/* XXX new animsys warning: depsgraph tag OB_RECALC_DATA should not skip drivers, 
 		   which is only in where_is_object now */
 		if(ob->recalc & OB_RECALC) {

Modified: branches/render25/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/render25/source/blender/blenloader/intern/readfile.c	2010-03-24 18:14:57 UTC (rev 27727)
+++ branches/render25/source/blender/blenloader/intern/readfile.c	2010-03-24 18:15:29 UTC (rev 27728)
@@ -3652,6 +3652,8 @@
 	link_list(fd, &pose->chanbase);
 	link_list(fd, &pose->agroups);
 
+	pose->chanhash= NULL;
+
 	for (pchan = pose->chanbase.first; pchan; pchan=pchan->next) {
 		pchan->bone= NULL;
 		pchan->parent= newdataadr(fd, pchan->parent);

Modified: branches/render25/source/blender/editors/armature/editarmature.c
===================================================================
--- branches/render25/source/blender/editors/armature/editarmature.c	2010-03-24 18:14:57 UTC (rev 27727)
+++ branches/render25/source/blender/editors/armature/editarmature.c	2010-03-24 18:15:29 UTC (rev 27728)
@@ -892,6 +892,8 @@
 				
 				BLI_remlink(&opose->chanbase, pchan);
 				BLI_addtail(&pose->chanbase, pchan);
+				free_pose_channels_hash(opose);
+				free_pose_channels_hash(pose);
 			}
 			
 			ED_base_object_free_and_unlink(scene, base);
@@ -1095,6 +1097,7 @@
 			
 			/* free any of the extra-data this pchan might have */
 			free_pose_channel(pchan);
+			free_pose_channels_hash(ob->pose);
 			
 			/* get rid of unneeded bone */
 			bone_free(arm, curbone);
@@ -1802,6 +1805,7 @@
 			
 			if (curBone && (curBone->flag & BONE_SELECTED) && (arm->layer & curBone->layer)) {
 				free_pose_channel(pchan);
+				free_pose_channels_hash(obedit->pose);
 				BLI_freelinkN (&obedit->pose->chanbase, pchan);
 			}
 			else {

Modified: branches/render25/source/blender/makesdna/DNA_action_types.h
===================================================================
--- branches/render25/source/blender/makesdna/DNA_action_types.h	2010-03-24 18:14:57 UTC (rev 27727)
+++ branches/render25/source/blender/makesdna/DNA_action_types.h	2010-03-24 18:15:29 UTC (rev 27728)
@@ -40,6 +40,7 @@
 struct SpaceLink;
 struct Object;
 struct Group;
+struct GHash;
 
 /* ************************************************ */
 /* Visualisation */
@@ -326,6 +327,7 @@
  */
 typedef struct bPose {
 	ListBase chanbase; 			/* list of pose channels, PoseBones in RNA */
+	struct GHash *chanhash;		/* ghash for quicker string lookups */
 	
 	short flag, proxy_layer;	/* proxy layer: copy from armature, gets synced */
 	

Modified: branches/render25/source/blender/makesrna/intern/rna_pose.c
===================================================================
--- branches/render25/source/blender/makesrna/intern/rna_pose.c	2010-03-24 18:14:57 UTC (rev 27727)
+++ branches/render25/source/blender/makesrna/intern/rna_pose.c	2010-03-24 18:15:29 UTC (rev 27728)
@@ -38,6 +38,7 @@
 #include "DNA_scene_types.h"
 
 #include "BLI_math.h"
+#include "BLI_ghash.h"
 
 #include "WM_types.h"
 
@@ -526,7 +527,7 @@
 {
 	PointerRNA rptr;
 	bPose *pose= (bPose*)ptr->data;
-	bPoseChannel *pchan= BLI_findstring(&pose->chanbase, key, offsetof(bPoseChannel, name));
+	bPoseChannel *pchan= get_pose_channel(pose, key);
 	RNA_pointer_create(ptr->id.data, &RNA_PoseBone, pchan, &rptr);
 	return rptr;
 }





More information about the Bf-blender-cvs mailing list