You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-18 16:16:35 +09:00
Updated ImageSample, removed dead code and added debug info at end
This commit is contained in:
@@ -81,11 +81,11 @@ namespace ImageClient
|
|||||||
m_startedFetching = NetTime.Now;
|
m_startedFetching = NetTime.Now;
|
||||||
break;
|
break;
|
||||||
case NetIncomingMessageType.Data:
|
case NetIncomingMessageType.Data:
|
||||||
|
|
||||||
// image data, whee!
|
// image data, whee!
|
||||||
// ineffective but simple data model
|
// ineffective but simple data model
|
||||||
ushort width = inc.ReadUInt16();
|
ushort width = inc.ReadUInt16();
|
||||||
ushort height = inc.ReadUInt16();
|
ushort height = inc.ReadUInt16();
|
||||||
uint segment = inc.ReadVariableUInt32();
|
|
||||||
|
|
||||||
Bitmap bm = pictureBox1.Image as Bitmap;
|
Bitmap bm = pictureBox1.Image as Bitmap;
|
||||||
if (bm == null)
|
if (bm == null)
|
||||||
@@ -97,36 +97,9 @@ namespace ImageClient
|
|||||||
}
|
}
|
||||||
pictureBox1.SuspendLayout();
|
pictureBox1.SuspendLayout();
|
||||||
|
|
||||||
int totalBytes = (width * height * 3);
|
for (int y = 0; y < height; y++)
|
||||||
if (inc.LengthBytes < totalBytes)
|
|
||||||
{
|
{
|
||||||
int wholeSegments = totalBytes / 990;
|
for (int x = 0; x < width; x++)
|
||||||
int segLen = 990;
|
|
||||||
int remainder = totalBytes - (wholeSegments * inc.LengthBytes);
|
|
||||||
int totalNumberOfSegments = wholeSegments + (remainder > 0 ? 1 : 0);
|
|
||||||
if (segment >= wholeSegments)
|
|
||||||
segLen = remainder; // last segment can be shorter
|
|
||||||
|
|
||||||
if (ReceivedSegments == null)
|
|
||||||
ReceivedSegments = new bool[totalNumberOfSegments];
|
|
||||||
if (ReceivedSegments[segment] == false)
|
|
||||||
{
|
|
||||||
ReceivedSegments[segment] = true;
|
|
||||||
NumReceivedSegments++;
|
|
||||||
if (NumReceivedSegments >= totalNumberOfSegments)
|
|
||||||
{
|
|
||||||
Client.Disconnect("So long and thanks for all the fish!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int pixelsAhead = (int)segment * 330;
|
|
||||||
|
|
||||||
int y = pixelsAhead / width;
|
|
||||||
int x = pixelsAhead - (y * width);
|
|
||||||
|
|
||||||
for (int i = 0; i < (segLen / 3); i++)
|
|
||||||
{
|
{
|
||||||
// set pixel
|
// set pixel
|
||||||
byte r = inc.ReadByte();
|
byte r = inc.ReadByte();
|
||||||
@@ -134,37 +107,15 @@ namespace ImageClient
|
|||||||
byte b = inc.ReadByte();
|
byte b = inc.ReadByte();
|
||||||
Color col = Color.FromArgb(r, g, b);
|
Color col = Color.FromArgb(r, g, b);
|
||||||
bm.SetPixel(x, y, col);
|
bm.SetPixel(x, y, col);
|
||||||
x++;
|
|
||||||
if (x >= width)
|
|
||||||
{
|
|
||||||
x = 0;
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
for(int y=0;y<height;y++)
|
NativeMethods.AppendText(richTextBox1, Client.Statistics.ToString());
|
||||||
{
|
|
||||||
for (int x = 0; x < width; x++)
|
|
||||||
{
|
|
||||||
// set pixel
|
|
||||||
byte r = inc.ReadByte();
|
|
||||||
byte g = inc.ReadByte();
|
|
||||||
byte b = inc.ReadByte();
|
|
||||||
Color col = Color.FromArgb(r, g, b);
|
|
||||||
bm.SetPixel(x, y, col);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double span = NetTime.Now - m_startedFetching;
|
NativeMethods.AppendText(richTextBox1, Client.ServerConnection.Statistics.ToString());
|
||||||
double bytesPerSecond = (double)totalBytes / span;
|
|
||||||
NativeMethods.AppendText(richTextBox1, "Fetched at " + NetUtility.ToHumanReadable((long)bytesPerSecond) + " per second");
|
|
||||||
|
|
||||||
Client.Disconnect("So long and thanks for all the fish!");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Client.Disconnect("So long and thanks for all the fish!");
|
||||||
|
|
||||||
pictureBox1.ResumeLayout();
|
pictureBox1.ResumeLayout();
|
||||||
pictureBox1.Invalidate();
|
pictureBox1.Invalidate();
|
||||||
System.Threading.Thread.Sleep(0);
|
System.Threading.Thread.Sleep(0);
|
||||||
|
|||||||
@@ -114,7 +114,6 @@ namespace ImageServer
|
|||||||
|
|
||||||
om.Write((ushort)ImageWidth);
|
om.Write((ushort)ImageWidth);
|
||||||
om.Write((ushort)ImageHeight);
|
om.Write((ushort)ImageHeight);
|
||||||
om.WriteVariableUInt32(0);
|
|
||||||
om.Write(ImageData);
|
om.Write(ImageData);
|
||||||
|
|
||||||
Server.SendMessage(om, inc.SenderConnection, NetDeliveryMethod.ReliableOrdered, 0);
|
Server.SendMessage(om, inc.SenderConnection, NetDeliveryMethod.ReliableOrdered, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user