예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (_rendered && !_destroyed)
        {
            /*if (!grassEnabled && Vector3.Distance(TerrainController.Instance.newPlayerChunkPos, ChunkPosition) < maxGrassDistance)
             * {
             *  grassEnabled = true;
             *  SpawnGrass();
             * }
             * if (grassEnabled && Vector3.Distance(TerrainController.Instance.newPlayerChunkPos, ChunkPosition) > maxGrassDistance)
             * {
             *  grassEnabled = false;
             *  for (int i = 0; i < grassList.Count; i++)
             *      Destroy(grassList[i]);
             *  grassList.Clear();
             * }*/

            if (editQueue.Count > 0)
            {
                List <BlockChange> EditQueueCopy = new List <BlockChange>(editQueue);
                editQueue.Clear();
                Loom.QueueAsyncTask(TerrainController.setBlockThreadName, () =>
                {
                    lock (_lockObj)
                    {
                        List <Vector3Int> updateChunks = new List <Vector3Int>();
                        foreach (BlockChange change in EditQueueCopy)
                        {
                            Vector3Int position = change.position;
                            byte type           = change.type;
                            if (position.x == 0)
                            {
                                if (!updateChunks.Contains(new Vector3Int(chunkPosition.x - 1, chunkPosition.y, chunkPosition.z)))
                                {
                                    updateChunks.Add(new Vector3Int(chunkPosition.x - 1, chunkPosition.y, chunkPosition.z));
                                }
                            }
                            if (position.x == VoxelSettings.ChunkSizeX - 1)
                            {
                                if (!updateChunks.Contains(new Vector3Int(chunkPosition.x + 1, chunkPosition.y, chunkPosition.z)))
                                {
                                    updateChunks.Add(new Vector3Int(chunkPosition.x + 1, chunkPosition.y, chunkPosition.z));
                                }
                            }

                            if (position.y == 0)
                            {
                                if (!updateChunks.Contains(new Vector3Int(chunkPosition.x, chunkPosition.y - 1, chunkPosition.z)))
                                {
                                    updateChunks.Add(new Vector3Int(chunkPosition.x, chunkPosition.y - 1, chunkPosition.z));
                                }
                            }
                            if (position.y == VoxelSettings.ChunkSizeY - 1)
                            {
                                if (!updateChunks.Contains(new Vector3Int(chunkPosition.x, chunkPosition.y + 1, chunkPosition.z)))
                                {
                                    updateChunks.Add(new Vector3Int(chunkPosition.x, chunkPosition.y + 1, chunkPosition.z));
                                }
                            }

                            if (position.z == 0)
                            {
                                if (!updateChunks.Contains(new Vector3Int(chunkPosition.x, chunkPosition.y, chunkPosition.z - 1)))
                                {
                                    updateChunks.Add(new Vector3Int(chunkPosition.x, chunkPosition.y, chunkPosition.z - 1));
                                }
                            }
                            if (position.z == VoxelSettings.ChunkSizeZ - 1)
                            {
                                if (!updateChunks.Contains(new Vector3Int(chunkPosition.x, chunkPosition.y, chunkPosition.z + 1)))
                                {
                                    updateChunks.Add(new Vector3Int(chunkPosition.x, chunkPosition.y, chunkPosition.z + 1));
                                }
                            }
                            builder.SetBlock(position.x, position.y, position.z, new Block(type));
                        }
                        Render(true);
                        foreach (Vector3Int chunk in updateChunks)
                        {
                            pageController.UpdateChunk(chunk.x, chunk.y, chunk.z);
                        }
                    }
                });
            }
        }
    }
