I'm trying to create a grid-based ecosystem simulation game.
The design I came up with is something like a 1000 x 1000 (or larger) grid, with each cell being a representation of an object containing attributes like: soil, moisture, vegetation, temperature, coordinates, etc., which are stored in a 1000*1000 numpy array. These objects should be updated in real time and should affect adjacent neighbour cell objects. I'm generally thinking something along the lines of the classic SimCity map representation.
However, my implementation is far too slow, and I'm starting to doubt the feasibility of this approach. Here's some condensed pseudocode below:
class makeCell: def __init__(moisture, temperature, veg, rgb): self.moisture = moisture self.temperature = temperature self.veg = veg self.rgb= rgb def growVeg (): if self.moisture > 20: self.veg += 10 self.moisture -= 10 cellArray = np.array() for loop (): cell = makeCell() append cell to cellArray mainGameLoop(): while True: for each cell in cellArray: cellArray[cell].growVeg set pixel colour at cell_xy on pygame surf surface.blit(surf) pygame.display.flip()
So as you can see above, the problem is running a function on every object in the 1000*1000 grid every frame. How can I perform this simulation more efficiently?