Ejemplo n.º 1
0
        //-----------------------------------------------------------------------------------------
        //Our rendering function
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            GL.Enable(EnableCap.Blend);
            GL.BlendEquation(BlendEquationMode.FuncAdd);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            //           Matrix4 mvp = _projectionMatrix * ... * Matrix4.Identity;
            //Matrix4 mvp = GetTransform();
            //mvp.Transpose();

            GL.BindBuffer(BufferTarget.UniformBuffer, Buffers.Name(Buffers.Type.TRANSFORM));
            //GL.BufferSubData( BufferTarget.UniformBuffer, IntPtr.Zero, (IntPtr)(sizeof(float) * 16), ref mvp.Row0.X );
            GL.BufferSubData(BufferTarget.UniformBuffer, IntPtr.Zero, (IntPtr)(sizeof(float) * 16), GetTransform());

            uint data = 0;

            GL.BindBuffer(BufferTarget.AtomicCounterBuffer, Buffers.Name(Buffers.Type.ATOMIC_COUNTER));
            GL.ClearBufferSubData(BufferTarget.AtomicCounterBuffer, PixelInternalFormat.R8ui, IntPtr.Zero, (IntPtr)sizeof(uint),
                                  PixelFormat.Rgba, All.UnsignedInt, (IntPtr)data);

            GL.ViewportIndexed(0, 0, 0, ClientRectangle.X, ClientRectangle.Y);
            GL.ClearBuffer(ClearBuffer.Color, 0, new float[] { 0.0f, 0.0f, 0.0f, 1.0f });

            GL.UseProgram(_programName);
            GL.BindVertexArray(_vertexArrayName);
            GL.BindBufferBase(BufferRangeTarget.AtomicCounterBuffer, 0, Buffers.Name(Buffers.Type.ATOMIC_COUNTER));
            GL.BindBufferBase(BufferRangeTarget.UniformBuffer, (int)Bindings.TRANSFORM0, Buffers.Name(Buffers.Type.TRANSFORM));

            GL.DrawElementsInstancedBaseVertexBaseInstance(PrimitiveType.Triangles, _ElementData.Length,
                                                           DrawElementsType.UnsignedShort, (IntPtr)0,
                                                           5, 0, 0);
            SwapBuffers();
        }
Ejemplo n.º 2
0
        public static void ReadFromStream(this Buffers toBuffer, Stream fromStream)
        {
            if (fromStream.Position == fromStream.Length)
            {
                return;
            }

            int count = toBuffer.BufferCapacity - sizeof(long);
            int numRead;

            do
            {
                var buffer = toBuffer.GetMemory();
#if DEBUGOUTPUT
                var position = fromStream.Position;
#endif
                buffer.WriteLong(fromStream.Position);

                numRead = buffer.ReadFromSetLen(fromStream, count);

                if (numRead > 0)
                {
                    toBuffer.EnqueueBuffer(buffer);
                }
#if DEBUGOUTPUT
                ThreadMessage($"{position} : {numRead}");
#endif
            }while (numRead > 0 && numRead == count);
        }
Ejemplo n.º 3
0
        public Record(byte version, RecordType type, ushort requestID,
                      byte [] bodyData, int bodyIndex, int bodyLength) : this()
        {
            if (bodyData == null)
            {
                throw new ArgumentNullException("bodyData");
            }

            if (bodyIndex < 0 || bodyIndex > bodyData.Length)
            {
                throw new ArgumentOutOfRangeException(
                          "bodyIndex");
            }

            if (bodyLength < 0)
            {
                bodyLength = bodyData.Length - bodyIndex;
            }

            if (bodyLength > 0xFFFF)
            {
                throw new ArgumentException(
                          Strings.Record_DataTooBig,
                          "bodyLength");
            }


            this.version = version;
            this.type    = type;
            request_id   = requestID;
            buffers      = new Buffers(bodyData, bodyIndex, bodyLength);
            BodyLength   = (ushort)bodyLength;
        }
Ejemplo n.º 4
0
        public static void ReadFromCompressedStream(this Buffers toBuffer, Stream fromStream)
        {
            int numRead = 0;
            int chunckSize;

            do
            {
                MemoryStream memBytes = toBuffer.GetMemory();

                //read length of block
                var position = fromStream.Position;
                chunckSize = (int)fromStream.ReadLong();

                if (chunckSize > 0)
                {
                    numRead = memBytes.ReadFromSetLen(fromStream, chunckSize);

                    if (numRead > 0)
                    {
                        toBuffer.EnqueueBuffer(memBytes);
                    }

                    ThreadMessage($"{position} : {chunckSize}");
                }
            }while (chunckSize > 0 && numRead > 0);
        }
