Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Do you want to see the whole process? (Y/N):");
            string showcase        = Console.ReadLine();
            bool   continuous_save = false;

            if (showcase.ToUpper() == "Y")
            {
                Console.WriteLine("Do you want to save the whole process? (Y/N):");
                string continuous_save_text = Console.ReadLine();
                if (continuous_save_text.ToUpper() == "Y")
                {
                    continuous_save = true;
                }
            }

            BiomeGenerator bg = new BiomeGenerator();

            bg.continuous_save = continuous_save;
            Form form = new Form();

            form.Width  = 400;
            form.Height = 400;

            if (showcase.ToUpper() == "Y")
            {
                bg.showcase = true;
                bg.form     = form;

                Task.Run(() => {
                    Application.Run(bg.form);
                    bg.form.BringToFront();
                    bg.form.Activate();
                });

                bg.form.Text = "Generation Showcase";
            }

            while (!bg.finished)
            {
                try { bg.Update(); }
                catch (Exception e) { Console.WriteLine(e.ToString()); }
                if (bg.finished)
                {
                    Console.WriteLine("FINISHED");
                    Console.WriteLine("Do you want to repeat it? (Y/N):");
                    string repeat = Console.ReadLine();
                    if (repeat.ToUpper() == "Y")
                    {
                        bg = new BiomeGenerator();
                        bg.continuous_save = continuous_save;
                        if (showcase.ToUpper() == "Y")
                        {
                            bg.showcase = true;
                            bg.form     = form;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
    public TerrainChunk(Vector2 coord, HeightMapSettings heightMapSettings, MeshSettings meshSettings, int colliderLodIndex, Transform parent, Transform viewer, Material material)
    {
        this.Coord              = coord;
        this._colliderLodIndex  = colliderLodIndex;
        this._heightMapSettings = heightMapSettings;
        this._meshSettings      = meshSettings;
        this._viewer            = viewer;
        this.Biome              = BiomeGenerator.GenerateRelativeBiome(_unnormalizedCenter);

        _unnormalizedCenter = coord * meshSettings.meshWorldSize / meshSettings.meshScale;
        var position = coord * meshSettings.meshWorldSize;

        _bounds = new Bounds(position, Vector2.one * meshSettings.meshWorldSize);


        _meshObject = new GameObject("Terrain Chunk");
        _meshObject.transform.localScale = new Vector3(10.2f, 10.2f, 10.2f);

        _meshRenderer           = _meshObject.AddComponent <MeshRenderer>();
        _meshFilter             = _meshObject.AddComponent <MeshFilter>();
        _meshCollider           = _meshObject.AddComponent <MeshCollider>();
        _terrainChunkGameObject = _meshObject.AddComponent <TerrainChunkGameObject>();
        SetNeighboringChunks();
        _meshRenderer.material = material;

        _meshObject.transform.position = new Vector3(position.x, 0, position.y);
        _meshObject.transform.parent   = parent;
        SetVisible(false);
        _maxViewDst = 400f;
    }
    // Use this for initialization
    private void Start()
    {
        //var rand = new System.Random(Seed);
        NoiseMaker = new OpenSimplexNoise(Seed);

        BiomeGenerator = new BiomeGenerator(ChunkSize * WorldSize);
        var sw = new Stopwatch();

        sw.Start();
        BiomeGenerator.Generate();
        print("Made Biomes in " + sw.Elapsed.TotalSeconds + "s");

        LoadedChunks = new List <LoadChunk>();

        LoadChunks(new Vector3(0, 0, 0));

        //show settlements
        foreach (var s in BiomeGenerator.settlements)
        {
            var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            var height = GetTerrainHeight(s.Centre);
            sphere.transform.position   = new Vector3(s.Centre.x, height, s.Centre.y);
            sphere.transform.localScale = new Vector3(50, 50, 50);
            sphere.GetComponent <MeshRenderer>().material.color = Color.red;
        }
    }
Esempio n. 4
0
    void CreateBiomeGeneratorScript()
    {
        BiomeGenerator BGscript = gameObject.AddComponent <BiomeGenerator>() as BiomeGenerator;

        BGscript.useSeed          = useSeed;
        BGscript.randomSeed       = randomSeed;
        BGscript.UIMan            = UIMan;
        BGscript.size             = size;
        BGscript.shape_bmp        = shape_bmp.Equal().TexChangeFormat(TextureFormat.ARGB32);
        BGscript.destroyOnEnd     = true;
        BGscript.generation_phase = 1;
    }
        public override void OnInspectorGUI()
        {
            BiomeGenerator myScript = target as BiomeGenerator;

            DrawDefaultInspector();

            EditorGUILayout.Space();

            GUIStyle title_style = new GUIStyle();

            title_style.fontSize  = 14;
            title_style.fontStyle = FontStyle.Bold;

            if (myScript.mode == WorldGeneratorMode.Runtime)
            {
                if (GUILayout.Button("Clear World"))
                {
                    myScript.ClearBiomeObjects();
                    EditorUtility.SetDirty(myScript);
                    EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
                }
                return;
            }

            EditorGUILayout.LabelField("Objects Generator", title_style);

            if (GUILayout.Button("Clear Biome Objects"))
            {
                myScript.ClearBiomeObjects();
                EditorUtility.SetDirty(myScript);
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }

            if (GUILayout.Button("Generate Biome Objects"))
            {
                myScript.GenerateBiomeObjects();
                EditorUtility.SetDirty(myScript);
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }

            EditorGUILayout.LabelField("Finalizing", title_style);

            if (GUILayout.Button("Generate Biome UIDs"))
            {
                myScript.GenerateBiomeUID();
                EditorUtility.SetDirty(myScript);
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }

            EditorGUILayout.Space();
            EditorGUILayout.Space();
        }
 void Start()
 {
     terrainGenerator  = GameObject.FindGameObjectWithTag("Generator").GetComponent <TerrainGenerator>();
     player            = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>();
     biomeGenerator    = terrainGenerator.shape.biomeGenerator;
     resources         = new Dictionary <ResourceType, ResourceSettings>();
     unloadedResources = new Dictionary <Vector3, List <ResourceData> >();
     loadedResources   = new Dictionary <Vector3, List <ResourceUnit> >();
     foreach (ResourceSettings setting in LoadResourcesFromFile())
     {
         resources.Add(setting.type, setting);
     }
 }
Esempio n. 7
0
    public void GenerateFirstBiome()
    {
        if (_biomeGenerator == null)
        {
            _biomeGenerator = GetComponent <BiomeGenerator>();
        }

        if (Biomes[0] == null)
        {
            throw new NullReferenceException("Please specify a first pre-defined biome for testing purposes.");
        }

        _biomeGenerator.GenerateBiome(Biomes[0].RoomCountCutoff, Biomes[0].Type);
    }
        void ReadBiomeIDToken(string ln)
        {
            string s = ln.Substring(8, ln.Length - 8);

            string[] split = s.Split('=');
            if (split.Length == 2)
            {
                BiomeGenerator bgen = new BiomeGenerator(byte.Parse(split[1]));
                biomes.Add(byte.Parse(split[0]), bgen);
            }
            else
            {
                Program.WriteError("Syntax error in splat gen description: " + s);
            }
        }
    public static TerrainGenerator CreateTerrainGenerator()
    {
        GameObject       terObj   = new GameObject("Terrain Generator");
        TerrainGenerator terGen   = terObj.AddComponent <TerrainGenerator>();
        BiomeGenerator   biomeGen = terObj.AddComponent <BiomeGenerator>();
        NoiseMap         noiseMap = terObj.AddComponent <NoiseMap>();


        terGen.heightMap   = noiseMap;
        biomeGen.heightMap = noiseMap;
        terGen.terrain     = terObj.AddComponent <Terrain>();
        terObj.AddComponent <TerrainCollider>();

        Selection.activeGameObject = terObj;
        return(terGen);
    }
Esempio n. 10
0
        public static BoardDiffState Compare(BoardNode[,] boardA, BoardNode[,] boardB)
        {
            int  width        = boardA.GetLength(0);
            int  height       = boardA.GetLength(1);
            bool heightChange = false;
            bool biomeChange  = false;
            bool nodeChange   = false;

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    if (boardA[x, y] == boardB[x, y])
                    {
                        continue;
                    }

                    nodeChange = true;

                    if (heightChange == false)
                    {
                        if (boardA[x, y].altitude != boardB[x, y].altitude)
                        {
                            heightChange = true;
                        }
                    }

                    if (biomeChange == false)
                    {
                        Biome biomeA = BiomeGenerator.GetBiome(boardA[x, y]);
                        Biome biomeB = BiomeGenerator.GetBiome(boardB[x, y]);

                        if (biomeA != biomeB)
                        {
                            biomeChange = true;
                        }
                    }

                    if (nodeChange && heightChange && biomeChange)
                    {
                        return(new BoardDiffState(nodeChange, heightChange, biomeChange));
                    }
                }
            }

            return(new BoardDiffState(nodeChange, heightChange, biomeChange));
        }
Esempio n. 11
0
    public void ApplyActionAtCursor(Action action, int brushMagnitude)
    {
        if (board == null || cursorPosition == null)
        {
            return;
        }

        BoardNode node = board[cursorPosition.row, cursorPosition.col];

        if (action == Action.Wet)
        {
            node.moisture = Mathf.Clamp(node.moisture + brushMagnitude, 0, 100);
        }
        else if (action == Action.Dry)
        {
            node.moisture = Mathf.Clamp(node.moisture - brushMagnitude, 0, 100);
        }
        else if (action == Action.Raise)
        {
            node.altitude = Mathf.Clamp(node.altitude + brushMagnitude, 0, 100);
        }
        else if (action == Action.Lower)
        {
            node.altitude = Mathf.Clamp(node.altitude - brushMagnitude, 0, 100);
        }
        else if (action == Action.Hot)
        {
            node.temperature = Mathf.Clamp(node.temperature + brushMagnitude, 0, 100);
        }
        else if (action == Action.Cold)
        {
            node.temperature = Mathf.Clamp(node.temperature - brushMagnitude, 0, 100);
        }
        else if (action == Action.Inspect)
        {
            Biome biome = BiomeGenerator.GetBiome(node);
            SetInspectText(node, biome, cursorPosition.row, cursorPosition.col);
        }

        board[cursorPosition.row, cursorPosition.col] = node;

        if (display != null)
        {
            display.DrawBoard(board);
        }
    }
Esempio n. 12
0
    float GetWaterLevel(BoardNode[,] board)
    {
        int   width       = board.GetLength(0);
        int   height      = board.GetLength(1);
        int   waterLevels = 4;
        float totalWater  = 0;
        float waterLevel  = 0f;

        int[] numberOfTilesPerLevel = new int[waterLevels];

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                BoardNode node  = board[x, y];
                int       index = altitudeBiomeIndices[BiomeGenerator.GetAltitudeBiome(node.altitude)];
                totalWater += node.moisture;
                // Add volume for each level at or above this altitude.
                for (int i = index; i < waterLevels; i++)
                {
                    numberOfTilesPerLevel[i] += 1;
                }
            }
        }

        for (int i = 0; i < waterLevels; i++)
        {
            int   tiles = numberOfTilesPerLevel[i];
            int   availableVolumeOnThisLevel = tiles * 100;
            float waterOnThisLevel           = totalWater / availableVolumeOnThisLevel;

            if (waterOnThisLevel > 1f)
            {
                waterLevel += 1f;
                totalWater  = totalWater - availableVolumeOnThisLevel;
            }
            else
            {
                waterLevel += waterOnThisLevel;
                break;
            }
        }

        return(waterLevel);
    }
