Пример #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);
        }
    }
Пример #2
0
    public DeltaBuffer(int size)
    {
        sequenceBuffer = new Network.SequenceBuffer <Entry>(size);

        for (int i = 0; i < sequenceBuffer.GetSize(); ++i)
        {
            sequenceBuffer.Entries[i].resetSequence = 0;
            sequenceBuffer.Entries[i].numCubes      = 0;
            sequenceBuffer.Entries[i].cubeLookup    = new int[Constants.NumCubes];
            sequenceBuffer.Entries[i].cubeIds       = new int[Constants.NumCubes];
            sequenceBuffer.Entries[i].cubeState     = new CubeState[Constants.NumCubes];
        }

        Reset();
    }
Пример #3
0
        public static void GenerateAckBits <T>(SequenceBuffer <T> sequenceBuffer, out ushort ack, out uint ack_bits)
        {
            ack      = (ushort)(sequenceBuffer.GetSequence() - 1);
            ack_bits = 0;
            uint mask = 1;

            for (int i = 0; i < 32; ++i)
            {
                ushort sequence = (ushort)(ack - i);
                if (sequenceBuffer.Exists(sequence))
                {
                    ack_bits |= mask;
                }
                mask <<= 1;
            }
        }
        public static void GenerateAckBits <T>(SequenceBuffer <T> buffer, out ushort ack, out uint bits)
        {
            var mask = 1u;

            ack  = (ushort)(buffer.id - 1);
            bits = 0;

            for (int i = 0; i < 32; ++i)
            {
                if (buffer.Exists((ushort)(ack - i)))
                {
                    bits |= mask;
                }

                mask <<= 1;
            }
        }
Пример #5
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))));
    }