本文整理汇总了C#中Lidgren.Network.NetBuffer.ReadVariableUInt32方法的典型用法代码示例。如果您正苦于以下问题:C# NetBuffer.ReadVariableUInt32方法的具体用法?C# NetBuffer.ReadVariableUInt32怎么用?C# NetBuffer.ReadVariableUInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetBuffer
的用法示例。
在下文中一共展示了NetBuffer.ReadVariableUInt32方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadFrom
/// <summary>
/// Read this message from the packet buffer
/// </summary>
/// <returns>new read pointer position</returns>
internal void ReadFrom(NetBuffer buffer, IPEndPoint endpoint)
{
m_senderEndPoint = endpoint;
// read header
byte header = buffer.ReadByte();
m_type = (NetMessageLibraryType)(header & 7);
m_sequenceChannel = (NetChannel)(header >> 3);
m_sequenceNumber = buffer.ReadUInt16();
int payLen = (int)buffer.ReadVariableUInt32();
// copy payload into message buffer
m_data.EnsureBufferSize(payLen * 8);
buffer.ReadBytes(m_data.Data, 0, payLen);
m_data.Reset(0, payLen * 8);
return;
}
示例2: HandleMessage
/// <summary>
/// Handle incoming message
/// </summary>
private void HandleMessage(NetMessageType type, NetBuffer buffer)
{
switch (type)
{
case NetMessageType.DebugMessage:
//
// it's a library debug message; just display it in the console if debugger is attached
//
Console.WriteLine(buffer.ReadString());
break;
case NetMessageType.StatusChanged:
//
// it's a status change message; set the reason as window title and refresh picture
//
this.Text = buffer.ReadString();
pictureBox1.Refresh();
break;
case NetMessageType.ServerDiscovered:
//
// it's a server discovered message; connect to the discovered server
//
m_imageWidth = 0;
m_imageHeight = 0;
m_lineDisplayed = 0;
m_client.Connect(buffer.ReadIPEndPoint());
break;
case NetMessageType.Data:
//
// it's a data message (data sent from the server)
//
if (m_imageWidth == 0)
{
// first message is size
m_imageWidth = (int)buffer.ReadVariableUInt32();
m_imageHeight = (int)buffer.ReadVariableUInt32();
this.Size = new System.Drawing.Size(m_imageWidth + 40, m_imageHeight + 60);
pictureBox1.Image = new Bitmap(m_imageWidth, m_imageHeight);
pictureBox1.SetBounds(12, 12, m_imageWidth, m_imageHeight);
return;
}
uint pixelPos = buffer.ReadUInt32();
// it's color data
int y = (int)(pixelPos / m_imageWidth);
int x = (int)(pixelPos - (y * m_imageWidth));
Bitmap bm = pictureBox1.Image as Bitmap;
pictureBox1.SuspendLayout();
int pixels = (buffer.LengthBytes - 4) / 3;
for (int i = 0; i < pixels; i++)
{
// set pixel
byte r = buffer.ReadByte();
byte g = buffer.ReadByte();
byte b = buffer.ReadByte();
Color col = Color.FromArgb(r, g, b);
if (y > m_imageHeight)
continue;
bm.SetPixel(x, y, col);
x++;
if (x >= m_imageWidth)
{
x = 0;
y++;
}
}
pictureBox1.ResumeLayout();
// refresh image every horizontal line
if (pixelPos / m_imageWidth > m_lineDisplayed)
{
m_lineDisplayed = (int)(pixelPos / m_imageWidth);
pictureBox1.Refresh();
}
break;
default:
// unhandled
break;
}
}