예제 #1
0
        public void NMP_1()
        {
            NetworkMessageProtocol nmp = new NetworkMessageProtocol();
            Queue<Event> queue = new Queue<Event>();
            byte[] messageToSent = new byte[1200];
            int messageLen;
            int iterationNo;
            Int64 actualSimulationTime;
            GameObject gameObject = new GameObject();

            nmp.EventWasRead += new d_SimulationEventHandler(this.NMP_1_OnEventWasRead);
            actualSimulationTime = 22;
            iterationNo = 10;
            NMP_1_receivedEvents = 0;

            // generate a few events
            for (int i = 0; i < iterationNo; i++)
            {
                queue.Enqueue(new Event(i, i, gameObject, EventType.none));
            }

            // Prepare events in queue for sending; result is in "messageToRead"
            nmp.EncodeEvents(ref queue, ref messageToSent, out messageLen, actualSimulationTime);

            // Reading
            nmp.DecodeData(messageToSent, messageLen);

            Debug.Write("\nRESULT: " +NMP_1_receivedEvents.ToString() + " is equal to " + iterationNo.ToString() + " ? \n\n");
            Assert.That(NMP_1_receivedEvents == iterationNo);
        }
예제 #2
0
        public void NMP_2()
        {
            NetworkMessageProtocol nmp = new NetworkMessageProtocol();
            Queue<Event> queue = new Queue<Event>();
            byte[] messageToSent = new byte[1200];
            int messageLen;
            GameObject gameObject = new GameObject();

            nmp.NetworkTimeChanged += new d_NetworkTimeChanged(NMP_2_OnNetworkTimeChanged);

            queue.Enqueue(new Event(1, 1, gameObject, EventType.none));

            // Prepare events in queue for sending; result is in "messageToRead"
            nmp.EncodeEvents(ref queue, ref messageToSent, out messageLen, NMP_2_SentTime);

            // Reading
            nmp.DecodeData(messageToSent, messageLen);
        }
예제 #3
0
        public void NMP_3()
        {
            NetworkMessageProtocol nmp = new NetworkMessageProtocol();
            Queue<Event> queue = new Queue<Event>();
            byte[] messageToSent = new byte[1200];
            int messageLen;
            GameObject gameObject = new GameObject();

            nmp.EventWasRead += new d_SimulationEventHandler(NMP_3_OnEventWasRead);

            queue.Enqueue(new Event(NMP_3_eventID, NMP_3_when, NMP_3_gameObject, NMP_3_eventType, NMP_3_posX, NMP_3_posY));

            // Prepare events in queue for sending; result is in "messageToRead"
            nmp.EncodeEvents(ref queue, ref messageToSent, out messageLen, NMP_2_SentTime);

            // Reading
            nmp.DecodeData(messageToSent, messageLen);

            Debug.Write("\nRESULT #2: " + NMP_3_receivedEvents.ToString() + " should be 1. \n\n");
            Assert.That(NMP_3_receivedEvents == 1);
        }