fix to get msvc 6 to compile, related to 'Allocate' template

This commit is contained in:
ejcoumans
2006-11-22 19:41:25 +00:00
parent 0757f1fe9e
commit 633bb02daa

View File

@@ -24,7 +24,6 @@ GJK-EPA collision solver by Nathanael Presson
Nov.2006 Nov.2006
*/ */
#include "btGjkEpa.h" #include "btGjkEpa.h"
#include <string.h> //for memset #include <string.h> //for memset
@@ -95,18 +94,6 @@ throw(object); }
#else #else
template <typename T> static inline void Raise(const T&) {} template <typename T> static inline void Raise(const T&) {}
#endif #endif
static inline F Det(const Vector3& a,const Vector3& b,const Vector3&
c,const Vector3& d)
{
return( -(a.z()*b.y()*c.x()) + a.y()*b.z()*c.x() + a.z()*b.x()*c.y() -
a.x()*b.z()*c.y() - a.y()*b.x()*c.z() + a.x()*b.y()*c.z() +
a.z()*b.y()*d.x() - a.y()*b.z()*d.x() - a.z()*c.y()*d.x() +
b.z()*c.y()*d.x() + a.y()*c.z()*d.x() - b.y()*c.z()*d.x() -
a.z()*b.x()*d.y() + a.x()*b.z()*d.y() + a.z()*c.x()*d.y() -
b.z()*c.x()*d.y() - a.x()*c.z()*d.y() + b.x()*c.z()*d.y() +
a.y()*b.x()*d.z() - a.x()*b.y()*d.z() - a.y()*c.x()*d.z() +
b.y()*c.x()*d.z() + a.x()*c.y()*d.z() - b.x()*c.y()*d.z());
}
// //
// StackAlloc // StackAlloc
@@ -127,16 +114,6 @@ struct StackAlloc
data = new U1[size]; data = new U1[size];
totalsize = size; totalsize = size;
} }
StackAlloc* CreateChild(U size)
{
StackAlloc* sa(Allocate<StackAlloc>());
sa->ischild = true;
sa->data = Allocate(size);
sa->totalsize = size;
sa->usedsize = 0;
sa->current = 0;
return(sa);
}
void Free() void Free()
{ {
if(usedsize==0) if(usedsize==0)
@@ -148,7 +125,7 @@ struct StackAlloc
} }
Block* BeginBlock() Block* BeginBlock()
{ {
Block* pb(Allocate<Block>()); Block* pb((Block*)Allocate(sizeof(Block)));
pb->previous = current; pb->previous = current;
pb->address = data+usedsize; pb->address = data+usedsize;
current = pb; current = pb;
@@ -173,10 +150,6 @@ struct StackAlloc
Raise(L"Not enough memory"); Raise(L"Not enough memory");
return(0); return(0);
} }
template <typename T> T* Allocate() {
return((T*)Allocate((U)sizeof(T))); }
template <typename T> T* AllocateArray(U count) {
return((T*)Allocate((U)sizeof(T)*count)); }
private: private:
void ctor() void ctor()
{ {
@@ -208,10 +181,9 @@ struct GJK
Vector3 v; Vector3 v;
He* n; He* n;
}; };
static const U hashsize=64;
StackAlloc* sa; StackAlloc* sa;
StackAlloc::Block* sablock; StackAlloc::Block* sablock;
He* table[hashsize]; He* table[GJK_hashsize];
Rotation wrotations[2]; Rotation wrotations[2];
Vector3 positions[2]; Vector3 positions[2];
const btConvexShape* shapes[2]; const btConvexShape* shapes[2];
@@ -242,7 +214,7 @@ struct GJK
// vdh : very dumm hash // vdh : very dumm hash
static inline U Hash(const Vector3& v) static inline U Hash(const Vector3& v)
{ {
const U h((U)(v[0]*15461)^(U)(v[1]*83003)^(U)(v[2]*15473)); const U h(U(v[0]*15461)^U(v[1]*83003)^U(v[2]*15473));
return(((*((const U*)&h))*169639)&GJK_hashmask); return(((*((const U*)&h))*169639)&GJK_hashmask);
} }
// //
@@ -264,7 +236,7 @@ struct GJK
const U h(Hash(ray)); const U h(Hash(ray));
He* e(table[h]); He* e(table[h]);
while(e) { if(e->v==ray) { --order;return(false); } else e=e->n; } while(e) { if(e->v==ray) { --order;return(false); } else e=e->n; }
e=sa->Allocate<He>();e->v=ray;e->n=table[h];table[h]=e; e=(He*)sa->Allocate(sizeof(He));e->v=ray;e->n=table[h];table[h]=e;
Support(ray,simplex[++order]); Support(ray,simplex[++order]);
return(ray.dot(SPXW(order))>0); return(ray.dot(SPXW(order))>0);
} }
@@ -331,10 +303,12 @@ order=2;SPX(1)=SPX(0);SPX(0)=SPX(2);SPX(2)=SPX(3);return(SolveSimplex3a(ao,ad,ab
inline Z SearchOrigin(const Vector3& initray=Vector3(1,0,0)) inline Z SearchOrigin(const Vector3& initray=Vector3(1,0,0))
{ {
iterations = 0; iterations = 0;
order = 0; order = (U)-1;
failed = false; failed = false;
Support(initray,simplex[0]);ray=-SPXW(0); ray = initray.normalized();
ClearMemory(table,sizeof(void*)*hashsize); ClearMemory(table,sizeof(void*)*GJK_hashsize);
FetchSupport();
ray = -SPXW(0);
for(;iterations<GJK_maxiterations;++iterations) for(;iterations<GJK_maxiterations;++iterations)
{ {
const F rl(ray.length()); const F rl(ray.length());
@@ -483,7 +457,7 @@ c) const
// //
inline Face* NewFace(const GJK::Mkv* a,const GJK::Mkv* b,const GJK::Mkv* c) inline Face* NewFace(const GJK::Mkv* a,const GJK::Mkv* b,const GJK::Mkv* c)
{ {
Face* pf(sa->Allocate<Face>()); Face* pf((Face*)sa->Allocate(sizeof(Face)));
if(Set(pf,a,b,c)) if(Set(pf,a,b,c))
{ {
if(root) root->prev=pf; if(root) root->prev=pf;
@@ -525,7 +499,7 @@ c) const
// //
GJK::Mkv* Support(const Vector3& w) const GJK::Mkv* Support(const Vector3& w) const
{ {
GJK::Mkv* v(sa->Allocate<GJK::Mkv>()); GJK::Mkv* v((GJK::Mkv*)sa->Allocate(sizeof(GJK::Mkv)));
gjk->Support(w,*v); gjk->Support(w,*v);
return(v); return(v);
} }
@@ -596,7 +570,8 @@ U eidx[9][4]={{0,0,4,0},{0,1,2,1},{0,2,1,2},{1,1,5,2},{1,0,2,0},{2,2,3,2},{3,1,5
} break; } break;
} }
for(U i=0;i<=gjk->order;++i) { for(U i=0;i<=gjk->order;++i) {
basemkv[i]=sa->Allocate<GJK::Mkv>();*basemkv[i]=gjk->simplex[i]; } basemkv[i]=(GJK::Mkv*)sa->Allocate(sizeof(GJK::Mkv));*basemkv[i]=gjk->simplex[i];
}
for(U i=0;i<nfidx;++i,pfidx+=3) { for(U i=0;i<nfidx;++i,pfidx+=3) {
basefaces[i]=NewFace(basemkv[pfidx[0]],basemkv[pfidx[1]],basemkv[pfidx[2]]); basefaces[i]=NewFace(basemkv[pfidx[0]],basemkv[pfidx[1]],basemkv[pfidx[2]]);
} }
@@ -707,3 +682,5 @@ return(false);