[Bf-blender-cvs] [2c9b32949bc] blender2.8: Cleanup: refactor depsgraph physics API functions.

Brecht Van Lommel noreply at git.blender.org
Mon Jun 25 17:19:02 CEST 2018


Commit: 2c9b32949bc00e73603bcabadb74e5b3176a161a
Author: Brecht Van Lommel
Date:   Mon Jun 25 16:04:56 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB2c9b32949bc00e73603bcabadb74e5b3176a161a

Cleanup: refactor depsgraph physics API functions.

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

M	source/blender/blenkernel/intern/collision.c
M	source/blender/depsgraph/DEG_depsgraph_build.h
M	source/blender/depsgraph/DEG_depsgraph_physics.h
M	source/blender/depsgraph/intern/builder/deg_builder_relations.cc
M	source/blender/depsgraph/intern/depsgraph.cc
M	source/blender/depsgraph/intern/depsgraph.h
M	source/blender/depsgraph/intern/depsgraph_build.cc
M	source/blender/depsgraph/intern/depsgraph_intern.h
M	source/blender/depsgraph/intern/depsgraph_physics.cc
M	source/blender/modifiers/intern/MOD_cloth.c
M	source/blender/modifiers/intern/MOD_dynamicpaint.c
M	source/blender/modifiers/intern/MOD_smoke.c
M	source/blender/modifiers/intern/MOD_softbody.c

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

diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index 546f37dbee6..1debdbb847e 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -545,14 +545,7 @@ void BKE_collision_relations_free(ListBase *relations)
  * Self will be excluded. */
 Object **BKE_collision_objects_create(Depsgraph *depsgraph, Object *self, Collection *collection, unsigned int *numcollobj, unsigned int modifier_type)
 {
-	ListBase *relations;
-
-	if (modifier_type == eModifierType_Smoke) {
-		relations = DEG_get_smoke_collision_relations(depsgraph, collection);
-	}
-	else {
-		relations = DEG_get_collision_relations(depsgraph, collection);
-	}
+	ListBase *relations = DEG_get_collision_relations(depsgraph, collection, modifier_type);
 
 	if (!relations) {
 		return NULL;
@@ -592,8 +585,7 @@ void BKE_collision_objects_free(Object **objects)
  * Self will be excluded. */
 ListBase *BKE_collider_cache_create(Depsgraph *depsgraph, Object *self, Collection *collection)
 {
-	/* TODO: does this get built? */
-	ListBase *relations = DEG_get_collision_relations(depsgraph, collection);
+	ListBase *relations = DEG_get_collision_relations(depsgraph, collection, eModifierType_Collision);
 	ListBase *cache = NULL;
 
 	if (!relations) {
diff --git a/source/blender/depsgraph/DEG_depsgraph_build.h b/source/blender/depsgraph/DEG_depsgraph_build.h
index 834d45a7e61..30fefb7d4e4 100644
--- a/source/blender/depsgraph/DEG_depsgraph_build.h
+++ b/source/blender/depsgraph/DEG_depsgraph_build.h
@@ -153,22 +153,6 @@ void DEG_add_object_cache_relation(struct DepsNodeHandle *handle,
 struct Depsgraph *DEG_get_graph_from_handle(struct DepsNodeHandle *handle);
 void DEG_add_special_eval_flag(struct Depsgraph *graph, struct ID *id, short flag);
 
-/* Utility functions for physics modifiers */
-typedef bool (*DEG_CollobjFilterFunction)(struct Object *obj, struct ModifierData *md);
-
-void DEG_add_collision_relations(struct DepsNodeHandle *handle,
-                                 struct Object *object,
-                                 struct Collection *collection,
-                                 unsigned int modifier_type,
-                                 DEG_CollobjFilterFunction fn,
-                                 const char *name);
-void DEG_add_forcefield_relations(struct DepsNodeHandle *handle,
-                                  struct Object *object,
-                                  struct EffectorWeights *eff,
-                                  bool add_absorption,
-                                  int skip_forcefield,
-                                  const char *name);
-
 /* ************************************************ */
 
 #ifdef __cplusplus
diff --git a/source/blender/depsgraph/DEG_depsgraph_physics.h b/source/blender/depsgraph/DEG_depsgraph_physics.h
index c90f66838cc..fd35a7fb2c0 100644
--- a/source/blender/depsgraph/DEG_depsgraph_physics.h
+++ b/source/blender/depsgraph/DEG_depsgraph_physics.h
@@ -34,21 +34,49 @@
 
 struct Colllection;
 struct Depsgraph;
+struct DepsNodeHandle;
+struct EffectorWeights;
 struct ListBase;
+struct Object;
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+typedef enum ePhysicsRelationType {
+	DEG_PHYSICS_EFFECTOR        = 0,
+	DEG_PHYSICS_COLLISION       = 1,
+	DEG_PHYSICS_SMOKE_COLLISION = 2,
+	DEG_PHYSICS_DYNAMIC_BRUSH   = 3,
+	DEG_PHYSICS_RELATIONS_NUM   = 4
+} ePhysicsRelationType;
+
 /* Get collision/effector relations from collection or entire scene. These
  * created during depsgraph relations building and should only be accessed
  * during evaluation. */
 struct ListBase *DEG_get_effector_relations(const struct Depsgraph *depsgraph,
                                             struct Collection *collection);
 struct ListBase *DEG_get_collision_relations(const struct Depsgraph *depsgraph,
-                                             struct Collection *collection);
-struct ListBase *DEG_get_smoke_collision_relations(const struct Depsgraph *depsgraph,
-                                                   struct Collection *collection);
+                                             struct Collection *collection,
+                                             unsigned int modifier_type);
+
+
+/* Build collision/effector relations for depsgraph. */
+typedef bool (*DEG_CollobjFilterFunction)(struct Object *obj,
+                                          struct ModifierData *md);
+
+void DEG_add_collision_relations(struct DepsNodeHandle *handle,
+                                 struct Object *object,
+                                 struct Collection *collection,
+                                 unsigned int modifier_type,
+                                 DEG_CollobjFilterFunction fn,
+                                 const char *name);
+void DEG_add_forcefield_relations(struct DepsNodeHandle *handle,
+                                  struct Object *object,
+                                  struct EffectorWeights *eff,
+                                  bool add_absorption,
+                                  int skip_forcefield,
+                                  const char *name);
 
 #ifdef __cplusplus
 } /* extern "C" */
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
index d87cb59e976..06c17b19a8c 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
@@ -302,7 +302,7 @@ void DepsgraphRelationBuilder::add_collision_relations(
         Collection *collection,
         const char *name)
 {
-	ListBase *relations = deg_build_collision_relations(graph_, collection);
+	ListBase *relations = deg_build_collision_relations(graph_, collection, eModifierType_Collision);
 
 	LISTBASE_FOREACH (CollisionRelation *, relation, relations) {
 		if (relation->ob != object) {
diff --git a/source/blender/depsgraph/intern/depsgraph.cc b/source/blender/depsgraph/intern/depsgraph.cc
index 267cadb7993..ddc6e44ee1b 100644
--- a/source/blender/depsgraph/intern/depsgraph.cc
+++ b/source/blender/depsgraph/intern/depsgraph.cc
@@ -93,16 +93,14 @@ Depsgraph::Depsgraph(Scene *scene,
     mode(mode),
     ctime(BKE_scene_frame_get(scene)),
     scene_cow(NULL),
-    is_active(false),
-	collision_relations(NULL),
-	smoke_collision_relations(NULL),
-	effector_relations(NULL)
+    is_active(false)
 {
 	BLI_spin_init(&lock);
 	id_hash = BLI_ghash_ptr_new("Depsgraph id hash");
 	entry_tags = BLI_gset_ptr_new("Depsgraph entry_tags");
 	debug_flags = G.debug;
 	memset(id_type_updated, 0, sizeof(id_type_updated));
+	memset(physics_relations, 0, sizeof(physics_relations));
 }
 
 Depsgraph::~Depsgraph()
diff --git a/source/blender/depsgraph/intern/depsgraph.h b/source/blender/depsgraph/intern/depsgraph.h
index 3517a6f6f34..804fd1b36c2 100644
--- a/source/blender/depsgraph/intern/depsgraph.h
+++ b/source/blender/depsgraph/intern/depsgraph.h
@@ -45,6 +45,7 @@
 #include "BLI_threads.h"  /* for SpinLock */
 
 #include "DEG_depsgraph.h"
+#include "DEG_depsgraph_physics.h"
 
 #include "intern/depsgraph_types.h"
 
@@ -229,9 +230,7 @@ struct Depsgraph {
 
 	/* Cached list of colliders/effectors for collections and the scene
 	 * created along with relations, for fast lookup during evaluation. */
-	GHash *collision_relations;
-	GHash *smoke_collision_relations;
-	GHash *effector_relations;
+	GHash *physics_relations[DEG_PHYSICS_RELATIONS_NUM];
 };
 
 }  // namespace DEG
diff --git a/source/blender/depsgraph/intern/depsgraph_build.cc b/source/blender/depsgraph/intern/depsgraph_build.cc
index 042cf801e6b..fccb5808711 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.cc
+++ b/source/blender/depsgraph/intern/depsgraph_build.cc
@@ -43,12 +43,8 @@ extern "C" {
 #include "DNA_cachefile_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
-#include "DNA_object_force_types.h"
 
 #include "BKE_main.h"
-#include "BKE_collision.h"
-#include "BKE_effect.h"
-#include "BKE_modifier.h"
 #include "BKE_scene.h"
 } /* extern "C" */
 
@@ -322,75 +318,3 @@ void DEG_relations_tag_update(Main *bmain)
 		}
 	}
 }
-
-void DEG_add_collision_relations(DepsNodeHandle *handle,
-                                 Object *object,
-                                 Collection *collection,
-                                 unsigned int modifier_type,
-                                 DEG_CollobjFilterFunction fn,
-                                 const char *name)
-{
-	Depsgraph *depsgraph = DEG_get_graph_from_handle(handle);
-	DEG::Depsgraph *deg_graph = (DEG::Depsgraph *)depsgraph;
-	ListBase *relations;
-
-	if (modifier_type == eModifierType_Smoke) {
-		relations = deg_build_smoke_collision_relations(deg_graph, collection);
-	}
-	else {
-		relations = deg_build_collision_relations(deg_graph, collection);
-	}
-
-	LISTBASE_FOREACH (CollisionRelation *, relation, relations) {
-		Object *ob1 = relation->ob;
-		if (ob1 != object) {
-			if (!fn || fn(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_GEOMETRY, name);
-			}
-		}
-	}
-}
-
-void DEG_add_forcefield_relations(DepsNodeHandle *handle,
-                                  Object *object,
-                                  EffectorWeights *effector_weights,
-                                  bool add_absorption,
-                                  int skip_forcefield,
-                                  const char *name)
-{
-	Depsgraph *depsgraph = DEG_get_graph_from_handle(handle);
-	DEG::Depsgraph *deg_graph = (DEG::Depsgraph *)depsgraph;
-	ListBase *relations = deg_build_effector_relations(deg_graph, effector_weights->group);
-
-	LISTBASE_FOREACH (EffectorRelation *, relation, relations) {
-		if (relation->ob != object && relation->pd->forcefield != skip_forcefield) {
-			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 suffici

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list