Proposal: controllers

As discussed in viewtopic.php?f=4&t=3734 I'm adding a proposal to reintroduce the concept of controllers. I found it very useful to attach physics properties/behavior to bodies (as buoyancy, non-standard gravity, guidance system, etc.).

Actually I'm implementing them using some wrappers: a b2Body wrapper that stores the list of controllers attached to a body, and a b2World wrapper storing the whole list of controllers. Another wrapper around b2World::Step() execute all controllers before calling the Step() method.

This seems works nicely but, of course, is not directly supported in core.

As there is a similar proposal about joints in viewtopic.php?f=4&t=3970, I think would be useful to understand what feature would be more interesting to Box2D users. Simply to know with which to start.
Please explain for us how having core support makes controllers significantly easier/better.

When Box2D had controllers before, b2World would just keep a list of controllers and then loop through them at the beginning of the time step. They were not hooked into the solver.

So why not just keep an external list of controllers and loop through them before calling b2World::Step?
Quote:
Please explain for us how having core support makes controllers significantly easier/better.


I think that having controllers in core could be beneficial for two main reasons:
  1. having a "standard" interface allow people to share developed controllers; custom hacks to Box2D can't be easily shared.
  2. lifetime of controllers "attached" to b2Body objects can be managed directly (and maybe more efficiently) by b2World, instead to have a lot of custom wrappers to avoid memory leaks and so on.
Now I come to review controllers, I think the standard interface for them is crap. I chose it as minimal impact to the library while still allowing all sorts of controllers, but it's really too general. Like accepting more than two bodies for a spring?

I have a counter-proposal for controllers, involving having controllers and a simple event framework in Contrib. The event framework would also be a wrapper of sorts, but abstracted from controllers, to just provide event hooks. Controllers would then not have to conform to a standard interface, they could each attach to the events how it is best for them. The details will have to wait.

Original thread: https://box2d.org/forum/viewtopic.php?t=3972