Пример #1
0
 public AsyncStreamReader(Stream stream, IConnection connection, Action closeCallback)
 {
     _closeCallback = closeCallback;
     _stream        = stream;
     _connection    = connection;
     _buffer        = new ChunkBuffer();
 }
Пример #2
0
 public AsyncStreamReader(Stream stream, Connection connection, Action initializeCallback, Action <Exception> errorCallback)
 {
     _initializeCallback = initializeCallback;
     _errorCallback      = errorCallback;
     _stream             = stream;
     _connection         = connection;
     _buffer             = new ChunkBuffer();
 }
Пример #3
0
 private void ChunkBufferTrimUsedData()
 {
     //Remove 'used' data from memory stream, that is everything before it's current position
     byte[] internalBuffer = ChunkBuffer.GetBuffer();
     Buffer.BlockCopy(internalBuffer, (int)ChunkBuffer.Position, internalBuffer, 0, (int)ChunkBufferRemaining);
     ChunkBuffer.SetLength((int)ChunkBufferRemaining);
     ChunkBuffer.Position = 0;
 }
Пример #4
0
        public RpcOutputBuffer( ChunkBuffer chunkBuffer )
        {
            if ( chunkBuffer == null )
            {
                throw new ArgumentNullException( "chunkBuffer" );
            }

            this._chunks = chunkBuffer;
        }
Пример #5
0
 public AsyncStreamReader(Stream stream,
                          IConnection connection,
                          Action initializeCallback,
                          Action closeCallback)
 {
     m_initializeCallback = initializeCallback;
     m_closeCallback      = closeCallback;
     m_stream             = stream;
     m_connection         = connection;
     m_buffer             = new ChunkBuffer();
 }
Пример #6
0
            public void ReturnsTextUpToNewLine()
            {
                // Arrange
                var buffer = new ChunkBuffer();
                byte[] data = Encoding.UTF8.GetBytes("hello world\noy");

                // Act
                buffer.Add(data, data.Length);

                // Assert
                Assert.Equal("hello world", buffer.ReadLine());
            }
Пример #7
0
            public void ReturnsNullIfNoNewLineIfBuffer()
            {
                // Arrange
                var buffer = new ChunkBuffer();
                byte[] data = Encoding.UTF8.GetBytes("hello world");

                // Act
                buffer.Add(data, data.Length);

                // Assert
                Assert.Null(buffer.ReadLine());
            }
Пример #8
0
            public void ReturnsNullIfNoNewLineIfBuffer()
            {
                // Arrange
                var buffer = new ChunkBuffer();

                byte[] data = Encoding.UTF8.GetBytes("hello world");

                // Act
                buffer.Add(data, data.Length);

                // Assert
                Assert.Null(buffer.ReadLine());
            }
Пример #9
0
            public void ReturnsTextUpToNewLine()
            {
                // Arrange
                var buffer = new ChunkBuffer();

                byte[] data = Encoding.UTF8.GetBytes("hello world\noy");

                // Act
                buffer.Add(data, data.Length);

                // Assert
                Assert.Equal("hello world", buffer.ReadLine());
            }
Пример #10
0
            public void CanReadMultipleLines()
            {
                // Arrange
                var buffer = new ChunkBuffer();
                byte[] data = Encoding.UTF8.GetBytes("hel\nlo world\noy");

                // Act
                buffer.Add(data, data.Length);

                // Assert
                Assert.Equal("hel", buffer.ReadLine());
                Assert.Equal("lo world", buffer.ReadLine());
                Assert.Null(buffer.ReadLine());
            }
Пример #11
0
        private async Task <byte[]> ReadDataOfSizeAsync(int requiredSize)
        {
            await PopulateChunkBufferAsync(requiredSize).ConfigureAwait(false);

            var data     = new byte[requiredSize];
            int readSize = ChunkBuffer.Read(data, 0, requiredSize);

            if (readSize != requiredSize)
            {
                throw new IOException($"Unexpected end of stream, unable to read required data size");
            }

            return(data);
        }
