예제 #1
0
 public void AddColumnMesh(GeneratedDataInfo <MeshData[]> meshData)
 {
     if (_columns.TryGetValue(meshData.coord.XZ(), out ChunkColumn column))
     {
         column.SetMeshData(meshData);
     }
 }
예제 #2
0
        public void AddColumn(GeneratedDataInfo <MapData[]> mapData)
        {
            ChunkColumn column = _columnsForRecycling.Dequeue();

            column.SetMapData(mapData);
            _columns.Add(mapData.coord.XZ(), column);
        }
예제 #3
0
 public void SetMeshData(GeneratedDataInfo <MeshData[]> meshData)
 {
     for (int i = 0; i < _worldHeight; i++)
     {
         Chunks[i].SetMesh(meshData.data[i]);
     }
     HasMesh = true;
 }
예제 #4
0
 public void SetMapData(GeneratedDataInfo <MapData[]> mapData)
 {
     Coord = new Vector2Int(mapData.coord.x, mapData.coord.z);
     for (int i = 0; i < _worldHeight; i++)
     {
         Chunks[i].SetBlocks(mapData.data[i].blocks);
         Chunks[i].SetCoord(new Vector3Int(mapData.coord.x, i, mapData.coord.z));
     }
     HasMesh = false;
 }
예제 #5
0
        private void OnColumnMeshDataRecieved(GeneratedDataInfo <MeshData[]> meshData)
        {
            Vector2Int coord = meshData.coord.XZ();

            if (ExistingChunks.TryGetValue(coord, out ChunkColumn column))
            {
                column.SetMeshData(meshData);
                column.SetVisibility(IsVisible(coord));
            }
        }
예제 #6
0
        // Recieves map data from generator, assignes it for recycled chunk and triggers mesh generation
        private void OnMapDataReceived(GeneratedDataInfo <MapData[]> mapData)
        {
            Vector2Int coord = new Vector2Int(mapData.coord.x, mapData.coord.z);

            if (IsInsideBorders(coord) && !ExistingChunks.ContainsKey(coord))
            {
                ExistingChunks.AddColumn(mapData);

                TriggerMeshGeneration(coord);
            }
        }
예제 #7
0
 public void ManageRequests()
 {
     // Return generated data
     if (_mapDataQueue.Count > 0)
     {
         for (int i = 0; i < _mapDataQueue.Count; i++)
         {
             GeneratedDataInfo <MapData[]> mapData = _mapDataQueue.Dequeue();
             _dataCallback(mapData);
         }
     }
 }
예제 #8
0
        // Recieves mesh from generator and requests another one if chunk is dirty
        private void OnChunkMeshDataReceived(GeneratedDataInfo <MeshData> meshData)
        {
            if (ExistingChunks.TryGetValue(meshData.coord, out Chunk chunk))
            {
                chunk.SetMesh(meshData.data);

                if (chunk.IsDirty)
                {
                    RequestMesh(chunk);
                    chunk.IsDirty = (false);
                }
                else
                {
                    chunk.IsWaitingMesh = (false);
                }
            }
        }