I have spent a good month now redoing everything in the project, but I've hit a bit of a wall. It's pretty much in a "good enough" state for a release, minus a few of the testbed examples I have yet to port. Oh, and all of the documentation. Ugh. Now with Box2D's wiki down, it makes it even more difficult.
There's that old adage "release early; release often", but I find it hard to jump on that bandwagon. Releases are very difficult to do in the first place for multiple platforms and multiple versions of Python. And then support them afterward? Forget it. Oh well. I might continue at a slow pace for a while and wrap some more things up for a release whenever I manage to get a bunch of free time again, or maybe not. There's a bunch more changes on the SVN since the last blog post if you have any interest.
Perhaps this will take over in the meantime?
Saturday, January 16, 2010
Sunday, January 10, 2010
svn r246 (2.1.0 branch)
As I mentioned in the previous post, I've been working on the new version of pybox2d, based on the work-in-progress C++ library Box2D 2.1.0.
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:
You can try out this SVN version with:
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.
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:
self.world.CreateBody(
b2BodyDef(
type=b2_staticBody,
position=(0,3),
fixtures=[b2CircleShape(radius=0.5),
b2PolygonShape(box=(0.5, 0.5))],
)
)
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 withb2RevoluteJointDef(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=b2PolygonShape()
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)[0] = 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
cd pybox2d
python setup.py develop test
cd examples
python test_ApplyForce.py
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.
Monday, December 28, 2009
End of the year status
Hello to the loyal couple of you who continue to refresh this lonely blog. :)
I scrapped the branch I started on 6 months ago of the new version of pybox2d. The upstream library Box2D (now also hosted on Google Code) has seen a good deal of changes since then.
The most notable changes are:
Here are some things I'm trying to do with the upcoming version of pybox2d:
Any thoughts? What would you like to see in the new version? Yell at me and tell me what I'm doing wrong before I get too far into it.
I scrapped the branch I started on 6 months ago of the new version of pybox2d. The upstream library Box2D (now also hosted on Google Code) has seen a good deal of changes since then.
The most notable changes are:
- The new dynamic tree-based broadphase This makes it such that there will no longer be a maximum proxy count. So, you won't see b2_maxProxies assertion errors when you try to create too many colliding shapes.
- Normalized and simplified class interfaces The improved interface makes for an easier time in creating Pythonic properties.
- Kinematic bodies These special bodies are essentially static in that they don't respond to collisions, but they can have their velocities set. I'd imagine they would be most useful as, for example, rotating platforms in some side-scroller.
- The removal of shape definitions and the addition of fixtures I don't see this as offering much benefit to us on the Python end, but it allows shapes to be created and used without being attached to bodies. It makes for a great deal of changes for those attempting to port their code to the most recent version.
- One-sided platforms
- No more SetMassFromShapes() nonsense
- New collision callback system
- Weld and friction joints
- Controllers have been removed This is unfortunate, but was anyone actually using them?
Here are some things I'm trying to do with the upcoming version of pybox2d:
- Unit tests I'm attempting to use unit tests (suggestions would be welcome on this, as I'm fairly new to it) as I go along to ensure all of the properties work and I don't break things along the way.
- Hide all getters and setters, while keeping things accessible in properties I like this a lot, but I hate seeing the ugly __ClassName_GetterHere-type things when doing a dir(). Should I just skip the hiding and make it semi-private with _Getter to avoid the lengthy name-mangling? Should I re-implement __dir__ to hide these? I would just rather not have users calling the functions when there are perfectly good properties in place.
- Properly downcast joints/shapes So calls like b2Joint.downcast() (or previously getAsType()) are no longer necessary.
- Custom __setattr__? I've been toying with the possibility of using a custom setattr to keep the user from trying to set shadow class instance variables that don't exist in the real class. Maybe I'll make it an option or decide after performance tests.
- Eventual 64-bit and Python 3.x compatibility
- Pythonic-ish initializers? I've also been considering having the ability to do, for example:
- Scrapping deprecated stuff, hiding unusable classes, pickling, etc.
body.CreateFixture(b2FixtureDef(shape=b2CircleShape(radius=1), density=1, friction=0.3))
Any interest in that? It's simple sugar, but it could be useful.
Any thoughts? What would you like to see in the new version? Yell at me and tell me what I'm doing wrong before I get too far into it.
Tuesday, June 9, 2009
Status?
pybox2d isn't dead just yet.
A few days ago, I started porting the bleeding-edge version of the library.
Some changes include the addition of b2Fixture, contact listener changes, a new way to create edge chains, and significant algorithm changes. More information on these C++-specific changes can be found on the forums and the Box2D SVN changelog.
As it is a departure from the previous builds, it will stay as a branch on here at least until it's significantly improved over the trunk. I'm not entirely happy about the significant API changes that are occurring, but I'm just bringing to Python what Erin Catto and others are making available to the C++-world. I guess what I'm trying to say is, well, don't shoot the messenger.
A few days ago, I started porting the bleeding-edge version of the library.
Some changes include the addition of b2Fixture, contact listener changes, a new way to create edge chains, and significant algorithm changes. More information on these C++-specific changes can be found on the forums and the Box2D SVN changelog.
As it is a departure from the previous builds, it will stay as a branch on here at least until it's significantly improved over the trunk. I'm not entirely happy about the significant API changes that are occurring, but I'm just bringing to Python what Erin Catto and others are making available to the C++-world. I guess what I'm trying to say is, well, don't shoot the messenger.
Friday, March 6, 2009
Project spotlight: Mekanimo
Mekanimo is a 2D physics simulator. In minutes, you can create simulations, interactive games and puzzles, dazzling graphics and share them with others through the Internet.Mekanimo really surprised me with its professional-looking user interface. It allows for the creation of worlds with customizable scripting, various plots, and so many other things. I enjoyed trying out the exhibits like the marble pump, which require you to copy and paste the code into Mekanimo for now -- I think the author Fahri has been putting much more into the application itself than its website.
It's still got a ways to go and unfortunately is (for now?) closed source, but keep an eye on it. I expect it to turn into a really nice and polished learning/design tool some day.
pybox2d svn r184
Bugfix: Linux/x64 build issue.
Updated to Box2D r204:
b2Body now has these additional functions:
IsRotationFixed -> IsFixedRotation (property fixedRotation)
CanSleep -> IsAllowSleeping (property allowSleep)
Updated to Box2D r204:
b2Body now has these additional functions:
- SetLinear/AngularDamping (additionally accessible by body.linearDamping = (x,y) )
- SetStatic
- SetFixedRotation (additionally accessible by body.fixedRotation = True)
- SetSensor
IsRotationFixed -> IsFixedRotation (property fixedRotation)
CanSleep -> IsAllowSleeping (property allowSleep)
Wednesday, February 25, 2009
2.0.2b1 Released!
Since 2.0.2b0, there have been a good deal of changes to pybox2d:
The following are the additional properties added. Most are just for convenience and make the definition (e.g., b2ShapeDef) symmetric with the output (e.g., b2Shape). Ones with * are changeable; the rest are read-only:
Basic epydoc documentation is now available here. The testbed is no longer included in the installer, so please download it separately here.
Releasing for all these operating systems all by myself is time consuming, confusing, and tough at times. I'm sure I got something wrong, so please go easy on me. :) Do let me know if something doesn't work for you, though.
Enjoy!
- Code structure completely reorganized
- Doxygen comments converted to docstrings (should be a bit more friendly now, but still a bit C++'ish in places)
- Lists and tuples may be used anywhere in place of b2Vec2's, and all of the tests have been updated to reflect this
- Save/load state (pickling support for worlds)
- Bug fix: Seg faults during DebugDraw/etc callbacks
- Bug fix: userData reference counting causing leaks
- Bug fix: getType() didn't work on line joints
- Bug fix: TestSegment now returns from (-1,0,1) and not a bool
- b2PolygonDef.setVertices() added, supports either b2Vec2 or list/tuple, so no need to specify. Old setVertices_tuple/b2Vec2() are deprecated.
- New pretty printing style. It takes up a good deal of space, but it's actually readable.
- New examples: bezier edges with thin line segments, a simple belt, basic pickling example (might needs some updating)
- (Optionally compilable) C++ assertion failures turned into Python exceptions
Additional properties and accessors to make coding easier (see below) - Many tests were updated and rewritten to be cleaner
- Added b2CheckPolygonDef and deprecated the Python ported version. This version adds (optional) additional checks to ensure that your shape is convex and properly sized to not have strange results
- Added GetVertices() for b2EdgeShapes. Creating one b2ChainDef results in many b2EdgeShapes, so this properly loops through each connected shape and gets the vertices in order
- Box2D source updated, b2GravityController fixed
- A fix for not allowing b2Body/Joint/Controller/Shapes as dictionary keys. Don't know how I missed this one. Still won't be picklable unfortunately.
- Basic iterators have been added: b2World (iterates over bodies), b2Body (iterates over shapes), b2Controller (iterates over bodies), b2PolygonShape (iterates over vertices)
- The library is now called Box2D (and not the cumbersome Box2D2)
- Controllers now follow the factory style (see the buoyancy test for more information)
- b2Distance updated (see here if this affects you)
- b2Body.GetShapeList() used to return only first shape, now returns actual list
- b2World.GetBodyList/Joint() used to return only first body, now returns actual list
- All occurences of the ugly 'm_' have been removed. This might require some changes in your code, since this applies to all b2Joint.m_* and others, not just testbed stuff.
The following are the additional properties added. Most are just for convenience and make the definition (e.g., b2ShapeDef) symmetric with the output (e.g., b2Shape). Ones with * are changeable; the rest are read-only:
| b2World | gravity*, jointList, bodyList, groundBody, worldAABB, doSleep |
| b2Shape | filter*, friction*, restitution*, density* |
| b2Joint | type, userData, body1, body2, collideConnected |
| b2CircleShape | radius, localPosition |
| b2PolygonShape | vertices, coreVertices, normals |
| b2Body | massData*, position*, angle*, linearDamping, angularDamping, allowSleep*, isSleeping, IsRotationFixed, isBullet*, angularVelocity*, linearVelocity*, shapeList |
Basic epydoc documentation is now available here. The testbed is no longer included in the installer, so please download it separately here.
Releasing for all these operating systems all by myself is time consuming, confusing, and tough at times. I'm sure I got something wrong, so please go easy on me. :) Do let me know if something doesn't work for you, though.
Enjoy!
Subscribe to:
Posts (Atom)