I need to represent an abstraction over various parts of the hardware for a game. I'm trying to decouple the code that does things like manage the logic of the game from the code that is API/platform specific or any ugly implementation details.
std::unique_ptr<IDevice> device(CreateDevice()); IGraphicsDevice *graphics = device->getGraphicsDevice(); ISoundDevice *sound = device->getSoundDevice(); IWindow *window = device->getWindow(); IJobManager *jobmanager = device->getJobManager(); //etc
One solution I've seen was to simply put all of this as globals and initialize them in
main, but I'd like to avoid that if I can because I don't really like dealing with globals (and I find them to be "ugly", for the lack of a better word). I also can't allow more than one instance because it requires initialization of libraries which are globally initialized themselves.
What alternatives to the singleton pattern are there for this?
I know that more than one instance would likely lead to errors, is this a bad design decision? Could I do anything different?