This generally makes this code cleaner and easier to maintain, while also being more modern and fully tested. Looked at by: leper Differential Revision: https://code.wildfiregames.com/D8 This was SVN commit r22029.