- removed STL from the Bullet library: replace std::vector by btAlignedObjectArray. Also removed the std::set for overlapping pair set, and turned it into an overlapping pair array. The SAP only adds objects, never removed. Removal is postponed for during traversal of overlapping pairs (duplicates and non-overlapping pairs are removed during that traversal).
- added heap sort and binary search/linear search to btAlignedObjectArray - fixed wrong cast, thanks Hamstray, http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1015
This commit is contained in:
@@ -74,6 +74,8 @@ class btAlignedObjectArray
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
@@ -172,6 +174,127 @@ class btAlignedObjectArray
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class less
|
||||
{
|
||||
public:
|
||||
|
||||
bool operator() ( const T& a, const T& b )
|
||||
{
|
||||
return ( a < b );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
///heap sort from http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Sort/Heap/
|
||||
template <typename L>
|
||||
void downHeap(T *pArr, int k, int n,L CompareFunc)
|
||||
{
|
||||
/* PRE: a[k+1..N] is a heap */
|
||||
/* POST: a[k..N] is a heap */
|
||||
|
||||
T temp = pArr[k - 1];
|
||||
/* k has child(s) */
|
||||
while (k <= n/2)
|
||||
{
|
||||
int child = 2*k;
|
||||
|
||||
if ((child < n) && CompareFunc(pArr[child - 1] , pArr[child]))
|
||||
{
|
||||
child++;
|
||||
}
|
||||
/* pick larger child */
|
||||
if (CompareFunc(temp , pArr[child - 1]))
|
||||
{
|
||||
/* move child up */
|
||||
pArr[k - 1] = pArr[child - 1];
|
||||
k = child;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
pArr[k - 1] = temp;
|
||||
} /*downHeap*/
|
||||
|
||||
void swap(int index0,int index1)
|
||||
{
|
||||
T temp = m_data[index0];
|
||||
m_data[index0] = m_data[index1];
|
||||
m_data[index1] = temp;
|
||||
}
|
||||
|
||||
template <typename L>
|
||||
void heapSort(L CompareFunc)
|
||||
{
|
||||
/* sort a[0..N-1], N.B. 0 to N-1 */
|
||||
int k;
|
||||
int n = m_size;
|
||||
for (k = n/2; k > 0; k--)
|
||||
{
|
||||
downHeap(m_data, k, n, CompareFunc);
|
||||
}
|
||||
|
||||
/* a[1..N] is now a heap */
|
||||
while ( n>=1 )
|
||||
{
|
||||
swap(0,n-1); /* largest of a[0..n-1] */
|
||||
|
||||
|
||||
n = n - 1;
|
||||
/* restore a[1..i-1] heap */
|
||||
downHeap(m_data, 1, n, CompareFunc);
|
||||
}
|
||||
}
|
||||
|
||||
///non-recursive binary search, assumes sorted array
|
||||
int findBinarySearch(const T& key) const
|
||||
{
|
||||
int first = 0;
|
||||
int last = size();
|
||||
|
||||
//assume sorted array
|
||||
while (first <= last) {
|
||||
int mid = (first + last) / 2; // compute mid point.
|
||||
if (key > m_data[mid])
|
||||
first = mid + 1; // repeat search in top half.
|
||||
else if (key < m_data[mid])
|
||||
last = mid - 1; // repeat search in bottom half.
|
||||
else
|
||||
return mid; // found it. return position /////
|
||||
}
|
||||
return size(); // failed to find key
|
||||
}
|
||||
|
||||
|
||||
int findLinearSearch(const T& key) const
|
||||
{
|
||||
int index=size();
|
||||
int i;
|
||||
|
||||
for (i=0;i<size();i++)
|
||||
{
|
||||
if (m_data[i] == key)
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
void remove(const T& key)
|
||||
{
|
||||
|
||||
int findIndex = findLinearSearch(key);
|
||||
if (findIndex<size())
|
||||
{
|
||||
swap( findIndex,size()-1);
|
||||
pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //BT_OBJECT_ARRAY__
|
||||
|
||||
@@ -58,11 +58,14 @@ class btIDebugDraw
|
||||
|
||||
virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color)=0;
|
||||
|
||||
virtual void reportErrorWarning(const char* warningString) = 0;
|
||||
|
||||
virtual void setDebugMode(int debugMode) =0;
|
||||
|
||||
virtual int getDebugMode() const = 0;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //IDEBUG_DRAW__H
|
||||
|
||||
@@ -22,15 +22,6 @@ subject to the following restrictions:
|
||||
#ifndef QUICK_PROF_H
|
||||
#define QUICK_PROF_H
|
||||
|
||||
#define USE_QUICKPROF 1
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#ifdef __PPU__
|
||||
#include <sys/sys_time.h>
|
||||
@@ -51,39 +42,12 @@ typedef uint64_t __int64;
|
||||
#endif
|
||||
|
||||
#define mymin(a,b) (a > b ? a : b)
|
||||
namespace hidden
|
||||
{
|
||||
/// A simple data structure representing a single timed block
|
||||
/// of code.
|
||||
struct ProfileBlock
|
||||
{
|
||||
ProfileBlock()
|
||||
{
|
||||
currentBlockStartMicroseconds = 0;
|
||||
currentCycleTotalMicroseconds = 0;
|
||||
lastCycleTotalMicroseconds = 0;
|
||||
totalMicroseconds = 0;
|
||||
}
|
||||
|
||||
/// The starting time (in us) of the current block update.
|
||||
unsigned long int currentBlockStartMicroseconds;
|
||||
|
||||
/// The accumulated time (in us) spent in this block during the
|
||||
/// current profiling cycle.
|
||||
unsigned long int currentCycleTotalMicroseconds;
|
||||
|
||||
/// The accumulated time (in us) spent in this block during the
|
||||
/// past profiling cycle.
|
||||
unsigned long int lastCycleTotalMicroseconds;
|
||||
|
||||
/// The total accumulated time (in us) spent in this block.
|
||||
unsigned long int totalMicroseconds;
|
||||
};
|
||||
|
||||
class Clock
|
||||
/// basic clock
|
||||
class btClock
|
||||
{
|
||||
public:
|
||||
Clock()
|
||||
btClock()
|
||||
{
|
||||
#ifdef USE_WINDOWS_TIMERS
|
||||
QueryPerformanceFrequency(&mClockFrequency);
|
||||
@@ -91,7 +55,7 @@ namespace hidden
|
||||
reset();
|
||||
}
|
||||
|
||||
~Clock()
|
||||
~btClock()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -118,7 +82,7 @@ namespace hidden
|
||||
}
|
||||
|
||||
/// Returns the time in ms since the last call to reset or since
|
||||
/// the Clock was created.
|
||||
/// the btClock was created.
|
||||
unsigned long int getTimeMilliseconds()
|
||||
{
|
||||
#ifdef USE_WINDOWS_TIMERS
|
||||
@@ -248,6 +212,51 @@ namespace hidden
|
||||
#endif //__PPU__
|
||||
|
||||
};
|
||||
|
||||
|
||||
//#define USE_QUICKPROF 1
|
||||
//Don't use quickprof for now, because it contains STL. TODO: replace STL by Bullet container classes.
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
|
||||
|
||||
//#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
||||
|
||||
|
||||
namespace hidden
|
||||
{
|
||||
/// A simple data structure representing a single timed block
|
||||
/// of code.
|
||||
struct ProfileBlock
|
||||
{
|
||||
ProfileBlock()
|
||||
{
|
||||
currentBlockStartMicroseconds = 0;
|
||||
currentCycleTotalMicroseconds = 0;
|
||||
lastCycleTotalMicroseconds = 0;
|
||||
totalMicroseconds = 0;
|
||||
}
|
||||
|
||||
/// The starting time (in us) of the current block update.
|
||||
unsigned long int currentBlockStartMicroseconds;
|
||||
|
||||
/// The accumulated time (in us) spent in this block during the
|
||||
/// current profiling cycle.
|
||||
unsigned long int currentCycleTotalMicroseconds;
|
||||
|
||||
/// The accumulated time (in us) spent in this block during the
|
||||
/// past profiling cycle.
|
||||
unsigned long int lastCycleTotalMicroseconds;
|
||||
|
||||
/// The total accumulated time (in us) spent in this block.
|
||||
unsigned long int totalMicroseconds;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
/// A static class that manages timing for a set of profiling blocks.
|
||||
@@ -343,7 +352,7 @@ public:
|
||||
static bool mEnabled;
|
||||
|
||||
/// The clock used to time profile blocks.
|
||||
static hidden::Clock mClock;
|
||||
static btClock mClock;
|
||||
|
||||
/// The starting time (in us) of the current profiling cycle.
|
||||
static unsigned long int mCurrentCycleStartMicroseconds;
|
||||
|
||||
Reference in New Issue
Block a user