You've already forked lidgren-network-gen3
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:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user