示例#1
0
    // Base constructor
    public RoadGenerator(Vector2 origin, Vector2 destination, float maxSlope, float bridgePenalty)
    {
        // Obtain all extra needed information
        this.resolution = TerrainChunk.resolution;
        this.mapSize = TerrainCharacteristicsManager.Instance.mapSize;
        this.terrainAreas = TerrainCharacteristicsManager.Instance.getTerrainAreasDeepCopy();
        object map = TerrainCharacteristicsManager.Instance.getChunkMap (new Vector2 (-1, -1));
        if (map is Color[][])
            this.map = (Color[][])map;
        else if (map is Color) // Optimized if only one color
            this.optimizedTerrainArea = terrainAreas[(Color)map];
        this.waterBodies = UpperLayersManager.Instance.getWaterBodiesProcessedLayer ();

        this.maxSlope = maxSlope;
        this.bridgePenalty = bridgePenalty;
        origin = new Vector2 (Mathf.Round (origin.x * resolution), Mathf.Round (origin.y * resolution));
        destination = new Vector2 (Mathf.Round (destination.x * resolution), Mathf.Round (destination.y * resolution));
        openList = new SortedList<float, List<Vector2>> ();
        openNodes = new Dictionary<Vector2, ANode> ();
        float originY = getHeightValue (origin);
        Vector3 origin3 = new Vector3 (origin.x, Mathf.Abs(originY), origin.y);
        this.destination = new Vector3 (destination.x, Mathf.Abs(getHeightValue (destination)), destination.y);
        closedNodes = new Dictionary<Vector2, ANode> ();

        if (isInsideMapBoundaries(origin)) {
            ANode originNode = new ANode (origin3, originY < 0, this.destination, null, bridgePenalty);
            openList [Vector3.Distance (origin3, destination)] = new List<Vector2> () { origin };
            openNodes [origin] = originNode;
        }
    }
示例#2
0
 // Base constructor
 public WaterBodyGenerator(Vector2 origin)
 {
     this.resolution = TerrainChunk.resolution;
     this.mapSize = TerrainCharacteristicsManager.Instance.mapSize;
     this.terrainAreas = TerrainCharacteristicsManager.Instance.getTerrainAreasDeepCopy();
     object map = TerrainCharacteristicsManager.Instance.getChunkMap (new Vector2 (-1, -1));
     if (map is Color[][])
         this.map = (Color[][])map;
     else if (map is Color) // Optimized if only one color
         this.optimizedTerrainArea = terrainAreas[(Color)map];
 }
    public ValueCalculationThreadedJob(Vector2 chunkID, Vector3[] vertices)
    {
        this.chunkID = chunkID;
        this.vertices = vertices;

        this.resolution = TerrainChunk.resolution;
        this.terrainAreas = TerrainCharacteristicsManager.Instance.getTerrainAreasDeepCopy();
        object chunkMap = TerrainCharacteristicsManager.Instance.getChunkMap (chunkID);
        if (chunkMap is Color[][])
            this.chunkMap = (Color[][])chunkMap;
        else if (chunkMap is Color) // Optimized if only one color
            this.optimizedTerrainArea = terrainAreas[(Color)chunkMap];
    }
