本文整理汇总了C#中VRage.Library.Collections.BitStream类的典型用法代码示例。如果您正苦于以下问题:C# BitStream类的具体用法?C# BitStream怎么用?C# BitStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BitStream类属于VRage.Library.Collections命名空间,在下文中一共展示了BitStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialize
public override bool Serialize(BitStream stream, EndpointId forClient, uint timestamp, byte packetId, int maxBitPosition)
{
bool lowPrecisionOrientation = true;
bool applyWhenReading = true;
SetSupport(FindSupportDelegate());
if (stream.Writing)
{
bool moving = IsMoving(Entity);
stream.WriteBool(moving);
SerializeVelocities(stream, Entity, MyEntityPhysicsStateGroup.EffectiveSimulationRatio, applyWhenReading, moving);
SerializeTransform(stream, Entity, null, lowPrecisionOrientation, applyWhenReading, moving, timestamp);
}
else
{
bool moving = stream.ReadBool();
// reading
SerializeServerVelocities(stream, Entity, MyEntityPhysicsStateGroup.EffectiveSimulationRatio, moving, ref Entity.m_serverLinearVelocity, ref Entity.m_serverAngularVelocity);
applyWhenReading = SerializeServerTransform(stream, Entity, null, moving, timestamp, lowPrecisionOrientation,
ref Entity.m_serverPosition, ref Entity.m_serverOrientation, ref Entity.m_serverWorldMatrix, m_positionValidation);
if (applyWhenReading && moving)
{
Entity.PositionComp.SetWorldMatrix(Entity.m_serverWorldMatrix, null, true);
Entity.SetSpeedsAccordingToServerValues();
}
}
SerializeFriction(stream, Entity);
SerializeActive(stream, Entity);
return true;
}
示例2: SerializeActive
protected void SerializeActive(BitStream stream, MyEntity entity)
{
if (stream.Writing)
{
if (entity.Physics.RigidBody != null && entity.Physics.RigidBody.IsActive)
stream.WriteBool(true);
else
stream.WriteBool(false);
}
else
{
// reading
bool isActive = stream.ReadBool();
if (entity != null && entity.Physics != null)
{
HkRigidBody rb = entity.Physics.RigidBody;
if (rb != null)
{
if (isActive)
rb.Activate();
else
rb.Deactivate();
}
}
}
}
示例3: Serialize
public override void Serialize(BitStream stream)
{
if (stream.Writing)
Write(stream);
else
Read(stream);
}
示例4: Serialize
public void Serialize(BitStream stream, MyClientStateBase forClient, byte packetId, int maxBitPosition)
{
SmallBitField dirtyFlags;
if (stream.Writing)
{
var data = m_clientData[forClient];
dirtyFlags = data.DirtyProperties;
stream.WriteUInt64(dirtyFlags.Bits, m_properties.Count);
}
else
{
dirtyFlags.Bits = stream.ReadUInt64(m_properties.Count);
}
for (int i = 0; i < m_properties.Count; i++)
{
if (dirtyFlags[i])
{
m_properties[i].Serialize(stream, false); // Received from server, don't validate
if (stream.Reading) // Received from server, it's no longer dirty
m_dirtyProperties[i] = false;
}
}
if (stream.Writing && stream.BitPosition <= maxBitPosition)
{
var data = m_clientData[forClient];
data.PacketId = packetId;
data.SentProperties.Bits = data.DirtyProperties.Bits;
data.DirtyProperties.Bits = 0;
}
}
示例5: Write
public void Write(BitStream stream)
{
// TODO: this is suboptimal
if (stream == null || m_writeData == null)
{
if (stream == null)
Debug.Fail("BitReaderWriter - Write - stream is null");
if ( m_writeData == null)
Debug.Fail("BitReaderWriter - Write - m_writeData is null");
return;
}
// Store old bit position
int pos = stream.BitPosition;
// Write data
m_writeData.Serialize(stream, false);
// Measure data len
int len = stream.BitPosition - pos;
// Restore old position
stream.SetBitPositionWrite(pos);
// Write data len
stream.WriteVariant((uint)len);
// Write data again
m_writeData.Serialize(stream, false);
}
示例6: Serialize
public override void Serialize(BitStream stream,uint serverTimeStamp)
{
if (stream.Writing)
Write(stream);
else
Read(stream, serverTimeStamp);
}
示例7: ReadFrom
public static BitReaderWriter ReadFrom(BitStream stream)
{
Debug.Assert(stream.Reading, "Read stream should be set for reading!");
// Move current position after the data
uint dataBitLen = stream.ReadUInt32Variant();
var reader = new BitReaderWriter(stream, stream.BitPosition);
stream.SetBitPositionRead(stream.BitPosition + (int)dataBitLen);
return reader;
}
示例8: WriteInternal
protected override void WriteInternal(BitStream stream, MyEntity controlledEntity)
{
MyContextKind context = GetContextByPage(MyGuiScreenTerminal.GetCurrentScreen());
stream.WriteInt32((int)context, 2);
if (context != MyContextKind.None)
{
var entityId = MyGuiScreenTerminal.InteractedEntity != null ? MyGuiScreenTerminal.InteractedEntity.EntityId : 0;
stream.WriteInt64(entityId);
}
}
示例9: Write
void Write(BitStream stream)
{
// TODO: Make sure sleeping, server controlled entities are not moving locally (or they can be but eventually their position should be corrected)
stream.WriteBool(MySession.ControlledEntity != null);
if (MySession.ControlledEntity == null)
{
Vector3D pos = MySpectatorCameraController.Static.Position;
stream.WriteDouble(pos.X);
stream.WriteDouble(pos.Y);
stream.WriteDouble(pos.Z);
}
else
{
var controlledEntity = MySession.ControlledEntity.Entity.GetTopMostParent();
// Send controlled entity every other frame to server
if (MyMultiplayer.Static.FrameCounter % 2 == 0)
{
// TODO: Write additional client data, context
if (controlledEntity != null && controlledEntity.SyncFlag && ((MySyncEntity)controlledEntity.SyncObject).ResponsibleForUpdate(Sync.Clients.LocalClient))
{
stream.WriteInt64(controlledEntity.EntityId);
switch (MyGuiScreenTerminal.GetCurrentScreen())
{
case MyTerminalPageEnum.Inventory:
stream.WriteInt32((int)MyContextKind.Inventory, 2);
break;
case MyTerminalPageEnum.ControlPanel:
stream.WriteInt32((int)MyContextKind.Terminal, 2);
break;
case MyTerminalPageEnum.Production:
stream.WriteInt32((int)MyContextKind.Production, 2);
break;
default:
stream.WriteInt32((int)MyContextKind.None, 2);
break;
}
if (MyGuiScreenTerminal.InteractedEntity != null)
{
stream.WriteInt64(MyGuiScreenTerminal.InteractedEntity.EntityId);
}
else
{
stream.WriteInt64(0);
}
((MySyncEntity)controlledEntity.SyncObject).SerializePhysics(stream, null);
}
}
}
}
示例10: Write
private void Write(BitStream stream)
{
// TODO: Make sure sleeping, server controlled entities are not moving locally (or they can be but eventually their position should be corrected)
MyEntity controlledEntity = GetControlledEntity();
WriteShared(stream, controlledEntity);
if (controlledEntity != null)
{
WriteInternal(stream, controlledEntity);
WritePhysics(stream, controlledEntity);
}
}
示例11: ReadInternal
protected override void ReadInternal(BitStream stream, MyNetworkClient sender, MyEntity controlledEntity)
{
Context = (MyContextKind)stream.ReadInt32(2);
if (Context != MyContextKind.None)
{
long entityId = stream.ReadInt64();
ContextEntity = MyEntities.GetEntityByIdOrDefault(entityId);
}
else
{
ContextEntity = null;
}
}
示例12: Serialize
public override bool Serialize(BitStream stream, EndpointId forClient,uint timeStamp, byte packetId, int maxBitPosition)
{
base.Serialize(stream, forClient,timeStamp, packetId, maxBitPosition);
if (stream.Writing)
{
// Head and spine stuff, 36 - 152b (4.5B - 19 B)
stream.WriteHalf(Entity.HeadLocalXAngle); // 2B
stream.WriteHalf(Entity.HeadLocalYAngle); // 2B
// TODO: Spine has only one angle (bending forward backward)
// Getting EULER angles from Matrix seems good way to get it (z-component)
stream.WriteQuaternionNormCompressedIdentity(Entity.GetAdditionalRotation(Entity.Definition.SpineBone)); // 1b / 30b
stream.WriteQuaternionNormCompressedIdentity(Entity.GetAdditionalRotation(Entity.Definition.HeadBone)); // 1b / 30b
// Movement state, 2B
stream.WriteUInt16((ushort)Entity.GetCurrentMovementState());
// Movement flag.
stream.WriteUInt16((ushort)Entity.MovementFlags);
// Flags, 6 bits
bool hasJetpack = Entity.JetpackComp != null;
stream.WriteBool(hasJetpack ? Entity.JetpackComp.TurnedOn : false);
stream.WriteBool(hasJetpack ? Entity.JetpackComp.DampenersTurnedOn : false);
stream.WriteBool(Entity.LightEnabled); // TODO: Remove
stream.WriteBool(Entity.ZoomMode == MyZoomModeEnum.IronSight);
stream.WriteBool(Entity.RadioBroadcaster.WantsToBeEnabled); // TODO: Remove
stream.WriteBool(Entity.TargetFromCamera);
stream.WriteNormalizedSignedVector3(Entity.MoveIndicator, 8);
float speed = Entity.Physics.CharacterProxy != null ? Entity.Physics.CharacterProxy.Speed : 0.0f;
stream.WriteFloat(speed);
stream.WriteFloat(Entity.RotationIndicator.X);
stream.WriteFloat(Entity.RotationIndicator.Y);
stream.WriteFloat(Entity.RollIndicator);
}
else
{
Vector3 move;
MyCharacterNetState charNetState = ReadCharacterState(stream);
if (!IsControlledLocally && !Entity.Closed)
{
Entity.SetStateFromNetwork(ref charNetState);
}
}
return true;
}
示例13: Serialize
public void Serialize(BitStream stream, Type baseType, ref Type obj)
{
if (stream.Reading)
{
var id = new TypeId(stream.ReadUInt32());
obj = MyMultiplayer.Static.ReplicationLayer.GetType(id);
}
else
{
var id = MyMultiplayer.Static.ReplicationLayer.GetTypeId(obj);
stream.WriteUInt32(id);
}
}
示例14: Serialize
public bool Serialize(BitStream stream, bool validate)
{
if (stream.Reading)
{
SenderUserId = stream.ReadInt64();
NumElements = stream.ReadInt32();
stream.ReadBytes(CompressedVoiceBuffer, 0,NumElements);
}
else
{
stream.WriteInt64(SenderUserId);
stream.WriteInt32(NumElements);
stream.WriteBytes(CompressedVoiceBuffer, 0, NumElements);
}
return true;
}
示例15: Read
private void Read(BitStream stream)
{
MyNetworkClient sender;
if (!Sync.Clients.TryGetClient(EndpointId.Value, out sender))
{
Debug.Fail("Unknown sender");
return;
}
MyEntity controlledEntity;
ReadShared(stream, sender, out controlledEntity);
if (controlledEntity != null)
{
ReadInternal(stream, sender, controlledEntity);
ReadPhysics(stream, sender, controlledEntity);
}
}