[MUD-Dev] Rooms, 3D arrays, etc.

Miroslav Silovic silovic at srce.hr
Wed May 28 12:58:55 CEST 1997


> [Raz:]
> 
> [Discussion of spaces and zones]
> 
> :Continuation eagerly, and hopefully, awaited =3D)
> 
> OK, I'll try to dump what I can remember of my tentative plans in this
> realm. I want a really big world, my thinking is 2^32 x 2^32 (why not!).
> It would basically be a layered fractal terrain. That gives me the third
> dimension - calculated by the fractal generation algorithm. The way one
> common fractal landscape generator works is by starting with one point,
> wrapped as four corners of a square. At each step, you bisect each edge
> of your current square, average and perturb the endpoint heights, and
> mark the height of the middle of the edge. The middle of the square gets
> height from all four corners. [I've got code for this if some of you
> haven't seen this algorithm.]
> 
> What I haven't quite figured out is how to be able to repeatably generate
> the height for any given co-ordinates within the world. I want to
> represent the world *very* sparsely, of course. So, I would divide the

Use pseudorandom function. Here's one I use to generate procedural
textures in my renderer:

#define SRTABLE_SIZE 18723

double srtable[SRTABLE_SIZE];

#define NRAND(x,s) ((s)*128398191+(x))
#define SRTABLE(x) (srtable[(unsigned)(x)%SRTABLE_SIZE])
 
double irand (int n, int *i)
{
    switch (n) {
    case 1:
        return SRTABLE(NRAND(i[0],i[0]));
    case 2:
        return SRTABLE(NRAND(i[0],NRAND(i[1],i[0])));
    case 3:
        return SRTABLE(NRAND(i[0],NRAND(i[1],NRAND(i[2],i[0]))));
    case 4:
        return SRTABLE(NRAND(i[0],NRAND(i[1],NRAND(i[2],NRAND(i[3],i[0])))));
    default: {
            int s=0,k=i[0];
 
            while (n--)
                s=NRAND(*(i++),s);
            return SRTABLE(NRAND(k,s)%SRTABLE_SIZE);
        }
    }
}

void init (void)
{
    for (i=0; i<SRTABLE_SIZE; i++)
        srtable[i]=drand48();
}


(note that for each dimension, I use one extra NRAND which wraps around,
to remove most of the linearity). What's left of the correlation between
input and the output is not visible to human observers. It's pretty
easy to change it to return integers instead of doubles.

> You are going to need some fairly powerful code to examine the hierarchy
> around a given location in order to generate a nice description of that
> location (or a polygon image if you go graphics). As mentioned before,
> the final co-ordinates can be used to repeatably generate details such
> as trees, bushes, etc., which can also be overridden if wanted. If you
> are going full graphics, you can use fractals to generate the actual
> shape of nearby terrain (usual seeding, and using the height
> of this and neighbouring locations to start the fractals), and you will
> of course use the heights of nearby small terrain features and further
> large terrain features (accessible via the hierarchy) to make the
> background for the scene.
> 
> That gets terrain. How about towns? Well, you have to start with some
> kind of street generation routine (seeded by co-ords of town of course!).
> Within that you have another algorithm which creates the buildings, based
> on location within town, a few random choices about the nature of the
> town, its age, etc. You will then need algorithms to generate the details
> of the buildings themselves (floorplan, materials, colours, contents);
> and then of the interior furniture, and then of the stuff in the drawers,
> etc. etc. Of course everything is generated as "real", and if players
> change something you have to keep track of the change, and perhaps at
> some point you just decide to permanently instantiate stuff.

*Evil grin* I'd /love/ to see some code that does some of these things. :)
In fact I might try to write some.

> Whew! That would keep us all busy for a year or two! Nobody said it
> would be easy, but it would finally stop people like me that just want
> to explore everything!

This sounds like Cray (one that does infinite loop in 2.8 seconds) :)


> Uh-oh, its already past my bedtime... :-)
> 
> --
> Chris Gray   cg at ami-cg.GraySage.Edmonton.AB.CA
> 
> 




More information about the mud-dev-archive mailing list