Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using LibNoise.Xna;
- using LibNoise.Xna.Generator;
- using LibNoise.Xna.Operator;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using System.IO;
- using System.Threading;
- namespace Cubetex
- {
- class WorldGenSettings
- {
- /// <summary>
- /// The ammount of terrain change per pixel
- /// </summary>
- public float VerticalGradient = .3f;
- public float OceanLimit = .1f;
- public int Seed = 0;
- public volatile bool Generated = false;
- public string Path;
- }
- class WorldGenerator : IWorldGenerator
- {
- const int size = 1024;
- Noise2D noiseGenerator;
- public void ThreadedGenerate(object Context)
- {
- GenerateWorld((WorldGenSettings)Context);
- }
- public void GenerateWorld(WorldGenSettings settings)
- {
- ModuleBase Ocean = new Const(-1);
- ModuleBase flat_raw = new Const(.1);
- ModuleBase Flat = new Clamp(0, .1, flat_raw);
- //ModuleBase OceanSelector = new Voronoi(16, 2, 0, false);
- ModuleBase TerrainGenerator = new Perlin(1.5, 2.5, .5, 6, settings.Seed, QualityMode.Medium);
- ModuleBase abs = new Invert(TerrainGenerator);
- ModuleBase terrain_raw = new ScaleBias(settings.VerticalGradient, .1, abs);
- ModuleBase terrain_1 = new Clamp(.1, .8, terrain_raw);
- ModuleBase TerrainFinal = terrain_1;
- ModuleBase OceanSelector = new Perlin(1.5, 2.5, .5, 6, settings.Seed, QualityMode.Medium); // 1.png
- ModuleBase Ocean_1 = new Clamp(-1, .9, OceanSelector);
- ModuleBase OceanFinal = Ocean_1;
- ModuleBase terrain = new Select(.1, 1, 0, TerrainFinal, Ocean, OceanFinal);
- //
- //ModuleBase voronoi = new Voronoi(16, 2, 0, false);
- noiseGenerator = new Noise2D(size, terrain);
- noiseGenerator.GeneratePlanar(Noise2D.Left, Noise2D.Right, Noise2D.Top, Noise2D.Bottom);
- Texture2D tex = noiseGenerator.GetTexture(ArtManager.GraphicsDevice, Gradient.Terrain) ;
- string Path = FileSystem.GetWorldPath(settings.Path) ;
- string filename = "Terrain.png";
- using (Stream stream = File.Open(Path + filename, FileMode.OpenOrCreate))
- {
- tex.SaveAsPng(stream, size, size);
- GameConsole.ConsoleMessage("Screenshot saved as: " + filename);
- }
- lock (settings)
- {
- settings.Generated = true;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment