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


C# NetBuffer.ReadUInt32方法代码示例

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


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

示例1: Main

		static unsafe void Main(string[] args)
		{
			// JIT stuff
			NetBuffer msg = new NetBuffer(20);
			msg.Write((short)short.MaxValue);
			
			// Go
			double timeStart = NetTime.Now;

			msg = new NetBuffer(20);
			for (int n = 0; n < 10000; n++)
			{
				msg.Reset();

				msg.Write((short)short.MaxValue);
				msg.Write((short)short.MinValue);
				msg.Write((short)-42);

				msg.Write(421);
				msg.Write((byte)7);
				msg.Write(-42.8f);

				if (msg.LengthBytes != 15)
					throw new Exception("Bad message length");

				msg.Write("duke of earl");

				int bytesWritten;
				bytesWritten = msg.WriteVariableInt32(-1);
				bytesWritten = msg.WriteVariableInt32(5);
				bytesWritten = msg.WriteVariableInt32(-18);
				bytesWritten = msg.WriteVariableInt32(42);
				bytesWritten = msg.WriteVariableInt32(-420);

				msg.Write((uint)9991);

				// byte boundary kept until here

				msg.Write(true);
				msg.Write((uint)3, 5);
				msg.Write(8.111f);
				msg.Write("again");
				byte[] arr = new byte[] { 1, 6, 12, 24 };
				msg.Write(arr);
				msg.Write((byte)7, 7);
				msg.Write(Int32.MinValue);
				msg.Write(UInt32.MaxValue);
				msg.WriteRangedSingle(21.0f, -10, 50, 12);

				// test reduced bit signed writing
				msg.Write(15, 5);
				msg.Write(2, 5);
				msg.Write(0, 5);
				msg.Write(-1, 5);
				msg.Write(-2, 5);
				msg.Write(-15, 5);

				msg.Write(UInt64.MaxValue);
				msg.Write(Int64.MaxValue);
				msg.Write(Int64.MinValue);

				msg.Write(42);
				msg.WritePadBits();

				int numBits = msg.WriteRangedInteger(0, 10, 5);
				if (numBits != 4)
					throw new Exception("Ack WriteRangedInteger failed");

				// verify
				msg.Position = 0;

				short a = msg.ReadInt16();
				short b = msg.ReadInt16();
				short c = msg.ReadInt16();

				if (a != short.MaxValue || b != short.MinValue || c != -42)
					throw new Exception("Ack thpth short failed");

				if (msg.ReadInt32() != 421)
					throw new Exception("Ack thphth 1");
				if (msg.ReadByte() != (byte)7)
					throw new Exception("Ack thphth 2");
				if (msg.ReadSingle() != -42.8f)
					throw new Exception("Ack thphth 3");
				if (msg.ReadString() != "duke of earl")
					throw new Exception("Ack thphth 4");

				if (msg.ReadVariableInt32() != -1) throw new Exception("ReadVariableInt32 failed 1");
				if (msg.ReadVariableInt32() != 5) throw new Exception("ReadVariableInt32 failed 2");
				if (msg.ReadVariableInt32() != -18) throw new Exception("ReadVariableInt32 failed 3");
				if (msg.ReadVariableInt32() != 42) throw new Exception("ReadVariableInt32 failed 4");
				if (msg.ReadVariableInt32() != -420) throw new Exception("ReadVariableInt32 failed 5");

				if (msg.ReadUInt32() != 9991)
					throw new Exception("Ack thphth 4.5");

				if (msg.ReadBoolean() != true)
					throw new Exception("Ack thphth 5");
				if (msg.ReadUInt32(5) != (uint)3)
					throw new Exception("Ack thphth 6");
//.........这里部分代码省略.........
开发者ID:marvel54,项目名称:lidgren-network,代码行数:101,代码来源:Program.cs

示例2: OnDataMessage

 public void OnDataMessage(object sender, NetBuffer im, NetConnection conn)
 {
     if (DataMessage != null)
     {
         uint id = im.ReadUInt32();
         if(!DefMessageProc(id, im, conn))
         {
             DataMessage(sender, new DataMessageArgs(im, id, conn));
         }
     }
 }
开发者ID:xxy1991,项目名称:cozy,代码行数:11,代码来源:ServerMain.cs

示例3: Read

 public virtual void Read(NetBuffer im)
 {
     im.Position = 0;
     im.ReadUInt32();
     im.ReadAllProperties(this);
 }
开发者ID:xxy1991,项目名称:cozy,代码行数:6,代码来源:MessageBase.cs

示例4: 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;
			}
		}
开发者ID:marvel54,项目名称:lidgren-network,代码行数:85,代码来源:ImageClient.cs

