0

Here's a question from a total newbie

I'm trying to write an evolution simulator. (Requirement) That implies having a lot of objects that are supposed to interact with one another. I'm writing the code in Python (since it's the only language that I know), using Pygame to create a visual 2D environment. I was doing fine until I added the trees to my continent. That's when things got super slow, since there're thousands of trees on screen that have to be there each frame.

I got rid of pygame.display.flip() in favor of pygame.display.update(). Doing that I've run into two problems:

  1. The pg.draw.circle() function leaves behind a trace when moved. I've run into problems with this function before (the rect created by the function can never leave the screen, apparently), but maybe it's just me who does something wrong?

  2. The optimization solution I've come up with so far is still dubious at best. If you delete line 32 in bug.py you'll see how much faster things run in the project. Is there a way to get my code running as fast as this, or at least close to that? I mean, I'm to add a hundred or more other bugs, all eating plants and other bugs, seeing stuff and thinking with their neural network each, the whole thing is gonna be a mess unless I optimize the code.

Thanks you all for your input!

EDIT: I feel like relying on the order of objects in the biomes list instead of looping through every biome there is in bug.update_biomes() would significantly increase the process speed, but what do you think?

P.P.S.: Also, I just found out that the pygame.Surface.fill() function does not require and update. Where can I read which function in pygame require updates and which don't?

Shevvv
  • 1
  • 1
  • 2
    You have to add the relevant code to the question. Please read [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) and [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask). – Rabbid76 Apr 02 '21 at 21:07
  • @Shevvv - Why in `update_biomes` do you assemble and `return biomes_to_update` if you do nothing with that value? – Armali Apr 02 '21 at 21:50
  • @Armali looks like everything after line 70 can be deleted with no affect whatsoever. The `return` line is a leftover from the earlier versions of the code. – Shevvv Apr 02 '21 at 21:58
  • Welcome to SO! Please provide your code so that others can try to help you out with your problem. – troymyname00 Apr 02 '21 at 23:42
  • Hello, @troymyname00! The code is [here](https://github.com/Shevvv/Life), and the requirement is [here](https://github.com/caseman/noise) (besides pygame, obviously) – Shevvv Apr 03 '21 at 05:44
  • @Armali, you mean the `Settings` class I added? It's from `settings.py`, added 2 hours ago. – Shevvv Apr 03 '21 at 07:48

0 Answers0