コード例 #1
0
        public void PerceptionMessageClear()
        {
            PerceptionEventMessage originalMessage = new PerceptionEventMessage();

            originalMessage.ObjectFragment.ObjectId              = Guid.NewGuid();
            originalMessage.ObjectFragment.ObjectIndex           = 1;
            originalMessage.ObjectFragment.TypeId                = Guid.NewGuid();
            originalMessage.ObjectFragment.ObjectName            = "TestObjectName";
            originalMessage.ObjectFragment.TypeName              = "TestTypeName";
            originalMessage.ObjectFragment.OwnerId               = Guid.NewGuid();
            originalMessage.ObjectFragment.Location.X            = 1; originalMessage.ObjectFragment.Location.Y = 2; originalMessage.ObjectFragment.Location.Z = 3;
            originalMessage.ObjectFragment.Velocity.X            = 4; originalMessage.ObjectFragment.Velocity.Y = 5; originalMessage.ObjectFragment.Velocity.Z = 6;
            originalMessage.ObjectFragment.Acceleration.X        = 7; originalMessage.ObjectFragment.Acceleration.Y = 8; originalMessage.ObjectFragment.Acceleration.Z = 9;
            originalMessage.ObjectFragment.Orientation.X         = 10; originalMessage.ObjectFragment.Orientation.Y = 11; originalMessage.ObjectFragment.Orientation.Z = 12; originalMessage.ObjectFragment.Orientation.W = 13;
            originalMessage.ObjectFragment.AngularVelocity.X     = 14; originalMessage.ObjectFragment.AngularVelocity.Y = 15; originalMessage.ObjectFragment.AngularVelocity.Z = 16; originalMessage.ObjectFragment.AngularVelocity.W = 17;
            originalMessage.ObjectFragment.AngularAcceleration.X = 18; originalMessage.ObjectFragment.AngularAcceleration.Y = 19; originalMessage.ObjectFragment.AngularAcceleration.Z = 20; originalMessage.ObjectFragment.AngularAcceleration.W = 21;
            originalMessage.ObjectFragment.BoundingSphereRadius  = 22;
            originalMessage.ObjectFragment.Mass             = 23;
            originalMessage.ObjectFragment.ExtensionDialect = "TEST";
            originalMessage.ObjectFragment.SetExtensionData(UTF8Encoding.UTF8.GetBytes(
                                                                "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" +
                                                                "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" +
                                                                "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" +
                                                                "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"));
            originalMessage.PrepareEncoding();

            originalMessage.Clear();
            PerceptionEventMessage emptyMessage = new PerceptionEventMessage();

            emptyMessage.MessageId = originalMessage.MessageId;
            Assert.AreEqual(originalMessage.ToString(), emptyMessage.ToString());
        }
