Ejemplo n.º 1
0
        public void LoadSingleGlyphWithInt8Offset_signed_byte()
        {
            var writer = new BigEndianBinaryWriter();

            writer.WriteUInt16((ushort)CompositeFlags.ArgsAreXYValues); // signed byte
            writer.WriteUInt16(1);                                      // glyph id

            writer.WriteInt8(sbyte.MinValue + 1);                       // dx
            writer.WriteInt8(sbyte.MinValue + 2);                       // dy
            writer.GetReader();

            var bounds = new Bounds(0, 0, 100, 100);
            var glyph  = CompositeGlyphLoader.LoadCompositeGlyph(writer.GetReader(), in bounds);

            var tbl = new GlyphTable(new[]
            {
                new SimpleGlyphLoader(bounds), // padding
                new SimpleGlyphLoader(new short[] { 20 }, new short[] { 21 }, new[] { true }, new ushort[] { 1 }, bounds)
            });

            GlyphVector finalGlyph = glyph.CreateGlyph(tbl);

            Vector2 point = Assert.Single(finalGlyph.ControlPoints);

            Assert.Equal(new Vector2(sbyte.MinValue + 1 + 20, sbyte.MinValue + 2 + 21), point);
        }
        public void LoadSingleGlyphWithUInt8Offset_unsigned_byte()
        {
            var writer = new BigEndianBinaryWriter();

            writer.WriteUInt16(0);                 // 8bit unsigned
            writer.WriteUInt16(1);                 // glyph id

            writer.WriteUInt8(sbyte.MaxValue + 1); // dx
            writer.WriteUInt8(sbyte.MaxValue + 2); // dy
            writer.GetReader();

            var bounds = new Bounds(0, 0, 100, 100);
            var glyph  = CompositeGlyphLoader.LoadCompositeGlyph(writer.GetReader(), in bounds);

            var tbl = new GlyphTable(new[]
            {
                new SimpleGlyphLoader(bounds), // padding
                new SimpleGlyphLoader(new short[] { 20 }, new short[] { 21 }, new[] { true }, new ushort[] { 1 }, bounds, Array.Empty <byte>())
            });

            GlyphVector finalGlyph = glyph.CreateGlyph(tbl);

            Vector2 point = Assert.Single(finalGlyph.GetOutline().ControlPoints.ToArray());

            Assert.Equal(new Vector2(sbyte.MaxValue + 1 + 20, sbyte.MaxValue + 2 + 21), point);
        }
        public void LoadSingleGlyphWithInt16Offset_signed_short()
        {
            var writer = new BigEndianBinaryWriter();

            writer.WriteUInt16((ushort)(CompositeGlyphFlags.Args1And2AreWords /* 16bit */ | CompositeGlyphFlags.ArgsAreXYValues /* signed */)); // flags
            writer.WriteUInt16(1);                                                                                                              // glyph id

            writer.WriteInt16(short.MinValue + 1);                                                                                              // dx
            writer.WriteInt16(short.MinValue + 2);                                                                                              // dy
            writer.GetReader();

            var bounds = new Bounds(0, 0, 100, 100);
            var glyph  = CompositeGlyphLoader.LoadCompositeGlyph(writer.GetReader(), in bounds);

            var tbl = new GlyphTable(new[]
            {
                new SimpleGlyphLoader(bounds), // padding
                new SimpleGlyphLoader(new short[] { 20 }, new short[] { 21 }, new[] { true }, new ushort[] { 1 }, bounds, Array.Empty <byte>())
            });

            GlyphVector finalGlyph = glyph.CreateGlyph(tbl);

            Vector2 point = Assert.Single(finalGlyph.GetOutline().ControlPoints.ToArray());

            Assert.Equal(new Vector2(short.MinValue + 1 + 20, short.MinValue + 2 + 21), point);
        }
Ejemplo n.º 4
0
        public static void SendMessage(Socket udp, byte id, params byte[] payload)
        {
            byte[] msg = new byte[payload.Length + 4];

            uint innerLen = (uint)payload.Length;

            // bridge message format (all numbers big endian)
            //  bridge command - UINT8 (0 = transmit)
            // --start payload--
            //  inner command - UINT8
            //  inner payload length - UINT16
            //  payload
            msg[0] = BRIDGE_CMD_TX;
            msg[1] = id;
            msg[2] = (byte)((innerLen >> 8) & 0xff);
            msg[3] = (byte)(innerLen & 0xff);

            // copy over the payload
            Buffer.BlockCopy(payload, 0, msg, 4, payload.Length);

            // send that ish out
            udp.SendTo(msg, ControllerEP);
            if (payload.Length == 8)
            {
                msg = new byte[payload.Length + 9];

                BigEndianBinaryWriter writer = new BigEndianBinaryWriter(msg);
                // write a slot for the timestamp (zero as we don't have any timestamp)
                writer.WriteUInt16(0);
                writer.WriteInt32(0);

                // write message type
                writer.WriteByte(ACT_FEEDBACK_CMDRECEIVED);

                // write the length as bullstuff
                writer.WriteInt16(0);

                // only send for all message
                // change the message ID, only send a subset of the stuffs
                writer.WriteBytes(payload);

                // set the stuff stuff
                udp.SendTo(msg, MulticastEP);
            }
        }
        public static void SendMessage(Socket udp, byte id, params byte[] payload)
        {
            byte[] msg = new byte[payload.Length + 4];

            uint innerLen = (uint)payload.Length;

            // bridge message format (all numbers big endian)
            //  bridge command - UINT8 (0 = transmit)
            // --start payload--
            //  inner command - UINT8
            //  inner payload length - UINT16
            //  payload
            msg[0] = BRIDGE_CMD_TX;
            msg[1] = id;
            msg[2] = (byte)((innerLen >> 8) & 0xff);
            msg[3] = (byte)(innerLen & 0xff);

            // copy over the payload
            Buffer.BlockCopy(payload, 0, msg, 4, payload.Length);

            // send that ish out
            udp.SendTo(msg, ControllerEP);
            if (payload.Length == 8) {
                msg = new byte[payload.Length + 9];

                BigEndianBinaryWriter writer = new BigEndianBinaryWriter(msg);
                // write a slot for the timestamp (zero as we don't have any timestamp)
                writer.WriteUInt16(0);
                writer.WriteInt32(0);

                // write message type
                writer.WriteByte(ACT_FEEDBACK_CMDRECEIVED);

                // write the length as bullstuff
                writer.WriteInt16(0);

                // only send for all message
                // change the message ID, only send a subset of the stuffs
                writer.WriteBytes(payload);

                // set the stuff stuff
                udp.SendTo(msg, MulticastEP);
            }
        }