Depsgraph: Cleanup, code style

Should be no functional changes.
This commit is contained in:
Sergey Sharybin 2018-11-13 17:21:41 +01:00
parent 1386a4a0f2
commit fdd1fea851
2 changed files with 89 additions and 61 deletions

@ -69,7 +69,7 @@ void DEG_add_collision_relations(struct DepsNodeHandle *handle,
struct Object *object, struct Object *object,
struct Collection *collection, struct Collection *collection,
unsigned int modifier_type, unsigned int modifier_type,
DEG_CollobjFilterFunction fn, DEG_CollobjFilterFunction filter_function,
const char *name); const char *name);
void DEG_add_forcefield_relations(struct DepsNodeHandle *handle, void DEG_add_forcefield_relations(struct DepsNodeHandle *handle,
struct Object *object, struct Object *object,

@ -50,9 +50,10 @@ extern "C" {
#include "depsgraph.h" #include "depsgraph.h"
#include "depsgraph_intern.h" #include "depsgraph_intern.h"
/*********************** Evaluation Query API *************************/ /*************************** 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) { switch (modifier_type) {
case eModifierType_Collision: case eModifierType_Collision:
@ -70,27 +71,32 @@ static ePhysicsRelationType modifier_to_relation_type(unsigned int modifier_type
ListBase *DEG_get_effector_relations(const Depsgraph *graph, ListBase *DEG_get_effector_relations(const Depsgraph *graph,
Collection *collection) Collection *collection)
{ {
const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph); const DEG::Depsgraph *deg_graph =
reinterpret_cast<const DEG::Depsgraph *>(graph);
if (deg_graph->physics_relations[DEG_PHYSICS_EFFECTOR] == NULL) { if (deg_graph->physics_relations[DEG_PHYSICS_EFFECTOR] == NULL) {
return NULL; return NULL;
} }
ID *collection_orig = DEG_get_original_id(&collection->id); ID *collection_orig = DEG_get_original_id(&collection->id);
return (ListBase *)BLI_ghash_lookup(deg_graph->physics_relations[DEG_PHYSICS_EFFECTOR], collection_orig); return (ListBase *)BLI_ghash_lookup(
deg_graph->physics_relations[DEG_PHYSICS_EFFECTOR],
collection_orig);
} }
ListBase *DEG_get_collision_relations(const Depsgraph *graph, ListBase *DEG_get_collision_relations(const Depsgraph *graph,
Collection *collection, Collection *collection,
unsigned int modifier_type) unsigned int modifier_type)
{ {
const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph); const DEG::Depsgraph *deg_graph =
reinterpret_cast<const DEG::Depsgraph *>(graph);
const ePhysicsRelationType type = modifier_to_relation_type(modifier_type); const ePhysicsRelationType type = modifier_to_relation_type(modifier_type);
if (deg_graph->physics_relations[type] == NULL) { if (deg_graph->physics_relations[type] == NULL) {
return NULL; return NULL;
} }
ID *collection_orig = DEG_get_original_id(&collection->id); ID *collection_orig = DEG_get_original_id(&collection->id);
return (ListBase *)BLI_ghash_lookup(deg_graph->physics_relations[type], collection_orig); return (ListBase *)BLI_ghash_lookup(
deg_graph->physics_relations[type],
collection_orig);
} }
/********************** Depsgraph Building API ************************/ /********************** Depsgraph Building API ************************/
@ -99,23 +105,28 @@ void DEG_add_collision_relations(DepsNodeHandle *handle,
Object *object, Object *object,
Collection *collection, Collection *collection,
unsigned int modifier_type, unsigned int modifier_type,
DEG_CollobjFilterFunction fn, DEG_CollobjFilterFunction filter_function,
const char *name) const char *name)
{ {
Depsgraph *depsgraph = DEG_get_graph_from_handle(handle); Depsgraph *depsgraph = DEG_get_graph_from_handle(handle);
DEG::Depsgraph *deg_graph = (DEG::Depsgraph *)depsgraph; DEG::Depsgraph *deg_graph = (DEG::Depsgraph *)depsgraph;
ListBase *relations = deg_build_collision_relations(deg_graph, collection, modifier_type); ListBase *relations = deg_build_collision_relations(
deg_graph, collection, modifier_type);
LISTBASE_FOREACH (CollisionRelation *, relation, relations) { LISTBASE_FOREACH (CollisionRelation *, relation, relations) {
Object *ob1 = relation->ob; Object *ob1 = relation->ob;
if (ob1 != object) { if (ob1 == object) {
if (!fn || fn(ob1, modifiers_findByType(ob1, (ModifierType)modifier_type))) { continue;
}
if (filter_function == NULL ||
filter_function(
ob1,
modifiers_findByType(ob1, (ModifierType)modifier_type)))
{
DEG_add_object_relation(handle, ob1, DEG_OB_COMP_TRANSFORM, name); DEG_add_object_relation(handle, ob1, DEG_OB_COMP_TRANSFORM, name);
DEG_add_object_relation(handle, ob1, DEG_OB_COMP_GEOMETRY, name); DEG_add_object_relation(handle, ob1, DEG_OB_COMP_GEOMETRY, name);
} }
} }
} }
}
void DEG_add_forcefield_relations(DepsNodeHandle *handle, void DEG_add_forcefield_relations(DepsNodeHandle *handle,
Object *object, Object *object,
@ -126,19 +137,28 @@ void DEG_add_forcefield_relations(DepsNodeHandle *handle,
{ {
Depsgraph *depsgraph = DEG_get_graph_from_handle(handle); Depsgraph *depsgraph = DEG_get_graph_from_handle(handle);
DEG::Depsgraph *deg_graph = (DEG::Depsgraph *)depsgraph; DEG::Depsgraph *deg_graph = (DEG::Depsgraph *)depsgraph;
ListBase *relations = deg_build_effector_relations(deg_graph, effector_weights->group); ListBase *relations =
deg_build_effector_relations(deg_graph, effector_weights->group);
LISTBASE_FOREACH (EffectorRelation *, relation, relations) { LISTBASE_FOREACH (EffectorRelation *, relation, relations) {
if (relation->ob != object && relation->pd->forcefield != skip_forcefield) { if (relation->ob == object) {
DEG_add_object_relation(handle, relation->ob, DEG_OB_COMP_TRANSFORM, name); continue;
if (relation->psys) {
DEG_add_object_relation(handle, relation->ob, DEG_OB_COMP_EVAL_PARTICLES, name);
/* TODO: remove this when/if EVAL_PARTICLES is sufficient
* for up to date particles.
*/
DEG_add_object_relation(handle, relation->ob, DEG_OB_COMP_GEOMETRY, name);
} }
if (relation->pd->forcefield == PFIELD_SMOKEFLOW && relation->pd->f_source) { if (relation->pd->forcefield == skip_forcefield) {
continue;
}
DEG_add_object_relation(
handle, relation->ob, DEG_OB_COMP_TRANSFORM, name);
if (relation->psys) {
DEG_add_object_relation(
handle, relation->ob, DEG_OB_COMP_EVAL_PARTICLES, name);
/* TODO: remove this when/if EVAL_PARTICLES is sufficient for up to
* date particles. */
DEG_add_object_relation(
handle, relation->ob, DEG_OB_COMP_GEOMETRY, name);
}
if (relation->pd->forcefield == PFIELD_SMOKEFLOW &&
relation->pd->f_source != NULL)
{
DEG_add_object_relation(handle, DEG_add_object_relation(handle,
relation->pd->f_source, relation->pd->f_source,
DEG_OB_COMP_TRANSFORM, DEG_OB_COMP_TRANSFORM,
@ -158,9 +178,8 @@ void DEG_add_forcefield_relations(DepsNodeHandle *handle,
} }
} }
} }
}
/**************************** Internal API ****************************/ /******************************** Internal API ********************************/
namespace DEG namespace DEG
{ {
@ -170,17 +189,18 @@ ListBase *deg_build_effector_relations(Depsgraph *graph,
{ {
GHash *hash = graph->physics_relations[DEG_PHYSICS_EFFECTOR]; GHash *hash = graph->physics_relations[DEG_PHYSICS_EFFECTOR];
if (hash == NULL) { if (hash == NULL) {
graph->physics_relations[DEG_PHYSICS_EFFECTOR] = BLI_ghash_ptr_new("Depsgraph physics relations hash"); graph->physics_relations[DEG_PHYSICS_EFFECTOR] =
BLI_ghash_ptr_new("Depsgraph physics relations hash");
hash = graph->physics_relations[DEG_PHYSICS_EFFECTOR]; hash = graph->physics_relations[DEG_PHYSICS_EFFECTOR];
} }
ListBase *relations =
ListBase *relations = reinterpret_cast<ListBase*>(BLI_ghash_lookup(hash, collection)); reinterpret_cast<ListBase*>(BLI_ghash_lookup(hash, collection));
if (relations == NULL) { if (relations == NULL) {
::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph*>(graph); ::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph*>(graph);
relations = BKE_effector_relations_create(depsgraph, graph->view_layer, collection); relations = BKE_effector_relations_create(
depsgraph, graph->view_layer, collection);
BLI_ghash_insert(hash, &collection->id, relations); BLI_ghash_insert(hash, &collection->id, relations);
} }
return relations; return relations;
} }
@ -191,30 +211,35 @@ ListBase *deg_build_collision_relations(Depsgraph *graph,
const ePhysicsRelationType type = modifier_to_relation_type(modifier_type); const ePhysicsRelationType type = modifier_to_relation_type(modifier_type);
GHash *hash = graph->physics_relations[type]; GHash *hash = graph->physics_relations[type];
if (hash == NULL) { if (hash == NULL) {
graph->physics_relations[type] = BLI_ghash_ptr_new("Depsgraph physics relations hash"); graph->physics_relations[type] =
BLI_ghash_ptr_new("Depsgraph physics relations hash");
hash = graph->physics_relations[type]; hash = graph->physics_relations[type];
} }
ListBase *relations =
ListBase *relations = reinterpret_cast<ListBase*>(BLI_ghash_lookup(hash, collection)); reinterpret_cast<ListBase*>(BLI_ghash_lookup(hash, collection));
if (relations == NULL) { if (relations == NULL) {
::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph*>(graph); ::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph*>(graph);
relations = BKE_collision_relations_create(depsgraph, collection, modifier_type); relations = BKE_collision_relations_create(
depsgraph, collection, modifier_type);
BLI_ghash_insert(hash, &collection->id, relations); BLI_ghash_insert(hash, &collection->id, relations);
} }
return relations; return relations;
} }
static void free_effector_relations(void *value) namespace {
void free_effector_relations(void *value)
{ {
BKE_effector_relations_free(reinterpret_cast<ListBase*>(value)); BKE_effector_relations_free(reinterpret_cast<ListBase*>(value));
} }
static void free_collision_relations(void *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 deg_clear_physics_relations(Depsgraph *graph) void deg_clear_physics_relations(Depsgraph *graph)
{ {
for (int i = 0; i < DEG_PHYSICS_RELATIONS_NUM; i++) { for (int i = 0; i < DEG_PHYSICS_RELATIONS_NUM; i++) {
@ -223,17 +248,20 @@ void deg_clear_physics_relations(Depsgraph *graph)
switch (type) { switch (type) {
case DEG_PHYSICS_EFFECTOR: case DEG_PHYSICS_EFFECTOR:
BLI_ghash_free(graph->physics_relations[i], NULL, free_effector_relations); BLI_ghash_free(graph->physics_relations[i],
NULL,
free_effector_relations);
break; break;
case DEG_PHYSICS_COLLISION: case DEG_PHYSICS_COLLISION:
case DEG_PHYSICS_SMOKE_COLLISION: case DEG_PHYSICS_SMOKE_COLLISION:
case DEG_PHYSICS_DYNAMIC_BRUSH: case DEG_PHYSICS_DYNAMIC_BRUSH:
BLI_ghash_free(graph->physics_relations[i], NULL, free_collision_relations); BLI_ghash_free(graph->physics_relations[i],
NULL,
free_collision_relations);
break; break;
case DEG_PHYSICS_RELATIONS_NUM: case DEG_PHYSICS_RELATIONS_NUM:
break; break;
} }
graph->physics_relations[i] = NULL; graph->physics_relations[i] = NULL;
} }
} }