Replaced most STL std::vector with btAlignedObjectArray.

Same interface but less features (push_back, pop_back, clear, size, [] etc).
To prepare for SIMD/SSE code: Added 		#define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a
This commit is contained in:
ejcoumans
2006-12-06 04:22:36 +00:00
parent 2f21514f3d
commit bf591b44ec
29 changed files with 363 additions and 72 deletions

View File

@@ -121,8 +121,10 @@ void btCollisionWorld::addCollisionObject(btCollisionObject* collisionObject,sho
void btCollisionWorld::performDiscreteCollisionDetection(btDispatcherInfo& dispatchInfo)
void btCollisionWorld::performDiscreteCollisionDetection()
{
btDispatcherInfo& dispatchInfo = getDispatchInfo();
BEGIN_PROFILE("performDiscreteCollisionDetection");

View File

@@ -173,7 +173,7 @@ public:
struct ClosestRayResultCallback : public RayResultCallback
{
ClosestRayResultCallback(btVector3 rayFromWorld,btVector3 rayToWorld)
ClosestRayResultCallback(const btVector3& rayFromWorld,const btVector3& rayToWorld)
:m_rayFromWorld(rayFromWorld),
m_rayToWorld(rayToWorld),
m_collisionObject(0)
@@ -237,7 +237,7 @@ public:
void removeCollisionObject(btCollisionObject* collisionObject);
virtual void performDiscreteCollisionDetection( btDispatcherInfo& dispatchInfo);
virtual void performDiscreteCollisionDetection();
btDispatcherInfo& getDispatchInfo()
{

View File

@@ -23,6 +23,7 @@ subject to the following restrictions:
#include "LinearMath/btMatrix3x3.h"
#include <vector>
#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
#include "LinearMath/btAlignedObjectArray.h"
class btOptimizedBvh;
@@ -30,8 +31,8 @@ class btOptimizedBvh;
/// This allows for concave collision objects. This is more general then the Static Concave btTriangleMeshShape.
class btCompoundShape : public btCollisionShape
{
std::vector<btTransform> m_childTransforms;
std::vector<btCollisionShape*> m_childShapes;
btAlignedObjectArray<btTransform> m_childTransforms;
btAlignedObjectArray<btCollisionShape*> m_childShapes;
btVector3 m_localAabbMin;
btVector3 m_localAabbMax;

View File

@@ -22,6 +22,7 @@ subject to the following restrictions:
btConvexHullShape ::btConvexHullShape (const float* points,int numPoints,int stride)
{
m_points.resize(numPoints);
unsigned char* pointsBaseAddress = (unsigned char*)points;
for (int i=0;i<numPoints;i++)

View File

@@ -19,7 +19,8 @@ subject to the following restrictions:
#include "btPolyhedralConvexShape.h"
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
#include <vector>
#include "LinearMath/btAlignedObjectArray.h"
///ConvexHullShape implements an implicit (getSupportingVertex) Convex Hull of a Point Cloud (vertices)
///No connectivity is needed. localGetSupportingVertex iterates linearly though all vertices.
@@ -27,7 +28,7 @@ subject to the following restrictions:
///(memory is much slower then the cpu)
class btConvexHullShape : public btPolyhedralConvexShape
{
std::vector<btPoint3> m_points;
btAlignedObjectArray<btPoint3> m_points;
public:
///this constructor optionally takes in a pointer to points. Each point is assumed to be 3 consecutive float (x,y,z), the striding defines the number of bytes between each point, in memory.

View File

@@ -18,6 +18,11 @@ subject to the following restrictions:
#include "LinearMath/btAabbUtil2.h"
btOptimizedBvh::btOptimizedBvh() :m_rootNode1(0), m_numNodes(0)
{
}
void btOptimizedBvh::build(btStridingMeshInterface* triangles)
{

View File

@@ -15,9 +15,17 @@ subject to the following restrictions:
#ifndef OPTIMIZED_BVH_H
#define OPTIMIZED_BVH_H
#include "LinearMath/btVector3.h"
//http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/vclrf__m128.asp
#include <vector>
class btStridingMeshInterface;
/// btOptimizedBvhNode contains both internal and leaf node information.
@@ -26,7 +34,7 @@ class btStridingMeshInterface;
/// and storing aabbmin/max as quantized integers.
/// 'subpart' doesn't need an integer either. It allows to re-use graphics triangle
/// meshes stored in a non-uniform way (like batches/subparts of triangle-fans
struct btOptimizedBvhNode
ATTRIBUTE_ALIGNED16 (struct btOptimizedBvhNode)
{
btVector3 m_aabbMin;
@@ -52,12 +60,23 @@ public:
virtual void processNode(const btOptimizedBvhNode* node) = 0;
};
typedef std::vector<btOptimizedBvhNode> NodeArray;
#include "LinearMath/btAlignedAllocator.h"
#include "LinearMath/btAlignedObjectArray.h"
//typedef std::vector< unsigned , allocator_type > container_type;
const unsigned size = (1 << 20);
typedef btAlignedAllocator< btOptimizedBvhNode , size > allocator_type;
//typedef btAlignedObjectArray<btOptimizedBvhNode, allocator_type> NodeArray;
typedef btAlignedObjectArray<btOptimizedBvhNode> NodeArray;
///OptimizedBvh store an AABB tree that can be quickly traversed on CPU (and SPU,GPU in future)
class btOptimizedBvh
{
NodeArray m_leafNodes;
btOptimizedBvhNode* m_rootNode1;
btOptimizedBvhNode* m_contiguousNodes;
@@ -65,10 +84,11 @@ class btOptimizedBvh
int m_numNodes;
NodeArray m_leafNodes;
public:
btOptimizedBvh() :m_rootNode1(0), m_numNodes(0) { }
btOptimizedBvh();
virtual ~btOptimizedBvh();
void build(btStridingMeshInterface* triangles);

View File

@@ -17,7 +17,8 @@ subject to the following restrictions:
#define BT_TRIANGLE_BUFFER_H
#include "btTriangleCallback.h"
#include <vector>
//#include <vector>
#include "LinearMath/btAlignedObjectArray.h"
struct btTriangle
{
@@ -32,7 +33,7 @@ struct btTriangle
class btTriangleBuffer : public btTriangleCallback
{
std::vector<btTriangle> m_triangleBuffer;
btAlignedObjectArray<btTriangle> m_triangleBuffer;
public:

View File

@@ -17,7 +17,7 @@ subject to the following restrictions:
#define BT_TRIANGLE_INDEX_VERTEX_ARRAY_H
#include "btStridingMeshInterface.h"
#include <vector>
#include <LinearMath/btAlignedObjectArray.h>
///IndexedMesh indexes into existing vertex and index arrays, in a similar way OpenGL glDrawElements
///instead of the number of indices, we pass the number of triangles
@@ -38,7 +38,7 @@ struct btIndexedMesh
///So keep those arrays around during the lifetime of this btTriangleIndexVertexArray.
class btTriangleIndexVertexArray : public btStridingMeshInterface
{
std::vector<btIndexedMesh> m_indexedMeshes;
btAlignedObjectArray<btIndexedMesh> m_indexedMeshes;
public:

View File

@@ -18,9 +18,8 @@ subject to the following restrictions:
#define TRIANGLE_MESH_H
#include "BulletCollision/CollisionShapes/btStridingMeshInterface.h"
#include <vector>
#include <LinearMath/btVector3.h>
#include "LinearMath/btAlignedObjectArray.h"
struct btMyTriangle
{
btVector3 m_vert0;
@@ -31,8 +30,7 @@ struct btMyTriangle
///TriangleMesh provides storage for a concave triangle mesh. It can be used as data for the btTriangleMeshShape.
class btTriangleMesh : public btStridingMeshInterface
{
std::vector<btMyTriangle> m_triangles;
btAlignedObjectArray<btMyTriangle> m_triangles;
public:
btTriangleMesh ();