Skip to content
Snippets Groups Projects
BiomeParameter.cs 1.49 KiB
Newer Older
using System.Collections;
using System;
Ryan Chang's avatar
Ryan Chang committed
using System.Linq;
using UnityEngine;
using System.Collections.Generic;

[Serializable]
Ryan Chang's avatar
Ryan Chang committed
public class BiomeParameter
Ryan Chang's avatar
Ryan Chang committed
    public const int MAX_OCTAVE_OFFSET = 256;

    public string name;
    [Tooltip("What is used to generate the biome.")]
    public List<Octave> map;
    [Tooltip("What is used to generate the terrain.")]
    public List<Octave> shapeMap;
    [Tooltip("What is used to map terrain materials to heights.")]
Ryan Chang's avatar
Ryan Chang committed
    public List<TerrainHeightMap> terrainMap;
    public Color debugColor;
Ryan Chang's avatar
Ryan Chang committed

    public void DrawDebug(float x, float y)
    {
        Vector3 start = new(x, 0, y);
        Vector3 end = start + map.Sum(o => o.Calculate(new(x, y))) * Vector3.up;
        Debug.DrawLine(start, end, debugColor, 10);
    }

    /// <summary>
    /// Reseeds the map and shapeMap octaves by randomizing their
    /// offsets.
    /// </summary>
    public void ReseedOctaves()
    {
        map = ReseedOctave(map);
        shapeMap = ReseedOctave(shapeMap);
    }

    private List<Octave> ReseedOctave(List<Octave> octaves)
    {
        List<Octave> output = new(octaves.Count);

        foreach (var o in octaves)
        {
            Octave newOctave = new(o, RandomOffset());
            output.Add(newOctave);
        }

        return output;
    }

    private Vector2 RandomOffset() => RNG.GetRandomVector2(MAX_OCTAVE_OFFSET);
}

[Serializable]
public struct TerrainHeightMap
{
    public float minHeight;
    public float maxHeight;

    public Texture texture;
}