Merge branch 'development' of https://github.com/TorqueGameEngines/Torque3D into alpha41/cmake_adjustments

This commit is contained in:
AzaezelX 2023-06-08 13:31:34 -05:00
commit 52093cbde5
25 changed files with 530 additions and 266 deletions

View file

@ -58,7 +58,7 @@ NvRemoveTjunctions.cpp : A code snippet to remove tjunctions from a triangle mes
#pragma warning(disable:4702)
#pragma warning(disable:4127) //conditional expression is constant (because _HAS_EXCEPTIONS=0)
#include <vector>
#ifdef __APPLE__
#if defined( __APPLE__ ) || defined( __FreeBSD__)
#include <ext/hash_map>
#elif LINUX
#include <hash_map>

View file

@ -57,11 +57,16 @@ NvSimpleTypes.h : Defines basic data types for integers and floats.
*/
#ifdef __APPLE__
#if defined(__APPLE__)
#include <sys/malloc.h>
#else
#if defined( __FreeBSD__)
#include <stdlib.h>
#else
#include <malloc.h>
#endif
#endif
#include <assert.h>
#if defined(__APPLE__) || defined(__CELLOS_LV2__) || defined(LINUX)
@ -73,7 +78,7 @@ NvSimpleTypes.h : Defines basic data types for integers and floats.
#endif
#ifdef WIN32
#if defined(WIN32)
typedef __int64 NxI64;
typedef signed int NxI32;
typedef signed short NxI16;
@ -86,7 +91,7 @@ NvSimpleTypes.h : Defines basic data types for integers and floats.
typedef float NxF32;
typedef double NxF64;
#elif defined(LINUX)
typedef long long NxI64;
typedef signed int NxI32;
@ -115,6 +120,20 @@ NvSimpleTypes.h : Defines basic data types for integers and floats.
typedef float NxF32;
typedef double NxF64;
#elif defined(__FreeBSD__)
typedef long long NxI64;
typedef signed int NxI32;
typedef signed short NxI16;
typedef signed char NxI8;
typedef unsigned long long NxU64;
typedef unsigned int NxU32;
typedef unsigned short NxU16;
typedef unsigned char NxU8;
typedef float NxF32;
typedef double NxF64;
#elif defined(__CELLOS_LV2__)
typedef long long NxI64;
typedef signed int NxI32;

View file

