I'm using pymunk to create a simple 2-d simulation of cell-growth.
I grow my cells, then they can "bud" a new cell that remains attached. I attached them via 2 springs. Like this in sophisticated ASCII-Art...
0=0
... except the cells are actually touching.
Cells can bud 2 others, so I get a branching of connected cells. They all bump into each other and the springs are forced to stretch and when they got too long I break them. It all works pretty well, once you fiddle with the spring parameters. But it slows down a lot at about 200 cells. It is really sluggish and unresponsive. Now, I'm writing in python, so that has something to do with it. But when I profile it, most of it occurs in the "step" call to chipmunk.
So there are 200 cells with 400 springs. Should it really be slow? I've tried putting the spatial hash into action (this should be perfect, as all cells end up the same size), but to no effect.
The main loop looks like this:
Code: Select all
fps = 50
iterations = 10
dt = 1.0/float(fps)/float(iterations)
for x in range(iterations): # 10 iterations to get a more stable simulation
self.space.step(dt)
for c in self.cells:
c.step()
self.time_step += 1
Where should I begin looking to try and speed this up?