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
cpSpaceStep
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: cpSpaceStep
The conditional is the value used as the elastic coefficient passed to the contact iterations.
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.
Code: Select all
cpFloat elasticCoef = (space->elasticIterations ? 0.0f : 1.0f); // The ?:
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 25
- Joined: Sun May 24, 2009 11:04 pm
- Contact:
Re: cpSpaceStep
So it does the same calculations, only with coefficient 0.slembcke wrote:The conditional is the value used as the elastic coefficient passed to the contact iterations.
Would the code be faster if it skipped the computations instead of using a 0 factor?
So it first applies impulses calculated from previous frame, then calculates impulses for this frame, and applies those as well?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.
Bram
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: cpSpaceStep
#1) No not really, it's just a multiply and an add in there somewhere.
#2) Basically yes.
#2) Basically yes.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Who is online
Users browsing this forum: No registered users and 7 guests