Jump to content

  • Log In with Google      Sign In   
  • Create Account

Best method for distributing an abstracted interface pointer


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Khatharr   Crossbones+   -  Reputation: 3001

Like
0Likes
Like

Posted 03 December 2012 - 08:26 PM

Ehhh.....

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.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

Sponsor:

#2 Khatharr   Crossbones+   -  Reputation: 3001

Like
0Likes
Like

Posted 11 December 2012 - 05:28 PM

I solved this by abstracting irrKlang to a manager which both Audio and Sound have access to.
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS