public void EnNetLoadQueue(NetChunkData netChunkData)
 {
     lock (_netLoadQueue)
     {
         _netLoadQueue.Enqueue(netChunkData);
     }
 }
 //进入队列,该队列保存了客户端请求的chunk数据
 public void EnResponseNetChunkData(NetChunkData data)
 {
     lock (_waitResponseNetChunkDatas)
     {
         _waitResponseNetChunkDatas.Enqueue(data);
     }
 }
 public void EnNetChunkRemoveData(NetChunkData data)
 {
     lock (_waitNetChunkRemoveDatas)
     {
         _waitNetChunkRemoveDatas.Enqueue(data);
     }
 }
 public void EnNetSaveQueue(NetChunkData data)
 {
     lock (_netSaveQueue)
     {
         _netSaveQueue.Enqueue(data);
     }
 }
示例#5
0
        public override void ClientDo(ServerConnectionWorker connectionWork)
        {
            NetChunkData netChunkData = new NetChunkData(roleId, pos);

            netChunkData.data.data         = chunkByteData;
            netChunkData.data.compressType = (MTBCompressType)compressType;
            EventManager.SendEvent(NetEventMacro.ON_NET_SAVE_CHUNK, netChunkData);
        }
        public void SaveNetChunk(NetChunkData netChunkData)
        {
            WorldPos   regionPos          = GetRegionPos(netChunkData.worldPos);
            RegionFile regionFile         = GetNetRegionFile(regionPos);
            WorldPos   regionFileChunkPos = GetRegionFileChunkPos(netChunkData.worldPos, regionPos);

            regionFile.SaveChunkData(regionFileChunkPos.x, regionFileChunkPos.z, netChunkData.data);
        }
示例#7
0
        public override void ClientDo(ServerConnectionWorker connectionWork)
        {
            NetChunkData data = new NetChunkData(NetManager.Instance.client.roleId, pos);

            data.isExist       = false;
            data.hasChangeData = true;
            data.changedData   = new ClientChangedChunkData(sign, changedBlocks);
            EventManager.SendEvent(NetEventMacro.ON_NET_POPULATION_GENERATE, data);
        }
        public bool LoadNetChunk(NetChunkData netChunkData)
        {
            WorldPos   regionPos          = GetRegionPos(netChunkData.worldPos);
            RegionFile regionFile         = GetNetRegionFile(regionPos);
            WorldPos   regionFileChunkPos = GetRegionFileChunkPos(netChunkData.worldPos, regionPos);
            bool       succ = regionFile.GetChunkData(regionFileChunkPos.x, regionFileChunkPos.z, netChunkData.data);

            return(succ);
        }
        public override void ClientDo(ServerConnectionWorker connectionWork)
        {
            NetChunkData data = new NetChunkData(roleId, pos);

            data.isExist           = isExit;
            data.data.compressType = (MTBCompressType)compressType;
            data.data.data         = chunkByteData;
            data.hasChangeData     = hasChangedData;
            data.changedData       = changedData;
            EventManager.SendEvent(NetEventMacro.ON_NET_CHUNK_GENERATOR_RETURN, data);
        }
 public NetChunkData DeNetChunkRemoveData()
 {
     lock (_waitNetChunkRemoveDatas)
     {
         if (_waitNetChunkRemoveDatas.Count > 0)
         {
             NetChunkData data = _waitNetChunkRemoveDatas.Dequeue();
             return(data);
         }
         return(null);
     }
 }
        //(联机使用)
        public void GenerateNetChunk(NetChunkData data, WorldPos curInChunkPos)
        {
            WorldPos pos      = data.worldPos;
            Chunk    newChunk = _world.GetChunk(pos.x, pos.y, pos.z);

            if (newChunk != null)
            {
                NetChunk netChunk = new NetChunk(data);
                netChunk.chunk = newChunk;
                netChunk.curPlayerInChunkPos = curInChunkPos;
                _manager.EnqueueNetChunk(netChunk);
            }
        }
        public void UpdatePopulationFromServer(NetChunkData data, WorldPos curInChunkPos)
        {
            WorldPos pos      = data.worldPos;
            Chunk    curChunk = _world.GetChunk(pos.x, pos.y, pos.z);

            if (curChunk != null)
            {
                NetChunk netChunk = new NetChunk(data);
                netChunk.chunk = curChunk;
                netChunk.curPlayerInChunkPos = curInChunkPos;
                _manager.EnqueueUpdatePopulation(netChunk);
            }
        }
        public NetChunkData GetNetChunkData(Chunk chunk, int roleId)
        {
            _ms.SetLength(0);
            chunk.Serialize(_ms);
            _ms.Position = 0;
            IMTBCompress compress = MTBCompressFactory.GetCompress(MTBCompressType.ZLib);

            _ms          = (MemoryStream)compress.Encompress(_ms);
            _ms.Position = 0;
            NetChunkData netChunkData = new NetChunkData(roleId, chunk.worldPos);

            netChunkData.data.data         = _ms.ToArray();
            netChunkData.data.compressType = MTBCompressType.ZLib;
            return(netChunkData);
        }
