Member Function Callback - No User Supplied Args

This is a discussion on Member Function Callback - No User Supplied Args within the C++ Programming forums, part of the General Programming Boards category; I am trying to use a library called FMOD for audio, and I have a base 'game state' class with ...

  1. #1
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

    Member Function Callback - No User Supplied Args

    I am trying to use a library called FMOD for audio, and I have a base 'game state' class with an array of sounds which can be played (also serves as an interface to update and draw). You can critique this design decision too, but I derived from this base class with a loading_game_state, which then loads the sounds into the array. I am notified when a sound has completed loading through a callback with the prototype:

    Code:
    FMOD_RESULT F_CALLBACK AsyncOpenCompletion
        ( FMOD_SOUND * sound, FMOD_RESULT result );
    Neither of those parameters are user submitted data, and neither are under my control. I can make the callback a static member of my class, but I can't exactly see how I'd tie it back to an instance of the class.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,830
    Assuming that the 'sound' is unique, then search all the instances for the one which contains a matching 'sound' pointer.
    ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    >> Assuming that the 'sound' is unique, then search all the instances for the one which contains a matching 'sound' pointer.

    Well, because the sound arrays are empty until I fill the instance up with them. I may have misinterpreted what you said. Anyways. Some things have occured to me.

    1) Not all the sounds should be loaded into memory at the same time really.
    2) That each game state should then, probably just have different loading, instead of a central loader thing

    This poses a slight predicament, and brings me back to the problem which originally puzzled my puzzler. The loading takes a second, and gets get's it's own drawing and update routines.

    So, what kind of class relationship would a 'loader' class have to it's 'base', to fill up the base class with all it's goods. Then, after that, this loader has a static callback that recieves 'the goods' that it needs to give to the 'base' that it is relating to.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    I came up with a 'solution', but I think it's kind of awkward. I've got something like this.

    Code:
    class base
    {
          virtual void update() = 0;
          virtual void draw() = 0;
    
          static sound * sounds_array;
    };
    
    class loader : public base
    {
          void update();
          void draw();
    
          static FMOD_RESULT F_CALLBACK AsyncOpenCompletion
              ( FMOD_SOUND * sound, FMOD_RESULT result );
    
          static loader * fake_this;
          int completed, percentage_loaded;
    };
    
    class game : public base
    {
          void update();
          void draw();
    };
    I use the fake_this to communicate with the current instance of a loader class while I am inside the callback routine, and also to put the loaded sounds into the static array. I suppose more than one instance of this class will never exist, so I guess it's okay? Then I make the different game states use this sound array. Critiques welcome, anyways I think it'll stay.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 04:33 AM
  2. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 07:44 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21