erincatto / box2d

Box2D is a 2D physics engine for games
https://box2d.org
MIT License
8.17k stars 1.53k forks source link

missing api for fixture traversal #733

Closed Green-Sky closed 1 year ago

Green-Sky commented 1 year ago

I wanted to look at all the fixtures of a body for serialization purposes and noticed the https://github.com/erincatto/box2d/blob/9dc24a6fd4f32442c4bcf80791de47a0a7d25afb/include/box2d/b2_body.h#L360-L362 getter set of methods. BUT there is no way to know the length of the array! both m_fixtureCount and fixture.m_next are private/protected and inaccessible from outside.

To fix this, it would be trivial to expose a GetFixtureCount() returning m_fixtureCount.

Since this is a linked list, other ways would be possible, but they are not as easy.

erincatto commented 1 year ago

The count is not in the API because I consider it an internal detail that may change. Also notice that there is no count for the joints and contacts.