示例#1
0
        /// <summary>
        /// The default function to generate a new world.
        /// </summary>
        /// <returns>Return a world made with terrain generation</returns>
        public static WorldController GetNewWorld(FastNoise.NoiseType noise)
        {
            // Set the generation noise type
            Noise = noise;

            // Initialize World
            WorldController world = new WorldController();

            // Initialize WorldModel and ChunkGrid in World so you can add chunks to this grid
            world.WorldModel = new WorldModel
            {
                ChunkGrid = new Dictionary <Coords, WorldChunkController>()
            };

            // For loop to add chunks from -2 to +2 in both x and y directions. this makes for a 5x5 chunkmap.
            for (int x = -2; x <= 2; x++)
            {
                for (int y = -2; y <= 2; y++)
                {
                    // Sets the coords for the new chunk
                    Coords coords = new Coords {
                        x = x, y = y
                    };

                    // Initializes a new chunk with the set coords and a basic terrain type
                    WorldChunkController chunkController = WorldChunkFactory.ChunkOfDefaultTerrain(coords);

                    // Adds the new chunk to the worldgrid
                    world.WorldModel.ChunkGrid.Add(coords, chunkController);
                }
            }

            // Returns the worldController with a 5x5 chunkGrid initialized
            return(world);
        }
示例#2
0
        public SurfaceGenerator(TileCollection tiles, EntityCollection entityCollection, List <GeneratorEntityAffinity> entities)
        {
            surfaceSize       = Props.maxSurfaceSize * Props.chunkSize;
            moistureFactor    = 1.0f;
            temperatureFactor = 1.0f;
            elevationFactor   = 1.0f;
            elevationType     = FastNoise.NoiseType.PerlinFractal;
            moistureType      = FastNoise.NoiseType.PerlinFractal;
            temperatureType   = FastNoise.NoiseType.PerlinFractal;

            elevationNoise = new FastNoise();
            elevationNoise.SetNoiseType(elevationType);
            moistureNoise = new FastNoise();
            moistureNoise.SetNoiseType(moistureType);
            temperatureNoise = new FastNoise();
            temperatureNoise.SetNoiseType(temperatureType);

            Random r = new Random();

            seed = r.Next(0, int.MaxValue - 1);
            SetSeed(seed);

            tileList = tiles.GetTerrainTiles();
            this.entityCollection  = entityCollection;
            this.entitiesGenerated = entities;
        }
示例#3
0
    public static FastNoise GetFastNoise(Chunk chunk)
    {
        int   Octaves    = int.Parse(Configuration.GetPropertyValue(AdvFeatureClass, "Octaves"));
        float Lacunarity = float.Parse(Configuration.GetPropertyValue(AdvFeatureClass, "Lacunarity"));
        float Gain       = float.Parse(Configuration.GetPropertyValue(AdvFeatureClass, "Gain"));
        float Frequency  = float.Parse(Configuration.GetPropertyValue(AdvFeatureClass, "Frequency"));


        FastNoise.FractalType fractalType = EnumUtils.Parse <FastNoise.FractalType>(Configuration.GetPropertyValue(AdvFeatureClass, "FractalType"), false);
        FastNoise.NoiseType   noiseType   = EnumUtils.Parse <FastNoise.NoiseType>(Configuration.GetPropertyValue(AdvFeatureClass, "NoiseType"), false);

        FastNoise fastNoise = new FastNoise();

        fastNoise.SetFractalType(fractalType);
        fastNoise.SetNoiseType(noiseType);
        fastNoise.SetFractalOctaves(Octaves);
        fastNoise.SetFractalLacunarity(Lacunarity);
        fastNoise.SetFractalGain(Gain);
        fastNoise.SetFrequency(Frequency);
        fastNoise.SetSeed(chunk.GetHashCode());

        var chunkPos = chunk.GetWorldPos();

        String display = "Chunk and Seed: " + chunk.GetHashCode() + " Fractal Type: " + fractalType.ToString() + " Noise Type: " + noiseType.ToString() + " Position: " + chunkPos + " Octaves: " + Octaves + " Lacunarity: " + Lacunarity + " Gain: " + Gain + " Frequency: " + Frequency;

        AdvLogging.DisplayLog(AdvFeatureClass, display);

        return(fastNoise);
    }
