[Bf-blender-cvs] [98b81493f3] master: Refactor writefile handling of data-blocks.

Bastien Montagne noreply at git.blender.org
Fri Mar 17 10:05:47 CET 2017


Commit: 98b81493f3451f016fc409648bbe7c8c9e16940b
Author: Bastien Montagne
Date:   Fri Mar 17 10:02:08 2017 +0100
Branches: master
https://developer.blender.org/rB98b81493f3451f016fc409648bbe7c8c9e16940b

Refactor writefile handling of data-blocks.

Instead of calling a function looping over whole list of a given ID
type, make whole loop over Main in parent function, and call functions
writing a single datablock at a time.

This design is more in line with all other places in Blender where we
handle whole content of Main (including readfile.c), and much more easy
to extend and add e.g. some generic processing of IDs before/after
writing, etc.

>From user point, there should be no change at all, only difference is
that data-block types won't be saved in same order as before (.blend
file specs enforces no order here, so this is not an issue, but it could
bug some third party users using other, simplified .blend file reader maybe).

Reviewers: sergey, campbellbarton

Differential Revision: https://developer.blender.org/D2510

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

M	source/blender/blenloader/intern/writefile.c

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

diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 01d07e0d77..57be237be6 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -797,26 +797,22 @@ static void write_fcurves(WriteData *wd, ListBase *fcurves)
 	}
 }
 
-static void write_actions(WriteData *wd, ListBase *idbase)
+static void write_action(WriteData *wd, bAction *act)
 {
-	for (bAction *act = idbase->first; act; act = act->id.next) {
-		if (act->id.us > 0 || wd->current) {
-			writestruct(wd, ID_AC, bAction, 1, act);
-			write_iddata(wd, &act->id);
+	if (act->id.us > 0 || wd->current) {
+		writestruct(wd, ID_AC, bAction, 1, act);
+		write_iddata(wd, &act->id);
 
-			write_fcurves(wd, &act->curves);
+		write_fcurves(wd, &act->curves);
 
-			for (bActionGroup *grp = act->groups.first; grp; grp = grp->next) {
-				writestruct(wd, DATA, bActionGroup, 1, grp);
-			}
+		for (bActionGroup *grp = act->groups.first; grp; grp = grp->next) {
+			writestruct(wd, DATA, bActionGroup, 1, grp);
+		}
 
-			for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) {
-				writestruct(wd, DATA, TimeMarker, 1, marker);
-			}
+		for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) {
+			writestruct(wd, DATA, TimeMarker, 1, marker);
 		}
 	}
-
-	mywrite_flush(wd);
 }
 
 static void write_keyingsets(WriteData *wd, ListBase *list)
@@ -965,7 +961,7 @@ static void write_node_socket_interface(WriteData *wd, bNodeTree *UNUSED(ntree),
 	}
 }
 /* this is only direct data, tree itself should have been written */
-static void write_nodetree(WriteData *wd, bNodeTree *ntree)
+static void write_nodetree_nolib(WriteData *wd, bNodeTree *ntree)
 {
 	bNode *node;
 	bNodeSocket *sock;
@@ -1293,60 +1289,60 @@ static void write_pointcaches(WriteData *wd, ListBase *ptcaches)
 		}
 	}
 }
