As a short break from working on Letter for Mimi 3, I’ve restarted the voronoi game (but this time with version control). The engine has been ported for as far as was possible to HaxeFlixel, this should allow the game to run native on Linux, Windows and Mac. At the moment I’ve only tested native on Linux, and some performance tests have shown that it runs about 4 times faster than the Neko target.
The game generates a set of points (settlements) and then calculates the Voronoi cells (provinces) with as centroids the settlements. This works well for large amounts of points (e.g. 512). However, when it attempted to create a FlxSprite and a polygon representing the province it crashed when there are more than about 100 settlements.
As far as I know Flixel should not render sprites which are off-screen, and I assume this also applies for HaxeFlixel. So the number of sprites should not be an issue. The polygons are drawn on top of an empty graphic the size of the game world. This is what caused the lag, as it might thus generate more than 100 sprites sized 3840 by 2160. As these sprites need to be unique so they can be manipulated later, they are all stored in memory separately, this is way too much even for a computer with 8 GB of RAM. I ended up solving this problem by drawing the polygons on a graphic with the size of the maximum polygon size and moving the graphic from the origin to the place where the origin of the polygon is.