Nicer hashing functionality for sim debugging using a variadic macro
authorLukas Tönne <lukas.toenne@gmail.com>
Sun, 16 Nov 2014 13:59:33 +0000 (14:59 +0100)
committerLukas Tönne <lukas.toenne@gmail.com>
Tue, 20 Jan 2015 08:30:08 +0000 (09:30 +0100)
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

source/blender/blenkernel/BKE_effect.h
source/blender/blenkernel/intern/cloth.c
source/blender/blenkernel/intern/collision.c
source/blender/blenkernel/intern/effect.c
source/blender/physics/intern/BPH_mass_spring.cpp
source/blender/physics/intern/hair_volume.cpp
source/blender/physics/intern/implicit.h

index 6688cd33e842fb66819c6a4985635dc312485381..c85145470b177bae7559f192123cc9c4665273fe 100644 (file)
  *  \since March 2001
  *  \author nzc
  */
+
 #include "DNA_modifier_types.h"
 
+#include "BLI_utildefines.h"
+
 struct Object;
 struct Scene;
 struct Effect;
@@ -138,9 +141,35 @@ int get_effector_data(struct EffectorCache *eff, struct EffectorData *efd, struc
 
 /* ======== Simulation Debugging ======== */
 
+#define SIM_DEBUG_HASH_BASE 5381
+
+unsigned int BKE_sim_debug_data_hash(int i);
+unsigned int BKE_sim_debug_data_hash_combine(unsigned int kx, unsigned int ky);
+
+/* _VA_SIM_DEBUG_HASH#(i, ...): combined hash value of multiple integers */
+/* internal helpers*/
+#define _VA_SIM_DEBUG_HASH1(a) \
+       (BKE_sim_debug_data_hash(a))
+#define _VA_SIM_DEBUG_HASH2(a, b) \
+       (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH1(b)))
+#define _VA_SIM_DEBUG_HASH3(a, b, c) \
+       (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH2(b, c)))
+#define _VA_SIM_DEBUG_HASH4(a, b, c, d) \
+       (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH3(b, c, d)))
+#define _VA_SIM_DEBUG_HASH5(a, b, c, d, e) \
+       (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH4(b, c, d, e)))
+#define _VA_SIM_DEBUG_HASH6(a, b, c, d, e, f) \
+       (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH5(b, c, d, e, f)))
+#define _VA_SIM_DEBUG_HASH7(a, b, c, d, e, f, g) \
+       (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH6(b, c, d, e, f, g)))
+#define _VA_SIM_DEBUG_HASH8(a, b, c, d, e, f, g, h) \
+       (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH7(b, c, d, e, f, g, h)))
+
+#define SIM_DEBUG_HASH(...) VA_NARGS_CALL_OVERLOAD(_VA_SIM_DEBUG_HASH, __VA_ARGS__)
+
 typedef struct SimDebugElement {
-       int category_hash;
-       int hash;
+       unsigned int category_hash;
+       unsigned int hash;
        
        int type;
        float color[3];
@@ -160,11 +189,32 @@ 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, const char *category, int hash);
-void BKE_sim_debug_data_add_circle(struct SimDebugData *debug_data, const float p[3], const float radius, 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_add_element(struct 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_remove_element(struct SimDebugData *debug_data, unsigned int hash);
+
+#define BKE_sim_debug_data_add_dot(debug_data, 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__)); \
+}
+
+#define BKE_sim_debug_data_add_circle(debug_data, 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__)); \
+}
+
+#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_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_remove(debug_data, ...) \
+       BKE_sim_debug_data_remove_element(debug_data, 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);
index 09239a79d6c152d6c106bfc99807be3c23ed9a89..2b4cbf62bb8569b03d2c5cf08e354f9fbea7d856 100644 (file)
@@ -61,36 +61,6 @@ static void cloth_update_springs( ClothModifierData *clmd );
 static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm );
 static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm );
 
-/* ==== hash functions for debugging ==== */
-BLI_INLINE unsigned int hash_int_2d(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
-}
-
-BLI_INLINE int hash_vertex(int type, int vertex)
-{
-       return hash_int_2d((unsigned int)type, (unsigned int)vertex);
-}
-/* ================ */
-
 /******************************************************************************
  *
  * External interface called by modifier.c clothModifier functions.
@@ -1129,16 +1099,16 @@ static void cloth_update_bending_targets(ClothModifierData *clmd)
                        float a[3], b[3];
                        
                        copy_v3_v3(a, cloth->verts[spring->kl].x);
-//                     BKE_sim_debug_data_add_dot(clmd->debug_data, cloth_vert ? cloth_vert->x : key->co, 1, 1, 0, "frames", hash_vertex(8246, hash_int_2d(p, k)));
+//                     BKE_sim_debug_data_add_dot(clmd->debug_data, cloth_vert ? cloth_vert->x : key->co, 1, 1, 0, "frames", 8246, p, k);
                        
                        mul_v3_v3fl(b, hair_frame[0], clmd->sim_parms->avg_spring_len);
-                       BKE_sim_debug_data_add_vector(clmd->debug_data, a, b, 1, 0, 0, "frames", hash_vertex(8247, hash_int_2d(spring->kl, spring->mn)));
+                       BKE_sim_debug_data_add_vector(clmd->debug_data, a, b, 1, 0, 0, "frames", 8247, spring->kl, spring->mn);
                        
                        mul_v3_v3fl(b, hair_frame[1], clmd->sim_parms->avg_spring_len);
-                       BKE_sim_debug_data_add_vector(clmd->debug_data, a, b, 0, 1, 0, "frames", hash_vertex(8248, hash_int_2d(spring->kl, spring->mn)));
+                       BKE_sim_debug_data_add_vector(clmd->debug_data, a, b, 0, 1, 0, "frames", 8248, spring->kl, spring->mn);
                        
                        mul_v3_v3fl(b, hair_frame[2], clmd->sim_parms->avg_spring_len);
-                       BKE_sim_debug_data_add_vector(clmd->debug_data, a, b, 0, 0, 1, "frames", hash_vertex(8249, hash_int_2d(spring->kl, spring->mn)));
+                       BKE_sim_debug_data_add_vector(clmd->debug_data, a, b, 0, 0, 1, "frames", 8249, spring->kl, spring->mn);
                }
 #endif
                
index 0690d0fbd8f5c1ed61d45f2ea0ca03f7aac2cf28..92cd1ee061126a70f745a85ebaada34a1fa3597e 100644 (file)
 #endif
 
 
-/* ==== hash functions for debugging ==== */
-static unsigned int hash_int_2d(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
-}
-
-#if 0
-static int hash_vertex(int type, int vertex)
-{
-       return hash_int_2d((unsigned int)type, (unsigned int)vertex);
-}
-#endif
-
-static int hash_collpair(int type, CollPair *collpair)
-{
-       return hash_int_2d((unsigned int)type, hash_int_2d((unsigned int)collpair->face1, (unsigned int)collpair->face2));
-}
-/* ================ */
-
 /***********************************
 Collision modifier code start
 ***********************************/
@@ -1028,10 +991,9 @@ 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, "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));
+                       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);
                }
                /********/
 
@@ -1061,21 +1023,7 @@ static bool cloth_points_collision_response_static(ClothModifierData *clmd, Coll
                                bounce = 0.0f;
                                mul_v3_v3fl(impulse, collpair->normal, repulse);
                        }
