Some questions about the Bullet engine

Kasper
Posts: 3
Joined: Sat Mar 08, 2008 4:56 pm

Some questions about the Bullet engine

Post by Kasper »

Hi,

I have some questions about the Bullet engine

1.) why are classes like allocators, debugdraw, etc. in the LinearMath folder ?
2.) why is btAssert defined in btScalar.h ?
3.) why are btAssert and assert mixedup in the bt* source and header files ?
4.) why are there no assert and message handlers ?
5.) why you are using placement new and delete from stl instead of defining them your self (i.e. in btNew.h) ?
6.) why are there no memory allocation functions that can be overrriden by the user ?

I ask these questions because I had to make a lot of changes all over the place to implement Bullet in my engine, and I have to do this again when there is a new version of bullet ;(

Thx in advance,
Kasper
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Some questions about the Bullet engine

Post by Erwin Coumans »

Kasper wrote: 1.) why are classes like allocators, debugdraw, etc. in the LinearMath folder ?
2.) why is btAssert defined in btScalar.h ?
3.) why are btAssert and assert mixedup in the bt* source and header files ?
4.) why are there no assert and message handlers ?
Main reason is lazyness and convenience, but it would be good to sort out those things and improve coding standards.

LinearMath evolved so that it got platform dependencies and some abstract interface classes for convenience. A better name for LinearMath would be BaseSystem, and the platform specifics of btScalar could be moved into btPlatform.h. We don't plan on making large changes for Bullet 2.x to maintain stability of the API. However, we gather ideas for a larger refactoring in Bullet 3.x.
All asserts should use btAssert. A global find and replace should be able to deal with this. Assert/message handles can be added, there hasn't been a request for it yet. btAssert could serve this purpose. btIDebugDraw has a 'reportErrorWarning' but there is no global variable/singleton for this. Our main target platform has been Cell SPUs, so globals/singletons wouldn't help much.
5.) why you are using placement new and delete from stl instead of defining them your self (i.e. in btNew.h) ?
6.) why are there no memory allocation functions that can be overrriden by the user ?
Bullet/src doesn't use STL. All internal memory allocations go through btAlignedAllocInternal located inside btAlignedAllocator.cpp files. Bullet is open source, and the assumption was that developers route the btAlignedAllocInternal to their own by modifying the source code, if necessary. But we can add an API for this.

Do you request a 'set' method to set a custom memory allocator?
Can you please make it posible to override the default values DEFAULT_MAX_OVERLAPPING_PAIRS and DEFAULT_STACK_ALLOCATOR_SIZE (and maybe other memory consuming internals) ?
This should not be necessary, you can either pass in your own memory allocators or even create your own btCustomCollisionConfiguration.

Do you have a patch that deals with any/some/all of above issues?
Thanks for the feedback,
Erwin
Kasper
Posts: 3
Joined: Sat Mar 08, 2008 4:56 pm

Re: Some questions about the Bullet engine

Post by Kasper »

Thx,

1.) I added btNew.h (and removed all #include "new" (the double quote's are actually the less and greater sign)), see below
2.) Yes I did a global search / replace on assert's
3.) btAlignedAllocInternal, ok, I agree one place one change I can live whit that, I can add my personal flavour there
4.) sorry I overlookt the idee to make a derived class of btCollisionConfiguration, I'm just a beginner ;)

Replacement of #include "new" -> #include "btNew.h"

-- snap --
#ifndef BULLET_NEW_H
#define BULLET_NEW_H

#define BT_USE_PLACEMENT_NEW 1
#ifdef BT_USE_PLACEMENT_NEW

inline void* operator new(unsigned int, void* p) { return p; }
inline void* operator new[](unsigned int, void* p) { return p; }
inline void operator delete(void*, void*) { return; }
inline void operator delete[](void*, void*) { return; }

#endif // BT_USE_PLACEMENT_NEW
-- snap --