Adding objects during execution (randomly)
Posted: Mon Nov 22, 2010 3:00 pm
I'm working with chipmunk+cocos2d in an iPad application.
I want to add objects to the world while the physics simulation is running.
One approach would be to add a kind of 'pre step callback' to be run in every iteration of the main loop of the physics simulation, but afaik there's no such functionality in chipmunk, or am I wrong? Another similar one would be to add a post step callback, which exists but I can't add a post step callback that will be executed forever, they're ran just once and removed.
Other approach is to use another thread which randomly adds these objects, which is what is partially working now. In this thread I add one post step callback and then sleep for a few random seconds. In this callback I just add one more object to the world. But at one time I get a EXC_BAD_ACCESS, and my app crashes, and its is probably a concurrency problem.
Then, what is the right way to do this?
Thanks in advance.
I want to add objects to the world while the physics simulation is running.
One approach would be to add a kind of 'pre step callback' to be run in every iteration of the main loop of the physics simulation, but afaik there's no such functionality in chipmunk, or am I wrong? Another similar one would be to add a post step callback, which exists but I can't add a post step callback that will be executed forever, they're ran just once and removed.
Other approach is to use another thread which randomly adds these objects, which is what is partially working now. In this thread I add one post step callback and then sleep for a few random seconds. In this callback I just add one more object to the world. But at one time I get a EXC_BAD_ACCESS, and my app crashes, and its is probably a concurrency problem.
Then, what is the right way to do this?
Thanks in advance.