cpSpaceStep

Discuss new features and future development.
Post Reply
bram
Posts: 25
Joined: Sun May 24, 2009 11:04 pm
Contact:

cpSpaceStep

Post 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
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: cpSpaceStep

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
bram
Posts: 25
Joined: Sun May 24, 2009 11:04 pm
Contact:

Re: cpSpaceStep

Post 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
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: cpSpaceStep

Post by slembcke »

#1) No not really, it's just a multiply and an add in there somewhere.
#2) Basically yes.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests