[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53351] trunk/blender/source/blender: remove unneeded inline lookups and fix error with wpaint_stroke_test_start returning OPERATOR_PASS_THROUGH rather then a boolean .

Campbell Barton ideasman42 at gmail.com
Fri Dec 28 02:36:02 CET 2012


Revision: 53351
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53351
Author:   campbellbarton
Date:     2012-12-28 01:36:00 +0000 (Fri, 28 Dec 2012)
Log Message:
-----------
remove unneeded inline lookups and fix error with wpaint_stroke_test_start returning OPERATOR_PASS_THROUGH rather then a boolean.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/deform.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c

Modified: trunk/blender/source/blender/blenkernel/intern/deform.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/deform.c	2012-12-28 00:54:22 UTC (rev 53350)
+++ trunk/blender/source/blender/blenkernel/intern/deform.c	2012-12-28 01:36:00 UTC (rev 53351)
@@ -34,6 +34,7 @@
 #include <math.h>
 #include <ctype.h>
 #include <stdlib.h>
+#include <stddef.h>
 
 #include "MEM_guardedalloc.h"
 
@@ -337,37 +338,12 @@
 
 bDeformGroup *defgroup_find_name(Object *ob, const char *name)
 {
-	/* return a pointer to the deform group with this name
-	 * or return NULL otherwise.
-	 */
-	bDeformGroup *curdef;
-
-	for (curdef = ob->defbase.first; curdef; curdef = curdef->next) {
-		if (!strcmp(curdef->name, name)) {
-			return curdef;
-		}
-	}
-	return NULL;
+	return BLI_findstring(&ob->defbase, name, offsetof(bDeformGroup, name));
 }
 
 int defgroup_name_index(Object *ob, const char *name)
 {
-	/* Return the location of the named deform group within the list of
-	 * deform groups. This function is a combination of BLI_findlink and
-	 * defgroup_find_name. The other two could be called instead, but that
-	 * require looping over the vertexgroups twice.
-	 */
-	bDeformGroup *curdef;
-	int def_nr;
-
-	if (name && name[0] != '\0') {
-		for (curdef = ob->defbase.first, def_nr = 0; curdef; curdef = curdef->next, def_nr++) {
-			if (!strcmp(curdef->name, name))
-				return def_nr;
-		}
-	}
-
-	return -1;
+	return BLI_findstringindex(&ob->defbase, name, offsetof(bDeformGroup, name));
 }
 
 /* note, must be freed */

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c	2012-12-28 00:54:22 UTC (rev 53350)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c	2012-12-28 01:36:00 UTC (rev 53351)
@@ -416,6 +416,7 @@
 	if (!stroke->stroke_started) {
 		copy_v2_v2(stroke->last_mouse_position, sample_average.mouse);
 		stroke->stroke_started = stroke->test_start(C, op, sample_average.mouse);
+		BLI_assert((stroke->stroke_started & ~1) == 0);  /* 0/1 */
 
 		if (stroke->stroke_started) {
 			stroke->smooth_stroke_cursor =

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c	2012-12-28 00:54:22 UTC (rev 53350)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c	2012-12-28 01:36:00 UTC (rev 53351)
@@ -372,31 +372,22 @@
 	bDeformGroup *defgroup = BLI_findlink(&ob->defbase, vgroup_active);
 
 	if (defgroup) {
-		bDeformGroup *curdef;
 		int mirrdef;
 		char name[MAXBONENAME];
 
 		flip_side_name(name, defgroup->name, FALSE);
-
-		if (strcmp(name, defgroup->name) != 0) {
-			for (curdef = ob->defbase.first, mirrdef = 0; curdef; curdef = curdef->next, mirrdef++) {
-				if (!strcmp(curdef->name, name)) {
-					break;
-				}
+		mirrdef = defgroup_name_index(ob, name);
+		if (mirrdef == -1) {
+			int olddef = ob->actdef;  /* tsk, ED_vgroup_add sets the active defgroup */
+			if (ED_vgroup_add_name(ob, name)) {
+				mirrdef = BLI_countlist(&ob->defbase) - 1;
 			}
+			ob->actdef = olddef;
+		}
 
-			if (curdef == NULL) {
-				int olddef = ob->actdef;  /* tsk, ED_vgroup_add sets the active defgroup */
-				curdef = ED_vgroup_add_name(ob, name);
-				ob->actdef = olddef;
-			}
-
-			/* curdef should never be NULL unless this is
-			 * a  lamp and ED_vgroup_add_name fails */
-			if (curdef) {
-				return mirrdef;
-			}
-		}
+		/* curdef should never be NULL unless this is
+		 * a  lamp and ED_vgroup_add_name fails */
+		return mirrdef;
 	}
 
 	return -1;
@@ -2061,32 +2052,29 @@
 	int vgroup_mirror;
 	DMCoNo *vertexcosnos;
 	float wpimat[3][3];
-	
+
 	/* variables for auto normalize */
 	const char *vgroup_validmap; /* stores if vgroups tie to deforming bones or not */
 	const char *lock_flags;
 	int defbase_tot;
 };
 
-static int wpaint_stroke_test_start(bContext *C, wmOperator *op, const float UNUSED(mouse[2]))
+/* ensure we have data on wpaint start, add if needed */
+static int wpaint_ensure_data(bContext *C, wmOperator *op)
 {
 	Scene *scene = CTX_data_scene(C);
-	struct PaintStroke *stroke = op->customdata;
-	ToolSettings *ts = scene->toolsettings;
-	VPaint *wp = ts->wpaint;
 	Object *ob = CTX_data_active_object(C);
-	struct WPaintData *wpd;
-	Mesh *me;
+	Mesh *me = BKE_mesh_from_object(ob);
 
-	float mat[4][4], imat[4][4];
-	
 	if (scene->obedit) {
 		return FALSE;
 	}
-	
+
 	me = BKE_mesh_from_object(ob);
-	if (me == NULL || me->totpoly == 0) return OPERATOR_PASS_THROUGH;
-	
+	if (me == NULL || me->totpoly == 0) {
+		return FALSE;
+	}
+
 	/* if nothing was added yet, we make dverts and a vertex deform group */
 	if (!me->dvert) {
 		ED_vgroup_data_create(&me->id);
@@ -2125,6 +2113,25 @@
 		return FALSE;
 	}
 
+	return TRUE;
+}
+
+static int wpaint_stroke_test_start(bContext *C, wmOperator *op, const float UNUSED(mouse[2]))
+{
+	Scene *scene = CTX_data_scene(C);
+	struct PaintStroke *stroke = op->customdata;
+	ToolSettings *ts = scene->toolsettings;
+	VPaint *wp = ts->wpaint;
+	Object *ob = CTX_data_active_object(C);
+	Mesh *me = BKE_mesh_from_object(ob);
+	struct WPaintData *wpd;
+
+	float mat[4][4], imat[4][4];
+
+	if (wpaint_ensure_data(C, op) == FALSE) {
+		return FALSE;
+	}
+
 	{
 		/* check if we are attempting to paint onto a locked vertex group,
 		 * and other options disallow it from doing anything useful */
@@ -3208,7 +3215,9 @@
 
 static int paint_weight_gradient_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
-	int ret = WM_gesture_straightline_invoke(C, op, event);
+	int ret;
+
+	ret = WM_gesture_straightline_invoke(C, op, event);
 	if (ret & OPERATOR_RUNNING_MODAL) {
 		struct ARegion *ar = CTX_wm_region(C);
 		if (ar->regiontype == RGN_TYPE_WINDOW) {




More information about the Bf-blender-cvs mailing list