Ejemplo n.º 1
0
        private static void TestSerializerPacketA()
        {
            Serializer sender       = new WriterSerialize();
            PacketA    sendedPacket = new PacketA()
            {
                Position = new Vector3(-29.158f, 50.735f, 150.2875f), f = 100.191f, comment = "Je suis CON !!"
            };
            bool sendingAuthorized = sendedPacket.Serialize(sender);

            sendedPacket = new PacketA()
            {
                Position = new Vector3(50, 100, 40), f = 45.02f, comment = "Je suis un test."
            };
            sendingAuthorized |= sendedPacket.Serialize(sender);
            sender.BitPacking.PushTempInBuffer();
            byte[] data = sender.BitPacking.GetByteBuffer();
            if (sendingAuthorized)
            {
                Serializer receiver = new ReaderSerialize();
                receiver.BitPacking = BitPacker.FromArray(data);
                PacketA receivedPacket  = new PacketA();
                PacketA receivedPacket2 = new PacketA();
                bool    isValid         = receivedPacket.Serialize(receiver);
                isValid = receivedPacket2.Serialize(receiver);
            }
        }
Ejemplo n.º 2
0
        private static void TestSerializerPacketB()
        {
            Serializer    sender     = new WriterSerialize();
            List <IActor> senderList = new List <IActor>();
            Tank          t          = new Tank()
            {
                Name = "Toto", Life = 100, Position = new Vector2(150), ShouldBeSend = true
            };

            t.Shoot();
            senderList.Add(t);
            senderList.Add(new Loot()
            {
                NbOfAmmo = 1, AmmoType = eAmmoType.Grenada, Position = new Vector2(150), IsActive = true, ShouldBeSend = true
            });
            senderList.Add(new Tank()
            {
                Name = "Tata", Life = 80, Position = new Vector2(100), ShouldBeSend = true
            });
            senderList.Add(new Loot()
            {
                AmmoType = eAmmoType.Bullet, Position = new Vector2(360), IsActive = true, ShouldBeSend = true
            });
            senderList.Add(new Tank()
            {
                Life = 50, Position = new Vector2(50), ShouldBeSend = true
            });

            PacketB sendedPacket = new PacketB()
            {
                Actors = senderList
            };
            bool sendingAuthorized = sendedPacket.Serialize(sender);

            sender.BitPacking.PushTempInBuffer();

            byte[] dataSending = sender.BitPacking.GetByteBuffer();

            if (sendingAuthorized)
            {
                Serializer receiver = new ReaderSerialize();
                receiver.BitPacking = BitPacker.FromArray(dataSending);
                List <IActor> receiverList   = new List <IActor>();
                PacketB       receivedPacket = new PacketB()
                {
                    Actors = receiverList
                };
                bool isValid = receivedPacket.Serialize(receiver);
            }
        }
 public FrameReceiver() : base()
 {
     FrameSerializer = new ReaderSerialize();
 }