SpatialHash in version 6

Discuss new features and future development.
Post Reply
BobbyGilbert
Posts: 13
Joined: Fri Oct 07, 2011 6:36 am
Contact:

SpatialHash in version 6

Post by BobbyGilbert »

Hi,

I'm trying to get the hello chipmunk example working in the objective-C chipmunk environement (i.e. I've deleted the chipmunk files that are bundled with cocos2d). I've had to delete these lines from the init:

//cpSpaceResizeStaticHash(space, 400.0f, 40);
//cpSpaceResizeActiveHash(space, 100, 600);

//space->elasticIterations = space->iterations;

and these from the step routine:

//cpSpaceHashEach(space ->activeShapes, &eachShape, nil);
//cpSpaceHashEach(space->staticShapes, &eachShape, nil);

This results in a clean build but when I run it the little men no longer jiggle around to make room for each other. Seems that I've got rid of the old way of doing it (which I see from other posts here is no longer supported in version 6) but need a new way of doing it. Can someone point me in the right direction please? I'm pretty new to this.

Also I've just ordered "Learning Cocos2D: A Hands-on Guide to Building IOSGames with Cocos2D, Box2D, and Chipmunk (Addison-Wesley Learning Series)" Good book for someone getting up to speed in coco and chipmunk? Any other recommendations from anyone?

Thanks

Bobby
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: SpatialHash in version 6

Post by slembcke »

So here's the quick rundown for you:

//cpSpaceResizeStaticHash(space, 400.0f, 40);
//cpSpaceResizeActiveHash(space, 100, 600);

Chipmunk doesn't use a spatial hash by default anymore, and there is little reason to switch to turn it back on. Delete these lines, forget they ever existed and still get better performance without needing to tune anything.

//space->elasticIterations = space->iterations;

Elastic iterations have been deprecated for a very long time (over a year). Delete that line and forget it ever existed.

//cpSpaceHashEach(space ->activeShapes, &eachShape, nil);
//cpSpaceHashEach(space->staticShapes, &eachShape, nil);

eachShape() was presumably where you were synchronizing the position of the sprite to match the body, and that's why they don't move anymore. cpSpace.activeShapes and cpSpace.staticShapes were always private fields of cpSpace, I made public cpSpaceEachShape() which does pretty much the same thing as the two lines of code you pasted but will be future safe.

There is a book by Ray Wenderlich and Rod Strougo that was published pretty recently. It seemed to be a pretty solid book. Though it's the only one I've read because he asked if I'd proofread it. Keep in mind though that these libraries and the entire iPhone API even are all evolving pretty quickly. A book is a good way to get started, but once you do that you'll need to watch for how things are changing.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
mijator
Posts: 6
Joined: Fri Dec 16, 2011 11:40 am
Contact:

Re: SpatialHash in version 6

Post by mijator »

Similar issue, trying to complete an older tutorial with version 6... ( http://www.alexandre-gomes.com/articles/chipmunk )

How would you use cpSpaceEachShape() to replace the following using an ARC environment?

cpSpaceHashEach(space->activeShapes, &updateShape, nil);
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: SpatialHash in version 6

Post by slembcke »

Use cpSpaceEachShape() instead. The spatial hashes and their API were private before (as in commented as such in the headers), but nobody really noticed... cpSpaceEachShape() gives you the same functionality with an API that I can maintain easily.
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 4 guests