Code-style consistency improvement:
Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files. make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type. This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
@@ -17,28 +17,26 @@ struct btTiming
|
||||
FILE* gTimingFile = 0;
|
||||
#ifndef __STDC_FORMAT_MACROS
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#endif //__STDC_FORMAT_MACROS
|
||||
#endif //__STDC_FORMAT_MACROS
|
||||
|
||||
//see http://stackoverflow.com/questions/18107426/printf-format-for-unsigned-int64-on-windows
|
||||
#ifndef _WIN32
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#define BT_TIMING_CAPACITY 16*65536
|
||||
#define BT_TIMING_CAPACITY 16 * 65536
|
||||
static bool m_firstTiming = true;
|
||||
|
||||
|
||||
struct btTimings
|
||||
{
|
||||
btTimings()
|
||||
:m_numTimings(0),
|
||||
m_activeBuffer(0)
|
||||
: m_numTimings(0),
|
||||
m_activeBuffer(0)
|
||||
{
|
||||
|
||||
}
|
||||
void flush()
|
||||
{
|
||||
for (int i = 0; i<m_numTimings; i++)
|
||||
for (int i = 0; i < m_numTimings; i++)
|
||||
{
|
||||
const char* name = m_timings[m_activeBuffer][i].m_name;
|
||||
int threadId = m_timings[m_activeBuffer][i].m_threadId;
|
||||
@@ -64,8 +62,7 @@ struct btTimings
|
||||
|
||||
#else
|
||||
|
||||
|
||||
if (startTime>endTime)
|
||||
if (startTime > endTime)
|
||||
{
|
||||
endTime = startTime;
|
||||
}
|
||||
@@ -75,13 +72,13 @@ struct btTimings
|
||||
char startTimeRem1000Str[16];
|
||||
char endTimeRem1000Str[16];
|
||||
|
||||
if (startTimeRem1000<10)
|
||||
if (startTimeRem1000 < 10)
|
||||
{
|
||||
sprintf(startTimeRem1000Str, "00%d", startTimeRem1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (startTimeRem1000<100)
|
||||
if (startTimeRem1000 < 100)
|
||||
{
|
||||
sprintf(startTimeRem1000Str, "0%d", startTimeRem1000);
|
||||
}
|
||||
@@ -91,13 +88,13 @@ struct btTimings
|
||||
}
|
||||
}
|
||||
|
||||
if (endTimeRem1000<10)
|
||||
if (endTimeRem1000 < 10)
|
||||
{
|
||||
sprintf(endTimeRem1000Str, "00%d", endTimeRem1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (endTimeRem1000<100)
|
||||
if (endTimeRem1000 < 100)
|
||||
{
|
||||
sprintf(endTimeRem1000Str, "0%d", endTimeRem1000);
|
||||
}
|
||||
@@ -114,21 +111,19 @@ struct btTimings
|
||||
#ifdef _WIN32
|
||||
|
||||
fprintf(gTimingFile, "{\"cat\":\"timing\",\"pid\":1,\"tid\":%d,\"ts\":%I64d.%s ,\"ph\":\"B\",\"name\":\"%s\",\"args\":{}},\n",
|
||||
threadId, startTimeDiv1000, startTimeRem1000Str, newname);
|
||||
threadId, startTimeDiv1000, startTimeRem1000Str, newname);
|
||||
fprintf(gTimingFile, "{\"cat\":\"timing\",\"pid\":1,\"tid\":%d,\"ts\":%I64d.%s ,\"ph\":\"E\",\"name\":\"%s\",\"args\":{}}",
|
||||
threadId, endTimeDiv1000, endTimeRem1000Str, newname);
|
||||
threadId, endTimeDiv1000, endTimeRem1000Str, newname);
|
||||
|
||||
#else
|
||||
fprintf(gTimingFile, "{\"cat\":\"timing\",\"pid\":1,\"tid\":%d,\"ts\":%" PRIu64 ".%s ,\"ph\":\"B\",\"name\":\"%s\",\"args\":{}},\n",
|
||||
threadId, startTimeDiv1000, startTimeRem1000Str, newname);
|
||||
threadId, startTimeDiv1000, startTimeRem1000Str, newname);
|
||||
fprintf(gTimingFile, "{\"cat\":\"timing\",\"pid\":1,\"tid\":%d,\"ts\":%" PRIu64 ".%s ,\"ph\":\"E\",\"name\":\"%s\",\"args\":{}}",
|
||||
threadId, endTimeDiv1000, endTimeRem1000Str, newname);
|
||||
threadId, endTimeDiv1000, endTimeRem1000Str, newname);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
m_numTimings = 0;
|
||||
|
||||
}
|
||||
|
||||
void addTiming(const char* name, int threadId, unsigned long long int startTime, unsigned long long int endTime)
|
||||
@@ -151,7 +146,6 @@ struct btTimings
|
||||
m_timings[m_activeBuffer][slot].m_usEndTime = endTime;
|
||||
}
|
||||
|
||||
|
||||
int m_numTimings;
|
||||
int m_activeBuffer;
|
||||
btAlignedObjectArray<btTiming> m_timings[1];
|
||||
@@ -159,18 +153,15 @@ struct btTimings
|
||||
//#ifndef BT_NO_PROFILE
|
||||
btTimings gTimings[BT_QUICKPROF_MAX_THREAD_COUNT];
|
||||
#define MAX_NESTING 1024
|
||||
int gStackDepths[BT_QUICKPROF_MAX_THREAD_COUNT] = { 0 };
|
||||
int gStackDepths[BT_QUICKPROF_MAX_THREAD_COUNT] = {0};
|
||||
const char* gFuncNames[BT_QUICKPROF_MAX_THREAD_COUNT][MAX_NESTING];
|
||||
unsigned long long int gStartTimes[BT_QUICKPROF_MAX_THREAD_COUNT][MAX_NESTING];
|
||||
//#endif
|
||||
|
||||
btClock clk;
|
||||
|
||||
|
||||
|
||||
bool gProfileDisabled = true;
|
||||
|
||||
|
||||
void MyDummyEnterProfileZoneFunc(const char* msg)
|
||||
{
|
||||
}
|
||||
@@ -185,7 +176,7 @@ void MyEnterProfileZoneFunc(const char* msg)
|
||||
return;
|
||||
#ifndef BT_NO_PROFILE
|
||||
int threadId = btQuickprofGetCurrentThreadIndex2();
|
||||
if (threadId<0 || threadId >= BT_QUICKPROF_MAX_THREAD_COUNT)
|
||||
if (threadId < 0 || threadId >= BT_QUICKPROF_MAX_THREAD_COUNT)
|
||||
return;
|
||||
|
||||
if (gStackDepths[threadId] >= MAX_NESTING)
|
||||
@@ -201,7 +192,6 @@ void MyEnterProfileZoneFunc(const char* msg)
|
||||
}
|
||||
gStackDepths[threadId]++;
|
||||
#endif
|
||||
|
||||
}
|
||||
void MyLeaveProfileZoneFunc()
|
||||
{
|
||||
@@ -209,8 +199,8 @@ void MyLeaveProfileZoneFunc()
|
||||
return;
|
||||
#ifndef BT_NO_PROFILE
|
||||
int threadId = btQuickprofGetCurrentThreadIndex2();
|
||||
if (threadId<0 || threadId >= BT_QUICKPROF_MAX_THREAD_COUNT)
|
||||
return;
|
||||
if (threadId < 0 || threadId >= BT_QUICKPROF_MAX_THREAD_COUNT)
|
||||
return;
|
||||
|
||||
if (gStackDepths[threadId] <= 0)
|
||||
{
|
||||
@@ -224,56 +214,55 @@ void MyLeaveProfileZoneFunc()
|
||||
|
||||
unsigned long long int endTime = clk.getTimeNanoseconds();
|
||||
gTimings[threadId].addTiming(name, threadId, startTime, endTime);
|
||||
#endif //BT_NO_PROFILE
|
||||
#endif //BT_NO_PROFILE
|
||||
}
|
||||
|
||||
|
||||
void b3ChromeUtilsStartTimings()
|
||||
{
|
||||
m_firstTiming = true;
|
||||
gProfileDisabled = false;//true;
|
||||
b3SetCustomEnterProfileZoneFunc(MyEnterProfileZoneFunc);
|
||||
b3SetCustomLeaveProfileZoneFunc(MyLeaveProfileZoneFunc);
|
||||
m_firstTiming = true;
|
||||
gProfileDisabled = false; //true;
|
||||
b3SetCustomEnterProfileZoneFunc(MyEnterProfileZoneFunc);
|
||||
b3SetCustomLeaveProfileZoneFunc(MyLeaveProfileZoneFunc);
|
||||
|
||||
//also for Bullet 2.x API
|
||||
btSetCustomEnterProfileZoneFunc(MyEnterProfileZoneFunc);
|
||||
btSetCustomLeaveProfileZoneFunc(MyLeaveProfileZoneFunc);
|
||||
//also for Bullet 2.x API
|
||||
btSetCustomEnterProfileZoneFunc(MyEnterProfileZoneFunc);
|
||||
btSetCustomLeaveProfileZoneFunc(MyLeaveProfileZoneFunc);
|
||||
}
|
||||
|
||||
void b3ChromeUtilsStopTimingsAndWriteJsonFile(const char* fileNamePrefix)
|
||||
{
|
||||
b3SetCustomEnterProfileZoneFunc(MyDummyEnterProfileZoneFunc);
|
||||
b3SetCustomLeaveProfileZoneFunc(MyDummyLeaveProfileZoneFunc);
|
||||
//also for Bullet 2.x API
|
||||
btSetCustomEnterProfileZoneFunc(MyDummyEnterProfileZoneFunc);
|
||||
btSetCustomLeaveProfileZoneFunc(MyDummyLeaveProfileZoneFunc);
|
||||
char fileName[1024];
|
||||
static int fileCounter = 0;
|
||||
sprintf(fileName,"%s_%d.json",fileNamePrefix, fileCounter++);
|
||||
gTimingFile = fopen(fileName,"w");
|
||||
if (gTimingFile)
|
||||
b3SetCustomEnterProfileZoneFunc(MyDummyEnterProfileZoneFunc);
|
||||
b3SetCustomLeaveProfileZoneFunc(MyDummyLeaveProfileZoneFunc);
|
||||
//also for Bullet 2.x API
|
||||
btSetCustomEnterProfileZoneFunc(MyDummyEnterProfileZoneFunc);
|
||||
btSetCustomLeaveProfileZoneFunc(MyDummyLeaveProfileZoneFunc);
|
||||
char fileName[1024];
|
||||
static int fileCounter = 0;
|
||||
sprintf(fileName, "%s_%d.json", fileNamePrefix, fileCounter++);
|
||||
gTimingFile = fopen(fileName, "w");
|
||||
if (gTimingFile)
|
||||
{
|
||||
fprintf(gTimingFile, "{\"traceEvents\":[\n");
|
||||
//dump the content to file
|
||||
for (int i = 0; i < BT_QUICKPROF_MAX_THREAD_COUNT; i++)
|
||||
{
|
||||
if (gTimings[i].m_numTimings)
|
||||
{
|
||||
fprintf(gTimingFile,"{\"traceEvents\":[\n");
|
||||
//dump the content to file
|
||||
for (int i=0;i<BT_QUICKPROF_MAX_THREAD_COUNT;i++)
|
||||
{
|
||||
if (gTimings[i].m_numTimings)
|
||||
{
|
||||
printf("Writing %d timings for thread %d\n", gTimings[i].m_numTimings, i);
|
||||
gTimings[i].flush();
|
||||
}
|
||||
}
|
||||
fprintf(gTimingFile,"\n],\n\"displayTimeUnit\": \"ns\"}");
|
||||
fclose(gTimingFile);
|
||||
} else
|
||||
{
|
||||
b3Printf("Error opening file");
|
||||
b3Printf(fileName);
|
||||
printf("Writing %d timings for thread %d\n", gTimings[i].m_numTimings, i);
|
||||
gTimings[i].flush();
|
||||
}
|
||||
gTimingFile = 0;
|
||||
}
|
||||
fprintf(gTimingFile, "\n],\n\"displayTimeUnit\": \"ns\"}");
|
||||
fclose(gTimingFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
b3Printf("Error opening file");
|
||||
b3Printf(fileName);
|
||||
}
|
||||
gTimingFile = 0;
|
||||
}
|
||||
|
||||
|
||||
void b3ChromeUtilsEnableProfiling()
|
||||
{
|
||||
gProfileDisabled = false;
|
||||
|
||||
@@ -6,4 +6,4 @@ void b3ChromeUtilsStartTimings();
|
||||
void b3ChromeUtilsStopTimingsAndWriteJsonFile(const char* fileNamePrefix);
|
||||
void b3ChromeUtilsEnableProfiling();
|
||||
|
||||
#endif//B3_CHROME_TRACE_UTIL_H
|
||||
#endif //B3_CHROME_TRACE_UTIL_H
|
||||
@@ -4,11 +4,10 @@
|
||||
|
||||
#include "../Importers/ImportURDFDemo/urdfStringSplit.h"
|
||||
|
||||
|
||||
static bool readLine(FILE* file, btAlignedObjectArray<char>& line)
|
||||
{
|
||||
int c = 0;
|
||||
for (c=fgetc(file);(c != EOF && c != '\n');c=fgetc(file))
|
||||
for (c = fgetc(file); (c != EOF && c != '\n'); c = fgetc(file))
|
||||
{
|
||||
line.push_back(c);
|
||||
}
|
||||
@@ -16,13 +15,11 @@ static bool readLine(FILE* file, btAlignedObjectArray<char>& line)
|
||||
return (c == EOF);
|
||||
}
|
||||
|
||||
|
||||
int readMinitaurLogFile(const char* fileName, btAlignedObjectArray<std::string>& structNames, std::string& structTypes, btAlignedObjectArray<MinitaurLogRecord>& logRecords, bool verbose)
|
||||
{
|
||||
|
||||
int retVal = 0;
|
||||
|
||||
FILE* f = fopen(fileName,"rb");
|
||||
FILE* f = fopen(fileName, "rb");
|
||||
if (f)
|
||||
{
|
||||
if (verbose)
|
||||
@@ -30,36 +27,36 @@ int readMinitaurLogFile(const char* fileName, btAlignedObjectArray<std::string>&
|
||||
printf("Opened file %s\n", fileName);
|
||||
}
|
||||
btAlignedObjectArray<char> line0Buf;
|
||||
bool eof = readLine(f,line0Buf);
|
||||
bool eof = readLine(f, line0Buf);
|
||||
btAlignedObjectArray<char> line1Buf;
|
||||
eof |= readLine(f,line1Buf);
|
||||
eof |= readLine(f, line1Buf);
|
||||
std::string line0 = &line0Buf[0];
|
||||
structTypes = &line1Buf[0];
|
||||
|
||||
|
||||
btAlignedObjectArray<std::string> separators;
|
||||
separators.push_back(",");
|
||||
|
||||
urdfStringSplit(structNames,line0,separators);
|
||||
|
||||
urdfStringSplit(structNames, line0, separators);
|
||||
if (verbose)
|
||||
{
|
||||
printf("Num Fields = %d\n",structNames.size());
|
||||
printf("Num Fields = %d\n", structNames.size());
|
||||
}
|
||||
btAssert(structTypes.size() == structNames.size());
|
||||
if (structTypes.size() != structNames.size())
|
||||
{
|
||||
retVal = eCorruptHeader;
|
||||
}
|
||||
int numStructsRead = 0;
|
||||
int numStructsRead = 0;
|
||||
|
||||
if (structTypes.size() == structNames.size())
|
||||
{
|
||||
while (!eof)
|
||||
{
|
||||
unsigned char blaat[1024];
|
||||
size_t s = fread(blaat,2,1,f);
|
||||
if (s!=1)
|
||||
size_t s = fread(blaat, 2, 1, f);
|
||||
if (s != 1)
|
||||
{
|
||||
eof=true;
|
||||
eof = true;
|
||||
retVal = eInvalidAABBAlignCheck;
|
||||
break;
|
||||
}
|
||||
@@ -73,125 +70,120 @@ int readMinitaurLogFile(const char* fileName, btAlignedObjectArray<std::string>&
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
printf("Reading structure %d\n",numStructsRead);
|
||||
printf("Reading structure %d\n", numStructsRead);
|
||||
}
|
||||
MinitaurLogRecord record;
|
||||
|
||||
for (int i=0;i<structNames.size();i++)
|
||||
for (int i = 0; i < structNames.size(); i++)
|
||||
{
|
||||
|
||||
|
||||
switch (structTypes[i])
|
||||
{
|
||||
case 'I':
|
||||
{
|
||||
size_t s = fread(blaat,sizeof(int),1,f);
|
||||
if (s != 1)
|
||||
case 'I':
|
||||
{
|
||||
eof = true;
|
||||
retVal = eCorruptValue;
|
||||
size_t s = fread(blaat, sizeof(int), 1, f);
|
||||
if (s != 1)
|
||||
{
|
||||
eof = true;
|
||||
retVal = eCorruptValue;
|
||||
break;
|
||||
}
|
||||
int v = (int)*(unsigned int*)blaat;
|
||||
if (s == 1)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
printf("%s = %d\n", structNames[i].c_str(), v);
|
||||
}
|
||||
record.m_values.push_back(v);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
int v = (int) *(unsigned int*)blaat;
|
||||
if (s==1)
|
||||
case 'i':
|
||||
{
|
||||
size_t s = fread(blaat, sizeof(int), 1, f);
|
||||
if (s != 1)
|
||||
{
|
||||
eof = true;
|
||||
retVal = eCorruptValue;
|
||||
break;
|
||||
}
|
||||
int v = *(int*)blaat;
|
||||
if (s == 1)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
printf("%s = %d\n", structNames[i].c_str(), v);
|
||||
}
|
||||
record.m_values.push_back(v);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'f':
|
||||
{
|
||||
float v;
|
||||
size_t s = fread(&v, sizeof(float), 1, f);
|
||||
if (s != 1)
|
||||
{
|
||||
eof = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (s == 1)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
printf("%s = %f\n", structNames[i].c_str(), v);
|
||||
}
|
||||
record.m_values.push_back(v);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'B':
|
||||
{
|
||||
char v;
|
||||
size_t s = fread(&v, sizeof(char), 1, f);
|
||||
if (s != 1)
|
||||
{
|
||||
eof = true;
|
||||
break;
|
||||
}
|
||||
if (s == 1)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
printf("%s = %d\n", structNames[i].c_str(), v);
|
||||
}
|
||||
record.m_values.push_back(v);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
printf("%s = %d\n",structNames[i].c_str(),v);
|
||||
printf("Unknown type\n");
|
||||
}
|
||||
record.m_values.push_back(v);
|
||||
retVal = eUnknownType;
|
||||
btAssert(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'i':
|
||||
{
|
||||
size_t s = fread(blaat,sizeof(int),1,f);
|
||||
if (s != 1)
|
||||
{
|
||||
eof = true;
|
||||
retVal = eCorruptValue;
|
||||
break;
|
||||
|
||||
}
|
||||
int v = *(int*)blaat;
|
||||
if (s==1)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
printf("%s = %d\n",structNames[i].c_str(),v);
|
||||
}
|
||||
record.m_values.push_back(v);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'f':
|
||||
{
|
||||
float v;
|
||||
size_t s = fread(&v,sizeof(float),1,f);
|
||||
if (s != 1)
|
||||
{
|
||||
eof = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (s==1)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
printf("%s = %f\n",structNames[i].c_str(),v);
|
||||
}
|
||||
record.m_values.push_back(v);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'B':
|
||||
{
|
||||
char v;
|
||||
size_t s = fread(&v,sizeof(char),1,f);
|
||||
if (s != 1)
|
||||
{
|
||||
eof = true;
|
||||
break;
|
||||
}
|
||||
if (s==1)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
printf("%s = %d\n",structNames[i].c_str(),v);
|
||||
}
|
||||
record.m_values.push_back(v);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
printf("Unknown type\n");
|
||||
}
|
||||
retVal = eUnknownType;
|
||||
btAssert(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
logRecords.push_back(record);
|
||||
numStructsRead++;
|
||||
}
|
||||
if (verbose)
|
||||
{
|
||||
printf("numStructsRead = %d\n",numStructsRead);
|
||||
printf("numStructsRead = %d\n", numStructsRead);
|
||||
}
|
||||
if (retVal==0)
|
||||
if (retVal == 0)
|
||||
{
|
||||
retVal = numStructsRead;
|
||||
}
|
||||
}
|
||||
|
||||
//read header and
|
||||
} else
|
||||
|
||||
//read header and
|
||||
}
|
||||
else
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
@@ -202,28 +194,25 @@ int readMinitaurLogFile(const char* fileName, btAlignedObjectArray<std::string>&
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
FILE* createMinitaurLogFile(const char* fileName, btAlignedObjectArray<std::string>& structNames, std::string& structTypes)
|
||||
{
|
||||
FILE* f = fopen(fileName,"wb");
|
||||
FILE* f = fopen(fileName, "wb");
|
||||
if (f)
|
||||
{
|
||||
for (int i=0;i<structNames.size();i++)
|
||||
for (int i = 0; i < structNames.size(); i++)
|
||||
{
|
||||
int len = strlen(structNames[i].c_str());
|
||||
fwrite(structNames[i].c_str(),len,1,f);
|
||||
if (i<structNames.size()-1)
|
||||
fwrite(structNames[i].c_str(), len, 1, f);
|
||||
if (i < structNames.size() - 1)
|
||||
{
|
||||
fwrite(",",1,1,f);
|
||||
fwrite(",", 1, 1, f);
|
||||
}
|
||||
}
|
||||
int sz = sizeof("\n");
|
||||
fwrite("\n",sz-1,1,f);
|
||||
fwrite(structTypes.c_str(),strlen(structTypes.c_str()),1,f);
|
||||
fwrite("\n",sz-1,1,f);
|
||||
|
||||
fwrite("\n", sz - 1, 1, f);
|
||||
fwrite(structTypes.c_str(), strlen(structTypes.c_str()), 1, f);
|
||||
fwrite("\n", sz - 1, 1, f);
|
||||
}
|
||||
|
||||
|
||||
return f;
|
||||
}
|
||||
@@ -232,34 +221,33 @@ void appendMinitaurLogData(FILE* f, std::string& structTypes, const MinitaurLogR
|
||||
{
|
||||
if (f)
|
||||
{
|
||||
unsigned char buf[2] = {0xaa,0xbb};
|
||||
fwrite(buf,2,1,f);
|
||||
unsigned char buf[2] = {0xaa, 0xbb};
|
||||
fwrite(buf, 2, 1, f);
|
||||
if (structTypes.length() == logData.m_values.size())
|
||||
{
|
||||
for (int i=0;i<logData.m_values.size();i++)
|
||||
for (int i = 0; i < logData.m_values.size(); i++)
|
||||
{
|
||||
switch(structTypes[i])
|
||||
switch (structTypes[i])
|
||||
{
|
||||
case 'i':
|
||||
case 'I':
|
||||
{
|
||||
fwrite(&logData.m_values[i].m_intVal,sizeof(int),1,f);
|
||||
break;
|
||||
}
|
||||
case 'f':
|
||||
{
|
||||
fwrite(&logData.m_values[i].m_floatVal,sizeof(float),1,f);
|
||||
break;
|
||||
}
|
||||
case 'B':
|
||||
{
|
||||
fwrite(&logData.m_values[i].m_charVal,sizeof(char),1,f);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
|
||||
}
|
||||
case 'i':
|
||||
case 'I':
|
||||
{
|
||||
fwrite(&logData.m_values[i].m_intVal, sizeof(int), 1, f);
|
||||
break;
|
||||
}
|
||||
case 'f':
|
||||
{
|
||||
fwrite(&logData.m_values[i].m_floatVal, sizeof(float), 1, f);
|
||||
break;
|
||||
}
|
||||
case 'B':
|
||||
{
|
||||
fwrite(&logData.m_values[i].m_charVal, sizeof(char), 1, f);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,24 +7,23 @@
|
||||
struct MinitaurLogValue
|
||||
{
|
||||
MinitaurLogValue()
|
||||
:m_intVal(0xcdcdcdcd)
|
||||
: m_intVal(0xcdcdcdcd)
|
||||
{
|
||||
}
|
||||
MinitaurLogValue(int iv)
|
||||
:m_intVal(iv)
|
||||
: m_intVal(iv)
|
||||
{
|
||||
}
|
||||
MinitaurLogValue(float fv)
|
||||
:m_floatVal(fv)
|
||||
: m_floatVal(fv)
|
||||
{
|
||||
}
|
||||
MinitaurLogValue(char fv)
|
||||
:m_charVal(fv)
|
||||
: m_charVal(fv)
|
||||
{
|
||||
}
|
||||
|
||||
union
|
||||
{
|
||||
union {
|
||||
char m_charVal;
|
||||
int m_intVal;
|
||||
float m_floatVal;
|
||||
@@ -51,4 +50,4 @@ FILE* createMinitaurLogFile(const char* fileName, btAlignedObjectArray<std::stri
|
||||
void appendMinitaurLogData(FILE* f, std::string& structTypes, const MinitaurLogRecord& logData);
|
||||
void closeMinitaurLogFile(FILE* f);
|
||||
|
||||
#endif //ROBOT_LOGGING_UTIL_H
|
||||
#endif //ROBOT_LOGGING_UTIL_H
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
#include "b3Clock.h"
|
||||
|
||||
template <class T>
|
||||
const T& b3ClockMin(const T& a, const T& b)
|
||||
const T& b3ClockMin(const T& a, const T& b)
|
||||
{
|
||||
return a < b ? a : b ;
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __CELLOS_LV2__
|
||||
#include <sys/sys_time.h>
|
||||
#include <sys/time_util.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if defined (SUNOS) || defined (__SUNOS__)
|
||||
#include <stdio.h>
|
||||
#if defined(SUNOS) || defined(__SUNOS__)
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
@@ -23,38 +22,33 @@ const T& b3ClockMin(const T& a, const T& b)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOWINRES
|
||||
#define NOMCX
|
||||
#define NOIME
|
||||
#define NOIME
|
||||
|
||||
#ifdef _XBOX
|
||||
#include <Xtl.h>
|
||||
#else //_XBOX
|
||||
#include <windows.h>
|
||||
#endif //_XBOX
|
||||
#include <Xtl.h>
|
||||
#else //_XBOX
|
||||
#include <windows.h>
|
||||
#endif //_XBOX
|
||||
|
||||
#include <time.h>
|
||||
|
||||
|
||||
#else //_WIN32
|
||||
#else //_WIN32
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#endif //_WIN32
|
||||
|
||||
|
||||
#endif //_WIN32
|
||||
|
||||
struct b3ClockData
|
||||
{
|
||||
|
||||
#ifdef B3_USE_WINDOWS_TIMERS
|
||||
LARGE_INTEGER mClockFrequency;
|
||||
LARGE_INTEGER mStartTime;
|
||||
#else
|
||||
#ifdef __CELLOS_LV2__
|
||||
uint64_t mStartTime;
|
||||
uint64_t mStartTime;
|
||||
#else
|
||||
struct timeval mStartTime;
|
||||
#endif
|
||||
#endif //__CELLOS_LV2__
|
||||
|
||||
#endif //__CELLOS_LV2__
|
||||
};
|
||||
|
||||
///The b3Clock is a portable basic clock that measures accurate time in seconds, use for profiling.
|
||||
@@ -67,7 +61,6 @@ b3Clock::b3Clock()
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
b3Clock::~b3Clock()
|
||||
{
|
||||
delete m_data;
|
||||
@@ -85,8 +78,7 @@ b3Clock& b3Clock::operator=(const b3Clock& other)
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/// Resets the initial reference time.
|
||||
/// Resets the initial reference time.
|
||||
void b3Clock::reset(bool zeroReference)
|
||||
{
|
||||
if (zeroReference)
|
||||
@@ -94,126 +86,126 @@ void b3Clock::reset(bool zeroReference)
|
||||
#ifdef B3_USE_WINDOWS_TIMERS
|
||||
m_data->mStartTime.QuadPart = 0;
|
||||
#else
|
||||
#ifdef __CELLOS_LV2__
|
||||
m_data->mStartTime = 0;
|
||||
#else
|
||||
m_data->mStartTime = (struct timeval){0};
|
||||
#endif
|
||||
#ifdef __CELLOS_LV2__
|
||||
m_data->mStartTime = 0;
|
||||
#else
|
||||
m_data->mStartTime = (struct timeval){0};
|
||||
#endif
|
||||
|
||||
} else
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef B3_USE_WINDOWS_TIMERS
|
||||
QueryPerformanceCounter(&m_data->mStartTime);
|
||||
QueryPerformanceCounter(&m_data->mStartTime);
|
||||
#else
|
||||
#ifdef __CELLOS_LV2__
|
||||
|
||||
typedef uint64_t ClockSize;
|
||||
ClockSize newTime;
|
||||
//__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
|
||||
SYS_TIMEBASE_GET( newTime );
|
||||
m_data->mStartTime = newTime;
|
||||
typedef uint64_t ClockSize;
|
||||
ClockSize newTime;
|
||||
//__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
|
||||
SYS_TIMEBASE_GET(newTime);
|
||||
m_data->mStartTime = newTime;
|
||||
#else
|
||||
gettimeofday(&m_data->mStartTime, 0);
|
||||
gettimeofday(&m_data->mStartTime, 0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the time in ms since the last call to reset or since
|
||||
/// Returns the time in ms since the last call to reset or since
|
||||
/// the b3Clock was created.
|
||||
unsigned long int b3Clock::getTimeMilliseconds()
|
||||
{
|
||||
#ifdef B3_USE_WINDOWS_TIMERS
|
||||
LARGE_INTEGER currentTime;
|
||||
QueryPerformanceCounter(¤tTime);
|
||||
LONGLONG elapsedTime = currentTime.QuadPart -
|
||||
m_data->mStartTime.QuadPart;
|
||||
// Compute the number of millisecond ticks elapsed.
|
||||
unsigned long msecTicks = (unsigned long)(1000 * elapsedTime /
|
||||
m_data->mClockFrequency.QuadPart);
|
||||
|
||||
LONGLONG elapsedTime = currentTime.QuadPart -
|
||||
m_data->mStartTime.QuadPart;
|
||||
// Compute the number of millisecond ticks elapsed.
|
||||
unsigned long msecTicks = (unsigned long)(1000 * elapsedTime /
|
||||
m_data->mClockFrequency.QuadPart);
|
||||
|
||||
return msecTicks;
|
||||
return msecTicks;
|
||||
#else
|
||||
|
||||
#ifdef __CELLOS_LV2__
|
||||
uint64_t freq=sys_time_get_timebase_frequency();
|
||||
double dFreq=((double) freq) / 1000.0;
|
||||
typedef uint64_t ClockSize;
|
||||
ClockSize newTime;
|
||||
SYS_TIMEBASE_GET( newTime );
|
||||
//__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
|
||||
uint64_t freq = sys_time_get_timebase_frequency();
|
||||
double dFreq = ((double)freq) / 1000.0;
|
||||
typedef uint64_t ClockSize;
|
||||
ClockSize newTime;
|
||||
SYS_TIMEBASE_GET(newTime);
|
||||
//__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
|
||||
|
||||
return (unsigned long int)((double(newTime-m_data->mStartTime)) / dFreq);
|
||||
return (unsigned long int)((double(newTime - m_data->mStartTime)) / dFreq);
|
||||
#else
|
||||
|
||||
struct timeval currentTime;
|
||||
gettimeofday(¤tTime, 0);
|
||||
return (currentTime.tv_sec - m_data->mStartTime.tv_sec) * 1000 +
|
||||
(currentTime.tv_usec - m_data->mStartTime.tv_usec) / 1000;
|
||||
#endif //__CELLOS_LV2__
|
||||
struct timeval currentTime;
|
||||
gettimeofday(¤tTime, 0);
|
||||
return (currentTime.tv_sec - m_data->mStartTime.tv_sec) * 1000 +
|
||||
(currentTime.tv_usec - m_data->mStartTime.tv_usec) / 1000;
|
||||
#endif //__CELLOS_LV2__
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Returns the time in us since the last call to reset or since
|
||||
/// the Clock was created.
|
||||
/// Returns the time in us since the last call to reset or since
|
||||
/// the Clock was created.
|
||||
unsigned long long int b3Clock::getTimeMicroseconds()
|
||||
{
|
||||
#ifdef B3_USE_WINDOWS_TIMERS
|
||||
//see https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx
|
||||
LARGE_INTEGER currentTime, elapsedTime;
|
||||
|
||||
QueryPerformanceCounter(¤tTime);
|
||||
elapsedTime.QuadPart = currentTime.QuadPart -
|
||||
m_data->mStartTime.QuadPart;
|
||||
elapsedTime.QuadPart *= 1000000;
|
||||
elapsedTime.QuadPart /= m_data->mClockFrequency.QuadPart;
|
||||
LARGE_INTEGER currentTime, elapsedTime;
|
||||
|
||||
return (unsigned long long) elapsedTime.QuadPart;
|
||||
QueryPerformanceCounter(¤tTime);
|
||||
elapsedTime.QuadPart = currentTime.QuadPart -
|
||||
m_data->mStartTime.QuadPart;
|
||||
elapsedTime.QuadPart *= 1000000;
|
||||
elapsedTime.QuadPart /= m_data->mClockFrequency.QuadPart;
|
||||
|
||||
return (unsigned long long)elapsedTime.QuadPart;
|
||||
#else
|
||||
|
||||
#ifdef __CELLOS_LV2__
|
||||
uint64_t freq=sys_time_get_timebase_frequency();
|
||||
double dFreq=((double) freq)/ 1000000.0;
|
||||
typedef uint64_t ClockSize;
|
||||
ClockSize newTime;
|
||||
//__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
|
||||
SYS_TIMEBASE_GET( newTime );
|
||||
uint64_t freq = sys_time_get_timebase_frequency();
|
||||
double dFreq = ((double)freq) / 1000000.0;
|
||||
typedef uint64_t ClockSize;
|
||||
ClockSize newTime;
|
||||
//__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
|
||||
SYS_TIMEBASE_GET(newTime);
|
||||
|
||||
return (unsigned long int)((double(newTime-m_data->mStartTime)) / dFreq);
|
||||
return (unsigned long int)((double(newTime - m_data->mStartTime)) / dFreq);
|
||||
#else
|
||||
|
||||
struct timeval currentTime;
|
||||
gettimeofday(¤tTime, 0);
|
||||
return (currentTime.tv_sec - m_data->mStartTime.tv_sec) * 1000000 +
|
||||
(currentTime.tv_usec - m_data->mStartTime.tv_usec);
|
||||
#endif//__CELLOS_LV2__
|
||||
#endif
|
||||
struct timeval currentTime;
|
||||
gettimeofday(¤tTime, 0);
|
||||
return (currentTime.tv_sec - m_data->mStartTime.tv_sec) * 1000000 +
|
||||
(currentTime.tv_usec - m_data->mStartTime.tv_usec);
|
||||
#endif //__CELLOS_LV2__
|
||||
#endif
|
||||
}
|
||||
|
||||
double b3Clock::getTimeInSeconds()
|
||||
{
|
||||
return double(getTimeMicroseconds()/1.e6);
|
||||
return double(getTimeMicroseconds() / 1.e6);
|
||||
}
|
||||
|
||||
void b3Clock::usleep(int microSeconds)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (microSeconds==0)
|
||||
if (microSeconds == 0)
|
||||
{
|
||||
Sleep(0);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
int millis = microSeconds/1000;
|
||||
if (millis<1)
|
||||
millis=1;
|
||||
int millis = microSeconds / 1000;
|
||||
if (millis < 1)
|
||||
millis = 1;
|
||||
Sleep(millis);
|
||||
}
|
||||
#else
|
||||
if (microSeconds>0)
|
||||
if (microSeconds > 0)
|
||||
{
|
||||
::usleep(microSeconds);
|
||||
::usleep(microSeconds);
|
||||
//struct timeval tv;
|
||||
//tv.tv_sec = microSeconds/1000000L;
|
||||
//tv.tv_usec = microSeconds%1000000L;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef B3_CLOCK_H
|
||||
#define B3_CLOCK_H
|
||||
|
||||
|
||||
///The b3Clock is a portable basic clock that measures accurate time in seconds, use for profiling.
|
||||
class b3Clock
|
||||
{
|
||||
@@ -14,17 +13,17 @@ public:
|
||||
~b3Clock();
|
||||
|
||||
/// Resets the initial reference time. If zeroReference is true, will set reference to absolute 0.
|
||||
void reset(bool zeroReference=false);
|
||||
void reset(bool zeroReference = false);
|
||||
|
||||
/// Returns the time in ms since the last call to reset or since
|
||||
/// Returns the time in ms since the last call to reset or since
|
||||
/// the b3Clock was created.
|
||||
unsigned long int getTimeMilliseconds();
|
||||
|
||||
/// Returns the time in us since the last call to reset or since
|
||||
/// Returns the time in us since the last call to reset or since
|
||||
/// the Clock was created.
|
||||
unsigned long long int getTimeMicroseconds();
|
||||
|
||||
/// Returns the time in seconds since the last call to reset or since
|
||||
/// Returns the time in seconds since the last call to reset or since
|
||||
/// the Clock was created.
|
||||
double getTimeInSeconds();
|
||||
|
||||
@@ -36,5 +35,4 @@ private:
|
||||
struct b3ClockData* m_data;
|
||||
};
|
||||
|
||||
|
||||
#endif //B3_CLOCK_H
|
||||
#endif //B3_CLOCK_H
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
* @date 2015-09-20
|
||||
* @author Benjamin Ellenberger
|
||||
*/
|
||||
class b3ERPCFMHelper {
|
||||
class b3ERPCFMHelper
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* == How To Use ERP and CFM ==
|
||||
* ERP and CFM can be independently set in many joints. They can be set in contact joints, in joint limits and various other places, to control the spongyness and springyness of the joint (or joint limit).
|
||||
@@ -45,7 +45,8 @@ public:
|
||||
* @return
|
||||
*/
|
||||
static btScalar getERP(btScalar timeStep, btScalar kSpring,
|
||||
btScalar kDamper) {
|
||||
btScalar kDamper)
|
||||
{
|
||||
return timeStep * kSpring / (timeStep * kSpring + kDamper);
|
||||
}
|
||||
|
||||
@@ -71,7 +72,8 @@ public:
|
||||
* @return
|
||||
*/
|
||||
static btScalar getCFM(btScalar avoidSingularity, btScalar timeStep, btScalar kSpring,
|
||||
btScalar kDamper) {
|
||||
btScalar kDamper)
|
||||
{
|
||||
return btScalar(avoidSingularity) / (timeStep * kSpring + kDamper);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -24,37 +24,27 @@ subject to the following restrictions:
|
||||
**
|
||||
***************************************************************************************************/
|
||||
|
||||
// Credits: The Clock class was inspired by the Timer classes in
|
||||
// Credits: The Clock class was inspired by the Timer classes in
|
||||
// Ogre (www.ogre3d.org).
|
||||
|
||||
#include "Bullet3Common/b3MinMax.h"
|
||||
#include "b3Quickprof.h"
|
||||
|
||||
|
||||
#ifndef B3_NO_PROFILE
|
||||
|
||||
|
||||
static b3Clock b3s_profileClock;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
inline void b3Profile_Get_Ticks(unsigned long int * ticks)
|
||||
inline void b3Profile_Get_Ticks(unsigned long int* ticks)
|
||||
{
|
||||
*ticks = b3s_profileClock.getTimeMicroseconds();
|
||||
}
|
||||
|
||||
inline float b3Profile_Get_Tick_Rate(void)
|
||||
{
|
||||
// return 1000000.f;
|
||||
// return 1000000.f;
|
||||
return 1000.f;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
**
|
||||
** b3ProfileNode
|
||||
@@ -70,36 +60,33 @@ inline float b3Profile_Get_Tick_Rate(void)
|
||||
* The name is assumed to be a static pointer, only the pointer is stored and compared for *
|
||||
* efficiency reasons. *
|
||||
*=============================================================================================*/
|
||||
b3ProfileNode::b3ProfileNode( const char * name, b3ProfileNode * parent ) :
|
||||
Name( name ),
|
||||
TotalCalls( 0 ),
|
||||
TotalTime( 0 ),
|
||||
StartTime( 0 ),
|
||||
RecursionCounter( 0 ),
|
||||
Parent( parent ),
|
||||
Child( NULL ),
|
||||
Sibling( NULL ),
|
||||
m_userPtr(0)
|
||||
b3ProfileNode::b3ProfileNode(const char* name, b3ProfileNode* parent) : Name(name),
|
||||
TotalCalls(0),
|
||||
TotalTime(0),
|
||||
StartTime(0),
|
||||
RecursionCounter(0),
|
||||
Parent(parent),
|
||||
Child(NULL),
|
||||
Sibling(NULL),
|
||||
m_userPtr(0)
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
|
||||
void b3ProfileNode::CleanupMemory()
|
||||
void b3ProfileNode::CleanupMemory()
|
||||
{
|
||||
delete ( Child);
|
||||
delete (Child);
|
||||
Child = NULL;
|
||||
delete ( Sibling);
|
||||
delete (Sibling);
|
||||
Sibling = NULL;
|
||||
}
|
||||
|
||||
b3ProfileNode::~b3ProfileNode( void )
|
||||
b3ProfileNode::~b3ProfileNode(void)
|
||||
{
|
||||
delete ( Child);
|
||||
delete ( Sibling);
|
||||
delete (Child);
|
||||
delete (Sibling);
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************************************
|
||||
* INPUT: *
|
||||
* name - static string pointer to the name of the node we are searching for *
|
||||
@@ -108,127 +95,124 @@ b3ProfileNode::~b3ProfileNode( void )
|
||||
* All profile names are assumed to be static strings so this function uses pointer compares *
|
||||
* to find the named node. *
|
||||
*=============================================================================================*/
|
||||
b3ProfileNode * b3ProfileNode::Get_Sub_Node( const char * name )
|
||||
b3ProfileNode* b3ProfileNode::Get_Sub_Node(const char* name)
|
||||
{
|
||||
// Try to find this sub node
|
||||
b3ProfileNode * child = Child;
|
||||
while ( child ) {
|
||||
if ( child->Name == name ) {
|
||||
b3ProfileNode* child = Child;
|
||||
while (child)
|
||||
{
|
||||
if (child->Name == name)
|
||||
{
|
||||
return child;
|
||||
}
|
||||
child = child->Sibling;
|
||||
}
|
||||
|
||||
// We didn't find it, so add it
|
||||
|
||||
b3ProfileNode * node = new b3ProfileNode( name, this );
|
||||
|
||||
b3ProfileNode* node = new b3ProfileNode(name, this);
|
||||
node->Sibling = Child;
|
||||
Child = node;
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
void b3ProfileNode::Reset( void )
|
||||
void b3ProfileNode::Reset(void)
|
||||
{
|
||||
TotalCalls = 0;
|
||||
TotalTime = 0.0f;
|
||||
|
||||
|
||||
if ( Child ) {
|
||||
if (Child)
|
||||
{
|
||||
Child->Reset();
|
||||
}
|
||||
if ( Sibling ) {
|
||||
if (Sibling)
|
||||
{
|
||||
Sibling->Reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void b3ProfileNode::Call( void )
|
||||
void b3ProfileNode::Call(void)
|
||||
{
|
||||
TotalCalls++;
|
||||
if (RecursionCounter++ == 0) {
|
||||
if (RecursionCounter++ == 0)
|
||||
{
|
||||
b3Profile_Get_Ticks(&StartTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool b3ProfileNode::Return( void )
|
||||
bool b3ProfileNode::Return(void)
|
||||
{
|
||||
if ( --RecursionCounter == 0 && TotalCalls != 0 ) {
|
||||
if (--RecursionCounter == 0 && TotalCalls != 0)
|
||||
{
|
||||
unsigned long int time;
|
||||
b3Profile_Get_Ticks(&time);
|
||||
time-=StartTime;
|
||||
time -= StartTime;
|
||||
TotalTime += (float)time / b3Profile_Get_Tick_Rate();
|
||||
}
|
||||
return ( RecursionCounter == 0 );
|
||||
return (RecursionCounter == 0);
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
**
|
||||
** b3ProfileIterator
|
||||
**
|
||||
***************************************************************************************************/
|
||||
b3ProfileIterator::b3ProfileIterator( b3ProfileNode * start )
|
||||
b3ProfileIterator::b3ProfileIterator(b3ProfileNode* start)
|
||||
{
|
||||
CurrentParent = start;
|
||||
CurrentChild = CurrentParent->Get_Child();
|
||||
}
|
||||
|
||||
|
||||
void b3ProfileIterator::First(void)
|
||||
void b3ProfileIterator::First(void)
|
||||
{
|
||||
CurrentChild = CurrentParent->Get_Child();
|
||||
}
|
||||
|
||||
|
||||
void b3ProfileIterator::Next(void)
|
||||
void b3ProfileIterator::Next(void)
|
||||
{
|
||||
CurrentChild = CurrentChild->Get_Sibling();
|
||||
}
|
||||
|
||||
|
||||
bool b3ProfileIterator::Is_Done(void)
|
||||
bool b3ProfileIterator::Is_Done(void)
|
||||
{
|
||||
return CurrentChild == NULL;
|
||||
}
|
||||
|
||||
|
||||
void b3ProfileIterator::Enter_Child( int index )
|
||||
void b3ProfileIterator::Enter_Child(int index)
|
||||
{
|
||||
CurrentChild = CurrentParent->Get_Child();
|
||||
while ( (CurrentChild != NULL) && (index != 0) ) {
|
||||
while ((CurrentChild != NULL) && (index != 0))
|
||||
{
|
||||
index--;
|
||||
CurrentChild = CurrentChild->Get_Sibling();
|
||||
}
|
||||
|
||||
if ( CurrentChild != NULL ) {
|
||||
if (CurrentChild != NULL)
|
||||
{
|
||||
CurrentParent = CurrentChild;
|
||||
CurrentChild = CurrentParent->Get_Child();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void b3ProfileIterator::Enter_Parent( void )
|
||||
void b3ProfileIterator::Enter_Parent(void)
|
||||
{
|
||||
if ( CurrentParent->Get_Parent() != NULL ) {
|
||||
if (CurrentParent->Get_Parent() != NULL)
|
||||
{
|
||||
CurrentParent = CurrentParent->Get_Parent();
|
||||
}
|
||||
CurrentChild = CurrentParent->Get_Child();
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
**
|
||||
** b3ProfileManager
|
||||
**
|
||||
***************************************************************************************************/
|
||||
|
||||
b3ProfileNode b3ProfileManager::Root( "Root", NULL );
|
||||
b3ProfileNode * b3ProfileManager::CurrentNode = &b3ProfileManager::Root;
|
||||
int b3ProfileManager::FrameCounter = 0;
|
||||
unsigned long int b3ProfileManager::ResetTime = 0;
|
||||
|
||||
b3ProfileNode b3ProfileManager::Root("Root", NULL);
|
||||
b3ProfileNode* b3ProfileManager::CurrentNode = &b3ProfileManager::Root;
|
||||
int b3ProfileManager::FrameCounter = 0;
|
||||
unsigned long int b3ProfileManager::ResetTime = 0;
|
||||
|
||||
/***********************************************************************************************
|
||||
* b3ProfileManager::Start_Profile -- Begin a named profile *
|
||||
@@ -243,57 +227,55 @@ unsigned long int b3ProfileManager::ResetTime = 0;
|
||||
* The string used is assumed to be a static string; pointer compares are used throughout *
|
||||
* the profiling code for efficiency. *
|
||||
*=============================================================================================*/
|
||||
void b3ProfileManager::Start_Profile( const char * name )
|
||||
void b3ProfileManager::Start_Profile(const char* name)
|
||||
{
|
||||
if (name != CurrentNode->Get_Name()) {
|
||||
CurrentNode = CurrentNode->Get_Sub_Node( name );
|
||||
}
|
||||
|
||||
if (name != CurrentNode->Get_Name())
|
||||
{
|
||||
CurrentNode = CurrentNode->Get_Sub_Node(name);
|
||||
}
|
||||
|
||||
CurrentNode->Call();
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************************************
|
||||
* b3ProfileManager::Stop_Profile -- Stop timing and record the results. *
|
||||
*=============================================================================================*/
|
||||
void b3ProfileManager::Stop_Profile( void )
|
||||
void b3ProfileManager::Stop_Profile(void)
|
||||
{
|
||||
// Return will indicate whether we should back up to our parent (we may
|
||||
// be profiling a recursive function)
|
||||
if (CurrentNode->Return()) {
|
||||
if (CurrentNode->Return())
|
||||
{
|
||||
CurrentNode = CurrentNode->Get_Parent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************************************
|
||||
* b3ProfileManager::Reset -- Reset the contents of the profiling system *
|
||||
* *
|
||||
* This resets everything except for the tree structure. All of the timing data is reset. *
|
||||
*=============================================================================================*/
|
||||
void b3ProfileManager::Reset( void )
|
||||
{
|
||||
void b3ProfileManager::Reset(void)
|
||||
{
|
||||
b3s_profileClock.reset();
|
||||
Root.Reset();
|
||||
Root.Call();
|
||||
Root.Call();
|
||||
FrameCounter = 0;
|
||||
b3Profile_Get_Ticks(&ResetTime);
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************************************
|
||||
* b3ProfileManager::Increment_Frame_Counter -- Increment the frame counter *
|
||||
*=============================================================================================*/
|
||||
void b3ProfileManager::Increment_Frame_Counter( void )
|
||||
void b3ProfileManager::Increment_Frame_Counter(void)
|
||||
{
|
||||
FrameCounter++;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************************************
|
||||
* b3ProfileManager::Get_Time_Since_Reset -- returns the elapsed time since last reset *
|
||||
*=============================================================================================*/
|
||||
float b3ProfileManager::Get_Time_Since_Reset( void )
|
||||
float b3ProfileManager::Get_Time_Since_Reset(void)
|
||||
{
|
||||
unsigned long int time;
|
||||
b3Profile_Get_Ticks(&time);
|
||||
@@ -303,34 +285,34 @@ float b3ProfileManager::Get_Time_Since_Reset( void )
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void b3ProfileManager::dumpRecursive(b3ProfileIterator* profileIterator, int spacing)
|
||||
void b3ProfileManager::dumpRecursive(b3ProfileIterator* profileIterator, int spacing)
|
||||
{
|
||||
profileIterator->First();
|
||||
if (profileIterator->Is_Done())
|
||||
return;
|
||||
|
||||
float accumulated_time=0,parent_time = profileIterator->Is_Root() ? b3ProfileManager::Get_Time_Since_Reset() : profileIterator->Get_Current_Parent_Total_Time();
|
||||
float accumulated_time = 0, parent_time = profileIterator->Is_Root() ? b3ProfileManager::Get_Time_Since_Reset() : profileIterator->Get_Current_Parent_Total_Time();
|
||||
int i;
|
||||
int frames_since_reset = b3ProfileManager::Get_Frame_Count_Since_Reset();
|
||||
for (i=0;i<spacing;i++) b3Printf(".");
|
||||
for (i = 0; i < spacing; i++) b3Printf(".");
|
||||
b3Printf("----------------------------------\n");
|
||||
for (i=0;i<spacing;i++) b3Printf(".");
|
||||
b3Printf("Profiling: %s (total running time: %.3f ms) ---\n", profileIterator->Get_Current_Parent_Name(), parent_time );
|
||||
for (i = 0; i < spacing; i++) b3Printf(".");
|
||||
b3Printf("Profiling: %s (total running time: %.3f ms) ---\n", profileIterator->Get_Current_Parent_Name(), parent_time);
|
||||
float totalTime = 0.f;
|
||||
|
||||
|
||||
int numChildren = 0;
|
||||
|
||||
for (i = 0; !profileIterator->Is_Done(); i++,profileIterator->Next())
|
||||
|
||||
for (i = 0; !profileIterator->Is_Done(); i++, profileIterator->Next())
|
||||
{
|
||||
numChildren++;
|
||||
float current_total_time = profileIterator->Get_Current_Total_Time();
|
||||
accumulated_time += current_total_time;
|
||||
float fraction = parent_time > B3_EPSILON ? (current_total_time / parent_time) * 100 : 0.f;
|
||||
{
|
||||
int i; for (i=0;i<spacing;i++) b3Printf(".");
|
||||
int i;
|
||||
for (i = 0; i < spacing; i++) b3Printf(".");
|
||||
}
|
||||
b3Printf("%d -- %s (%.2f %%) :: %.3f ms / frame (%d calls)\n",i, profileIterator->Get_Current_Name(), fraction,(current_total_time / (double)frames_since_reset),profileIterator->Get_Current_Total_Calls());
|
||||
b3Printf("%d -- %s (%.2f %%) :: %.3f ms / frame (%d calls)\n", i, profileIterator->Get_Current_Name(), fraction, (current_total_time / (double)frames_since_reset), profileIterator->Get_Current_Total_Calls());
|
||||
totalTime += current_total_time;
|
||||
//recurse into children
|
||||
}
|
||||
@@ -339,92 +321,83 @@ void b3ProfileManager::dumpRecursive(b3ProfileIterator* profileIterator, int spa
|
||||
{
|
||||
b3Printf("what's wrong\n");
|
||||
}
|
||||
for (i=0;i<spacing;i++) b3Printf(".");
|
||||
b3Printf("%s (%.3f %%) :: %.3f ms\n", "Unaccounted:",parent_time > B3_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time);
|
||||
|
||||
for (i=0;i<numChildren;i++)
|
||||
for (i = 0; i < spacing; i++) b3Printf(".");
|
||||
b3Printf("%s (%.3f %%) :: %.3f ms\n", "Unaccounted:", parent_time > B3_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time);
|
||||
|
||||
for (i = 0; i < numChildren; i++)
|
||||
{
|
||||
profileIterator->Enter_Child(i);
|
||||
dumpRecursive(profileIterator,spacing+3);
|
||||
dumpRecursive(profileIterator, spacing + 3);
|
||||
profileIterator->Enter_Parent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void b3ProfileManager::dumpAll()
|
||||
void b3ProfileManager::dumpAll()
|
||||
{
|
||||
b3ProfileIterator* profileIterator = 0;
|
||||
profileIterator = b3ProfileManager::Get_Iterator();
|
||||
|
||||
dumpRecursive(profileIterator,0);
|
||||
dumpRecursive(profileIterator, 0);
|
||||
|
||||
b3ProfileManager::Release_Iterator(profileIterator);
|
||||
}
|
||||
|
||||
|
||||
void b3ProfileManager::dumpRecursive(FILE* f, b3ProfileIterator* profileIterator, int spacing)
|
||||
void b3ProfileManager::dumpRecursive(FILE* f, b3ProfileIterator* profileIterator, int spacing)
|
||||
{
|
||||
profileIterator->First();
|
||||
if (profileIterator->Is_Done())
|
||||
return;
|
||||
|
||||
float accumulated_time=0,parent_time = profileIterator->Is_Root() ? b3ProfileManager::Get_Time_Since_Reset() : profileIterator->Get_Current_Parent_Total_Time();
|
||||
float accumulated_time = 0, parent_time = profileIterator->Is_Root() ? b3ProfileManager::Get_Time_Since_Reset() : profileIterator->Get_Current_Parent_Total_Time();
|
||||
int i;
|
||||
int frames_since_reset = b3ProfileManager::Get_Frame_Count_Since_Reset();
|
||||
for (i=0;i<spacing;i++) fprintf(f,".");
|
||||
fprintf(f,"----------------------------------\n");
|
||||
for (i=0;i<spacing;i++) fprintf(f,".");
|
||||
fprintf(f,"Profiling: %s (total running time: %.3f ms) ---\n", profileIterator->Get_Current_Parent_Name(), parent_time );
|
||||
for (i = 0; i < spacing; i++) fprintf(f, ".");
|
||||
fprintf(f, "----------------------------------\n");
|
||||
for (i = 0; i < spacing; i++) fprintf(f, ".");
|
||||
fprintf(f, "Profiling: %s (total running time: %.3f ms) ---\n", profileIterator->Get_Current_Parent_Name(), parent_time);
|
||||
float totalTime = 0.f;
|
||||
|
||||
|
||||
int numChildren = 0;
|
||||
|
||||
for (i = 0; !profileIterator->Is_Done(); i++,profileIterator->Next())
|
||||
|
||||
for (i = 0; !profileIterator->Is_Done(); i++, profileIterator->Next())
|
||||
{
|
||||
numChildren++;
|
||||
float current_total_time = profileIterator->Get_Current_Total_Time();
|
||||
accumulated_time += current_total_time;
|
||||
float fraction = parent_time > B3_EPSILON ? (current_total_time / parent_time) * 100 : 0.f;
|
||||
{
|
||||
int i; for (i=0;i<spacing;i++) fprintf(f,".");
|
||||
int i;
|
||||
for (i = 0; i < spacing; i++) fprintf(f, ".");
|
||||
}
|
||||
fprintf(f,"%d -- %s (%.2f %%) :: %.3f ms / frame (%d calls)\n",i, profileIterator->Get_Current_Name(), fraction,(current_total_time / (double)frames_since_reset),profileIterator->Get_Current_Total_Calls());
|
||||
fprintf(f, "%d -- %s (%.2f %%) :: %.3f ms / frame (%d calls)\n", i, profileIterator->Get_Current_Name(), fraction, (current_total_time / (double)frames_since_reset), profileIterator->Get_Current_Total_Calls());
|
||||
totalTime += current_total_time;
|
||||
//recurse into children
|
||||
}
|
||||
|
||||
if (parent_time < accumulated_time)
|
||||
{
|
||||
fprintf(f,"what's wrong\n");
|
||||
fprintf(f, "what's wrong\n");
|
||||
}
|
||||
for (i=0;i<spacing;i++)
|
||||
fprintf(f,".");
|
||||
fprintf(f,"%s (%.3f %%) :: %.3f ms\n", "Unaccounted:",parent_time > B3_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time);
|
||||
|
||||
for (i=0;i<numChildren;i++)
|
||||
for (i = 0; i < spacing; i++)
|
||||
fprintf(f, ".");
|
||||
fprintf(f, "%s (%.3f %%) :: %.3f ms\n", "Unaccounted:", parent_time > B3_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time);
|
||||
|
||||
for (i = 0; i < numChildren; i++)
|
||||
{
|
||||
profileIterator->Enter_Child(i);
|
||||
dumpRecursive(f,profileIterator,spacing+3);
|
||||
dumpRecursive(f, profileIterator, spacing + 3);
|
||||
profileIterator->Enter_Parent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void b3ProfileManager::dumpAll(FILE* f)
|
||||
void b3ProfileManager::dumpAll(FILE* f)
|
||||
{
|
||||
b3ProfileIterator* profileIterator = 0;
|
||||
profileIterator = b3ProfileManager::Get_Iterator();
|
||||
|
||||
dumpRecursive(f, profileIterator,0);
|
||||
dumpRecursive(f, profileIterator, 0);
|
||||
|
||||
b3ProfileManager::Release_Iterator(profileIterator);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif //B3_NO_PROFILE
|
||||
#endif //B3_NO_PROFILE
|
||||
|
||||
@@ -20,65 +20,57 @@ subject to the following restrictions:
|
||||
**
|
||||
***************************************************************************************************/
|
||||
|
||||
// Credits: The Clock class was inspired by the Timer classes in
|
||||
// Credits: The Clock class was inspired by the Timer classes in
|
||||
// Ogre (www.ogre3d.org).
|
||||
|
||||
|
||||
|
||||
#ifndef B3_QUICK_PROF_H
|
||||
#define B3_QUICK_PROF_H
|
||||
|
||||
//To disable built-in profiling, please comment out next line
|
||||
//#define B3_NO_PROFILE 1
|
||||
#ifndef B3_NO_PROFILE
|
||||
#include <stdio.h>//@todo remove this, backwards compatibility
|
||||
#include <stdio.h> //@todo remove this, backwards compatibility
|
||||
#include "Bullet3Common/b3Scalar.h"
|
||||
#include "Bullet3Common/b3AlignedAllocator.h"
|
||||
#include <new>
|
||||
|
||||
|
||||
|
||||
|
||||
#include "b3Clock.h"
|
||||
|
||||
|
||||
|
||||
|
||||
///A node in the Profile Hierarchy Tree
|
||||
class b3ProfileNode {
|
||||
|
||||
class b3ProfileNode
|
||||
{
|
||||
public:
|
||||
b3ProfileNode( const char * name, b3ProfileNode * parent );
|
||||
~b3ProfileNode( void );
|
||||
b3ProfileNode(const char* name, b3ProfileNode* parent);
|
||||
~b3ProfileNode(void);
|
||||
|
||||
b3ProfileNode * Get_Sub_Node( const char * name );
|
||||
b3ProfileNode* Get_Sub_Node(const char* name);
|
||||
|
||||
b3ProfileNode * Get_Parent( void ) { return Parent; }
|
||||
b3ProfileNode * Get_Sibling( void ) { return Sibling; }
|
||||
b3ProfileNode * Get_Child( void ) { return Child; }
|
||||
b3ProfileNode* Get_Parent(void) { return Parent; }
|
||||
b3ProfileNode* Get_Sibling(void) { return Sibling; }
|
||||
b3ProfileNode* Get_Child(void) { return Child; }
|
||||
|
||||
void CleanupMemory();
|
||||
void Reset( void );
|
||||
void Call( void );
|
||||
bool Return( void );
|
||||
void CleanupMemory();
|
||||
void Reset(void);
|
||||
void Call(void);
|
||||
bool Return(void);
|
||||
|
||||
const char* Get_Name(void) { return Name; }
|
||||
int Get_Total_Calls(void) { return TotalCalls; }
|
||||
float Get_Total_Time(void) { return TotalTime; }
|
||||
void* GetUserPointer() const { return m_userPtr; }
|
||||
void SetUserPointer(void* ptr) { m_userPtr = ptr; }
|
||||
|
||||
const char * Get_Name( void ) { return Name; }
|
||||
int Get_Total_Calls( void ) { return TotalCalls; }
|
||||
float Get_Total_Time( void ) { return TotalTime; }
|
||||
void* GetUserPointer() const {return m_userPtr;}
|
||||
void SetUserPointer(void* ptr) { m_userPtr = ptr;}
|
||||
protected:
|
||||
const char* Name;
|
||||
int TotalCalls;
|
||||
float TotalTime;
|
||||
unsigned long int StartTime;
|
||||
int RecursionCounter;
|
||||
|
||||
const char * Name;
|
||||
int TotalCalls;
|
||||
float TotalTime;
|
||||
unsigned long int StartTime;
|
||||
int RecursionCounter;
|
||||
|
||||
b3ProfileNode * Parent;
|
||||
b3ProfileNode * Child;
|
||||
b3ProfileNode * Sibling;
|
||||
void* m_userPtr;
|
||||
b3ProfileNode* Parent;
|
||||
b3ProfileNode* Child;
|
||||
b3ProfileNode* Sibling;
|
||||
void* m_userPtr;
|
||||
};
|
||||
|
||||
///An iterator to navigate through the tree
|
||||
@@ -86,88 +78,73 @@ class b3ProfileIterator
|
||||
{
|
||||
public:
|
||||
// Access all the children of the current parent
|
||||
void First(void);
|
||||
void Next(void);
|
||||
bool Is_Done(void);
|
||||
bool Is_Root(void) { return (CurrentParent->Get_Parent() == 0); }
|
||||
void First(void);
|
||||
void Next(void);
|
||||
bool Is_Done(void);
|
||||
bool Is_Root(void) { return (CurrentParent->Get_Parent() == 0); }
|
||||
|
||||
void Enter_Child( int index ); // Make the given child the new parent
|
||||
void Enter_Largest_Child( void ); // Make the largest child the new parent
|
||||
void Enter_Parent( void ); // Make the current parent's parent the new parent
|
||||
void Enter_Child(int index); // Make the given child the new parent
|
||||
void Enter_Largest_Child(void); // Make the largest child the new parent
|
||||
void Enter_Parent(void); // Make the current parent's parent the new parent
|
||||
|
||||
// Access the current child
|
||||
const char * Get_Current_Name( void ) { return CurrentChild->Get_Name(); }
|
||||
int Get_Current_Total_Calls( void ) { return CurrentChild->Get_Total_Calls(); }
|
||||
float Get_Current_Total_Time( void ) { return CurrentChild->Get_Total_Time(); }
|
||||
const char* Get_Current_Name(void) { return CurrentChild->Get_Name(); }
|
||||
int Get_Current_Total_Calls(void) { return CurrentChild->Get_Total_Calls(); }
|
||||
float Get_Current_Total_Time(void) { return CurrentChild->Get_Total_Time(); }
|
||||
|
||||
void* Get_Current_UserPointer( void ) { return CurrentChild->GetUserPointer(); }
|
||||
void Set_Current_UserPointer(void* ptr) {CurrentChild->SetUserPointer(ptr);}
|
||||
void* Get_Current_UserPointer(void) { return CurrentChild->GetUserPointer(); }
|
||||
void Set_Current_UserPointer(void* ptr) { CurrentChild->SetUserPointer(ptr); }
|
||||
// Access the current parent
|
||||
const char * Get_Current_Parent_Name( void ) { return CurrentParent->Get_Name(); }
|
||||
int Get_Current_Parent_Total_Calls( void ) { return CurrentParent->Get_Total_Calls(); }
|
||||
float Get_Current_Parent_Total_Time( void ) { return CurrentParent->Get_Total_Time(); }
|
||||
|
||||
|
||||
const char* Get_Current_Parent_Name(void) { return CurrentParent->Get_Name(); }
|
||||
int Get_Current_Parent_Total_Calls(void) { return CurrentParent->Get_Total_Calls(); }
|
||||
float Get_Current_Parent_Total_Time(void) { return CurrentParent->Get_Total_Time(); }
|
||||
|
||||
protected:
|
||||
b3ProfileNode* CurrentParent;
|
||||
b3ProfileNode* CurrentChild;
|
||||
|
||||
b3ProfileNode * CurrentParent;
|
||||
b3ProfileNode * CurrentChild;
|
||||
|
||||
|
||||
b3ProfileIterator( b3ProfileNode * start );
|
||||
friend class b3ProfileManager;
|
||||
b3ProfileIterator(b3ProfileNode* start);
|
||||
friend class b3ProfileManager;
|
||||
};
|
||||
|
||||
|
||||
///The Manager for the Profile system
|
||||
class b3ProfileManager {
|
||||
class b3ProfileManager
|
||||
{
|
||||
public:
|
||||
static void Start_Profile( const char * name );
|
||||
static void Stop_Profile( void );
|
||||
static void Start_Profile(const char* name);
|
||||
static void Stop_Profile(void);
|
||||
|
||||
static void CleanupMemory(void)
|
||||
static void CleanupMemory(void)
|
||||
{
|
||||
Root.CleanupMemory();
|
||||
}
|
||||
|
||||
static void Reset( void );
|
||||
static void Increment_Frame_Counter( void );
|
||||
static int Get_Frame_Count_Since_Reset( void ) { return FrameCounter; }
|
||||
static float Get_Time_Since_Reset( void );
|
||||
static void Reset(void);
|
||||
static void Increment_Frame_Counter(void);
|
||||
static int Get_Frame_Count_Since_Reset(void) { return FrameCounter; }
|
||||
static float Get_Time_Since_Reset(void);
|
||||
|
||||
static b3ProfileIterator * Get_Iterator( void )
|
||||
{
|
||||
|
||||
return new b3ProfileIterator( &Root );
|
||||
static b3ProfileIterator* Get_Iterator(void)
|
||||
{
|
||||
return new b3ProfileIterator(&Root);
|
||||
}
|
||||
static void Release_Iterator( b3ProfileIterator * iterator ) { delete ( iterator); }
|
||||
static void Release_Iterator(b3ProfileIterator* iterator) { delete (iterator); }
|
||||
|
||||
static void dumpRecursive(b3ProfileIterator* profileIterator, int spacing);
|
||||
static void dumpAll();
|
||||
static void dumpRecursive(b3ProfileIterator* profileIterator, int spacing);
|
||||
static void dumpAll();
|
||||
|
||||
static void dumpRecursive(FILE* f, b3ProfileIterator* profileIterator, int spacing);
|
||||
static void dumpAll(FILE* f);
|
||||
static void dumpRecursive(FILE* f, b3ProfileIterator* profileIterator, int spacing);
|
||||
static void dumpAll(FILE* f);
|
||||
|
||||
private:
|
||||
static b3ProfileNode Root;
|
||||
static b3ProfileNode * CurrentNode;
|
||||
static int FrameCounter;
|
||||
static unsigned long int ResetTime;
|
||||
static b3ProfileNode Root;
|
||||
static b3ProfileNode* CurrentNode;
|
||||
static int FrameCounter;
|
||||
static unsigned long int ResetTime;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#endif //#ifndef B3_NO_PROFILE
|
||||
|
||||
|
||||
#endif //#ifndef B3_NO_PROFILE
|
||||
|
||||
|
||||
|
||||
#endif //B3_QUICK_PROF_H
|
||||
|
||||
|
||||
#endif //B3_QUICK_PROF_H
|
||||
|
||||
@@ -19,38 +19,44 @@ subject to the following restrictions:
|
||||
#include "LinearMath/btTransform.h"
|
||||
#include "LinearMath/btVector3.h"
|
||||
|
||||
class b3ReferenceFrameHelper {
|
||||
class b3ReferenceFrameHelper
|
||||
{
|
||||
public:
|
||||
static btVector3 getPointWorldToLocal(const btTransform& localObjectCenterOfMassTransform, const btVector3& point) {
|
||||
return localObjectCenterOfMassTransform.inverse() * point; // transforms the point from the world frame into the local frame
|
||||
static btVector3 getPointWorldToLocal(const btTransform& localObjectCenterOfMassTransform, const btVector3& point)
|
||||
{
|
||||
return localObjectCenterOfMassTransform.inverse() * point; // transforms the point from the world frame into the local frame
|
||||
}
|
||||
|
||||
static btVector3 getPointLocalToWorld(const btTransform& localObjectCenterOfMassTransform,const btVector3& point) {
|
||||
return localObjectCenterOfMassTransform * point; // transforms the point from the world frame into the local frame
|
||||
static btVector3 getPointLocalToWorld(const btTransform& localObjectCenterOfMassTransform, const btVector3& point)
|
||||
{
|
||||
return localObjectCenterOfMassTransform * point; // transforms the point from the world frame into the local frame
|
||||
}
|
||||
|
||||
static btVector3 getAxisWorldToLocal(const btTransform& localObjectCenterOfMassTransform, const btVector3& axis) {
|
||||
btTransform local1 = localObjectCenterOfMassTransform.inverse(); // transforms the axis from the local frame into the world frame
|
||||
btVector3 zero(0,0,0);
|
||||
local1.setOrigin(zero);
|
||||
return local1 * axis;
|
||||
static btVector3 getAxisWorldToLocal(const btTransform& localObjectCenterOfMassTransform, const btVector3& axis)
|
||||
{
|
||||
btTransform local1 = localObjectCenterOfMassTransform.inverse(); // transforms the axis from the local frame into the world frame
|
||||
btVector3 zero(0, 0, 0);
|
||||
local1.setOrigin(zero);
|
||||
return local1 * axis;
|
||||
}
|
||||
|
||||
static btVector3 getAxisLocalToWorld(const btTransform& localObjectCenterOfMassTransform, const btVector3& axis) {
|
||||
btTransform local1 = localObjectCenterOfMassTransform; // transforms the axis from the local frame into the world frame
|
||||
btVector3 zero(0,0,0);
|
||||
local1.setOrigin(zero);
|
||||
return local1 * axis;
|
||||
static btVector3 getAxisLocalToWorld(const btTransform& localObjectCenterOfMassTransform, const btVector3& axis)
|
||||
{
|
||||
btTransform local1 = localObjectCenterOfMassTransform; // transforms the axis from the local frame into the world frame
|
||||
btVector3 zero(0, 0, 0);
|
||||
local1.setOrigin(zero);
|
||||
return local1 * axis;
|
||||
}
|
||||
|
||||
static btTransform getTransformWorldToLocal(const btTransform& localObjectCenterOfMassTransform, const btTransform& transform) {
|
||||
return localObjectCenterOfMassTransform.inverse() * transform; // transforms the axis from the local frame into the world frame
|
||||
static btTransform getTransformWorldToLocal(const btTransform& localObjectCenterOfMassTransform, const btTransform& transform)
|
||||
{
|
||||
return localObjectCenterOfMassTransform.inverse() * transform; // transforms the axis from the local frame into the world frame
|
||||
}
|
||||
|
||||
static btTransform getTransformLocalToWorld(const btTransform& localObjectCenterOfMassTransform, const btTransform& transform) {
|
||||
return localObjectCenterOfMassTransform * transform; // transforms the axis from the local frame into the world frame
|
||||
static btTransform getTransformLocalToWorld(const btTransform& localObjectCenterOfMassTransform, const btTransform& transform)
|
||||
{
|
||||
return localObjectCenterOfMassTransform * transform; // transforms the axis from the local frame into the world frame
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /* B3_REFERENCEFRAMEHELPER_H */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "b3ResourcePath.h"
|
||||
#include "Bullet3Common/b3Logging.h"
|
||||
#ifdef __APPLE__
|
||||
#include <mach-o/dyld.h> /* _NSGetExecutablePath */
|
||||
#include <mach-o/dyld.h> /* _NSGetExecutablePath */
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
@@ -11,7 +11,6 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#include "Bullet3Common/b3FileUtils.h"
|
||||
#define B3_MAX_EXE_PATH_LEN 4096
|
||||
|
||||
@@ -20,13 +19,14 @@ int b3ResourcePath::getExePath(char* path, int maxPathLenInBytes)
|
||||
int numBytes = 0;
|
||||
|
||||
#if __APPLE__
|
||||
uint32_t bufsize = uint32_t(maxPathLenInBytes);
|
||||
uint32_t bufsize = uint32_t(maxPathLenInBytes);
|
||||
|
||||
if (_NSGetExecutablePath(path, &bufsize)!=0)
|
||||
if (_NSGetExecutablePath(path, &bufsize) != 0)
|
||||
{
|
||||
b3Warning("Cannot find executable path\n");
|
||||
return false;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
numBytes = strlen(path);
|
||||
}
|
||||
@@ -39,16 +39,17 @@ int b3ResourcePath::getExePath(char* path, int maxPathLenInBytes)
|
||||
|
||||
#else
|
||||
///http://stackoverflow.com/questions/933850/how-to-find-the-location-of-the-executable-in-c
|
||||
numBytes = (int)readlink("/proc/self/exe", path, maxPathLenInBytes-1);
|
||||
if (numBytes > 0)
|
||||
numBytes = (int)readlink("/proc/self/exe", path, maxPathLenInBytes - 1);
|
||||
if (numBytes > 0)
|
||||
{
|
||||
path[numBytes] = 0;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
b3Warning("Cannot find executable path\n");
|
||||
}
|
||||
#endif //_WIN32
|
||||
#endif //__APPLE__
|
||||
#endif //_WIN32
|
||||
#endif //__APPLE__
|
||||
|
||||
return numBytes;
|
||||
}
|
||||
@@ -59,7 +60,7 @@ struct TempResourcePath
|
||||
TempResourcePath(int len)
|
||||
{
|
||||
m_path = (char*)malloc(len);
|
||||
memset(m_path,0,len);
|
||||
memset(m_path, 0, len);
|
||||
}
|
||||
virtual ~TempResourcePath()
|
||||
{
|
||||
@@ -74,12 +75,13 @@ void b3ResourcePath::setAdditionalSearchPath(const char* path)
|
||||
if (path)
|
||||
{
|
||||
int len = strlen(path);
|
||||
if (len<(B3_MAX_EXE_PATH_LEN-1))
|
||||
if (len < (B3_MAX_EXE_PATH_LEN - 1))
|
||||
{
|
||||
strcpy(sAdditionalSearchPath,path);
|
||||
strcpy(sAdditionalSearchPath, path);
|
||||
sAdditionalSearchPath[len] = 0;
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
sAdditionalSearchPath[0] = 0;
|
||||
}
|
||||
@@ -92,16 +94,16 @@ int b3ResourcePath::findResourcePath(const char* resourceName, char* resourcePat
|
||||
|
||||
bool res = b3FileUtils::findFile(resourceName, resourcePathOut, resourcePathMaxNumBytes);
|
||||
if (res)
|
||||
{
|
||||
return strlen(resourcePathOut);
|
||||
}
|
||||
{
|
||||
return strlen(resourcePathOut);
|
||||
}
|
||||
|
||||
if (sAdditionalSearchPath[0])
|
||||
{
|
||||
TempResourcePath tmpPath(resourcePathMaxNumBytes+1024);
|
||||
TempResourcePath tmpPath(resourcePathMaxNumBytes + 1024);
|
||||
char* resourcePathIn = tmpPath.m_path;
|
||||
sprintf(resourcePathIn,"%s/%s",sAdditionalSearchPath,resourceName);
|
||||
//printf("try resource at %s\n", resourcePath);
|
||||
sprintf(resourcePathIn, "%s/%s", sAdditionalSearchPath, resourceName);
|
||||
//printf("try resource at %s\n", resourcePath);
|
||||
if (b3FileUtils::findFile(resourcePathIn, resourcePathOut, resourcePathMaxNumBytes))
|
||||
{
|
||||
return strlen(resourcePathOut);
|
||||
@@ -111,37 +113,34 @@ int b3ResourcePath::findResourcePath(const char* resourceName, char* resourcePat
|
||||
int l = b3ResourcePath::getExePath(exePath, B3_MAX_EXE_PATH_LEN);
|
||||
if (l)
|
||||
{
|
||||
char pathToExe[B3_MAX_EXE_PATH_LEN];
|
||||
char pathToExe[B3_MAX_EXE_PATH_LEN];
|
||||
|
||||
int exeNamePos = b3FileUtils::extractPath(exePath,pathToExe,B3_MAX_EXE_PATH_LEN);
|
||||
if (exeNamePos)
|
||||
{
|
||||
TempResourcePath tmpPath(resourcePathMaxNumBytes+1024);
|
||||
char* resourcePathIn = tmpPath.m_path;
|
||||
sprintf(resourcePathIn,"%s../data/%s",pathToExe,resourceName);
|
||||
//printf("try resource at %s\n", resourcePath);
|
||||
if (b3FileUtils::findFile(resourcePathIn, resourcePathOut, resourcePathMaxNumBytes))
|
||||
{
|
||||
return strlen(resourcePathOut);
|
||||
}
|
||||
int exeNamePos = b3FileUtils::extractPath(exePath, pathToExe, B3_MAX_EXE_PATH_LEN);
|
||||
if (exeNamePos)
|
||||
{
|
||||
TempResourcePath tmpPath(resourcePathMaxNumBytes + 1024);
|
||||
char* resourcePathIn = tmpPath.m_path;
|
||||
sprintf(resourcePathIn, "%s../data/%s", pathToExe, resourceName);
|
||||
//printf("try resource at %s\n", resourcePath);
|
||||
if (b3FileUtils::findFile(resourcePathIn, resourcePathOut, resourcePathMaxNumBytes))
|
||||
{
|
||||
return strlen(resourcePathOut);
|
||||
}
|
||||
|
||||
sprintf(resourcePathIn,"%s../resources/%s/%s",pathToExe,&exePath[exeNamePos],resourceName);
|
||||
//printf("try resource at %s\n", resourcePath);
|
||||
if (b3FileUtils::findFile(resourcePathIn, resourcePathOut, resourcePathMaxNumBytes))
|
||||
{
|
||||
return strlen(resourcePathOut);
|
||||
}
|
||||
sprintf(resourcePathIn,"%s.runfiles/google3/third_party/bullet/data/%s",exePath,resourceName);
|
||||
//printf("try resource at %s\n", resourcePath);
|
||||
if (b3FileUtils::findFile(resourcePathIn, resourcePathOut, resourcePathMaxNumBytes))
|
||||
{
|
||||
return strlen(resourcePathOut);
|
||||
}
|
||||
}
|
||||
sprintf(resourcePathIn, "%s../resources/%s/%s", pathToExe, &exePath[exeNamePos], resourceName);
|
||||
//printf("try resource at %s\n", resourcePath);
|
||||
if (b3FileUtils::findFile(resourcePathIn, resourcePathOut, resourcePathMaxNumBytes))
|
||||
{
|
||||
return strlen(resourcePathOut);
|
||||
}
|
||||
sprintf(resourcePathIn, "%s.runfiles/google3/third_party/bullet/data/%s", exePath, resourceName);
|
||||
//printf("try resource at %s\n", resourcePath);
|
||||
if (b3FileUtils::findFile(resourcePathIn, resourcePathOut, resourcePathMaxNumBytes))
|
||||
{
|
||||
return strlen(resourcePathOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef _B3_RESOURCE_PATH_H
|
||||
#define _B3_RESOURCE_PATH_H
|
||||
#define _B3_RESOURCE_PATH_H
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -11,4 +11,3 @@ public:
|
||||
static void setAdditionalSearchPath(const char* path);
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user