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); } }
public bool AddCubeState(ushort sequence, int cubeId, ref CubeState cubeState) { int index = sequenceBuffer.Find(sequence); if (index == -1) { return(false); } int numCubes = sequenceBuffer.Entries[index].numCubes; Assert.IsTrue(numCubes < Constants.NumCubes); sequenceBuffer.Entries[index].cubeLookup[cubeId] = numCubes; sequenceBuffer.Entries[index].cubeIds[numCubes] = cubeId; sequenceBuffer.Entries[index].cubeState[numCubes] = cubeState; sequenceBuffer.Entries[index].numCubes++; return(true); }
public void ProcessPacketHeader(ref PacketHeader header) { PacketReceived(header.sequence); for (int i = 0; i < 32; ++i) { if ((header.ack_bits & 1) != 0) { ushort acked_sequence = (ushort)(header.ack - i); int index = m_sentPackets.Find(acked_sequence); if (index != -1 && !m_sentPackets.Entries[index].acked) { PacketAcked(acked_sequence); m_sentPackets.Entries[index].acked = true; } } header.ack_bits >>= 1; } }