As I discover new improvements to C++, it encourages me to look for more of them. A couple of weeks ago, I was adding a new screen for space combat, and I found myself cutting & pasting code from the existing territory screen. Although I was eager to work on the new space combat screen, I ‘did the right long-term thing’ and started a small project to refactor the common code from several screens into a new shared base class that I could also use for the space combat screen. There were some constants at the top of each .cpp file that are sometimes used in various unique ways by each screen.
const f32 RATIO = 0.86602540378f; // sqrt(3) / 2
const f32 CELL_HEIGHT = 1800.f;
const f32 CELL_WIDTH = CELL_HEIGHT / RATIO;
const f32 FACTOR_X = CELL_WIDTH * 0.75f;
const f32 FACTOR_Y = CELL_HEIGHT;
const f32 SPACER = 0.98f;
…