1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-06 02:11:06 +09:00

- ReadMessages() added to batch read messages. Image sample changed to use the new batch method.

This commit is contained in:
lidgren
2011-09-09 08:11:38 +00:00
parent 768038d5e4
commit b4fd011e5b
4 changed files with 81 additions and 6 deletions

View File

@@ -19,6 +19,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
using System;
using System.Diagnostics;
using System.Collections.Generic;
namespace Lidgren.Network
{
@@ -159,6 +160,30 @@ namespace Lidgren.Network
}
}
/// <summary>
/// Gets an item from the head of the queue, or returns default(T) if empty
/// </summary>
public int TryDrain(IList<T> addTo)
{
if (m_size == 0)
return 0;
lock (m_lock)
{
int added = m_size;
while (m_size > 0)
{
var item = m_items[m_head];
addTo.Add(item);
m_items[m_head] = default(T);
m_head = (m_head + 1) % m_items.Length;
m_size--;
}
return added;
}
}
/// <summary>
/// Returns default(T) if queue is empty
/// </summary>