public void UpdateLoadedArea(int x, int y, int width, int height, WorldLoader worldLoader) { Rect newrect = new Rect(x - 3, y - 3, width + 6, height + 6); if (newrect.Equals(lastRect)) { return; } Rect newDrawRect = new Rect(x, y, width, height); ChunksLoaded.ForEachWrapper((cw) => { int j = cw.x; int i = cw.y; if (!newrect.Contains(j, i)) { Chunk chunk = ChunksLoaded.Get(j, i); if (chunk == null) { return; } UnloadChunk(chunk); } }); ChunksVisible.ForEachWrapper((cw) => { int j = cw.x; int i = cw.y; if (!newDrawRect.Contains(j, i)) { ChunksVisible.Remove(j, i); } }); for (int i = newrect.Y; i < newrect.Y + newrect.Height; i++) { for (int j = newrect.X; j < newrect.X + newrect.Width; j++) { if (!ChunksLoaded.Includes(j, i)) { Chunk chunk = worldLoader.LoadChunk(j, i); if (chunk == null) { continue; } chunk.Load(); ChunksLoaded.Add(j, i, chunk); } if (newDrawRect.Contains(j, i)) { Chunk chunk = ChunksLoaded.Get(j, i); if (chunk == null) { continue; } ChunksVisible.Add(j, i, chunk); } } } lastRect = newrect; lastDrawRect = newDrawRect; }
public LoadedChunksManager(WorldLoader worldLoader) { this.worldLoader = worldLoader; }