[Bf-blender-cvs] [371920f] temp_merge_gooseberry_hair: Nicer hashing functionality for sim debugging using a variadic macro to support multiple hash identifiers.
Lukas Tönne
noreply at git.blender.org
Mon Jan 19 20:51:10 CET 2015
Commit: 371920f07c7b5d0a20df952bc65cc80ab133a719
Author: Lukas Tönne
Date: Sun Nov 16 14:59:33 2014 +0100
Branches: temp_merge_gooseberry_hair
https://developer.blender.org/rB371920f07c7b5d0a20df952bc65cc80ab133a719
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
===================================================================
M source/blender/blenkernel/BKE_effect.h
M source/blender/blenkernel/intern/cloth.c
M source/blender/blenkernel/intern/collision.c
M source/blender/blenkernel/intern/effect.c
M source/blender/physics/intern/BPH_mass_spring.cpp
M source/blender/physics/intern/hair_volume.cpp
M source/blender/physics/intern/implicit.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_effect.h b/source/blender/blenkernel/BKE_effect.h
index 6688cd3..c851454 100644
--- a/source/blender/blenkernel/BKE_effect.h
+++ b/source/blender/blenkernel/BKE_effect.h
@@ -32,8 +32,11 @@
* \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);
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 09239a7..2b4cbf6 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -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
diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index 0690d0f..92cd1ee 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -61,43 +61,6 @@
#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, collm
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list