From d43f7608923bb3ff84c5eed0631d0457d68416e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Tue, 2 Sep 2014 14:10:28 +0200 Subject: Hair debugging: use "categories" (strings) for grouping debug elements and support clearing for categories. --- source/blender/blenkernel/BKE_effect.h | 11 ++++++---- source/blender/blenkernel/intern/collision.c | 16 +++++--------- source/blender/blenkernel/intern/effect.c | 32 +++++++++++++++++++++++++--- source/blender/blenkernel/intern/implicit.c | 4 +++- 4 files changed, 44 insertions(+), 19 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/BKE_effect.h b/source/blender/blenkernel/BKE_effect.h index 852f9de4c09..04853bbb163 100644 --- a/source/blender/blenkernel/BKE_effect.h +++ b/source/blender/blenkernel/BKE_effect.h @@ -139,8 +139,10 @@ int get_effector_data(struct EffectorCache *eff, struct EffectorData *efd, struc /* ======== Simulation Debugging ======== */ typedef struct SimDebugElement { - int type; + int category_hash; int hash; + + int type; float color[3]; float v1[3], v2[3]; @@ -157,11 +159,12 @@ typedef struct SimDebugData { } SimDebugData; struct SimDebugData *BKE_sim_debug_data_new(void); -void BKE_sim_debug_data_add_dot(struct SimDebugData *debug_data, const float p[3], float r, float g, float b, int hash); -void BKE_sim_debug_data_add_line(struct SimDebugData *debug_data, const float p1[3], const float p2[3], float r, float g, float b, int hash); -void BKE_sim_debug_data_add_vector(struct SimDebugData *debug_data, const float p[3], const float d[3], float r, float g, float b, int hash); +void BKE_sim_debug_data_add_dot(struct SimDebugData *debug_data, const float p[3], float r, float g, float b, const char *category, int hash); +void BKE_sim_debug_data_add_line(struct SimDebugData *debug_data, const float p1[3], const float p2[3], float r, float g, float b, const char *category, int hash); +void BKE_sim_debug_data_add_vector(struct SimDebugData *debug_data, const float p[3], const float d[3], float r, float g, float b, const char *category, int hash); void BKE_sim_debug_data_remove(struct SimDebugData *debug_data, int hash); void BKE_sim_debug_data_clear(struct SimDebugData *debug_data); +void BKE_sim_debug_data_clear_category(struct SimDebugData *debug_data, const char *category); void BKE_sim_debug_data_free(struct SimDebugData *debug_data); #endif diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index 4f92fdab739..c421296e4eb 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -1010,10 +1010,10 @@ static bool cloth_points_collision_response_static(ClothModifierData *clmd, Coll /**** DEBUG ****/ if (clmd->debug_data) { - BKE_sim_debug_data_add_dot(clmd->debug_data, collpair->pa, 0.9, 0.2, 0.2, hash_collpair(833, collpair)); - BKE_sim_debug_data_add_dot(clmd->debug_data, collpair->pb, 0.2, 0.9, 0.2, hash_collpair(834, collpair)); - BKE_sim_debug_data_add_line(clmd->debug_data, collpair->pa, collpair->pb, 0.8, 0.8, 0.8, hash_collpair(835, collpair)); - BKE_sim_debug_data_add_vector(clmd->debug_data, collpair->pa, collpair->normal, 1.0, 1.0, 0.0, hash_collpair(836, collpair)); + BKE_sim_debug_data_add_dot(clmd->debug_data, collpair->pa, 0.9, 0.2, 0.2, "collision", hash_collpair(833, collpair)); + BKE_sim_debug_data_add_dot(clmd->debug_data, collpair->pb, 0.2, 0.9, 0.2, "collision", hash_collpair(834, collpair)); + BKE_sim_debug_data_add_line(clmd->debug_data, collpair->pa, collpair->pb, 0.8, 0.8, 0.8, "collision", hash_collpair(835, collpair)); +// BKE_sim_debug_data_add_vector(clmd->debug_data, collpair->pa, collpair->normal, 1.0, 1.0, 0.0, "collision", hash_collpair(836, collpair)); } /********/ @@ -1046,16 +1046,10 @@ static bool cloth_points_collision_response_static(ClothModifierData *clmd, Coll copy_v3_v3(impulse, repulse); } cloth1->verts[collpair->ap1].impulse_count++; - BKE_sim_debug_data_add_vector(clmd->debug_data, collpair->pa, impulse, 0.0, 1.0, 0.6, hash_collpair(873, collpair)); + BKE_sim_debug_data_add_vector(clmd->debug_data, collpair->pa, impulse, 0.0, 1.0, 0.6, "collision", hash_collpair(873, collpair)); result = true; } - else { - BKE_sim_debug_data_remove(clmd->debug_data, hash_collpair(833, collpair)); - BKE_sim_debug_data_remove(clmd->debug_data, hash_collpair(834, collpair)); - BKE_sim_debug_data_remove(clmd->debug_data, hash_collpair(835, collpair)); - BKE_sim_debug_data_remove(clmd->debug_data, hash_collpair(873, collpair)); - } if (result) { int i = 0; diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index 0cbd7376e4f..82c3ed847a9 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -1070,14 +1070,16 @@ static void debug_data_insert(SimDebugData *debug_data, SimDebugElement *elem) BLI_ghash_insert(debug_data->gh, elem, elem); } -void BKE_sim_debug_data_add_dot(struct SimDebugData *debug_data, const float p[3], float r, float g, float b, int hash) +void BKE_sim_debug_data_add_dot(struct SimDebugData *debug_data, const float p[3], float r, float g, float b, const char *category, int hash) { + int category_hash = (int)BLI_ghashutil_strhash_p(category); SimDebugElement *elem; if (!debug_data) return; elem = MEM_callocN(sizeof(SimDebugElement), "sim debug data element"); elem->type = SIM_DEBUG_ELEM_DOT; + elem->category_hash = category_hash; elem->hash = hash; elem->color[0] = r; elem->color[1] = g; @@ -1087,14 +1089,16 @@ void BKE_sim_debug_data_add_dot(struct SimDebugData *debug_data, const float p[3 debug_data_insert(debug_data, elem); } -void BKE_sim_debug_data_add_line(struct SimDebugData *debug_data, const float p1[3], const float p2[3], float r, float g, float b, int hash) +void BKE_sim_debug_data_add_line(struct SimDebugData *debug_data, const float p1[3], const float p2[3], float r, float g, float b, const char *category, int hash) { + int category_hash = (int)BLI_ghashutil_strhash_p(category); SimDebugElement *elem; if (!debug_data) return; elem = MEM_callocN(sizeof(SimDebugElement), "sim debug data element"); elem->type = SIM_DEBUG_ELEM_LINE; + elem->category_hash = category_hash; elem->hash = hash; elem->color[0] = r; elem->color[1] = g; @@ -1105,14 +1109,16 @@ void BKE_sim_debug_data_add_line(struct SimDebugData *debug_data, const float p1 debug_data_insert(debug_data, elem); } -void BKE_sim_debug_data_add_vector(struct SimDebugData *debug_data, const float p[3], const float d[3], float r, float g, float b, int hash) +void BKE_sim_debug_data_add_vector(struct SimDebugData *debug_data, const float p[3], const float d[3], float r, float g, float b, const char *category, int hash) { + int category_hash = (int)BLI_ghashutil_strhash_p(category); SimDebugElement *elem; if (!debug_data) return; elem = MEM_callocN(sizeof(SimDebugElement), "sim debug data element"); elem->type = SIM_DEBUG_ELEM_VECTOR; + elem->category_hash = category_hash; elem->hash = hash; elem->color[0] = r; elem->color[1] = g; @@ -1142,6 +1148,26 @@ void BKE_sim_debug_data_clear(SimDebugData *debug_data) BLI_ghash_clear(debug_data->gh, NULL, debug_element_free); } +void BKE_sim_debug_data_clear_category(SimDebugData *debug_data, const char *category) +{ + int category_hash = (int)BLI_ghashutil_strhash_p(category); + + if (!debug_data) + return; + + if (debug_data->gh) { + GHashIterator iter; + BLI_ghashIterator_init(&iter, debug_data->gh); + while(!BLI_ghashIterator_done(&iter)) { + SimDebugElement *elem = BLI_ghashIterator_getValue(&iter); + BLI_ghashIterator_step(&iter); /* removing invalidates the current iterator, so step before removing */ + + if (elem->category_hash == category_hash) + BLI_ghash_remove(debug_data->gh, elem, NULL, debug_element_free); + } + } +} + void BKE_sim_debug_data_free(SimDebugData *debug_data) { if (!debug_data) diff --git a/source/blender/blenkernel/intern/implicit.c b/source/blender/blenkernel/intern/implicit.c index d0f0bc9455a..45f210fd89d 100644 --- a/source/blender/blenkernel/intern/implicit.c +++ b/source/blender/blenkernel/intern/implicit.c @@ -1959,6 +1959,8 @@ int implicit_solver(Object *ob, float frame, ClothModifierData *clmd, ListBase * /*float (*initial_cos)[3] = MEM_callocN(sizeof(float)*3*cloth->numverts, "initial_cos implicit.c");*/ /* UNUSED */ Implicit_Data *id = cloth->implicit; + BKE_sim_debug_data_clear_category(clmd->debug_data, "collision"); + if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) { /* do goal stuff */ /* Update vertex constraints for pinned vertices */ @@ -1975,7 +1977,7 @@ int implicit_solver(Object *ob, float frame, ClothModifierData *clmd, ListBase * if (clmd->debug_data) { for (i = 0; i < numverts; i++) { - BKE_sim_debug_data_add_dot(clmd->debug_data, verts[i].x, 1.0f, 0.1f, 1.0f, hash_vertex(583, i)); + BKE_sim_debug_data_add_dot(clmd->debug_data, verts[i].x, 1.0f, 0.1f, 1.0f, "points", hash_vertex(583, i)); } } -- cgit v1.2.3