Guest User

Untitled

a guest
Nov 23rd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using LibNoise.Xna;
  6. using LibNoise.Xna.Generator;
  7. using LibNoise.Xna.Operator;
  8. using Microsoft.Xna.Framework;
  9. using Microsoft.Xna.Framework.Graphics;
  10. using System.IO;
  11. using System.Threading;
  12.  
  13. namespace Cubetex
  14. {
  15.  
  16. class WorldGenSettings
  17. {
  18. /// <summary>
  19. /// The ammount of terrain change per pixel
  20. /// </summary>
  21. public float VerticalGradient = .3f;
  22. public float OceanLimit = .1f;
  23.  
  24. public int Seed = 0;
  25.  
  26. public volatile bool Generated = false;
  27.  
  28. public string Path;
  29.  
  30. }
  31.  
  32.  
  33.  
  34. class WorldGenerator : IWorldGenerator
  35. {
  36. const int size = 1024;
  37. Noise2D noiseGenerator;
  38.  
  39.  
  40. public void ThreadedGenerate(object Context)
  41. {
  42. GenerateWorld((WorldGenSettings)Context);
  43. }
  44.  
  45.  
  46. public void GenerateWorld(WorldGenSettings settings)
  47. {
  48.  
  49.  
  50. ModuleBase Ocean = new Const(-1);
  51.  
  52.  
  53. ModuleBase flat_raw = new Const(.1);
  54. ModuleBase Flat = new Clamp(0, .1, flat_raw);
  55.  
  56.  
  57.  
  58. //ModuleBase OceanSelector = new Voronoi(16, 2, 0, false);
  59. ModuleBase TerrainGenerator = new Perlin(1.5, 2.5, .5, 6, settings.Seed, QualityMode.Medium);
  60. ModuleBase abs = new Invert(TerrainGenerator);
  61. ModuleBase terrain_raw = new ScaleBias(settings.VerticalGradient, .1, abs);
  62.  
  63. ModuleBase terrain_1 = new Clamp(.1, .8, terrain_raw);
  64. ModuleBase TerrainFinal = terrain_1;
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. ModuleBase OceanSelector = new Perlin(1.5, 2.5, .5, 6, settings.Seed, QualityMode.Medium); // 1.png
  72. ModuleBase Ocean_1 = new Clamp(-1, .9, OceanSelector);
  73. ModuleBase OceanFinal = Ocean_1;
  74.  
  75.  
  76.  
  77. ModuleBase terrain = new Select(.1, 1, 0, TerrainFinal, Ocean, OceanFinal);
  78.  
  79.  
  80. //
  81. //ModuleBase voronoi = new Voronoi(16, 2, 0, false);
  82.  
  83.  
  84. noiseGenerator = new Noise2D(size, terrain);
  85.  
  86. noiseGenerator.GeneratePlanar(Noise2D.Left, Noise2D.Right, Noise2D.Top, Noise2D.Bottom);
  87.  
  88.  
  89. Texture2D tex = noiseGenerator.GetTexture(ArtManager.GraphicsDevice, Gradient.Terrain) ;
  90.  
  91. string Path = FileSystem.GetWorldPath(settings.Path) ;
  92. string filename = "Terrain.png";
  93.  
  94. using (Stream stream = File.Open(Path + filename, FileMode.OpenOrCreate))
  95. {
  96.  
  97. tex.SaveAsPng(stream, size, size);
  98. GameConsole.ConsoleMessage("Screenshot saved as: " + filename);
  99. }
  100. lock (settings)
  101. {
  102. settings.Generated = true;
  103. }
  104. }
  105. }
  106. }
Add Comment
Please, Sign In to add comment