private void OnResponseRemoveChunkExtData(object[] param) { WorldPos pos = (WorldPos)param[0]; bool needSave = (bool)param[1]; List <ClientEntityInfo> listEntityInfo = (List <ClientEntityInfo>)param[2]; Chunk chunk; _removedChunks.TryGetValue(pos, out chunk); if (chunk != null) { _removedChunks.Remove(pos); NetRemovedChunk removedChunk = new NetRemovedChunk(chunk); removedChunk.needSave = needSave; removedChunk.changedEntityInfos = listEntityInfo; world.WorldGenerator.RemoveChunkFromClient(removedChunk); Debug.Log("保存位置为:" + pos + "的数据!"); } else { chunk = null; _savedChunks.TryGetValue(pos, out chunk); if (chunk != null) { _savedChunks.Remove(pos); NetRemovedChunk savedChunk = new NetRemovedChunk(chunk); savedChunk.needSave = needSave; savedChunk.changedEntityInfos = listEntityInfo; EventManager.SendEvent(EventMacro.CHUNK_DATA_SAVE, savedChunk); if (_savedChunks.Count <= 0) { Debug.Log("保存数据完毕!"); } } } }
public void EnNetChunkSaveQueue(NetRemovedChunk data) { lock (_netChunkSaveQueue) { _netChunkSaveQueue.Enqueue(data); } }
//将客户端的chunk数据序列化好(保存到服务器上)(联机使用) public void EnqueueSaveNetChunk(NetRemovedChunk netRemovedChunk) { persistanceWorker.EnNetChunkSaveQueue(netRemovedChunk); }
//联机的时候的持续化工作 private void NetPersistanceWorker() { //网络 //从本地数据加载作为网络数据 NetChunkData netLoadChunkData = DeNetLoadQueue(); if (netLoadChunkData != null) { bool succ = WorldPersistanceManager.Instance.LoadNetChunk(netLoadChunkData); if (succ) { netLoadChunkData.isExist = true; } else { netLoadChunkData.isExist = false; } _manager.EnResponseNetChunkData(netLoadChunkData); } //从网络数据加载保存为本地数据 NetChunkData netSaveChunkData = DeNetSaveQueue(); if (netSaveChunkData != null) { WorldPersistanceManager.Instance.SaveNetChunk(netSaveChunkData); } //从网络数据加载作为内存数据 NetPriorityChunk requestNetChunk = DeNetChunkLoadQueue(); if (requestNetChunk != null) { requestNetChunk.netChunk.chunk.InitData(); if (requestNetChunk.netChunk.chunkData.isExist) { requestNetChunk.netChunk.chunk = WorldPersistanceManager.Instance.GetChunk(requestNetChunk.netChunk); //当从网络上获取到区块数据,并产生的时候,发送到服务器上 EventManager.SendEvent(EventMacro.CHUNK_DATA_GENERATE_FINISH, requestNetChunk.netChunk.chunk); } else { //如果当前客户端是主机,尝试从本机读取数据 if (NetManager.Instance.client.isMainClient) { if (WorldConfig.Instance.loadInMap) { if (WorldPersistanceManager.Instance.LoadChunk(requestNetChunk.netChunk.chunk)) { //当从本地上获取到区块数据,并产生的时候,发送到服务器上 EventManager.SendEvent(EventMacro.CHUNK_DATA_GENERATE_FINISH, requestNetChunk.netChunk.chunk); } } } } _manager.generatorWorker.EnNetGeneratorQueue(requestNetChunk); } //将内存数据序列化为网络数据 NetRemovedChunk netSaveChunk = DeNetChunkSaveQueue(); if (netSaveChunk != null) { EventManager.SendEvent(EventMacro.CHUNK_DATA_REMOVE_FINISH, netSaveChunk); _manager.EnqueueWaitRemove(netSaveChunk.chunk); } }
public void RemoveChunkFromClient(NetRemovedChunk removedChunk) { _manager.EnqueueSaveNetChunk(removedChunk); }