Пример #12
0
            public void CanReadMultipleLines()
            {
                // Arrange
                var buffer = new ChunkBuffer();

                byte[] data = Encoding.UTF8.GetBytes("hel\nlo world\noy");

                // Act
                buffer.Add(data, data.Length);

                // Assert
                Assert.Equal("hel", buffer.ReadLine());
                Assert.Equal("lo world", buffer.ReadLine());
                Assert.Null(buffer.ReadLine());
            }
Пример #13
0
 public void WillCompleteNewLine()
 {
     // Arrange
     var buffer = new ChunkBuffer();
     byte[] data = Encoding.UTF8.GetBytes("hello");
     buffer.Add(data, data.Length);
     Assert.Null(buffer.ReadLine());
     data = Encoding.UTF8.GetBytes("\n");
     buffer.Add(data, data.Length);
     Assert.Equal("hello", buffer.ReadLine());
     data = Encoding.UTF8.GetBytes("Another line");
     buffer.Add(data, data.Length);
     Assert.Null(buffer.ReadLine());
     data = Encoding.UTF8.GetBytes("\nnext");
     buffer.Add(data, data.Length);
     Assert.Equal("Another line", buffer.ReadLine());
 }
Пример #14
0
            public void WillCompleteNewLine()
            {
                // Arrange
                var buffer = new ChunkBuffer();

                byte[] data = Encoding.UTF8.GetBytes("hello");
                buffer.Add(data, data.Length);
                Assert.Null(buffer.ReadLine());
                data = Encoding.UTF8.GetBytes("\n");
                buffer.Add(data, data.Length);
                Assert.Equal("hello", buffer.ReadLine());
                data = Encoding.UTF8.GetBytes("Another line");
                buffer.Add(data, data.Length);
                Assert.Null(buffer.ReadLine());
                data = Encoding.UTF8.GetBytes("\nnext");
                buffer.Add(data, data.Length);
                Assert.Equal("Another line", buffer.ReadLine());
            }
Пример #15
0
        private async Task PopulateChunkBufferAsync(int requiredSize = Constants.ChunkBufferSize)
        {
            if (ChunkBufferRemaining >= requiredSize)
            {
                return;
            }

            ChunkBufferTrimUsedData();

            long storedPosition = ChunkBuffer.Position;
            int  numBytesRead   = 0;

            requiredSize = requiredSize - (int)ChunkBufferRemaining;
            int bufferSize = Math.Max(Constants.ChunkBufferSize, requiredSize);

            byte[] data = new byte[bufferSize];

            ChunkBuffer.Position = ChunkBuffer.Length;

            while (requiredSize > 0)
            {
                numBytesRead = await InputStream.ReadWithTimeoutAsync(data, 0, bufferSize, (int)_readTimeoutMs).ConfigureAwait(false);

                if (numBytesRead <= 0)
                {
                    break;
                }

                ChunkBuffer.Write(data, 0, numBytesRead);
                requiredSize -= numBytesRead;
            }

            ChunkBuffer.Position = storedPosition; //Restore the chunkbuffer state so that any reads can continue

            if (ChunkBuffer.Length == 0)           //No data so stop
            {
                throw new IOException($"Unexpected end of stream, unable to read expected data from the network connection");
            }
        }
Пример #16
0
 public ZeroCopyingRpcOutputBufferStream( ChunkBuffer chunks )
 {
     this._chunks = chunks;
 }
Пример #17
0
 public ChunkBuffer ReallocateReceivingBuffer( ChunkBuffer oldBuffer, long requestedLength, ReceivingContext context )
 {
     return ChunkBuffer.CreateDefault();
 }
