With all of the upstream changes (see the previous post), it gave me a good opportunity to start anew. SVN r246 offers these benefits over previous versions of pybox2d, in no particular order:
- Python 3k (3.1 tested) support. Many would argue that you wouldn't want to use it, but I have seen very little fps difference in my tests.
- Significantly increased performance. I get a steady 55-60fps on test_Pyramid with the menu drawing disabled, on both Python 2.6 and 3.1. I never got above 40fps on 2.0.1.
- The above is partly related to the new (optional) b2DebugDrawExtended class. It adds slightly to the base b2DebugDrawClass by doing world->screen coordinate conversions in C++ before passing them to Python. Possibly not very useful in the OpenGL case, but very useful for SDL-based systems. I think in my small tests it offered a gain of 5-10fps.
- DebugDraw flags are also implemented as keywords now, so it's unnecessary to pass a bitmask to it.
- Callback functions that used to get b2Vec2s now get tuples -- so you don't risk a crash when holding on to a b2Vec2 instance created on the stack.
- kwarg support for all class __init__ routines. This means you can do things like:
Which would create a static body at (0,3) with a circle (of radius 0.5) and a box (with half-dimensions 0.5,0.5). You can still create things the old fashioned way, if you like. Just remember with the new Box2D there are no b2ShapeDefs.
- kwarg support extended to allow for b2JointDef creation. In the past, you would have had to do
b2RevoluteJointDef.Initialize(bodyA, bodyB, anchorpoint)to get all of the necessary elements properly set, but now the same is possible with
b2RevoluteJointDef(bodyA=a, bodyB=b, anchor=pt, other_kwargs=blah).
- Additional properties for polygon shapes, so that
b2PolygonShape(box=(2.0, 2.0))is sugar for:
s.SetAsBox( (2.0, 2.0) )
(or in the current version,
s.box = (2.0, 2.0))
- You can do: point in b2AABB to see if a vector is inside an AABB.
- Unit tests. You should be able to tell just after installation whether or not the library is working properly.
- A mechanism so that you don't have to keep a reference to the callback classes (e.g., b2DebugDraw). In most cases you would want to have access to it, but it shouldn't crash anymore without it being stored on the Python side. [still need to test this more to ensure it works properly]
- dir() listings are clean for almost every class, so you should be able to see what's possible with a specific
- Improved vector and matrix classes, with more operator support. b2Vec2s are also indexable -- so:
b2Vec2(1,2) = 1
- b2Color has also been enhanced to allow for operators, and useful things like
b2Color.byteto get color components clamped in the [0,255] range are also there.
getAsType()is no longer necessary. Joints and shapes are properly downcast in all instances.
- Plenty of other things from the new C++ code.
- I've been doing my best to keep everything accessible in properties when possible.
- Unused classes are also hidden, and the rest have been gone through and at least basically checked for accessibility/usability.
- [... and all of the other stuff that I've forgotten.]
You can try out this SVN version with:
svn checkout http://pybox2d.googlecode.com/svn/branches/box2d_2.1/ pybox2d
python setup.py develop test
Or just browse the code here.
Keep in mind that this will overwrite your current installed version. The testbed is likely to go through more changes, but the basic API shouldn't be changing much more from now on (unless something unexpected comes from the upstream library).
Like it? Hate it? Lemme know.