当前位置: 首页>>代码示例>>C#>>正文


C# NetIncomingMessage.Reset方法代码示例

本文整理汇总了C#中Lidgren.Network.NetIncomingMessage.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# NetIncomingMessage.Reset方法的具体用法?C# NetIncomingMessage.Reset怎么用?C# NetIncomingMessage.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lidgren.Network.NetIncomingMessage的用法示例。


在下文中一共展示了NetIncomingMessage.Reset方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Recycle

        /// <summary>
        /// Recycles a NetIncomingMessage instance for reuse; taking pressure off the garbage collector
        /// </summary>
        public void Recycle(NetIncomingMessage msg)
        {
            if (m_incomingMessagesPool == null)
                return;

            NetException.Assert(m_incomingMessagesPool.Contains(msg) == false, "Recyling already recycled message! Thread race?");

            byte[] storage = msg.m_data;
            msg.m_data = null;
            Recycle(storage);
            msg.Reset();
            m_incomingMessagesPool.Enqueue(msg);
        }
开发者ID:JamieH,项目名称:lidgren-network-gen3,代码行数:16,代码来源:NetPeer.MessagePools.cs

示例2: Recycle

 /// <summary>
 /// Recycles a NetIncomingMessage instance for reuse; taking pressure off the garbage collector
 /// </summary>
 public void Recycle(NetIncomingMessage msg)
 {
     if (m_incomingMessagesPool == null)
         return;
     #if DEBUG
     if (m_incomingMessagesPool.Contains(msg))
         throw new NetException("Recyling already recycled message! Thread race?");
     #endif
     byte[] storage = msg.m_data;
     msg.m_data = null;
     Recycle(storage);
     msg.Reset();
     m_incomingMessagesPool.Enqueue(msg);
 }
开发者ID:tomoprime,项目名称:CrabBattle,代码行数:17,代码来源:NetPeer.MessagePools.cs

示例3: Update


//.........这里部分代码省略.........
                                    //Only push updates for remote players...
                                    if(playerid != ClientId)
                                        player.Controller.PushUpdate(x, y, player.xVelocity, player.yVelocity, isShooting, triptime);

                                }
                                break;
                            case (byte)PacketTypes.EnemyAction:
                                {
                                    int actionId = inc.ReadInt16();
                                    float speed = inc.ReadFloat();
                                    int seed = inc.ReadInt16();

                                    EnemyManager.CrabCommand(actionId, speed, seed);
                                }
                                break;
                            case (byte)PacketTypes.EnemyHealth:
                                {
                                    EnemyManager.CurrentHealth = inc.ReadInt16();
                                }
                                break;
                            case (byte)PacketTypes.PlayerHit:
                                {
                                    int playerid = inc.ReadInt16();

                                    if (Player==null||Player.Id == playerid)
                                        break;

                                    PlayerObject player = Players.Find(p => p.Id == playerid);
                                    if (player!=null)
                                        GameObject.Instantiate(Resources.Load("Detonator-Insanity"), player.Obj.transform.position, Quaternion.identity);
                                }
                                break;
                            default:
                                inc.Reset();
                                Debug.Log("Unhandled Packet Type Recieved.  Packettype is " + Enum.GetName(typeof(PacketTypes), (int)inc.ReadByte()) + ".");
                                break;
                        }
                    }
                    break;
                default:

                    break;
            }
        }

        if (Time.time > lastSec+1)
        {
            lastSec=Time.time;
            SendKeepAlive();

            if (client.ConnectionStatus == NetConnectionStatus.Disconnected)
            {
                AddLobbyMessage("Lost connection to server. Attempting to reconnect...");
                NetOutgoingMessage outmsg = new NetOutgoingMessage();
                outmsg.Write("A Client");

                IPAddress addr = (Dns.GetHostEntry(hostIp)).AddressList[0];
                IPEndPoint ip = new IPEndPoint(addr,gm.gamePort);
                NetConnection nc = client.GetConnection(ip);

                if (nc !=null)
                {
                    isConnected = false;
                    gm.isReady = false;
                    client.AcceptConnection(nc);
                    AddConsoleMessage("Lost connection to server. Attempting to reconnect...");
开发者ID:tomoprime,项目名称:CrabBattle,代码行数:67,代码来源:NetworkManager.cs

示例4: Update


//.........这里部分代码省略.........
                                }
                                break;
                            case (byte)PacketTypes.PlayerSpecial:
                                {
                                    int playerid = inc.ReadInt16();

                                    PlayerObject player = Players.Find(p => p.Id == playerid);
                                    if (player == null)
                                        break;

                                    int specialType = inc.ReadInt16();

                                    Debug.Log("Got special action request for player " + playerid);

                                    if(playerid != ClientId)
                                        player.Controller.UseSpecial(specialType);
                                }
                                break;
                            case (byte)PacketTypes.PlayerAction:
                                {
                                    int playerid = inc.ReadInt16();

                                    PlayerObject player = Players.Find(p => p.Id == playerid);
                                    if (player == null)
                                        break;

                                    float x = inc.ReadFloat();
                                    float y = inc.ReadFloat();

                                    player.xVelocity = inc.ReadFloat();
                                    player.yVelocity = inc.ReadFloat();

                                    bool isShooting = inc.ReadBoolean();

                                    float triptime = inc.ReadFloat() + roundtriptime;

                                    //Only push updates for remote players...
                                    if(playerid != ClientId)
                                        player.Controller.PushUpdate(x, y, player.xVelocity, player.yVelocity, isShooting, triptime);

                                }
                                break;
                            case (byte)PacketTypes.EnemyAction:
                                {
                                    int actionId = inc.ReadInt16();
                                    float speed = inc.ReadFloat();
                                    int seed = inc.ReadInt16();

                                    EnemyManager.CrabCommand(actionId, speed, seed);
                                }
                                break;
                            case (byte)PacketTypes.EnemyHealth:
                                {
                                    EnemyManager.CurrentHealth = inc.ReadInt16();
                                }
                                break;
                            case (byte)PacketTypes.PlayerHit:
                                {
                                    int playerid = inc.ReadInt16();

                                    if (Player.Id == playerid)
                                        break;

                                    PlayerObject player = Players.Find(p => p.Id == playerid);

                                    GameObject.Instantiate(Resources.Load("Detonator-Insanity"), player.Obj.transform.position, Quaternion.identity);
                                }
                                break;
                            default:
                                inc.Reset();
                                Debug.Log("Unhandled Packet Type Recieved.  Packettype is " + Enum.GetName(typeof(PacketTypes), (int)inc.ReadByte()) + ".");
                                break;
                        }
                    }
                    break;
                default:

                    break;
            }
        }

        if ((lastBeat + 10 < Time.time) || (lastBeat + 4 < Time.time && !isConnected))
        {
            if (isConnected)
            {
                AddConsoleMessage("Lost connection to server.  Attempting to reconnect...");
                isConnected = false;
                isReady = false;
            }
            else
                AddConsoleMessage("Attempting to connect to the server...");

            NetOutgoingMessage outmsg = new NetOutgoingMessage();
            outmsg.Write("A Client");

            client.Connect(hostIp, 14248, outmsg);

            lastBeat = Time.time;
        }
    }
开发者ID:kiichi7,项目名称:CrabBattle,代码行数:101,代码来源:NetworkManager.cs


注:本文中的Lidgren.Network.NetIncomingMessage.Reset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。