Ejemplo n.º 5
0
        public IBuffers Create <T>(int width, int height)
            where T : IFrameBuffer, new()
        {
            var buffers = new Buffers <T>(width, height);

            return(buffers);
        }
Ejemplo n.º 6
0
        protected void Send(EndPoint endpoint, byte[] data)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            SocketAsyncEventArgs args = Arguments.Retrieve();

            args.Completed     += Sent;
            args.RemoteEndPoint = endpoint;
            byte[] buffer = Buffers.Retrieve();
            int    length = Math.Min(data.Length, buffer.Length);

            args.SetBuffer(buffer, 0, length);
            Array.Copy(data, args.Buffer, length);
            try {
                if (!Socket.SendToAsync(args))
                {
                    Sent(Socket, args);
                }
            } catch (Exception ex) {
                args.Completed     -= Sent;
                args.RemoteEndPoint = null;
                Buffers.Return(buffer);
                args.SetBuffer(NO_BUFFER, 0, 0);
                Arguments.Return(args);
                Caught(endpoint, ex);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Performs a beam search decoding the logits.
        /// </summary>
        /// <param name="y">The logits that have been predicted.</param>
        /// <returns>The collection of decoded class sequences along with their weights.</returns>
        public IList <(string[] Classes, float Probability)> BeamSearch(Tensor y)
        {
            if (y == null)
            {
                throw new ArgumentNullException(nameof(y));
            }

#pragma warning disable SA1312          // Variable names must begin with lower-case letter
            int T = y.Shape.Axes[0];    // Number of mini-batches (time)
            int A = y.Shape.Strides[0]; // Number of classes (alphabet size)
#pragma warning restore SA1312          // Variable names must begin with lower-case letter

            // allocate buffers
            BufferManager manager = new BufferManager(T, 2 * this.BufferCount);

            Buffers flip = new Buffers(manager, this.BufferCount);
            Buffers flop = new Buffers(manager, this.BufferCount);

            // convert predicted probabilities into log space
            float[] ylog = new float[y.Length];
            Vectors.Log(y.Length, y.Weights, 0, ylog, 0);

            // run algoritm
            if (this.languageModel != null)
            {
                flop = this.BeamSearch(flip, flop, T, A, ylog, this.languageModel);
            }
            else
            {
                flop = this.BeamSearch(flip, flop, T, A, ylog);
            }

            return(this.CreateFinalAnswer(flop));
        }
 public AsynchronousSocketClient()
 {
     this.Reader   = new DefaultReader(this);
     this.Writer   = new DefaultWriter(this);
     this.Buffers  = new Buffers(BufferPoolSize, MaxBufferSize);
     this.MsgQueue = new MessageQueue();
 }
Ejemplo n.º 9
0
        private void ValidateMagic()
        {
            var startingPosition = BaseStream.Position;
            var magicLength      = ArrowFileConstants.Magic.Length;

            try
            {
                Buffers.RentReturn(magicLength, buffer =>
                {
                    // Seek to the beginning of the stream
                    BaseStream.Position = 0;

                    // Read beginning of stream
                    BaseStream.Read(buffer);

                    VerifyMagic(buffer);

                    // Move stream position to magic-length bytes away from the end of the stream
                    BaseStream.Position = BaseStream.Length - magicLength;

                    // Read the end of the stream
                    BaseStream.Read(buffer);

                    VerifyMagic(buffer);
                });
            }
            finally
            {
                BaseStream.Position = startingPosition;
            }
        }
Ejemplo n.º 10
0
        private async ValueTask ValidateMagicAsync()
        {
            var startingPosition = BaseStream.Position;
            var magicLength      = ArrowFileConstants.Magic.Length;

            try
            {
                await Buffers.RentReturnAsync(magicLength, async (buffer) =>
                {
                    // Seek to the beginning of the stream
                    BaseStream.Position = 0;

                    // Read beginning of stream
                    await BaseStream.ReadAsync(buffer).ConfigureAwait(false);

                    VerifyMagic(buffer);

                    // Move stream position to magic-length bytes away from the end of the stream
                    BaseStream.Position = BaseStream.Length - magicLength;

                    // Read the end of the stream
                    await BaseStream.ReadAsync(buffer).ConfigureAwait(false);

                    VerifyMagic(buffer);
                }).ConfigureAwait(false);
            }
            finally
            {
                BaseStream.Position = startingPosition;
            }
        }
Ejemplo n.º 11
0
        public override string ToString()
        {
            var sb = new StringBuilder();

            if (Crane.LocationId == 0)
            {
                sb.AppendLine(Crane.ToString());
            }
            sb.AppendLine(Production.ToString());
            foreach (var b in Buffers.OrderBy(x => x.Id))
            {
                if (Crane.LocationId == b.Id)
                {
                    sb.AppendLine(Crane.ToString());
                }
                sb.AppendLine(b.ToString());
            }
            if (Crane.LocationId == Handover.Id)
            {
                sb.AppendLine(Crane.ToString());
            }
            sb.AppendLine(Handover.ToString());
            sb.AppendLine(KPIs.ToString());
            return(sb.ToString());
        }
Ejemplo n.º 12
0
        void buildMark()
        {
            M = Matrix <double> .Build.Dense(petriNet.Places, 1);

            Buffers.ForEach(b => b.clearConnected());
            //machines and buffers
            for (int m = 0; m < Machines; m++)
            {
                M[firstMachineAddress + m, 0]                 = 1;
                M[firstMachineAddress + Machines + m, 0]      = Buffers.First(i => i.Number == m + 1).Capacity;
                Buffers.First(b => b.Number == m + 1).Address = firstMachineAddress + Machines + m;
            }
            //inputs
            int place = 0;

            foreach (var process in Processes)
            {
                var output = getCorrespondingOutput(process.Number);
                M[place, 0] = Inputs.First(i => i.Number == process.Number).Value;
                Inputs.First(i => i.Number == process.Number).Address             = place;
                Inputs.First(i => i.Number == process.Number).CorrespondingOutput = output;
                place += process.Operations.Count * 3 + 2;
                foreach (var o in process.Operations)
                {
                    Buffers.First(i => i.Number == o.MachineNumber).Connect(process, o.Number);
                }
            }
        }
Ejemplo n.º 13
0
        private void xfer_XferNotify(object sender, SapXferNotifyEventArgs argsNotify)
        {
            try
            {
                var core = argsNotify.Context as DalsaCore;
                if (argsNotify.Trash)
                {
                }
                else
                {
                    //DateTime getStart = DateTime.Now;

                    IntPtr bufferAddress;
                    Buffers.GetAddress(out bufferAddress);
                    Debug.WriteLine(_name + "Dalsa ImgPtr:[" + _id + "]" + bufferAddress + DateTime.Now);

                    var imgInfo = new ImgBytesInfo();
                    imgInfo._imgSrcPtr = bufferAddress;
                    imgInfo._imgBytes  = new byte[ObjSize];
                    imgInfo._imgTicks  = DateTime.Now.Ticks / 10000;
                    Marshal.Copy(bufferAddress, imgInfo._imgBytes, 0, ObjSize);

                    OnDalsaImageArrivedHandle(imgInfo);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 14
0
 //-----------------------------------------------------------------------------------------
 protected override void OnUnload(EventArgs e)
 {
     GL.DeleteProgram(_shaderProgramName[0]);
     GL.DeleteProgram(_shaderProgramName[1]);
     GL.DeleteBuffers(Buffers.GetCount(), Buffers.Names);
     GL.DeleteVertexArrays(1, ref _vertexArrayName);
 }
Ejemplo n.º 15
0
        protected void Send(Socket socket, byte[] data, object token)
        {
            if (socket == null)
            {
                throw new ArgumentNullException(nameof(socket));
            }
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            SocketAsyncEventArgs args = Arguments.Retrieve();

            args.Completed += Sent;
            args.UserToken  = token;
            byte[] buffer = Buffers.Retrieve();
            int    length = Math.Min(data.Length, buffer.Length);

            args.SetBuffer(buffer, 0, length);
            Array.Copy(data, args.Buffer, length);
            try {
                if (!socket.SendAsync(args))
                {
                    Sent(socket, args);
                }
            }catch (Exception ex) {
                args.Completed -= Sent;
                args.UserToken  = null;
                Buffers.Return(buffer);
                args.SetBuffer(NO_BUFFER, 0, 0);
                Arguments.Return(args);
                Caught(token, ex);
            }
        }
Ejemplo n.º 16
0
    public void PlayerMove(Int32 x, Int32 z, Int32 ry, Int32 uid, Int32 state)
    {
        // 客户端发送move信息
        msgtemp = new MSG_PLAYER_MOVE();
        Byte[] temp = new byte[1024];
        using (CodedOutputStream cos = new CodedOutputStream(temp))
        {
            //Debug.LogError("Send mov: x = " + x + ", z = " + z + ".");

            msgtemp.Ry       = ry;
            msgtemp.X        = x;
            msgtemp.Z        = z;
            msgtemp.Playerid = uid;
            msgtemp.State    = state;
            msgtemp.WriteTo(cos);
            //Debug.LogError("-------------------------state   " + state);

            //data = cos.to.ToArray();
        }
        Buffers.Encode(data, 1006, uid, msgtemp.CalculateSize()); // 1006 -> player move
        for (int i = 0; i < msgtemp.CalculateSize(); i++)
        {
            data[sizeof(Int32) * 3 + i] = temp[i];
        }
        net_manager.Send(data, 0, sizeof(Int32) * 3 + msgtemp.CalculateSize(), out se);
    }
Ejemplo n.º 17
0
    public void RegistePlayerSelf(Player player, Int32 uid, Int32 ry, Int32 x, Int32 y)
    {
        if (player == null)
        {
            return;
        }
        m_PlayerSelf = player;

        // 客户端发送register信息
        msgRegister      = new MSG_PLAYER_REGISTER();
        msgtemp_register = new MSG_PLAYER_REGISTER();
        Byte[] temp = new byte[1024];
        using (CodedOutputStream cos = new CodedOutputStream(temp))
        {
            msgRegister.Playerid      = uid;
            msgRegister.Ry            = ry;
            msgRegister.Professsional = 0;
            msgRegister.X             = x;
            msgRegister.Z             = y;
            msgRegister.Speed         = 0;
            msgRegister.WriteTo(cos);
            //data = cos.to.ToArray();
        }
        Buffers.Encode(data, 1008, uid, msgRegister.CalculateSize());
        for (int i = 0; i < msgRegister.CalculateSize(); i++)
        {
            data[sizeof(Int32) * 3 + i] = temp[i];
        }
        net_manager.Send(data, 0, sizeof(Int32) * 3 + msgRegister.CalculateSize(), out se);
    }
        public void sampleData()
        {
            clearData();
            Machines        = 3;
            ProcessesAmount = 2;
            for (int p = 0; p < ProcessesAmount; p++)
            {
                var process = new Process(p + 1);
                if (p == 0)
                {
                    process.Operations.Add(new Operation(10, 1, 1, p + 1));
                    process.Operations.Add(new Operation(20, 2, 2, p + 1));
                    process.Operations.Add(new Operation(30, 3, 3, p + 1));
                }
                if (p == 1)
                {
                    process.Operations.Add(new Operation(5, 1, 3, p + 1));
                    process.Operations.Add(new Operation(15, 2, 2, p + 1));
                    process.Operations.Add(new Operation(25, 3, 1, p + 1));
                }
                Processes.Add(process);

                Inputs.Add(new Input(p + 1, p * 2 + 2));
            }
            for (int m = 0; m < Machines; m++)
            {
                Buffers.Add(new Buffer(m + 1, 2));
            }
        }
Ejemplo n.º 19
0
        public static SourceBuffer[] Generate(int count)
        {
            OpenAL.DebugFormat("Generating {0} source buffers", count);

            lock (lck)
            {
                if (Buffers == null)
                {
                    Buffers = new Dictionary <uint, SourceBuffer> (count);
                }

                SourceBuffer[] buffers = new SourceBuffer[count];

                uint[] bufferIDs = new uint[count];
                alGenBuffers(count, bufferIDs);
                OpenAL.ErrorCheck();

                for (int i = 0; i < count; ++i)
                {
                    OpenAL.DebugFormat("Generated source buffer {0}", bufferIDs[i]);

                    buffers[i] = new SourceBuffer(bufferIDs[i]);
                    Buffers.Add(buffers[i].bufferID, buffers[i]);
                }

                return(buffers);
            }
        }
Ejemplo n.º 20
0
        protected override void ReadSchema()
        {
            if (HasReadSchema)
            {
                return;
            }

            ValidateFile();

            int footerLength = 0;

            Buffers.RentReturn(4, (buffer) =>
            {
                BaseStream.Position = GetFooterLengthPosition();

                int bytesRead = BaseStream.ReadFullBuffer(buffer);
                EnsureFullRead(buffer, bytesRead);

                footerLength = ReadFooterLength(buffer);
            });

            Buffers.RentReturn(footerLength, (buffer) =>
            {
                _footerStartPostion = (int)GetFooterLengthPosition() - footerLength;

                BaseStream.Position = _footerStartPostion;

                int bytesRead = BaseStream.ReadFullBuffer(buffer);
                EnsureFullRead(buffer, bytesRead);

                ReadSchema(buffer);
            });
        }
Ejemplo n.º 21
0
        private void renderedControl1_Rendered(object sender, RenderEventArgs e)
        {
            int   tickCount = Environment.TickCount;
            float deltaTime = (tickCount - _previousTickCount) / 1000f;

            _previousTickCount = tickCount;

            _simulator.Update(deltaTime);
            _framesCount++;
            int secondsCount = (tickCount - _startTickCount) / 1000;

            if (secondsCount != 0)
            {
                label.Text = String.Format("FPS: {0}", _framesCount / secondsCount);
            }

            //draw scene
            var render = e.Render;

            render.BeginScene();

            render.Draw(() =>
            {
                _simulator.ActorsFactory.AcceptVisit(_renderingVisitor);
            },
                        Lights.Point(new Vector3(0, 5, -6), new Vector3(1, 1, 1)),
                        Cameras.LookAt(new Vector3(0, 15, -30), new Vector3(0, 0, 0), new Vector3(0, 1, 0)),
                        Cameras.Perspective(render.GetAspectRatio()),
                        Buffers.Clear(0.2f, 0.2f, 0.4f, 1),
                        Buffers.ClearDepth(),
                        Shaders.Phong
                        );
            render.EndScene();
            renderedControl1.Invalidate();
        }
Ejemplo n.º 22
0
        protected override async ValueTask ReadSchemaAsync()
        {
            if (HasReadSchema)
            {
                return;
            }

            await ValidateFileAsync().ConfigureAwait(false);

            int footerLength = 0;
            await Buffers.RentReturnAsync(4, async (buffer) =>
            {
                BaseStream.Position = GetFooterLengthPosition();

                int bytesRead = await BaseStream.ReadFullBufferAsync(buffer).ConfigureAwait(false);
                EnsureFullRead(buffer, bytesRead);

                footerLength = ReadFooterLength(buffer);
            }).ConfigureAwait(false);

            await Buffers.RentReturnAsync(footerLength, async (buffer) =>
            {
                _footerStartPostion = (int)GetFooterLengthPosition() - footerLength;

                BaseStream.Position = _footerStartPostion;

                int bytesRead = await BaseStream.ReadFullBufferAsync(buffer).ConfigureAwait(false);
                EnsureFullRead(buffer, bytesRead);

                ReadSchema(buffer);
            }).ConfigureAwait(false);
        }
Ejemplo n.º 23
0
        public void ReadBuffers(byte[] memory)
        {
            Buffers X = new Buffers();

            X.Wireframe1 = new byte[4];
            byte[] buffer = new byte[20];
            int[]  output = new int[3];
            for (int i = 0; i < 20; i++)
            {
                buffer[i]  = memory[readerpos];
                readerpos += 1;
            }
            output[0]     = BitConverter.ToInt32(buffer, 0);
            X.UV1         = output[0];
            output[1]     = BitConverter.ToInt32(buffer, 4);
            X.UV2         = output[1];
            output[2]     = BitConverter.ToInt32(buffer, 8);
            X.IndexBuffer = output[2];
            int counter = 0;

            for (int i = 12; i < 16; i++)
            {
                X.Wireframe1[counter] = buffer[i];
                counter += 1;
            }
            ;
            X.Wireframe2 = new byte[4];
            counter      = 0;
            for (int i = 16; i < 20; i++)
            {
                X.Wireframe2[counter] = buffer[i];
                counter += 1;
            }
            Mesh.Buffers = X;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Read in-memory buckets combined in a single buffer
        /// </summary>
        /// <param name="bucket"></param>
        /// <param name="bufferSize"></param>
        /// <param name="requested"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static async ValueTask <BucketBytes> ReadCombinedAsync(this Bucket bucket, int bufferSize, int requested = int.MaxValue)
        {
            if (bucket is null)
            {
                throw new ArgumentNullException(nameof(bucket));
            }
            else if (bucket is IBucketReadBuffers iov)
            {
                var(Buffers, Done) = await iov.ReadBuffersAsync(bufferSize).ConfigureAwait(false);

                int bytes = (Buffers.Length > 0) ? Buffers.Sum(x => x.Length) : 0;

                if (bytes > 0)
                {
                    byte[] buffer = new byte[bytes];
                    int    pos    = 0;

                    foreach (var v in Buffers)
                    {
                        v.CopyTo(new Memory <byte>(buffer, pos, v.Length));
                        pos += v.Length;
                    }

                    return(buffer);
                }
            }

            return(await bucket.ReadAsync(requested).ConfigureAwait(false));
        }
Ejemplo n.º 25
0
    static public Buffers Get()
    {
        if (instance != null)
        {
            if (instance.transform != null)
            {
                return(instance);
            }
            else
            {
                instance = null;
            }
        }

        foreach (Buffers root in Object.FindObjectsOfType(typeof(Buffers)))
        {
            instance = root;

            return(instance);
        }


        LightingManager2D manager = LightingManager2D.Get();

        GameObject gameObject = new GameObject();

        gameObject.transform.parent = manager.transform;
        gameObject.name             = "Buffers";

        instance = gameObject.AddComponent <Buffers> ();
        instance.GetCamera();
        instance.UpdateFlags();

        return(instance);
    }
Ejemplo n.º 26
0
        private async Task <XmlNodeStartTag> readXmlNodeStartTag()
        {
            int             nsRef           = buffer.getInt();
            int             nameRef         = buffer.getInt();
            XmlNodeStartTag xmlNodeStartTag = new XmlNodeStartTag();

            if (nsRef > 0)
            {
                xmlNodeStartTag.setNamespace(stringPool.get(nsRef));
            }
            xmlNodeStartTag.setName(stringPool.get(nameRef));

            // read attributes.
            // attributeStart and attributeSize are always 20 (0x14)
            int attributeStart = await Buffers.readUShort(buffer);

            int attributeSize = await Buffers.readUShort(buffer);

            int attributeCount = await Buffers.readUShort(buffer);

            int idIndex = await Buffers.readUShort(buffer);

            int classIndex = await Buffers.readUShort(buffer);

            int styleIndex = await Buffers.readUShort(buffer);

            // read attributes
            Attributes attributes = new Attributes(attributeCount);

            for (int count = 0; count < attributeCount; count++)
            {
                Attribute_ attribute = await readAttribute();

                if (xmlStreamer != null)
                {
                    string value = attribute.toStringValue(resourceTable, locale);
                    if (intAttributes.Contains(attribute.getName()) && Utils.isNumeric(value))
                    {
                        try
                        {
                            value = getFinalValueAsString(attribute.getName(), value);
                        }
                        catch
                        {
                            //ignore exception
                        }
                    }
                    attribute.setValue(value);
                    attributes.set(count, attribute);
                }
            }
            xmlNodeStartTag.setAttributes(attributes);

            if (xmlStreamer != null)
            {
                xmlStreamer.onStartTag(xmlNodeStartTag);
            }

            return(xmlNodeStartTag);
        }
Ejemplo n.º 27
0
        public Workspace(
            string[] usings             = null,
            File[] files                = null,
            Buffer[] buffers            = null,
            string workspaceType        = DefaultWorkspaceType,
            bool includeInstrumentation = false)
        {
            WorkspaceType = workspaceType ?? DefaultWorkspaceType;
            Usings        = usings ?? Array.Empty <string>();
            Usings        = usings ?? Array.Empty <string>();
            Files         = files ?? Array.Empty <File>();
            Buffers       = buffers ?? Array.Empty <Buffer>();

            IncludeInstrumentation = includeInstrumentation;

            if (Files.Distinct().Count() != Files.Length)
            {
                throw new ArgumentException($"Duplicate file names:{Environment.NewLine}{string.Join(Environment.NewLine, Files.Select(f => f.Name))}");
            }

            if (Buffers.Distinct().Count() != Buffers.Length)
            {
                throw new ArgumentException($"Duplicate buffer ids:{Environment.NewLine}{string.Join(Environment.NewLine, Buffers.Select(b => b.Id))}");
            }
        }
Ejemplo n.º 28
0
    static public LightingMainBuffer2D Get(CameraSettings cameraSettings)
    {
        if (cameraSettings.GetCamera() == null)
        {
            return(null);
        }

        foreach (LightingMainBuffer2D mainBuffer in List)
        {
            if (mainBuffer.cameraSettings.GetCamera() == cameraSettings.GetCamera() && mainBuffer.cameraSettings.bufferID == cameraSettings.bufferID)
            {
                return(mainBuffer);
            }
        }

        if (Lighting2D.BufferPresets.Length <= cameraSettings.bufferID)
        {
            Debug.LogWarning("Lighting2D: Not enough buffer settings initialized");

            return(null);
        }

        Buffers.Get();

        LightingMainBuffer2D buffer = new LightingMainBuffer2D();

        buffer.cameraSettings = cameraSettings;

        Rendering.LightingMainBuffer.InitializeRenderTexture(buffer);

        return(buffer);
    }
Ejemplo n.º 29
0
        private void WriteFooter(Schema schema)
        {
            Builder.Clear();

            long offset = BaseStream.Position;

            // Serialize the schema

            FlatBuffers.Offset <Flatbuf.Schema> schemaOffset = SerializeSchema(schema);

            // Serialize all record batches

            Flatbuf.Footer.StartRecordBatchesVector(Builder, RecordBatchBlocks.Count);

            // flatbuffer struct vectors have to be created in reverse order
            for (int i = RecordBatchBlocks.Count - 1; i >= 0; i--)
            {
                Block recordBatch = RecordBatchBlocks[i];
                Flatbuf.Block.CreateBlock(
                    Builder, recordBatch.Offset, recordBatch.MetadataLength, recordBatch.BodyLength);
            }

            FlatBuffers.VectorOffset recordBatchesVectorOffset = Builder.EndVector();

            // Serialize all dictionaries
            // NOTE: Currently unsupported.

            Flatbuf.Footer.StartDictionariesVector(Builder, 0);

            FlatBuffers.VectorOffset dictionaryBatchesOffset = Builder.EndVector();

            // Serialize and write the footer flatbuffer

            FlatBuffers.Offset <Flatbuf.Footer> footerOffset = Flatbuf.Footer.CreateFooter(Builder, CurrentMetadataVersion,
                                                                                           schemaOffset, dictionaryBatchesOffset, recordBatchesVectorOffset);

            Builder.Finish(footerOffset.Value);

            WriteFlatBuffer();

            // Write footer length

            Buffers.RentReturn(4, (buffer) =>
            {
                int footerLength;
                checked
                {
                    footerLength = (int)(BaseStream.Position - offset);
                }

                BinaryPrimitives.WriteInt32LittleEndian(buffer.Span, footerLength);

                BaseStream.Write(buffer);
            });

            // Write magic

            WriteMagic();
        }
Ejemplo n.º 30
0
        public void parse()
        {
            // read magic
            string magic = Encoding.UTF8.GetString(Buffers.readBytes(buffer, 8)); //new string(Buffers.readBytes(buffer, 8));

            if (!magic.StartsWith("dex\n"))
            {
                return;
            }
            int version = int.Parse(magic.Substring(4, 7));

            // now the version is 035
            if (version < 35)
            {
                // version 009 was used for the M3 releases of the Android platform (November–December 2007),
                // and version 013 was used for the M5 releases of the Android platform (February–March 2008)
                throw new Exception("Dex file version: " + version + " is not supported");
            }

            // read header
            DexHeader header = readDexHeader();

            header.setVersion(version);

            // read string pool
            long[] stringOffsets = readStringPool(header.getStringIdsOff(), header.getStringIdsSize());

            // read types
            int[] typeIds = readTypes(header.getTypeIdsOff(), header.getTypeIdsSize());

            // read classes
            DexClassStruct[] dexClassStructs = readClass(header.getClassDefsOff(),
                                                         header.getClassDefsSize());

            StringPool stringpool = readStrings(stringOffsets);

            string[] types = new string[typeIds.Length];
            for (int i = 0; i < typeIds.Length; i++)
            {
                types[i] = stringpool.get(typeIds[i]);
            }

            dexClasses = new DexClass[dexClassStructs.Length];
            for (int i = 0; i < dexClasses.Length; i++)
            {
                dexClasses[i] = new DexClass();
            }
            for (int i = 0; i < dexClassStructs.Length; i++)
            {
                DexClassStruct dexClassStruct = dexClassStructs[i];
                DexClass       dexClass       = dexClasses[i];
                dexClass.setClassType(types[dexClassStruct.getClassIdx()]);
                if (dexClassStruct.getSuperclassIdx() != NO_INDEX)
                {
                    dexClass.setSuperClass(types[dexClassStruct.getSuperclassIdx()]);
                }
                dexClass.setAccessFlags(dexClassStruct.getAccessFlags());
            }
        }
Ejemplo n.º 31
0
        Buffers Load(Renderable renderable)
        {
            int size;

            Buffers buf = new Buffers();
            var shape = renderable.Shape;

            GL.GenBuffers(1, out buf.vertex_buffer_object);
            GL.GenBuffers(1, out buf.color_buffer_object);
            GL.GenBuffers(1, out buf.element_buffer_object);
            GL.GenBuffers(1, out buf.normal_buffer_object);
            GL.GenBuffers(1, out buf.tex_buffer_object);

            // Upload the vertex buffer.
            GL.BindBuffer(BufferTarget.ArrayBuffer, buf.vertex_buffer_object);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(shape.Vertices.Length * 3 * sizeof(float)), shape.Vertices,
                BufferUsageHint.StaticDraw);
            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (size != shape.Vertices.Length * 3 * sizeof(Single))
                throw new ApplicationException(String.Format(
                    "Problem uploading vertex buffer to VBO (vertices). Tried to upload {0} bytes, uploaded {1}.",
                    shape.Vertices.Length * 3 * sizeof(Single), size));

            // Upload the color buffer.
            GL.BindBuffer(BufferTarget.ArrayBuffer, buf.color_buffer_object);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(shape.Colors.Length * sizeof(int)), shape.Colors,
                BufferUsageHint.StaticDraw);
            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (size != shape.Colors.Length * sizeof(int))
                throw new ApplicationException(String.Format(
                    "Problem uploading vertex buffer to VBO (colors). Tried to upload {0} bytes, uploaded {1}.",
                    shape.Colors.Length * sizeof(int), size));

            // Upload the index buffer (elements inside the vertex buffer, not color indices as per the IndexPointer function!)
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, buf.element_buffer_object);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(shape.Indices.Length * sizeof(Int32)), shape.Indices,
                BufferUsageHint.StaticDraw);
            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (size != shape.Indices.Length * sizeof(int))
                throw new ApplicationException(String.Format(
                    "Problem uploading vertex buffer to VBO (offsets). Tried to upload {0} bytes, uploaded {1}.",
                    shape.Indices.Length * sizeof(int), size));

            GL.BindBuffer(BufferTarget.ArrayBuffer, buf.normal_buffer_object);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(shape.Normals.Length * 3 * sizeof(float)), shape.Normals,
                BufferUsageHint.StaticDraw);
            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (size != shape.Normals.Length * sizeof(float) * 3)
                throw new ApplicationException(String.Format(
                    "Problem uploading vertex buffer to VBO (offsets). Tried to upload {0} bytes, uploaded {1}.",
                    shape.Normals.Length * sizeof(float) * 3, size));

            GL.BindBuffer(BufferTarget.ArrayBuffer, buf.tex_buffer_object);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(shape.Texcoords.Length * 2 * sizeof(float)), shape.Texcoords,
                BufferUsageHint.StaticDraw);
            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (size != shape.Texcoords.Length * sizeof(float) * 2)
                throw new ApplicationException(String.Format(
                    "Problem uploading vertex buffer to VBO (offsets). Tried to upload {0} bytes, uploaded {1}.",
                    shape.Texcoords.Length * sizeof(float) * 2, size));

            return buf;
        }
