Esempio n. 1
0
        public void Execute(int i)
        {
            Utils.IndexDeflattenizer2D(i, TotalBlockNumberX, out int x, out int z);

            ReadonlyVector3Int heights = TerrainGenerator.CalculateHeights(Seed, x, z);

            int max = heights.X; // max could be passed to the loop below but it requires air to be default type

            if (heights.Y > max)
            {
                max = heights.Y;
            }
            if (heights.Z > max)
            {
                max = heights.Z;
            }

            var blockTypes = new BlockTypeColumn(max);

            unsafe
            {
                // heights are inclusive
                for (int y = 0; y <= max; y++)
                {
                    blockTypes.Types[y] = (byte)TerrainGenerator.DetermineType(Seed, x, y, z, in heights);
                }
            }

            Result[i] = blockTypes;
        }
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            NativeArray <CoordinatesComponent> coordinatesArray = chunk.GetNativeArray(Coordinates);
            NativeArray <BlockTypesComponent>  blockTypesArray  = chunk.GetNativeArray(BlockTypes);
            SeedComponent seed = chunk.GetChunkComponentData(Seed);

            for (int i = 0; i < chunk.Count; i++)
            {
                int3 coordinates           = coordinatesArray[i].Coordinates;
                ReadonlyVector3Int heights = TerrainGenerator.CalculateHeights(seed.Seed, coordinates.x, coordinates.z);

                blockTypesArray[i] = new BlockTypesComponent()
                {
                    BlockType = TerrainGenerator.DetermineType(seed.Seed, coordinates.x, coordinates.y, coordinates.z, in heights)
                };
            }
        }
    }
Esempio n. 3
0
    /// <summary>
    /// Generates block types with hp and hp level.
    /// Chunks and their objects (if first run = true).
    /// And calculates faces.
    /// </summary>
    public IEnumerator GenerateWorld(bool firstRun)
    {
        _stopwatch.Restart();
        ResetProgressBarVariables();

        Status = WorldGeneratorStatus.GeneratingTerrain;

        yield return(null);

        ProgressDescription = "Initialization...";
        Blocks            = new Block[Settings.WorldSizeX * ChunkSize, WorldSizeY *ChunkSize, Settings.WorldSizeZ *ChunkSize];
        AlreadyGenerated += _progressStep;

        yield return(null);

        ProgressDescription = "Calculating heights...";
        var heights = _terrainGenerator.CalculateHeights();

        AlreadyGenerated += _progressStep;

        yield return(null);

        ProgressDescription = "Generating terrain...";
        var types = _terrainGenerator.CalculateBlockTypes(heights);

        AlreadyGenerated += _progressStep;

        yield return(null);

        ProgressDescription = "Output deflattenization...";
        DeflattenizeOutput(ref types);
        AlreadyGenerated += _progressStep;

        yield return(null);

        UnityEngine.Debug.Log("WaterLevel " + Settings.WaterLevel);
        if (Settings.IsWater)
        {
            ProgressDescription = "Generating water...";
            _terrainGenerator.AddWater(ref Blocks);
        }
        AlreadyGenerated += _progressStep;

        yield return(null);

        ProgressDescription = "Generating trees...";
        _terrainGenerator.AddTrees(ref Blocks);
        AlreadyGenerated += _progressStep;

        yield return(null);

        ProgressDescription = "Creating game objects...";
        if (firstRun)
        {
            _worldScene = SceneManager.CreateScene(name);
        }

        Chunks = new Chunk[Settings.WorldSizeX, WorldSizeY, Settings.WorldSizeZ];
        CreateGameObjects(firstRun);
        AlreadyGenerated += _progressStep;

        yield return(null);

        ProgressDescription = "Calculating faces...";
        _meshGenerator.CalculateFaces(ref Blocks);
        AlreadyGenerated += _progressStep;

        yield return(null);

        ProgressDescription = "World boundaries check...";
        _meshGenerator.WorldBoundariesCheck(ref Blocks);
        AlreadyGenerated += _progressStep;

        Status = WorldGeneratorStatus.TerrainReady;

        _stopwatch.Stop();
        UnityEngine.Debug.Log($"It took {_stopwatch.ElapsedTicks / TimeSpan.TicksPerMillisecond} ms to generate all terrain.");
    }
 public void Execute(int i)
 {
     Utils.IndexDeflattenizer2D(i, TotalBlockNumberX, out int x, out int z);
     Result[i] = TerrainGenerator.CalculateHeights(Seed, x, z);
 }