So I'm using irrKlang and I'm wanting to abstract it completely within my Sound class and Audio namespace. Previously I've just had a 'get' function in the namespace to pass out the pointer to the irrKlang engine's interface, but this is defeating the abstraction so I decided to try something new.
I placed a private static pointer in the Sound class (default value NULL) and when the Audio namespace inits it sets the pointer in the Sound class (sets it back to NULL on shutdown.)
When Sound creates an object it checks the static pointer to ensure that it's not NULL. If it's okay then it passes the pointer into an RAII wrapper owned by the object (and uses ->grab() on it to invoke irrKlang's reference counting on the engine). This way any active Sound objects can still play even after Audio gets shut down, and the interface pointer is completely abstracted.
The problem is that it requires Sound to friend the initialize() and shutdown() functions in Audio and also I'm trying to create an RAII class for wrapping ISoundSource pointers, which (I think intentionally) resist RAII treatment and it's making a spaghetti of friendships and modifications to the Audio init/sdown functions as well as causing other problems. (I mailed irrKlang maintainers and complained about this problem since reading the documentation makes it seem like they're doing it on purpose to force people to use irrKlang's internal source cache.) In short, it's working great for the sound class but not so great for the RAII wrapper.
Anyway, I wanted to ask for people's opinion on which method to use here, or if there's a better way of doing this that I'm not catching.
(I've also considered using the same code file for the stuff that needs shared access behind the scenes, but that seems nasty and abusive.)
Edited by Khatharr, 03 December 2012 - 08:37 PM.