cpSpaceStep

Discuss new features and future development.

cpSpaceStep

Postby bram » Sun Oct 18, 2009 5:03 pm

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
bram
 
Posts: 25
Joined: Sun May 24, 2009 11:04 pm

Re: cpSpaceStep

Postby slembcke » Sun Oct 18, 2009 8:50 pm

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

Re: cpSpaceStep

Postby bram » Sun Oct 18, 2009 9:08 pm

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
bram
 
Posts: 25
Joined: Sun May 24, 2009 11:04 pm

Re: cpSpaceStep

Postby slembcke » Mon Oct 19, 2009 8:04 am

#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/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm


Return to Features/Development

Who is online

Users browsing this forum: No registered users and 2 guests

cron