Bullet Physics on Wii

User avatar
vswbmw
Posts: 4
Joined: Mon May 25, 2009 10:26 am

Bullet Physics on Wii

Post by vswbmw »

I've used Bullet Physics to implement collision & dynamics parts of unannounced Wii game.
And I would like to describe some issues and advantages which I have encountered.

1. Data aligning & ATTRIBUTE_ALIGNED16 usage
Bullet use ATTRIBUTE_ALIGNED16 macro to align data e.g.

Code: Select all

ATTRIBUTE_ALIGNED16(class) btVector3
{
...
};
On most (non win32) platforms this gives result:

Code: Select all

class __attribute__ ((aligned (16))) btVector3
{
...
};
But on metroworks wii compiler, code above does not align the data.
To align data we must write something like this:

Code: Select all

class btVector3
{
} __attribute__ ((aligned (16)));
For our build I was defined macro like EXTRA_ATTRIBUTE_ALIGNED16 in btScalar.h and use it after class closing brace:

Code: Select all

#if MYPLATFORM
#define EXTRA_ATTRIBUTE_ALIGNED16 __attribute__ ((aligned (16)))
#define ATTRIBUTE_ALIGNED16(a)    a
#endif
ATTRIBUTE_ALIGNED16(class) btVector3
{
...
} EXTRA_ATTRIBUTE_ALIGNED16;
I'll post other issues later. Maybe there is some mistakes, anyway it works in my current build :)
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Bullet Physics on Wii

Post by Erwin Coumans »

Have you tried

Code: Select all

#ifdef MY_PLATFORM
#define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
#endif //MY_PLATFORM
ATTRIBUTE_ALIGNED16(btVector3) should expand to

Code: Select all

class btVector3
{
}__attribute__ ((aligned (16)));
which works fine for gcc compilers etc.

Thanks,
Erwin
kester
Posts: 27
Joined: Mon Dec 01, 2008 5:08 am

Re: Bullet Physics on Wii

Post by kester »

Hi,

We did the same thing, only named it ATTRIBUTE_ALIGNED16_BEGIN and ATTRIBUTE_ALIGNED16_END:

The only effect of the aligned attribute on Codewarrior is to pad the structure - it doesn't call any aligned allocators. :roll:
User avatar
vswbmw
Posts: 4
Joined: Mon May 25, 2009 10:26 am

Re: Bullet Physics on Wii

Post by vswbmw »

Erwin Coumans wrote:Have you tried

Code: Select all

#ifdef MY_PLATFORM
#define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
#endif //MY_PLATFORM
ATTRIBUTE_ALIGNED16(btVector3) should expand to

Code: Select all

class btVector3
{
}__attribute__ ((aligned (16)));
which works fine for gcc compilers etc.

Thanks,
Erwin
Thanks for reply, how ATTRIBUTE_ALIGNED16(btVector3) expands to

Code: Select all

class btVector3
{
}__attribute__ ((aligned (16)));
When I can write ATTRIBUTE_ALIGNED16(btVector3) to do this?
Somewhere in class declaration? In Bullet on gcc this macro used as:

Code: Select all

ATTRIBUTE_ALIGNED16(class) btVector3
{
...
};
and expands to

Code: Select all

class __attribute__ ((aligned (16))) btVector3
{
...
};
Or I am not right?
Last edited by vswbmw on Tue Jun 09, 2009 9:54 am, edited 1 time in total.
User avatar
vswbmw
Posts: 4
Joined: Mon May 25, 2009 10:26 am

Re: Bullet Physics on Wii

Post by vswbmw »

kester wrote:Hi,

We did the same thing, only named it ATTRIBUTE_ALIGNED16_BEGIN and ATTRIBUTE_ALIGNED16_END:

The only effect of the aligned attribute on Codewarrior is to pad the structure - it doesn't call any aligned allocators. :roll:
We're using custom memory allocator which supports aligned allocations & call btAlignedAllocSetCustomAligned to override bullet allocator functions and define BT_HAS_ALIGNED_ALLOCATOR.