コード例 #1
0
    static void test_sequence_buffer32()
    {
        Log("test_sequence_buffer32");
        const int Size   = 256;
        var       buffer = new SequenceBuffer32 <TestPacketData32>(Size);

        for (int i = 0; i < Size; ++i)
        {
            TestPacketData entry;
            entry.sequence = 0;
            IsTrue(buffer.Exists((uint)i) == false);
            IsTrue(buffer.Available((uint)i) == true);
            IsTrue(buffer.Get((uint)i) == -1);
        }

        for (int i = 0; i <= Size * 4; ++i)
        {
            int index = buffer.Insert((uint)i);
            IsTrue(index != -1);
            IsTrue(buffer.id == i + 1);
            buffer.entries[index].sequence = (uint)i;
        }

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

        uint sequence = Size * 4;

        for (int i = 0; i < Size; ++i)
        {
            int index = buffer.Get(sequence);
            IsTrue(index >= 0);
            IsTrue(index < Size);
            IsTrue(buffer.entries[index].sequence == sequence);
            sequence--;
        }

        buffer.Reset();
        IsTrue(buffer.id == 0);

        for (int i = 0; i < Size; ++i)
        {
            IsTrue(buffer.Exists((uint)i) == false);
            IsTrue(buffer.Available((uint)i) == true);
            IsTrue(buffer.Get((uint)i) == -1);
        }
    }
コード例 #2
0
    public bool AddUpdatePacket(byte[] packet, DeltaBuffer receiveBuffer, ushort resetId, out long frame)
    {
        PacketHeader header;

        ReadUpdateHeader(packet, out header);
        frame = header.frame;
        int entryId = buffer.Insert(header.frame);

        if (entryId < 0)
        {
            return(false);
        }

        var result = true;

        Profiler.BeginSample("ProcessStateUpdatePacket");
        var e = buffer.entries[entryId];

        if (ReadUpdatePacket(packet, out e.header, out e.avatarCount, ref e.avatarsQuantized, out e.cubeCount, ref e.cubeIds, ref e.notChanged, ref e.hasDelta, ref e.hasPerfectPrediction, ref e.hasPrediction, ref e.baselineIds, ref e.cubes, ref e.deltas, ref e.predictions)
            )
        {
            for (int i = 0; i < e.avatarCount; ++i)
            {
                AvatarState.Unquantize(ref e.avatarsQuantized[i], out e.avatars[i]);
            }

            DecodePrediction(receiveBuffer, resetId, e.header.id, e.cubeCount, ref e.cubeIds, ref e.hasPerfectPrediction, ref e.hasPrediction, ref e.baselineIds, ref e.cubes, ref e.predictions);
            DecodeNotChangedAndDeltas(receiveBuffer, resetId, e.cubeCount, ref e.cubeIds, ref e.notChanged, ref e.hasDelta, ref e.baselineIds, ref e.cubes, ref e.deltas);
        }
        else
        {
            buffer.Remove(header.frame);
            result = false;
        }
        Profiler.EndSample();

        return(result);
    }