I am working on a mapping system to support pathfinding over areas that are too large to hold in memory. The problem i have run into is how to load only a small part of the map when its all linked together and then dynamicaly load more of the map when it is needed and dump unnecessary pieces to disk.
I was thinking I could use seralization to save the objects to disk only problem i have is they are all linked together multiple times and im not sure how to keep track of which links need to be updated when chunks are loaded/unloaded.
Here is the class that makes up the structure of the map:
public class Chunk {
private ArrayList<Terminal> connections;
private Vector3f location;
private static int width;
private static int height;
public Chunk() {
connections = new ArrayList<Terminal>();
}
//Class continues . . . getter setter and manipulation methods
}
Connections between chunks are defined by the Terminal class:
public class Terminal {
//connection data
private ConcurrentHashMap<Terminal, ArrayList<Flag>> linkFlags;
private ArrayList<Flag> localFlags;
private ArrayList<Terminal> links; //The Terminals this Terminal is connected to within the same chunk.
private ConcurrentHashMap<Terminal, Integer> distance;
//Terminal data
private Chunk parent;
private Link connection; //the connection to a neighboring chunk terminals only exist at the connections between chunks.
private Vector3f position; //position relative to parent chunk may be unnecessary will be used for render though
public Terminal() {
links = new ArrayList<Terminal>();
distance = new ConcurrentHashMap<Terminal, Integer>();
linkFlags = new ConcurrentHashMap<Terminal, ArrayList<Flag>>();
parent = null;
connection = null;
}
//Class continues . . . getter setter and manipulation methods
}
I am using the Link class as a way to seperate chunks so they are easier to load and store but am having trouble figuring out how to distinguish chunks so I can load the right ones into memory and link the correct terminals togetherd.
Any ideas on how to "individualize" chunks would be great along with how to deal with "hanging link pointers" in terminals caused by neighboring chunks not being loaded would be great.
Thanks