示例#4
0
    public override void InitializeAgent()
    {
        base.InitializeAgent();
        agent    = GameObject.FindGameObjectWithTag("Agent");
        animator = GetComponent <Animator>();

        terrainArea = GetComponentInParent <TerrainArea>();
        rigidbody   = GetComponent <Rigidbody>();

        //dict = new Dictionary<string, string>();
        //dict.Add("TrashYellow", "TrashBinYellow");
        //dict.Add("TrashRed", "TrashBinRed");
        //dict.Add("TrashGreen", "TrashBinGreen");
        //dict.Add("TrashBlue", "TrashBinBlue");
    }
        public void TerrainUpdated(TerrainArea heightArea, TerrainArea surfaceArea, TerrainArea zoneArea)
        {
            float minX = zoneArea.m_min.x;
            float minZ = zoneArea.m_min.z;
            float maxX = zoneArea.m_max.x;
            float maxZ = zoneArea.m_max.z;
            //begin mod
            int num1 = Mathf.Max((int)(((double)minX - 46.0) / 64.0 + HALFGRID), 0);
            int num2 = Mathf.Max((int)(((double)minZ - 46.0) / 64.0 + HALFGRID), 0);
            int num3 = Mathf.Min((int)(((double)maxX + 46.0) / 64.0 + HALFGRID), GRIDSIZE - 1);
            int num4 = Mathf.Min((int)(((double)maxZ + 46.0) / 64.0 + HALFGRID), GRIDSIZE - 1);

            //end mod
            for (int index1 = num2; index1 <= num4; ++index1)
            {
                for (int index2 = num1; index2 <= num3; ++index2)
                {
                    //begin mod
                    ushort blockID = this.m_zoneGrid[index1 * GRIDSIZE + index2];
                    //end mod
                    int num5 = 0;
                    while ((int)blockID != 0)
                    {
                        Vector3 vector3 = this.m_blocks.m_buffer[(int)blockID].m_position;
                        if ((double)Mathf.Max(Mathf.Max(minX - 46f - vector3.x, minZ - 46f - vector3.z), Mathf.Max((float)((double)vector3.x - (double)maxX - 46.0), (float)((double)vector3.z - (double)maxZ - 46.0))) < 0.0)
                        {
                            this.m_blocks.m_buffer[(int)blockID].ZonesUpdated(blockID, minX, minZ, maxX, maxZ);
                        }
                        blockID = this.m_blocks.m_buffer[(int)blockID].m_nextGridBlock;
                        if (++num5 >= 49152)
                        {
                            CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace);

                            break;
                        }
                    }
                }
            }
        }
		private static void TerrainUpdated(TreeManager tm, TerrainArea heightArea, TerrainArea surfaceArea, TerrainArea zoneArea)
		{
			unsafe
			{
				float mMin = surfaceArea.m_min.x;
				float single = surfaceArea.m_min.z;
				float mMax = surfaceArea.m_max.x;
				float mMax1 = surfaceArea.m_max.z;
				int num = Mathf.Max((int)(((double)mMin - 8) / 32 + 270), 0);
				int num1 = Mathf.Max((int)(((double)single - 8) / 32 + 270), 0);
				int num2 = Mathf.Min((int)(((double)mMax + 8) / 32 + 270), 539);
				int num3 = Mathf.Min((int)(((double)mMax1 + 8) / 32 + 270), 539);
				for (int i = num1; i <= num3; i++)
				{
					for (int j = num; j <= num2; j++)
					{
						uint mTreeGrid = tm.m_treeGrid[i * 540 + j];
						int num4 = 0;
						while (mTreeGrid != 0)
						{
							Vector3 position = tm.m_trees.m_buffer[mTreeGrid].Position;
							if ((double)Mathf.Max(Mathf.Max(mMin - 8f - position.x, single - 8f - position.z), Mathf.Max((float)((double)position.x - (double)mMax - 8), (float)((double)position.z - (double)mMax1 - 8))) < 0)
							{
								tm.m_trees.m_buffer[mTreeGrid].TerrainUpdated(mTreeGrid, mMin, single, mMax, mMax1);
							}
							mTreeGrid = tm.m_trees.m_buffer[mTreeGrid].m_nextGridTree;
							int num5 = num4 + 1;
							num4 = num5;
							if (num5 < LimitTreeManager.Helper.TreeLimit)
							{
								continue;
							}
							CODebugBase<LogChannel>.Error(LogChannel.Core, string.Concat("Invalid list detected!\n", Environment.StackTrace));
							break;
						}
					}
				}
			}
		}
        public static void Postfix(TerrainArea heightArea, TerrainArea surfaceArea, TerrainArea zoneArea)
        {
            float minX = heightArea.m_min.x;
            float minZ = heightArea.m_min.z;
            float maxX = heightArea.m_max.x;
            float maxZ = heightArea.m_max.z;

            int minGridX = Mathf.Max((int)(((double)minX - 8.0) / 64.0 + 135.0), 0);
            int minGridZ = Mathf.Max((int)(((double)minZ - 8.0) / 64.0 + 135.0), 0);
            int maxGridX = Mathf.Min((int)(((double)maxX + 8.0) / 64.0 + 135.0), 269);
            int maxGridZ = Mathf.Min((int)(((double)maxZ + 8.0) / 64.0 + 135.0), 269);

            for (int index1 = minGridZ; index1 <= maxGridZ; ++index1)
            {
                for (int index2 = minGridX; index2 <= maxGridX; ++index2)
                {
                    int gridKey = index1 * 270 + index2;
                    List <PropContainer> list = PropUnlimiterManager.instance.GetPropsInGrid(gridKey);

                    if (list != null)
                    {
                        for (int i = 0; i < list.Count; i++)
                        {
                            PropInstance instance = list[i].propInstance;
                            instance.TerrainUpdated(0, minX, minZ, maxX, maxZ);
                            Vector3 position = instance.Position;
                            position.y = TerrainManager.instance.SampleDetailHeight(position);
                            ushort num = (ushort)Mathf.Clamp(Mathf.RoundToInt(position.y * 64f), 0, (int)ushort.MaxValue);
                            instance.m_posY      = num;
                            list[i].propInstance = instance;
                            PropManager.instance.UpdateProp(0);
                            PropManager.instance.UpdatePropRenderer(0, true);
                        }
                    }
                }
            }
        }
