本文整理汇总了C#中Lidgren.Network.NetBuffer.ReadInt16方法的典型用法代码示例。如果您正苦于以下问题:C# NetBuffer.ReadInt16方法的具体用法?C# NetBuffer.ReadInt16怎么用?C# NetBuffer.ReadInt16使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetBuffer
的用法示例。
在下文中一共展示了NetBuffer.ReadInt16方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseGameState
void ParseGameState(NetBuffer msg)
{
clc.connectPacketCount = 0;
// wipe local client state
ClearState();
// a gamestate always marks a server command sequence
clc.serverCommandSequence = msg.ReadInt32();
// parse all the configstrings and baselines
while (true)
{
int cmd = msg.ReadByte();
if (cmd == (int)svc_ops_e.svc_EOF)
break;
if (cmd == (int)svc_ops_e.svc_configstring)
{
int index = msg.ReadInt16();
string s = msg.ReadString();
cl.gamestate.data.Add(index, s);
}
else if (cmd == (int)svc_ops_e.svc_baseline)
{
int newnum = msg.ReadInt32();
if (newnum < 0 || newnum >= 1024)
{
Common.Instance.Error("ParseGameState: Baseline number out of range: " + newnum);
}
Common.entityState_t nullstate = new Common.entityState_t();
Net.Instance.MSG_ReadDeltaEntity(msg, ref nullstate, ref cl.entityBaselines[newnum], newnum);
}
else
{
Common.Instance.Error("ParseGameState: bad command byte");
}
}
clc.clientNum = msg.ReadInt32();
// parse useful values out of CS_SERVERINFO
//ParseServerInfo();
// parse serverId and other cvars
SystemInfoChanged();
InitDownloads();
}
示例2: 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");
//.........这里部分代码省略.........
示例3: ReadDeltaPlayerstate
public static void ReadDeltaPlayerstate(NetBuffer msg, Common.PlayerState from, Common.PlayerState to)
{
int startoffset = msg.Position;
if (from == null)
from = new Common.PlayerState();
to.commandTime = msg.ReadBoolean() ? msg.ReadInt32() : from.commandTime;
to.pm_type = msg.ReadBoolean() ? (Common.PMType)msg.ReadInt32() : from.pm_type;
to.pm_flags = msg.ReadBoolean() ? (client.PMFlags)msg.ReadInt32() : from.pm_flags;
to.pm_time = msg.ReadBoolean() ? msg.ReadInt32() : from.pm_time;
to.origin.X = msg.ReadBoolean() ? msg.ReadFloat() : from.origin.X;
to.origin.Y = msg.ReadBoolean() ? msg.ReadFloat() : from.origin.Y;
to.origin.Z = msg.ReadBoolean() ? msg.ReadFloat() : from.origin.Z;
to.velocity.X = msg.ReadBoolean() ? msg.ReadFloat() : from.velocity.X;
to.velocity.Y = msg.ReadBoolean() ? msg.ReadFloat() : from.velocity.Y;
to.velocity.Z = msg.ReadBoolean() ? msg.ReadFloat() : from.velocity.Z;
to.weaponTime = msg.ReadBoolean() ? msg.ReadInt32() : from.weaponTime;
to.gravity = msg.ReadBoolean() ? msg.ReadInt32() : from.gravity;
to.delta_angles[0] = msg.ReadBoolean() ? msg.ReadInt32() : from.delta_angles[0];
to.delta_angles[1] = msg.ReadBoolean() ? msg.ReadInt32() : from.delta_angles[1];
to.delta_angles[2] = msg.ReadBoolean() ? msg.ReadInt32() : from.delta_angles[2];
to.groundEntityNum = msg.ReadBoolean() ? msg.ReadInt32() : from.groundEntityNum;
to.movementDir = msg.ReadBoolean() ? msg.ReadInt32() : from.movementDir;
to.ladderNormal.X = msg.ReadBoolean() ? msg.ReadFloat() : from.ladderNormal.X;
to.ladderNormal.Y = msg.ReadBoolean() ? msg.ReadFloat() : from.ladderNormal.Y;
to.ladderNormal.Z = msg.ReadBoolean() ? msg.ReadFloat() : from.ladderNormal.Z;
to.speed = msg.ReadBoolean() ? msg.ReadInt32() : from.speed;
to.eFlags = msg.ReadBoolean() ? (Common.EntityFlags)Enum.Parse(typeof(Common.EntityFlags), ""+msg.ReadInt32()) : from.eFlags;
to.eventSequence = msg.ReadBoolean() ? msg.ReadInt32() : from.eventSequence;
to.events[0] = msg.ReadBoolean() ? msg.ReadInt32() : from.events[0];
to.events[1] = msg.ReadBoolean() ? msg.ReadInt32() : from.events[1];
to.eventParms[0] = msg.ReadBoolean() ? msg.ReadInt32() : from.eventParms[0];
to.eventParms[1] = msg.ReadBoolean() ? msg.ReadInt32() : from.eventParms[1];
to.externalEvent = msg.ReadBoolean() ? msg.ReadInt32() : from.externalEvent;
to.externalEventParm = msg.ReadBoolean() ? msg.ReadInt32() : from.externalEventParm;
to.externalEventTime = msg.ReadBoolean() ? msg.ReadInt32() : from.externalEventTime;
to.clientNum = msg.ReadBoolean() ? msg.ReadInt32() : from.clientNum;
to.viewangles.X = msg.ReadBoolean() ? msg.ReadFloat() : from.viewangles.X;
to.viewangles.Y = msg.ReadBoolean() ? msg.ReadFloat() : from.viewangles.Y;
to.viewangles.Z = msg.ReadBoolean() ? msg.ReadFloat() : from.viewangles.Z;
to.viewheight = msg.ReadBoolean() ? msg.ReadInt32() : from.viewheight;
//if (to.viewheight == 16)
//{
// int test = 2;
//}
to.generic1 = msg.ReadBoolean() ? msg.ReadInt32() : from.generic1;
to.bobCycle = msg.ReadBoolean() ? msg.ReadInt32() : from.bobCycle;
to.Ducked = msg.ReadBoolean() ? msg.ReadBoolean() : from.Ducked;
to.Ducking = msg.ReadBoolean() ? msg.ReadBoolean() : from.Ducking;
to.DuckTime = msg.ReadBoolean() ? msg.ReadInt32() : from.DuckTime;
to.OldButtons = msg.ReadBoolean() ? msg.ReadInt32() : from.OldButtons;
// Got diff arrays
int msgMiddle = 99999;
if (msg.ReadBoolean())
{
if (msg.ReadBoolean())
{
// stat
int statbits = msg.ReadInt32();
for (int i = 0; i < 16; i++)
{
if ((statbits & (1 << i)) == (1 << i))
{
to.stats[i] = msg.ReadInt16();
}
else
to.stats[i] = from.stats[i];
}
}
else
to.stats = from.stats;
msgMiddle = msg.Position;
if (msg.ReadBoolean())
{
// pers
int persbits = msg.ReadInt32();
for (int i = 0; i < 16; i++)
{
if ((persbits & (1 << i)) == (1 << i))
{
to.persistant[i] = msg.ReadInt16();
}
else
to.persistant[i] = from.persistant[i];
}
}
else
to.persistant = from.persistant;
}
else
{
to.stats = from.stats;
to.persistant = from.persistant;
}
//System.Console.WriteLine("Read {0}bits snapshot, {1} middle", msg.Position - startoffset, msgMiddle - startoffset);
}