Esempio n. 1
0
        /// <summary>
        /// Generate additional 3D objects using the heightmap and surrounding blocks
        /// </summary>
        private void GenerateExtraObjects(Biome biome, VoxelCache cache, int x, int z)
        {
            int newOffsetX = (int)(offset.X + (x * cache.SizeX));
            int newOffsetZ = (int)(offset.Z + (z * cache.SizeZ));
            int seed       = cache.GetHashCode() ^ ((newOffsetX << 13) + (newOffsetZ >> 5));// ^ cache.MapSeed;

            Random rnd    = new Random(seed);
            int    localX = rnd.Next(cache.SizeX) ^ (mapSeed & 0x1f);
            int    localZ = rnd.Next(cache.SizeZ) ^ (mapSeed & 0x1f);

            localX++;
            localZ++;

            float objectDist = Noise.Simplex.Generate(
                (float)(((float)newOffsetX / 800f) + 120f),
                (float)(((float)newOffsetZ / 800f) + 100f));

            objectDist = (float)Math.Pow((objectDist * 0.5f) + 0.5f, 1.2f);

            int objectChance = rnd.Next(100);
            int chance       = (int)(objectDist * 100f) / 2;

            // We can grab the height value instantly from the noise pattern
            float height = biome.GetBaseHeight(localX + newOffsetX, localZ + newOffsetZ, false);

            if (height < 80 && objectChance < chance)
            {
                Engine.TreePopulator treePopulator = new Engine.TreePopulator(biome, cache.voxels[offset], rnd);

                treePopulator.Populate(
                    localX + (x * cache.SizeX),
                    localZ + (z * cache.SizeZ),
                    (int)height, cache.SizeX);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Offset the location (usually to rebuild)
        /// </summary>
        /// <param name="offset"></param>
        public void OffsetLocation(Point offset, SpeedyDictionary chunkCollection)
        {
            // Remove old chunks and update location
            for (int i = 0; i < chunks.Length; ++i)
            {
                chunkCollection.Remove(new Vector3(location.X, i * chunkSize, location.Y));
            }

            this.location.X += offset.X;
            this.location.Y += offset.Y;

            // Update the chunk locations as well
            for (int i = 0; i < chunks.Length; ++i)
            {
                chunks[i].SetLocation(new Vector3(location.X, i * chunkSize, location.Y));
            }

            // Reset biome location and generate 2D biome map data
            biome.SetLocation(location);
            Parallel.For(0, chunkSize + 2, x =>
            {
                for (int z = 0; z < chunkSize + 2; ++z)
                {
                    biome.GetBaseHeight(x, z, true);
                    biome.GetLocalHumidity(x, z, 0.05f, true);
                }
            });

            // Set dirty flag
            state = ChunkState.Dirty;
        }