Hi guys,

Here’s a bit of background info…

I am developing a verlet physics engine with collision detection and support for solving constraints through relaxation. I am aware of existing engines such as Box2D; I’m doing this simply as a programming exercise.

‘Relaxation’ of constraints, if you’re unaware, is simply iteratively applying equational rules to values, with the number of iterations determining how well each rule is satisfied. Effectively this is making ‘constraints’ into ‘restraints’, since there may not be a specific value satisfying all constraints.

In order to optimise performance, I’ve been probing options for efficient implementation of constraints. Performance priorities are, as you’d expect, to minimise the number of iterations going on, and minimise the number of function calls made.

To support the modular nature of the engine, it would be nice to implement each constraint as a Function object, which would operate on only one out of each set of values (e.g. one x, y out of a set of coordinates).

The issue facing me is that such an implementation will clearly produce a large number of function calls, since I’ll be calling each constraint Function once for each value in the set, and doing this N times assuming N iterations of the relaxation loop.

An alternative route would be to simply have each constraint operate on the set itself. However, to satisfy my curiosity, I wondered whether there were any other options available which would produce a high performance implementation. More specifically, is there any way to inline a function, without using the haXe AS3.0 derivative language? I suppose I could simply write a script to do this myself, but I’m interested to discover whether there is a fitting application I haven’t yet found via Google.

Note that I mean ‘inline’ in the C++ sense, that is to say the function contents are simply inserted as code lines wherever the function is called.

Excuse the long-winded nature of this post, I’d prefer to give as much relevant information as possible.

Many thanks!