//刷新区块网格和光照 public void EnReFreshQueue(RefreshChunkArea chunk) { lock (_refreshQueue) { _refreshQueue.Enqueue(chunk); } }
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]); } } }
public void Collection(RefreshChunkArea area) { if (canCollection) { _area = area; } }
public void updateArea(RefreshChunkArea area) { //同步大块更改数据到服务器 ClientAreaCollection.Instance.BeginCollection(); ClientAreaCollection.Instance.Collection(area); ClientAreaCollection.Instance.SendPackage(); ClientAreaCollection.Instance.EndCollection(); }
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); }
//刷新网络大范围区块网格和光照 public void EnNetRefreshAreaQueue(RefreshChunkArea chunk) { lock (_netRefreshQueue) { if (_netRefreshQueue.Count > 1000) { return; } _netRefreshQueue.Enqueue(chunk); } }
private RefreshChunkArea DeNetRefreshAreaQueue() { lock (_netRefreshQueue) { if (_netRefreshQueue.Count > 0) { RefreshChunkArea c = _netRefreshQueue.Dequeue(); return(c); } return(null); } }
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); } }
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); } } } } }
//更新网络大范围更新数据 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); } }
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); }
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); }
public void EndCollection() { _area = null; canCollection = false; }
public void updateArea(RefreshChunkArea area) { World.world.WorldGenerator.RefreshChunk(area); }
//刷新区块网格和光照 public void RefreshChunk(RefreshChunkArea chunk) { _manager.EnqueueRefreshChunk(chunk); }