Advertisement

Optimize map for high-level pathfinding

Started by June 23, 2015 03:15 PM
2 comments, last by Ravyne 9 years, 5 months ago

In my game, I create high-level maps at runtime that I use for answering distance and accessibility queries. They are not used for pathfinding. I call them "region maps". The region maps cover the whole playfield.

The region maps are made by flood filling the terrain map grid with a small cutoff limit so the map consists of many small regions. Connections between neighbouring regions are stored in a graph and used for lookup.

There is a general region map for the base terrain that can be used by all agents. In addition, each faction has a few region maps which are made from the terrain data with threat data overlaid.

In total, this means that each faction (a single independent agent is also a faction) has a memory footprint of 7 MB.

How can I make the factions' region maps smaller. Most of the information in them is similar to the underlying terrain anyway. It is only the nearby threats that the factions know about which make their region maps different.

What data structures are you using? What representation do you have for the pathfinding system? Is your data dense (i.e. you need to have a value in every "cell" for it to make sense) or sparse (i.e. you could represent only the non-zero cells as an example)?

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Advertisement

        /// <summary>
        /// the coordinate map that tells what region(color!) a subtile belongs to
        /// </summary>
        public ushort[][] AllSubtiles;

This array uses the most memory. It covers the whole map and can be about 750 * 750 in size. That's about 1 MB. Then there is some additional data also, and each faction has 3-6 of these region maps...

I am thinking now about subdividing the map into square sections, about half a screen wide. The flood fill would stop at the border between sections.
Then, the region maps that belong to factions could disregard most of the sections, and just leave them empty. When I create the graph, I could link up with the underlying, full region map whenever there is a hole/empty section.

What's the nature of the data in the cells of each array? are they an arbitrary value, or are they essentially boolean? If boolean (or even small ranges), it could well be beneficial to pack some of the maps together, utilizing otherwise unused bits of the cells -- and depending on what you do while iterating, this might even end up faster due to cache locality.

If combining maps per-faction is odd or doesn't quite work, it might instead make sense to combine the factions into a single region map of each sub-type of region map using the same kind of approach.

Another approach would be to determine whether you can get away with sampling some of the maps with lower frequency (say, threat-info at half the rate, so only ~375x375 cells), or even lower sampling, possibly by transforming (nearly?) binary data into something like a signed-distance field.

throw table_exception("(? ???)? ? ???");

This topic is closed to new replies.

Advertisement