public void Grow(GenerationData data, Random rng) { if (isEmpty()) { return; } int width = data.width; int height = data.height; int nIndex; nIndex = rng.Next(0, frontier.Count); int nextIndex = frontier[nIndex]; int endIndex = frontier[frontier.Count - 1]; frontier[nIndex] = endIndex; frontier[frontier.Count - 1] = nextIndex; frontier.RemoveAt(frontier.Count - 1); int x = nextIndex % width; int y = nextIndex / width; nIndex = ((y + 0) * width) + (x + 1); if (nIndex >= 0 && nIndex < data.pointData.Length && data.pointData[nIndex].biome == BIOME.NONE) { data.pointData[nIndex].biome = biomeType; frontier.Add(nIndex); } nIndex = ((y + 0) * width) + (x - 1); if (nIndex >= 0 && nIndex < data.pointData.Length && data.pointData[nIndex].biome == BIOME.NONE) { data.pointData[nIndex].biome = biomeType; frontier.Add(nIndex); } nIndex = ((y + 1) * width) + (x + 0); if (nIndex >= 0 && nIndex < data.pointData.Length && data.pointData[nIndex].biome == BIOME.NONE) { data.pointData[nIndex].biome = biomeType; frontier.Add(nIndex); } nIndex = ((y - 1) * width) + (x + 0); if (nIndex >= 0 && nIndex < data.pointData.Length && data.pointData[nIndex].biome == BIOME.NONE) { data.pointData[nIndex].biome = biomeType; frontier.Add(nIndex); } }
public GenerationData Generate(GenerationSettings settings, BackgroundWorker worker = null) { Random rng = new Random(); //settings.seed GenerationData data = new GenerationData(); data.width = (int)Config.sizeMap[settings.size].X * Config.CHUNK_SIZE; data.height = (int)Config.sizeMap[settings.size].Y * Config.CHUNK_SIZE; data.pointData = new PointData[data.width * data.height]; for (int i = 0; i < data.pointData.Length; i++) { data.pointData[i] = new PointData(); } Stopwatch timer = new Stopwatch(); foreach (GenerationStep step in steps) { timer.Start(); step.Execute(data, rng, worker); Debug.WriteLine("[GENERATION] " + step.GetName() + " Ran In: " + FormatTime(timer.Elapsed)); timer.Reset(); } //determine spawn location int equator = data.height / 2; int startingY = equator * data.width; int firstLand = 0; while (!data.pointData[startingY + firstLand].land) { firstLand++; } data.spawnArea = new Rectangle(firstLand + 10, equator - 5, Config.SPAWN_AREA_SIZE, Config.SPAWN_AREA_SIZE); return(data); }