コード例 #2
0
        public void PerceptionMessageThreeFrameEncoding()
        {
            PerceptionEventMessage originalMessage = new PerceptionEventMessage();

            originalMessage.ObjectFragment.ObjectId              = Guid.NewGuid();
            originalMessage.ObjectFragment.ObjectIndex           = 1;
            originalMessage.ObjectFragment.TypeId                = Guid.NewGuid();
            originalMessage.ObjectFragment.ObjectName            = "TestObjectName";
            originalMessage.ObjectFragment.TypeName              = "TestTypeName";
            originalMessage.ObjectFragment.OwnerId               = Guid.NewGuid();
            originalMessage.ObjectFragment.Location.X            = 1; originalMessage.ObjectFragment.Location.Y = 2; originalMessage.ObjectFragment.Location.Z = 3;
            originalMessage.ObjectFragment.Velocity.X            = 4; originalMessage.ObjectFragment.Velocity.Y = 5; originalMessage.ObjectFragment.Velocity.Z = 6;
            originalMessage.ObjectFragment.Acceleration.X        = 7; originalMessage.ObjectFragment.Acceleration.Y = 8; originalMessage.ObjectFragment.Acceleration.Z = 9;
            originalMessage.ObjectFragment.Orientation.X         = 10; originalMessage.ObjectFragment.Orientation.Y = 11; originalMessage.ObjectFragment.Orientation.Z = 12; originalMessage.ObjectFragment.Orientation.W = 13;
            originalMessage.ObjectFragment.AngularVelocity.X     = 14; originalMessage.ObjectFragment.AngularVelocity.Y = 15; originalMessage.ObjectFragment.AngularVelocity.Z = 16; originalMessage.ObjectFragment.AngularVelocity.W = 17;
            originalMessage.ObjectFragment.AngularAcceleration.X = 18; originalMessage.ObjectFragment.AngularAcceleration.Y = 19; originalMessage.ObjectFragment.AngularAcceleration.Z = 20; originalMessage.ObjectFragment.AngularAcceleration.W = 21;
            originalMessage.ObjectFragment.BoundingSphereRadius  = 22;
            originalMessage.ObjectFragment.Mass             = 23;
            originalMessage.ObjectFragment.ExtensionDialect = "TEST";
            originalMessage.ObjectFragment.SetExtensionData(UTF8Encoding.UTF8.GetBytes(
                                                                "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" +
                                                                "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" +
                                                                "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" +
                                                                "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"));
            originalMessage.PrepareEncoding();

            byte[] encodedBytes = new byte[MxpConstants.MaxPacketSize];

            Assert.AreEqual(originalMessage.FrameCount, 3);
            Assert.AreEqual(originalMessage.FrameDataSize(0), 255);
            Assert.AreEqual(originalMessage.FrameDataSize(1), 255);
            Assert.AreEqual(originalMessage.FrameDataSize(2), 100);

            int currentIndex = originalMessage.EncodeFrameData(0, encodedBytes, 0);

            currentIndex = originalMessage.EncodeFrameData(1, encodedBytes, currentIndex);
            currentIndex = originalMessage.EncodeFrameData(2, encodedBytes, currentIndex);

            PerceptionEventMessage decodedMessage = new PerceptionEventMessage();

            int currentDecodeIndex = decodedMessage.DecodeFrameData(0, encodedBytes, 0, originalMessage.FrameDataSize(0));

            currentDecodeIndex = decodedMessage.DecodeFrameData(1, encodedBytes, currentDecodeIndex, originalMessage.FrameDataSize(1));
            currentDecodeIndex = decodedMessage.DecodeFrameData(2, encodedBytes, currentDecodeIndex, originalMessage.FrameDataSize(2));



            decodedMessage.MessageId = originalMessage.MessageId;


            String originalMessageString = originalMessage.ToString();
            String decodedMessageString  = decodedMessage.ToString();

            Assert.AreEqual(originalMessageString, decodedMessageString);
        }
