예제 #1
0
    /// <summary>
    /// This function is run every physics update, and in it we collect any generated mapData and meshData from the other thread and use it's
    ///data in the map
    /// </summary>
    private void FixedUpdate()
    {
        //If there is data in the mapData thread queue, get all of it
        if (mapDataThreadInfoQueue.Count > 0)
        {
            //iterate over all the data
            for (int i = 0; i < mapDataThreadInfoQueue.Count; i++)
            {
                //get the data
                MapThreadInfo <MapData> mapThreadInfo = mapDataThreadInfoQueue.Dequeue();
                //call the function tht was stored in the thread data with the variable that was computed in the other thread as a parameter,
                //the supplied callBack Action must only take in one parameter of the correct type for this to work
                mapThreadInfo.callBack(mapThreadInfo.parameter);
            }
        }

        //Do the exact same again for meshData
        if (meshDataThreadInfoQueue.Count > 0)
        {
            for (int i = 0; i < meshDataThreadInfoQueue.Count; i++)
            {
                MapThreadInfo <MeshData> meshThreadInfo = meshDataThreadInfoQueue.Dequeue();
                meshThreadInfo.callBack(meshThreadInfo.parameter);
            }
            textureData.updateMeshHeights(terrainMaterial, terrainData.minHeight, terrainData.maxHeight);
        }

        //textureData.updateMeshHeights(terrainMaterial, terrainData.minHeight, terrainData.maxHeight);
    }
예제 #2
0
    void Update()
    {
        if (mapDataThreadInfoQueue.Count > 0)
        {
            for (int i = 0; i < mapDataThreadInfoQueue.Count; i++)
            {
                MapThreadInfo <MapData> threadInfo = mapDataThreadInfoQueue.Dequeue();
                threadInfo.callBack(threadInfo.parameter);
            }
        }

        if (meshDataThreadInfoQueue.Count > 0)
        {
            for (int i = 0; i < meshDataThreadInfoQueue.Count; i++)
            {
                MapThreadInfo <MeshData> threadInfo = meshDataThreadInfoQueue.Dequeue();
                threadInfo.callBack(threadInfo.parameter);
            }
        }
    }
    private void Update()
    {
        if (_mapThreadInfoQueue.Count > 0)
        {
            for (int i = 0; i < _mapThreadInfoQueue.Count; i++)
            {
                MapThreadInfo <MapData> _threadInfo = _mapThreadInfoQueue.Dequeue();
                _threadInfo.callBack(_threadInfo.parameter);
            }
        }

        if (_meshThreadInfoQueue.Count > 0)
        {
            for (int i = 0; i < _meshThreadInfoQueue.Count; i++)
            {
                MapThreadInfo <MeshData> _threadInfo = _meshThreadInfoQueue.Dequeue();
                _threadInfo.callBack(_threadInfo.parameter);
            }
        }
    }
예제 #4
0
 void Update()
 {
     //if the map thread info queue has something in it (greater than 1)
     if (mapThreadInfoQueue.Count > 0)
     {
         //loop through the elements
         for (int i = 0; i < mapThreadInfoQueue.Count; i++)
         {
             MapThreadInfo <MapData> threadInfo = mapThreadInfoQueue.Dequeue();
             threadInfo.callBack(threadInfo.parameter);
         }
     }
     //if the mesh thread info queue has something in it (greater than 1)
     if (meshThreadInfoQueue.Count > 0)
     {
         //loop through the elements
         for (int i = 0; i < meshThreadInfoQueue.Count; i++)
         {
             MapThreadInfo <MeshData> threadInfo = meshThreadInfoQueue.Dequeue();
             threadInfo.callBack(threadInfo.parameter);
         }
     }
 }
