1997Q1/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: q&#45;tree stuff -->
<!--X-From-R13: ptNnzv&#45;pt.UenlEntr.Sqzbagba.OP.QO (Quevf Uenl) -->
<!--X-Date: from babe.globecomm.net [207.51.48.8] by mx01.ny.us.ibm.net id 857333989.128579&#45;1 Sun Mar  2 20:19:49 1997 -->
<!--X-Message-Id: 9703021924.7ujd@ami&#45;cg.GraySage.Edmonton.AB.CA -->
<!--X-Content-Type: text/plain -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, q-tree stuff</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">
</head>
<body background="/backgrounds/paperback.gif" bgcolor="#ffffff"
      text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000">

  <font size="+4" color="#804040">
    <strong><em>MUD-Dev<br>mailing list archive</em></strong>
  </font>
      
<br>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
<br clear=all><hr>
<!--X-Body-Begin-->
<!--X-User-Header-->
<!--X-User-Header-End-->
<!--X-TopPNI-->

Date:&nbsp;
[&nbsp;<a href="msg00040.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00042.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00149.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00043.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00041">Author</A>
&nbsp;|&nbsp;<A HREF="#00041">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00041">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>q-tree stuff</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: <A HREF="mailto:mud-dev#null,net">mud-dev#null,net</A></LI>
<LI><em>Subject</em>: q-tree stuff</LI>
<LI><em>From</em>: <A HREF="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</A> (Chris Gray)</LI>
<LI><em>Date</em>: Sun, 2 Mar 97 12:24:15 MST</LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>
Thanks Todd! The picture came out fine on my Amiga, so it must have
worked on PC's, right? :-)

To summarize my understanding here (you never know, I could have missed
it altogether!), objects are stored in B-trees, in which the index is
the Morton code (or some other similar function) of the co-ordinates of
the object. Objects that are "nearby" in the co-ordinate space are
nearby in the B-tree, so searching for them is much faster than any kind of
linear scan of the whole set of objects. This works well in a setup where
there isn't a specific data structure for each location in the world, on
which to hang the object list, and on which to hang pointers to nearby
locations. Given a co-ordinate, it is fairly quick to find what would
be there, and keeping track of the B-tree search path lets you find the
nearest objects easily too.

I did a game system for CP/M, which was kinda like the old Ultima games.
I had "grids" representing tile-based surface maps, and "mazes" representing
the underground 3D view areas (line-drawing only - this *was* on a 1 Mhz
8080 with 64K RAM, including the graphics card). I had a global linked
list of all objects in the grid or maze, and simply did a linear scan,
checking the co-ordinates, in order to find things. This worked since I
was in a small world with only a few dozen objects (if that!), but it sure
wouldn't have worked in a big world with hundred's of objects.

To follow on to that, I'll mention how I did "special" things. I used
something like 6 bits to select the terrain for each location in a grid.
The terrain value gave me the tile, and the monster-set. One value said
"special". When I found that, I would search for that location in the
grid's list of special terrains. That gave me a new tile and/or monster
set. The Morton-indexed B-trees could be used for these terrain things in a
bigger world. The final tree entry could be a pointer to a database entry
giving detailed information for that special location. Similarly, for
3-D maze areas, the basic entry in the description array could give bits
describing the walls/floor/ceiling. "Special" entries could be used for
things like hidden doors, traps, monster triggers, etc. in a similar way.

If your "grids" get *very* big, so that having an array for them is not
practical, then you do as Todd said - just have quad-trees representing
the various properties that are needed to describe the location (terrain
type, monster sets, weather, temperature, etc.) You can layer the whole
thing - if you need smaller regions within your large world that are too
varied for efficient storage using quadtrees, then you can have a B-tree
entry for them that points to an array-based description, which in turn
can point at a few special single-location descriptions.

Note that in some cases you may be able to use a simple function on the
co-ordinates to calculate some properties, rather than having to store
it is a quadtree. Pseudo-random number generators, seeded by the co-ordinates,
are something I've always had in mind for this. I did it once in a little
CRT-based system (curses/termcap), and it worked OK, but not super.

--
Chris Gray   cg#ami-cg,GraySage.Edmonton.AB.CA

</PRE>

<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<HR>
<!--X-Follow-Ups-End-->
<!--X-References-->
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00040.html">Re: Quadtrees?</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00042.html">Re: Just a bit of musing</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00149.html">Re: Issues from the digests and Wout's list</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00043.html">Re: q-tree stuff</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00041"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00041"><STRONG>Thread</STRONG></A></LI>
</UL>
</LI>
</UL>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
<ul><li>Thread context:
<BLOCKQUOTE><UL>
<LI><strong><A NAME="00044" HREF="msg00044.html">Issues from the digests and Wout's list</A></strong>, 
Alex Oren <a href="mailto:alexo#europa,com">alexo#europa,com</a>, Mon 03 Mar 1997, 20:08 GMT
<UL>
<LI><strong><A NAME="00047" HREF="msg00047.html">Re: Issues from the digests and Wout's list</A></strong>, 
coder <a href="mailto:coder#ibm,net">coder#ibm,net</a>, Tue 04 Mar 1997, 13:29 GMT
</LI>
</UL>
<UL>
<li>&lt;Possible follow-up(s)&gt;<br>
<LI><strong><A NAME="00148" HREF="msg00148.html">Re: Issues from the digests and Wout's list</A></strong>, 
coder <a href="mailto:coder#ibm,net">coder#ibm,net</a>, Thu 20 Mar 1997, 13:05 GMT
</LI>
<LI><strong><A NAME="00149" HREF="msg00149.html">Re: Issues from the digests and Wout's list</A></strong>, 
coder <a href="mailto:coder#ibm,net">coder#ibm,net</a>, Thu 20 Mar 1997, 13:21 GMT
</LI>
</UL>
</LI>
<LI><strong><A NAME="00041" HREF="msg00041.html">q-tree stuff</A></strong>, 
Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Mon 03 Mar 1997, 04:19 GMT
<UL>
<li>&lt;Possible follow-up(s)&gt;<br>
<LI><strong><A NAME="00043" HREF="msg00043.html">Re: q-tree stuff</A></strong>, 
Carter T Shock <a href="mailto:ctso#umiacs,umd.edu">ctso#umiacs,umd.edu</a>, Mon 03 Mar 1997, 14:05 GMT
</LI>
<LI><strong><A NAME="00070" HREF="msg00070.html">Re: q-tree stuff</A></strong>, 
coder <a href="mailto:coder#ibm,net">coder#ibm,net</a>, Sat 08 Mar 1997, 11:54 GMT
</LI>
</UL>
</LI>
<LI><strong><A NAME="00033" HREF="msg00033.html">Linear Quadtrees</A></strong>, 
Carter T Shock <a href="mailto:ctso#umiacs,umd.edu">ctso#umiacs,umd.edu</a>, Sun 02 Mar 1997, 20:35 GMT
<LI><strong><A NAME="00018" HREF="msg00018.html">Quadtrees?</A></strong>, 
Wout Mertens <a href="mailto:Wout.Mertens#rug,ac.be">Wout.Mertens#rug,ac.be</a>, Fri 28 Feb 1997, 10:54 GMT
</LI>
</UL></BLOCKQUOTE>

</ul>
<hr>
<center>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
</center>
<hr>
</body>
</html>