Exemplo n.º 1
0
    static void test_sequence_buffer()
    {
        Debug.Log("test_sequence_buffer");

        const int Size = 256;

        var sequenceBuffer = new Network.SequenceBuffer <TestPacketData>(Size);

        for (int i = 0; i < Size; ++i)
        {
            TestPacketData entry;
            entry.sequence = 0;
            Assert.IsTrue(sequenceBuffer.Exists((ushort)i) == false);
            Assert.IsTrue(sequenceBuffer.Available((ushort)i) == true);
            Assert.IsTrue(sequenceBuffer.Find((ushort)i) == -1);
        }

        for (int i = 0; i <= Size * 4; ++i)
        {
            int index = sequenceBuffer.Insert((ushort)i);
            Assert.IsTrue(index != -1);
            Assert.IsTrue(sequenceBuffer.GetSequence() == i + 1);
            sequenceBuffer.Entries[index].sequence = (ushort)i;
        }

        for (int i = 0; i <= Size; ++i)
        {
            // note: outside bounds!
            int index = sequenceBuffer.Insert((ushort)i);
            Assert.IsTrue(index == -1);
        }

        ushort sequence = Size * 4;

        for (int i = 0; i < Size; ++i)
        {
            int index = sequenceBuffer.Find(sequence);
            Assert.IsTrue(index >= 0);
            Assert.IsTrue(index < Size);
            Assert.IsTrue(sequenceBuffer.Entries[index].sequence == sequence);
            sequence--;
        }

        sequenceBuffer.Reset();

        Assert.IsTrue(sequenceBuffer.GetSequence() == 0);

        for (int i = 0; i < Size; ++i)
        {
            Assert.IsTrue(sequenceBuffer.Exists((ushort)i) == false);
            Assert.IsTrue(sequenceBuffer.Available((ushort)i) == true);
            Assert.IsTrue(sequenceBuffer.Find((ushort)i) == -1);
        }
    }
Exemplo n.º 2
0
        public void GeneratePacketHeader(out PacketHeader header)
        {
            header.sequence = m_sequence;
            Util.GenerateAckBits(m_receivedPackets, out header.ack, out header.ack_bits);
            header.frameNumber            = 0;
            header.resetSequence          = 0;
            header.avatarSampleTimeOffset = 0.0f;
            int index = m_sentPackets.Insert(m_sequence);

            Assert.IsTrue(index != -1);
            m_sentPackets.Entries[index].acked = false;
            m_sequence++;
        }
Exemplo n.º 3
0
    static void test_generate_ack_bits()
    {
        Debug.Log("test_generate_ack_bits");

        const int Size = 256;

        var receivedPackets = new Network.SequenceBuffer <TestPacketData>(Size);

        ushort ack      = 0xFFFF;
        uint   ack_bits = 0xFFFFFFFF;

        Network.Util.GenerateAckBits(receivedPackets, out ack, out ack_bits);
        Assert.IsTrue(ack == 0xFFFF);
        Assert.IsTrue(ack_bits == 0);

        for (int i = 0; i <= Size; ++i)
        {
            receivedPackets.Insert((ushort)i);
        }

        Network.Util.GenerateAckBits(receivedPackets, out ack, out ack_bits);
        Assert.IsTrue(ack == Size);
        Assert.IsTrue(ack_bits == 0xFFFFFFFF);

        receivedPackets.Reset();

        ushort[] input_acks = { 1, 5, 9, 11 };
        for (int i = 0; i < input_acks.Length; ++i)
        {
            receivedPackets.Insert(input_acks[i]);
        }

        Network.Util.GenerateAckBits(receivedPackets, out ack, out ack_bits);

        Assert.IsTrue(ack == 11);
        Assert.IsTrue(ack_bits == (1 | (1 << (11 - 9)) | (1 << (11 - 5)) | (1 << (11 - 1))));
    }
Exemplo n.º 4
0
    public bool AddPacket(ushort sequence, ushort resetSequence)
    {
        int index = sequenceBuffer.Insert(sequence);

        if (index == -1)
        {
            return(false);
        }

        sequenceBuffer.Entries[index].resetSequence = resetSequence;

        sequenceBuffer.Entries[index].numCubes = 0;

        for (int i = 0; i < Constants.NumCubes; ++i)
        {
            sequenceBuffer.Entries[index].cubeLookup[i] = -1;
        }

        return(true);
    }
Exemplo n.º 5
0
 void PacketReceived(ushort sequence)
 {
     m_receivedPackets.Insert(sequence);
 }