public Vec2i? ClosestUnloaded(int i, int j, int maxDist) { int dist = maxDist; Vec2i? res = null; for (int x = i - maxDist; x <= i + maxDist; x++) for (int y = j - maxDist; y <= j + maxDist; y++) { int curDist = Math.Max(Math.Abs(x - i), Math.Abs(y - j)); if (this[x, y].Texture == null && curDist < dist) { dist = curDist; res = new Vec2i(x, y); } } return res; }
Vertex[,] GetChunk(int x, int y) { Vec2i v = new Vec2i(x, y); if (!map.ContainsKey(v)) { var chunk = new Vertex[CHUNK_SIZE, CHUNK_SIZE]; for (int i = 0; i < CHUNK_SIZE; i++) for (int j = 0; j < CHUNK_SIZE; j++) chunk[i, j] = new Vertex(); map[v] = chunk; } return map[v]; }