What we want to accomplish with Thrive is monumental, and to do this, we need to increase the FPS as much as we can now so that we can add CPU-heavy features in the future without too much problem. Right now, I am running at 35 fps on my laptop, and we haven’t even implemented an AI and toxins and compound clouds and countless others important features which will surely drop the framerate even more. So let’s get Thrive up to 60 fps, that sounds like a good benchmark.
Okay, so Lua scripts. They’re quick to type up, easy to modify, take no time to recompile. Even better—anyone can change them, even someone lacking extensive programming training (we already have two mods from non-programmers). However, all of this comes with one huge BUT. Lua scripts are days slow. Their greatest strength—no need to compile them—is also their greatest weakness. While I was doing the compound clouds, I realized that the game starts to significantly lag when there are more than a few microbes in the screen. Imagine my surprise when I realized that all the microbe computing (AI, spawning, processes, etc…) is done at run-time in the Lua scripts.
Here are some statistics to show what I mean:
With the one player microbe on the screen the MicrobeSystem:update() function takes under 5 ms to complete. With 3-5 microbes, the times was 10-15 ms, and in multiple cases, I got over 20 ms for the MicrobeSystem update function alone. This is all with the game running at under 35 fps (28 milliseconds per frame), so all in all, the microbe update function is around 5% of the total frame rate. Okay, I’ll admit, I was expecting more when I started writing this post, but it adds up.
Anyway, I propose moving all of the components and systems from the Lua scripts to C++.