From 98f5477abac38b807e22b4a699b6abdf200bd9db Mon Sep 17 00:00:00 2001 From: imdex Date: Sat, 15 Jul 2017 04:11:01 +0300 Subject: [PATCH] Small refactoring --- .../tri-colliderknoopc/dTriColliderCommon.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/code/engine/xrPhysics/tri-colliderknoopc/dTriColliderCommon.h b/code/engine/xrPhysics/tri-colliderknoopc/dTriColliderCommon.h index 5d339c187..6c75066b2 100644 --- a/code/engine/xrPhysics/tri-colliderknoopc/dTriColliderCommon.h +++ b/code/engine/xrPhysics/tri-colliderknoopc/dTriColliderCommon.h @@ -9,12 +9,21 @@ extern xr_vector gl_cl_tries_state; // extern xr_vector::iterator I,E,B ; -#define CONTACT(Ptr, Stride) ((dContactGeom*)(((char*)Ptr) + (Stride))) +// NOTE: stride is sizeof(dContact) * N, where N is [0, ...) + +inline dContactGeom* CONTACT(dContactGeom* ptr, const int stride) { + const size_t count = stride / sizeof(dContact); + dContact* contact = (dContact*)(uintptr_t(ptr) - uintptr_t(offsetof(dContact, geom))); + return &(contact[count]).geom; +} //#define SURFACE(Ptr, Stride) ((dSurfaceParameters*) (((char*)Ptr) + //(Stride-sizeof(dSurfaceParameters)))) -#define SURFACE(Ptr, Stride) \ - ((dSurfaceParameters*)(((char*)Ptr) + \ - (Stride - offsetof(dContact, geom) + offsetof(dContact, surface)))) +inline dSurfaceParameters* SURFACE(dContactGeom* ptr, const int stride) { + const size_t count = stride / sizeof(dContact); + dContact* contact = (dContact*)(uintptr_t(ptr) - uintptr_t(offsetof(dContact, geom))); + return &(contact[count]).surface; +} + #define NUMC_MASK (0xffff) #define M_SIN_PI_3 REAL(0.8660254037844386467637231707529362)