Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411977 Posts in 69438 Topics- by 58486 Members - Latest Member: Fuimus

June 15, 2024, 05:02:45 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)How to make a messaging system [SOLVED!]
Pages: [1]
Print
Author Topic: How to make a messaging system [SOLVED!]  (Read 928 times)
Ben_Hurr
Level 10
*****


nom nom nom


View Profile
« on: June 09, 2010, 09:03:05 AM »

How do you make a messaging system?

Say you have a dozen game objects all listening for commands on arbitrary channels, how would I dispatch a command from one object to all matching objects?  Shrug

Edit:
Say you have a switch that turns on all things with a tag of 100, and a dozen things tagged 100, how would I get that ON message to them without just stupidly looking through the object list for objects that have a matching tag?


MORE Edit:
I decided to just use an array, with each element acting as a channel and having objects poll its value.  It seems to work nicely for what I'm doing!

« Last Edit: June 09, 2010, 10:33:32 AM by Ben_Hurr » Logged
oahda
Level 10
*****



View Profile
« Reply #1 on: June 09, 2010, 09:10:00 AM »

What do you mean by "matching" objects?
Logged

bateleur
Level 10
*****



View Profile
« Reply #2 on: June 09, 2010, 09:12:30 AM »

There are basically three ways to do it.

Option 1: Each listener on a particular message channel provides a handler function that gets called immediately (synchronously) in the context of the message dispatcher, with the message passed in as a parameter.

Option 2: Each listener provides a passive structure in which a copy of the message is left for later processing in its own context.

Option 3: Each listener polls periodically for the presence of messages. Messages keep a count of how many of the listeners have yet to handle them, but are kept in a central store which avoids the need to make copies.

All the approaches have advantages and drawbacks and which one you choose will depend on which language you're using and what sort of application you're writing.

I generally use a variant on approach 1) in which the handlers are extremely lightweight and basically do little more than set a few values.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic