diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-06-22 15:42:03 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-06-25 14:35:41 +0300 |
commit | a99dcab148ed209409f3b2479ada12d869ae84b6 (patch) | |
tree | 2b7fc55752cbe3538fc05c8f77fd86b18a0d6df7 /source/blender/depsgraph/intern/depsgraph_physics.cc | |
parent | 5b3ff9f7d890554ae87e63095f24ac6d31a36d3c (diff) |
Depsgraph: cache collision relations, for performance and stability.
Same reasoning as effector relations in earlier commit.
Diffstat (limited to 'source/blender/depsgraph/intern/depsgraph_physics.cc')
-rw-r--r-- | source/blender/depsgraph/intern/depsgraph_physics.cc | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/source/blender/depsgraph/intern/depsgraph_physics.cc b/source/blender/depsgraph/intern/depsgraph_physics.cc index fb14c020f81..ba42ef96365 100644 --- a/source/blender/depsgraph/intern/depsgraph_physics.cc +++ b/source/blender/depsgraph/intern/depsgraph_physics.cc @@ -33,6 +33,7 @@ #include "BLI_ghash.h" extern "C" { +#include "BKE_collision.h" #include "BKE_effect.h" } /* extern "C" */ @@ -56,6 +57,28 @@ ListBase *DEG_get_effector_relations(const Depsgraph *graph, return (ListBase *)BLI_ghash_lookup(deg_graph->effector_relations, collection); } +ListBase *DEG_get_collision_relations(const Depsgraph *graph, + Collection *collection) +{ + const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph); + if (deg_graph->collision_relations == NULL) { + return NULL; + } + + return (ListBase*)BLI_ghash_lookup(deg_graph->collision_relations, collection); +} + +ListBase *DEG_get_smoke_collision_relations(const Depsgraph *graph, + Collection *collection) +{ + const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph); + if (deg_graph->smoke_collision_relations == NULL) { + return NULL; + } + + return (ListBase*)BLI_ghash_lookup(deg_graph->smoke_collision_relations, collection); +} + /*********************** Internal API ************************/ namespace DEG @@ -78,13 +101,60 @@ ListBase *deg_build_effector_relations(Depsgraph *graph, return relations; } +ListBase *deg_build_collision_relations(Depsgraph *graph, + Collection *collection) +{ + if (graph->collision_relations == NULL) { + graph->collision_relations = BLI_ghash_ptr_new("Depsgraph collision relations hash"); + } + + ListBase *relations = reinterpret_cast<ListBase*>(BLI_ghash_lookup(graph->collision_relations, collection)); + if (relations == NULL) { + ::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph*>(graph); + relations = BKE_collision_relations_create(depsgraph, collection, eModifierType_Collision); + BLI_ghash_insert(graph->collision_relations, collection, relations); + } + + return relations; +} + +ListBase *deg_build_smoke_collision_relations(Depsgraph *graph, + Collection *collection) +{ + if (graph->smoke_collision_relations == NULL) { + graph->smoke_collision_relations = BLI_ghash_ptr_new("Depsgraph smoke collision relations hash"); + } + + ListBase *relations = reinterpret_cast<ListBase*>(BLI_ghash_lookup(graph->smoke_collision_relations, collection)); + if (relations == NULL) { + ::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph*>(graph); + relations = BKE_collision_relations_create(depsgraph, collection, eModifierType_Smoke); + BLI_ghash_insert(graph->smoke_collision_relations, collection, relations); + } + + return relations; +} + static void free_effector_relations(void *value) { BKE_effector_relations_free(reinterpret_cast<ListBase*>(value)); } +static void free_collision_relations(void *value) +{ + BKE_collision_relations_free(reinterpret_cast<ListBase*>(value)); +} + void deg_clear_physics_relations(Depsgraph *graph) { + if (graph->collision_relations) { + BLI_ghash_free(graph->collision_relations, NULL, free_collision_relations); + graph->collision_relations = NULL; + } + if (graph->smoke_collision_relations) { + BLI_ghash_free(graph->smoke_collision_relations, NULL, free_collision_relations); + graph->smoke_collision_relations = NULL; + } if (graph->effector_relations) { BLI_ghash_free(graph->effector_relations, NULL, free_effector_relations); graph->effector_relations = NULL; |