private void GenerateRoads(HeightMap <ushort> heightMap) { //var generator = new RoadGenerator(2, heightMap); var generator = new RoadGenerator <double>(2, () => new RoadCellMapDouble(heightMap, 8)); generator.Generate(); generator.Save(BaseDirectory); }
// Update is called once per frame RoadGenerator nextRoad(bool newLevel = false, bool endPath = false) { if (firstRoad) { nextDirection = Direction.Straight; firstRoad = false; } int space = 2 + Hardness(); hasSpace = Random.Range(0, space) < 2 ? false : true; //random hasSpace nextLength = Random.Range((newLevel || endPath) ? (CurrentLevel < 5 ? 8 : 5) : (CurrentLevel < 5 ? 4 : 3), CurrentLevel < 5 ? 10 : 5); // random length GameObject obj = (GameObject)Instantiate(roadPrefap, nextPostiton, Quaternion.identity); //get the road RoadGenerator road = obj.GetComponent <RoadGenerator>(); bool longSpace = hasSpace ? Random.Range(0, 2) == 0 : false; road.Map = this; road.direction = nextDirection; road.length = nextLength; calculateNextPosition(longSpace); road.Generate(hasSpace, longSpace, endPath, newLevel); //next spawm position int changeDirectionRate = 2 + Hardness(); if (Random.Range(0, changeDirectionRate) == 0) { nextDirection = convertIntToDirection(Random.Range(0, 3)); // random direction } else { int next = (Random.Range(0, 3)); while (next == (int)nextDirection) { next = (Random.Range(0, 3)); } nextDirection = convertIntToDirection(next); } //nextDirection = convertIntToDirection(Random.Range(0, 3)); // random direction obj.tag = nextDirection.ToString(); return(road); }
public void BuildRoads(int gridPosX, int gridPosY) { if (Input.GetMouseButtonDown(0)) { //Start generation _roadGenerator.Start(); _mouseDownPosX = gridPosX; _mouseDownPosY = gridPosY; } if (Input.GetMouseButton(0)) { //Generating _roadGenerator.ClearSavedRoads(); if (_roadGenerator.CanCreateRoad(gridPosX, gridPosY)) { Vector2Int startPos = new Vector2Int(_mouseDownPosX, _mouseDownPosY); Vector2Int endPos = new Vector2Int(gridPosX, gridPosY); List <Vector2Int> path = Map.GetShortestPath(startPos, endPos); foreach (Vector2Int road in path) { _roadGenerator.Generate(road.x, road.y); } } } if (Input.GetMouseButtonUp(0)) { //End generation _roadGenerator.End(); } if (Input.GetMouseButtonDown(1)) { //Cancel generation _roadGenerator.Cancel(); } }
public void ReGenerate() { Generator.Generate(); Layout(Generator.CurrentBlock); }
private void Start() { roadGenerator.Generate(); }
IEnumerator Coroutine() { Utils.ClearMemory(); if (terrainData == null || terrain == null) { CreateTerrain(); yield return(null); } heights = terrainData.GetHeights(0, 0, terrainData.heightmapWidth, terrainData.heightmapHeight); alphas = terrainData.GetAlphamaps(0, 0, terrainData.alphamapWidth, terrainData.alphamapHeight); Vector3 position = terrain.transform.position; float waterRelativeHeight = water.position.y / size.y; //Generate heights terrainGenerator.SetupConfig(); bool terrainHeights1 = true; ThreadPool.QueueUserWorkItem((o) => { terrainGenerator.GenerateHeights(heights, 0, 4); terrainHeights1 = false; }); bool terrainHeights2 = true; ThreadPool.QueueUserWorkItem((o) => { terrainGenerator.GenerateHeights(heights, 1, 4); terrainHeights2 = false; }); bool terrainHeights3 = true; ThreadPool.QueueUserWorkItem((o) => { terrainGenerator.GenerateHeights(heights, 2, 4); terrainHeights3 = false; }); bool terrainHeights4 = true; ThreadPool.QueueUserWorkItem((o) => { terrainGenerator.GenerateHeights(heights, 3, 4); terrainHeights4 = false; }); while (terrainHeights1 || terrainHeights2 || terrainHeights3 || terrainHeights4) { yield return(null); } //create roads bool road = true; ThreadPool.QueueUserWorkItem((o) => { roadGenerator.Generate(heights, size, position, waterRelativeHeight); road = false; }); //paint textures bool terrainTextures = true; ThreadPool.QueueUserWorkItem((o) => { terrainGenerator.PrepareTextures(heights, waterRelativeHeight); terrainTextures = false; }); while (terrainTextures) { yield return(null); } bool terrainTextures1 = true; ThreadPool.QueueUserWorkItem((o) => { terrainGenerator.GenerateTextures(heights, alphas, 0, 4); terrainTextures1 = false; }); bool terrainTextures2 = true; ThreadPool.QueueUserWorkItem((o) => { terrainGenerator.GenerateTextures(heights, alphas, 1, 4); terrainTextures2 = false; }); bool terrainTextures3 = true; ThreadPool.QueueUserWorkItem((o) => { terrainGenerator.GenerateTextures(heights, alphas, 2, 4); terrainTextures3 = false; }); bool terrainTextures4 = true; ThreadPool.QueueUserWorkItem((o) => { terrainGenerator.GenerateTextures(heights, alphas, 3, 4); terrainTextures4 = false; }); //level roads while (road) { yield return(null); } bool roadHeights = true; ThreadPool.QueueUserWorkItem((o) => { roadGenerator.DrawRoadHeights(heights, size, position, alphas.GetLength(0)); roadHeights = false; }); //paint roads while (road || terrainTextures1 || terrainTextures2 || terrainTextures3 || terrainTextures4) { yield return(null); } bool roadTextures = true; ThreadPool.QueueUserWorkItem((o) => { roadGenerator.DrawRoadTextures(alphas, size, position); roadTextures = false; }); while (roadTextures || roadHeights) { yield return(null); } terrainData.SetHeights(0, 0, heights); terrainData.SetAlphamaps(0, 0, alphas); terrain.Flush(); yield return(null); reflection.RenderProbe(); Utils.ClearMemory(); if (onGenerated != null) { onGenerated(); } }
public void FoliageGenerationCallback(Voronoi sourceVoronoi, Generation world) { roadGenerator.Generate(sourceVoronoi, world, zone); }