Skip to main content
GameDev.net gamedev.net
🔒 Locked

Tiled map abstraction

Started by comfy chair Jan 5, 2011 at 12:18 PM 4 replies 2.7k views
Original Post
comfy chair
comfy chair
I have a 2d tiled map that I would like to create an abstracted movement graph for. The purpose is to be able to make fast checks on movement distance and accessibility between any 2 points in the map.

Performance of recomputing the graph is important, because I actually have multiple maps, one for each different agent type. I want to recompute the graphs every 10 seconds perhaps.


I am trying to decide between different options for building the graph.
I know of these:

1. Region map. Created via flood fill.
Plus: should be easy to implement.
Plus: not too costly.
- regions can be large and irregular in size, so is most useful for accessibility checks. Not so useful for determining movement distance between points.

2. Sector/region map (AI Game Programming Wisdom 4, p. 203)
It divides the map into quadratic sectors first, then does flood fill to divide these into regions.
Plus: Regions are smaller and so more useful for distance checks.
- Dividing the map into sectors means I have to copy a lot of data from the tile map representation (a multidimensional byte array) into smaller byte arrays before I can perform flood fill.
- The regions can still be irregular, making them less useful for distance checks.

3. Navigation mesh
The map is divided into regions which have line of sight between neighbouring centers.
I have found this brief description on how to do this from a tiled map:
http://www.gamedev.net/community/forums/topic.asp?topic_id=524802
Plus: Regions are very regular. This makes them very accurate for distance checks.
- Doing a flood fill from every tile could be very costly...

So, do you know of other ways? Or have any comments/experience?

[Edited by - comfy chair on January 5, 2011 2:23:13 PM]
Kevin Dill
Kevin Dill
If you can find the first issue of the Journal of Game Development (which I think might also have been the only issue), it had an article that might be helpful.

Look into Chris Jurney's work on Company of Heroes. I believe he used flood fill.

I suspect that making this fast enough will be challenging.
Kevin Dill
Kevin Dill
One other thought... my first thought would be to use flood fill, and then divide any large regions up (or just put a limit on how far you allow the flood fill to go out when creating each region).
comfy chair
comfy chair
Quote:
Original post by Kevin Dill
One other thought... my first thought would be to use flood fill, and then divide any large regions up (or just put a limit on how far you allow the flood fill to go out when creating each region).


Good idea, I hadn't thought of that.
comfy chair
comfy chair
On his site:

http://www.chrisjurney.com/

in the slide presentation "Dealing with destruction", the first images show sectors (what I called regions).

They are quite small, only 10 tiles radius or so. It isn't explained how he generated them, but as you say, probably by flood fill from regularly spaced points.

Is there a faster flood fill algorithm than Dijkstra (BFS)?
comfy chair
comfy chair
I am done with my first draft of the flood fill code. It starts a limited flood fill repeatedly from regular intervals. If I come across a tile that is completely blocked, I skip ahead. So this means that there can be holes in the region map. I try to fix these in a second pass.



Now I need to create the graph from the regions that are connected. I am thinking of doing it by scanning through the map and look at 4 tiles at a time, then adding edges to my graph when I come across 2 or more regions within the 4 tile box.

But is there a smarter/more efficient way of building the graph?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.