Added b3Printf, b3Warning and b3Error that can be re-routed to custom handlers.
See in src/Bullet3Common/b3Logging.h for details
This commit is contained in:
@@ -127,7 +127,7 @@ void* b3AlignedAllocInternal (size_t size, int alignment,int line,char* filen
|
||||
ret = (void *)(real);//??
|
||||
}
|
||||
|
||||
printf("allocation#%d at address %x, from %s,line %d, size %d\n",b3g_numAlignedAllocs,real, filename,line,size);
|
||||
b3Printf("allocation#%d at address %x, from %s,line %d, size %d\n",b3g_numAlignedAllocs,real, filename,line,size);
|
||||
|
||||
int* ptr = (int*)ret;
|
||||
*ptr = 12;
|
||||
@@ -145,12 +145,12 @@ void b3AlignedFreeInternal (void* ptr,int line,char* filename)
|
||||
int size = *((int*)(ptr)-2);
|
||||
b3g_totalBytesAlignedAllocs -= size;
|
||||
|
||||
printf("free #%d at address %x, from %s,line %d, size %d\n",b3g_numAlignedFree,real, filename,line,size);
|
||||
b3Printf("free #%d at address %x, from %s,line %d, size %d\n",b3g_numAlignedFree,real, filename,line,size);
|
||||
|
||||
b3s_freeFunc(real);
|
||||
} else
|
||||
{
|
||||
printf("NULL ptr\n");
|
||||
b3Printf("NULL ptr\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ void* b3AlignedAllocInternal (size_t size, int alignment)
|
||||
b3g_numAlignedAllocs++;
|
||||
void* ptr;
|
||||
ptr = b3s_alignedAllocFunc(size, alignment);
|
||||
// printf("b3AlignedAllocInternal %d, %x\n",size,ptr);
|
||||
// b3Printf("b3AlignedAllocInternal %d, %x\n",size,ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ void b3AlignedFreeInternal (void* ptr)
|
||||
}
|
||||
|
||||
b3g_numAlignedFree++;
|
||||
// printf("b3AlignedFreeInternal %x\n",ptr);
|
||||
// b3Printf("b3AlignedFreeInternal %x\n",ptr);
|
||||
b3s_alignedFreeFunc(ptr);
|
||||
}
|
||||
|
||||
|
||||
69
src/Bullet3Common/b3Logging.cpp
Normal file
69
src/Bullet3Common/b3Logging.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "b3Logging.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
void b3PrintfFuncDefault(const char* msg)
|
||||
{
|
||||
printf(msg);
|
||||
}
|
||||
|
||||
void b3WarningMessageFuncDefault(const char* msg)
|
||||
{
|
||||
printf(msg);
|
||||
}
|
||||
|
||||
void b3ErrorMessageFuncDefault(const char* msg)
|
||||
{
|
||||
printf(msg);
|
||||
}
|
||||
|
||||
static b3PrintfFunc* b3s_printfFunc = b3PrintfFuncDefault;
|
||||
static b3WarningMessageFunc* b3s_warningMessageFunc = b3WarningMessageFuncDefault;
|
||||
static b3ErrorMessageFunc* b3s_errorMessageFunc = b3ErrorMessageFuncDefault;
|
||||
|
||||
|
||||
///The developer can route b3Printf output using their own implementation
|
||||
void b3SetCustomPrintfFunc(b3PrintfFunc* printfFunc)
|
||||
{
|
||||
b3s_printfFunc = printfFunc;
|
||||
}
|
||||
void b3SetCustomWarningMessageFunc(b3PrintfFunc* warningMessageFunc)
|
||||
{
|
||||
b3s_warningMessageFunc = warningMessageFunc;
|
||||
}
|
||||
void b3SetCustomErrorMessageFunc(b3PrintfFunc* errorMessageFunc)
|
||||
{
|
||||
b3s_errorMessageFunc = errorMessageFunc;
|
||||
}
|
||||
|
||||
|
||||
void b3OutputPrintfVarArgsInternal(const char *str, ...)
|
||||
{
|
||||
char strDebug[1024]={0};
|
||||
va_list argList;
|
||||
va_start(argList, str);
|
||||
vsprintf_s(strDebug,str,argList);
|
||||
(b3s_printfFunc)(strDebug);
|
||||
va_end(argList);
|
||||
}
|
||||
void b3OutputWarningMessageVarArgsInternal(const char *str, ...)
|
||||
{
|
||||
char strDebug[1024]={0};
|
||||
va_list argList;
|
||||
va_start(argList, str);
|
||||
vsprintf_s(strDebug,str,argList);
|
||||
(b3s_warningMessageFunc)(strDebug);
|
||||
va_end(argList);
|
||||
}
|
||||
void b3OutputErrorMessageVarArgsInternal(const char *str, ...)
|
||||
{
|
||||
char strDebug[1024]={0};
|
||||
va_list argList;
|
||||
va_start(argList, str);
|
||||
vsprintf_s(strDebug,str,argList);
|
||||
(b3s_errorMessageFunc)(strDebug);
|
||||
va_end(argList);
|
||||
}
|
||||
|
||||
|
||||
30
src/Bullet3Common/b3Logging.h
Normal file
30
src/Bullet3Common/b3Logging.h
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
#ifndef B3_LOGGING_H
|
||||
#define B3_LOGGING_H
|
||||
|
||||
|
||||
typedef void (b3PrintfFunc)(const char* msg);
|
||||
typedef void (b3WarningMessageFunc)(const char* msg);
|
||||
typedef void (b3ErrorMessageFunc)(const char* msg);
|
||||
|
||||
///The developer can route b3Printf output using their own implementation
|
||||
void b3SetCustomPrintfFunc(b3PrintfFunc* printfFunc);
|
||||
void b3SetCustomWarningMessageFunc(b3WarningMessageFunc* warningMsgFunc);
|
||||
void b3SetCustomErrorMessageFunc(b3ErrorMessageFunc* errorMsgFunc);
|
||||
|
||||
///Don't use those internal functions directly, use the b3Printf or b3SetCustomPrintfFunc instead (or warning/error version)
|
||||
void b3OutputPrintfVarArgsInternal(const char *str, ...);
|
||||
void b3OutputWarningMessageVarArgsInternal(const char *str, ...);
|
||||
void b3OutputErrorMessageVarArgsInternal(const char *str, ...);
|
||||
|
||||
///You can also customize the message by uncommenting out a different line below
|
||||
#define b3Printf(...) b3OutputPrintfVarArgsInternal(__VA_ARGS__)
|
||||
//#define b3Printf(...) {b3OutputPrintfVarArgsInternal("b3Printf[%s,%d]:",__FILE__,__LINE__);b3OutputPrintfVarArgsInternal(__VA_ARGS__); }
|
||||
//#define b3Printf b3OutputPrintfVarArgsInternal
|
||||
//#define b3Printf(...) printf(__VA_ARGS__)
|
||||
//#define b3Printf(...)
|
||||
|
||||
#define b3Warning(...) {b3OutputWarningMessageVarArgsInternal("b3Warning[%s,%d]:\n",__FILE__,__LINE__);b3OutputWarningMessageVarArgsInternal(__VA_ARGS__); }
|
||||
#define b3Error(...) {b3OutputErrorMessageVarArgsInternal("b3Error[%s,%d]:\n",__FILE__,__LINE__);b3OutputErrorMessageVarArgsInternal(__VA_ARGS__); }
|
||||
|
||||
#endif//B3_LOGGING_H
|
||||
@@ -525,10 +525,10 @@ void b3ProfileManager::dumpRecursive(b3ProfileIterator* profileIterator, int spa
|
||||
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++) printf(".");
|
||||
printf("----------------------------------\n");
|
||||
for (i=0;i<spacing;i++) printf(".");
|
||||
printf("Profiling: %s (total running time: %.3f ms) ---\n", profileIterator->Get_Current_Parent_Name(), parent_time );
|
||||
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 );
|
||||
float totalTime = 0.f;
|
||||
|
||||
|
||||
@@ -541,19 +541,19 @@ void b3ProfileManager::dumpRecursive(b3ProfileIterator* profileIterator, int spa
|
||||
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++) printf(".");
|
||||
int i; for (i=0;i<spacing;i++) b3Printf(".");
|
||||
}
|
||||
printf("%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
|
||||
}
|
||||
|
||||
if (parent_time < accumulated_time)
|
||||
{
|
||||
printf("what's wrong\n");
|
||||
b3Printf("what's wrong\n");
|
||||
}
|
||||
for (i=0;i<spacing;i++) printf(".");
|
||||
printf("%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<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++)
|
||||
{
|
||||
|
||||
@@ -23,12 +23,13 @@ subject to the following restrictions:
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>//size_t for MSVC 6.0
|
||||
#include <float.h>
|
||||
|
||||
/* SVN $Revision$ on $Date$ from http://bullet.googlecode.com*/
|
||||
#define B3_BULLET_VERSION 281
|
||||
//Original repository is at http://github.com/erwincoumans/bullet3
|
||||
#define B3_BULLET_VERSION 300
|
||||
|
||||
inline int b3GetVersion()
|
||||
{
|
||||
@@ -39,6 +40,8 @@ inline int b3GetVersion()
|
||||
#define B3_DEBUG
|
||||
#endif
|
||||
|
||||
#include "b3Logging.h"//for b3Error
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -88,7 +91,7 @@ inline int b3GetVersion()
|
||||
#ifdef B3_DEBUG
|
||||
#ifdef _MSC_VER
|
||||
#include <stdio.h>
|
||||
#define b3Assert(x) { if(!(x)){printf("Assert "__FILE__ ":%u ("#x")\n", __LINE__);__debugbreak(); }}
|
||||
#define b3Assert(x) { if(!(x)){b3Error("Assert "__FILE__ ":%u ("#x")\n", __LINE__);__debugbreak(); }}
|
||||
#else//_MSC_VER
|
||||
#include <assert.h>
|
||||
#define b3Assert assert
|
||||
@@ -116,7 +119,7 @@ inline int b3GetVersion()
|
||||
#ifdef __SPU__
|
||||
#include <spu_printf.h>
|
||||
#define printf spu_printf
|
||||
#define b3Assert(x) {if(!(x)){printf("Assert "__FILE__ ":%u ("#x")\n", __LINE__);spu_hcmpeq(0,0);}}
|
||||
#define b3Assert(x) {if(!(x)){b3Error("Assert "__FILE__ ":%u ("#x")\n", __LINE__);spu_hcmpeq(0,0);}}
|
||||
#else
|
||||
#define b3Assert assert
|
||||
#endif
|
||||
@@ -201,7 +204,7 @@ inline int b3GetVersion()
|
||||
{\
|
||||
if(!(x))\
|
||||
{\
|
||||
printf("Assert %s in line %d, file %s\n",#x, __LINE__, __FILE__);\
|
||||
b3Error("Assert %s in line %d, file %s\n",#x, __LINE__, __FILE__);\
|
||||
asm volatile ("int3");\
|
||||
}\
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user