The bulk of the main game loop.