Ejemplo n.º 32
0
 public void ReadBuffers(byte[] memory)
 {
     Buffers X = new Buffers();
     X.Wireframe1 = new byte[4];
     byte[] buffer = new byte[20];
     int[] output = new int[3];
     for (int i = 0; i < 20; i++)
     {
         buffer[i] = memory[readerpos];
         readerpos += 1;
     }
     output[0] = BitConverter.ToInt32(buffer, 0);
     X.UV1 = output[0];
     output[1] = BitConverter.ToInt32(buffer, 4);
     X.UV2 = output[1];
     output[2] = BitConverter.ToInt32(buffer, 8);
     X.IndexBuffer = output[2];
     int counter = 0;
     for (int i = 12; i < 16; i++)
     {
         X.Wireframe1[counter] = buffer[i];
         counter += 1;
     };
     X.Wireframe2 = new byte[4];
     counter = 0;
     for (int i = 16; i < 20; i++)
     {
         X.Wireframe2[counter] = buffer[i];
         counter += 1;
     }
     Mesh.Buffers = X;
 }
Ejemplo n.º 33
0
 void Unload(Buffers buf)
 {
     if (buf.vertex_buffer_object != 0)
         GL.DeleteBuffers(1, ref buf.vertex_buffer_object);
     if (buf.color_buffer_object != 0)
         GL.DeleteBuffers(1, ref buf.color_buffer_object);
     if (buf.element_buffer_object != 0)
         GL.DeleteBuffers(1, ref buf.element_buffer_object);
     if (buf.normal_buffer_object != 0)
         GL.DeleteBuffers(1, ref buf.normal_buffer_object);
     if (buf.tex_buffer_object != 0)
         GL.DeleteBuffers(1, ref buf.tex_buffer_object);
 }
