Tuesday 29 September 2015

Tiles!

Now the project is all set up and I've imported Kenney's spritesheets, the next step is to actually get something drawn on the screen.

With Paradox it wasn't too difficult to get some sprites set up. For now I'm just randomly drawing either a grass sprite or a stone sprite (proper terrain to come in the next blog). 


This was quite straightforward, but performance wasn't great as a 100 x 100 sprites means 10,000 GPU draw calls every frame. Whilst rendering this many sprites, the FPS sometimes dropped below double digits. Not acceptable at all.

To get around this performance issue, I will be rendering the tiles onto a texture. This means there will only be the performance hit of rendering the 10,000 sprites once, and from then on just there will be just one texture per 10,000 sprites. This means performance even on quite low-end machines should be fine - I'm developing on a laptop with an Nvidia GeForce 750m, which is fairly low end in desktop terms. Plus, it's not exactly AAA graphics, so good performance will be expected!

Figuring out how to draw the sprites onto a texture was somewhat challenging, but with the help of the Paradox forums (http://forums.paradox3d.net/) and the samples that come with the Paradox engine, I was able to draw batches of 100x100 sprites onto textures, and then add these textures to the scene using the normal entity/component structure. This has massively improved performance - it can now draw 10x10 cells of 100x100 squares (the equivalent of 1 million sprites) and the framerate sits at a steady 60FPS (capped by VSync).

Here's a slightly zoomed out screenshot using the new drawing method:

Looks the same, but the performance is orders of magnitude better.

The next blog entry will look at adding some terrain features such as forests and lakes instead of randomly placing grass or stone. There won't be such a large gap between the next blog entry and the previous blog entry, so stay tuned!