@ -302,13 +302,13 @@ template <class Type> NxI32 Array<Type>::IndexOf(Type t)
NxI32 argmin(NxF32 a[],NxI32 n);
NxF32 sqr(NxF32 a);
NxF32 sqr(NxF32 a);
NxF32 clampf(NxF32 a) ;
NxF32 Round(NxF32 a,NxF32 precision);
NxF32 Interpolate(const NxF32 &f0,const NxF32 &f1,NxF32 alpha) ;
template <class T>
void Swap(T &a,T &b)
void Swap(T &a,T &b)
{
T tmp = a;
a=b;
@ -318,13 +318,13 @@ void Swap(T &a,T &b)
template <class T>
T Max(const T &a,const T &b)
T Max(const T &a,const T &b)
{
return (a>b)?a:b;
}
template <class T>
T Min(const T &a,const T &b)
T Min(const T &a,const T &b)
{
return (a<b)?a:b;
}
@ -409,7 +409,7 @@ class float3x3 : public Memalloc
const float3& operator[](NxI32 i) const {assert(i>=0&&i<3);return (&x)[i];}
NxF32& operator()(NxI32 r, NxI32 c) {assert(r>=0&&r<3&&c>=0&&c<3);return ((&x)[r])[c];}
const NxF32& operator()(NxI32 r, NxI32 c) const {assert(r>=0&&r<3&&c>=0&&c<3);return ((&x)[r])[c];}
};
};
float3x3 Transpose( const float3x3& m );
float3 operator*( const float3& v , const float3x3& m );
float3 operator*( const float3x3& m , const float3& v );
@ -442,7 +442,7 @@ public:
};
struct D3DXMATRIX;
struct D3DXMATRIX;
class float4x4 : public Memalloc
{
@ -450,9 +450,9 @@ class float4x4 : public Memalloc
float4 x,y,z,w; // the 4 rows
float4x4(){}
float4x4(const float4 &_x, const float4 &_y, const float4 &_z, const float4 &_w):x(_x),y(_y),z(_z),w(_w){}
float4x4(NxF32 m00, NxF32 m01, NxF32 m02, NxF32 m03,
NxF32 m10, NxF32 m11, NxF32 m12, NxF32 m13,
NxF32 m20, NxF32 m21, NxF32 m22, NxF32 m23,
float4x4(NxF32 m00, NxF32 m01, NxF32 m02, NxF32 m03,
NxF32 m10, NxF32 m11, NxF32 m12, NxF32 m13,
NxF32 m20, NxF32 m21, NxF32 m22, NxF32 m23,
NxF32 m30, NxF32 m31, NxF32 m32, NxF32 m33 )
:x(m00,m01,m02,m03),y(m10,m11,m12,m13),z(m20,m21,m22,m23),w(m30,m31,m32,m33){}
NxF32& operator()(NxI32 r, NxI32 c) {assert(r>=0&&r<4&&c>=0&&c<4);return ((&x)[r])[c];}
@ -510,7 +510,7 @@ NxF32 dot( const Quaternion &a, const Quaternion &b );
float3 operator*( const Quaternion& q, const float3& v );
float3 operator*( const float3& v, const Quaternion& q );
Quaternion slerp( Quaternion a, const Quaternion& b, NxF32 interp );
Quaternion Interpolate(const Quaternion &q0,const Quaternion &q1,NxF32 alpha);
Quaternion Interpolate(const Quaternion &q0,const Quaternion &q1,NxF32 alpha);
Quaternion RotationArc(float3 v0, float3 v1 ); // returns quat q where q*v0=v1
Quaternion Inverse(const Quaternion &q);
float4x4 MatrixFromQuatVec(const Quaternion &q, const float3 &v);
@ -528,7 +528,7 @@ NxF32 Pitch( const float3& v );
//------- Plane ----------
class Plane
class Plane
{
public:
float3 normal;
@ -576,7 +576,7 @@ NxF32 Round(NxF32 a,NxF32 precision)
}
NxF32 Interpolate(const NxF32 &f0,const NxF32 &f1,NxF32 alpha)
NxF32 Interpolate(const NxF32 &f0,const NxF32 &f1,NxF32 alpha)
{
return f0*(1-alpha) + f1*alpha;
}
@ -585,11 +585,11 @@ NxF32 Interpolate(const NxF32 &f0,const NxF32 &f1,NxF32 alpha)
NxI32 argmin(NxF32 a[],NxI32 n)
{
NxI32 r=0;
for(NxI32 i=1;i<n;i++)
for(NxI32 i=1;i<n;i++)
{
if(a[i]<a[r])
if(a[i]<a[r])
{
r = i;
r = i;
}
}
return r;
@ -601,49 +601,49 @@ NxI32 argmin(NxF32 a[],NxI32 n)
float3 operator+( const float3& a, const float3& b )
float3 operator+( const float3& a, const float3& b )
{
return float3(a.x+b.x, a.y+b.y, a.z+b.z);
return float3(a.x+b.x, a.y+b.y, a.z+b.z);
}
float3 operator-( const float3& a, const float3& b )
{
return float3( a.x-b.x, a.y-b.y, a.z-b.z );
return float3( a.x-b.x, a.y-b.y, a.z-b.z );
}
float3 operator-( const float3& v )
float3 operator-( const float3& v )
{
return float3( -v.x, -v.y, -v.z );
return float3( -v.x, -v.y, -v.z );
}
float3 operator*( const float3& v, NxF32 s )
float3 operator*( const float3& v, NxF32 s )
{
return float3( v.x*s, v.y*s, v.z*s );
return float3( v.x*s, v.y*s, v.z*s );
}
float3 operator*( NxF32 s, const float3& v )
float3 operator*( NxF32 s, const float3& v )
{
return float3( v.x*s, v.y*s, v.z*s );
return float3( v.x*s, v.y*s, v.z*s );
}
float3 operator/( const float3& v, NxF32 s )
{
return v*(1.0f/s);
}
NxF32 dot( const float3& a, const float3& b )
{
return a.x*b.x + a.y*b.y + a.z*b.z;
return v*(1.0f/s);
}
float3 cmul( const float3 &v1, const float3 &v2)
{
return float3(v1.x*v2.x, v1.y*v2.y, v1.z*v2.z);
NxF32 dot( const float3& a, const float3& b )
{
return a.x*b.x + a.y*b.y + a.z*b.z;
}
float3 cmul( const float3 &v1, const float3 &v2)
{
return float3(v1.x*v2.x, v1.y*v2.y, v1.z*v2.z);
}
@ -710,7 +710,7 @@ float3 normalize( const float3 &v )
{
// this routine, normalize, is ok, provided magnitude works!!
NxF32 d=magnitude(v);
if (d==0)
if (d==0)
{
printf("Cant normalize ZERO vector\n");
assert(0);// yes this could go here
@ -735,7 +735,7 @@ float3 Round(const float3 &a,NxF32 precision)
}
float3 Interpolate(const float3 &v0,const float3 &v1,NxF32 alpha)
float3 Interpolate(const float3 &v0,const float3 &v1,NxF32 alpha)
{
return v0*(1-alpha) + v1*alpha;
}
@ -755,7 +755,7 @@ float3 VectorMax(const float3 &a,const float3 &b)
// - dot product
// - cross product
// Therefore we never declare/implement this function.
// So we will never see: float3 operator*(float3 a,float3 b)
// So we will never see: float3 operator*(float3 a,float3 b)
@ -763,7 +763,7 @@ float3 VectorMax(const float3 &a,const float3 &b)
//------------ float3x3 ---------------
NxF32 Determinant(const float3x3 &m)
{
return m.x.x*m.y.y*m.z.z + m.y.x*m.z.y*m.x.z + m.z.x*m.x.y*m.y.z
return m.x.x*m.y.y*m.z.z + m.y.x*m.z.y*m.x.z + m.z.x*m.x.y*m.y.z
-m.x.x*m.z.y*m.y.z - m.y.x*m.x.y*m.z.z - m.z.x*m.y.y*m.x.z ;
}
@ -772,9 +772,9 @@ float3x3 Inverse(const float3x3 &a)
float3x3 b;
NxF32 d=Determinant(a);
assert(d!=0);
for(NxI32 i=0;i<3;i++)
for(NxI32 i=0;i<3;i++)
{
for(NxI32 j=0;j<3;j++)
for(NxI32 j=0;j<3;j++)
{
NxI32 i1=(i+1)%3;
NxI32 i2=(i+2)%3;
@ -798,28 +798,28 @@ float3x3 Transpose( const float3x3& m )
float3 operator*(const float3& v , const float3x3 &m ) {
return float3((m.x.x*v.x + m.y.x*v.y + m.z.x*v.z),
(m.x.y*v.x + m.y.y*v.y + m.z.y*v.z),
return float3((m.x.x*v.x + m.y.x*v.y + m.z.x*v.z),
(m.x.y*v.x + m.y.y*v.y + m.z.y*v.z),
(m.x.z*v.x + m.y.z*v.y + m.z.z*v.z));
}
float3 operator*(const float3x3 &m,const float3& v ) {
float3 operator*(const float3x3 &m,const float3& v ) {
return float3(dot(m.x,v),dot(m.y,v),dot(m.z,v));
}
float3x3 operator*( const float3x3& a, const float3x3& b )
{
float3x3 operator*( const float3x3& a, const float3x3& b )
{
return float3x3(a.x*b,a.y*b,a.z*b);
}
float3x3 operator*( const float3x3& a, const NxF32& s )
{
return float3x3(a.x*s, a.y*s ,a.z*s);
float3x3 operator*( const float3x3& a, const NxF32& s )
{
return float3x3(a.x*s, a.y*s ,a.z*s);
}
float3x3 operator/( const float3x3& a, const NxF32& s )
{
float3x3 operator/( const float3x3& a, const NxF32& s )
{
NxF32 t=1/s;
return float3x3(a.x*t, a.y*t ,a.z*t);
return float3x3(a.x*t, a.y*t ,a.z*t);
}
float3x3 operator+( const float3x3& a, const float3x3& b )
{
@ -868,7 +868,7 @@ float4 operator*( const float4& v, const float4x4& m )
return v.x*m.x + v.y*m.y + v.z*m.z + v.w*m.w; // yes this actually works
}
NxI32 operator==( const float4 &a, const float4 &b )
NxI32 operator==( const float4 &a, const float4 &b )
{
return (a.x==b.x && a.y==b.y && a.z==b.z && a.w==b.w);
}
@ -883,32 +883,32 @@ NxI32 operator==( const float4 &a, const float4 &b )
float4 cmul( const float4 &a, const float4 &b)
float4 cmul( const float4 &a, const float4 &b)
{
return float4(a.x*b.x,a.y*b.y,a.z*b.z,a.w*b.w);
}
float4 operator*( const float4 &v, NxF32 s)
float4 operator*( const float4 &v, NxF32 s)
{
return float4(v.x*s,v.y*s,v.z*s,v.w*s);
}
float4 operator*( NxF32 s, const float4 &v)
float4 operator*( NxF32 s, const float4 &v)
{
return float4(v.x*s,v.y*s,v.z*s,v.w*s);
}
float4 operator+( const float4 &a, const float4 &b)
float4 operator+( const float4 &a, const float4 &b)
{
return float4(a.x+b.x,a.y+b.y,a.z+b.z,a.w+b.w);
}
float4 operator-( const float4 &a, const float4 &b)
float4 operator-( const float4 &a, const float4 &b)
{
return float4(a.x-b.x,a.y-b.y,a.z-b.z,a.w-b.w);
}
@ -1010,7 +1010,7 @@ float4x4 Inverse(const float4x4 &m)
src[i] = m(i,0) ;
src[i + 4] = m(i,1);
src[i + 8] = m(i,2);
src[i + 12] = m(i,3);
src[i + 12] = m(i,3);
}
/* calculate pairs for first 8 elements (cofactors) */
tmp[0] = src[10] * src[15];
@ -1083,14 +1083,14 @@ float4x4 Inverse(const float4x4 &m)
//--------- Quaternion --------------
Quaternion operator*( const Quaternion& a, const Quaternion& b )
{
Quaternion c;
c.w = a.w*b.w - a.x*b.x - a.y*b.y - a.z*b.z;
c.x = a.w*b.x + a.x*b.w + a.y*b.z - a.z*b.y;
c.y = a.w*b.y - a.x*b.z + a.y*b.w + a.z*b.x;
c.z = a.w*b.z + a.x*b.y - a.y*b.x + a.z*b.w;
c.w = a.w*b.w - a.x*b.x - a.y*b.y - a.z*b.z;
c.x = a.w*b.x + a.x*b.w + a.y*b.z - a.z*b.y;
c.y = a.w*b.y - a.x*b.z + a.y*b.w + a.z*b.x;
c.z = a.w*b.z + a.x*b.y - a.y*b.x + a.z*b.w;
return c;
}
@ -1126,8 +1126,8 @@ void Quaternion::Normalize()
float3 operator*( const Quaternion& q, const float3& v )
{
// The following is equivalent to:
//return (q.getmatrix() * v);
// The following is equivalent to:
//return (q.getmatrix() * v);
NxF32 qx2 = q.x*q.x;
NxF32 qy2 = q.y*q.y;
NxF32 qz2 = q.z*q.z;
@ -1151,14 +1151,14 @@ Quaternion operator+( const Quaternion& a, const Quaternion& b )
NxF32 dot( const Quaternion &a,const Quaternion &b )
{
return (a.w*b.w + a.x*b.x + a.y*b.y + a.z*b.z);
return (a.w*b.w + a.x*b.x + a.y*b.y + a.z*b.z);
}
Quaternion normalize( Quaternion a )
{
NxF32 m = sqrtf(sqr(a.w)+sqr(a.x)+sqr(a.y)+sqr(a.z));
if(m<0.000000001)
{
if(m<0.000000001)
{
a.w=1;
a.x=a.y=a.z=0;
return a;
@ -1168,7 +1168,7 @@ Quaternion normalize( Quaternion a )
Quaternion slerp( Quaternion a, const Quaternion& b, NxF32 interp )
{
if(dot(a,b) <0.0)
if(dot(a,b) <0.0)
{
a.w=-a.w;
a.x=-a.x;
@ -1190,7 +1190,7 @@ Quaternion Interpolate(const Quaternion &q0,const Quaternion &q1,NxF32 alpha) {
}
Quaternion YawPitchRoll( NxF32 yaw, NxF32 pitch, NxF32 roll )
Quaternion YawPitchRoll( NxF32 yaw, NxF32 pitch, NxF32 roll )
{
roll *= DEG2RAD;
yaw *= DEG2RAD;
@ -1234,7 +1234,7 @@ NxF32 Pitch( const float3& v )
void Plane::Transform(const float3 &position, const Quaternion &orientation) {
// Transforms the plane to the space defined by the
// Transforms the plane to the space defined by the
// given position/orientation.
static float3 newnormal;
static float3 origin;
@ -1271,9 +1271,9 @@ Quaternion RotationArc(float3 v0,float3 v1){
}
float4x4 MatrixFromQuatVec(const Quaternion &q, const float3 &v)
float4x4 MatrixFromQuatVec(const Quaternion &q, const float3 &v)
{
// builds a 4x4 transformation matrix based on orientation q and translation v
// builds a 4x4 transformation matrix based on orientation q and translation v
NxF32 qx2 = q.x*q.x;
NxF32 qy2 = q.y*q.y;
NxF32 qz2 = q.z*q.z;
@ -1286,18 +1286,18 @@ float4x4 MatrixFromQuatVec(const Quaternion &q, const float3 &v)
NxF32 qzqw = q.z*q.w;
return float4x4(
1-2*(qy2+qz2),
2*(qxqy+qzqw),
2*(qxqz-qyqw),
0 ,
2*(qxqy-qzqw),
1-2*(qx2+qz2),
2*(qyqz+qxqw),
0 ,
2*(qxqz+qyqw),
2*(qyqz-qxqw),
1-2*(qx2+qy2),
0 ,
1-2*(qy2+qz2),
2*(qxqy+qzqw),
2*(qxqz-qyqw),
0 ,
2*(qxqy-qzqw),
1-2*(qx2+qz2),
2*(qyqz+qxqw),
0 ,
2*(qxqz+qyqw),
2*(qyqz-qxqw),
1-2*(qx2+qy2),
0 ,
v.x ,
v.y ,
v.z ,
@ -1351,10 +1351,10 @@ float3 TriNormal(const float3 &v0, const float3 &v1, const float3 &v2)
NxI32 BoxInside(const float3 &p, const float3 &bmin, const float3 &bmax)
NxI32 BoxInside(const float3 &p, const float3 &bmin, const float3 &bmax)
{
return (p.x >= bmin.x && p.x <=bmax.x &&
p.y >= bmin.y && p.y <=bmax.y &&
return (p.x >= bmin.x && p.x <=bmax.x &&
p.y >= bmin.y && p.y <=bmax.y &&
p.z >= bmin.z && p.z <=bmax.z );
}
@ -1366,13 +1366,13 @@ NxI32 BoxIntersect(const float3 &v0, const float3 &v1, const float3 &bmin, const
*impact=v0;
return 1;
}
if(v0.x<=bmin.x && v1.x>=bmin.x)
if(v0.x<=bmin.x && v1.x>=bmin.x)
{
NxF32 a = (bmin.x-v0.x)/(v1.x-v0.x);
//v.x = bmin.x;
NxF32 vy = (1-a) *v0.y + a*v1.y;
NxF32 vz = (1-a) *v0.z + a*v1.z;
if(vy>=bmin.y && vy<=bmax.y && vz>=bmin.z && vz<=bmax.z)
if(vy>=bmin.y && vy<=bmax.y && vz>=bmin.z && vz<=bmax.z)
{
impact->x = bmin.x;
impact->y = vy;
@ -1380,13 +1380,13 @@ NxI32 BoxIntersect(const float3 &v0, const float3 &v1, const float3 &bmin, const
return 1;
}
}
else if(v0.x >= bmax.x && v1.x <= bmax.x)
else if(v0.x >= bmax.x && v1.x <= bmax.x)
{
NxF32 a = (bmax.x-v0.x)/(v1.x-v0.x);
//v.x = bmax.x;
NxF32 vy = (1-a) *v0.y + a*v1.y;
NxF32 vz = (1-a) *v0.z + a*v1.z;
if(vy>=bmin.y && vy<=bmax.y && vz>=bmin.z && vz<=bmax.z)
if(vy>=bmin.y && vy<=bmax.y && vz>=bmin.z && vz<=bmax.z)
{
impact->x = bmax.x;
impact->y = vy;
@ -1394,13 +1394,13 @@ NxI32 BoxIntersect(const float3 &v0, const float3 &v1, const float3 &bmin, const
return 1;
}
}
if(v0.y<=bmin.y && v1.y>=bmin.y)
if(v0.y<=bmin.y && v1.y>=bmin.y)
{
NxF32 a = (bmin.y-v0.y)/(v1.y-v0.y);
NxF32 vx = (1-a) *v0.x + a*v1.x;
//v.y = bmin.y;
NxF32 vz = (1-a) *v0.z + a*v1.z;
if(vx>=bmin.x && vx<=bmax.x && vz>=bmin.z && vz<=bmax.z)
if(vx>=bmin.x && vx<=bmax.x && vz>=bmin.z && vz<=bmax.z)
{
impact->x = vx;
impact->y = bmin.y;
@ -1408,13 +1408,13 @@ NxI32 BoxIntersect(const float3 &v0, const float3 &v1, const float3 &bmin, const
return 1;
}
}
else if(v0.y >= bmax.y && v1.y <= bmax.y)
else if(v0.y >= bmax.y && v1.y <= bmax.y)
{
NxF32 a = (bmax.y-v0.y)/(v1.y-v0.y);
NxF32 vx = (1-a) *v0.x + a*v1.x;
// vy = bmax.y;
NxF32 vz = (1-a) *v0.z + a*v1.z;
if(vx>=bmin.x && vx<=bmax.x && vz>=bmin.z && vz<=bmax.z)
if(vx>=bmin.x && vx<=bmax.x && vz>=bmin.z && vz<=bmax.z)
{
impact->x = vx;
impact->y = bmax.y;
@ -1422,13 +1422,13 @@ NxI32 BoxIntersect(const float3 &v0, const float3 &v1, const float3 &bmin, const
return 1;
}
}
if(v0.z<=bmin.z && v1.z>=bmin.z)
if(v0.z<=bmin.z && v1.z>=bmin.z)
{
NxF32 a = (bmin.z-v0.z)/(v1.z-v0.z);
NxF32 vx = (1-a) *v0.x + a*v1.x;
NxF32 vy = (1-a) *v0.y + a*v1.y;
// v.z = bmin.z;
if(vy>=bmin.y && vy<=bmax.y && vx>=bmin.x && vx<=bmax.x)
if(vy>=bmin.y && vy<=bmax.y && vx>=bmin.x && vx<=bmax.x)
{
impact->x = vx;
impact->y = vy;
@ -1436,13 +1436,13 @@ NxI32 BoxIntersect(const float3 &v0, const float3 &v1, const float3 &bmin, const
return 1;
}
}
else if(v0.z >= bmax.z && v1.z <= bmax.z)
else if(v0.z >= bmax.z && v1.z <= bmax.z)
{
NxF32 a = (bmax.z-v0.z)/(v1.z-v0.z);
NxF32 vx = (1-a) *v0.x + a*v1.x;
NxF32 vy = (1-a) *v0.y + a*v1.y;
// v.z = bmax.z;
if(vy>=bmin.y && vy<=bmax.y && vx>=bmin.x && vx<=bmax.x)
if(vy>=bmin.y && vy<=bmax.y && vx>=bmin.x && vx<=bmax.x)
{
impact->x = vx;
impact->y = vy;
@ -1462,14 +1462,14 @@ NxF32 DistanceBetweenLines(const float3 &ustart, const float3 &udir, const float
NxF32 distu = -dot(cp,ustart);
NxF32 distv = -dot(cp,vstart);
NxF32 dist = (NxF32)fabs(distu-distv);
if(upoint)
if(upoint)
{
Plane plane;
plane.normal = normalize(cross(vdir,cp));
plane.dist = -dot(plane.normal,vstart);
*upoint = PlaneLineIntersection(plane,ustart,ustart+udir);
}
if(vpoint)
if(vpoint)
{
Plane plane;
plane.normal = normalize(cross(udir,cp));
@ -1480,19 +1480,19 @@ NxF32 DistanceBetweenLines(const float3 &ustart, const float3 &udir, const float
}
Quaternion VirtualTrackBall(const float3 &cop, const float3 &cor, const float3 &dir1, const float3 &dir2)
Quaternion VirtualTrackBall(const float3 &cop, const float3 &cor, const float3 &dir1, const float3 &dir2)
{
// routine taken from game programming gems.
// Implement track ball functionality to spin stuf on the screen
// cop center of projection
// cor center of rotation
// dir1 old mouse direction
// dir1 old mouse direction
// dir2 new mouse direction
// pretend there is a sphere around cor. Then find the points
// where dir1 and dir2 intersect that sphere. Find the
// rotation that takes the first point to the second.
NxF32 m;
// compute plane
// compute plane
float3 nrml = cor - cop;
NxF32 fudgefactor = 1.0f/(magnitude(nrml) * 0.25f); // since trackball proportional to distance from cop
nrml = normalize(nrml);
@ -1501,11 +1501,11 @@ Quaternion VirtualTrackBall(const float3 &cop, const float3 &cor, const float3 &
u=u-cor;
u=u*fudgefactor;
m= magnitude(u);
if(m>1)
if(m>1)
{
u/=m;
}
else
else
{
u=u - (nrml * sqrtf(1-m*m));
}
@ -1513,7 +1513,7 @@ Quaternion VirtualTrackBall(const float3 &cop, const float3 &cor, const float3 &
v=v-cor;
v=v*fudgefactor;
m= magnitude(v);
if(m>1)
if(m>1)
{
v/=m;
}
@ -1531,7 +1531,7 @@ NxI32 PolyHit(const float3 *vert, const NxI32 n, const float3 &v0, const float3
countpolyhit++;
NxI32 i;
float3 nrml(0,0,0);
for(i=0;i<n;i++)
for(i=0;i<n;i++)
{
NxI32 i1=(i+1)%n;
NxI32 i2=(i+2)%n;
@ -1546,12 +1546,12 @@ NxI32 PolyHit(const float3 *vert, const NxI32 n, const float3 &v0, const float3
nrml = nrml * (1.0f/m);
NxF32 dist = -dot(nrml,vert[0]);
NxF32 d0,d1;
if((d0=dot(v0,nrml)+dist) <0 || (d1=dot(v1,nrml)+dist) >0)
{
if((d0=dot(v0,nrml)+dist) <0 || (d1=dot(v1,nrml)+dist) >0)
{
return 0;
}
static float3 the_point;
static float3 the_point;
// By using the cached plane distances d0 and d1
// we can optimize the following:
// the_point = planelineintersection(nrml,dist,v0,v1);
@ -1560,7 +1560,7 @@ NxI32 PolyHit(const float3 *vert, const NxI32 n, const float3 &v0, const float3
NxI32 inside=1;
for(NxI32 j=0;inside && j<n;j++)
for(NxI32 j=0;inside && j<n;j++)
{
// let inside = 0 if outside
float3 pp1,pp2,side;
@ -1569,7 +1569,7 @@ NxI32 PolyHit(const float3 *vert, const NxI32 n, const float3 &v0, const float3
side = cross((pp2-pp1),(the_point-pp1));
inside = (dot(nrml,side) >= 0.0);
}
if(inside)
if(inside)
{
if(normal){*normal=nrml;}
if(impact){*impact=the_point;}
@ -1675,7 +1675,7 @@ NxI32 SplitTest(ConvexH &convex,const Plane &plane) {
return flag;
}
class VertFlag
class VertFlag
{
public:
NxU8 planetest;
@ -1683,7 +1683,7 @@ public:
NxU8 undermap;
NxU8 overmap;
};
class EdgeFlag
class EdgeFlag
{
public:
NxU8 planetest;
@ -1691,7 +1691,7 @@ public:
short undermap;
short overmap;
};
class PlaneFlag
class PlaneFlag
{
public:
NxU8 undermap;
@ -1821,7 +1821,7 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice)
}
else if((vertflag[edge0.v].planetest | vertflag[edge1.v].planetest) == UNDER) {
// at least one endpoint under, the other coplanar or under
edgeflag[e0].undermap = (short)under_edge_count;
tmpunderedges[under_edge_count].v = (NxU8)vertflag[edge0.v].undermap;
tmpunderedges[under_edge_count].p = (NxU8)underplanescount;
@ -1834,16 +1834,16 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice)
under_edge_count++;
}
else if((vertflag[edge0.v].planetest | vertflag[edge1.v].planetest) == COPLANAR) {
// both endpoints coplanar
// both endpoints coplanar
// must check a 3rd point to see if UNDER
NxI32 e2 = e1+1;
NxI32 e2 = e1+1;
if(e2>=convex.edges.count || convex.edges[e2].p!=currentplane) {
e2 = estart;
}
assert(convex.edges[e2].p==currentplane);
HalfEdge &edge2 = convex.edges[e2];
if(vertflag[edge2.v].planetest==UNDER) {
edgeflag[e0].undermap = (short)under_edge_count;
tmpunderedges[under_edge_count].v = (NxU8)vertflag[edge0.v].undermap;
tmpunderedges[under_edge_count].p = (NxU8)underplanescount;
@ -1859,8 +1859,8 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice)
}
}
else if(vertflag[edge0.v].planetest == UNDER && vertflag[edge1.v].planetest == OVER) {
// first is under 2nd is over
// first is under 2nd is over
edgeflag[e0].undermap = (short) under_edge_count;
tmpunderedges[under_edge_count].v = (NxU8)vertflag[edge0.v].undermap;
tmpunderedges[under_edge_count].p = (NxU8)underplanescount;
@ -1880,7 +1880,7 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice)
vout = vertcountunder++;
}
under_edge_count++;
/// hmmm something to think about: i might be able to output this edge regarless of
/// hmmm something to think about: i might be able to output this edge regarless of
// wheter or not we know v-in yet. ok i;ll try this now:
tmpunderedges[under_edge_count].v = (NxU8)vout;
tmpunderedges[under_edge_count].p = (NxU8)underplanescount;
@ -1897,8 +1897,8 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice)
}
else if(vertflag[edge0.v].planetest == COPLANAR && vertflag[edge1.v].planetest == OVER) {
// first is coplanar 2nd is over
// first is coplanar 2nd is over
edgeflag[e0].undermap = -1;
vout = vertflag[edge0.v].undermap;
// I hate this but i have to make sure part of this face is UNDER before ouputting this vert
@ -1914,11 +1914,11 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice)
tmpunderedges[under_edge_count].ea = -1;
coplanaredge = under_edge_count; // hmmm should make a note of the edge # for later on
under_edge_count++;
}
}
else if(vertflag[edge0.v].planetest == OVER && vertflag[edge1.v].planetest == UNDER) {
// first is over next is under
// first is over next is under
// new vertex!!!
if (vin!=-1) return NULL;
if(e0<edge0.ea) {
@ -1955,8 +1955,8 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice)
under_edge_count++;
}
else if(vertflag[edge0.v].planetest == OVER && vertflag[edge1.v].planetest == COPLANAR) {
// first is over next is coplanar
// first is over next is coplanar
edgeflag[e0].undermap = -1;
vin = vertflag[edge1.v].undermap;
if (vin==-1) return NULL;
@ -1970,7 +1970,7 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice)
else {
assert(0);
}
e0=e1;
e1++; // do the modulo at the beginning of the loop
@ -2069,7 +2069,7 @@ static NxI32 candidateplane(Plane *planes,NxI32 planes_count,ConvexH *convex,NxF
if(d<=md) continue;
for(j=0;j<convex->facets.count;j++)
{
if(planes[i]==convex->facets[j])
if(planes[i]==convex->facets[j])
{
d=0;continue;
}
@ -2121,7 +2121,7 @@ NxI32 maxdirfiltered(const T *p,NxI32 count,const T &dir,Array<NxI32> &allow)
}
assert(m!=-1);
return m;
}
}
float3 orth(const float3 &v)
{
@ -2175,21 +2175,21 @@ NxI32 maxdirsterid(const T *p,NxI32 count,const T &dir,Array<NxI32> &allow)
}
assert(0);
return m;
}
}
NxI32 operator ==(const int3 &a,const int3 &b)
NxI32 operator ==(const int3 &a,const int3 &b)
{
for(NxI32 i=0;i<3;i++)
for(NxI32 i=0;i<3;i++)
{
if(a[i]!=b[i]) return 0;
}
return 1;
}
int3 roll3(int3 a)
int3 roll3(int3 a)
{
NxI32 tmp=a[0];
a[0]=a[1];
@ -2197,15 +2197,15 @@ int3 roll3(int3 a)
a[2]=tmp;
return a;
}
NxI32 isa(const int3 &a,const int3 &b)
NxI32 isa(const int3 &a,const int3 &b)
{
return ( a==b || roll3(a)==b || a==roll3(b) );
}
NxI32 b2b(const int3 &a,const int3 &b)
NxI32 b2b(const int3 &a,const int3 &b)
{
return isa(a,int3(b[2],b[1],b[0]));
}
NxI32 above(float3* vertices,const int3& t, const float3 &p, NxF32 epsilon)
NxI32 above(float3* vertices,const int3& t, const float3 &p, NxF32 epsilon)
{
float3 n=TriNormal(vertices[t[0]],vertices[t[1]],vertices[t[2]]);
return (dot(n,p-vertices[t[0]]) > epsilon); // EPSILON???
@ -2265,7 +2265,7 @@ NxI32 &Tri::neib(NxI32 a,NxI32 b)
{
static NxI32 er=-1;
NxI32 i;
for(i=0;i<3;i++)
for(i=0;i<3;i++)
{
NxI32 i1=(i+1)%3;
NxI32 i2=(i+2)%3;
@ -2278,7 +2278,7 @@ NxI32 &Tri::neib(NxI32 a,NxI32 b)
void b2bfix(Tri* s,Tri*t)
{
NxI32 i;
for(i=0;i<3;i++)
for(i=0;i<3;i++)
{
NxI32 i1=(i+1)%3;
NxI32 i2=(i+2)%3;
@ -2356,11 +2356,11 @@ bool hasVolume(float3 *verts, NxI32 p0, NxI32 p1, NxI32 p2, NxI32 p3)
int4 FindSimplex(float3 *verts,NxI32 verts_count,Array<NxI32> &allow)
{
float3 basis[3];
basis[0] = float3( 0.01f, 0.02f, 1.0f );
basis[0] = float3( 0.01f, 0.02f, 1.0f );
NxI32 p0 = maxdirsterid(verts,verts_count, basis[0],allow);
NxI32 p1 = maxdirsterid(verts,verts_count,-basis[0],allow);
basis[0] = verts[p0]-verts[p1];
if(p0==p1 || basis[0]==float3(0,0,0))
if(p0==p1 || basis[0]==float3(0,0,0))
return int4(-1,-1,-1,-1);
basis[1] = cross(float3( 1, 0.02f, 0),basis[0]);
basis[2] = cross(float3(-0.02f, 1, 0),basis[0]);
@ -2370,13 +2370,13 @@ int4 FindSimplex(float3 *verts,NxI32 verts_count,Array<NxI32> &allow)
{
p2 = maxdirsterid(verts,verts_count,-basis[1],allow);
}
if(p2 == p0 || p2 == p1)
if(p2 == p0 || p2 == p1)
return int4(-1,-1,-1,-1);
basis[1] = verts[p2] - verts[p0];
basis[2] = normalize(cross(basis[1],basis[0]));
NxI32 p3 = maxdirsterid(verts,verts_count,basis[2],allow);
if(p3==p0||p3==p1||p3==p2||!hasVolume(verts, p0, p1, p2, p3)) p3 = maxdirsterid(verts,verts_count,-basis[2],allow);
if(p3==p0||p3==p1||p3==p2)
if(p3==p0||p3==p1||p3==p2)
return int4(-1,-1,-1,-1);
assert(!(p0==p1||p0==p2||p0==p3||p1==p2||p1==p3||p2==p3));
if(dot(verts[p3]-verts[p0],cross(verts[p1]-verts[p0],verts[p2]-verts[p0])) <0) {Swap(p2,p3);}
@ -2384,7 +2384,7 @@ int4 FindSimplex(float3 *verts,NxI32 verts_count,Array<NxI32> &allow)
}
#pragma warning(push)
#pragma warning(disable:4706)
NxI32 calchullgen(float3 *verts,NxI32 verts_count, NxI32 vlimit)
NxI32 calchullgen(float3 *verts,NxI32 verts_count, NxI32 vlimit)
{
if(verts_count <4) return 0;
if(vlimit==0) vlimit=1000000000;
@ -2392,7 +2392,7 @@ NxI32 calchullgen(float3 *verts,NxI32 verts_count, NxI32 vlimit)
float3 bmin(*verts),bmax(*verts);
Array<NxI32> isextreme(verts_count);
Array<NxI32> allow(verts_count);
for(j=0;j<verts_count;j++)
for(j=0;j<verts_count;j++)
{
allow.Add(1);
isextreme.Add(0);
@ -2464,7 +2464,7 @@ NxI32 calchullgen(float3 *verts,NxI32 verts_count, NxI32 vlimit)
if(t->vmax>=0) break;
float3 n=TriNormal(verts[(*t)[0]],verts[(*t)[1]],verts[(*t)[2]]);
t->vmax = maxdirsterid(verts,verts_count,n,allow);
if(isextreme[t->vmax])
if(isextreme[t->vmax])
{
t->vmax=-1; // already done that vertex - algorithm needs to be able to terminate.
}
@ -2479,7 +2479,7 @@ NxI32 calchullgen(float3 *verts,NxI32 verts_count, NxI32 vlimit)
}
#pragma warning(pop)
NxI32 calchull(float3 *verts,NxI32 verts_count, NxI32 *&tris_out, NxI32 &tris_count,NxI32 vlimit)
NxI32 calchull(float3 *verts,NxI32 verts_count, NxI32 *&tris_out, NxI32 &tris_count,NxI32 vlimit)
{
NxI32 rc=calchullgen(verts,verts_count, vlimit) ;
if(!rc) return 0;
@ -2502,7 +2502,7 @@ static NxF32 area2(const float3 &v0,const float3 &v1,const float3 &v2)
float3 cp = cross(v0-v1,v2-v0);
return dot(cp,cp);
}
NxI32 calchullpbev(float3 *verts,NxI32 verts_count,NxI32 vlimit, Array<Plane> &planes,NxF32 bevangle)
NxI32 calchullpbev(float3 *verts,NxI32 verts_count,NxI32 vlimit, Array<Plane> &planes,NxF32 bevangle)
{
NxI32 i,j;
Array<Plane> bplanes;
@ -2526,7 +2526,7 @@ NxI32 calchullpbev(float3 *verts,NxI32 verts_count,NxI32 vlimit, Array<Plane> &p
REAL3 e = verts[(*t)[(j+2)%3]] - verts[(*t)[(j+1)%3]];
REAL3 n = (e!=REAL3(0,0,0))? cross(snormal,e)+cross(e,p.normal) : snormal+p.normal;
assert(n!=REAL3(0,0,0));
if(n==REAL3(0,0,0)) return 0;
if(n==REAL3(0,0,0)) return 0;
n=normalize(n);
bplanes.Add(Plane(n,-dot(n,verts[maxdir(verts,verts_count,n)])));
}
@ -2656,7 +2656,7 @@ static NxI32 overhull(Plane *planes,NxI32 planes_count,float3 *verts, NxI32 vert
float3 *&verts_out, NxI32 &verts_count_out, NxI32 *&faces_out, NxI32 &faces_count_out ,NxF32 inflate)
{
NxI32 i,j;
if(verts_count <4) return NULL;
if (verts_count < 4) return 0;
maxplanes = Min(maxplanes,planes_count);
float3 bmin(verts[0]),bmax(verts[0]);
for(i=0;i<verts_count;i++)
@ -2862,7 +2862,7 @@ HullError HullLibrary::CreateConvexHull(const HullDesc &desc, //
}
NxF32 skinwidth = 0;
if ( desc.HasHullFlag(QF_SKIN_WIDTH) )
if ( desc.HasHullFlag(QF_SKIN_WIDTH) )
skinwidth = desc.mSkinWidth;
ok = ComputeHull(ovcount,vsource,hr,desc.mMaxVertices,skinwidth);

View file

@ -71,7 +71,7 @@ NvThreadConfig.cpp : A simple wrapper class to define threading and mutex locks.
#include <xtl.h>
#endif
#if defined(__linux__) || defined( __APPLE__ )
#if defined(__linux__) || defined( __APPLE__ ) || defined( __FreeBSD__)
//#include <sys/time.h>
#include <time.h>
#include <unistd.h>
@ -79,15 +79,18 @@ NvThreadConfig.cpp : A simple wrapper class to define threading and mutex locks.
#define __stdcall
#endif
#if defined( __APPLE__ )
#if defined( __APPLE__ ) || defined( __FreeBSD__)
#include <sys/time.h>
#endif
#if defined(__APPLE__) || defined(__linux__)
#if defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
#include <pthread.h>
#endif
#if defined( __APPLE__ )
#if defined( __APPLE__ ) || defined( __FreeBSD__)
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
#endif
@ -107,7 +110,8 @@ NxU32 tc_timeGetTime(void)
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
#elif defined( __APPLE__ )
#elif defined( __APPLE__ ) || defined( __FreeBSD__)
struct timeval tp;
gettimeofday(&tp, (struct timezone *)0);
return tp.tv_sec * 1000 + tp.tv_usec / 1000;
@ -120,7 +124,7 @@ NxU32 tc_timeGetTime(void)
void tc_sleep(NxU32 ms)
{
#if defined(__linux__) || defined( __APPLE__ )
#if defined(__linux__) || defined( __APPLE__ ) || defined( __FreeBSD__)
usleep(ms * 1000);
#else
Sleep(ms);
@ -129,26 +133,28 @@ void tc_sleep(NxU32 ms)
void tc_spinloop()
{
#if defined( _XBOX )
// Pause would do nothing on the Xbox. Threads are not scheduled.
#elif defined( _WIN64 )
YieldProcessor( );
#elif defined( __APPLE__ )
pthread_yield_np();
#elif defined(__linux__)
#if defined(_POSIX_PRIORITY_SCHEDULING)
sched_yield();
#else
asm("pause");
#if defined( _XBOX )
// Pause would do nothing on the Xbox. Threads are not scheduled.
#elif defined( _WIN64 )
YieldProcessor( );
#elif defined( __APPLE__ )
pthread_yield_np();
#elif defined(__linux__) || defined(__FreeBSD__)
#if defined(_POSIX_PRIORITY_SCHEDULING)
sched_yield();
#else
asm("pause");
#endif
#elif
__asm { pause };
#endif
#elif
__asm { pause };
#endif
}
void tc_interlockedExchange(void *dest, const int64_t exchange)
{
#if defined( __linux__ ) || defined( __APPLE__ )
#if defined( __linux__ ) || defined( __APPLE__ ) || defined( __FreeBSD__)
// not working
assert(false);
//__sync_lock_test_and_set((int64_t*)dest, exchange);
@ -174,7 +180,8 @@ void tc_interlockedExchange(void *dest, const int64_t exchange)
NxI32 tc_interlockedCompareExchange(void *dest, NxI32 exchange, NxI32 compare)
{
#if defined( __linux__ ) || defined( __APPLE__ )
#if defined( __linux__ ) || defined( __APPLE__ ) || defined( __FreeBSD__)
// not working
assert(false);
return 0;
@ -203,7 +210,7 @@ NxI32 tc_interlockedCompareExchange(void *dest, NxI32 exchange, NxI32 compare)
NxI32 tc_interlockedCompareExchange(void *dest, const NxI32 exchange1, const NxI32 exchange2, const NxI32 compare1, const NxI32 compare2)
{
#if defined( __linux__ ) || defined( __APPLE__ )
#if defined( __linux__ ) || defined( __APPLE__ ) || defined( __FreeBSD__)
// not working
assert(false);
return 0;
@ -239,7 +246,8 @@ public:
{
#if defined(WIN32) || defined(_XBOX)
InitializeCriticalSection(&m_Mutex);
#elif defined(__APPLE__) || defined(__linux__)
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
pthread_mutexattr_t mutexAttr; // Mutex Attribute
VERIFY( pthread_mutexattr_init(&mutexAttr) == 0 );
VERIFY( pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE_NP) == 0 );
@ -252,7 +260,8 @@ public:
{
#if defined(WIN32) || defined(_XBOX)
DeleteCriticalSection(&m_Mutex);
#elif defined(__APPLE__) || defined(__linux__)
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
VERIFY( pthread_mutex_destroy(&m_Mutex) == 0 );
#endif
}
@ -261,7 +270,8 @@ public:
{
#if defined(WIN32) || defined(_XBOX)
EnterCriticalSection(&m_Mutex);
#elif defined(__APPLE__) || defined(__linux__)
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
VERIFY( pthread_mutex_lock(&m_Mutex) == 0 );
#endif
}
@ -273,7 +283,8 @@ public:
//assert(("TryEnterCriticalSection seems to not work on XP???", 0));
bRet = TryEnterCriticalSection(&m_Mutex) ? true : false;
return bRet;
#elif defined(__APPLE__) || defined(__linux__)
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
NxI32 result = pthread_mutex_trylock(&m_Mutex);
return (result == 0);
#endif
@ -283,7 +294,8 @@ public:
{
#if defined(WIN32) || defined(_XBOX)
LeaveCriticalSection(&m_Mutex);
#elif defined(__APPLE__) || defined(__linux__)
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
VERIFY( pthread_mutex_unlock(&m_Mutex) == 0 );
#endif
}
@ -291,7 +303,8 @@ public:
private:
#if defined(WIN32) || defined(_XBOX)
CRITICAL_SECTION m_Mutex;
#elif defined(__APPLE__) || defined(__linux__)
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
pthread_mutex_t m_Mutex;
#endif
};
@ -310,7 +323,8 @@ void tc_releaseThreadMutex(ThreadMutex *tm)
#if defined(WIN32) || defined(_XBOX)
static unsigned long __stdcall _ThreadWorkerFunc(LPVOID arg);
#elif defined(__APPLE__) || defined(__linux__)
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
static void* _ThreadWorkerFunc(void* arg);
#endif
@ -322,7 +336,8 @@ public:
mInterface = iface;
#if defined(WIN32) || defined(_XBOX)
mThread = CreateThread(0, 0, _ThreadWorkerFunc, this, 0, 0);
#elif defined(__APPLE__) || defined(__linux__)
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
VERIFY( pthread_create(&mThread, NULL, _ThreadWorkerFunc, this) == 0 );
#endif
}
@ -347,7 +362,8 @@ private:
ThreadInterface *mInterface;
#if defined(WIN32) || defined(_XBOX)
HANDLE mThread;
#elif defined(__APPLE__) || defined(__linux__)
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
pthread_t mThread;
#endif
};
@ -367,7 +383,8 @@ void tc_releaseThread(Thread *t)
#if defined(WIN32) || defined(_XBOX)
static unsigned long __stdcall _ThreadWorkerFunc(LPVOID arg)
#elif defined(__APPLE__) || defined(__linux__)
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
static void* _ThreadWorkerFunc(void* arg)
#endif
{
@ -384,7 +401,8 @@ public:
{
#if defined(WIN32) || defined(_XBOX)
mEvent = ::CreateEventA(NULL,TRUE,TRUE,"ThreadEvent");
#elif defined(__APPLE__) || defined(__linux__)
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
pthread_mutexattr_t mutexAttr; // Mutex Attribute
VERIFY( pthread_mutexattr_init(&mutexAttr) == 0 );
VERIFY( pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE_NP) == 0 );
@ -401,7 +419,8 @@ public:
{
::CloseHandle(mEvent);
}
#elif defined(__APPLE__) || defined(__linux__)
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
VERIFY( pthread_cond_destroy(&mEvent) == 0 );
VERIFY( pthread_mutex_destroy(&mEventMutex) == 0 );
#endif
@ -414,7 +433,8 @@ public:
{
::SetEvent(mEvent);
}
#elif defined(__APPLE__) || defined(__linux__)
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
VERIFY( pthread_mutex_lock(&mEventMutex) == 0 );
VERIFY( pthread_cond_signal(&mEvent) == 0 );
VERIFY( pthread_mutex_unlock(&mEventMutex) == 0 );
@ -438,7 +458,8 @@ public:
{
::WaitForSingleObject(mEvent,ms);
}
#elif defined(__APPLE__) || defined(__linux__)
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
VERIFY( pthread_mutex_lock(&mEventMutex) == 0 );
if (ms == 0xffffffff)
{
@ -468,7 +489,8 @@ public:
private:
#if defined(WIN32) || defined(_XBOX)
HANDLE mEvent;
#elif defined(__APPLE__) || defined(__linux__)
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
pthread_mutex_t mEventMutex;
pthread_cond_t mEvent;
#endif

View file

@ -43,7 +43,7 @@
#include <iosfwd> // for ostream forward-declaration
// Don't use bits/type_traits.h on Linux - Andrew Galante, GG 8/2/2009
#if !defined(_MSC_VER) && !defined(__CELLOS_LV2__) && !defined(__APPLE__) && !defined(__linux__)
#if !defined(_MSC_VER) && !defined(__CELLOS_LV2__) && !defined(__APPLE__) && !defined(__linux__) && !defined( __FreeBSD__)
#ifdef __MINGW32__
#define HAVE_TYPE_TRAITS
#include <bits/type_traits.h>

View file

@ -275,6 +275,8 @@ public:
/// Returns the datablock for this object.
GameBaseData* getDataBlock() { return mDataBlock; }
/// returns the datablock name for this object
StringTableEntry getTypeHint() const override { return (mDataBlock) ? mDataBlock->getName() : StringTable->EmptyString(); };
/// Called when a new datablock is set. This allows subclasses to
/// appropriately handle new datablocks.
///

View file

@ -166,6 +166,8 @@ class SpawnSphere : public MissionMarker
bool mAutoSpawn;
bool mSpawnTransform;
/// returns the datablock spawned for this object
StringTableEntry getTypeHint() const override { return (mSpawnDataBlock.isNotEmpty()) ? mSpawnDataBlock.c_str() : StringTable->EmptyString(); };
// Radius/weight info
F32 mRadius;
F32 mSphereWeight;

View file

@ -93,6 +93,10 @@ void Prefab::initPersistFields()
Parent::initPersistFields();
}
StringTableEntry Prefab::getTypeHint() const
{
return (mFilename != StringTable->EmptyString()) ? StringTable->insert(Torque::Path(mFilename).getFileName().c_str()) : StringTable->EmptyString();
}
extern bool gEditingMission;
bool Prefab::onAdd()

View file

@ -60,6 +60,9 @@ public:
static void initPersistFields();
/// returns the filename for this object
StringTableEntry getTypeHint() const override;
// SimObject
virtual bool onAdd();
virtual void onRemove();

View file

@ -106,6 +106,8 @@ class SFXEmitter : public SceneObject
DECLARE_SOUNDASSET(SFXEmitter, Sound);
DECLARE_ASSET_NET_SETGET(SFXEmitter, Sound, DirtyUpdateMask);
/// returns the shape asset used for this object
StringTableEntry getTypeHint() const override { return (getSoundAsset()) ? getSoundAsset()->getAssetName() : StringTable->EmptyString(); }
/// The sound source for the emitter.
SFXSource *mSource;

View file

@ -237,6 +237,8 @@ public:
DECLARE_CONOBJECT(TSStatic);
static void initPersistFields();
/// returns the shape asset used for this object
StringTableEntry getTypeHint() const override { return (getShapeAsset()) ? getShapeAsset()->getAssetName(): StringTable->EmptyString(); }
static void consoleInit();
static bool _setFieldSkin(void* object, const char* index, const char* data);
static const char* _getFieldSkin(void* object, const char* data);

View file

@ -738,7 +738,7 @@ DefineEngineFunction( strrepeat, const char*, ( const char* str, S32 numTimes, c
{
StringBuilder result;
bool isFirst = false;
for( U32 i = 0; i < numTimes; ++ i )
for( S32 i = 0; i < numTimes; ++ i )
{
if( !isFirst )
result.append( delimiter );

View file

@ -549,6 +549,9 @@ class SimObject: public ConsoleObject, public TamlCallbacks
/// Get the internal name of this control
StringTableEntry getInternalName() const { return mInternalName; }
/// type-specified slot for returning hints for the main difference between object instances
virtual StringTableEntry getTypeHint() const { return StringTable->EmptyString(); }
/// Set the original name of this control
void setOriginalName(const char* originalName);

View file

@ -56,8 +56,8 @@ GFXGLTextureObject::GFXGLTextureObject(GFXDevice * aDevice, GFXTextureProfile *p
glGenBuffers(1, &mBuffer);
}
GFXGLTextureObject::~GFXGLTextureObject()
{
GFXGLTextureObject::~GFXGLTextureObject()
{
glDeleteTextures(1, &mHandle);
glDeleteBuffers(1, &mBuffer);
delete[] mZombieCache;
@ -81,7 +81,7 @@ GFXLockedRect* GFXGLTextureObject::lock(U32 mipLevel, RectI *inRect)
{
mLockedRectRect = RectI(0, 0, width, height);
}
mLockedRect.pitch = mLockedRectRect.extent.x * mBytesPerTexel;
// CodeReview [ags 12/19/07] This one texel boundary is necessary to keep the clipmap code from crashing. Figure out why.
@ -93,7 +93,7 @@ GFXLockedRect* GFXGLTextureObject::lock(U32 mipLevel, RectI *inRect)
#ifdef TORQUE_DEBUG
mFrameAllocatorMarkGuard = FrameAllocator::getWaterMark();
#endif
if( !mLockedRect.bits )
return NULL;
@ -117,12 +117,12 @@ void GFXGLTextureObject::unlock(U32 mipLevel)
glTexSubImage3D(mBinding, mipLevel, mLockedRectRect.point.x, mLockedRectRect.point.y, z,
mLockedRectRect.extent.x, mLockedRectRect.extent.y, z, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
else if(mBinding == GL_TEXTURE_2D)
glTexSubImage2D(mBinding, mipLevel, mLockedRectRect.point.x, mLockedRectRect.point.y,
glTexSubImage2D(mBinding, mipLevel, mLockedRectRect.point.x, mLockedRectRect.point.y,
mLockedRectRect.extent.x, mLockedRectRect.extent.y, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
else if(mBinding == GL_TEXTURE_1D)
glTexSubImage1D(mBinding, mipLevel, (mLockedRectRect.point.x > 1 ? mLockedRectRect.point.x : mLockedRectRect.point.y),
glTexSubImage1D(mBinding, mipLevel, (mLockedRectRect.point.x > 1 ? mLockedRectRect.point.x : mLockedRectRect.point.y),
(mLockedRectRect.extent.x > 1 ? mLockedRectRect.extent.x : mLockedRectRect.extent.y), GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
mLockedRect.bits = NULL;
@ -138,7 +138,7 @@ void GFXGLTextureObject::release()
{
glDeleteTextures(1, &mHandle);
glDeleteBuffers(1, &mBuffer);
mHandle = 0;
mBuffer = 0;
}
@ -174,7 +174,7 @@ bool GFXGLTextureObject::copyToBmp(GBitmap * bmp)
U8 srcBytesPerPixel = GFXFormat_getByteSize( mFormat );
FrameAllocatorMarker mem;
U32 mipLevels = getMipLevels();
for (U32 mip = 0; mip < mipLevels; mip++)
@ -204,7 +204,7 @@ bool GFXGLTextureObject::copyToBmp(GBitmap * bmp)
}
}
}
glBindTexture(mBinding, NULL);
glBindTexture(mBinding, 0);
return true;
}
@ -236,8 +236,8 @@ U8* GFXGLTextureObject::getTextureData( U32 mip )
AssertFatal( mMipLevels, "");
mip = (mip < mMipLevels) ? mip : 0;
const U32 dataSize = ImageUtil::isCompressedFormat(mFormat)
? getCompressedSurfaceSize( mFormat, mTextureSize.x, mTextureSize.y, mip )
const U32 dataSize = ImageUtil::isCompressedFormat(mFormat)
? getCompressedSurfaceSize( mFormat, mTextureSize.x, mTextureSize.y, mip )
: (mTextureSize.x >> mip) * (mTextureSize.y >> mip) * mBytesPerTexel;
U8* data = new U8[dataSize];
@ -258,10 +258,10 @@ void GFXGLTextureObject::copyIntoCache()
U32 cacheSize = mTextureSize.x * mTextureSize.y;
if(mBinding == GL_TEXTURE_3D)
cacheSize *= mTextureSize.z;
cacheSize *= mBytesPerTexel;
mZombieCache = new U8[cacheSize];
glGetTexImage(mBinding, 0, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
}
@ -269,7 +269,7 @@ void GFXGLTextureObject::reloadFromCache()
{
if(!mZombieCache)
return;
if(mBinding == GL_TEXTURE_3D)
{
static_cast<GFXGLTextureManager*>(TEXMGR)->_loadTexture(this, mZombieCache);
@ -277,7 +277,7 @@ void GFXGLTextureObject::reloadFromCache()
mZombieCache = NULL;
return;
}
PRESERVE_TEXTURE(mBinding);
glBindTexture(mBinding, mHandle);
@ -285,10 +285,10 @@ void GFXGLTextureObject::reloadFromCache()
glTexSubImage2D(mBinding, 0, 0, 0, mTextureSize.x, mTextureSize.y, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
else if(mBinding == GL_TEXTURE_1D)
glTexSubImage1D(mBinding, 0, 0, (mTextureSize.x > 1 ? mTextureSize.x : mTextureSize.y), GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
if(mMipLevels != 1)
glGenerateMipmap(mBinding);
delete[] mZombieCache;
mZombieCache = NULL;
mIsZombie = false;
@ -298,11 +298,11 @@ void GFXGLTextureObject::zombify()
{
if(mIsZombie)
return;
mIsZombie = true;
if(!mProfile->doStoreBitmap() && !mProfile->isRenderTarget() && !mProfile->isDynamic() && !mProfile->isZTarget())
copyIntoCache();
release();
}
@ -310,7 +310,7 @@ void GFXGLTextureObject::resurrect()
{
if(!mIsZombie)
return;
glGenTextures(1, &mHandle);
glGenBuffers(1, &mBuffer);
}
@ -329,6 +329,6 @@ const String GFXGLTextureObject::describeSelf() const
{
String ret = Parent::describeSelf();
ret += String::ToString(" GL Handle: %i", mHandle);
return ret;
}

View file

@ -425,6 +425,7 @@ U32 GuiTreeViewCtrl::Item::getDisplayTextLength()
StringTableEntry name = obj->getName();
StringTableEntry internalName = obj->getInternalName();
StringTableEntry typeHint = obj->getTypeHint();
StringTableEntry className = obj->getClassName();
if( showInternalNameOnly() )
@ -466,6 +467,11 @@ U32 GuiTreeViewCtrl::Item::getDisplayTextLength()
if( internalName && internalName[ 0 ] )
len += dStrlen( internalName ) + 3; // ' [<internalname>]'
}
if ( mState.test(ShowTypeHint) )
{
if (typeHint && typeHint[0])
len += dStrlen(typeHint) + 3;
}
if( mState.test( Marked ) )
{
len += 1; // '*<name>'
@ -502,8 +508,10 @@ void GuiTreeViewCtrl::Item::getDisplayText(U32 bufLen, char *buf)
{
const char* pObjName = pObject->getName();
const char* pInternalName = pObject->getInternalName();
const char* pTypeHint = pObject->getTypeHint();
bool hasInternalName = pInternalName && pInternalName[0];
bool hasTypeHint = pTypeHint && pTypeHint[0];
bool hasObjectName = pObjName && pObjName[0];
const char* pClassName = pObject->getClassName();
@ -566,6 +574,14 @@ void GuiTreeViewCtrl::Item::getDisplayText(U32 bufLen, char *buf)
else
dSprintf(ptr, len, " [%s]", pInternalName);
}
if (hasTypeHint && mState.test(ShowTypeHint))
{
if (mState.test(Item::Marked))
dSprintf(ptr, len, " *<%s>", pTypeHint);
else
dSprintf(ptr, len, " <%s>", pTypeHint);
}
}
}
else
@ -835,6 +851,7 @@ GuiTreeViewCtrl::GuiTreeViewCtrl()
mShowClassNames = true;
mShowObjectNames = true;
mShowInternalNames = true;
mShowTypeHints = false;
mShowClassNameForUnnamedObjects = false;
mFlags.set(RebuildVisible);
@ -894,7 +911,10 @@ void GuiTreeViewCtrl::initPersistFields()
addField( "showObjectNames", TypeBool, Offset( mShowObjectNames, GuiTreeViewCtrl ),
"If true, item text labels for objects will include object names." );
addField( "showInternalNames", TypeBool, Offset( mShowInternalNames, GuiTreeViewCtrl ),
"If true, item text labels for obje ts will include internal names." );
"If true, item text labels for objets will include internal names." );
addField("showTypeHints", TypeBool, Offset(mShowTypeHints, GuiTreeViewCtrl),
"If true, item text labels for objets will include TypeHints.");
addField( "showClassNameForUnnamedObjects", TypeBool, Offset( mShowClassNameForUnnamedObjects, GuiTreeViewCtrl ),
"If true, class names will be used as object names for unnamed objects." );
addField( "compareToObjectID", TypeBool, Offset(mCompareToObjectID, GuiTreeViewCtrl));
@ -1794,6 +1814,7 @@ bool GuiTreeViewCtrl::onAdd()
mShowClassNames = false;
mShowObjectNames = false;
mShowInternalNames = true;
mShowTypeHints = false;
}
const char* objectNamesOnly = getDataField( sObjectNamesOnly, NULL );
@ -1803,6 +1824,7 @@ bool GuiTreeViewCtrl::onAdd()
mShowClassNames = false;
mShowObjectNames = true;
mShowInternalNames = false;
mShowTypeHints = false;
}
}
@ -4109,6 +4131,10 @@ GuiTreeViewCtrl::Item* GuiTreeViewCtrl::addInspectorDataItem(Item *parent, SimOb
item->mState.clear( Item::ShowInternalName );
else
item->mState.set( Item::ShowInternalName );
if (!mShowTypeHints)
item->mState.clear(Item::ShowTypeHint);
else
item->mState.set(Item::ShowTypeHint);
if( mShowClassNameForUnnamedObjects )
item->mState.set( Item::ShowClassNameForUnnamed );

View file

@ -79,6 +79,7 @@ class GuiTreeViewCtrl : public GuiArrayCtrl
ForceItemName = BIT(15),
ForceDragTarget = BIT(16),
DenyDrag = BIT(17),
ShowTypeHint = BIT(18),
};
GuiTreeViewCtrl* mParentControl;
@ -395,6 +396,9 @@ class GuiTreeViewCtrl : public GuiArrayCtrl
/// If true, internal names will be included in inspector tree item labels.
bool mShowInternalNames;
/// If true, TypeHints will be included in inspector tree item labels.
bool mShowTypeHints;
/// If true, class names will be used as object names for unnamed objects.
bool mShowClassNameForUnnamedObjects;

View file

@ -33,7 +33,7 @@ bool PopupMenu::smSelectionEventHandled = false;
/// Event class used to remove popup menus from the event notification in a safe way
class PopUpNotifyRemoveEvent : public SimEvent
{
{
public:
void process(SimObject *object)
{
@ -46,7 +46,7 @@ public:
//-----------------------------------------------------------------------------
PopupMenu::PopupMenu()
{
mMenuItems = NULL;
mMenuItems = 0;
mMenuBarCtrl = nullptr;
mBarTitle = StringTable->EmptyString();
@ -115,7 +115,7 @@ void PopupMenu::onMenuSelect()
//-----------------------------------------------------------------------------
void PopupMenu::handleSelectEvent(U32 popID, U32 command)
{
{
}
//-----------------------------------------------------------------------------
@ -199,7 +199,7 @@ bool PopupMenu::setItem(S32 pos, const char *title, const char* accelerator, con
{
mMenuItems[i].mID = pos;
mMenuItems[i].mCMD = cmd;
if (accelerator && accelerator[0])
mMenuItems[i].mAccelerator = dStrdup(accelerator);
else
@ -207,7 +207,7 @@ bool PopupMenu::setItem(S32 pos, const char *title, const char* accelerator, con
return true;
}
}
return false;
}

View file

@ -353,6 +353,17 @@ DefineEngineFunction( mLerp, F32, ( F32 v1, F32 v2, F32 time ),,
return mLerp( v1, v2, time );
}
DefineEngineFunction(mInvLerp, F32, (F32 v1, F32 v2, F32 point), ,
"Calculate the percentage of a point along a line.\n"
"@param v1 Interpolate From Input value."
"@param v2 Interpolate To Input value."
"@param point Point along range."
"@returns normalized time used to interpolate values"
"@ingroup Math")
{
return mInvLerp(v1, v2, point);
}
DefineEngineFunction( mPi, F32, (),,
"Return the value of PI (half-circle in radians).\n"
"@returns The value of PI."

View file

@ -265,6 +265,14 @@ inline T mLerp( const T &v1, const T &v2, F32 factor )
return ( v1 * ( 1.0f - factor ) ) + ( v2 * factor );
}
/// Template function for determining a percentage of interpolation between any two
/// types which implement operators for scalar multiply and addition.
template <typename T>
inline T mInvLerp(const T& v1, const T& v2, F32 point)
{
return (point - v1) / (v2 - v1);
}
inline S32 mMulDiv(S32 a, S32 b, S32 c)
{
return m_mulDivS32(a, b, c);

View file

@ -191,7 +191,7 @@ EulerF MatrixF::toEuler() const
void MatrixF::dumpMatrix(const char *caption /* =NULL */) const
{
U32 size = dStrlen(caption);
U32 size = (caption == NULL)? 0 : dStrlen(caption);
FrameTemp<char> spacer(size+1);
char *spacerRef = spacer;

View file

@ -20,7 +20,7 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef __APPLE__
#if !defined( __APPLE__ ) && !defined( __FreeBSD__ )
#include <fstream>
#include <iostream>
@ -38,14 +38,18 @@
Platform::SystemInfo_struct Platform::SystemInfo;
static inline void rtrim(std::string &s)
{
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
// trim from start (in place)
static inline void ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
return !std::isspace(ch);
}));
}
static inline void ltrim(std::string &s)
{
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
// trim from end (in place)
static inline void rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
return !std::isspace(ch);
}).base(), s.end());
}
static void getCPUInformation()
@ -183,7 +187,7 @@ static void getCPUInformation()
SetProcessorInfo(Platform::SystemInfo.processor, vendorString.c_str(), brandString.c_str());
}
void Processor::init()
void Processor::init()
{
getCPUInformation();
@ -244,11 +248,11 @@ namespace CPUInfo
}
else if (!Platform::SystemInfo.processor.isHyperThreaded && Platform::SystemInfo.processor.numPhysicalProcessors == 1)
{
return CONFIG_SingleCoreAndHTNotCapable;
return CONFIG_SingleCoreAndHTNotCapable;
}
return CONFIG_MultiCoreAndHTEnabled;
}
}; // namespace CPUInfo
#endif
#endif

View file

@ -34,6 +34,7 @@
#include <unistd.h>
#include <signal.h>
#include "console/engineAPI.h"
#include "core/util/journal/process.h"
#ifndef TORQUE_DEDICATED
#include <SDL.h>
#endif
@ -48,7 +49,7 @@ static void CheckExitCode(S64 exitCode)
{
if (exitCode != 0)
{
Con::errorf(ConsoleLogEntry::General,
Con::errorf(ConsoleLogEntry::General,
"Nonzero exit code: %d, triggering SIGSEGV for core dump",
exitCode);
kill(getpid(), SIGSEGV);
@ -62,7 +63,7 @@ static void SignalHandler(int sigtype)
{
signal(SIGSEGV, SIG_DFL);
signal(SIGTRAP, SIG_DFL);
// restore the signal handling to default so that we don't get into
// restore the signal handling to default so that we don't get into
// a crash loop with ImmediateShutdown
ImmediateShutdown(-sigtype, sigtype);
}
@ -85,7 +86,7 @@ void Cleanup(bool minimal)
StdConsole::destroy();
#ifndef TORQUE_DEDICATED
#ifndef TORQUE_DEDICATED
SDL_Quit();
#endif
}
@ -105,7 +106,7 @@ void ImmediateShutdown(S32 exitCode, S32 signalNum)
}
else
{
// there is a problem in kernel 2.4.17 which causes a hang when a segfault
// there is a problem in kernel 2.4.17 which causes a hang when a segfault
// occurs. also subsequent runs of "ps" will hang and the machine has to be
// hard reset to clear up the problem
// JMQ: this bug appears to be fixed in 2.4.18
@ -130,7 +131,7 @@ void ProcessControlInit()
signal(SIGTTIN, SIG_IGN);
signal(SIGTTOU, SIG_IGN);
// we're not interested in the exit status of child processes, so this
// we're not interested in the exit status of child processes, so this
// prevents zombies from accumulating.
#if defined(__FreeBSD__) || defined(__APPLE__)
signal(SIGCHLD, SIG_IGN);
@ -147,6 +148,7 @@ void ProcessControlInit()
//-----------------------------------------------------------------------------
void Platform::postQuitMessage(const S32 in_quitVal)
{
// if we have a window send a quit event, otherwise just force shutdown
#if 0
if (x86UNIXState->windowCreated())
@ -155,18 +157,19 @@ void Platform::postQuitMessage(const S32 in_quitVal)
SendQuitEvent();
}
else
#endif
{
forceShutdown(in_quitVal);
}
#endif
Process::requestShutdown();
}
//-----------------------------------------------------------------------------
void Platform::debugBreak()
{
// in windows, "Calling DebugBreak causes the program to display
// in windows, "Calling DebugBreak causes the program to display
// a dialog box as if it had crashed." So we segfault.
Con::errorf(ConsoleLogEntry::General,
Con::errorf(ConsoleLogEntry::General,
"Platform::debugBreak: triggering SIGSEGV for core dump");
//kill(getpid(), SIGSEGV);
@ -197,20 +200,20 @@ void Platform::forceShutdown(S32 returnValue)
void Platform::outputDebugString(const char *string, ...)
{
char buffer[2048];
va_list args;
va_start( args, string );
dVsprintf( buffer, sizeof(buffer), string, args );
va_end( args );
U32 length = dStrlen(buffer);
if( length == (sizeof(buffer) - 1 ) )
length--;
buffer[length++] = '\n';
buffer[length] = '\0';
fwrite(buffer, sizeof(char), length, stderr);
}
@ -234,4 +237,4 @@ void Platform::restartInstance()
*/
exit(0);
}
#endif
#endif

View file

@ -0,0 +1,148 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
// XXTH used for FreeBSD
// Note: SDL_cpuinfo have not all information, but better than using
// "sysctl hw"
//
//-----------------------------------------------------------------------------
#if defined( __FreeBSD__ )
#include "SDL.h"
#include "platform/platformCPUCount.h"
#include "console/console.h"
#include <math/mMathFn.h>
Platform::SystemInfo_struct Platform::SystemInfo;
void Processor::init()
{
S32 lCpuCount = SDL_GetCPUCount();
Platform::SystemInfo.processor.numLogicalProcessors = lCpuCount;
//sdl dont have logical/physical CPU count so ... time to guess
if (lCpuCount > 1)
{
Platform::SystemInfo.processor.numPhysicalProcessors = mFloor(lCpuCount / 2); // guessing ;
Platform::SystemInfo.processor.isMultiCore = true;
//modern CPU should have isHyperThreaded
Platform::SystemInfo.processor.isHyperThreaded = true;
}
else {
Platform::SystemInfo.processor.numPhysicalProcessors = lCpuCount; // guessing ;
Platform::SystemInfo.processor.isMultiCore = false;
Platform::SystemInfo.processor.isHyperThreaded = false;
}
//hackfest
Platform::SystemInfo.processor.mhz = 2666;
#if defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_X32)
// Set sane default information
Platform::SystemInfo.processor.name = StringTable->insert("Unknown Processor");
Platform::SystemInfo.processor.properties |= CPU_PROP_C | CPU_PROP_FPU | CPU_PROP_LE ;
Platform::SystemInfo.processor.type = CPU_X86Compatible;
#elif defined(TORQUE_CPU_ARM32) || defined(TORQUE_CPU_ARM64)
Platform::SystemInfo.processor.type = CPU_ArmCompatible;
Platform::SystemInfo.processor.name = StringTable->insert("Unknown ARM Processor");
Platform::SystemInfo.processor.properties = CPU_PROP_C;
#else
#warning Unsupported CPU
#endif
// Set 64bit flag
#if defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_ARM64)
Platform::SystemInfo.processor.properties |= CPU_PROP_64bit;
#endif
Con::printf("Processor Init:");
Con::printf(" CPU count: %d", lCpuCount);
Con::printf(" CacheLine size: %d", SDL_GetCPUCacheLineSize());
if (lCpuCount > 1) {
Platform::SystemInfo.processor.properties |= CPU_PROP_MP;
Con::printf(" MultiCore CPU detected" );
}
Con::printf(" RAM: %d MB", SDL_GetSystemRAM());
if (SDL_HasMMX()) {
Platform::SystemInfo.processor.properties |= CPU_PROP_MMX;
Con::printf(" MMX detected" );
}
if (SDL_HasSSE()) {
Platform::SystemInfo.processor.properties |= CPU_PROP_SSE;
Con::printf(" SSE detected" );
}
if (SDL_HasSSE2()) {
Platform::SystemInfo.processor.properties |= CPU_PROP_SSE2;
Con::printf(" SSE2 detected" );
}
if (SDL_HasSSE3()) {
Platform::SystemInfo.processor.properties |= CPU_PROP_SSE3;
Con::printf(" SSE3 detected" );
}
if (SDL_HasSSE41()) {
Platform::SystemInfo.processor.properties |= CPU_PROP_SSE4_1;
Con::printf(" SSE4.1 detected" );
}
if (SDL_HasSSE42()) {
Platform::SystemInfo.processor.properties |= CPU_PROP_SSE4_2;
Con::printf(" SSE4.2 detected" );
}
if (SDL_HasSSE42()) {
Platform::SystemInfo.processor.properties |= CPU_PROP_SSE4_2;
Con::printf(" SSE4.2 detected" );
}
if (SDL_HasAVX() || SDL_HasAVX2()) {
Platform::SystemInfo.processor.properties |= CPU_PROP_AVX;
Con::printf(" AVX detected" );
}
if (SDL_HasNEON()) {
Platform::SystemInfo.processor.properties |= CPU_PROP_NEON;
Con::printf(" NEON detected" );
}
Con::printf(" ");
SetProcessorInfo(Platform::SystemInfo.processor, "Unknown", "Unknown");
}
namespace CPUInfo
{
EConfig CPUCount(U32 &logical, U32 &physical)
{
// We don't set logical or physical here because it's already been determined by this point
if (Platform::SystemInfo.processor.isHyperThreaded && Platform::SystemInfo.processor.numPhysicalProcessors == 1)
{
return CONFIG_SingleCoreHTEnabled;
}
else if (!Platform::SystemInfo.processor.isHyperThreaded && Platform::SystemInfo.processor.numPhysicalProcessors > 1)
{
return CONFIG_MultiCoreAndHTNotCapable;
}
else if (!Platform::SystemInfo.processor.isHyperThreaded && Platform::SystemInfo.processor.numPhysicalProcessors == 1)
{
return CONFIG_SingleCoreAndHTNotCapable;
}
return CONFIG_MultiCoreAndHTEnabled;
}
}; // namespace CPUInfo
#endif // defined( __FreeBSD__ )

View file

@ -65,7 +65,7 @@ class TSCallback
{
public:
virtual ~TSCallback() {}
virtual void setNodeTransform(TSShapeInstance * si, S32 nodeIndex, MatrixF & localTransform) = 0;
};
@ -114,13 +114,13 @@ class TSShapeInstance
struct ObjectInstance
{
virtual ~ObjectInstance() {}
/// this needs to be set before using an objectInstance...tells us where to
/// look for the transforms...gets set be shape instance 'setStatics' method
const Vector<MatrixF> *mTransforms;
S32 nodeIndex;
/// Gets the transform of this object
inline const MatrixF& getTransform() const
{
@ -166,8 +166,8 @@ class TSShapeInstance
/// If true this mesh is forced to be hidden
/// regardless of the animation state.
bool forceHidden;
/// The time at which this mesh
/// The time at which this mesh
/// was last rendered.
U32 mLastTime;
@ -248,7 +248,7 @@ class TSShapeInstance
static Vector<TSThread*> smTranslationThreads;
static Vector<TSThread*> smScaleThreads;
/// @}
TSMaterialList* mMaterialList; ///< by default, points to hShape material list
//-------------------------------------------------------------------------------------
// Misc.
@ -333,17 +333,17 @@ protected:
TSShape* getShape() const { return mShape; }
TSMaterialList* getMaterialList() const { return mMaterialList; }
/// Set the material list without taking ownership.
/// @see cloneMaterialList
void setMaterialList( TSMaterialList *matList );
/// Call this to own the material list -- i.e., we'll make a copy of the
/// Call this to own the material list -- i.e., we'll make a copy of the
/// currently set material list and be responsible for deleting it. You
/// can pass an optional feature set for initializing the cloned materials.
void cloneMaterialList( const FeatureSet *features = NULL );
void cloneMaterialList( const FeatureSet *features = NULL );
/// Initializes or re-initializes the material list with
/// Initializes or re-initializes the material list with
/// an optional feature set.
void initMaterialList( const FeatureSet *features = NULL );
@ -469,7 +469,7 @@ protected:
static F32 smDetailAdjust;
/// If this is set to a positive pixel value shapes
/// with a smaller pixel size than this will skip
/// with a smaller pixel size than this will skip
/// rendering entirely.
static F32 smSmallestVisiblePixelSize;
@ -490,7 +490,7 @@ protected:
void renderDebugNormals( F32 normalScalar, S32 dl );
/// Render all node transforms as small axis gizmos. It is recommended
/// that prior to calling this, shapeInstance::animate is called so that
/// that prior to calling this, shapeInstance::animate is called so that
/// nodes are in object space and that the GFX state is setup for
/// rendering in model space.
void renderDebugNodes();
@ -518,7 +518,7 @@ protected:
/// Sets the 'forceHidden' state on the named mesh.
/// @see MeshObjectInstance::forceHidden
void setMeshForceHidden( const char *meshName, bool hidden );
/// Sets the 'forceHidden' state on a mesh.
/// @see MeshObjectInstance::forceHidden
void setMeshForceHidden( S32 meshIndex, bool hidden );
@ -558,8 +558,8 @@ protected:
void setCurrentDetail( S32 dl, F32 intraDL = 1.0f );
/// Helper function which internally calls setDetailFromDistance.
S32 setDetailFromPosAndScale( const SceneRenderState *state,
const Point3F &pos,
S32 setDetailFromPosAndScale( const SceneRenderState *state,
const Point3F &pos,
const Point3F &scale );
/// Selects the current detail level using the scaled
@ -788,7 +788,7 @@ class TSThread
keyPos = 0;
mSeqPos = 0;
mShapeInstance = NULL;
makePath = NULL;
makePath = false;
priority = 0;
sequence = 0;
timeScale = 1.0f;

View file

@ -172,6 +172,7 @@ $guiContent = new GuiControl() {
showClassNames = "0";
showObjectNames = "1";
showInternalNames = "1";
showTypeHints = "1";
showClassNameForUnnamedObjects = "1";
};
};