-static void write_particlesettings(WriteData *wd, ListBase *idbase)
+
+static void write_particlesettings(WriteData *wd, ParticleSettings *part)
 {
-	for (ParticleSettings *part = idbase->first; part; part = part->id.next) {
-		if (part->id.us > 0 || wd->current) {
-			/* write LibData */
-			writestruct(wd, ID_PA, ParticleSettings, 1, part);
-			write_iddata(wd, &part->id);
-
-			if (part->adt) {
-				write_animdata(wd, part->adt);
-			}
-			writestruct(wd, DATA, PartDeflect, 1, part->pd);
-			writestruct(wd, DATA, PartDeflect, 1, part->pd2);
-			writestruct(wd, DATA, EffectorWeights, 1, part->effector_weights);
+	if (part->id.us > 0 || wd->current) {
+		/* write LibData */
+		writestruct(wd, ID_PA, ParticleSettings, 1, part);
+		write_iddata(wd, &part->id);
 
-			if (part->clumpcurve) {
-				write_curvemapping(wd, part->clumpcurve);
-			}
-			if (part->roughcurve) {
-				write_curvemapping(wd, part->roughcurve);
-			}
+		if (part->adt) {
+			write_animdata(wd, part->adt);
+		}
+		writestruct(wd, DATA, PartDeflect, 1, part->pd);
+		writestruct(wd, DATA, PartDeflect, 1, part->pd2);
+		writestruct(wd, DATA, EffectorWeights, 1, part->effector_weights);
 
-			for (ParticleDupliWeight *dw = part->dupliweights.first; dw; dw = dw->next) {
-				/* update indices, but only if dw->ob is set (can be NULL after loading e.g.) */
-				if (dw->ob != NULL) {
-					dw->index = 0;
-					if (part->dup_group) { /* can be NULL if lining fails or set to None */
-						for (GroupObject *go = part->dup_group->gobject.first;
-						     go && go->ob != dw->ob;
-						     go = go->next, dw->index++);
-					}
+		if (part->clumpcurve) {
+			write_curvemapping(wd, part->clumpcurve);
+		}
+		if (part->roughcurve) {
+			write_curvemapping(wd, part->roughcurve);
+		}
+
+		for (ParticleDupliWeight *dw = part->dupliweights.first; dw; dw = dw->next) {
+			/* update indices, but only if dw->ob is set (can be NULL after loading e.g.) */
+			if (dw->ob != NULL) {
+				dw->index = 0;
+				if (part->dup_group) { /* can be NULL if lining fails or set to None */
+					for (GroupObject *go = part->dup_group->gobject.first;
+						 go && go->ob != dw->ob;
+						 go = go->next, dw->index++);
 				}
-				writestruct(wd, DATA, ParticleDupliWeight, 1, dw);
 			}
+			writestruct(wd, DATA, ParticleDupliWeight, 1, dw);
+		}
 
-			if (part->boids && part->phystype == PART_PHYS_BOIDS) {
-				writestruct(wd, DATA, BoidSettings, 1, part->boids);
+		if (part->boids && part->phystype == PART_PHYS_BOIDS) {
+			writestruct(wd, DATA, BoidSettings, 1, part->boids);
 
-				for (BoidState *state = part->boids->states.first; state; state = state->next) {
-					write_boid_state(wd, state);
-				}
-			}
-			if (part->fluid && part->phystype == PART_PHYS_FLUID) {
-				writestruct(wd, DATA, SPHFluidSettings, 1, part->fluid);
+			for (BoidState *state = part->boids->states.first; state; state = state->next) {
+				write_boid_state(wd, state);
 			}
+		}
+		if (part->fluid && part->phystype == PART_PHYS_FLUID) {
+			writestruct(wd, DATA, SPHFluidSettings, 1, part->fluid);
+		}
 
-			for (int a = 0; a < MAX_MTEX; a++) {
-				if (part->mtex[a]) {
-					writestruct(wd, DATA, MTex, 1, part->mtex[a]);
-				}
+		for (int a = 0; a < MAX_MTEX; a++) {
+			if (part->mtex[a]) {
+				writestruct(wd, DATA, MTex, 1, part->mtex[a]);
 			}
 		}
 	}
 }
+
 static void write_particlesystems(WriteData *wd, ListBase *particles)
 {
 	ParticleSystem *psys = particles->first;
@@ -1866,198 +1862,178 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
 	}
 }
 
-static void write_objects(WriteData *wd, ListBase *idbase)
+static void write_object(WriteData *wd, Object *ob)
 {
-	for (Object *ob = idbase->first; ob; ob = ob->id.next) {
-		if (ob->id.us > 0 || wd->current) {
-			/* write LibData */
-			writestruct(wd, ID_OB, Object, 1, ob);
-			write_iddata(wd, &ob->id);
-
-			if (ob->adt) {
-				write_animdata(wd, ob->adt);
-			}
-
-			/* direct data */
-			writedata(wd, DATA, sizeof(void *) * ob->totcol, ob->mat);
-			writedata(wd, DATA, sizeof(char) * ob->totcol, ob->matbits);
-			/* write_effects(wd, &ob->effect); */ /* not used anymore */
-			write_properties(wd, &ob->prop);
-			write_sensors(wd, &ob->sensors);
-			write_controllers(wd, &ob->controllers);
-			write_actuators(wd, &ob->actuators);
-
-			if (ob->type == OB_ARMATURE) {
-				bArmature *arm = ob->data;
-				if (arm && ob->pose && arm->act_bone) {
-					BLI_strncpy(ob->pose->proxy_act_bone, arm->act_bone->name, sizeof(ob->pose->proxy_act_bone));
-				}
-			}
+	if (ob->id.us > 0 || wd->current) {
+		/* write LibData */
+		writestruct(wd, ID_OB, Object, 1, ob);
+		write_iddata(wd, &ob->id);
 
-			write_pose(wd, ob->pose);
-			write_defgroups(wd, &ob->defbase);
-			write_constraints(wd, &ob->constraints);
-			write_motionpath(wd, ob->mpath);
+		if (ob->adt) {
+			write_animdata(wd, ob->adt);
+		}
 
-			writestruct(wd, DATA, PartDeflect, 1, ob->pd);
-			writestruct(wd, DATA, SoftBody, 1, ob->soft);
-			if (ob->soft) {
-				write_pointcaches(wd, &ob->soft->ptcaches);
-				writestruct(wd, DATA, EffectorWeights, 1, ob->soft->effector_weights);
-			}
-			writestruct(wd, DATA, BulletSoftBody, 1, ob->bsoft);
+		/* direct data */
+		writedata(wd, DATA, sizeof(void *) * ob->totcol, ob->mat);
+		writedata(wd, DATA, sizeof(char) * ob->totcol, ob->matbits);
+		/* write_effects(wd, &ob->effect); */ /* not used anymore */
+		write_properties(wd, &ob->prop);
+		write_sensors(wd, &ob->sensors);
+		write_controllers(wd, &ob->controllers);
+		write_actuators(wd, &ob->actuators);
 
-			if (ob->rigidbody_object) {
-				/* TODO: if any extra data is added to handle duplis, will need separate function then */
-				writestruct(wd, DATA, RigidBodyOb, 1, ob->rigidbody_object);
-			}
-			if (ob->rigidbody_constraint) {
-				writestruct(wd, DATA, RigidBodyCon, 1, ob->rigidbody_constraint);
+		if (ob->type == OB_ARMATURE) {
+			bArmature *arm = ob->data;
+			if (arm && ob->pose && arm->act_bone) {
+				BLI_strncpy(ob->pose->proxy_act_bone, arm->act_bone->name, sizeof(ob->pose->proxy_act_bone));
 			}
+		}
 
-			if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) {
-				writestruct(wd, DATA, ImageUser, 1, ob->iuser);
-			}
+		write_pose(wd, ob->pose);
+		write_defgroups(wd, &ob->defbase);
+		write_constraints(wd, &ob->constraints);
+		write_motionpath(wd, ob->mpath);
 
-			write_particlesystems(wd, &ob->particlesystem);
-			write_modifiers(wd, &ob->modifiers);
+		writestruct(wd, DATA, PartDeflect, 1, ob->pd);
+		writestruct(wd, DATA, SoftBody, 1, ob->soft);
+		if (ob->soft) {
+			write_pointcaches(wd, &ob->soft->ptcaches);
+			writestruct(wd, DATA, EffectorWeights, 1, ob->soft->effector_weights);
+		}
+		writestruct(wd, DATA, BulletSoftBody, 1, ob->bsoft);
 
-			writelist(wd, DATA, LinkData, &ob->pc_ids);
-			writelist(wd, DATA, LodLevel, &ob->lodlevels);
+		if (ob->rigidbody_object) {
+			/* TODO: if any extra data is added to handle duplis, will need separate function then */
+			writestruct(wd, DATA, RigidBodyOb, 1, ob->rigidbody_object);
+		}
+		if (ob->rigidbody_constraint) {
+			writestruct(wd, DATA, RigidBodyCon, 1, ob->rigidbody_constraint);
+		}
 
-			write_previews(wd, ob->preview);
+		if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) {
+			writestruct(wd, DATA, ImageUser, 1, ob->iuser);
 		}
-	}
 
-	mywrite_flush(wd);
+		write_particlesystems(wd, &ob->particlesystem);
+		write_modifiers(wd, &ob->modifiers);
+
+		writelist(wd, DATA, LinkData, &ob->pc_ids);
+		writelist(wd, DATA, LodLevel, &ob->lodlevels);
+
+		write_previews(wd, ob->preview);
+	}
 }
 
 
-static void write_vfonts(WriteData *wd, ListBase *idbase)
+static void write_vfont(WriteData *wd, VFont *vf)
 {
-	for (VFont *vf = idbase->first; vf; vf = vf->id.next) {
-		if (vf->id.us > 0 || wd->current) {
-			/* write LibData */
-			writestruct(wd, ID_VF, VFont, 1, vf);
-			write_iddata(wd, &vf->id);
+	if (vf->id.us > 0 || wd->current) {
+		/* write LibData */
+		writestruct(wd, ID_VF, VFont, 1, vf);
+		write_iddata(wd, &vf->id);
 
-			/* direct data */
-			if (vf->packedfile) {
-				PackedFile *pf = vf->packedfile;
-				writestruct(wd, DATA, PackedFile, 1, pf);
-				writedata(wd, DATA, pf->size, pf->data);
-			}
+		/* direct data */
+		if (vf->packedfile) {
+			PackedFile *pf = vf->packedfile;
+			writestruct(wd, DATA, PackedFile, 1, pf);
+	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list