Wednesday, February 25, 2009

2.0.2b1 Released!

Since 2.0.2b0, there have been a good deal of changes to pybox2d:

  • 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)
There are several code-breaking features that you might run into:

  • 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:
b2Worldgravity*, jointList, bodyList, groundBody, worldAABB, doSleep
b2Shapefilter*, friction*, restitution*, density*
b2Jointtype, userData, body1, body2, collideConnected
b2CircleShape radius, localPosition
b2PolygonShapevertices, 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!

9 comments:

  1. Incredible progress! I can't wait to play with this in my game :)

    ReplyDelete
  2. Thanks for the comment! I hope it works well for your game.

    ReplyDelete
  3. hey, I'm trying to disable fixedRotation on a body after it's created. Apparently you're supposed to be able to do this with:

    body.m_flags |= b2Body.e_fixedRotationFlag;

    but in pybox2d, m_flags doesn't exist? I tried just "flags" too. Is there any way I can access this?

    ReplyDelete
  4. tazg,

    As m_flags is a private variable on the C++ side, it is inaccessible. As of 2.0.2b1, you cannot change fixedRotation after a body is created.

    You'll notice that just 3 days ago on the C++ end this functionality was added (here, Is/GetFixedRotation).

    I'll probably eventually get around to updating the source, but I'm burnt out on the project after lots of work and a rather disappointing reaction from the community.

    ReplyDelete
  5. well I just discovered that setting inertia to 0 has the same effect as fixedRotation and I can disable it later just by calling SetMassFromShapes, so I'm fine for now. It's too bad you're having a hard time with the project. I for one am thankful for it and prefer it over pymunk, and this was a nice update too.

    ReplyDelete
  6. Glad you found a workaround. And thanks for the encouragement. :)

    ReplyDelete
  7. kne,

    I've heard you mention a few times about the lack of support for PyBox2D, and I understand how you must feel--there's no one stepping up to match your phenomenal efforts, which must not be too encouraging. Do you mind a few personal thoughts?

    I just found out about pybox2d relatively recently, and only then from a chance mention on pygame.org. I'm exceedingly grateful for all the work that you've put into this and want it to flourish. However, I don't know how others are discovering this; and if they do, I think it needs to be acknowledged that Box2D has a non-trivial learning curve with both the API and the underlying physics. This is not in the same league as the "punch the chimp" pygame example. I'm a very experienced programmer, and incorporating this into my games requires a fair bit of skill. The subset of programmers who know Python, a game library, and who are confident enough to want a physics library is a decreasingly smaller pie slice.

    It may be more reasonable to assume that it will take time for Python programmers to hear about PyBox2D as it gradually matures, and then to wrap their minds around it. The way I see it, is that you're at the forefront of making physics readily available to programmers. That to me is exciting.

    What would accelerate PyBox2D's growth is if there was a super-duper simple "punch the chimp" style example for Pygame that would invite extension and experimentation; just a bare-bones demo. Also if there were someone who was good at promotion and knew how to get this cool project out where people could discover it (are there promoters here?). A showcase game wouldn't hurt either, but that's what we all want to accomplish, right? :)

    In any case, I think you're doing a high-quality job, and if it's any consolation, I think it's just going to take some time before momentum builds behind such a focused toolkit. Keep up the great work!

    ReplyDelete
  8. Michael,

    I know my efforts are far from 'phenomenal', but I appreciate the compliment in any case. :) At the beginning I admittedly knew nothing about Python or SWIG (or even Box2D). An experienced person probably could have pumped out the same quality project in perhaps a month or so.

    Both the project and I have come a long way. It's finally at a point where I feel it is mature enough to be more successful than it is. But how successful could it possibly be? I honestly don't know. As you say, there's an incredibly small market for such a library.

    I've thought about making a simple example for a while. But the problem is, well, just what do you include? Pygame/pybox2d initialization, okay. But that's boring; it doesn't show anything (see hello.py). Okay, so add debug drawing or custom drawing. That's not terribly fun without user input. A "simple" example quickly becomes rather complicated. Soon you just have the behemoth that is the testbed.

    As far as promoters go, I'm the one and only. :) No one to bounce ideas off of even. There's the PyGame page, PyPi page, blog, and homepage. Outside of that, pybox2d may as well not exist. I had kind of expected it to get around by word of mouth, or by people talking about using it in their projects. Except for that doesn't happen! I can only guess that I'm doing something terribly wrong with the project, but no one cares enough to clue me in. Or perhaps that I'm expecting way too much out of a niche project.

    At least one positive thing has come out of my desire for some feedback -- I've been taking those extra few seconds myself and thanking developers and submitting bug reports for libraries I use. I see so many developer blogs with no comments. These people pour a good deal of their free time into their side projects and no one even takes a second to stop in and say a simple 'thanks', or 'that sounds cool'. I wonder what drives them to continue their work.

    If you'd like to continue the discussion, please feel free to e-mail me any time. And thanks again. :)

    ReplyDelete
  9. Thank you for your amazing work with pyBox2D!

    ReplyDelete