-#if 0
-                       {
-                               float d[3], md[3];
-                               mul_v3_v3fl(d, collpair->normal, -collpair->distance);
-                               mul_v3_v3fl(md, collpair->normal, -margin_distance);
-                               BKE_sim_debug_data_add_vector(clmd->debug_data, collpair->pa, d, 1, 1, 0, "collision", hash_collpair(5, collpair));
-                               BKE_sim_debug_data_add_vector(clmd->debug_data, collpair->pa, md, 0, 1, 1, "collision", hash_collpair(6, collpair));
-                               
-                               BKE_sim_debug_data_add_line(clmd->debug_data, collmd->current_x[collpair->bp1].co, collmd->current_x[collpair->bp2].co, 0, 0, 1, "collision", hash_collpair(85, collpair));
-                               BKE_sim_debug_data_add_line(clmd->debug_data, collmd->current_x[collpair->bp2].co, collmd->current_x[collpair->bp3].co, 0, 0, 1, "collision", hash_collpair(86, collpair));
-                               BKE_sim_debug_data_add_line(clmd->debug_data, collmd->current_x[collpair->bp3].co, collmd->current_x[collpair->bp1].co, 0, 0, 1, "collision", hash_collpair(87, collpair));
-                       }
-#endif
                        cloth1->verts[collpair->ap1].impulse_count++;
-//                     BKE_sim_debug_data_add_vector(clmd->debug_data, collpair->pa, impulse, 1.0, 1.0, 1.0, "collision", hash_collpair(873, collpair));
                        
                        result = true;
                }
index b07d972b7701049d4ad53f1b55d11df0307576ff..e43bde7ea383b51a21340080e49c5de4621e19b7 100644 (file)
@@ -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)
index 7a3660d173457dee15ffb072fb98f8e35ee03ebe..67b2aec7863494486686b4958f03fde15a295337 100644 (file)
@@ -242,20 +242,6 @@ static void cloth_setup_constraints(ClothModifierData *clmd, ColliderContacts *c
                        \r
                        BPH_mass_spring_add_constraint_ndof2(data, v, collpair->normal, impulse);\r
                        ++verts[v].impulse_count;\r
-                       \r
-                       BKE_sim_debug_data_add_dot(clmd->debug_data, collpair->pa, 0, 1, 0, "collision", hash_collpair(936, collpair));\r
-//                     BKE_sim_debug_data_add_dot(clmd->debug_data, collpair->pb, 1, 0, 0, "collision", hash_collpair(937, collpair));\r
-//                     BKE_sim_debug_data_add_line(clmd->debug_data, collpair->pa, collpair->pb, 0.7, 0.7, 0.7, "collision", hash_collpair(938, collpair));\r
-                       \r
-#if 0\r
-                       { /* DEBUG */\r
-                               float nor[3];\r
-                               mul_v3_v3fl(nor, collpair->normal, -collpair->distance);\r
-                               BKE_sim_debug_data_add_vector(clmd->debug_data, collpair->pa, nor, 1, 1, 0, "collision", hash_collpair(939, collpair));\r
-//                             BKE_sim_debug_data_add_vector(clmd->debug_data, collpair->pb, impulse, 1, 1, 0, "collision", hash_collpair(940, collpair));\r
-//                             BKE_sim_debug_data_add_vector(clmd->debug_data, collpair->pb, collpair->normal, 1, 1, 0, "collision", hash_collpair(941, collpair));\r
-                       }\r
-#endif\r
                }\r
        }\r
 }\r
@@ -428,14 +414,14 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
                        BPH_mass_spring_get_motion_state(data, s->kl, x_kl, v);\r
                        BPH_mass_spring_get_motion_state(data, s->mn, x_mn, v);\r
                        \r
-                       BKE_sim_debug_data_add_dot(clmd->debug_data, x_kl, 0.9, 0.9, 0.9, "target", hash_vertex(7980, s->kl));\r
-                       BKE_sim_debug_data_add_line(clmd->debug_data, x_kl, x_mn, 0.8, 0.8, 0.8, "target", hash_vertex(7981, s->kl));\r
+                       BKE_sim_debug_data_add_dot(clmd->debug_data, x_kl, 0.9, 0.9, 0.9, "target", 7980, s->kl);\r
+                       BKE_sim_debug_data_add_line(clmd->debug_data, x_kl, x_mn, 0.8, 0.8, 0.8, "target", 7981, s->kl);\r
                        \r
                        copy_v3_v3(d, s->target);\r
