[Bf-blender-cvs] [69bebcf8b56] hair_guides: Store section and vertex data in arrays instead of linked lists.

Lukas Tönne noreply at git.blender.org
Mon Dec 25 17:21:10 CET 2017


Commit: 69bebcf8b56be463e81424cb797387e3e96b651a
Author: Lukas Tönne
Date:   Mon Dec 25 16:20:44 2017 +0000
Branches: hair_guides
https://developer.blender.org/rB69bebcf8b56be463e81424cb797387e3e96b651a

Store section and vertex data in arrays instead of linked lists.

===================================================================

M	source/blender/blenkernel/intern/groom.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/draw/intern/draw_cache_impl_groom.c
M	source/blender/editors/groom/editgroom.c
M	source/blender/editors/groom/editgroom_region.c
M	source/blender/editors/groom/editgroom_select.c
M	source/blender/makesdna/DNA_groom_types.h

===================================================================

diff --git a/source/blender/blenkernel/intern/groom.c b/source/blender/blenkernel/intern/groom.c
index 3e07968c74b..709af5926af 100644
--- a/source/blender/blenkernel/intern/groom.c
+++ b/source/blender/blenkernel/intern/groom.c
@@ -75,14 +75,14 @@ static void groom_bundles_free(ListBase *bundles)
 {
 	for (GroomBundle *bundle = bundles->first; bundle; bundle = bundle->next)
 	{
-		for (GroomSection *section = bundle->sections.first; section; section = section->next)
+		if (bundle->sections)
 		{
-			if (section->verts)
-			{
-				MEM_freeN(section->verts);
-			}
+			MEM_freeN(bundle->sections);
+		}
+		if (bundle->verts)
+		{
+			MEM_freeN(bundle->verts);
 		}
-		BLI_freelistN(&bundle->sections);
 	}
 	BLI_freelistN(bundles);
 }
@@ -124,13 +124,13 @@ void BKE_groom_copy_data(Main *UNUSED(bmain), Groom *groom_dst, const Groom *gro
 	BLI_duplicatelist(&groom_dst->bundles, &groom_src->bundles);
 	for (GroomBundle *bundle = groom_dst->bundles.first; bundle; bundle = bundle->next)
 	{
-		BLI_duplicatelist(&bundle->sections, &bundle->sections);
-		for (GroomSection *section = bundle->sections.first; section; section = section->next)
+		if (bundle->sections)
+		{
+			bundle->sections = MEM_dupallocN(bundle->sections);
+		}
+		if (bundle->verts)
 		{
-			if (section->verts)
-			{
-				section->verts = MEM_dupallocN(section->verts);
-			}
+			bundle->verts = MEM_dupallocN(bundle->verts);
 		}
 	}
 	
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index c4955911472..564143c8093 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -8398,11 +8398,8 @@ static void direct_link_groom(FileData *fd, Groom *groom)
 	link_list(fd, &groom->bundles);
 	for (GroomBundle *bundle = groom->bundles.first; bundle; bundle = bundle->next)
 	{
-		link_list(fd, &bundle->sections);
-		for (GroomSection *section = bundle->sections.first; section; section = section->next)
-		{
-			section->verts = newdataadr(fd, section->verts);
-		}
+		bundle->sections = newdataadr(fd, bundle->sections);
+		bundle->verts = newdataadr(fd, bundle->verts);
 	}
 	
 	groom->bb = NULL;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 8ae92f2d92c..6fc2ec195fd 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3825,11 +3825,8 @@ static void write_groom(WriteData *wd, Groom *groom)
 	writelist(wd, DATA, GroomBundle, &groom->bundles);
 	for (GroomBundle *bundle = groom->bundles.first; bundle; bundle = bundle->next)
 	{
-		writelist(wd, DATA, GroomSection, &bundle->sections);
-		for (GroomSection *section = bundle->sections.first; section; section = section->next)
-		{
-			writestruct(wd, DATA, GroomSectionVertex, section->totverts, section->verts);
-		}
+		writestruct(wd, DATA, GroomSection, bundle->totsections, bundle->sections);
+		writestruct(wd, DATA, GroomSectionVertex, bundle->totverts, bundle->verts);
 	}
 }
 
