Last year I participated in a game development project in my spare time. The idea was to do a small, top-down RPG with roguelike elements. The game was made for Windows with C++, using the SFML library for its multimedia capabilities. It features quests, skills, items, monsters, NPCs and more.
Recently I added precompiled headers to improve build times and made an Android port for the game. Having had some issues and made some discoveries, I decided to make a blog post to share what I found.
Build times can be very frustrating, especially on template-heavy C++ projects. After getting small gains from cleaning up unused includes and forward declaring what was possible, I started to look for other alternatives.
Following this Viva64 tutorial, I implemented the precompiled headers technique. My precompiled header contains:
This file is parsed once and used to compile every other translation unit. This was enough to slash the compilation time by more than half, from about 45 seconds to 20 seconds.
https://xkcd.com/303/
After having the game run on Windows, I decided to challenge myself and attempt to make an Android port. I had already programmed Android apps here at Poatek, but this would require using the native NDK. I knew beforehand some of the issues I would be working on, but others took me by surprise. Here is how it went:
And… success! It’s not perfect, but it works.
C++ can be very slow to compile, but with some work, it’s possible to speed it up considerably, making great improvements to development productivity.
Porting to Android will be very dependent on the project size, as well as the portability of any third-party library being used. If your project already compiles with Clang, the porting will be much easier.
About the author
Gabriel Allegretti is a software developer at Poatek. He studies Computer Science at the Federal University of Rio Grande do Sul. He works on the frontend and backend for web applications, as well as native Android development. On his spare time, he likes to make video games, play guitar and take his dog for a walk.