-                       BKE_sim_debug_data_add_vector(clmd->debug_data, x_kl, d, 0.8, 0.8, 0.2, "target", hash_vertex(7982, s->kl));\r
+                       BKE_sim_debug_data_add_vector(clmd->debug_data, x_kl, d, 0.8, 0.8, 0.2, "target", 7982, s->kl);\r
                        \r
 //                     copy_v3_v3(d, s->target_ij);\r
-//                     BKE_sim_debug_data_add_vector(clmd->debug_data, x, d, 1, 0.4, 0.4, "target", hash_vertex(7983, s->kl));\r
+//                     BKE_sim_debug_data_add_vector(clmd->debug_data, x, d, 1, 0.4, 0.4, "target", 7983, s->kl);\r
                }\r
 #endif\r
 #endif\r
@@ -745,13 +731,13 @@ static void cloth_continuum_step(ClothModifierData *clmd, float dt)
                                        \r
                                        BPH_hair_volume_grid_interpolate(grid, x, &gdensity, gvel, gvel_smooth, NULL, NULL);\r
                                        \r
-//                                     BKE_sim_debug_data_add_circle(clmd->debug_data, x, gdensity, 0.7, 0.3, 1, "grid density", hash_int_2d(hash_int_2d(i, j), 3111));\r
+//                                     BKE_sim_debug_data_add_circle(clmd->debug_data, x, gdensity, 0.7, 0.3, 1, "grid density", i, j, 3111);\r
                                        if (!is_zero_v3(gvel) || !is_zero_v3(gvel_smooth)) {\r
                                                float dvel[3];\r
                                                sub_v3_v3v3(dvel, gvel_smooth, gvel);\r
-//                                             BKE_sim_debug_data_add_vector(clmd->debug_data, x, gvel, 0.4, 0, 1, "grid velocity", hash_int_2d(hash_int_2d(i, j), 3112));\r
-//                                             BKE_sim_debug_data_add_vector(clmd->debug_data, x, gvel_smooth, 0.6, 1, 1, "grid velocity", hash_int_2d(hash_int_2d(i, j), 3113));\r
-                                               BKE_sim_debug_data_add_vector(clmd->debug_data, x, dvel, 0.4, 1, 0.7, "grid velocity", hash_int_2d(hash_int_2d(i, j), 3114));\r
+//                                             BKE_sim_debug_data_add_vector(clmd->debug_data, x, gvel, 0.4, 0, 1, "grid velocity", i, j, 3112);\r
+//                                             BKE_sim_debug_data_add_vector(clmd->debug_data, x, gvel_smooth, 0.6, 1, 1, "grid velocity", i, j, 3113);\r
+                                               BKE_sim_debug_data_add_vector(clmd->debug_data, x, dvel, 0.4, 1, 0.7, "grid velocity", i, j, 3114);\r
 #if 0\r
                                                if (gdensity > 0.0f) {\r
                                                        float col0[3] = {0.0, 0.0, 0.0};\r
@@ -759,9 +745,9 @@ static void cloth_continuum_step(ClothModifierData *clmd, float dt)
                                                        float col[3];\r
                                                        \r
                                                        interp_v3_v3v3(col, col0, col1, CLAMPIS(gdensity * clmd->sim_parms->density_strength, 0.0, 1.0));\r
-//                                                     BKE_sim_debug_data_add_circle(clmd->debug_data, x, gdensity * clmd->sim_parms->density_strength, 0, 1, 0.4, "grid velocity", hash_int_2d(hash_int_2d(i, j), 3115));\r
-//                                                     BKE_sim_debug_data_add_dot(clmd->debug_data, x, col[0], col[1], col[2], "grid velocity", hash_int_2d(hash_int_2d(i, j), 3115));\r
-                                                       BKE_sim_debug_data_add_circle(clmd->debug_data, x, 0.01f, col[0], col[1], col[2], "grid velocity", hash_int_2d(hash_int_2d(i, j), 3115));\r
+//                                                     BKE_sim_debug_data_add_circle(clmd->debug_data, x, gdensity * clmd->sim_parms->density_strength, 0, 1, 0.4, "grid velocity", i, j, 3115);\r
+//                                                     BKE_sim_debug_data_add_dot(clmd->debug_data, x, col[0], col[1], col[2], "grid velocity", i, j, 3115);\r
+                                                       BKE_sim_debug_data_add_circle(clmd->debug_data, x, 0.01f, col[0], col[1], col[2], "grid velocity", i, j, 3115);\r
                                                }\r
 #endif\r
                                        }\r
