diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2014-11-16 16:59:33 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2015-01-20 11:30:08 +0300 |
commit | 674c98bd06a8d3752d750fb659b98ff5b9a238d8 (patch) | |
tree | 03509daa8e1537fa95c125b86a5fcf44d5197652 /source/blender/blenkernel/intern/effect.c | |
parent | 52384179f4c5153a62d711d326a7f6a877508dbb (diff) |
Nicer hashing functionality for sim debugging using a variadic macro
to support multiple hash identifiers.
Using explicit hashing functions for every sim debug call defeats the
purpose of having a quick feedback system. Now this can be done simply
by passing an arbitrary number of hash inputs (integers) at the end of
the function calls, which are then combined by a system of variadic
macros (based on the ELEM feature). Up to 8 identifiers are supported
currently, but more could be added easily if needed.
Conflicts:
source/blender/blenkernel/intern/particle_system.c
source/blender/physics/intern/BPH_mass_spring.cpp
Diffstat (limited to 'source/blender/blenkernel/intern/effect.c')
-rw-r--r-- | source/blender/blenkernel/intern/effect.c | 101 |
1 files changed, 35 insertions, 66 deletions
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index b07d972b770..e43bde7ea38 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -30,6 +30,7 @@ */ #include <stddef.h> +#include <stdarg.h> #include <math.h> #include <stdlib.h> @@ -1028,6 +1029,34 @@ void pdDoEffectors(ListBase *effectors, ListBase *colliders, EffectorWeights *we /* ======== Simulation Debugging ======== */ +unsigned int BKE_sim_debug_data_hash(int i) +{ + return BLI_ghashutil_uinthash((unsigned int)i); +} + +unsigned int BKE_sim_debug_data_hash_combine(unsigned int kx, unsigned int ky) +{ +#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) + + unsigned int a, b, c; + + a = b = c = 0xdeadbeef + (2 << 2) + 13; + a += kx; + b += ky; + + c ^= b; c -= rot(b,14); + a ^= c; a -= rot(c,11); + b ^= a; b -= rot(a,25); + c ^= b; c -= rot(b,16); + a ^= c; a -= rot(c,4); + b ^= a; b -= rot(a,14); + c ^= b; c -= rot(b,24); + + return c; + +#undef rot +} + static unsigned int debug_element_hash(const void *key) { const SimDebugElement *elem = key; @@ -1070,87 +1099,27 @@ 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, 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; - elem->color[2] = b; - copy_v3_v3(elem->v1, p); - - debug_data_insert(debug_data, elem); -} - -void BKE_sim_debug_data_add_circle(struct SimDebugData *debug_data, const float p[3], float radius, 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_CIRCLE; - elem->category_hash = category_hash; - elem->hash = hash; - elem->color[0] = r; - elem->color[1] = g; - elem->color[2] = b; - copy_v3_v3(elem->v1, p); - elem->v2[0] = radius; - elem->v2[1] = elem->v2[2] = 0.0f; - - 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, 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; - elem->color[2] = b; - copy_v3_v3(elem->v1, p1); - copy_v3_v3(elem->v2, p2); - - 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, const char *category, int hash) +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) { - int category_hash = (int)BLI_ghashutil_strhash_p(category); + unsigned int category_hash = 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->type = type; elem->category_hash = category_hash; elem->hash = hash; elem->color[0] = r; elem->color[1] = g; elem->color[2] = b; - copy_v3_v3(elem->v1, p); - copy_v3_v3(elem->v2, d); + copy_v3_v3(elem->v1, v1); + copy_v3_v3(elem->v2, v2); debug_data_insert(debug_data, elem); } -void BKE_sim_debug_data_remove(SimDebugData *debug_data, int hash) +void BKE_sim_debug_data_remove_element(SimDebugData *debug_data, unsigned int hash) { SimDebugElement dummy; if (!debug_data) |