Re: Circlemud design issues 15:44:42 +0100"

From: James Turner (turnerjh@XTN.NET)
Date: 04/21/98


Luis Pedro Passos Carvalho <lpcarvalho@SONAE.PT> writes:

> Personally i believe that it would be easier and in more accord to the
> present code:
>
> struct char_data *l;
> for (l= first_char_in_room(ch); l ; l=next_char_in_room(l)) {
>   blah(l)
>   ...
> }

The problem is, though, that l can't store enough state information,
unless we put next fields in the char_data structures -- something I'd
like to not do.  A piece of data is fundamentally different than a
list of the same data.  Just as a pointer to a struct is different
than a struct.  Further... for every list we want the current code to
allow a given char_data to be a member of, we need to add a new entry
to the structure.  That can get messy and difficult to maintain.

> That way you don't need to allocate lists and free them afterwards.
> Basically you would only need a first_char_<criteria to meet> and a
> next_char_in_<criteria to meet>
> Similar to the way to run through the directory tree in MS-DOS (hey, it had
> nice things)

There would be no reason to allocate and free lists in first design I
suggested (and probably not in the second with some clever work).
Example:

struct list {
  struct list *next;
  void *data;
};

You could then use a list * as an interator over a given list.  Then,
things like first_char_in_room() could return the list that contains
the people in the room.  The iterator (ie the single list element)
wouldn't allocate data, or need to be removed from the heap.

> >Or another way,
> >
> >Iterator i;
> >
> >for (i = chars_in_room_iterator(ch); i; i = next(i)) {
> >  tch = iter_to_ch(i);
> >  blah(tch);
> >  ...
> >}
>
> A bit over the edge wouldn't you think?

Somewhat, perhaps.  Just throwing ideas out.  But it would allow for a
more general Iterator class, which would reduce the complexity of the
libraries -- at the cost of wrapper functions like iter_to_ch.

> Hmmm... I think i'll start coding it, right after I code my ROOM_HUGE rooms.
> Talk of a major change in code!

If you do much of this, post to the list how it goes, I'd be very
interested in hearing :)

--
James Turner               turnerjh@xtn.net
                           http://www.vuse.vanderbilt.edu/~turnerj1/


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST