Пример #1
0
        /// <summary>
        ///   Convert a string into a compact binary representation and write it out
        ///   to the passed BinaryWriter.
        /// </summary>
        public override bool ConvertStringToCustomBinary(
            BinaryWriter writer,             // Writer into the baml stream
            string stringValue)              // String to convert
        {
#if PBTCOMPILER
            List <IntegerMarkup> ints = Parse(stringValue);
#else
            Int32Collection ints = Int32Collection.Parse(stringValue);
#endif
            int cur, last, count, max = 0;

            count = ints.Count;

            // loop through the collection testing for
            // if the numbers are consecutive, and what's the max.

            bool consecutive = true;
            bool allPositive = true;
            for (int i = 1; i < count; i++)
            {
#if PBTCOMPILER
                last = ints[i - 1].Value;
                cur  = ints[i].Value;
#else
                last = ints.Internal_GetItem(i - 1);
                cur  = ints.Internal_GetItem(i);
#endif

                if (consecutive && (last + 1 != cur))
                {
                    consecutive = false;
                }

                //
                // If any number is negative - we will just use Integer type.
                //
                //  We could handle this by encoding the min/max and creating a different number of bit encoding.
                //  For now - we're seeing enough gains with this change.
                //
                if (cur < 0)
                {
                    allPositive = false;
                }

                if (cur > max)
                {
                    max = cur;
                }
            }

            if (consecutive)
            {
                writer.Write((byte)IntegerCollectionType.Consecutive);
                writer.Write(count);   // Write the count

                // Write the first number.
#if PBTCOMPILER
                writer.Write(ints[0].Value);
#else
                writer.Write(ints.Internal_GetItem(0));
#endif
            }
            else
            {
                IntegerCollectionType type;

                if (allPositive && max <= 255)
                {
                    type = IntegerCollectionType.Byte;
                }
                else if (allPositive && max <= UInt16.MaxValue)
                {
                    type = IntegerCollectionType.UShort;
                }
                else
                {
                    type = IntegerCollectionType.Integer;
                }

                writer.Write((byte)type);
                writer.Write(count);   // Write the count

                switch (type)
                {
                case IntegerCollectionType.Byte:
                {
                    for (int i = 0; i < count; i++)
                    {
                        writer.Write((byte)
#if PBTCOMPILER
                                     ints[i].Value
#else
                                     ints.Internal_GetItem(i)
#endif
                                     );
                    }
                }
                break;

                case IntegerCollectionType.UShort:
                {
                    for (int i = 0; i < count; i++)
                    {
                        writer.Write((ushort)
#if PBTCOMPILER
                                     ints[i].Value
#else
                                     ints.Internal_GetItem(i)
#endif
                                     );
                    }
                }
                break;

                case IntegerCollectionType.Integer:
                {
                    for (int i = 0; i < count; i++)
                    {
                        writer.Write(
#if PBTCOMPILER
                            ints[i].Value
#else
                            ints.Internal_GetItem(i)
#endif
                            );
                    }
                }
                break;
                }
            }

            return(true);
        }
        // Token: 0x06002280 RID: 8832 RVA: 0x000AB618 File Offset: 0x000A9818
        public override bool ConvertStringToCustomBinary(BinaryWriter writer, string stringValue)
        {
            Int32Collection int32Collection = Int32Collection.Parse(stringValue);
            int             num             = 0;
            int             count           = int32Collection.Count;
            bool            flag            = true;
            bool            flag2           = true;

            for (int i = 1; i < count; i++)
            {
                int num2 = int32Collection.Internal_GetItem(i - 1);
                int num3 = int32Collection.Internal_GetItem(i);
                if (flag && num2 + 1 != num3)
                {
                    flag = false;
                }
                if (num3 < 0)
                {
                    flag2 = false;
                }
                if (num3 > num)
                {
                    num = num3;
                }
            }
            if (flag)
            {
                writer.Write(1);
                writer.Write(count);
                writer.Write(int32Collection.Internal_GetItem(0));
            }
            else
            {
                XamlInt32CollectionSerializer.IntegerCollectionType value;
                if (flag2 && num <= 255)
                {
                    value = XamlInt32CollectionSerializer.IntegerCollectionType.Byte;
                }
                else if (flag2 && num <= 65535)
                {
                    value = XamlInt32CollectionSerializer.IntegerCollectionType.UShort;
                }
                else
                {
                    value = XamlInt32CollectionSerializer.IntegerCollectionType.Integer;
                }
                writer.Write((byte)value);
                writer.Write(count);
                switch (value)
                {
                case XamlInt32CollectionSerializer.IntegerCollectionType.Byte:
                    for (int j = 0; j < count; j++)
                    {
                        writer.Write((byte)int32Collection.Internal_GetItem(j));
                    }
                    break;

                case XamlInt32CollectionSerializer.IntegerCollectionType.UShort:
                    for (int k = 0; k < count; k++)
                    {
                        writer.Write((ushort)int32Collection.Internal_GetItem(k));
                    }
                    break;

                case XamlInt32CollectionSerializer.IntegerCollectionType.Integer:
                    for (int l = 0; l < count; l++)
                    {
                        writer.Write(int32Collection.Internal_GetItem(l));
                    }
                    break;
                }
            }
            return(true);
        }
Пример #3
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCheck)
        {
            // If we're told we can skip the channel check, then we must be on channel
            Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel));

            if (skipOnChannelCheck || _duceResource.IsOnChannel(channel))
            {
                base.UpdateResource(channel, skipOnChannelCheck);

                // Read values of properties into local variables
                Point3DCollection  vPositions          = Positions;
                Vector3DCollection vNormals            = Normals;
                PointCollection    vTextureCoordinates = TextureCoordinates;
                Int32Collection    vTriangleIndices    = TriangleIndices;

                // Store the count of this resource's contained collections in local variables.
                int PositionsCount          = (vPositions == null) ? 0 : vPositions.Count;
                int NormalsCount            = (vNormals == null) ? 0 : vNormals.Count;
                int TextureCoordinatesCount = (vTextureCoordinates == null) ? 0 : vTextureCoordinates.Count;
                int TriangleIndicesCount    = (vTriangleIndices == null) ? 0 : vTriangleIndices.Count;

                // Pack & send command packet
                DUCE.MILCMD_MESHGEOMETRY3D data;
                unsafe
                {
                    data.Type                   = MILCMD.MilCmdMeshGeometry3D;
                    data.Handle                 = _duceResource.GetHandle(channel);
                    data.PositionsSize          = (uint)(sizeof(MilPoint3F) * PositionsCount);
                    data.NormalsSize            = (uint)(sizeof(MilPoint3F) * NormalsCount);
                    data.TextureCoordinatesSize = (uint)(sizeof(Point) * TextureCoordinatesCount);
                    data.TriangleIndicesSize    = (uint)(sizeof(Int32) * TriangleIndicesCount);

                    channel.BeginCommand(
                        (byte *)&data,
                        sizeof(DUCE.MILCMD_MESHGEOMETRY3D),
                        (int)(data.PositionsSize +
                              data.NormalsSize +
                              data.TextureCoordinatesSize +
                              data.TriangleIndicesSize)
                        );


                    // Copy this collection's elements (or their handles) to reserved data
                    for (int i = 0; i < PositionsCount; i++)
                    {
                        MilPoint3F resource = CompositionResourceManager.Point3DToMilPoint3F(vPositions.Internal_GetItem(i));
                        channel.AppendCommandData(
                            (byte *)&resource,
                            sizeof(MilPoint3F)
                            );
                    }

                    // Copy this collection's elements (or their handles) to reserved data
                    for (int i = 0; i < NormalsCount; i++)
                    {
                        MilPoint3F resource = CompositionResourceManager.Vector3DToMilPoint3F(vNormals.Internal_GetItem(i));
                        channel.AppendCommandData(
                            (byte *)&resource,
                            sizeof(MilPoint3F)
                            );
                    }

                    // Copy this collection's elements (or their handles) to reserved data
                    for (int i = 0; i < TextureCoordinatesCount; i++)
                    {
                        Point resource = vTextureCoordinates.Internal_GetItem(i);
                        channel.AppendCommandData(
                            (byte *)&resource,
                            sizeof(Point)
                            );
                    }

                    // Copy this collection's elements (or their handles) to reserved data
                    for (int i = 0; i < TriangleIndicesCount; i++)
                    {
                        Int32 resource = vTriangleIndices.Internal_GetItem(i);
                        channel.AppendCommandData(
                            (byte *)&resource,
                            sizeof(Int32)
                            );
                    }

                    channel.EndCommand();
                }
            }
        }