コード例 #3
0
        public void PacketEncodingPerceptionMessageMultiFrame()
        {
            PerceptionEventMessage originalMessage = new PerceptionEventMessage();

            originalMessage.ObjectFragment.ObjectId              = Guid.NewGuid();
            originalMessage.ObjectFragment.ObjectIndex           = 1;
            originalMessage.ObjectFragment.TypeId                = Guid.NewGuid();
            originalMessage.ObjectFragment.ObjectName            = "TestObjectName";
            originalMessage.ObjectFragment.TypeName              = "TestTypeName";
            originalMessage.ObjectFragment.OwnerId               = Guid.NewGuid();
            originalMessage.ObjectFragment.Location.X            = 1; originalMessage.ObjectFragment.Location.Y = 2; originalMessage.ObjectFragment.Location.Z = 3;
            originalMessage.ObjectFragment.Velocity.X            = 4; originalMessage.ObjectFragment.Velocity.Y = 5; originalMessage.ObjectFragment.Velocity.Z = 6;
            originalMessage.ObjectFragment.Acceleration.X        = 7; originalMessage.ObjectFragment.Acceleration.Y = 8; originalMessage.ObjectFragment.Acceleration.Z = 9;
            originalMessage.ObjectFragment.Orientation.X         = 10; originalMessage.ObjectFragment.Orientation.Y = 11; originalMessage.ObjectFragment.Orientation.Z = 12; originalMessage.ObjectFragment.Orientation.W = 13;
            originalMessage.ObjectFragment.AngularVelocity.X     = 14; originalMessage.ObjectFragment.AngularVelocity.Y = 15; originalMessage.ObjectFragment.AngularVelocity.Z = 16; originalMessage.ObjectFragment.AngularVelocity.W = 17;
            originalMessage.ObjectFragment.AngularAcceleration.X = 18; originalMessage.ObjectFragment.AngularAcceleration.Y = 19; originalMessage.ObjectFragment.AngularAcceleration.Z = 20; originalMessage.ObjectFragment.AngularAcceleration.W = 21;
            originalMessage.ObjectFragment.BoundingSphereRadius  = 22;
            originalMessage.ObjectFragment.Mass             = 23;
            originalMessage.ObjectFragment.ExtensionDialect = "TEST";
            originalMessage.ObjectFragment.SetExtensionData(UTF8Encoding.UTF8.GetBytes(
                                                                "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" +
                                                                "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" +
                                                                "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"));

            Packet originalPacket = new Packet();

            originalPacket.SessionId     = 1;
            originalPacket.PacketId      = 2;
            originalPacket.FirstSendTime = 3;
            originalPacket.ResendCount   = 4;
            originalPacket.Quaranteed    = true;

            Session senderSession = new Session();

            senderSession.Send(originalMessage);

            PacketEncoder.EncodePacketHeader(originalPacket);
            bool packetQuaranteed = false;

            PacketEncoder.EncodePacketData(senderSession, originalPacket, ref packetQuaranteed);
            Assert.IsTrue(packetQuaranteed);

            Session receiverSession = new Session();

            Packet receivedPacket = new Packet();

            receivedPacket.PacketLength = originalPacket.PacketLength;
            receivedPacket.PacketBytes  = originalPacket.PacketBytes;

            List <int> highlightedIndexes = new List <int>();

            highlightedIndexes.Add(18 + 5);
            highlightedIndexes.Add(18 + 265 + 5);

            PacketEncoder.DecodePacketHeader(receivedPacket);

            Assert.AreEqual(2, receivedPacket.PacketBytes[18 + 5]);
            Assert.AreEqual(2, receivedPacket.PacketBytes[18 + 265 + 5]);

            packetQuaranteed = false;
            PacketEncoder.DecodePacketData(receiverSession, receivedPacket, ref packetQuaranteed);
            Assert.IsTrue(packetQuaranteed);

            Message decodedMessage = receiverSession.Receive();

            Assert.IsNotNull(decodedMessage);

            Assert.AreEqual(0, senderSession.GetOutboundMessageCount());
            Assert.AreEqual(0, senderSession.GetPartiallySentMessageCount());
            Assert.AreEqual(0, senderSession.AvailableMessages);
            Assert.AreEqual(0, senderSession.GetPartiallyReceivedMessageCount());
            Assert.AreEqual(0, receiverSession.GetOutboundMessageCount());
            Assert.AreEqual(0, receiverSession.GetPartiallySentMessageCount());
            Assert.AreEqual(0, receiverSession.AvailableMessages);
            Assert.AreEqual(0, receiverSession.GetPartiallyReceivedMessageCount());



            decodedMessage.MessageId     = originalMessage.MessageId;
            decodedMessage.IsAutoRelease = false;

            String originalMessageString = originalMessage.ToString();
            String decodedMessageString  = decodedMessage.ToString();

            Assert.AreEqual(originalMessageString, decodedMessageString);

            String originalPacketString = originalPacket.ToString();
            String receivedPacketString = receivedPacket.ToString();

            Assert.AreEqual(originalPacketString, receivedPacketString);
        }
