private void CheckForChunkEvict() { lock (this) { if (ActiveChunks.Count < 25) { return; } GraphChunk evict = null; foreach (GraphChunk gc in ActiveChunks) { if (evict == null || gc.LRU < evict.LRU) { evict = gc; } } // It is full! evict.Save(BaseDir + "\\" + Continent + "\\"); ActiveChunks.Remove(evict); chunks.Clear(evict.ix, evict.iy); evict.Clear(); } }
public Spot GetSpot2D(float x, float y) { LoadChunk(x, y); GraphChunk gc = GetChunkAt(x, y); return(gc.GetSpot2D(x, y)); }
public Spot GetSpot(float x, float y, float z) { LoadChunk(x, y); GraphChunk gc = GetChunkAt(x, y); return(gc.GetSpot(x, y, z)); }
public Spot AddSpot(Spot s) { LoadChunk(s.X, s.Y); GraphChunk gc = GetChunkAt(s.X, s.Y); return(gc.AddSpot(s)); }
private GraphChunk GetChunkAt(float x, float y) { int ix, iy; GetChunkCoord(x, y, out ix, out iy); GraphChunk c = chunks.Get(ix, iy); if (c != null) { c.LRU = LRU++; } return(c); }
// Create and load from file if exisiting private void LoadChunk(float x, float y) { GraphChunk gc = GetChunkAt(x, y); if (gc == null) { int ix, iy; GetChunkCoord(x, y, out ix, out iy); float base_x, base_y; GetChunkBase(ix, iy, out base_x, out base_y); gc = new GraphChunk(base_x, base_y, ix, iy); gc.LRU = LRU++; CheckForChunkEvict(); gc.Load(BaseDir + "\\" + Continent + "\\"); chunks.Set(ix, iy, gc); ActiveChunks.Add(gc); } }
public List <Spot> FindAllSpots(float min_x, float min_y, float max_x, float max_y) { // hmm, do it per chunk List <Spot> l = new List <Spot>(); for (float mx = min_x; mx <= max_x + GraphChunk.CHUNK_SIZE - 1; mx += GraphChunk.CHUNK_SIZE) { for (float my = min_y; my <= max_y + GraphChunk.CHUNK_SIZE - 1; my += GraphChunk.CHUNK_SIZE) { LoadChunk(mx, my); GraphChunk gc = GetChunkAt(mx, my); List <Spot> sl = gc.GetAllSpots(); foreach (Spot s in sl) { if (s.X >= min_x && s.X <= max_x && s.Y >= min_y && s.Y <= max_y) { l.Add(s); } } } } return(l); }