@@ -903,12 +889,6 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
                }\r
        }\r
        \r
-       if (clmd->debug_data) {\r
-               for (i = 0; i < numverts; i++) {\r
-//                     BKE_sim_debug_data_add_dot(clmd->debug_data, verts[i].x, 1.0f, 0.1f, 1.0f, "points", hash_vertex(583, i));\r
-               }\r
-       }\r
-       \r
        while (step < tf) {\r
                ImplicitSolverResult result;\r
                \r
@@ -967,12 +947,6 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
                        }\r
                        \r
                        BPH_mass_spring_get_motion_state(id, i, verts[i].txold, NULL);\r
-                       \r
-//                     if (!(verts[i].flags & CLOTH_VERT_FLAG_PINNED) && i > 0) {\r
-//                             BKE_sim_debug_data_add_line(clmd->debug_data, id->X[i], id->X[i-1], 0.6, 0.3, 0.3, "hair", hash_vertex(4892, i));\r
-//                             BKE_sim_debug_data_add_line(clmd->debug_data, id->Xnew[i], id->Xnew[i-1], 1, 0.5, 0.5, "hair", hash_vertex(4893, i));\r
-//                     }\r
-//                     BKE_sim_debug_data_add_vector(clmd->debug_data, id->X[i], id->V[i], 0, 0, 1, "velocity", hash_vertex(3158, i));\r
                }\r
                \r
                /* free contact points */\r
index b08eef053920c7e3cfedb5ada7cbdd984360bc59..c8f9edb3a987d9b491aa8c01427350c25df2f915 100644 (file)
@@ -412,14 +412,14 @@ BLI_INLINE void hair_volume_add_segment_2D(HairGrid *grid,
                                grid_to_world(grid, x3w, x3);
                                
                                if (vert_k->samples > 0)
-                                       BKE_sim_debug_data_add_circle(debug_data, wloc, 0.01f, 1.0, 1.0, 0.3, "grid", hash_vertex(2525, hash_int_2d(debug_i, hash_int_2d(j, k))));
+                                       BKE_sim_debug_data_add_circle(debug_data, wloc, 0.01f, 1.0, 1.0, 0.3, "grid", 2525, debug_i, j, k);
                                
                                if (grid->debug_value) {
-                                       BKE_sim_debug_data_add_dot(debug_data, wloc, 1, 0, 0, "grid", hash_vertex(93, hash_int_2d(debug_i, hash_int_2d(j, k))));
-                                       BKE_sim_debug_data_add_dot(debug_data, x2w, 0.1, 0.1, 0.7, "grid", hash_vertex(649, hash_int_2d(debug_i, hash_int_2d(j, k))));
-                                       BKE_sim_debug_data_add_line(debug_data, wloc, x2w, 0.3, 0.8, 0.3, "grid", hash_vertex(253, hash_int_2d(debug_i, hash_int_2d(j, k))));
-                                       BKE_sim_debug_data_add_line(debug_data, wloc, x3w, 0.8, 0.3, 0.3, "grid", hash_vertex(254, hash_int_2d(debug_i, hash_int_2d(j, k))));
-//                                     BKE_sim_debug_data_add_circle(debug_data, x2w, len_v3v3(wloc, x2w), 0.2, 0.7, 0.2, "grid", hash_vertex(255, hash_int_2d(i, hash_int_2d(j, k))));
+                                       BKE_sim_debug_data_add_dot(debug_data, wloc, 1, 0, 0, "grid", 93, debug_i, j, k);
+                                       BKE_sim_debug_data_add_dot(debug_data, x2w, 0.1, 0.1, 0.7, "grid", 649, debug_i, j, k);
+                                       BKE_sim_debug_data_add_line(debug_data, wloc, x2w, 0.3, 0.8, 0.3, "grid", 253, debug_i, j, k);
+                                       BKE_sim_debug_data_add_line(debug_data, wloc, x3w, 0.8, 0.3, 0.3, "grid", 254, debug_i, j, k);
+//                                     BKE_sim_debug_data_add_circle(debug_data, x2w, len_v3v3(wloc, x2w), 0.2, 0.7, 0.2, "grid", 255, i, j, k);
                                }
                        }
 #endif
@@ -707,7 +707,7 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float dt, float target_den
                                                interp_v3_v3v3(col, col0, coln, fac);
                                        }
                                        if (fac > 0.05f)
-                                               BKE_sim_debug_data_add_circle(grid->debug_data, wloc, 0.01f, col[0], col[1], col[2], "grid", hash_int_2d(5522, hash_int_2d(i, hash_int_2d(j, k))));
+                                               BKE_sim_debug_data_add_circle(grid->debug_data, wloc, 0.01f, col[0], col[1], col[2], "grid", 5522, i, j, k);
                                }
 #endif
                        }
@@ -859,12 +859,12 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float dt, float target_den
                                                        interp_v3_v3v3(col, col0, coln, fac);
                                                }
                                                if (fac > 0.05f)
-                                                       BKE_sim_debug_data_add_circle(grid->debug_data, wloc, 0.01f, col[0], col[1], col[2], "grid", hash_int_2d(5533, hash_int_2d(i, hash_int_2d(j, k))));
+                                                       BKE_sim_debug_data_add_circle(grid->debug_data, wloc, 0.01f, col[0], col[1], col[2], "grid", 5533, i, j, k);
                                                
                                                if (!is_margin) {
                                                        float dvel[3];
                                                        sub_v3_v3v3(dvel, vert->velocity_smooth, vert->velocity);
-//                                                     BKE_sim_debug_data_add_vector(grid->debug_data, wloc, dvel, 1, 1, 1, "grid", hash_int_2d(5566, hash_int_2d(i, hash_int_2d(j, k))));
+//                                                     BKE_sim_debug_data_add_vector(grid->debug_data, wloc, dvel, 1, 1, 1, "grid", 5566, i, j, k);
                                                }
                                                
                                                if (!is_margin) {
@@ -875,7 +875,7 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float dt, float target_den
                                                        
                                                        interp_v3_v3v3(col, col0, colp, d);
 //                                                     if (d > 0.05f)
-//                                                             BKE_sim_debug_data_add_dot(grid->debug_data, wloc, col[0], col[1], col[2], "grid", hash_int_2d(5544, hash_int_2d(i, hash_int_2d(j, k))));
+//                                                             BKE_sim_debug_data_add_dot(grid->debug_data, wloc, col[0], col[1], col[2], "grid", 5544, i, j, k);
                                                }
                                        }
                                }
index e4c90c22fb2bc7f36baa48e88320b5fa152ed005..7081dd507a99ab1fc93f1657068ebc12ce60c0ac 100644 (file)
@@ -74,41 +74,6 @@ BLI_INLINE void implicit_print_matrix_elem(float v)
     printf("%-8.3f", v);
 }
 
-/* ==== hash functions for debugging ==== */
-BLI_INLINE unsigned int hash_int_2d(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
-}
-
-BLI_INLINE int hash_vertex(int type, int vertex)
-{
-       return hash_int_2d((unsigned int)type, (unsigned int)vertex);
-}
-
-BLI_INLINE int hash_collpair(int type, CollPair *collpair)
-{
-       return hash_int_2d((unsigned int)type, hash_int_2d((unsigned int)collpair->face1, (unsigned int)collpair->face2));
-}
-/* ================ */
-
 void BPH_mass_spring_solver_debug_data(struct Implicit_Data *id, struct SimDebugData *debug_data);
 
 void BPH_mass_spring_set_vertex_mass(struct Implicit_Data *data, int index, float mass);