示例#8
0
文件: Noise.cs 项目: parmandorc/PCG
    // Returns the height calculation parameters for a given point in [0,1] coordinates for the provided chunkMap
    public static TerrainArea getParameters(float x, float y, Color[][] chunkMap, Dictionary<Color, TerrainArea> terrainAreas)
    {
        TerrainArea parameters;

        // Change coords from [0,1] scale to [0, chunkResolution]
        x = Mathf.Lerp (0, chunkMap.Length - 2, x);
        y = Mathf.Lerp (0, chunkMap [0].Length - 2, y);

        // Get coords for the terrain area for interpolation
        int xCoord = Mathf.FloorToInt(x - 0.5f) + 1;
        int yCoord = Mathf.FloorToInt(y - 0.5f) + 1;

        // Get color keys for the 4 areas
        Color colorKey00 = chunkMap[xCoord][yCoord];
        Color colorKey10 = chunkMap[xCoord + 1][yCoord];
        Color colorKey01 = chunkMap[xCoord][yCoord + 1];
        Color colorKey11 = chunkMap[xCoord + 1][yCoord + 1];

        if (!terrainAreas.ContainsKey (colorKey00) || !terrainAreas.ContainsKey (colorKey01) ||
            !terrainAreas.ContainsKey (colorKey10) || !terrainAreas.ContainsKey (colorKey11))
            Debug.Log ("EXCEPTION: Color key not existent!");

        // Optimization: 4 areas are the same
        if (colorKey00 == colorKey01 && colorKey00 == colorKey10 && colorKey00 == colorKey11) {
            TerrainArea terrainArea = terrainAreas [colorKey00];
            parameters = new TerrainArea(terrainArea.averageHeight, terrainArea.flatness, terrainArea.roughness, terrainArea.material);

        } else {

            // Get the 4 areas
            TerrainArea terrainArea00 = terrainAreas [colorKey00];
            TerrainArea terrainArea10 = terrainAreas [colorKey10];
            TerrainArea terrainArea01 = terrainAreas [colorKey01];
            TerrainArea terrainArea11 = terrainAreas [colorKey11];

            // Get interpolated parameters
            float deltaX = x - xCoord + 0.5f;
            float deltaY = y - yCoord + 0.5f;
            float averageHeight = Mathf.Lerp (Mathf.Lerp (terrainArea00.averageHeight, terrainArea10.averageHeight, deltaX),
                Mathf.Lerp (terrainArea01.averageHeight, terrainArea11.averageHeight, deltaX), deltaY);
            float flatness = Mathf.Lerp (Mathf.Lerp (terrainArea00.flatness, terrainArea10.flatness, deltaX),
                Mathf.Lerp (terrainArea01.flatness, terrainArea11.flatness, deltaX), deltaY);
            float roughness = Mathf.Lerp (Mathf.Lerp (terrainArea00.roughness, terrainArea10.roughness, deltaX),
                Mathf.Lerp (terrainArea01.roughness, terrainArea11.roughness, deltaX), deltaY);
            parameters = new ExtendedTerrainArea(averageHeight, flatness, roughness,
                terrainArea00.material.Item2, terrainArea10.material.Item2, terrainArea01.material.Item2, terrainArea11.material.Item2,
                deltaX, deltaY);
        }

        return parameters;
    }
 public void TerrainUpdated(TerrainArea heightArea, TerrainArea surfaceArea, TerrainArea zoneArea)
 {
     var zm = ZoneManager.instance;
     float x = zoneArea.m_min.x;
     float z = zoneArea.m_min.z;
     float x2 = zoneArea.m_max.x;
     float z2 = zoneArea.m_max.z;
     int num = Mathf.Max((int)((x - 46f) / 64f + HALFGRID), 0);
     int num2 = Mathf.Max((int)((z - 46f) / 64f + HALFGRID), 0);
     int num3 = Mathf.Min((int)((x2 + 46f) / 64f + HALFGRID), GRIDSIZE - 1);
     int num4 = Mathf.Min((int)((z2 + 46f) / 64f + HALFGRID), GRIDSIZE - 1);
     for (int i = num2; i <= num4; i++)
     {
         for (int j = num; j <= num3; j++)
         {
             ushort num5 = zoneGrid[i * GRIDSIZE + j];
             int num6 = 0;
             while (num5 != 0)
             {
                 Vector3 position = zm.m_blocks.m_buffer[(int)num5].m_position;
                 float num7 = Mathf.Max(Mathf.Max(x - 46f - position.x, z - 46f - position.z), Mathf.Max(position.x - x2 - 46f, position.z - z2 - 46f));
                 if (num7 < 0f)
                 {
                     zm.m_blocks.m_buffer[(int)num5].ZonesUpdated(num5, x, z, x2, z2);
                 }
                 num5 = zm.m_blocks.m_buffer[(int)num5].m_nextGridBlock;
                 if (++num6 >= 32768)
                 {
                     CODebugBase<LogChannel>.Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);
                     break;
                 }
             }
         }
     }
 }