//刷新区块网格和光照
 public void EnReFreshQueue(RefreshChunkArea chunk)
 {
     lock (_refreshQueue)
     {
         _refreshQueue.Enqueue(chunk);
     }
 }
コード例 #2
0
        private void ReculateChunkAreaLightAndAround(RefreshChunkArea chunkArea, bool reRender = false)
        {
            reculateLightArounds.Clear();
            reculateAreaLightArounds.Clear();
            for (int i = 0; i < chunkArea.chunkList.Count; i++)
            {
                List <Chunk> list = _manager.World.GetAroundChunks(chunkArea.chunkList[i].chunk, reculateLightArounds);
                for (int j = 0; j < list.Count; j++)
                {
                    if (!reculateAreaLightArounds.Contains(list[j]))
                    {
                        reculateAreaLightArounds.Add(list[j]);
                    }
                }
                if (!reculateAreaLightArounds.Contains(chunkArea.chunkList[i].chunk))
                {
                    reculateAreaLightArounds.Add(chunkArea.chunkList[i].chunk);
                }
            }

            for (int i = 0; i < reculateAreaLightArounds.Count; i++)
            {
                ReculateChunkLight(reculateAreaLightArounds[i]);
            }
            if (reRender)
            {
                for (int i = 0; i < reculateAreaLightArounds.Count; i++)
                {
                    _manager.EnqueueRender(reculateAreaLightArounds[i]);
                }
            }
        }
コード例 #3
0
 public void Collection(RefreshChunkArea area)
 {
     if (canCollection)
     {
         _area = area;
     }
 }
コード例 #4
0
 public void updateArea(RefreshChunkArea area)
 {
     //同步大块更改数据到服务器
     ClientAreaCollection.Instance.BeginCollection();
     ClientAreaCollection.Instance.Collection(area);
     ClientAreaCollection.Instance.SendPackage();
     ClientAreaCollection.Instance.EndCollection();
 }
コード例 #5
0
        public override void ReadAllData()
        {
            int count = ReadInt();
            List <RefreshChunk> chunkList = new List <RefreshChunk>(count);

            for (int i = 0; i < count; i++)
            {
                chunkList.Add(readChangedChunk());
            }
            area = new RefreshChunkArea(chunkList);
        }
コード例 #6
0
 //刷新网络大范围区块网格和光照
 public void EnNetRefreshAreaQueue(RefreshChunkArea chunk)
 {
     lock (_netRefreshQueue)
     {
         if (_netRefreshQueue.Count > 1000)
         {
             return;
         }
         _netRefreshQueue.Enqueue(chunk);
     }
 }
コード例 #7
0
 private RefreshChunkArea DeNetRefreshAreaQueue()
 {
     lock (_netRefreshQueue)
     {
         if (_netRefreshQueue.Count > 0)
         {
             RefreshChunkArea c = _netRefreshQueue.Dequeue();
             return(c);
         }
         return(null);
     }
 }
コード例 #8
0
        private void SingleGeneratorWorker()
        {
            //单机使用
            Chunk chunk = DeGeneratorQueue();

            if (chunk != null)
            {
                WorldPos pos = chunk.worldPos;
                if (World.world.GetChunk(pos.x, pos.y, pos.z) == null)
                {
                    return;
                }
                if (!chunk.isTerrainDataPrepared)
                {
                    _terrainControlGenerator.Generate(chunk);
                    if (WorldConfig.Instance.CaveEnable)
                    {
                        _cavesGenerator.generate(chunk);
                    }
                    chunk.isTerrainDataPrepared = true;
                    chunk.isUpdate = true;
                }

                CheckAroundChunkAndGeneratorPopulation(chunk, false);
                RemoveSingleGenerateChunk(chunk);
            }

            RefreshChunkArea refreshChunkArea = DeRefreshQueue();

            if (refreshChunkArea != null)
            {
                for (int i = 0; i < refreshChunkArea.chunkList.Count; i++)
                {
                    if (refreshChunkArea.chunkList[i].refreshList.Count > 0)
                    {
                        for (int j = 0; j < refreshChunkArea.chunkList[i].refreshList.Count; j++)
                        {
                            UpdateBlock updateBlock = refreshChunkArea.chunkList[i].refreshList[j];
                            refreshChunkArea.chunkList[i].chunk.UpdateChangedBlock(updateBlock);
                        }
                    }
                }
                ReculateChunkAreaLightAndAround(refreshChunkArea, true);
            }
        }
        //单机的持续化工作
        private void SinglePersistanceWorker()
        {
            //单机
            //从本地数据加载
            PriorityChunk loadPriorityChunk = DeLoadQueue();

            if (loadPriorityChunk != null)
            {
                WorldPos pos = loadPriorityChunk.chunk.worldPos;
                if (World.world.GetChunk(pos.x, pos.y, pos.z) == null)
                {
                    return;
                }
                loadPriorityChunk.chunk.InitData();
                if (WorldConfig.Instance.loadInMap)
                {
                    WorldPersistanceManager.Instance.LoadChunk(loadPriorityChunk.chunk);
                }
                //这里进入产生线程
                _manager.generatorWorker.EnGeneratorQueue(loadPriorityChunk);
            }
            //保存到本地数据
            Chunk saveChunk = DeSaveQueue();

            if (saveChunk != null)
            {
                if (saveChunk.isUpdate)
                {
                    if (WorldConfig.Instance.saveBlock)
                    {
                        WorldPersistanceManager.Instance.SaveChunk(saveChunk);
                        saveChunk.isUpdate = false;
                    }
                }
                _manager.EnqueueWaitRemove(saveChunk);
            }
            RefreshChunkArea refreshChunkArea = DeRefreshQueue();

            if (refreshChunkArea != null)
            {
                _manager.generatorWorker.EnRefreshQueue(refreshChunkArea);
            }
        }
