> >  What would be a fair comparison would be to use <call #mMethod, 
> > plistOfBehaviors]>
> 
> Hmm... that's a new syntax for me. I assume plistOfBehaviors 
> is a list of 
> the instance references of all 44 sprites? Maybe I can learn 
> something  here. How would that be faster than sendAllSprites?
>
> >I'll just reiterate: "sendAllSprites" is great for picking up object 
> >references at initialization, typically from "beginsprite" or 
> >"prepareFrame" events.

One of my basic objects that gets reused in all of my projects is my
"broadcast manager" object.  Essentially it provides methods where other
objects can create/destroy channels, and subscribe/unsubscribe and broadcast
to these channels.  What the broacast manager does is keep lists of objects
subscribed to each channel and uses "call" as in the example above to pass
on messages to said objects when you broadcast to said channel. My principal
interest in this kind of approach is being able to better target my
messaging - i may have a number of behaviors with an "updatePosition"
handler but I might only want to call said handler in a particular group of
them. Something like sendAllSprites isn't specific enough (and I want to be
able to message objects not attached to sprites too, and sometimes only some
of the behaviors on a particular sprite). I can easily group objects into
functional groups by which channel they subscribe to.

Yes, you have to have discipline and have objects unsubscribe themselves
when you want to dispose of them.

Secret bonus of using "call" on a list of objects - no errors generated if
any/all objects in the list don't have the handler in question. 

The basic accessor methods for my broadcast manager are:

-AddChannel flxChannelID -- create a new channel
-DeleteChannel flxChannelID -- delete a channel
-AddReceiver flxChannelID, objReceiver -- add the object as a subscriber to
the channel
-DeleteReceiver flxChannelID, objReceiver -- unsubscribe the object from the
channel
-BroadCast flxChannelID, symHandler,flxMssg1,flxMssg2,flxMssg3 -- call
handler "symhandler" in all objects subscribed with up to 3 parameters
-CreateUniqueChannel -- create a channel with a unique integer id, returns
the ID
-ClearChannels objReceiver -- unsubscribe the object from all channels (use
in subscriber "mDestroy" handler)

Should give you some idea of what the thing does, not too hard to code its
just a matter of managing lists of subscriber objects.  I've also added some
additional methods to link channels from different MIAW's (so broadcasting
on channel #goodGuys in MIAW 1 gets passed on to the objects subscribed to
#goodGuys in MIAW 2) and other fun stuff.

I haven't specifically tested performance vs. sendAllSprites, but I haven't
noticed any great hit and looking at the code the overhead doesn't seem too
bad, broadcasting basically involves only finding the subscriber list and
using "call" on it. It's been useful enough to me that a modest hit would be
worth it in any case.

Steph


[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to