Пример #18
0
        public void Render(Structure structure, int x, int y, int z, BlockAtlas blockAtlas, ChunkBuffer vbi)
        {
            var block     = structure[x, y, z];
            var blockData = blockAtlas[block.Id];
            var tex       = blockData.Textures[0];

            var tc00 = new Uv(0, 0);
            var tc10 = new Uv(1, 0);
            var tc01 = new Uv(0, 1);
            var tc11 = new Uv(1, 1);

            if (tex != null)
            {
                var d = 0.0002f;                 // bleed compensation
                tc00 = new Uv(tex.MinU + d, tex.MinV + d);
                tc10 = new Uv(tex.MaxU - d, tex.MinV + d);
                tc01 = new Uv(tex.MinU + d, tex.MaxV - d);
                tc11 = new Uv(tex.MaxU - d, tex.MaxV - d);
            }

            var norm = (Vector3.UnitX + Vector3.UnitZ).Normalized();

            vbi.Append(new Vertex(x, y, z + 1), new Vertex(norm.X, norm.Y, norm.Z), tc01);
            vbi.Append(new Vertex(x + 1, y, z), new Vertex(norm.X, norm.Y, norm.Z), tc11);
            vbi.Append(new Vertex(x + 1, y + 1, z), new Vertex(norm.X, norm.Y, norm.Z), tc10);
            vbi.Append(new Vertex(x, y + 1, z + 1), new Vertex(norm.X, norm.Y, norm.Z), tc00);

            norm = (Vector3.UnitX - Vector3.UnitZ).Normalized();
            vbi.Append(new Vertex(x, y, z), new Vertex(norm.X, norm.Y, norm.Z), tc01);
            vbi.Append(new Vertex(x + 1, y, z + 1), new Vertex(norm.X, norm.Y, norm.Z), tc11);
            vbi.Append(new Vertex(x + 1, y + 1, z + 1), new Vertex(norm.X, norm.Y, norm.Z), tc10);
            vbi.Append(new Vertex(x, y + 1, z), new Vertex(norm.X, norm.Y, norm.Z), tc00);
        }
 public AsyncStreamReader(Stream stream, Connection connection, Action initializeCallback, Action<Exception> errorCallback)
 {
     _initializeCallback = initializeCallback;
     _errorCallback = errorCallback;
     _stream = stream;
     _connection = connection;
     _buffer = new ChunkBuffer();
 }
 private static BufferFeeding FeedingNotRequired( ChunkBuffer buffer, int? expectedLength, object context )
 {
     Assert.Fail( "Feeding must not required." );
     return default( BufferFeeding );
 }
Пример #21
0
 public AsyncStreamReader(Stream stream, Connection connection, Action initializeCallback, Action closeCallback)
 {
     _initializeCallback = initializeCallback;
     _closeCallback = closeCallback;
     _stream = stream;
     _connection = connection;
     _buffer = new ChunkBuffer();
 }
 private static ChunkBuffer ReallocationNotRequired( ChunkBuffer oldBuffer, long requestLength, object context )
 {
     Assert.Fail( "Reallocation must not required." );
     return default( ChunkBuffer );
 }
Пример #23
0
        public static void Render(Structure structure, int x, int y, int z, BlockAtlas blockAtlas, ChunkBuffer vbi, int pass)
        {
            var block      = structure[x, y, z];
            var renderType = blockAtlas[block.Id].Properties.Render;

            if (!VertexProducers.TryGetValue(renderType, out var producer))
            {
                return;
            }

            if (producer.ShouldRenderInPass(pass))
            {
                producer.Render(structure, x, y, z, blockAtlas, vbi);
            }
        }
Пример #24
0
 protected virtual ChunkBuffer ReallocateReceivingBufferCore( ChunkBuffer oldBuffer, long requestedLength, ReceivingContext context )
 {
     return ChunkBuffer.CreateDefault( context.SessionContext.Options.BufferSegmentCount ?? 1, context.SessionContext.Options.BufferSegmentSize ?? ChunkBuffer.DefaultSegmentSize );
 }
Пример #25
0
 ChunkBuffer ITransportReceiveHandler.ReallocateReceivingBuffer( ChunkBuffer oldBuffer, long requestedLength, ReceivingContext context )
 {
     return this.ReallocateReceivingBufferCore( oldBuffer, requestedLength, context );
 }
