adonthell-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Adonthell-devel] map structure


From: Kai Sterker
Subject: Re: [Adonthell-devel] map structure
Date: Sat, 6 Jul 2002 12:49:31 +0200

On Fri, 5 Jul 2002 14:16:52 +0200 Kai Sterker wrote:

Some more thoughts about the topic, this time concerning the
implementation.


The mapobject cache:
That would be a static class that would store mapobjects in a hash map.
It would implement a load method that takes the filename of a mapobject.
If it finds it already in the hash it'll increase it's refcount by one
and return a pointer to it. Otherwise it'll create a new mapobject, load
it from disk, store it inside the hash and return a pointer.

The refcount could be stored in the mapobjects themselves. As only one
instance of a certain mapobject will exist at any given time this won't
be a problem.

The only problem is to free mapobjects that are no longer needed. For
that we could have an "area" class that keeps track of the mapobjects
used by a certain area (list of mapobject filenames). If the area is
removed from memory, the filenames are passed to the cache and the
refcount is decremented for the according objects. If it reaches 0,
they're deleted.

Future addition:
Even better would be to keep mapobjects with refcount 0 in memory as
well, as long as they don't exceed a certain size. Say 16 Megs or
something. This could even be configurable. Only if the cache becomes
that large, unreferenced mapobjects will be freed. Probably those that
weren't used for the longest time. That's no must have right now, but as
available memory becomes more and more we could as well make use of it.
Have to be careful that we're not running out of memory though; swapping
to disk has to be avoided, 



Multiple mapviews:
Using multiple mapviews with a single map that is completely in memory
is easy. However, it might use loads of resources and there are other
problems. For example, what should be done with all the NPCs? Should
their shedules be run or not. It's obviously impossible to run the
schedule of every NPC.

But what if each mapview would have its own map (these nine areas I
talked about in my last mail). Think about it in client/server terms.
The mapview is the client (that renders the map), the part that has the
map in memory the server. So the server would have a distinct map for
each connected client. As a map does nothing but tell where to place the
scenery it wouldn't hurt to have different instances of the same
location. They only thing they need to share are the characters and
other changeable objects, like doors and items of all kinds. That means,
the server keeps a global list of those, similar to the mapobject cache.
That way, it is rather simple to let the server know which NPCs are in a
location visible to at least one client. Only their schedule would be
run once per cycle. If all the maps keep references to the characters,
they'll always be in sync, even though they are unique for each
mapview/client. It's the same for items on the map. If they're kept in a
map-inventory which is shared by all maps, picking up items will make
them vanish for all clients, as well as dropping them will make them
appear.

The advantage is that a server needs not keep the whole map in memory,
only those parts visible to the clients. That also means, there wouldn't
be any difference between single- and multiplayer code in that area.
Singleplayer could also have several mapviews (for example a spell that
allows to watch other characters) and thus several map instances.
Multiplayer is just the same, except that the clients are connected
across a network. Even a splitscreen mode would be possible with exactly
the same code.



Architecture:

                          +---------------------------+
                +---------|   Mapobject Cache (Gfx)   |--------+
  Client        |         +---------------------------+        |
                |                   |                          |     
        +-------------+     +-------------+             +-------------+
        |   Mapview   |     |   Mapview   |    . . .    |   Mapview   |
        +-------------+     +-------------+             +-------------+
_______________|___________________|___________________________|_______
               |                   |                           |
        +-------------+     +-------------+             +-------------+
        |     Map     |     |     Map     |    . . .    |     Map     |
        +-------------+     +-------------+             +-------------+
              |                    |                           |
  Server      |           +---------------------------+        |
              +-----------|   Mapobject Cache (Data)  |--------+
                          +---------------------------+        
 

It's basically what we already had in mind, except that there is no
global map.


Does that make sense to you?

Kai



reply via email to

[Prev in Thread] Current Thread [Next in Thread]