void UpdateCursor(WorldChunk _chunk, WorldChunkSettings setting, WorldChunkZone zone, Coord coord, Coord lastCoordDirection) { this.countTest++; if (coord.x < 0 || coord.y < 0 || coord.x >= setting.scaledSize || coord.y >= setting.scaledSize) { // Is out of chunk! return; } // First already contains on the current zone (ex: [0;0] -> [0;1] -> [0;0] will append offen) if (zone.coords.Contains(coord)) { return; } // Test zone type (get the type based on heightMap) WorldZoneTypes coordType = _chunk.chunkData.GetZoneType(coord, setting); if (coordType != zone.type) { // It's not the same region (add it only one time) if (!this.HasZone(coord) && !this.availableCoords.Contains(coord)) { this.availableCoords.Add(coord); } return; } // It's a new on the same zone, add zone.AddCoord(coord, setting); // If the coord is on the free coord list (for future next list) if (this.availableCoords.Contains(coord)) { this.availableCoords.Remove(coord); } // Test all sides (but avoid returning on same than previous) if (lastCoordDirection != Coord.Top) { UpdateCursor(_chunk, setting, zone, coord.GetDirection(Direction.Top), Coord.Bottom); } if (lastCoordDirection != Coord.Bottom) { UpdateCursor(_chunk, setting, zone, coord.GetDirection(Direction.Bottom), Coord.Top); } if (lastCoordDirection != Coord.Left) { UpdateCursor(_chunk, setting, zone, coord.GetDirection(Direction.Left), Coord.Right); } if (lastCoordDirection != Coord.Right) { UpdateCursor(_chunk, setting, zone, coord.GetDirection(Direction.Right), Coord.Left); } return; }
void FindNewZone(WorldChunk _chunk, WorldChunkSettings setting) { // Coord found if (availableCoords.Count > 0) { Coord firstNotInZone = availableCoords [0]; // Create a new zone based on this coord WorldChunkZone zone = new WorldChunkZone(_chunk.chunkData.GetZoneType(firstNotInZone, setting)); this.zones.Add(zone); this.UpdateCursor(_chunk, setting, zone, firstNotInZone, new Coord(0, 0)); // Zone computed, check for next this.FindNewZone(_chunk, setting); } }