示例#14
0
 private IEnumerator ResponseNetChunk()
 {
     while (true)
     {
         NetChunkData netChunkData = world.WorldGenerator.DataProcessorManager.DeResponseNetChunkData();
         if (netChunkData != null)
         {
             ResponseChunkPackage package = PackageFactory.GetPackage(PackageType.ResponseChunk) as ResponseChunkPackage;
             package.roleId        = netChunkData.roleId;
             package.pos           = netChunkData.worldPos;
             package.isExit        = netChunkData.isExist;
             package.compressType  = (byte)netChunkData.data.compressType;
             package.chunkByteData = netChunkData.data.data;
             NetManager.Instance.client.SendPackage(package);
         }
         yield return(null);
     }
 }
示例#15
0
        public override void ClientDo(ServerConnectionWorker connectionWork)
        {
            NetChunkData data = new NetChunkData(roleId, pos);

            EventManager.SendEvent(NetEventMacro.ON_NET_CHUNK_GENERATOR, data);
        }
 public void LoadNetChunkData(NetChunkData data)
 {
     _manager.EnqueueLoadNetChunkData(data);
 }
 //保存从客户端发送过来的chunk数据 (联机使用)
 public void EnqueueSaveNetChunkData(NetChunkData data)
 {
     persistanceWorker.EnNetSaveQueue(data);
 }
 //从本地加载出chunk数据(为了发给请求的客户端)(联机使用)
 public void EnqueueLoadNetChunkData(NetChunkData data)
 {
     persistanceWorker.EnNetLoadQueue(data);
 }
示例#19
0
        private void OnNetChunkGeneratorReturn(object[] param)
        {
            NetChunkData netChunkData = (NetChunkData)param[0];

            world.WorldGenerator.GenerateNetChunk(netChunkData, _curChunkPos);
        }
示例#20
0
        private void OnNetChunkGenerator(object[] param)
        {
            NetChunkData data = (NetChunkData)param[0];

            world.WorldGenerator.LoadNetChunkData(data);
        }
示例#21
0
        private void OnNetSaveChunk(object[] param)
        {
            NetChunkData data = (NetChunkData)param[0];

            world.WorldGenerator.DataProcessorManager.EnqueueSaveNetChunkData(data);
        }
示例#22
0
        private void OnNetPopulationGenerate(object[] param)
        {
            NetChunkData data = (NetChunkData)param[0];

            world.WorldGenerator.UpdatePopulationFromServer(data, _curChunkPos);
        }
        //联机的时候的持续化工作
        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 NetChunk(NetChunkData data)
 {
     chunkData = data;
     chunkPos  = data.worldPos;
 }