diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2015-01-20 20:29:31 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2015-01-20 20:32:06 +0300 |
commit | 9d9dc06014ea7f8fd186246d1e55d429c5193cb6 (patch) | |
tree | faad9521f23f32c9ce1b9331f9763c69d52bedae /source/blender/blenkernel | |
parent | 3356f3f0bb15fa50c2920e4bc428a8375b43f321 (diff) |
Made SimDebugData into a single global instance.
This way it doesn't have to be stored as DNA runtime pointers or passed
down as a function argument. Currently there is now no property or
button to enable debugging, this will be added again later.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_effect.h | 35 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/collision.c | 14 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/effect.c | 71 |
3 files changed, 66 insertions, 54 deletions
diff --git a/source/blender/blenkernel/BKE_effect.h b/source/blender/blenkernel/BKE_effect.h index c85145470b1..c4c27e1060d 100644 --- a/source/blender/blenkernel/BKE_effect.h +++ b/source/blender/blenkernel/BKE_effect.h @@ -188,36 +188,39 @@ typedef struct SimDebugData { struct GHash *gh; } SimDebugData; -struct SimDebugData *BKE_sim_debug_data_new(void); +extern SimDebugData *_sim_debug_data; -void BKE_sim_debug_data_add_element(struct SimDebugData *debug_data, int type, const float v1[3], const float v2[3], +void BKE_sim_debug_data_set_enabled(bool enable); +bool BKE_sim_debug_data_get_enabled(void); +void BKE_sim_debug_data_free(void); + +void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[3], float r, float g, float b, const char *category, unsigned int hash); -void BKE_sim_debug_data_remove_element(struct SimDebugData *debug_data, unsigned int hash); +void BKE_sim_debug_data_remove_element(unsigned int hash); -#define BKE_sim_debug_data_add_dot(debug_data, p, r, g, b, category, ...) { \ +#define BKE_sim_debug_data_add_dot(p, r, g, b, category, ...) { \ const float v2[3] = { 0.0f, 0.0f, 0.0f }; \ - BKE_sim_debug_data_add_element(debug_data, SIM_DEBUG_ELEM_DOT, p, v2, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \ + BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_DOT, p, v2, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \ } -#define BKE_sim_debug_data_add_circle(debug_data, p, radius, r, g, b, category, ...) { \ +#define BKE_sim_debug_data_add_circle(p, radius, r, g, b, category, ...) { \ const float v2[3] = { radius, 0.0f, 0.0f }; \ - BKE_sim_debug_data_add_element(debug_data, SIM_DEBUG_ELEM_CIRCLE, p, v2, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \ + BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_CIRCLE, p, v2, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \ } -#define BKE_sim_debug_data_add_line(debug_data, p1, p2, r, g, b, category, ...) { \ - BKE_sim_debug_data_add_element(debug_data, SIM_DEBUG_ELEM_LINE, p1, p2, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \ +#define BKE_sim_debug_data_add_line(p1, p2, r, g, b, category, ...) { \ + BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_LINE, p1, p2, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \ } -#define BKE_sim_debug_data_add_vector(debug_data, p, d, r, g, b, category, ...) { \ - BKE_sim_debug_data_add_element(debug_data, SIM_DEBUG_ELEM_VECTOR, p, d, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \ +#define BKE_sim_debug_data_add_vector(p, d, r, g, b, category, ...) { \ + BKE_sim_debug_data_add_element(SIM_DEBUG_ELEM_VECTOR, p, d, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \ } -#define BKE_sim_debug_data_remove(debug_data, ...) \ - BKE_sim_debug_data_remove_element(debug_data, SIM_DEBUG_HASH(__VA_ARGS__)) +#define BKE_sim_debug_data_remove(...) \ + BKE_sim_debug_data_remove_element(SIM_DEBUG_HASH(__VA_ARGS__)) -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); +void BKE_sim_debug_data_clear(void); +void BKE_sim_debug_data_clear_category(const char *category); #endif diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index 92cd1ee0611..5266c5b323d 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -990,11 +990,9 @@ static bool cloth_points_collision_response_static(ClothModifierData *clmd, Coll mag_v_rel = dot_v3v3(v_rel_old, collpair->normal); /**** DEBUG ****/ - if (clmd->debug_data) { - BKE_sim_debug_data_add_dot(clmd->debug_data, collpair->pa, 0.9, 0.2, 0.2, "collision", 833, collpair->face1, collpair->face2); - BKE_sim_debug_data_add_dot(clmd->debug_data, collpair->pb, 0.2, 0.9, 0.2, "collision", 834, collpair->face1, collpair->face2); - BKE_sim_debug_data_add_line(clmd->debug_data, collpair->pa, collpair->pb, 0.8, 0.8, 0.8, "collision", 835, collpair->face1, collpair->face2); - } + BKE_sim_debug_data_add_dot(collpair->pa, 0.9, 0.2, 0.2, "collision", 833, collpair->face1, collpair->face2); + BKE_sim_debug_data_add_dot(collpair->pb, 0.2, 0.9, 0.2, "collision", 834, collpair->face1, collpair->face2); + BKE_sim_debug_data_add_line(collpair->pa, collpair->pb, 0.8, 0.8, 0.8, "collision", 835, collpair->face1, collpair->face2); /********/ if (mag_v_rel < -ALMOST_ZERO) { @@ -1106,7 +1104,7 @@ BLI_INLINE bool cloth_point_face_collision_params(const float p1[3], const float } static CollPair *cloth_point_collpair(float p1[3], float p2[3], MVert *mverts, int bp1, int bp2, int bp3, - int index_cloth, int index_coll, float epsilon, CollPair *collpair, SimDebugData *UNUSED(debug_data)) + int index_cloth, int index_coll, float epsilon, CollPair *collpair) { float *co1 = mverts[bp1].co, *co2 = mverts[bp2].co, *co3 = mverts[bp3].co; float lambda, distance1, distance2; @@ -1163,9 +1161,9 @@ static CollPair* cloth_point_collision(ModifierData *md1, ModifierData *md2, vert = &clmd->clothObject->verts[overlap->indexA]; face = &collmd->mfaces[overlap->indexB]; - collpair = cloth_point_collpair(vert->tx, vert->x, mverts, face->v1, face->v2, face->v3, overlap->indexA, overlap->indexB, epsilon, collpair, clmd->debug_data); + collpair = cloth_point_collpair(vert->tx, vert->x, mverts, face->v1, face->v2, face->v3, overlap->indexA, overlap->indexB, epsilon, collpair); if (face->v4) - collpair = cloth_point_collpair(vert->tx, vert->x, mverts, face->v3, face->v4, face->v1, overlap->indexA, overlap->indexB, epsilon, collpair, clmd->debug_data); + collpair = cloth_point_collpair(vert->tx, vert->x, mverts, face->v3, face->v4, face->v1, overlap->indexA, overlap->indexB, epsilon, collpair); return collpair; } diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index e43bde7ea38..c896fa2bbcf 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -1029,6 +1029,8 @@ void pdDoEffectors(ListBase *effectors, ListBase *colliders, EffectorWeights *we /* ======== Simulation Debugging ======== */ +SimDebugData *_sim_debug_data = NULL; + unsigned int BKE_sim_debug_data_hash(int i) { return BLI_ghashutil_uinthash((unsigned int)i); @@ -1080,12 +1082,31 @@ static void debug_element_free(void *val) MEM_freeN(elem); } -SimDebugData *BKE_sim_debug_data_new(void) +void BKE_sim_debug_data_set_enabled(bool enable) { - SimDebugData *debug_data = MEM_callocN(sizeof(SimDebugData), "sim debug data"); - debug_data->gh = BLI_ghash_new(debug_element_hash, debug_element_compare, "sim debug element hash"); - return debug_data; - + if (enable) { + if (!_sim_debug_data) { + _sim_debug_data = MEM_callocN(sizeof(SimDebugData), "sim debug data"); + _sim_debug_data->gh = BLI_ghash_new(debug_element_hash, debug_element_compare, "sim debug element hash"); + } + } + else { + BKE_sim_debug_data_free(); + } +} + +bool BKE_sim_debug_data_get_enabled(void) +{ + return _sim_debug_data != NULL; +} + +void BKE_sim_debug_data_free(void) +{ + if (_sim_debug_data) { + if (_sim_debug_data->gh) + BLI_ghash_free(_sim_debug_data->gh, NULL, debug_element_free); + MEM_freeN(_sim_debug_data); + } } static void debug_data_insert(SimDebugData *debug_data, SimDebugElement *elem) @@ -1099,11 +1120,11 @@ static void debug_data_insert(SimDebugData *debug_data, SimDebugElement *elem) BLI_ghash_insert(debug_data->gh, elem, elem); } -void BKE_sim_debug_data_add_element(SimDebugData *debug_data, int type, const float v1[3], const float v2[3], float r, float g, float b, const char *category, unsigned int hash) +void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[3], float r, float g, float b, const char *category, unsigned int hash) { unsigned int category_hash = BLI_ghashutil_strhash_p(category); SimDebugElement *elem; - if (!debug_data) + if (!_sim_debug_data) return; elem = MEM_callocN(sizeof(SimDebugElement), "sim debug data element"); @@ -1116,54 +1137,44 @@ void BKE_sim_debug_data_add_element(SimDebugData *debug_data, int type, const fl copy_v3_v3(elem->v1, v1); copy_v3_v3(elem->v2, v2); - debug_data_insert(debug_data, elem); + debug_data_insert(_sim_debug_data, elem); } -void BKE_sim_debug_data_remove_element(SimDebugData *debug_data, unsigned int hash) +void BKE_sim_debug_data_remove_element(unsigned int hash) { SimDebugElement dummy; - if (!debug_data) + if (!_sim_debug_data) return; dummy.hash = hash; - BLI_ghash_remove(debug_data->gh, &dummy, NULL, debug_element_free); + BLI_ghash_remove(_sim_debug_data->gh, &dummy, NULL, debug_element_free); } -void BKE_sim_debug_data_clear(SimDebugData *debug_data) +void BKE_sim_debug_data_clear(void) { - if (!debug_data) + if (!_sim_debug_data) return; - if (debug_data->gh) - BLI_ghash_clear(debug_data->gh, NULL, debug_element_free); + if (_sim_debug_data->gh) + BLI_ghash_clear(_sim_debug_data->gh, NULL, debug_element_free); } -void BKE_sim_debug_data_clear_category(SimDebugData *debug_data, const char *category) +void BKE_sim_debug_data_clear_category(const char *category) { int category_hash = (int)BLI_ghashutil_strhash_p(category); - if (!debug_data) + if (!_sim_debug_data) return; - if (debug_data->gh) { + if (_sim_debug_data->gh) { GHashIterator iter; - BLI_ghashIterator_init(&iter, debug_data->gh); + BLI_ghashIterator_init(&iter, _sim_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); + BLI_ghash_remove(_sim_debug_data->gh, elem, NULL, debug_element_free); } } } - -void BKE_sim_debug_data_free(SimDebugData *debug_data) -{ - if (!debug_data) - return; - - if (debug_data->gh) - BLI_ghash_free(debug_data->gh, NULL, debug_element_free); - MEM_freeN(debug_data); -} |