public override bool ParseBytesAndExecute(byte[] data) { if (data.Length < (4 + 4)) { return(false); } BlockUpperArea bua = new BlockUpperArea(); int x = Utilities.BytesToInt(Utilities.BytesPartial(data, 0, 4)); int y = Utilities.BytesToInt(Utilities.BytesPartial(data, 4, 4)); int len = Utilities.BytesToInt(Utilities.BytesPartial(data, 4 + 4, 4)); byte[] subdata = FileHandler.Uncompress(Utilities.BytesPartial(data, 4 + 4 + 4, len)); for (int i = 0; i < (Constants.CHUNK_WIDTH * Constants.CHUNK_WIDTH); i++) { bua.Blocks[i] = Utilities.BytesToInt(Utilities.BytesPartial(subdata, i * 4, 4)); } subdata = FileHandler.Uncompress(Utilities.BytesPartial(data, 4 + 4 + 4 + len, data.Length - (4 + 4 + 4 + len))); for (int i = 0; i < (Constants.CHUNK_WIDTH * Constants.CHUNK_WIDTH * 4); i++) { ushort mat = Utilities.BytesToUShort(Utilities.BytesPartial(subdata, i * 2, 2)); int height = Utilities.BytesToInt(Utilities.BytesPartial(subdata, (Constants.CHUNK_WIDTH * Constants.CHUNK_WIDTH * 4 * 2) + i * 4, 4)); bua.BlocksTrans[i] = new BlockUpperArea.TopBlock() { BasicMat = (Material)mat, Height = height }; } TheClient.TheRegion.UpperAreas[new Vector2i(x, y)] = bua; return(true); }
public TopsPacketOut(Vector2i pos, BlockUpperArea bua) { ID = ServerToClientPacket.TOPS; byte[] tdat = bua.ToNetBytes(); byte[] tdat2 = bua.ToNetBytesTrans(); Data = new byte[4 + 4 + 4 + tdat.Length + tdat2.Length]; Utilities.IntToBytes(pos.X).CopyTo(Data, 0); Utilities.IntToBytes(pos.Y).CopyTo(Data, 4); Utilities.IntToBytes(tdat.Length).CopyTo(Data, 4 + 4); tdat.CopyTo(Data, 4 + 4 + 4); tdat2.CopyTo(Data, 4 + 4 + 4 + tdat.Length); }
public void PushTopsEdited(Vector2i two, BlockUpperArea bua) { Vector2i two1 = HigherLocFor(two); Vector2i two2 = HigherLocFor(two1); Vector2i two3 = HigherLocFor(two2); Vector2i two4 = HigherLocFor(two3); // TODO: Send notice packet to affected players! bua.Edited = false; ChunkManager.WriteTops(two.X, two.Y, bua.ToBytes(), bua.ToBytesTrans()); // 1x KeyValuePair <byte[], byte[]> z1 = PushTopsToHigherStart(two1, two, bua); // 5x KeyValuePair <byte[], byte[]> z2 = PushTopsToHigherSubsequent(two2, two1, 2, z1.Key, z1.Value); // 25x KeyValuePair <byte[], byte[]> z3 = PushTopsToHigherSubsequent(two3, two2, 3, z2.Key, z2.Value); // 125x PushTopsToHigherSubsequent(two4, two3, 4, z3.Key, z3.Value); // 625x }
public void NoticeChunkForUpperArea(Vector3i pos) { Vector2i two = new Vector2i(pos.X, pos.Y); if (!UpperAreas.TryGetValue(two, out BlockUpperArea bua)) { KeyValuePair <byte[], byte[]> b = ChunkManager.GetTops(two.X, two.Y); bua = new BlockUpperArea(); if (b.Key != null) { bua.FromBytes(b.Key); } if (b.Value != null) { bua.FromBytesTrans(b.Value); } UpperAreas[two] = bua; } bua.ChunksUsing.Add(pos.Z); }
public KeyValuePair <byte[], byte[]> PushTopsToHigherStart(Vector2i two, Vector2i two_lower, BlockUpperArea bua) { Vector2i relPos; relPos.X = two_lower.X - two.X * HIGHER_DIV; relPos.Y = two_lower.Y - two.Y * HIGHER_DIV; KeyValuePair <byte[], byte[]> bses = ChunkManager.GetTopsHigher(two.X, two.Y, 1); byte[] b = bses.Key; byte[] bt = bses.Value; if (b == null) { b = new byte[Constants.CHUNK_WIDTH * Constants.CHUNK_WIDTH * 2]; } if (bt == null) { bt = new byte[Constants.CHUNK_WIDTH * Constants.CHUNK_WIDTH * 2 * 4]; } for (int x = 0; x < HIGHER_SIZE; x++) { for (int y = 0; y < HIGHER_SIZE; y++) { int inder = bua.BlockIndex(x * 5, y * 5); Material mat = bua.Blocks[inder].BasicMat; int ind = TopsHigherBlockIndex(x + relPos.X * HIGHER_SIZE, y + relPos.Y * HIGHER_SIZE); Utilities.UshortToBytes((ushort)mat).CopyTo(b, ind * 2); ind *= 4; inder *= 4; for (int bz = 0; bz < 4; bz++) { mat = bua.BlocksTrans[inder + bz].BasicMat; Utilities.UshortToBytes((ushort)mat).CopyTo(bt, (ind + bz) * 2); } } } ChunkManager.WriteTopsHigher(two.X, two.Y, 1, b, bt); return(new KeyValuePair <byte[], byte[]>(b, bt)); }