Posted October 08, 2020 by Michael Macha
#update #object pooling
This isn't an object-oriented language, but here the term still applies; in the past, every time I created a new bullet or ship, there was a memory allocation call. When that entity was destroyed, there was also a free. This was fine while things were simple, but I've hit the point where there's tangible benefit to pooling all the memory for these game entities, and pre-allocating it, at the very loading of the game; and then clean it all up on close. It avoids memory fragmentation and extra work allocating and deallocating usable short-term storage space, both of which slow the game down.
It also frees up stunts that are almost unfeasible otherwise.
I've soak-tested the game to a thousand points without any SEGFLT or SIGABRT errors, so it's safe to say that everybody out there in internet-land is going to be fine; but as a note, if somehow it ever has more than a hundred and twenty eight ships or bullets on screen, it will crash. I'll consider turning that up in the future, possibly as high as 512, but only if there's a benefit. Otherwise, it should run a lot smoother now.
I'm also beginning work on a gradual difficulty scale for the game, which will slowly increase with time to keep things interesting. It will have an effect on spawned powerups and enemies. It should add a lot of color.