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

@@ -3,18 +3,18 @@ Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty. This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the In no event will the authors be held liable for any damages arising from the
use of this software. use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it including commercial applications, and to alter it and redistribute it
freely, freely,
subject to the following restrictions: subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not 1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software in a claim that you wrote the original software. If you use this software in a
product, an acknowledgment in the product documentation would be appreciated product, an acknowledgment in the product documentation would be appreciated
but is not required. but is not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
@@ -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
@@ -90,23 +89,11 @@ return(a>b?a:b); }
static inline void ClearMemory(void* p,U sz) { memset(p,0,(size_t)sz); static inline void ClearMemory(void* p,U sz) { memset(p,0,(size_t)sz);
} }
#if 0 #if 0
template <typename T> static inline void Raise(const T& object) { template <typename T> static inline void Raise(const T& object) {
throw(object); } 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());
@@ -464,7 +438,7 @@ struct EPA
return(bf); return(bf);
} }
// //
inline Z Set(Face* f,const GJK::Mkv* a,const GJK::Mkv* b,const GJK::Mkv* inline Z Set(Face* f,const GJK::Mkv* a,const GJK::Mkv* b,const GJK::Mkv*
c) const c) const
{ {
const Vector3 nrm(cross(b->w-a->w,c->w-a->w)); const Vector3 nrm(cross(b->w-a->w,c->w-a->w));
@@ -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);