示例5: StateUpdateEventArgs

		public StateUpdateEventArgs(NetBuffer msg) : base(msg)
		{
			EntitiesUpdatedState = new List<StateUpdateData>();
			RemarkableEvents = new List<RemarkableEventData>();

			LastAcknowledgedActionID = msg.ReadUInt64();
			Time = msg.ReadDouble();
			Vec2 velocity = new Vec2(msg.ReadFloat(), msg.ReadFloat());
			byte nbClients = msg.ReadByte();
			for (byte i = 0; i < nbClients; ++i) {
				ulong id = msg.ReadUInt64();
				Vec2 pos = new Vec2(msg.ReadFloat(), msg.ReadFloat());
				ChampionAnimation anim = (ChampionAnimation)msg.ReadByte();
				bool facingLeft = msg.ReadBoolean();

				EntitiesUpdatedState.Add(new StateUpdateData(id, pos, velocity, anim, facingLeft));
			}
			while (msg.Position != msg.LengthBits) {
				ServerCommand cmd = (ServerCommand)msg.ReadByte();
				RemarkableEventData data = null;
				switch (cmd) {
					case ServerCommand.SpellCast:
						data = new SpellCastEventData(
							msg.ReadUInt64(),
							msg.ReadUInt64(),
							(SpellTypes)msg.ReadByte(),
							msg.ReadFloat(),
							new Vec2(msg.ReadFloat(), msg.ReadFloat()),
							new Vec2(msg.ReadFloat(), msg.ReadFloat()),
							TimeSpan.FromSeconds(msg.ReadFloat()),
							msg.ReadFloat(),
							msg.ReadFloat());
						break;

					case ServerCommand.SpellDisappear:
						data = new SpellDisappearEventData(msg.ReadUInt64());
						break;

					case ServerCommand.StatsChanged:
						data = new StatsChangedEventData(msg.ReadUInt64(), msg.ReadFloat());
						break;

					case ServerCommand.ChampionDied:
						data = new ChampionDiedEventData(msg.ReadUInt64(),
						                                 msg.ReadUInt64(),
						                                 msg.ReadUInt32(), msg.ReadUInt32(), msg.ReadUInt32(), msg.ReadUInt32(),
						                                 TimeSpan.FromSeconds(msg.ReadUInt16()));
						break;

					case ServerCommand.StructureStatsChanged:
						data = new StructureStatsChangedEventData(msg.ReadBoolean() ? Teams.Left : Teams.Right,
						                                          (StructureTypes)msg.ReadByte(),
						                                          msg.ReadFloat());
						break;

					case ServerCommand.StructureDestroyed:
						data = new StructureDestroyedEventData(msg.ReadBoolean() ? Teams.Left : Teams.Right,
						                                       (StructureTypes)msg.ReadByte());
						break;

					case ServerCommand.EndOfGame:
						data = new EndOfGameEventData(msg.ReadBoolean() ? Teams.Left : Teams.Right);
						break;

					case ServerCommand.TowerPreparingToShoot:
						data = new TowerPreparingToShootEventData(msg.ReadBoolean() ? Teams.Left : Teams.Right,
						                                          (StructureTypes)msg.ReadByte());
						break;

					default:
						Debug.Fail("Unknown server command when updating (unknown remarkable event)");
						break;
				}
				if (data != null) {
					RemarkableEvents.Add(data);
				}
			}
		}
开发者ID:DrPandemic,项目名称:EraParadox,代码行数:78,代码来源:Client.cs

示例6: MSG_ReadDeltaKey

 uint MSG_ReadDeltaKey(NetBuffer msg, uint oldV, int bits)
 {
     if (msg.ReadBoolean())
     {
         return (msg.ReadUInt32(bits));
     }
     return oldV;
 }
开发者ID:maesse,项目名称:CubeHags,代码行数:8,代码来源:Input.cs

示例7: MSG_ReadDeltaUsercmdKey

        public UserCommand MSG_ReadDeltaUsercmdKey(NetBuffer msg, ref  UserCommand from)
        {
            UserCommand to = new UserCommand();
            if (msg.ReadBoolean())
                to.serverTime = from.serverTime + (int)msg.ReadUInt32(8);
            else
                to.serverTime = msg.ReadInt32();
            if (msg.ReadBoolean())
            {
                to.anglex = (int)MSG_ReadDeltaKey(msg, (uint)from.anglex, 16);
                to.angley = (int)MSG_ReadDeltaKey(msg, (uint)from.angley, 16);
                to.anglez = (int)MSG_ReadDeltaKey(msg, (uint)from.anglez, 16);
                to.forwardmove = (short)MSG_ReadDeltaKey(msg, from.forwardmove, 16);
                to.rightmove = (short)MSG_ReadDeltaKey(msg, from.rightmove, 16);
                to.upmove = (short)MSG_ReadDeltaKey(msg, from.upmove, 16);
                to.buttons = MSG_ReadDeltaKey(msg,  from.buttons, 16);
                to.weapon = (byte)MSG_ReadDeltaKey(msg, from.weapon, 8);
            }
            else
            {
                to.anglex = from.anglex;
                to.angley = from.angley;
                to.anglez = from.anglez;
                to.forwardmove = from.forwardmove;
                to.rightmove = from.rightmove;
                to.upmove = from.upmove;
                to.buttons = from.buttons;
                to.weapon = from.weapon;
            }

            return to;
        }
开发者ID:maesse,项目名称:CubeHags,代码行数:32,代码来源:Input.cs


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