[DGD] Rooms implementation

Stephen Schmidt schmidsj at union.edu
Mon Jan 13 15:39:56 CET 2003


Lord Lerkista <lordlerkista at yahoo.com.mx> wrote:
:I want to make some type of array of all the rooms in
:my mud, something like a system of room's coordinates,
:to make easy things like interact with rooms around
:the actual room, i try to make a 3D array, xyz[][][],
:but it's so heavy for the mud,
:which would be the better implementation of that??

If you have a fairly sparse array (more on that below) then
you might be better off having a linked list whose elements
contain a pointer to each room object, and its X-Y-Z
coordinates. Then if you have a query like "find all rooms
within 3 spaces of a given room" or "find the nearest room
to the north of (6,4,2)" then you need only search the
linked list. I have used that method (actually, I did it
with an array and an upper limit on the number of rooms,
since the language I'm using doesn't really support pointers)
and it works pretty well as long as most spaces of the X-Y-Z
coordinate system are empty.

On Mon, 13 Jan 2003, Felix A. Croes wrote:
> In the best implementation, each room would have an array (or mapping)
> of neighbour rooms.  That way, you can ask the room what the surrounding
> rooms are like.  Actually, this is very close to the list of exits
> that must already be present in every room.

Indeed, if all you want to do is query for neighboring rooms, then
the exits mapping already does what you want. You don't need to
move to a grid system unless you need some kind of absolute
reference with regard to a fixed point (perhaps the entry room)
or unless you want to have relative steps of more than one step
(ie "find the room that is 2 steps north and 3 steps west of
here.") You can do the latter with the exits mapping if you
understand recursion and have CPU to spare, but an array lookup
would be faster.

> Suppose that there are a thousand rooms, in a grid of 100 by 100, with
> 10 different height levels.  Storing each room by coordinate in a
> central object, you'd need an array of 100 * 100 * 10 = 100000
> elements.  This amount possibly be reduced because not every element is
> used, but it's still a large amount of information.

If the array is reasonably full, then any other scheme will use
the same amount of memory (since in that case you really do have
100,000 rooms) and you may as well go with the array.

Otherwise you are probably better off with some kind of pointer
scheme that allocates the memory dynamically. It would also be
relational ("this room is north of that room") but, unlike the
exits mapping, would allow for gaps between rooms ("The nearest
room to this room in the north direction is 11 steps away.")

The other question to consider is whether the rooms are all the
same size. Do you want the possibility of a small room that is
at (3,3,1) but a larger room that occupies the space between
(4,5,2) and (6,8,2)? If you want the latter, then I advise a
major redesign of your code. Muds have always been oriented
by exits and they just don't work well for a true spacial
orientation, though I guess DGD would work better than any
other since you could re-implement the physical concepts at
a lower level.

Steve





_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list