本文整理汇总了C#中BitReader.GetBits方法的典型用法代码示例。如果您正苦于以下问题:C# BitReader.GetBits方法的具体用法?C# BitReader.GetBits怎么用?C# BitReader.GetBits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitReader
的用法示例。
在下文中一共展示了BitReader.GetBits方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Deserialize
public static ActorState Deserialize(int maxChannels, List<ActorState> existingActorStates, List<ActorState> frameActorStates, string[] objectIndexToName, IDictionary<string, ClassNetCache> classNetCacheByName, UInt32 versionMajor, UInt32 versionMinor, BitReader br)
{
var startPosition = br.Position;
ActorState a = new ActorState();
try
{
var actorId = br.ReadUInt32Max(maxChannels);
a.Id = actorId;
if (br.ReadBit())
{
if (br.ReadBit())
{
a.State = ActorStateState.New;
if (versionMajor > 868 || (versionMajor == 868 && versionMinor >= 14))
{
a.NameId = br.ReadUInt32();
}
a.Unknown1 = br.ReadBit();
a.TypeId = br.ReadUInt32();
a.TypeName = objectIndexToName[(int)a.TypeId.Value];
a._classNetCache = ObjectNameToClassNetCache(a.TypeName, classNetCacheByName);
a.ClassName = objectIndexToName[a._classNetCache.ObjectIndex];
if ( !ClassHasInitialPosition(a.ClassName))
{
#if DEBUG
a.KnownBits = br.GetBits(startPosition, br.Position - startPosition);
a.Complete = true;
#endif
return a;
}
a.Position = Vector3D.Deserialize(br);
if (ClassHasRotation(a.ClassName))
{
a.Rotation = Rotator.Deserialize(br);
}
#if DEBUG
a.Complete = true;
#endif
}
else
{
a.State = ActorStateState.Existing;
var oldState = existingActorStates.Where(x => x.Id == a.Id).Single();
a.TypeId = oldState.TypeId;
a.Properties = new List<ActorStateProperty>();
ActorStateProperty lastProp = null;
while (br.ReadBit())
{
lastProp = ActorStateProperty.Deserialize(oldState._classNetCache, oldState.TypeName, objectIndexToName, versionMajor, versionMinor, br);
a.Properties.Add(lastProp);
#if DEBUG
if (!lastProp.IsComplete)
{
break;
}
#endif
}
#if DEBUG
a.Complete = lastProp.IsComplete;
if (lastProp.Data.Count > 0 && lastProp.Data.Last().ToString() == "FAILED")
{
a.Failed = true;
}
#endif
var endPosition = br.Position;
}
}
else
{
a.State = ActorStateState.Deleted;
var actor = existingActorStates.Where(x => x.Id == a.Id).SingleOrDefault();
#if DEBUG
a.Complete = true;
#endif
var endPosition = br.Position;
}
#if DEBUG
if (!a.Complete)
{
// Read a bunch of data so we have something to look at in the logs
// Otherwise the logs may not show any data bits for whatever is broken, which is hard to interpret
br.ReadBytes(16);
}
a.KnownBits = br.GetBits(startPosition, br.Position - startPosition);
#endif
//.........这里部分代码省略.........
示例2: Deserialize
//.........这里部分代码省略.........
case "TAGame.CameraSettingsActor_TA:ProfileSettings":
asp.Data.Add(CameraSettings.Deserialize(br));
asp.MarkComplete();
break;
case "TAGame.Car_TA:TeamPaint":
asp.Data.Add(TeamPaint.Deserialize(br));
asp.MarkComplete();
break;
case "ProjectX.GRI_X:GameServerID":
asp.Data.Add(br.ReadUInt32());
asp.Data.Add(br.ReadUInt32());
asp.MarkComplete();
break;
case "ProjectX.GRI_X:Reservations":
asp.Data.Add(Reservation.Deserialize(versionMajor, versionMinor, br));
asp.MarkComplete();
break;
case "TAGame.Ball_TA:ReplicatedExplosionData":
asp.Data.Add(br.ReadBit());
asp.Data.Add(br.ReadUInt32());
asp.Data.Add(Vector3D.Deserialize(br)); // Almost definitely position
asp.MarkComplete();
break;
case "TAGame.Car_TA:ReplicatedDemolish":
asp.Data.Add(ReplicatedDemolish.Deserialize(br));
asp.MarkComplete();
break;
case "TAGame.GameEvent_Soccar_TA:ReplicatedMusicStinger":
asp.Data.Add(br.ReadBit());
asp.Data.Add(br.ReadByte());
asp.Data.Add(br.ReadUInt32());
asp.MarkComplete();
break;
case "TAGame.CarComponent_FlipCar_TA:FlipCarTime":
case "TAGame.Ball_TA:ReplicatedBallScale":
case "TAGame.CarComponent_Boost_TA:RechargeDelay":
case "TAGame.CarComponent_Boost_TA:RechargeRate":
case "TAGame.Ball_TA:ReplicatedAddedCarBounceScale":
case "TAGame.Ball_TA:ReplicatedBallMaxLinearSpeedScale":
case "TAGame.Ball_TA:ReplicatedWorldBounceScale":
case "TAGame.CarComponent_Boost_TA:BoostModifier":
case "Engine.Actor:DrawScale":
case "TAGame.CrowdActor_TA:ModifiedNoise":
case "TAGame.CarComponent_TA:ReplicatedActivityTime":
case "TAGame.SpecialPickup_BallFreeze_TA:RepOrigSpeed":
case "TAGame.SpecialPickup_BallVelcro_TA:AttachTime":
case "TAGame.SpecialPickup_BallVelcro_TA:BreakTime":
case "TAGame.Car_TA:AddedCarForceMultiplier":
case "TAGame.Car_TA:AddedBallForceMultiplier":
asp.Data.Add(br.ReadFloat());
asp.MarkComplete();
break;
case "TAGame.GameEvent_SoccarPrivate_TA:MatchSettings":
asp.Data.Add(PrivateMatchSettings.Deserialize(br));
asp.MarkComplete();
break;
case "TAGame.PRI_TA:ClientLoadoutOnline":
asp.Data.Add(ClientLoadoutOnline.Deserialize(br));
asp.MarkComplete();
break;
case "TAGame.GameEvent_TA:GameMode":
if (versionMajor >= 868 && versionMinor >= 12)
{
asp.Data.Add(br.ReadByte());
}
else
{
asp.Data.Add(br.ReadUInt32Max(4));
}
asp.MarkComplete();
break;
case "TAGame.PRI_TA:ClientLoadoutsOnline":
asp.Data.Add(ClientLoadoutsOnline.Deserialize(br));
asp.MarkComplete();
break;
case "TAGame.PRI_TA:ClientLoadouts":
asp.Data.Add(ClientLoadouts.Deserialize(br));
asp.MarkComplete();
break;
case "TAGame.Team_TA:ClubColors":
case "TAGame.Car_TA:ClubColors":
asp.Data.Add(br.ReadBit());
asp.Data.Add(br.ReadByte());
asp.Data.Add(br.ReadBit());
asp.Data.Add(br.ReadByte());
asp.MarkComplete();
break;
case "TAGame.RBActor_TA:WeldedInfo":
asp.Data.Add(WeldedInfo.Deserialize(br));
asp.MarkComplete();
break;
default:
throw new NotSupportedException(string.Format("Unknown property {0}. Next bits in the data are {1}. Figure it out!", asp.PropertyName, br.GetBits(br.Position, Math.Min(4096, br.Length - br.Position)).ToBinaryString()));
}
#if DEBUG
asp.KnownDataBits = br.GetBits(startPosition, br.Position - startPosition);
#endif
return asp;
}
示例3: Deserialize
public static Frame Deserialize(int maxChannels, ref List<ActorState> existingActorStates, string[] objectIdToName, IDictionary<string, ClassNetCache> classNetCacheByName, UInt32 versionMajor, UInt32 versionMinor, BitReader br)
{
var f = new Frame();
f.Position = br.Position;
f.Time = br.ReadFloat();
f.Delta = br.ReadFloat();
if (f.Time < 0 || f.Delta < 0
|| (f.Time > 0 && f.Time < 1E-10)
|| (f.Delta > 0 && f.Delta < 1E-10))
{
string error = string.Format("\"Frame\" at postion {0} has time values that are negative or suspicious. The parser got lost. Check the previous frame for bad data. Time {1}, Delta {2}", f.Position, f.Time, f.Delta);
#if DEBUG
Console.WriteLine(error);
f.Failed = true;
return f;
#endif
throw new Exception(error);
}
f.ActorStates = new List<ActorState>();
ActorState lastActorState = null;
while (br.ReadBit())
{
lastActorState = ActorState.Deserialize(maxChannels, existingActorStates, f.ActorStates, objectIdToName, classNetCacheByName, versionMajor, versionMinor, br);
var existingActor = existingActorStates.Where(x => x.Id == lastActorState.Id).SingleOrDefault();
if (lastActorState.State != ActorStateState.Deleted)
{
if (existingActor == null)
{
existingActorStates.Add(lastActorState);
}
}
else
{
existingActorStates = existingActorStates.Where(x => x.Id != lastActorState.Id).ToList();
}
f.ActorStates.Add(lastActorState);
#if DEBUG
if(!lastActorState.Complete)
{
break;
}
#endif
}
#if DEBUG
if (lastActorState == null || lastActorState.Complete)
{
f.Complete = true;
}
if (lastActorState != null && lastActorState.Failed)
{
f.Failed = true;
}
f.RawData = br.GetBits(f.Position, br.Position - f.Position).ToArray();
#endif
return f;
}