RE: pfDeleting non-Performer objects

New Message Reply Date view Thread view Subject view Author view

Acosta, Mark W (acostmw++at++texaco.com)
Tue, 17 Aug 1999 13:15:29 -0500


Kevin,

        I became aware of this capability of Performer just recently. Your
suggestion is a good one and can be easily used for items that are tied to a
node or a sub graph. However, some of the classes I wanted to do this with
aren't tied to the allocation/deletion of a particular node. So, at least
for these objects, I don't think it would be appropriate. Thanks for you
input.

        I'd still like to know if subclassing my c++ objects off of pfMemory
will let me pfDelete them or if there is any other way to achieve the effect
I want. Anyone else out there know?

Thanks,

Mark Acosta
Texaco

        -----Original Message-----
        From: Kevin Curry [SMTP:curry++at++ccpo.odu.edu]
        Sent: Tuesday, August 17, 1999 7:29 AM
        To: Acosta, Mark W
        Cc: info-performer++at++sgi.com
        Subject: Re: pfDeleting non-Performer objects

        Mark:

        Actually, there is a way (perhaps several?) to use pfDelete to clean
up
        your non-Performer objects without subclassing. Essentially, you
stuff
        your object into a pfUserDataSlot of some Performer object and give
        Performer a user-defined delete function to call whenever pfDelete
is
        called on that Performer object. It goes like this:

        -------

            myObj = new MyObject( );

            // Stuff 'myObj' into user data slot 'slotNum' of 'grp'.
            // In our case 'grp' is a pfGroup, but it can be whatever type
of
        Performer obj into which you put your data.
            // If you don't specify slot #, Performer will put it in the
next
        avail. slot.
            grp->setUserData(slotNum, (void*)myObj);

            // Register a delete callback for the user data in slot
        # 'slotNum'.
            // 'userDataDelete' will be called when pfDelete is called on
        'grp'.
            // 'userDataDelete' does not replace pfDelete. It gets called
when
        pfDelete reaches 'slotNum' and finds user data
            grp->setDeleteFunc(slotNum, userDataDelete);

        -------

            // This is the delete function that is registered for slot
        'slotNum' in 'grp', above
            void userDataDelete(pfObject *obj)
            {
                // NOTE: if "myObj" is not stored in 'obj',
        'getNamedUserDataSlot' will return the next avail. slot #.
                // So, it is important to check that your object is
actually
        there.
                int slot = obj->getNamedUserDataSlot("myObj");
                MyObject *m = (MyObject *)obj->getUserData(slot);

                // Confirm that your object is really there
                if(!m)
                {
                    cout << "No user data to delete from slot #" << slot <<
        endl;
                    return;
                }

                // Clean up as appropriate for your data. In our case, we
call
        the destructor for the class we are storing
                delete m;
                return;
            }

        -------

        Consult the man pages for pfObject for variations and other
functions
        associated with user data slots. Let me know if you have questions
or
        any trouble with this.

        Good Luck!

        KMC

        --
        Kevin M. Curry
        Research Associate, Virtual Environments Lab
        Center for Coastal Physical Oceanography, ODURF
        phone: 757.683.6276

         


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Tue Aug 17 1999 - 16:15:22 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.