예제 #2
0
    // Update is called once per frame
    public void ChunkUpdate()
    {
        return;

        if (_rendered && !_destroyed)
        {
            /*if (!grassEnabled && Vector3.Distance(TerrainController.Instance.newPlayerChunkPos, ChunkPosition) < maxGrassDistance)
             * {
             *  grassEnabled = true;
             *  SpawnGrass();
             * }
             * if (grassEnabled && Vector3.Distance(TerrainController.Instance.newPlayerChunkPos, ChunkPosition) > maxGrassDistance)
             * {
             *  grassEnabled = false;
             *  for (int i = 0; i < grassList.Count; i++)
             *      Destroy(grassList[i]);
             *  grassList.Clear();
             * }*/


            if (!_treesPlaced)
            {
                System.Random rand = new System.Random();
                _treesPlaced = true;
            }

            float distance = Vector3.Distance(globalPosition, TerrainController.Instance.LODtarget);
            if (distance > (SmoothVoxelSettings.radius * SmoothVoxelSettings.MeterSizeX))
            {
                _destroyed = true;
                TerrainController.Instance.DestroyChunk(chunkPosition);
                Debug.Log("Destoying chunk");
                return;
            }

            UpdateLOD();

            if (editQueue.Count > 0)
            {
                List <BlockChange> EditQueueCopy = new List <BlockChange>(editQueue);
                editQueue.Clear();
                Loom.QueueAsyncTask(TerrainController.setBlockThreadName, () =>
                {
                    lock (_lockObj)
                    {
                        List <Vector3Int> updateChunks = new List <Vector3Int>();
                        foreach (BlockChange change in EditQueueCopy)
                        {
                            Vector3Int position = change.position;
                            byte type           = change.type;
                            if (position.x == 0)
                            {
                                if (!updateChunks.Contains(new Vector3Int(chunkPosition.x - 1, chunkPosition.y, chunkPosition.z)))
                                {
                                    updateChunks.Add(new Vector3Int(chunkPosition.x - 1, chunkPosition.y, chunkPosition.z));
                                }
                            }
                            if (position.x == SmoothVoxelSettings.ChunkSizeX - 1)
                            {
                                if (!updateChunks.Contains(new Vector3Int(chunkPosition.x + 1, chunkPosition.y, chunkPosition.z)))
                                {
                                    updateChunks.Add(new Vector3Int(chunkPosition.x + 1, chunkPosition.y, chunkPosition.z));
                                }
                            }

                            if (position.y == 0)
                            {
                                if (!updateChunks.Contains(new Vector3Int(chunkPosition.x, chunkPosition.y - 1, chunkPosition.z)))
                                {
                                    updateChunks.Add(new Vector3Int(chunkPosition.x, chunkPosition.y - 1, chunkPosition.z));
                                }
                            }
                            if (position.y == SmoothVoxelSettings.ChunkSizeY - 1)
                            {
                                if (!updateChunks.Contains(new Vector3Int(chunkPosition.x, chunkPosition.y + 1, chunkPosition.z)))
                                {
                                    updateChunks.Add(new Vector3Int(chunkPosition.x, chunkPosition.y + 1, chunkPosition.z));
                                }
                            }

                            if (position.z == 0)
                            {
                                if (!updateChunks.Contains(new Vector3Int(chunkPosition.x, chunkPosition.y, chunkPosition.z - 1)))
                                {
                                    updateChunks.Add(new Vector3Int(chunkPosition.x, chunkPosition.y, chunkPosition.z - 1));
                                }
                            }
                            if (position.z == SmoothVoxelSettings.ChunkSizeZ - 1)
                            {
                                if (!updateChunks.Contains(new Vector3Int(chunkPosition.x, chunkPosition.y, chunkPosition.z + 1)))
                                {
                                    updateChunks.Add(new Vector3Int(chunkPosition.x, chunkPosition.y, chunkPosition.z + 1));
                                }
                            }
                            builder.SetBlock(position.x, position.y, position.z, new Block(type));
                        }
                        Render(true);
                        foreach (Vector3Int chunk in updateChunks)
                        {
                            pageController.UpdateChunk(chunk.x, chunk.y, chunk.z);
                        }
                    }
                });
            }
        }
    }