In Box2D there are several functions to obtain a list of objects.
In particular I spotted two kind of these functions:
The latter needs a callback that gets called for any matching element until they're over or until the user is satisfied.
I find this second kind to be pretty awkward. The advantage of it is that the engine does only the needed computation, and doesn't waste CPU loops, but I think it's possible to do another way (which I think would be better):
Why not using iterators? That's it, iterators compatible with STL/boost, with an operator++ to iterate thru elements, functions begin() and end() and so on.
This way all of Box2D lists will have a homogeneous interface, and they'll be compatible with other standard tools (many std algorithms and boost functions, like std::for_each, std::find, std::count_if, BOOST_FOREACH ... ).
In particular I spotted two kind of these functions:
- Functions like b2World::GetBodyList()
- Functions like b2World::QueryAABB
The latter needs a callback that gets called for any matching element until they're over or until the user is satisfied.
I find this second kind to be pretty awkward. The advantage of it is that the engine does only the needed computation, and doesn't waste CPU loops, but I think it's possible to do another way (which I think would be better):
Why not using iterators? That's it, iterators compatible with STL/boost, with an operator++ to iterate thru elements, functions begin() and end() and so on.
This way all of Box2D lists will have a homogeneous interface, and they'll be compatible with other standard tools (many std algorithms and boost functions, like std::for_each, std::find, std::count_if, BOOST_FOREACH ... ).