Page 1 of 1

cpSpaceStep

PostPosted: Sun Oct 18, 2009 5:03 pm
by bram
Hi

I am confused about cpSpaceStep() implementation.
For instance, take this code snippet:

// Run the impulse solver.
// run the old-style elastic solver if elastic iterations are disabled
cpFloat elasticCoef = (space->elasticIterations ? 0.0f : 1.0f);
for(int i=0; i<space->iterations; i++){
for(int j=0; j<arbiters->num; j++)
cpArbiterApplyImpulse((cpArbiter *)arbiters->arr[j], elasticCoef);

for(int j=0; j<constraints->num; j++){
cpConstraint *constraint = (cpConstraint *)constraints->arr[j];
constraint->klass->applyImpulse(constraint);
}
}

According to the comment, the old-style elastic solver is run *if* elastic iterations are disabled.
I have 8 elastic iterations, but it seems to execute the quoted code anyways.
I don't see the 'conditional part' here.

Also... I tried to follow the cached impulses.
I would expect some mechanism that says 'if cached do cheap stuff else do expensive stuff'.
However, I can't find this test. It seems that the expensive stuff is done every frame?

Bram

Re: cpSpaceStep

PostPosted: Sun Oct 18, 2009 8:50 pm
by slembcke
The conditional is the value used as the elastic coefficient passed to the contact iterations.
Code: Select all
cpFloat elasticCoef = (space->elasticIterations ? 0.0f : 1.0f); // The ?:


There is no "cheap path" exactly. What it does is use the cached impulses as a starting solution to the next step's set of iterations. Because of that, you can get the stability of using 100 iterations from using 10-20 iterations. That is what makes it fast.

Re: cpSpaceStep

PostPosted: Sun Oct 18, 2009 9:08 pm
by bram
slembcke wrote:The conditional is the value used as the elastic coefficient passed to the contact iterations.


So it does the same calculations, only with coefficient 0.
Would the code be faster if it skipped the computations instead of using a 0 factor?

slembcke wrote:There is no "cheap path" exactly. What it does is use the cached impulses as a starting solution to the next step's set of iterations. Because of that, you can get the stability of using 100 iterations from using 10-20 iterations. That is what makes it fast.


So it first applies impulses calculated from previous frame, then calculates impulses for this frame, and applies those as well?

Bram

Re: cpSpaceStep

PostPosted: Mon Oct 19, 2009 8:04 am
by slembcke
#1) No not really, it's just a multiply and an add in there somewhere.
#2) Basically yes.