Skip to content

Commit

Permalink
moved more inline to cpp
Browse files Browse the repository at this point in the history
delay dll loading has big problem with inlines and global variables.
  • Loading branch information
JulioJerez committed Sep 21, 2024
1 parent 8da7ebc commit a8278f6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 32 deletions.
52 changes: 42 additions & 10 deletions newton-4.00/sdk/dCollision/ndShapeHeightfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ndShapeHeightfield::ndShapeHeightfield(
:ndShapeStaticMesh(m_heightField)
,m_minBox(ndVector::m_zero)
,m_maxBox(ndVector::m_zero)
,m_atributeMap(width * height)
,m_attributeMap(width * height)
,m_elevationMap(width * height)
,m_horizontalScale_x(horizontalScale_x)
,m_horizontalScale_z(horizontalScale_z)
Expand All @@ -55,11 +55,13 @@ ndShapeHeightfield::ndShapeHeightfield(
{
ndAssert(width >= 2);
ndAssert(height >= 2);
m_atributeMap.SetCount(width * height);
m_attributeMap.SetCount(width * height);
m_elevationMap.SetCount(width * height);

memset(&m_atributeMap[0], 0, sizeof(ndInt8) * m_atributeMap.GetCount());
memset(&m_elevationMap[0], 0, sizeof(ndReal) * m_elevationMap.GetCount());
//memset(&m_atributeMap[0], 0, sizeof(ndInt8) * m_atributeMap.GetCount());
//memset(&m_elevationMap[0], 0, sizeof(ndReal) * m_elevationMap.GetCount());
ndMemSet(&m_attributeMap[0], ndInt8(0), m_attributeMap.GetCount());
ndMemSet(&m_elevationMap[0], ndReal(0.0f), m_elevationMap.GetCount());

CalculateLocalObb();
}
Expand All @@ -68,6 +70,36 @@ ndShapeHeightfield::~ndShapeHeightfield(void)
{
}

ndArray<ndReal>& ndShapeHeightfield::GetElevationMap()
{
return m_elevationMap;
}

const ndArray<ndReal>& ndShapeHeightfield::GetElevationMap() const
{
return m_elevationMap;
}

ndArray<ndInt8>& ndShapeHeightfield::GetAttributeMap()
{
return m_attributeMap;
}

const ndArray<ndInt8>& ndShapeHeightfield::GetAttributeMap() const
{
return m_attributeMap;
}

ndInt32 ndShapeHeightfield::FastInt(ndFloat32 x) const
{
ndInt32 i = ndInt32(x);
if (ndFloat32(i) > x)
{
i--;
}
return i;
}

ndShapeInfo ndShapeHeightfield::GetShapeInfo() const
{
ndShapeInfo info(ndShapeStaticMesh::GetShapeInfo());
Expand All @@ -78,7 +110,7 @@ ndShapeInfo ndShapeHeightfield::GetShapeInfo() const
info.m_heightfield.m_horizonalScale_x = m_horizontalScale_x;
info.m_heightfield.m_horizonalScale_z = m_horizontalScale_z;
info.m_heightfield.m_elevation = (ndReal*)&m_elevationMap[0];
info.m_heightfield.m_atributes = (ndInt8*)&m_atributeMap[0];
info.m_heightfield.m_atributes = (ndInt8*)&m_attributeMap[0];

return info;
}
Expand Down Expand Up @@ -405,8 +437,8 @@ ndFloat32 ndShapeHeightfield::RayCast(ndRayCastNotify&, const ndVector& localP0,
// bail out at the first intersection and copy the data into the descriptor
ndAssert(normalOut.m_w == ndFloat32(0.0f));
contactOut.m_normal = normalOut.Normalize();
contactOut.m_shapeId0 = m_atributeMap[zIndex0 * m_width + xIndex0];
contactOut.m_shapeId1 = m_atributeMap[zIndex0 * m_width + xIndex0];
contactOut.m_shapeId0 = m_attributeMap[zIndex0 * m_width + xIndex0];
contactOut.m_shapeId1 = m_attributeMap[zIndex0 * m_width + xIndex0];

return t;
}
Expand Down Expand Up @@ -568,7 +600,7 @@ void ndShapeHeightfield::GetCollidingFaces(ndPolygonMeshDesc* const data) const
quad.m_triangle0.m_i0 = i2;
quad.m_triangle0.m_i1 = i1;
quad.m_triangle0.m_i2 = i0;
quad.m_triangle0.m_material = m_atributeMap[zStep + x];
quad.m_triangle0.m_material = m_attributeMap[zStep + x];
quad.m_triangle0.m_normal = normalIndex0;
quad.m_triangle0.m_normal_edge01 = normalIndex0;
quad.m_triangle0.m_normal_edge12 = normalIndex0;
Expand All @@ -579,7 +611,7 @@ void ndShapeHeightfield::GetCollidingFaces(ndPolygonMeshDesc* const data) const
quad.m_triangle1.m_i0 = i1;
quad.m_triangle1.m_i1 = i2;
quad.m_triangle1.m_i2 = i3;
quad.m_triangle1.m_material = m_atributeMap[zStep + x];
quad.m_triangle1.m_material = m_attributeMap[zStep + x];
quad.m_triangle1.m_normal = normalIndex1;
quad.m_triangle1.m_normal_edge01 = normalIndex1;
quad.m_triangle1.m_normal_edge12 = normalIndex1;
Expand Down Expand Up @@ -776,7 +808,7 @@ void ndShapeHeightfield::GetCollidingFaces(ndPolygonMeshDesc* const data) const

ndUnsigned64 ndShapeHeightfield::GetHash(ndUnsigned64 hash) const
{
hash = ndCRC64(&m_atributeMap[0], ndInt32(m_atributeMap.GetCount()) * ndInt32(sizeof(ndInt8)), hash);
hash = ndCRC64(&m_attributeMap[0], ndInt32(m_attributeMap.GetCount()) * ndInt32(sizeof(ndInt8)), hash);
hash = ndCRC64(&m_elevationMap[0], ndInt32(m_elevationMap.GetCount()) * ndInt32(sizeof(ndReal)), hash);
return hash;
}
28 changes: 6 additions & 22 deletions newton-4.00/sdk/dCollision/ndShapeHeightfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ class ndShapeHeightfield: public ndShapeStaticMesh
D_COLLISION_API ndShapeHeightfield(ndInt32 width, ndInt32 height, ndGridConstruction constructionMode,ndFloat32 horizontalScale_x, ndFloat32 horizontalScale_z);
D_COLLISION_API virtual ~ndShapeHeightfield();

ndArray<ndReal>& GetElevationMap();
const ndArray<ndReal>& GetElevationMap() const;
D_COLLISION_API ndArray<ndReal>& GetElevationMap();
D_COLLISION_API const ndArray<ndReal>& GetElevationMap() const;

D_COLLISION_API ndArray<ndInt8>& GetAttributeMap();
D_COLLISION_API const ndArray<ndInt8>& GetAttributeMap() const;

D_COLLISION_API void UpdateElevationMapAabb();
D_COLLISION_API void GetLocalAabb(const ndVector& p0, const ndVector& p1, ndVector& boxP0, ndVector& boxP1) const;
Expand All @@ -84,7 +87,7 @@ class ndShapeHeightfield: public ndShapeStaticMesh

ndVector m_minBox;
ndVector m_maxBox;
ndArray<ndInt8> m_atributeMap;
ndArray<ndInt8> m_attributeMap;
ndArray<ndReal> m_elevationMap;
ndFloat32 m_horizontalScale_x;
ndFloat32 m_horizontalScale_z;
Expand All @@ -102,24 +105,5 @@ class ndShapeHeightfield: public ndShapeStaticMesh
friend class ndContactSolver;
};

inline ndArray<ndReal>& ndShapeHeightfield::GetElevationMap()
{
return m_elevationMap;
}

inline const ndArray<ndReal>& ndShapeHeightfield::GetElevationMap() const
{
return m_elevationMap;
}

inline ndInt32 ndShapeHeightfield::FastInt(ndFloat32 x) const
{
ndInt32 i = ndInt32(x);
if (ndFloat32(i) > x)
{
i--;
}
return i;
}

#endif

0 comments on commit a8278f6

Please sign in to comment.