Esempio n. 13
0
    private void SetVariables()
    {
        blocksDatabase = blockDB.database;
        biomesDatabase = biomeDB.database;
        xBound         = xChunkSize * chunkCountX;
        yBound         = yChunkSize * chunkCountY;

        if (useSeed)
        {
            SeedManager.setSeed(seed);
        }
        else
        {
            SeedManager.setSeed();
        }
        rng            = SeedManager.rng;
        biomeGenerator = new BiomeGenerator(xBound, yBound, rng, xSamples, ySamples, tranzitionTreshhold);
    }
Esempio n. 14
0
    void DrawBiomeClouds(BoardNode[,] board, float[,] heightMap)
    {
        int width  = board.GetLength(0);
        int height = board.GetLength(1);

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                BoardNode node  = board[x, y];
                Biome     biome = BiomeGenerator.GetBiome(node);

                if (biome.moisture == MoistureBiome.Dry || biome.moisture == MoistureBiome.Moist)
                {
                    continue;
                }

                Vector3 scale;

                if (biome.moisture == MoistureBiome.Wet)
                {
                    scale = new Vector3(.75f, .25f, .75f);
                }
                else
                {
                    scale = new Vector3(1f, .5f, 1f);
                }
                float   nodeHeight = heightMap[x, y];
                Vector3 position   = new Vector3(x - width / 2 + .5f, nodeHeight / 2 + 5, y - width / 2 + .5f);

                GameObject   obj          = GameObject.CreatePrimitive(PrimitiveType.Cube);
                MeshRenderer meshRenderer = obj.GetComponent <MeshRenderer> ();
                meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                meshRenderer.receiveShadows    = false;
                obj.transform.localScale       = scale;
                obj.transform.localPosition    = position;
                obj.transform.parent           = transform;
                obj.GetComponent <MeshRenderer> ().sharedMaterial = cloudMaterial;
                doodads.Add(obj);
            }
        }
    }
Esempio n. 15
0
    IEnumerator finalCountdown()
    {
        UIMan.SetSDebugText(updateCount.ToString("D5") + " BG" + " is going to be destroyed in 5");
        yield return(new WaitForSeconds(1));

        UIMan.SetSDebugText(updateCount.ToString("D5") + " BG" + " is going to be destroyed in 4");
        yield return(new WaitForSeconds(1));

        UIMan.SetSDebugText(updateCount.ToString("D5") + " BG" + " is going to be destroyed in 3");
        yield return(new WaitForSeconds(1));

        UIMan.SetSDebugText(updateCount.ToString("D5") + " BG" + " is going to be destroyed in 2");
        yield return(new WaitForSeconds(1));

        UIMan.SetSDebugText(updateCount.ToString("D5") + " BG" + " is going to be destroyed in 1");
        yield return(new WaitForSeconds(1));

        UIMan.SetPDebugText("Minimap");
        UIMan.AlingPDTCenter();
        UIMan.SetSDebugText("");
        BiomeGenerator script = GetComponent <BiomeGenerator>();

        Destroy(script);
    }
Esempio n. 16
0
 public FlatDebugTerrain(BiomeGenerator biomeGenerator)
     : base(biomeGenerator)
 {
 }
Esempio n. 17
0
 /// <summary>
 /// Creates a new biomed terrain instance with given biome generator.
 /// </summary>
 /// <param name="biomeGenerator"><see cref="BiomeGenerator"/></param>
 public BiomedTerrain(BiomeGenerator biomeGenerator)
 {
     this.BiomeGenerator = biomeGenerator;
 }
