本文整理汇总了C#中Lidgren.Network.NetOutgoingMessage类的典型用法代码示例。如果您正苦于以下问题:C# NetOutgoingMessage类的具体用法?C# NetOutgoingMessage怎么用?C# NetOutgoingMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NetOutgoingMessage类属于Lidgren.Network命名空间,在下文中一共展示了NetOutgoingMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write
internal void Write(NetOutgoingMessage Message)
{
ChunkCoords.Write(Message);
Vector3i BlockCoords = ChunkCoords * Size;
for (int x = 0; x < Size.X; x++) {
for (int y = 0; y < Size.Y; y++) {
for (int z = 0; z < Size.Z; z++) {
Vector3i BlockAt = BlockCoords + new Vector3i(x, y, z);
if (!Game.World.MapGenerator.Exists(BlockAt / Sector.Size)) {
Game.World.MapGenerator.GenerateSector(BlockAt / Sector.Size);
}
Block Value = Realm.GetBlock(BlockAt);
if (Value != null) {
Message.Write(true);
Value.Write(Message);
} else {
Message.Write(false);
}
}
}
}
}
示例2: Encode
public void Encode(NetOutgoingMessage om)
{
om.Write(this.MessageTime);
om.Write(this.Id);
om.Write(this.EquipmentPosition);
om.Write(this.InventoryPosition);
}
示例3: Enqueue
internal override NetSendResult Enqueue(NetOutgoingMessage message)
{
m_queuedSends.Enqueue(message);
if (m_queuedSends.Count <= GetAllowedSends())
return NetSendResult.Sent;
return NetSendResult.Queued;
}
示例4: Encode
public void Encode(NetOutgoingMessage om)
{
om.Write((int) Value);
om.Write(Text);
om.Write(Row);
om.Write(Col);
}
示例5: SendMessage
/// <summary>
/// Send a message to a specific connection
/// </summary>
/// <param name="msg">The message to send</param>
/// <param name="recipient">The recipient connection</param>
/// <param name="method">How to deliver the message</param>
/// <param name="sequenceChannel">Sequence channel within the delivery method</param>
public NetSendResult SendMessage(NetOutgoingMessage msg, NetConnection recipient, NetDeliveryMethod method, int sequenceChannel)
{
if (msg == null)
throw new ArgumentNullException("msg");
if (recipient == null)
throw new ArgumentNullException("recipient");
if (sequenceChannel >= NetConstants.NetChannelsPerDeliveryMethod)
throw new ArgumentOutOfRangeException("sequenceChannel");
NetException.Assert(
((method != NetDeliveryMethod.Unreliable && method != NetDeliveryMethod.ReliableUnordered) ||
((method == NetDeliveryMethod.Unreliable || method == NetDeliveryMethod.ReliableUnordered) && sequenceChannel == 0)),
"Delivery method " + method + " cannot use sequence channels other than 0!"
);
NetException.Assert(method != NetDeliveryMethod.Unknown, "Bad delivery method!");
if (msg.m_isSent)
throw new NetException("This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently");
msg.m_isSent = true;
int len = NetConstants.UnfragmentedMessageHeaderSize + msg.LengthBytes; // headers + length, faster than calling msg.GetEncodedSize
if (len <= recipient.m_currentMTU)
{
Interlocked.Increment(ref msg.m_recyclingCount);
return recipient.EnqueueMessage(msg, method, sequenceChannel);
}
else
{
// message must be fragmented!
SendFragmentedMessage(msg, new NetConnection[] { recipient }, method, sequenceChannel);
return NetSendResult.Queued; // could be different for each connection; Queued is "most true"
}
}
示例6: SerializeStream
private void SerializeStream(NetOutgoingMessage netOutgoingMessage)
{
//send our position to the server
//this should only be happening on an object that is ours
_serializer.vector3 = transform.position;
_serializer.OnSerialize(netOutgoingMessage);
}
示例7: SendMessage
public override void SendMessage(NetOutgoingMessage message)
{
for (int i = 0; i < connections.Count; ++i)
{
SendMessage(message, connections[i]);
}
}
示例8: WriteData
protected override void WriteData(NetOutgoingMessage Message)
{
texture.Write(Message);
byte[] data = GetBytes(texture.Texture);
Message.Write((Int32)data.Length);
Message.Write(data);
}
示例9: Encode
public void Encode(NetOutgoingMessage om)
{
om.Write(this.Id);
om.Write(this.MessageTime);
om.Write(this.Health);
om.Write(this.MaxHealth);
}
示例10: W
public void W(NetOutgoingMessage om)
{
om.Write(Uid);
om.Write(X);
om.Write(Y);
om.Write(SpriteId);
}
示例11: SendFragmentedMessage
// on user thread
private NetSendResult SendFragmentedMessage(NetOutgoingMessage msg, IList<NetConnection> recipients, NetDeliveryMethod method, int sequenceChannel)
{
// Note: this group id is PER SENDING/NetPeer; ie. same id is sent to all recipients;
// this should be ok however; as long as recipients differentiate between same id but different sender
int group = Interlocked.Increment(ref m_lastUsedFragmentGroup);
if (group >= NetConstants.MaxFragmentationGroups)
{
// @TODO: not thread safe; but in practice probably not an issue
m_lastUsedFragmentGroup = 1;
group = 1;
}
msg.m_fragmentGroup = group;
// do not send msg; but set fragmentgroup in case user tries to recycle it immediately
// create fragmentation specifics
int totalBytes = msg.LengthBytes;
// determine minimum mtu for all recipients
int mtu = GetMTU(recipients);
int bytesPerChunk = NetFragmentationHelper.GetBestChunkSize(group, totalBytes, mtu);
int numChunks = totalBytes / bytesPerChunk;
if (numChunks * bytesPerChunk < totalBytes)
numChunks++;
NetSendResult retval = NetSendResult.Sent;
int bitsPerChunk = bytesPerChunk * 8;
int bitsLeft = msg.LengthBits;
for (int i = 0; i < numChunks; i++)
{
NetOutgoingMessage chunk = CreateMessage(0);
chunk.m_bitLength = (bitsLeft > bitsPerChunk ? bitsPerChunk : bitsLeft);
chunk.m_data = msg.m_data;
chunk.m_fragmentGroup = group;
chunk.m_fragmentGroupTotalBits = totalBytes * 8;
chunk.m_fragmentChunkByteSize = bytesPerChunk;
chunk.m_fragmentChunkNumber = i;
NetException.Assert(chunk.m_bitLength != 0);
NetException.Assert(chunk.GetEncodedSize() < mtu);
Interlocked.Add(ref chunk.m_recyclingCount, recipients.Count);
foreach (NetConnection recipient in recipients)
{
var res = recipient.EnqueueMessage(chunk, method, sequenceChannel);
if (res == NetSendResult.Dropped)
Interlocked.Decrement(ref chunk.m_recyclingCount);
if ((int)res > (int)retval)
retval = res; // return "worst" result
}
bitsLeft -= bitsPerChunk;
}
return retval;
}
示例12: SendMessage
public void SendMessage(NetOutgoingMessage msg)
{
if (InnerClient.Status == NetPeerStatus.Running)
{
InnerClient.SendMessage(msg, NetDeliveryMethod.Unreliable);
}
}
示例13: WriteType
public void WriteType(NetOutgoingMessage Message, AttributeTypeID Type, object Data)
{
switch (Type) {
case AttributeTypeID.Float:
Message.Write((float)Data);
break;
case AttributeTypeID.Int:
Message.Write((int)Data);
break;
case AttributeTypeID.List:
Console.WriteLine("Engine unable to serialize list objects");
break;
case AttributeTypeID.Long:
Message.Write((long)Data);
break;
case AttributeTypeID.Rectangle:
Message.WriteRectangle((Rectangle)Data);
break;
case AttributeTypeID.String:
Message.Write((string)Data);
break;
case AttributeTypeID.Vector2:
Message.WriteVector2((Vector2)Data);
break;
case AttributeTypeID.Bool:
Message.Write((bool)Data);
break;
default:
Console.WriteLine("AttributeSystem Unrecognised Type In AttributeSystem Type: {0}", Type.ToString());
break;
}
}
示例14: CreateOutgoingMessage
public static OutgoingMessage CreateOutgoingMessage(int opcode, byte[] data, NetOutgoingMessage packet)
{
OutgoingMessage com = CreateOutgoingMessage(opcode, data);
com.EncodeTo(packet);
return com;
}
示例15: Encode
public void Encode(NetOutgoingMessage om)
{
om.Write(Shots);
om.Write(Hits);
om.Write(Misses);
om.Write(ShipsKilled);
}