public Cave(ref Random rnd, ref IMapHandler mh, Vector3i StartingPoint) { mMap = mh; rand = rnd; AddPoint(StartingPoint); // We need at least 4 points. int numPoints2Make = rand.Next(3, 10); for(int i=0;i<numPoints2Make;i++) { i++; AddPoint(new Vector3i(StartingPoint.X+rand.Next(-16, 16), StartingPoint.Y+rand.Next(-16, 16), StartingPoint.Z+rand.Next(-16, 16))); } Profiler profSphere = new Profiler("MakeSphere"); Profiler profSpline = new Profiler("GetInterpolatedSplinePoint"); int rad = rand.Next(1, 3); for(int p = 0;p<20;p++) { double t = (double)p/(double)(Points.Count*32); // Between 2/10 radius. profSpline.Start(); Vector3i derp = this.GetInterpolatedSplinePoint(t); profSpline.Stop(); mMap.SetBlockAt(derp.X, derp.Y, derp.Z, 0); profSphere.Start(); MakeSphere(derp, rad); profSphere.Stop(); //Console.WriteLine("MakeSphere r={0} @ t={1}", rad, t); //t += 0.05; } mMap.SaveAll(); Console.WriteLine(profSpline.ToString()); Console.WriteLine(profSphere.ToString()); }
public Cave(ref Random rnd, ref IMapHandler mh, Vector3i StartingPoint) { mMap = mh; rand = rnd; AddPoint(StartingPoint); // We need at least 4 points. int numPoints2Make = rand.Next(3, 10); for (int i = 0; i < numPoints2Make; i++) { i++; AddPoint(new Vector3i(StartingPoint.X + rand.Next(-16, 16), StartingPoint.Y + rand.Next(-16, 16), StartingPoint.Z + rand.Next(-16, 16))); } Profiler profSphere = new Profiler("MakeSphere"); Profiler profSpline = new Profiler("GetInterpolatedSplinePoint"); int rad = rand.Next(1, 3); for (int p = 0; p < 20; p++) { double t = (double)p / (double)(Points.Count * 32); // Between 2/10 radius. profSpline.Start(); Vector3i derp = this.GetInterpolatedSplinePoint(t); profSpline.Stop(); mMap.SetBlockAt(derp.X, derp.Y, derp.Z, 0); profSphere.Start(); MakeSphere(derp, rad); profSphere.Stop(); //Console.WriteLine("MakeSphere r={0} @ t={1}", rad, t); //t += 0.05; } mMap.SaveAll(); Console.WriteLine(profSpline.ToString()); Console.WriteLine(profSphere.ToString()); }
public virtual void AddTrees(ref IMapHandler mh, BiomeType[,] biomes, ref Random rand, int X, int Z, int H) { int xo = (int)(X * mh.ChunkScale.X); int zo = (int)(Z * mh.ChunkScale.Z); List <Vector2i> PlantedTrees = new List <Vector2i>(); int DistanceReqd = 3; for (int t = 0; t < (int)((HumidityNoise.Noise((double)(xo) / BIOME_SCALE, (double)(zo) / BIOME_SCALE, 0) + HumidityOffset) * 5.0); t++) { Vector2i me = new Vector2i(rand.Next(0, 15), rand.Next(0, 15)); if (!Biome.NeedsTrees(biomes[me.X, me.Y])) { continue; } bool tooclose = false; foreach (Vector2i tree in PlantedTrees) { if (Vector2i.Distance(tree, me) < DistanceReqd) { tooclose = true; break; } } if (tooclose) { continue; } bool founddert = false; for (int y = (int)H - 10; y > 0; y--) { switch (mh.GetBlockAt(me.X + xo, y, me.Y + zo)) { case 0: // Air case 78: // Snow cover continue; // case 1: // ROCK case 2: // GRASS case 3: // DIRT //Utils.GrowTree(ref blocks, rand, (int)me.X, (int)y + 1, (int)me.Y); mh.SetBlockAt(me.X + xo, y + 1, me.Y + zo, 6); // Sapling mh.SetDataAt(me.X + xo, y + 1, me.Y + zo, 15); // Growth stage 15. /* * Tree tree = new NormalTree(me.X + xo, y + 1, me.Y + zo, rand.Next(5, 8)); * tree.MakeTrunk(ref mh); * tree.MakeFoliage(ref mh); */ mh.SaveAll(); founddert = true; break; case 11: // SAND //Utils.GrowCactus(ref b, rand, me.X, y + 1, me.Y); break; default: founddert = true; break; } if (founddert) { break; } } PlantedTrees.Add(me); } }
public virtual void AddTrees(ref IMapHandler mh, BiomeType[,] biomes, ref Random rand, int X, int Z, int H) { int xo = (int)(X * mh.ChunkScale.X); int zo = (int)(Z * mh.ChunkScale.Z); List<Vector2i> PlantedTrees = new List<Vector2i>(); int DistanceReqd = 3; for (int t = 0; t < (int)((HumidityNoise.Noise((double)(xo) / BIOME_SCALE, (double)(zo) / BIOME_SCALE, 0) + HumidityOffset) * 5.0); t++) { Vector2i me = new Vector2i(rand.Next(0, 15),rand.Next(0, 15)); if (!Biome.NeedsTrees(biomes[me.X, me.Y])) continue; bool tooclose=false; foreach (Vector2i tree in PlantedTrees) { if (Vector2i.Distance(tree, me) < DistanceReqd) { tooclose = true; break; } } if (tooclose) continue; bool founddert = false; for (int y = (int)H - 10; y > 0; y--) { switch (mh.GetBlockAt(me.X+xo, y, me.Y+zo)) { case 0: // Air case 78: // Snow cover continue; // case 1: // ROCK case 2: // GRASS case 3: // DIRT //Utils.GrowTree(ref blocks, rand, (int)me.X, (int)y + 1, (int)me.Y); mh.SetBlockAt(me.X + xo, y + 1, me.Y + zo, 6); // Sapling mh.SetDataAt(me.X + xo, y + 1, me.Y + zo, 15); // Growth stage 15. /* Tree tree = new NormalTree(me.X + xo, y + 1, me.Y + zo, rand.Next(5, 8)); tree.MakeTrunk(ref mh); tree.MakeFoliage(ref mh); */ mh.SaveAll(); founddert = true; break; case 11: // SAND //Utils.GrowCactus(ref b, rand, me.X, y + 1, me.Y); break; default: founddert = true; break; } if (founddert) break; } PlantedTrees.Add(me); } }