diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/depsgraph/intern/depsgraph_physics.cc | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.
For details on usage and instructions for migrating branches
without conflicts, see:
https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/depsgraph/intern/depsgraph_physics.cc')
-rw-r--r-- | source/blender/depsgraph/intern/depsgraph_physics.cc | 292 |
1 files changed, 127 insertions, 165 deletions
diff --git a/source/blender/depsgraph/intern/depsgraph_physics.cc b/source/blender/depsgraph/intern/depsgraph_physics.cc index 02265ba0e7a..3f81e49b170 100644 --- a/source/blender/depsgraph/intern/depsgraph_physics.cc +++ b/source/blender/depsgraph/intern/depsgraph_physics.cc @@ -49,51 +49,44 @@ extern "C" { /*************************** Evaluation Query API *****************************/ -static ePhysicsRelationType modifier_to_relation_type( - unsigned int modifier_type) +static ePhysicsRelationType modifier_to_relation_type(unsigned int modifier_type) { - switch (modifier_type) { - case eModifierType_Collision: - return DEG_PHYSICS_COLLISION; - case eModifierType_Smoke: - return DEG_PHYSICS_SMOKE_COLLISION; - case eModifierType_DynamicPaint: - return DEG_PHYSICS_DYNAMIC_BRUSH; - } - - BLI_assert(!"Unknown collision modifier type"); - return DEG_PHYSICS_RELATIONS_NUM; + switch (modifier_type) { + case eModifierType_Collision: + return DEG_PHYSICS_COLLISION; + case eModifierType_Smoke: + return DEG_PHYSICS_SMOKE_COLLISION; + case eModifierType_DynamicPaint: + return DEG_PHYSICS_DYNAMIC_BRUSH; + } + + BLI_assert(!"Unknown collision modifier type"); + return DEG_PHYSICS_RELATIONS_NUM; } -ListBase *DEG_get_effector_relations(const Depsgraph *graph, - Collection *collection) +ListBase *DEG_get_effector_relations(const Depsgraph *graph, Collection *collection) { - const DEG::Depsgraph *deg_graph = - reinterpret_cast<const DEG::Depsgraph *>(graph); - if (deg_graph->physics_relations[DEG_PHYSICS_EFFECTOR] == NULL) { - return NULL; - } - - ID *collection_orig = DEG_get_original_id(&collection->id); - return (ListBase *)BLI_ghash_lookup( - deg_graph->physics_relations[DEG_PHYSICS_EFFECTOR], - collection_orig); + const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph); + if (deg_graph->physics_relations[DEG_PHYSICS_EFFECTOR] == NULL) { + return NULL; + } + + ID *collection_orig = DEG_get_original_id(&collection->id); + return (ListBase *)BLI_ghash_lookup(deg_graph->physics_relations[DEG_PHYSICS_EFFECTOR], + collection_orig); } ListBase *DEG_get_collision_relations(const Depsgraph *graph, Collection *collection, unsigned int modifier_type) { - const DEG::Depsgraph *deg_graph = - reinterpret_cast<const DEG::Depsgraph *>(graph); - const ePhysicsRelationType type = modifier_to_relation_type(modifier_type); - if (deg_graph->physics_relations[type] == NULL) { - return NULL; - } - ID *collection_orig = DEG_get_original_id(&collection->id); - return (ListBase *)BLI_ghash_lookup( - deg_graph->physics_relations[type], - collection_orig); + const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph); + const ePhysicsRelationType type = modifier_to_relation_type(modifier_type); + if (deg_graph->physics_relations[type] == NULL) { + return NULL; + } + ID *collection_orig = DEG_get_original_id(&collection->id); + return (ListBase *)BLI_ghash_lookup(deg_graph->physics_relations[type], collection_orig); } /********************** Depsgraph Building API ************************/ @@ -105,26 +98,20 @@ void DEG_add_collision_relations(DepsNodeHandle *handle, DEG_CollobjFilterFunction filter_function, const char *name) { - Depsgraph *depsgraph = DEG_get_graph_from_handle(handle); - DEG::Depsgraph *deg_graph = (DEG::Depsgraph *)depsgraph; - ListBase *relations = build_collision_relations( - deg_graph, collection, modifier_type); - LISTBASE_FOREACH (CollisionRelation *, relation, relations) { - Object *ob1 = relation->ob; - if (ob1 == object) { - continue; - } - if (filter_function == NULL || - filter_function( - ob1, - modifiers_findByType(ob1, (ModifierType)modifier_type))) - { - DEG_add_object_pointcache_relation( - handle, ob1, DEG_OB_COMP_TRANSFORM, name); - DEG_add_object_pointcache_relation( - handle, ob1, DEG_OB_COMP_GEOMETRY, name); - } - } + Depsgraph *depsgraph = DEG_get_graph_from_handle(handle); + DEG::Depsgraph *deg_graph = (DEG::Depsgraph *)depsgraph; + ListBase *relations = build_collision_relations(deg_graph, collection, modifier_type); + LISTBASE_FOREACH (CollisionRelation *, relation, relations) { + Object *ob1 = relation->ob; + if (ob1 == object) { + continue; + } + if (filter_function == NULL || + filter_function(ob1, modifiers_findByType(ob1, (ModifierType)modifier_type))) { + DEG_add_object_pointcache_relation(handle, ob1, DEG_OB_COMP_TRANSFORM, name); + DEG_add_object_pointcache_relation(handle, ob1, DEG_OB_COMP_GEOMETRY, name); + } + } } void DEG_add_forcefield_relations(DepsNodeHandle *handle, @@ -134,144 +121,119 @@ void DEG_add_forcefield_relations(DepsNodeHandle *handle, int skip_forcefield, const char *name) { - Depsgraph *depsgraph = DEG_get_graph_from_handle(handle); - DEG::Depsgraph *deg_graph = (DEG::Depsgraph *)depsgraph; - ListBase *relations = - build_effector_relations(deg_graph, effector_weights->group); - LISTBASE_FOREACH (EffectorRelation *, relation, relations) { - if (relation->ob == object) { - continue; - } - if (relation->pd->forcefield == skip_forcefield) { - continue; - } - - /* Relation to forcefield object, optionally including geometry. - * Use special point cache relations for automatic cache clearing. */ - DEG_add_object_pointcache_relation( - handle, relation->ob, DEG_OB_COMP_TRANSFORM, name); - - if (relation->psys || - ELEM(relation->pd->shape, PFIELD_SHAPE_SURFACE, PFIELD_SHAPE_POINTS) || - relation->pd->forcefield == PFIELD_GUIDE) - { - /* TODO(sergey): Consider going more granular with more dedicated - * particle system operation. */ - DEG_add_object_pointcache_relation( - handle, relation->ob, DEG_OB_COMP_GEOMETRY, name); - } - - /* Smoke flow relations. */ - if (relation->pd->forcefield == PFIELD_SMOKEFLOW && - relation->pd->f_source != NULL) - { - DEG_add_object_pointcache_relation(handle, - relation->pd->f_source, - DEG_OB_COMP_TRANSFORM, - "Smoke Force Domain"); - DEG_add_object_pointcache_relation(handle, - relation->pd->f_source, - DEG_OB_COMP_GEOMETRY, - "Smoke Force Domain"); - } - - /* Absorption forces need collision relation. */ - if (add_absorption && (relation->pd->flag & PFIELD_VISIBILITY)) { - DEG_add_collision_relations(handle, - object, - NULL, - eModifierType_Collision, - NULL, - "Force Absorption"); - } - } + Depsgraph *depsgraph = DEG_get_graph_from_handle(handle); + DEG::Depsgraph *deg_graph = (DEG::Depsgraph *)depsgraph; + ListBase *relations = build_effector_relations(deg_graph, effector_weights->group); + LISTBASE_FOREACH (EffectorRelation *, relation, relations) { + if (relation->ob == object) { + continue; + } + if (relation->pd->forcefield == skip_forcefield) { + continue; + } + + /* Relation to forcefield object, optionally including geometry. + * Use special point cache relations for automatic cache clearing. */ + DEG_add_object_pointcache_relation(handle, relation->ob, DEG_OB_COMP_TRANSFORM, name); + + if (relation->psys || ELEM(relation->pd->shape, PFIELD_SHAPE_SURFACE, PFIELD_SHAPE_POINTS) || + relation->pd->forcefield == PFIELD_GUIDE) { + /* TODO(sergey): Consider going more granular with more dedicated + * particle system operation. */ + DEG_add_object_pointcache_relation(handle, relation->ob, DEG_OB_COMP_GEOMETRY, name); + } + + /* Smoke flow relations. */ + if (relation->pd->forcefield == PFIELD_SMOKEFLOW && relation->pd->f_source != NULL) { + DEG_add_object_pointcache_relation( + handle, relation->pd->f_source, DEG_OB_COMP_TRANSFORM, "Smoke Force Domain"); + DEG_add_object_pointcache_relation( + handle, relation->pd->f_source, DEG_OB_COMP_GEOMETRY, "Smoke Force Domain"); + } + + /* Absorption forces need collision relation. */ + if (add_absorption && (relation->pd->flag & PFIELD_VISIBILITY)) { + DEG_add_collision_relations( + handle, object, NULL, eModifierType_Collision, NULL, "Force Absorption"); + } + } } /******************************** Internal API ********************************/ -namespace DEG -{ +namespace DEG { ListBase *build_effector_relations(Depsgraph *graph, Collection *collection) { - GHash *hash = graph->physics_relations[DEG_PHYSICS_EFFECTOR]; - if (hash == NULL) { - graph->physics_relations[DEG_PHYSICS_EFFECTOR] = - BLI_ghash_ptr_new("Depsgraph physics relations hash"); - hash = graph->physics_relations[DEG_PHYSICS_EFFECTOR]; - } - ListBase *relations = - reinterpret_cast<ListBase*>(BLI_ghash_lookup(hash, collection)); - if (relations == NULL) { - ::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph*>(graph); - relations = BKE_effector_relations_create( - depsgraph, graph->view_layer, collection); - BLI_ghash_insert(hash, &collection->id, relations); - } - return relations; + GHash *hash = graph->physics_relations[DEG_PHYSICS_EFFECTOR]; + if (hash == NULL) { + graph->physics_relations[DEG_PHYSICS_EFFECTOR] = BLI_ghash_ptr_new( + "Depsgraph physics relations hash"); + hash = graph->physics_relations[DEG_PHYSICS_EFFECTOR]; + } + ListBase *relations = reinterpret_cast<ListBase *>(BLI_ghash_lookup(hash, collection)); + if (relations == NULL) { + ::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph *>(graph); + relations = BKE_effector_relations_create(depsgraph, graph->view_layer, collection); + BLI_ghash_insert(hash, &collection->id, relations); + } + return relations; } ListBase *build_collision_relations(Depsgraph *graph, Collection *collection, unsigned int modifier_type) { - const ePhysicsRelationType type = modifier_to_relation_type(modifier_type); - GHash *hash = graph->physics_relations[type]; - if (hash == NULL) { - graph->physics_relations[type] = - BLI_ghash_ptr_new("Depsgraph physics relations hash"); - hash = graph->physics_relations[type]; - } - ListBase *relations = - reinterpret_cast<ListBase*>(BLI_ghash_lookup(hash, collection)); - if (relations == NULL) { - ::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph*>(graph); - relations = BKE_collision_relations_create( - depsgraph, collection, modifier_type); - BLI_ghash_insert(hash, &collection->id, relations); - } - return relations; + const ePhysicsRelationType type = modifier_to_relation_type(modifier_type); + GHash *hash = graph->physics_relations[type]; + if (hash == NULL) { + graph->physics_relations[type] = BLI_ghash_ptr_new("Depsgraph physics relations hash"); + hash = graph->physics_relations[type]; + } + ListBase *relations = reinterpret_cast<ListBase *>(BLI_ghash_lookup(hash, collection)); + if (relations == NULL) { + ::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph *>(graph); + relations = BKE_collision_relations_create(depsgraph, collection, modifier_type); + BLI_ghash_insert(hash, &collection->id, relations); + } + return relations; } namespace { void free_effector_relations(void *value) { - BKE_effector_relations_free(reinterpret_cast<ListBase*>(value)); + BKE_effector_relations_free(reinterpret_cast<ListBase *>(value)); } void free_collision_relations(void *value) { - BKE_collision_relations_free(reinterpret_cast<ListBase*>(value)); + BKE_collision_relations_free(reinterpret_cast<ListBase *>(value)); } } // namespace void clear_physics_relations(Depsgraph *graph) { - for (int i = 0; i < DEG_PHYSICS_RELATIONS_NUM; i++) { - if (graph->physics_relations[i]) { - const ePhysicsRelationType type = (ePhysicsRelationType)i; - - switch (type) { - case DEG_PHYSICS_EFFECTOR: - BLI_ghash_free(graph->physics_relations[i], - NULL, - free_effector_relations); - break; - case DEG_PHYSICS_COLLISION: - case DEG_PHYSICS_SMOKE_COLLISION: - case DEG_PHYSICS_DYNAMIC_BRUSH: - BLI_ghash_free(graph->physics_relations[i], - NULL, - free_collision_relations); - break; - case DEG_PHYSICS_RELATIONS_NUM: - break; - } - graph->physics_relations[i] = NULL; - } - } + for (int i = 0; i < DEG_PHYSICS_RELATIONS_NUM; i++) { + if (graph->physics_relations[i]) { + const ePhysicsRelationType type = (ePhysicsRelationType)i; + + switch (type) { + case DEG_PHYSICS_EFFECTOR: + BLI_ghash_free(graph->physics_relations[i], NULL, free_effector_relations); + break; + case DEG_PHYSICS_COLLISION: + case DEG_PHYSICS_SMOKE_COLLISION: + case DEG_PHYSICS_DYNAMIC_BRUSH: + BLI_ghash_free(graph->physics_relations[i], NULL, free_collision_relations); + break; + case DEG_PHYSICS_RELATIONS_NUM: + break; + } + graph->physics_relations[i] = NULL; + } + } } -} +} // namespace DEG |