示例#4
0
 public NoiseWrapper(FastNoise.NoiseType noiseType, FastNoise.FractalType fractalType, float frequency, float persistence, int octaves, int seed)
 {
     generator = new FastNoise(seed);
     generator.SetNoiseType(noiseType);
     generator.SetFractalType(fractalType);
     generator.SetFrequency(frequency);
     generator.SetFractalGain(persistence);
     generator.SetFractalOctaves(octaves);
     generator.SetFractalLacunarity(2.0f);
 }
示例#5
0
 public static void NoiseFill(int surfaceHeight, FastNoise.NoiseType noiseType, Action <int, int> iterateMethod)
 {
     int[] randomOffsets = NoiseHelper.Get2dDisplacements(Main.maxTilesX, 0.02f, 75, 1, WorldGen._genRandSeed, noiseType);
     for (int i = 0; i < Main.maxTilesX; i++)
     {
         int startLevel = surfaceHeight + randomOffsets[i];
         for (int j = startLevel; j < Main.maxTilesY; j++)
         {
             iterateMethod(i, j);
         }
     }
 }
示例#6
0
        private void InstantiateToggle(FastNoise.NoiseType noiseType)
        {
            var toggle = InstantiateControl <ToggleControl>(toggleGroup.transform);

            toggle.Initialize(
                header: noiseType.ToString(),
                value: noiseType == currentNoiseType,
                onValueChanged: isOn =>
            {
                if (isOn)
                {
                    currentNoiseType = noiseType;
                    Generate();
                }
            },
                toggleGroup: toggleGroup);
        }
示例#7
0
        public static int[] Get2dDisplacements(int displacementCount, float frequency, int maxLimit, float multiplier, int seed, FastNoise.NoiseType noiseType) //libvaxy method
        {
            FastNoise noise = new FastNoise(seed);

            noise.SetNoiseType(noiseType);
            noise.SetFrequency(frequency);

            int[] displacements = new int[displacementCount];

            for (int x = 0; x < displacementCount; x++)
            {
                displacements[x] = (int)Math.Floor(noise.GetNoise(x, x) * maxLimit * multiplier);
            }

            return(displacements);
        }
示例#8
0
    public float Get(Vector3 location, float amplitude, float frequency, int octaves, FastNoise.NoiseType type)
    {
        Noise.SetNoiseType(type);
        Noise.SetFrequency(frequency);
        Noise.SetFractalOctaves(octaves);
        float elevation = Noise.GetNoise(location.x, location.y, location.z) * amplitude;

        return(elevation);
    }
示例#9
0
        public static Texture2D CreateNoiseTexture(int width, int height, float frequency, FastNoise.NoiseType noiseType = FastNoise.NoiseType.Perlin)
        {
            Texture2D texture = CreateTexture(width, height);

            FastNoise noise = new FastNoise(Main.rand.Next(int.MaxValue));

            noise.SetNoiseType(noiseType);
            noise.SetFrequency(frequency);

            Color[] colors = new Color[width * height];

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    byte value = (byte)Math.Abs(noise.GetNoise(x, y) * 255);
                    colors[CoordinateToIndex(x, y, width)] = new Color(value, value, value);
                }
            }

            texture.SetData(colors);

            return(texture);
        }
示例#10
0
		public MapParameters(float mapScale, float baseHeight, AnimationCurve heightCurve, int size, FastNoise.NoiseType noiseType,
			int octaves, float lacunarity, int noiseSeed, float noiseScale, Vector2 noisePosition, bool useMeshColor,
			float colorSmoothing, int levelOfDetail, int textureResolutionFactor, List<TerrainTextureType> terrainTextures,
			bool useNormalMap, float normalMapStrength)
		{
			if (heightCurve == null) throw new ArgumentNullException(nameof(heightCurve));
			if (terrainTextures == null) throw new ArgumentNullException(nameof(terrainTextures));
			this.mapScale = mapScale;
			this.baseHeight = baseHeight;
			this.heightCurve = heightCurve;
			this.size = size;
			this.noiseType = noiseType;
			this.octaves = octaves;
			this.lacunarity = lacunarity;
			this.noiseSeed = noiseSeed;
			this.noiseScale = noiseScale;
			this.noisePosition = noisePosition;
			this.useMeshColor = useMeshColor;
			this.colorSmoothing = colorSmoothing;
			this.levelOfDetail = levelOfDetail;
			this.textureResolutionFactor = textureResolutionFactor;
			this.terrainTextures = terrainTextures;
			this.useNormalMap = useNormalMap;
			this.normalMapStrength = normalMapStrength;
		}