예제 #5
0
    void Update()
    {
        /*
         * if (viewer.transform.hasChanged)
         * {
         *  print("Changed");
         *  viewer.transform.hasChanged = false;
         *  removeObjectsForNewGeneration();
         *  locUpdate = viewer.transform.position;
         *      genDone = false;
         *      if (!genDone)
         *      {
         *
         *      float[,] noiseMap = noisey;
         *
         *          for (int y = 0; y < mapChunkSize; y++)
         *          {
         *              for (int x = 0; x < mapChunkSize; x++)
         *              {
         *                  float currentHeight = noiseMap[x, y];
         *                  if (currentHeight >= 0.45 && currentHeight <= 0.6)
         *                  {
         *                      float highestNoiseHeight = 0f;
         *                      if (x != 0 && y != 0 && x < mapChunkSize - 1 && y < mapChunkSize - 1)
         *                      {
         *                          highestNoiseHeight = Mathf.Max(currentHeight, noiseMap[x - 1, y - 1], noiseMap[x, y + 1], noiseMap[x, y - 1], noiseMap[x + 1, y + 1]);
         *                      }
         *
         *                      if (highestNoiseHeight == currentHeight)
         *                      {
         *                          float heightToUse = currentHeight;
         *
         *                          float xToUse = x;
         *                          float yToUse = y;
         *                          pos = new Vector3((xToUse * 10) - (mapChunkSize * 5), (heightToUse * 100) - 30, (yToUse * 10) - (mapChunkSize * 5));
         *                          pos = Vector3.Reflect(pos, Vector3.forward);
         *
         *                          Instantiate(tree, pos, new Quaternion(), extraStore.transform);
         *
         *                      }
         *                      else if (x >= mapChunkSize - 1 && y >= mapChunkSize - 1)
         *                      {
         *                          break;
         *                      }
         *                  }
         *                  if (currentHeight >= 0.85f)
         *                  {
         *                      float highestNoiseHeight = 0f;
         *                      if (x != 0 && y != 0 && x < mapChunkSize - 1 && y < mapChunkSize - 1)
         *                      {
         *                          highestNoiseHeight = Mathf.Max(currentHeight, noiseMap[x - 1, y - 1], noiseMap[x, y + 1], noiseMap[x, y - 1], noiseMap[x + 1, y + 1]);
         *                      }
         *
         *                      if (highestNoiseHeight == currentHeight)
         *                      {
         *                          float heightToUse = currentHeight;
         *                          float xToUse = x;
         *                          float yToUse = y;
         *                          pos = new Vector3((xToUse * 10) - (mapChunkSize * 5), heightToUse * meshHeightMultiplier, (yToUse * 10) - (mapChunkSize * 5));
         *                          pos = Vector3.Reflect(pos, Vector3.forward);
         *                          Instantiate(snowParticleEffect, pos, new Quaternion(), extraStore.transform);
         *                          snowParticleEffect.Play();
         *                      }
         *                      else if (x >= mapChunkSize - 1 && y >= mapChunkSize - 1)
         *                      {
         *                          break;
         *                      }
         *
         *                  }
         *              }
         *          }
         *
         *          //extraStore.transform.position = viewer.transform.position;
         *      }
         *      genDone = true;
         * }
         */

        /***
         * if (Input.GetKeyDown(KeyCode.Z))
         * {
         *  if (drawMode == DrawMode.Mesh)
         *  {
         *      drawMode = DrawMode.HeatMap;
         *
         *  }
         *  else
         *  {
         *      drawMode = DrawMode.Mesh;
         *  }
         *
         * }
         *
         * if (Input.GetKeyDown(KeyCode.N))
         * {
         *  if (drawMode == DrawMode.Mesh)
         *  {
         *
         *      noiseScale = UnityEngine.Random.Range(200, 450);
         *      lacunarity = UnityEngine.Random.Range(2, 2.5f);
         *      meshHeightMultiplier = UnityEngine.Random.Range(100, 200);
         *      octaves = UnityEngine.Random.Range(5, 6);
         *      persistence = UnityEngine.Random.Range(0.0f, 1.0f);
         *      if (transform.childCount > 0)
         *      {
         *          removeObjectsForNewGeneration();
         *      }
         *      DrawMapInEditor();
         *  }
         *  else if (drawMode == DrawMode.HeatMap)
         *  {
         *      GenerateHeatMap();
         *  }
         *
         * }
         *
         * if (Input.GetKeyDown(KeyCode.S))
         * {
         *
         *  seed--;
         *  if (transform.childCount > 0)
         *  {
         *      removeObjectsForNewGeneration();
         *  }
         *  DrawMapInEditor();
         *
         * }
         * else if (Input.GetKeyDown(KeyCode.W))
         * {
         *  seed++;
         *  if (transform.childCount > 0)
         *  {
         *      removeObjectsForNewGeneration();
         *  }
         *  DrawMapInEditor();
         * }
         *
         * if (Input.GetKeyDown(KeyCode.F))
         * {
         *  offset.x -= 0.1f;
         *  if (transform.childCount > 0)
         *  {
         *      removeObjectsForNewGeneration();
         *  }
         *  DrawMapInEditor();
         * }
         * else if (Input.GetKeyDown(KeyCode.H))
         * {
         *  offset.x += 0.1f;
         *  if (transform.childCount > 0)
         *  {
         *      removeObjectsForNewGeneration();
         *  }
         *  DrawMapInEditor();
         * }
         * else if (Input.GetKeyDown(KeyCode.T))
         * {
         *  offset.y -= 0.1f;
         *  if (transform.childCount > 0)
         *  {
         *      removeObjectsForNewGeneration();
         *  }
         *  DrawMapInEditor();
         * }
         * else if (Input.GetKeyDown(KeyCode.G))
         * {
         *  offset.y += 0.1f;
         *  if (transform.childCount > 0)
         *  {
         *      removeObjectsForNewGeneration();
         *  }
         *  DrawMapInEditor();
         * }
         *
         * if (Input.GetKeyDown(KeyCode.D))
         * {
         *  if (levelOfDetail == 6)
         *  {
         *      levelOfDetail = 6;
         *  }
         *  else
         *  {
         *      levelOfDetail++;
         *      if (transform.childCount > 0)
         *      {
         *          removeObjectsForNewGeneration();
         *      }
         *      DrawMapInEditor();
         *  }
         * }
         * else if (Input.GetKeyDown(KeyCode.E))
         * {
         *  if (levelOfDetail == 0)
         *  {
         *      levelOfDetail = 0;
         *  }
         *  else
         *  {
         *      levelOfDetail--;
         *      if (transform.childCount > 0)
         *      {
         *          removeObjectsForNewGeneration();
         *      }
         *      DrawMapInEditor();
         *  }
         * }
         ***/

        if (mapDataThreadInfoQueue.Count > 0)
        {
            for (int i = 0; i < mapDataThreadInfoQueue.Count; i++)
            {
                MapThreadInfo <MapData> threadInfo = mapDataThreadInfoQueue.Dequeue();
                threadInfo.callBack(threadInfo.parameter);
            }
        }

        if (meshDataThreadInfoQueue.Count > 0)
        {
            for (int i = 0; i < meshDataThreadInfoQueue.Count; i++)
            {
                MapThreadInfo <MeshData> threadInfo = meshDataThreadInfoQueue.Dequeue();
                threadInfo.callBack(threadInfo.parameter);
            }
        }
    }