コード例 #4
0
        public void PerceptionMessageEncoding()
        {
            PerceptionEventMessage originalMessage = new PerceptionEventMessage();

            originalMessage.ObjectFragment.ObjectId              = Guid.NewGuid();
            originalMessage.ObjectFragment.ObjectIndex           = 1;
            originalMessage.ObjectFragment.TypeId                = Guid.NewGuid();
            originalMessage.ObjectFragment.ObjectName            = "TestObjectName";
            originalMessage.ObjectFragment.TypeName              = "TestTypeName";
            originalMessage.ObjectFragment.OwnerId               = Guid.NewGuid();
            originalMessage.ObjectFragment.Location.X            = 1; originalMessage.ObjectFragment.Location.Y = 2; originalMessage.ObjectFragment.Location.Z = 3;
            originalMessage.ObjectFragment.Velocity.X            = 4; originalMessage.ObjectFragment.Velocity.Y = 5; originalMessage.ObjectFragment.Velocity.Z = 6;
            originalMessage.ObjectFragment.Acceleration.X        = 7; originalMessage.ObjectFragment.Acceleration.Y = 8; originalMessage.ObjectFragment.Acceleration.Z = 9;
            originalMessage.ObjectFragment.Orientation.X         = 10; originalMessage.ObjectFragment.Orientation.Y = 11; originalMessage.ObjectFragment.Orientation.Z = 12; originalMessage.ObjectFragment.Orientation.W = 13;
            originalMessage.ObjectFragment.AngularVelocity.X     = 14; originalMessage.ObjectFragment.AngularVelocity.Y = 15; originalMessage.ObjectFragment.AngularVelocity.Z = 16; originalMessage.ObjectFragment.AngularVelocity.W = 17;
            originalMessage.ObjectFragment.AngularAcceleration.X = 18; originalMessage.ObjectFragment.AngularAcceleration.Y = 19; originalMessage.ObjectFragment.AngularAcceleration.Z = 20; originalMessage.ObjectFragment.AngularAcceleration.W = 21;
            originalMessage.ObjectFragment.BoundingSphereRadius  = 22;
            originalMessage.ObjectFragment.Mass = 23;

            OmSlPrimitiveExt originalExtensionFragment = new OmSlPrimitiveExt();

            originalExtensionFragment.State     = 24;
            originalExtensionFragment.NameValue = "TestExtensionNameValue";
            MsdVector3f scale = new MsdVector3f();

            scale.X = 1;
            scale.Y = 2;
            scale.Z = 3;
            originalExtensionFragment.Scale = scale;

            originalMessage.SetExtension <OmSlPrimitiveExt>(originalExtensionFragment);
            originalMessage.PrepareEncoding();

            byte[] encodedBytes = new byte[MxpConstants.MaxPacketSize];

            Assert.AreEqual(originalMessage.FrameCount, 2);
            Assert.AreEqual(originalMessage.FrameDataSize(0), 255);
            Assert.AreEqual(originalMessage.FrameDataSize(1), 49);

            int currentIndex = originalMessage.EncodeFrameData(0, encodedBytes, 0);

            currentIndex = originalMessage.EncodeFrameData(1, encodedBytes, currentIndex);

            PerceptionEventMessage decodedMessage = new PerceptionEventMessage();

            int currentDecodeIndex = decodedMessage.DecodeFrameData(0, encodedBytes, 0, originalMessage.FrameDataSize(0));

            currentDecodeIndex = decodedMessage.DecodeFrameData(1, encodedBytes, currentDecodeIndex, originalMessage.FrameDataSize(1));

            decodedMessage.MessageId = originalMessage.MessageId;

            String originalMessageString = originalMessage.ToString();
            String decodedMessageString  = decodedMessage.ToString();

            Assert.AreEqual(originalMessageString, decodedMessageString);

            OmSlPrimitiveExt decodedExtensionFragmet = decodedMessage.GetExtension <OmSlPrimitiveExt>();

            Assert.AreEqual(originalExtensionFragment.State, decodedExtensionFragmet.State);
            Assert.AreEqual(originalExtensionFragment.NameValue, decodedExtensionFragmet.NameValue);
        }