diff --git a/source/blender/draw/intern/draw_cache_impl_groom.c b/source/blender/draw/intern/draw_cache_impl_groom.c
index eb6b82151db..ce62d61d1ed 100644
--- a/source/blender/draw/intern/draw_cache_impl_groom.c
+++ b/source/blender/draw/intern/draw_cache_impl_groom.c
@@ -206,18 +206,14 @@ static int groom_count_verts(Groom *groom, int parts, int tessellation)
 	{
 		for (GroomBundle *bundle = bundles->first; bundle; bundle = bundle->next)
 		{
-			int numsections = BLI_listbase_count(&bundle->sections);
-			vert_len += numsections;
+			vert_len += bundle->totsections;
 		}
 	}
 	if (parts & GM_RENDER_SECTIONS)
 	{
 		for (GroomBundle *bundle = bundles->first; bundle; bundle = bundle->next)
 		{
-			for (GroomSection *section = bundle->sections.first; section; section = section->next)
-			{
-				vert_len += section->totverts;
-			}
+			vert_len += bundle->totverts;
 		}
 	}
 	
@@ -239,19 +235,15 @@ static int groom_count_edges(Groom *groom, int parts, int tessellation)
 	{
 		for (GroomBundle *bundle = bundles->first; bundle; bundle = bundle->next)
 		{
-			int numsections = BLI_listbase_count(&bundle->sections);
-			edge_len += numsections - 1;
+			edge_len += bundle->totsections - 1;
 		}
 	}
 	if (parts & GM_RENDER_SECTIONS)
 	{
 		for (GroomBundle *bundle = bundles->first; bundle; bundle = bundle->next)
 		{
-			for (GroomSection *section = bundle->sections.first; section; section = section->next)
-			{
-				// Closed edge loop, 1 edge per vertex
-				edge_len += section->totverts;
-			}
+			// Closed edge loop, 1 edge per vertex
+			edge_len += bundle->totverts;
 		}
 	}
 	
