Example #1
0
    private void Update()
    {
        viewerPosition = new Vector2(viewer.position.x, viewer.position.z);
        UpdateVisibleChunks();

        if (chunkRedrawQueue.Count > 0)
        {
            ChunkRedrawInfo redrawInfo = chunkRedrawQueue [0];
            Texture2D       texture    = TextureGenerator.GenerateTextureFromColorMap(redrawInfo.colours, chunkSize + 1, chunkSize + 1);
            redrawInfo.chunk.RedrawTexture(texture);
            chunkRedrawQueue.Remove(redrawInfo);
        }
    }
Example #2
0
 public void RedrawAllTextures()
 {
     foreach (KeyValuePair <Vector2, TerrainChunk> kvp in terrainChunkDictionary)
     {
         TerrainChunk chunk       = kvp.Value;
         ThreadStart  threadStart = delegate {
             MapData         mapData    = chunk.GenerateMapData();
             ChunkRedrawInfo redrawInfo = new ChunkRedrawInfo(chunk, mapData.colorMap);
             lock (chunkRedrawQueue) {
                 chunkRedrawQueue.Add(redrawInfo);
             }
         };
         new Thread(threadStart).Start();
     }
     for (int i = 1; i < chunkRedrawQueue.Count; i++)
     {
         ChunkRedrawInfo info = chunkRedrawQueue [i];
         if (info.chunk != null && info.chunk.IsVisible())
         {
             chunkRedrawQueue.Remove(info);
             chunkRedrawQueue.Insert(0, info);
         }
     }
 }