----- Original Message ----- From: "George Greer" <greerga@CIRCLEMUD.ORG> > Hm, "snoop room" sounds like an interesting command. Makes me want to give > each room an output queue, where everything in that room then gets the > output instead of just being per thing inside. sigh One of my favorite concepts from Java is that of listener objects. An object (such as a room) has a number of things it can report, and other objects (such as characters) register an interest in listening to those reports (events). While it can be a little difficult to carry object-oriented concepts into a procedural language like C, it is not impossible. Much of the object/listener concept could be accomplished using callbacks. For example: #define ROOM_LISTENER(name) \ void (name)(const char *msg, void *receiver) struct room_listener_queue { ROOM_LISTENER(*callback); void *receiver; struct room_listener_queue *next; }; struct room_data { ... + struct room_listener_queue *listeners; }; void add_room_listener(room_rnum room, void *receiver, ROOM_LISTENER(*callback)) { struct room_listener_queue *queue; CREATE(queue, struct room_listener_queue, 1); queue->callback = callback; queue->receiver = receiver; queue->next = world[room].listeners; world[room].listeners = queue; } ROOM_LISTENER(char_listener) { struct descriptor_data *d = (struct descriptor_data *)receiver; SEND_TO_Q(msg, d); } Whenever a char enters a room: add_room_listener(room, ch->desc, char_listener); Then, things like act(..., TO_ROOM) can walk the listener queue instead of the "people" list. Obviously, there is some sanity checking and other supporting functions (like remove_room_listener) that need to be added, but this should be enough to get the concept across. A structure like this would make snooping trivial, although it would take a lot of work to make it trivial. :-) Mike -- +---------------------------------------------------------------+ | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html | | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html | +---------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/06/01 PST