The engine for the game loop