As part of a 9-day game development contest (finishing the 28th), I am creating a game (with RubyGosu) that simulates a battle between two swarms of microbs trying to conquier a Petri dish. You can get an idea here: http://gavos.free.fr/volatil/petri3.png
Now I am running into problems with performance. On this screenshot the battle is far from finished, a Petri dish full of microbs would run around 15 FPS. And there is no gameplay logic (on this screenshot) or AI neither...
The way I implemented this was as follow:
- loop through the list of colour squares that are on the field
- draw every square using Gosu::Image.draw
The field is 800x600 large and the squares are 8-pixel large, so I might have to draw up to 7500 images per frame... You can find the code responsible for the graphics here: http://gavos.free.fr/volatil/petri.rb
What I would like to do is:
- loop through the list of colour squares that have been updated at this turn
- only draw those squares on top of the existing screen
Is there any way to do that with Gosu? I am aware of what that technique involves when using double (triple?) buffering but I am kind of desperate, I do not have any other idea for optimisation now. I know it would reduce the number of squares to draw enough to stay over 40 FPS (without game logic / AI). If you think of any other way to optimise that would be great as well :-) I have started programming in Ruby at the beginning of this week (I am more of a C++ programmer), so there might be obvious ruby-ish optimisations left to do.
There is nothing to win in the contest but I would be disapointed to publish a game that is hardly playable...
Thanks a lot for your answers :-)