Ejemplo n.º 34
0
        public void ReadBuffers(byte[] memory)
        {
            Buffers X = new Buffers();
            X.Wireframe1 = new byte[4];

            TreeNode res = new TreeNode("Buffers (?), Position: 0x" + readerpos.ToString("X4"));
            byte[] buffer = new byte[20];
            int[] output = new int[3];
            for (int i = 0; i < 20; i++)
            {
                buffer[i] = memory[readerpos];
                readerpos += 1;
            }
            /// Here using struct Buffers
            output[0] = BitConverter.ToInt32(buffer, 0);
            X.UV1 = output[0];
            output[1] = BitConverter.ToInt32(buffer, 4);
            X.UV2 = output[1];
            output[2] = BitConverter.ToInt32(buffer, 8);
            X.IndexBuffer = output[2];
            int counter = 0;

            for (int i = 12; i < 16; i++)
            {
                X.Wireframe1[counter] = buffer[i];
                counter += 1;
            };
            X.Wireframe2 = new byte[4];
            counter = 0;
            for (int i = 16; i < 20; i++)
            {
                X.Wireframe2[counter] = buffer[i];
                counter += 1;
            }
            /// Here displaying all data
            res.Nodes.Add(new TreeNode("UV Buffer 1 [INT32]: " + output[0].ToString()));
            res.Nodes.Add(new TreeNode("UV Buffer 2 [INT32]: " + output[1].ToString()));
            res.Nodes.Add(new TreeNode("Index Buffer [INT32]: " + output[2].ToString()));
            res.Nodes.Add(new TreeNode("Wireframe buffer 1[four bytes] : " + buffer[12].ToString("X4") + " " + buffer[14].ToString("X4")));
            res.Nodes.Add(new TreeNode("Wireframe buffer 2 [four bytes] : " + buffer[16].ToString("X4") + " " + buffer[18].ToString("X4")));

            Mesh.Buffers = X;
            Mesh.Buffers.t = res;

        }