On Sun, 2001-09-02 at 19:30, John Eikenberry wrote:
> Another idea would be to swap infrequently needed hexes to disk. Using
> something like the shelf module.
My intuition is that this is unlikely to be a win; presumably we have
virtual memory which will swap unneeded stuff to disk if that becomes an
issue. OTOH, I don't know if the VM would be clever enough to know what
parts of the program were least used (but maybe?).
> Or maybe just go the pure procedural route and replace the hex objects with a
> dictionary and a set of functions to manipulate them. Using the module as the
> abstraction layer.
Yeah, that would be my plan as of now. Maybe in map, have a 2-D array
of dictionaries, one for each hex, that hold named properties of the
hex. You might access it though map methods, rather than directly. The
altitude storage in map could be subsumed into that, although it's
*very* heavily used in line-of-sight calculation and I'm not certain
adding another abstraction layer there is wise...
A very brief explaination of map.py, theory and practice:
The idea is that this class contains the map data. To the
server/engine, the map appears continuous. The engine only draws a few
things from map:
(NB: where we say (x,y), unless otherwise specified we refer to 'map
coordinates', that is, one unit per pixel with 0,0 in upper left corner
of map. If we refer to hex coordinates, hex (0,0) has its center at map
coordinate (0,0) and hex (0,1) is below and to the right, with its left
edge vertical along the left edge of the map. Inside the map class,
hexes are decomposed into triangles because the math is a disaster
*) What is terrain type at point (x,y)?
*) What is altitude at point (x,y)?
*) How good is visibility between points (x1,y1) and (x2,y2)?
Code that deals with graphics (the client, the map builder) often needs
to know about hexes, so there are functions in map to support this.
Most likely the AI will deal with hexes, too, as a way of breaking the
map into discrete segments. There is a minor complication here in that
hexes can have multiple terrain types: the 6 triangles that compose a
hex may have different terrains.
That makes sense to me, but I wrote the code, so feel free to pepper me
with questions or complaints. :)