diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-11-17 17:11:55 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-11-17 17:11:55 +0300 |
commit | 0a08d8c892d595eab9aaec46739ef697bcee5cef (patch) | |
tree | c3a3ac92aa717a035bd9dfbd1ac3f0075d372d66 /source/blender/depsgraph | |
parent | 0c322c3000a0ddd7ac58c650f30b29d55afd1a97 (diff) |
Depsgraph: Use utility macro to iterate over linked list
This will be compiled into same exact code, just saves us from
doing annoying type casts all over the place.
Diffstat (limited to 'source/blender/depsgraph')
5 files changed, 65 insertions, 85 deletions
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc index 1eaacea69eb..89b9fc98e33 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc @@ -105,6 +105,7 @@ extern "C" { #include "intern/nodes/deg_node_operation.h" #include "intern/depsgraph_types.h" #include "intern/depsgraph_intern.h" +#include "util/deg_util_foreach.h" namespace DEG { @@ -347,7 +348,7 @@ void DepsgraphNodeBuilder::build_scene(Main *bmain, Scene *scene) } /* scene objects */ - for (Base *base = (Base *)scene->base.first; base; base = base->next) { + LINKLIST_FOREACH (Base *, base, &scene->base) { Object *ob = base->object; /* object itself */ @@ -395,10 +396,7 @@ void DepsgraphNodeBuilder::build_scene(Main *bmain, Scene *scene) } /* cache files */ - for (CacheFile *cachefile = static_cast<CacheFile *>(bmain->cachefiles.first); - cachefile; - cachefile = static_cast<CacheFile *>(cachefile->id.next)) - { + LINKLIST_FOREACH (CacheFile *, cachefile, &bmain->cachefiles) { build_cachefile(cachefile); } } @@ -413,10 +411,7 @@ void DepsgraphNodeBuilder::build_group(Scene *scene, } group_id->tag |= LIB_TAG_DOIT; - for (GroupObject *go = (GroupObject *)group->gobject.first; - go != NULL; - go = go->next) - { + LINKLIST_FOREACH (GroupObject *, go, &group->gobject) { build_object(scene, base, go->ob); } } @@ -433,10 +428,7 @@ SubgraphDepsNode *DepsgraphNodeBuilder::build_subgraph(Group *group) DepsgraphNodeBuilder subgraph_builder(m_bmain, subgraph); /* add group objects */ - for (GroupObject *go = (GroupObject *)group->gobject.first; - go != NULL; - go = go->next) - { + LINKLIST_FOREACH (GroupObject *, go, &group->gobject) { /*Object *ob = go->ob;*/ /* Each "group object" is effectively a separate instance of the @@ -653,7 +645,7 @@ void DepsgraphNodeBuilder::build_animdata(ID *id) } /* drivers */ - for (FCurve *fcu = (FCurve *)adt->drivers.first; fcu; fcu = fcu->next) { + LINKLIST_FOREACH (FCurve *, fcu, &adt->drivers) { /* create driver */ build_driver(id, fcu); } @@ -766,7 +758,7 @@ void DepsgraphNodeBuilder::build_rigidbody(Scene *scene) /* objects - simulation participants */ if (rbw->group) { - for (GroupObject *go = (GroupObject *)rbw->group->gobject.first; go; go = go->next) { + LINKLIST_FOREACH (GroupObject *, go, &rbw->group->gobject) { Object *ob = go->ob; if (!ob || (ob->type != OB_MESH)) @@ -802,7 +794,7 @@ void DepsgraphNodeBuilder::build_particles(Scene *scene, Object *ob) ComponentDepsNode *psys_comp = add_component_node(&ob->id, DEPSNODE_TYPE_EVAL_PARTICLES); /* particle systems */ - for (ParticleSystem *psys = (ParticleSystem *)ob->particlesystem.first; psys; psys = psys->next) { + LINKLIST_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { ParticleSettings *part = psys->part; /* particle settings */ @@ -812,7 +804,11 @@ void DepsgraphNodeBuilder::build_particles(Scene *scene, Object *ob) /* this particle system */ // TODO: for now, this will just be a placeholder "ubereval" node add_operation_node(psys_comp, - DEPSOP_TYPE_EXEC, function_bind(BKE_particle_system_eval, _1, scene, ob, psys), + DEPSOP_TYPE_EXEC, function_bind(BKE_particle_system_eval, + _1, + scene, + ob, + psys), DEG_OPCODE_PSYS_EVAL, psys->name); } @@ -871,33 +867,26 @@ void DepsgraphNodeBuilder::build_obdata_geom(Scene *scene, Object *ob) // TODO: "Done" operation /* Modifiers */ - if (ob->modifiers.first) { - for (ModifierData *md = (ModifierData *)ob->modifiers.first; - md != NULL; - md = md->next) - { - add_operation_node(&ob->id, - DEPSNODE_TYPE_GEOMETRY, - DEPSOP_TYPE_EXEC, - function_bind(BKE_object_eval_modifier, - _1, - scene, - ob, - md), - DEG_OPCODE_GEOMETRY_MODIFIER, - md->name); - } + LINKLIST_FOREACH (ModifierData *, md, &ob->modifiers) { + add_operation_node(&ob->id, + DEPSNODE_TYPE_GEOMETRY, + DEPSOP_TYPE_EXEC, + function_bind(BKE_object_eval_modifier, + _1, + scene, + ob, + md), + DEG_OPCODE_GEOMETRY_MODIFIER, + md->name); } /* materials */ - if (ob->totcol) { - for (int a = 1; a <= ob->totcol; a++) { - Material *ma = give_current_material(ob, a); - if (ma != NULL) { - // XXX?! - ComponentDepsNode *geom_node = add_component_node(&ob->id, DEPSNODE_TYPE_GEOMETRY); - build_material(geom_node, ma); - } + for (int a = 1; a <= ob->totcol; a++) { + Material *ma = give_current_material(ob, a); + if (ma != NULL) { + // XXX?! + ComponentDepsNode *geom_node = add_component_node(&ob->id, DEPSNODE_TYPE_GEOMETRY); + build_material(geom_node, ma); } } @@ -1091,7 +1080,7 @@ void DepsgraphNodeBuilder::build_nodetree(DepsNode *owner_node, bNodeTree *ntree DEG_OPCODE_PLACEHOLDER, "Parameters Eval"); /* nodetree's nodes... */ - for (bNode *bnode = (bNode *)ntree->nodes.first; bnode; bnode = bnode->next) { + LINKLIST_FOREACH (bNode *, bnode, &ntree->nodes) { ID *id = bnode->id; if (id != NULL) { short id_type = GS(id->name); diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc index b9c7c3c7f92..8ba41a4b4b1 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc @@ -60,6 +60,7 @@ extern "C" { #include "intern/nodes/deg_node_operation.h" #include "intern/depsgraph_types.h" #include "intern/depsgraph_intern.h" +#include "util/deg_util_foreach.h" namespace DEG { @@ -178,7 +179,7 @@ void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *ob) DEPSOP_TYPE_POST, function_bind(BKE_pose_eval_flush, _1, scene, ob, ob->pose), DEG_OPCODE_POSE_DONE); /* bones */ - for (bPoseChannel *pchan = (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan = pchan->next) { + LINKLIST_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { /* node for bone eval */ add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEPSOP_TYPE_INIT, NULL, // XXX: BKE_pose_eval_bone_local @@ -212,7 +213,7 @@ void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *ob) * - Care is needed to ensure that multi-headed trees work out the same as in ik-tree building * - Animated chain-lengths are a problem... */ - for (bConstraint *con = (bConstraint *)pchan->constraints.first; con; con = con->next) { + LINKLIST_FOREACH (bConstraint *, con, &pchan->constraints) { switch (con->type) { case CONSTRAINT_TYPE_KINEMATIC: build_ik_pose(scene, ob, pchan, con); @@ -248,10 +249,7 @@ void DepsgraphNodeBuilder::build_proxy_rig(Object *ob) function_bind(BKE_pose_eval_proxy_copy, _1, ob), DEG_OPCODE_POSE_INIT); - for (bPoseChannel *pchan = (bPoseChannel *)ob->pose->chanbase.first; - pchan != NULL; - pchan = pchan->next) - { + LINKLIST_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEPSOP_TYPE_INIT, NULL, DEG_OPCODE_BONE_LOCAL); diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index 1497a16e47f..d8477358dad 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -356,7 +356,7 @@ void DepsgraphRelationBuilder::build_scene(Main *bmain, Scene *scene) } /* scene objects */ - for (Base *base = (Base *)scene->base.first; base; base = base->next) { + LINKLIST_FOREACH (Base *, base, &scene->base) { Object *ob = base->object; /* object itself */ @@ -429,10 +429,7 @@ void DepsgraphRelationBuilder::build_group(Main *bmain, OperationKey object_local_transform_key(&object->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_LOCAL); - for (GroupObject *go = (GroupObject *)group->gobject.first; - go != NULL; - go = go->next) - { + LINKLIST_FOREACH (GroupObject *, go, &group->gobject) { if (!group_done) { build_object(bmain, scene, go->ob); } @@ -709,9 +706,10 @@ void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode ListBase targets = {NULL, NULL}; cti->get_constraint_targets(con, &targets); - for (bConstraintTarget *ct = (bConstraintTarget *)targets.first; ct; ct = ct->next) { - if (!ct->tar) + LINKLIST_FOREACH (bConstraintTarget *, ct, &targets) { + if (ct->tar == NULL) { continue; + } if (ELEM(con->type, CONSTRAINT_TYPE_KINEMATIC, CONSTRAINT_TYPE_SPLINEIK)) { /* ignore IK constraints - these are handled separately (on pose level) */ @@ -838,7 +836,7 @@ void DepsgraphRelationBuilder::build_animdata(ID *id) } /* drivers */ - for (FCurve *fcu = (FCurve *)adt->drivers.first; fcu; fcu = fcu->next) { + LINKLIST_FOREACH (FCurve *, fcu, &adt->drivers) { OperationKey driver_key(id, DEPSNODE_TYPE_PARAMETERS, DEG_OPCODE_DRIVER, @@ -862,10 +860,7 @@ void DepsgraphRelationBuilder::build_animdata(ID *id) */ if (fcu->array_index > 0) { FCurve *fcu_prev = NULL; - for (FCurve *fcu_candidate = (FCurve *)adt->drivers.first; - fcu_candidate != NULL; - fcu_candidate = fcu_candidate->next) - { + LINKLIST_FOREACH (FCurve *, fcu_candidate, &adt->drivers) { /* Writing to different RNA paths is */ if (!STREQ(fcu_candidate->rna_path, fcu->rna_path)) { continue; @@ -1029,7 +1024,7 @@ void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu) // XXX: the data itself could also set this, if it were to be truly initialised later? /* loop over variables to get the target relationships */ - for (DriverVar *dvar = (DriverVar *)driver->variables.first; dvar; dvar = dvar->next) { + LINKLIST_FOREACH (DriverVar *, dvar, &driver->variables) { /* only used targets */ DRIVER_TARGETS_USED_LOOPER(dvar) { @@ -1149,10 +1144,11 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene *scene) /* objects - simulation participants */ if (rbw->group) { - for (GroupObject *go = (GroupObject *)rbw->group->gobject.first; go; go = go->next) { + LINKLIST_FOREACH (GroupObject *, go, &rbw->group->gobject) { Object *ob = go->ob; - if (!ob || ob->type != OB_MESH) + if (ob == NULL || ob->type != OB_MESH) { continue; + } /* hook up evaluation order... * 1) flushing rigidbody results follows base transforms being applied @@ -1200,10 +1196,11 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene *scene) /* constraints */ if (rbw->constraints) { - for (GroupObject *go = (GroupObject *)rbw->constraints->gobject.first; go; go = go->next) { + LINKLIST_FOREACH (GroupObject *, go, &rbw->constraints->gobject) { Object *ob = go->ob; - if (!ob || !ob->rigidbody_constraint) + if (ob == NULL || !ob->rigidbody_constraint) { continue; + } RigidBodyCon *rbc = ob->rigidbody_constraint; @@ -1232,7 +1229,7 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob) DEG_OPCODE_GEOMETRY_UBEREVAL); /* particle systems */ - for (ParticleSystem *psys = (ParticleSystem *)ob->particlesystem.first; psys; psys = psys->next) { + LINKLIST_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { ParticleSettings *part = psys->part; /* particle settings */ @@ -1263,9 +1260,7 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob) #if 0 if (ELEM(part->phystype, PART_PHYS_KEYED, PART_PHYS_BOIDS)) { - ParticleTarget *pt; - - for (pt = psys->targets.first; pt; pt = pt->next) { + LINKLIST_FOREACH (ParticleTarget *, pt, &psys->targets) { if (pt->ob && BLI_findlink(&pt->ob->particlesystem, pt->psys - 1)) { node2 = dag_get_node(dag, pt->ob); dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Particle Targets"); @@ -1284,7 +1279,7 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob) } if (part->ren_as == PART_DRAW_GR && part->dup_group) { - for (go = part->dup_group->gobject.first; go; go = go->next) { + LINKLIST_FOREACH (GroupObject *, go, &part->dup_group->gobject) { node2 = dag_get_node(dag, go->ob); dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Particle Group Visualization"); } @@ -1301,11 +1296,8 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob) /* boids */ if (part->boids) { - BoidRule *rule = NULL; - BoidState *state = NULL; - - for (state = (BoidState *)part->boids->states.first; state; state = state->next) { - for (rule = (BoidRule *)state->rules.first; rule; rule = rule->next) { + LINKLIST_FOREACH (BoidState *, state, &part->boids->states) { + LINKLIST_FOREACH (BoidRule *, rule, &state->rules) { Object *ruleob = NULL; if (rule->type == eBoidRuleType_Avoid) ruleob = ((BoidRuleGoalAvoid *)rule)->ob; @@ -1405,10 +1397,9 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje /* Modifiers */ if (ob->modifiers.first) { - ModifierData *md; OperationKey prev_mod_key; - for (md = (ModifierData *)ob->modifiers.first; md; md = md->next) { + LINKLIST_FOREACH (ModifierData *, md, &ob->modifiers) { const ModifierTypeInfo *mti = modifierType_getInfo((ModifierType)md->type); OperationKey mod_key(&ob->id, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_MODIFIER, md->name); @@ -1643,7 +1634,7 @@ void DepsgraphRelationBuilder::build_nodetree(ID *owner, bNodeTree *ntree) "Parameters Eval"); /* nodetree's nodes... */ - for (bNode *bnode = (bNode *)ntree->nodes.first; bnode; bnode = bnode->next) { + LINKLIST_FOREACH (bNode *, bnode, &ntree->nodes) { if (bnode->id) { if (GS(bnode->id->name) == ID_MA) { build_material(owner, (Material *)bnode->id); diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc index 3edb2b7acb7..0fa7a5b1830 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc @@ -335,8 +335,8 @@ void DepsgraphRelationBuilder::build_rig(Scene *scene, Object *ob) */ RootPChanMap root_map; bool pose_depends_on_local_transform = false; - for (bPoseChannel *pchan = (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan = pchan->next) { - for (bConstraint *con = (bConstraint *)pchan->constraints.first; con; con = con->next) { + LINKLIST_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { + LINKLIST_FOREACH (bConstraint *, con, &pchan->constraints) { switch (con->type) { case CONSTRAINT_TYPE_KINEMATIC: build_ik_pose(ob, pchan, con, &root_map); @@ -377,7 +377,7 @@ void DepsgraphRelationBuilder::build_rig(Scene *scene, Object *ob) /* links between operations for each bone */ - for (bPoseChannel *pchan = (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan = pchan->next) { + LINKLIST_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { OperationKey bone_local_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_LOCAL); OperationKey bone_pose_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_POSE_PARENT); OperationKey bone_ready_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_READY); @@ -441,10 +441,7 @@ void DepsgraphRelationBuilder::build_proxy_rig(Object *ob) { OperationKey pose_init_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT); OperationKey pose_done_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE); - for (bPoseChannel *pchan = (bPoseChannel *)ob->pose->chanbase.first; - pchan != NULL; - pchan = pchan->next) - { + LINKLIST_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { OperationKey bone_local_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_LOCAL); OperationKey bone_ready_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_READY); OperationKey bone_done_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_DONE); diff --git a/source/blender/depsgraph/util/deg_util_foreach.h b/source/blender/depsgraph/util/deg_util_foreach.h index 14cf4fc11ed..87d37168d51 100644 --- a/source/blender/depsgraph/util/deg_util_foreach.h +++ b/source/blender/depsgraph/util/deg_util_foreach.h @@ -66,3 +66,8 @@ #define GSET_FOREACH_END() \ } \ } while(0) + +#define LINKLIST_FOREACH(type, var, list) \ + for (type var = (type)((list)->first); \ + var != NULL; \ + var = (type)(((Link*)(var))->next)) |