@@ -283,7 +275,8 @@ static void groom_get_verts(
 		for (GroomBundle *bundle = bundles->first; bundle; bundle = bundle->next)
 		{
 			const bool active = bundle->flag & GM_BUNDLE_SELECT;
-			for (GroomSection *section = bundle->sections.first; section; section = section->next)
+			GroomSection *section = bundle->sections;
+			for (int i = 0; i < bundle->totsections; ++i, ++section)
 			{
 				if (id_pos != GM_ATTR_ID_UNUSED)
 				{
@@ -304,15 +297,16 @@ static void groom_get_verts(
 		uint idx = 0;
 		for (GroomBundle *bundle = bundles->first; bundle; bundle = bundle->next)
 		{
-			for (GroomSection *section = bundle->sections.first; section; section = section->next)
+			GroomSection *section = bundle->sections;
+			GroomSectionVertex *vertex = bundle->verts;
+			for (int i = 0; i < bundle->totsections; ++i, ++section)
 			{
 				const bool active = (bundle->flag & GM_BUNDLE_SELECT) && (section->flag & GM_SECTION_SELECT);
 				float mat[4][4];
 				unit_m4(mat); // TODO rotation
 				copy_v3_v3(mat[3], section->center); // translation
 				
-				GroomSectionVertex *vertex = section->verts;
-				for (int i = 0; i < section->totverts; ++i, ++vertex)
+				for (int j = 0; j < bundle->numloopverts; ++j, ++vertex)
 				{
 					if (id_pos != GM_ATTR_ID_UNUSED)
 					{
@@ -358,12 +352,10 @@ static void groom_get_edges(
 		uint idx = 0;
 		for (GroomBundle *bundle = bundles->first; bundle; bundle = bundle->next)
 		{
-			for (GroomSection *section = bundle->sections.first; section; section = section->next)
+			GroomSection *section = bundle->sections;
+			for (int i = 0; i < bundle->totsections - 1; ++i, ++section)
 			{
-				if (section->prev)
-				{
-					GWN_indexbuf_add_line_verts(&elb, idx-1, idx);
-				}
+				GWN_indexbuf_add_line_verts(&elb, idx, idx + 1);
 				
 				++idx;
 			}
@@ -374,20 +366,22 @@ static void groom_get_edges(
 		uint idx = 0;
 		for (GroomBundle *bundle = bundles->first; bundle; bundle = bundle->next)
 		{
-			for (GroomSection *section = bundle->sections.first; section; section = section->next)
+			if (bundle->numloopverts > 1)
 			{
-				if (section->totverts > 1)
+				GroomSection *section = bundle->sections;
+				for (int i = 0; i < bundle->totsections; ++i, ++section)
 				{
-					for (int i = 0; i < section->totverts - 1; ++i)
+					uint idx0 = idx + i * bundle->numloopverts;
+					for (int j = 0; j < bundle->numloopverts - 1; ++j)
 					{
-						GWN_indexbuf_add_line_verts(&elb, idx + i, idx + i + 1);
+						GWN_indexbuf_add_line_verts(&elb, idx0 + j, idx0 + j + 1);
 					}
 					// close the loop
-					GWN_indexbuf_add_line_verts(&elb, idx + section->totverts - 1, idx);
+					GWN_indexbuf_add_line_verts(&elb, idx0 + bundle->numloopverts - 1, idx0);
 				}
-				
-				idx += section->totverts;
 			}
+			
+			idx += bundle->totverts;
 		}
 	}
 	
diff --git a/source/blender/editors/groom/editgroom.c b/source/blender/editors/groom/editgroom.c
index dd4f27005be..9fd478e2857 100644
--- a/source/blender/editors/groom/editgroom.c
+++ b/source/blender/editors/groom/editgroom.c
@@ -72,14 +72,14 @@ static void groom_bundles_free(ListBase *bundles)
 {
 	for (GroomBundle *bundle = bundles->first; bundle; bundle = bundle->next)
 	{
-		for (GroomSection *section = bundle->sections.first; section; section = section->next)
+		if (bundle->verts)
 		{
-			if (section->verts)
-			{
-				MEM_freeN(section->verts);
-			}
+			MEM_freeN(bundle->verts);
+		}
+		if (bundle->sections)
+		{
+			MEM_freeN(bundle->sections);
 		}
-		BLI_freelistN(&bundle->sections);
 	}
 	BLI_freelistN(bundles);
 }
@@ -89,13 +89,13 @@ static void groom_bundles_copy(ListBase *bundles_dst, ListBase *bundles_src)
 	BLI_duplicatelist(bundles_dst, bundles_src);
 	for (GroomBundle *bundle = bundles_dst->first; bundle; bundle = bundle->next)
 	{
-		BLI_duplicatelist(&bundle->sections, &bundle->sections);
-		for (GroomSection *section = bundle->sections.first; section; section = section->next)
+		if (bundle->sections)
+		{
+			bundle->sections = MEM_dupallocN(bundle->sections);
+		}
+		if (bundle->verts)
 		{
-			if (section->verts)
-			{
-				section->verts = MEM_dupallocN(section->verts);
-			}
+			bundle->verts = MEM_dupallocN(bundle->verts);
 		}
 	}
 }
diff --git a/source/blender/editors/groom/editgroom_region.c b/source/blender/editors/groom/editgroom_region.c
index ed0dac06700..5ae9b7e8dcd 100644
--- a/source/blender/editors/groom/editgroom_region.c
+++ b/source/blender/editors/groom/editgroom_region.c
@@ -59,20 +59,14 @@
 
 #include "groom_intern.h"
 
-static GroomSection* groom_add_bundle_section(float mat[4][4], float cparam)
+static void groom_bundle_section_init(GroomSection *section, GroomSectionVertex *verts, int numverts, float mat[4][4], float cparam)
 {
-	GroomSection *section = MEM_callocN(sizeof(GroomSection), "groom bundle section");
-	
 	madd_v3_v3v3fl(section->center, mat[3], mat[2], cparam);
 	copy_v3_v3(section->normal, mat[2]);
 	
 	{
-		const int numverts = 6;
-		section->totverts = numverts;
-		section->verts = MEM_mallocN(sizeof(GroomSectionVertex) * numverts, "groom section vertices");
-		
 		const float radius = 0.5f;
-		GroomSectionVertex *vertex = section->verts;
+		GroomSectionVertex *vertex = verts;
 		for (int i = 0; i < numverts; ++i, ++vertex)
 		{
 			float angle = 2*M_PI * (float)i / (float)numverts;
@@ -80,16 +74,21 @@ static GroomSection* groom_add_bundle_section(float mat[4][4], float cparam)
 			vertex->co[1] = sin(angle) * radius;
 		}
 	}
-	
-	return section;
 }
 
 static GroomBundle* groom_add_bundle(float mat[4][4])
 {
 	GroomBundle *bundle = MEM_callocN(sizeof(Gr

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list