public McpeBatch GetBatch() { if (_cache != null && _cachedBatch != null) { return(_cachedBatch); } McpeFullChunkData fullChunkData = McpeFullChunkData.CreateObject(); fullChunkData.chunkX = x; fullChunkData.chunkZ = z; fullChunkData.chunkData = GetBytes(); fullChunkData.chunkDataLength = fullChunkData.chunkData.Length; byte[] bytes = fullChunkData.Encode(); fullChunkData.PutPool(); McpeBatch batch = McpeBatch.CreateObject(); byte[] buffer = Player.CompressBytes(bytes, CompressionLevel.Optimal); batch.payloadSize = buffer.Length; batch.payload = buffer; batch.Encode(); batch.MarkPermanent(); _cachedBatch = batch; return(batch); }
public McpeBatch GetBatch() { lock (_cacheSync) { if (_cache != null && _cachedBatch != null) { return(_cachedBatch); } McpeFullChunkData fullChunkData = McpeFullChunkData.CreateObject(); fullChunkData.chunkX = x; fullChunkData.chunkZ = z; fullChunkData.order = 0; fullChunkData.chunkData = GetBytes(); fullChunkData.chunkDataLength = fullChunkData.chunkData.Length; byte[] bytes = fullChunkData.Encode(); fullChunkData.PutPool(); MemoryStream memStream = new MemoryStream(); memStream.Write(BitConverter.GetBytes(Endian.SwapInt32(bytes.Length)), 0, 4); memStream.Write(bytes, 0, bytes.Length); McpeBatch batch = McpeBatch.CreateObject(); byte[] buffer = Player.CompressBytes(memStream.ToArray(), CompressionLevel.Optimal); batch.payloadSize = buffer.Length; batch.payload = buffer; batch.Encode(); batch.MarkPermanent(); _cachedBatch = batch; return(batch); } }
internal static McpeBatch CreateMcpeBatch(byte[] bytes) { McpeBatch batch = BatchUtils.CreateBatchPacket(bytes, 0, (int)bytes.Length, CompressionLevel.Optimal, true); batch.MarkPermanent(); batch.Encode(); return(batch); }
public object Clone() { ChunkColumn cc = (ChunkColumn)MemberwiseClone(); //public int x; //public int z; //public bool isDirty; //public byte[] biomeId = ArrayOf<byte>.Create(256, 2); cc.biomeId = (byte[])biomeId.Clone(); //public int[] biomeColor = ArrayOf<int>.Create(256, 1); cc.biomeColor = (int[])biomeColor.Clone(); //public byte[] height = ArrayOf<byte>.Create(256, 0); cc.height = (byte[])height.Clone(); //public byte[] blocks = new byte[16 * 16 * 128]; cc.blocks = (byte[])blocks.Clone(); //public NibbleArray metadata = new NibbleArray(16 * 16 * 128); cc.metadata = (NibbleArray)metadata.Clone(); //public NibbleArray blocklight = new NibbleArray(16 * 16 * 128); cc.blocklight = (NibbleArray)blocklight.Clone(); //public NibbleArray skylight = new NibbleArray(16 * 16 * 128); cc.skylight = (NibbleArray)skylight.Clone(); //public IDictionary<BlockCoordinates, NbtCompound> BlockEntities = new Dictionary<BlockCoordinates, NbtCompound>(); cc.BlockEntities = new Dictionary <BlockCoordinates, NbtCompound>(); foreach (KeyValuePair <BlockCoordinates, NbtCompound> blockEntityPair in BlockEntities) { cc.BlockEntities.Add(blockEntityPair.Key, (NbtCompound)blockEntityPair.Value.Clone()); } //private byte[] _cache; if (_cache != null) { cc._cache = (byte[])_cache.Clone(); } //private McpeBatch _cachedBatch = null; McpeBatch batch = McpeBatch.CreateObject(); batch.payloadSize = _cachedBatch.payloadSize; batch.payload = _cachedBatch.payload; batch.Encode(); batch.MarkPermanent(); cc._cachedBatch = batch; //private object _cacheSync = new object(); _cacheSync = new object(); return(cc); }
internal void ClearCache() { lock (_cacheSync) { if (_cachedBatch != null) { _cachedBatch.MarkPermanent(false); _cachedBatch.PutPool(); _cachedBatch = null; } } }
internal static McpeBatch CreateMcpeBatch(byte[] bytes) { MemoryStream memStream = MiNetServer.MemoryStreamManager.GetStream(); memStream.Write(BitConverter.GetBytes(Endian.SwapInt32(bytes.Length)), 0, 4); memStream.Write(bytes, 0, bytes.Length); McpeBatch batch = McpeBatch.CreateObject(); byte[] buffer = Player.CompressBytes(memStream.ToArray(), CompressionLevel.Optimal); batch.MarkPermanent(); batch.payloadSize = buffer.Length; batch.payload = buffer; batch.Encode(true); return(batch); }
public object Clone() { ChunkColumn cc = (ChunkColumn)MemberwiseClone(); cc.chunks = new Chunk[16]; for (int i = 0; i < chunks.Length; i++) { cc.chunks[i] = (Chunk)chunks[i].Clone(); } cc.biomeId = (byte[])biomeId.Clone(); cc.biomeColor = (int[])biomeColor.Clone(); cc.height = (byte[])height.Clone(); cc.BlockEntities = new Dictionary <BlockCoordinates, NbtCompound>(); foreach (KeyValuePair <BlockCoordinates, NbtCompound> blockEntityPair in BlockEntities) { cc.BlockEntities.Add(blockEntityPair.Key, (NbtCompound)blockEntityPair.Value.Clone()); } if (_cache != null) { cc._cache = (byte[])_cache.Clone(); } McpeBatch batch = McpeBatch.CreateObject(); batch.payload = _cachedBatch.payload; batch.Encode(); batch.MarkPermanent(); cc._cachedBatch = batch; _cacheSync = new object(); return(cc); }