Esempio n. 18
0
 public void Start()
 {
     _biomeGenerator = GetComponent <BiomeGenerator>();
 }
Esempio n. 19
0
    public void DrawBoard(BoardNode[,] board, bool forceRedraw = false)
    {
        int width  = board.GetLength(0);
        int height = board.GetLength(1);

        bool redrawMesh    = false;
        bool redrawTexture = false;
        bool redrawDoodads = false;
        bool redrawWater   = false;

        if (lastBoardCopy == null || forceRedraw || !drawPartialUpdates)
        {
            redrawMesh    = true;
            redrawTexture = true;
            redrawDoodads = true;
            redrawWater   = true;
        }
        else if (lastBoard != null)
        {
            BoardDiffState diff = BoardDiffState.Compare(board, lastBoardCopy);

            if (!diff.hasNodeChange)
            {
                return;
            }

            redrawDoodads = true;
            redrawWater   = true;

            if (diff.hasHeightChange)
            {
                redrawMesh = true;
            }
            if (diff.hasBiomeChange)
            {
                redrawTexture = true;
            }
        }

        lastBoard = board;
        if (lastBoardCopy == null)
        {
            lastBoardCopy = new BoardNode[width, height];
        }
        if (drawPartialUpdates)
        {
            Array.Copy(board, lastBoardCopy, width * height);
        }

        float[,] heightMap = GenerateHeightMap(board);
        Biome[,] biomeMap  = BiomeGenerator.GenerateBiomeData(board);
        Color[] colorMap = GenerateBiomeColorMap(board, heightMap, biomeMap);

        if (redrawMesh)
        {
            // The cubes rendered in DrawBoardCubes are added to the doodads list, so that call
            // needs to happen after that list has been cleared.
            if (!drawTerrainAsCubes)
            {
                DrawBoardMesh(heightMap, colorMap);
            }
        }

        if (redrawTexture)
        {
            DrawBoardTexture(board, colorMap);
        }

        if (redrawDoodads)
        {
            foreach (GameObject obj in doodads)
            {
                Destroy(obj);
            }
            doodads.Clear();

            if (drawTerrainAsCubes)
            {
                meshFilter.mesh       = null;
                bottomMeshFilter.mesh = null;
                DrawBoardCubes(heightMap, colorMap);
            }
            else

            if (drawBiomeDoodads)
            {
                DrawBiomeDoodads(heightMap, biomeMap);
            }

            if (drawBiomeClouds)
            {
                DrawBiomeClouds(board, heightMap);
            }
        }

        if (redrawWater)
        {
            if (waterCube != null)
            {
                float waterLevel = GetWaterLevel(board);
                waterCube.transform.localScale    = new Vector3(width - 1 + 2 * borderSize, waterLevel, height - 1 + 2 * borderSize);
                waterCube.transform.localPosition = new Vector3(0, waterLevel / 2 - waterLevelOffset, 0);
            }
        }
    }
Esempio n. 20
0
 public MountainousTerrain(BiomeGenerator biomeGenerator)
     : base(biomeGenerator)
 {
 }
Esempio n. 21
0
 public ValleyTerrain(BiomeGenerator biomeGenerator)
     : base(biomeGenerator)
 {
 }
Esempio n. 22
0
 public TerrainShape(TextAsset biomesJSON)
 {
     biomeGenerator = new BiomeGenerator(biomesJSON);
     biomeGenerator.GenerateBiomes();
 }