From 7b87b2ca04b6ca5fa2754a53fae2babbe473112d Mon Sep 17 00:00:00 2001 From: Xottab-DUTY Date: Sat, 12 Aug 2017 23:12:01 +0500 Subject: [PATCH] dTriColliderCommon.h: macro replaced with inline functions Thanks to Im-Dex. Imported from commit: https://github.com/Im-dex/xray-162/commit/98f5477abac38b807e22b4a699b6abdf200bd9db --- .../tri-colliderknoopc/dTriColliderCommon.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/xrPhysics/tri-colliderknoopc/dTriColliderCommon.h b/src/xrPhysics/tri-colliderknoopc/dTriColliderCommon.h index 1bf4056842a..127dd7b6a80 100644 --- a/src/xrPhysics/tri-colliderknoopc/dTriColliderCommon.h +++ b/src/xrPhysics/tri-colliderknoopc/dTriColliderCommon.h @@ -1,3 +1,4 @@ +#pragma once #ifndef D_TRI_COLLIDER_COMMON #define D_TRI_COLLIDER_COMMON @@ -7,11 +8,21 @@ extern xr_vector gl_cl_tries_state; -// extern xr_vector::iterator I,E,B ; +// 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; +} + +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 CONTACT(Ptr, Stride) ((dContactGeom*)(((char*)Ptr) + (Stride))) -//#define SURFACE(Ptr, Stride) ((dSurfaceParameters*)(((char*)Ptr) + (Stride - sizeof(dSurfaceParameters)))) -#define SURFACE(Ptr, Stride) ((dSurfaceParameters*) (((char*)Ptr) + (Stride - offsetof(dContact, geom) + offsetof(dContact, surface)))) #define NUMC_MASK (0xffff) #define M_SIN_PI_3 REAL(0.8660254037844386467637231707529362)