コード例 #10
0
 public void ChangedArea(RefreshChunkArea area)
 {
     lock (_chunkMap)
     {
         for (int i = 0; i < area.chunkList.Count; i++)
         {
             ClientChangedChunk changedChunk;
             _chunkMap.TryGetValue(area.chunkList[i].chunk.worldPos, out changedChunk);
             if (changedChunk != null)
             {
                 for (int j = 0; j < area.chunkList[i].refreshList.Count; j++)
                 {
                     Int16 index = ClientChangedChunk.GetChunkIndex(area.chunkList[i].refreshList[j].Pos.x, area.chunkList[i].refreshList[j].Pos.y, area.chunkList[i].refreshList[j].Pos.z);
                     ClientChangedBlock block = new ClientChangedBlock(index, (byte)area.chunkList[i].refreshList[j].type, area.chunkList[i].refreshList[j].exid);
                     changedChunk.ChangeBlock(block);
                 }
             }
         }
     }
 }
コード例 #11
0
        //更新网络大范围更新数据
        private void refreshNetArea()
        {
            RefreshChunkArea netRefreshChunkArea = DeNetRefreshAreaQueue();

            if (netRefreshChunkArea != null)
            {
                for (int i = 0; i < netRefreshChunkArea.chunkList.Count; i++)
                {
                    if (netRefreshChunkArea.chunkList[i].refreshList.Count > 0)
                    {
                        for (int j = 0; j < netRefreshChunkArea.chunkList[i].refreshList.Count; j++)
                        {
                            UpdateBlock updateBlock = netRefreshChunkArea.chunkList[i].refreshList[j];
                            netRefreshChunkArea.chunkList[i].chunk.UpdateChangedBlock(updateBlock);
                        }
                    }
                }
                ReculateChunkAreaLightAndAround(netRefreshChunkArea, true);
            }
        }
コード例 #12
0
 public void BroadcastPlaerAreaChangedPackage(ClientPlayer sourcePlayer, RefreshChunkArea area, NetPackage package, bool includeSelf)
 {
     lock (_chunkMap)
     {
         for (int i = 0; i < area.chunkList.Count; i++)
         {
             ClientChangedChunk changedChunk;
             _chunkMap.TryGetValue(area.chunkList[i].chunk.worldPos, out changedChunk);
             if (changedChunk != null)
             {
                 List <int> playerIds = changedChunk.players;
                 for (int j = 0; j < playerIds.Count; j++)
                 {
                     if (!includeSelf && playerIds[j] == sourcePlayer.id)
                     {
                         continue;
                     }
                     ClientPlayer player = NetManager.Instance.server.playerManager.GetPlayer(playerIds[j]);
                     player.worker.SendPackage(package);
                 }
             }
         }
     }
 }
 //刷新区块网格和光照
 public void EnqueueRefreshChunk(RefreshChunkArea chunk)
 {
     persistanceWorker.EnReFreshQueue(chunk);
 }
コード例 #14
0
        private void OnNetAreaUpdate(object[] param)
        {
            RefreshChunkArea area = (RefreshChunkArea)param[0];

            world.WorldGenerator.UpdateAreaFromServer(area);
        }
 public void UpdateAreaFromServer(RefreshChunkArea area)
 {
     _manager.EnqueueNetUpdateArea(area);
 }
 //更新网络同步的大量块刷新
 public void EnqueueNetUpdateArea(RefreshChunkArea area)
 {
     generatorWorker.EnNetRefreshAreaQueue(area);
 }
コード例 #17
0
 public void EndCollection()
 {
     _area         = null;
     canCollection = false;
 }
コード例 #18
0
 public void updateArea(RefreshChunkArea area)
 {
     World.world.WorldGenerator.RefreshChunk(area);
 }
 //刷新区块网格和光照
 public void RefreshChunk(RefreshChunkArea chunk)
 {
     _manager.EnqueueRefreshChunk(chunk);
 }