Пример #26
0
        public void Render(Structure structure, int x, int y, int z, BlockAtlas blockAtlas, ChunkBuffer vbi)
        {
            var block     = structure[x, y, z];
            var blockData = blockAtlas[block.Id];
            var tex       = blockData.Textures[0];

            Uv       tc00, tc10, tc01, tc11;
            TexCoord front, back, left, right;

            front = back = left = right = blockData.Textures[1];

            var top    = blockData.Textures[0];
            var bottom = blockData.Textures[2];

            const float d = 0.0002f;             // bleed compensation

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.PosX, blockAtlas))
            {
                CreateUv(right, d, out tc00, out tc10, out tc01, out tc11);

                vbi.Append(new Vertex(x + 1, y + 1, z), new Vertex(FaceDir.PosX), tc00);
                vbi.Append(new Vertex(x + 1, y + 1, z + 1), new Vertex(FaceDir.PosX), tc10);
                vbi.Append(new Vertex(x + 1, y, z + 1), new Vertex(FaceDir.PosX), tc11);
                vbi.Append(new Vertex(x + 1, y, z), new Vertex(FaceDir.PosX), tc01);
            }

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.NegX, blockAtlas))
            {
                CreateUv(left, d, out tc00, out tc10, out tc01, out tc11);

                vbi.Append(new Vertex(x, y, z), new Vertex(FaceDir.NegX), tc01);
                vbi.Append(new Vertex(x, y, z + 1), new Vertex(FaceDir.NegX), tc11);
                vbi.Append(new Vertex(x, y + 1, z + 1), new Vertex(FaceDir.NegX), tc10);
                vbi.Append(new Vertex(x, y + 1, z), new Vertex(FaceDir.NegX), tc00);
            }

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.PosY, blockAtlas))
            {
                CreateUv(top, d, out tc00, out tc10, out tc01, out tc11);

                vbi.Append(new Vertex(x, y + 1, z + 1), new Vertex(FaceDir.PosY), tc00);
                vbi.Append(new Vertex(x + 1, y + 1, z + 1), new Vertex(FaceDir.PosY), tc10);
                vbi.Append(new Vertex(x + 1, y + 1, z), new Vertex(FaceDir.PosY), tc11);
                vbi.Append(new Vertex(x, y + 1, z), new Vertex(FaceDir.PosY), tc01);
            }

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.NegY, blockAtlas))
            {
                CreateUv(bottom, d, out tc00, out tc10, out tc01, out tc11);

                vbi.Append(new Vertex(x, y, z), new Vertex(FaceDir.NegY), tc01);
                vbi.Append(new Vertex(x + 1, y, z), new Vertex(FaceDir.NegY), tc11);
                vbi.Append(new Vertex(x + 1, y, z + 1), new Vertex(FaceDir.NegY), tc10);
                vbi.Append(new Vertex(x, y, z + 1), new Vertex(FaceDir.NegY), tc00);
            }

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.PosZ, blockAtlas))
            {
                CreateUv(back, d, out tc00, out tc10, out tc01, out tc11);

                vbi.Append(new Vertex(x, y, z + 1), new Vertex(FaceDir.PosZ), tc01);
                vbi.Append(new Vertex(x + 1, y, z + 1), new Vertex(FaceDir.PosZ), tc11);
                vbi.Append(new Vertex(x + 1, y + 1, z + 1), new Vertex(FaceDir.PosZ), tc10);
                vbi.Append(new Vertex(x, y + 1, z + 1), new Vertex(FaceDir.PosZ), tc00);
            }

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.NegZ, blockAtlas))
            {
                CreateUv(front, d, out tc00, out tc10, out tc01, out tc11);

                vbi.Append(new Vertex(x, y + 1, z), new Vertex(FaceDir.NegZ), tc00);
                vbi.Append(new Vertex(x + 1, y + 1, z), new Vertex(FaceDir.NegZ), tc10);
                vbi.Append(new Vertex(x + 1, y, z), new Vertex(FaceDir.NegZ), tc11);
                vbi.Append(new Vertex(x, y, z), new Vertex(FaceDir.NegZ), tc01);
            }
        }
