private ClientChangedBlock ReadChangedBlockData()
        {
            Int16 index              = ReadInt16();
            byte  blockType          = ReadByte();
            byte  extendId           = ReadByte();
            ClientChangedBlock block = new ClientChangedBlock(index, blockType, extendId);

            return(block);
        }
Esempio n. 2
0
 public void ChangeBlock(ClientChangedBlock block)
 {
     if (_blockMap.ContainsKey(block.index))
     {
         _blockMap[block.index] = block;
     }
     else
     {
         _blockMap.Add(block.index, block);
         CheckNeedSave();
     }
 }
Esempio n. 3
0
        public void UpdateClientChangedBlock(ClientChangedBlock changedBlock, bool refresh = false)
        {
            WorldPos pos = ClientChangedChunk.GetChunkPos(changedBlock.index);
            //			Debug.Log("updateClientChangedBlock:" + pos.ToString());
            Section s = GetSection(pos.y);
            Block   b = new Block((BlockType)changedBlock.blockType, changedBlock.extendId);

            s.SetBlock(pos.x, pos.y - s.chunkOffsetY, pos.z, b, true);
            if (refresh)
            {
                this.world.CheckAndRecalculateMesh(this, pos.x, pos.y, pos.z, b);
            }
        }
Esempio n. 4
0
        public override void ReadAllData()
        {
            int x = ReadInt();
            int y = ReadInt();
            int z = ReadInt();

            pos = new WorldPos(x, y, z);
            Int16 index     = ReadInt16();
            byte  blockType = ReadByte();
            byte  extendId  = ReadByte();

            changedBlock = new ClientChangedBlock(index, blockType, extendId);
        }
Esempio n. 5
0
        private void NetGeneratorWorker()
        {
            NetPriorityChunk netPriorityChunk = DeNetGeneratorQueue();

            if (netPriorityChunk != null)
            {
                Chunk chunk = netPriorityChunk.netChunk.chunk;
                if (!netPriorityChunk.netChunk.chunkData.isExist)
                {
                    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;
                        //这里是地形数据在本机上产生时,需要发送到服务器上
                        EventManager.SendEvent(EventMacro.CHUNK_DATA_GENERATE_FINISH, chunk);
                    }
                }
                //如果服务器上已经有最新的数据,拿到最新的数据更改
                if (netPriorityChunk.netChunk.chunkData.hasChangeData)
                {
                    ClientChangedChunkData changedData = netPriorityChunk.netChunk.chunkData.changedData;
                    chunk.UpdateSign(changedData.sign);
                    if (changedData.list.Count > 0)
                    {
                        for (int i = 0; i < changedData.list.Count; i++)
                        {
                            ClientChangedBlock changedBlock = changedData.list[i];
                            chunk.UpdateClientChangedBlock(changedBlock);
                        }
                        ReculateChunkLightAndAround(chunk);
                    }
                }
                CheckAroundChunkAndGeneratorPopulation(chunk, true);
            }

            ////////////////////////////////////////////////////
            //收到服务器同步的大块更改数据
            refreshNetArea();
        }
Esempio n. 6
0
 public void ChangedBlock(WorldPos pos, ClientChangedBlock block)
 {
     lock (_chunkMap)
     {
         ClientChangedChunk changedChunk;
         _chunkMap.TryGetValue(pos, out changedChunk);
         if (changedChunk == null)
         {
             //					changedChunk = new ClientChangedChunk();
             //					_chunkMap.Add(pos,changedChunk);
             throw new Exception("位置为Pos:" + pos.ToString() + "的chunk不存在,不能更改block:" + block.index);
         }
         changedChunk.ChangeBlock(block);
     }
 }
Esempio n. 7
0
 public void Collection(WorldPos pos, int x, int y, int z, Block block)
 {
     if (canCollection)
     {
         List <ClientChangedBlock> list;
         _map.TryGetValue(pos, out list);
         if (list == null)
         {
             list = new List <ClientChangedBlock>();
             _map.Add(pos, list);
         }
         Int16 index     = ClientChangedChunk.GetChunkIndex(x, y, z);
         byte  blockType = (byte)block.BlockType;
         byte  extendId  = block.ExtendId;
         ClientChangedBlock changedBlock = new ClientChangedBlock(index, blockType, extendId);
         list.Add(changedBlock);
     }
 }
Esempio n. 8
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);
                 }
             }
         }
     }
 }
 private void WriteChangedBlockData(ClientChangedBlock block)
 {
     WriteInt16(block.index);
     WriteByte(block.blockType);
     WriteByte(block.extendId);
 }