Пример #27
0
        public void Render(Structure structure, int x, int y, int z, BlockAtlas blockAtlas, ChunkBuffer vbi)
        {
            var block     = structure[x, y, z];
            var blockData = blockAtlas[block.Id];
            var tex       = blockData.Textures[0];

            var tc00 = new Uv(0, 0);
            var tc10 = new Uv(1, 0);
            var tc01 = new Uv(0, 1);
            var tc11 = new Uv(1, 1);

            if (tex != null)
            {
                var d = 0.0002f;                 // bleed compensation
                tc00 = new Uv(tex.MinU + d, tex.MinV + d);
                tc10 = new Uv(tex.MaxU - d, tex.MinV + d);
                tc01 = new Uv(tex.MinU + d, tex.MaxV - d);
                tc11 = new Uv(tex.MaxU - d, tex.MaxV - d);
            }

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.PosX, blockAtlas))
            {
                vbi.Append(new Vertex(x + 1, y + 1, z), new Vertex(FaceDir.PosX), tc00);
                vbi.Append(new Vertex(x + 1, y + 1, z + 1), new Vertex(FaceDir.PosX), tc10);
                vbi.Append(new Vertex(x + 1, y, z + 1), new Vertex(FaceDir.PosX), tc11);
                vbi.Append(new Vertex(x + 1, y, z), new Vertex(FaceDir.PosX), tc01);
            }

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.NegX, blockAtlas))
            {
                vbi.Append(new Vertex(x, y, z), new Vertex(FaceDir.NegX), tc01);
                vbi.Append(new Vertex(x, y, z + 1), new Vertex(FaceDir.NegX), tc11);
                vbi.Append(new Vertex(x, y + 1, z + 1), new Vertex(FaceDir.NegX), tc10);
                vbi.Append(new Vertex(x, y + 1, z), new Vertex(FaceDir.NegX), tc00);
            }

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.PosY, blockAtlas))
            {
                vbi.Append(new Vertex(x, y + 1, z + 1), new Vertex(FaceDir.PosY), tc00);
                vbi.Append(new Vertex(x + 1, y + 1, z + 1), new Vertex(FaceDir.PosY), tc10);
                vbi.Append(new Vertex(x + 1, y + 1, z), new Vertex(FaceDir.PosY), tc11);
                vbi.Append(new Vertex(x, y + 1, z), new Vertex(FaceDir.PosY), tc01);
            }

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.NegY, blockAtlas))
            {
                vbi.Append(new Vertex(x, y, z), new Vertex(FaceDir.NegY), tc01);
                vbi.Append(new Vertex(x + 1, y, z), new Vertex(FaceDir.NegY), tc11);
                vbi.Append(new Vertex(x + 1, y, z + 1), new Vertex(FaceDir.NegY), tc10);
                vbi.Append(new Vertex(x, y, z + 1), new Vertex(FaceDir.NegY), tc00);
            }

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.PosZ, blockAtlas))
            {
                vbi.Append(new Vertex(x, y, z + 1), new Vertex(FaceDir.PosZ), tc01);
                vbi.Append(new Vertex(x + 1, y, z + 1), new Vertex(FaceDir.PosZ), tc11);
                vbi.Append(new Vertex(x + 1, y + 1, z + 1), new Vertex(FaceDir.PosZ), tc10);
                vbi.Append(new Vertex(x, y + 1, z + 1), new Vertex(FaceDir.PosZ), tc00);
            }

            if (structure.IsBorderingTransparent(x, y, z, FaceDir.NegZ, blockAtlas))
            {
                vbi.Append(new Vertex(x, y + 1, z), new Vertex(FaceDir.NegZ), tc00);
                vbi.Append(new Vertex(x + 1, y + 1, z), new Vertex(FaceDir.NegZ), tc10);
                vbi.Append(new Vertex(x + 1, y, z), new Vertex(FaceDir.NegZ), tc11);
                vbi.Append(new Vertex(x, y, z), new Vertex(FaceDir.NegZ), tc01);
            }
        }