本文整理汇总了C#中VRage.Library.Collections.BitStream类的典型用法代码示例。如果您正苦于以下问题:C# BitStream类的具体用法?C# BitStream怎么用?C# BitStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BitStream类属于VRage.Library.Collections命名空间,在下文中一共展示了BitStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:33,代码来源:MySmallObjectPhysicsStateGroup.cs
示例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();
}
}
}
}
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:26,代码来源:MySmallObjectPhysicsStateGroup.cs
示例3: Serialize
public override void Serialize(BitStream stream)
{
if (stream.Writing)
Write(stream);
else
Read(stream);
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:7,代码来源:MyClientState.cs
示例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;
}
}
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:31,代码来源:MyTerminalBlockData.cs
示例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);
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:30,代码来源:BitReaderWriter.cs
示例6: Serialize
public override void Serialize(BitStream stream,uint serverTimeStamp)
{
if (stream.Writing)
Write(stream);
else
Read(stream, serverTimeStamp);
}
开发者ID:liiir1985,项目名称:SpaceEngineers,代码行数:7,代码来源:MyClientState.cs
示例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;
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:10,代码来源:BitReaderWriter.cs
示例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);
}
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:11,代码来源:MySpaceClientState.cs
示例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);
}
}
}
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:54,代码来源:MyClientState.cs
示例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);
}
}
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:12,代码来源:MyClientState.cs
示例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;
}
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:13,代码来源:MySpaceClientState.cs
示例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;
}
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:51,代码来源:MyCharacterPhysicsStateGroup.cs
示例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);
}
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:14,代码来源:MyDynamicObjectResolver.cs
示例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;
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:16,代码来源:MyVoiceChatSessionComponent.cs
示例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);
}
}
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:17,代码来源:MyClientState.cs
示例16: Write
public void Write(BitStream stream)
{
// TODO: this is suboptimal
// 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);
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:22,代码来源:BitReaderWriter.cs
示例17: Serialize
public override bool Serialize(BitStream stream, EndpointId forClient, uint timestamp, byte packetId, int maxBitPosition)
{
bool lowPrecisionOrientation = true;
bool applyWhenReading = true;
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);
float positionTolerancy = Math.Max(Entity.PositionComp.MaximalSize * 0.1f, 0.1f);
float smallSpeed = 0.1f;
if (Entity.m_serverLinearVelocity == Vector3.Zero || Entity.m_serverLinearVelocity.Length() < smallSpeed)
{
positionTolerancy = Math.Max(Entity.PositionComp.MaximalSize * 0.5f, 1.0f);
}
applyWhenReading = SerializeServerTransform(stream, Entity, null, moving, timestamp, lowPrecisionOrientation, positionTolerancy,
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;
}
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:38,代码来源:MySmallObjectPhysicsStateGroup.cs
示例18: WritePlanetSectors
private void WritePlanetSectors(BitStream stream)
{
stream.WriteInt32(0x42424242);
var planets = MyPlanets.GetPlanets();
stream.WriteInt32(planets.Count);
foreach (var planet in planets)
{
stream.WriteInt64(planet.EntityId);
foreach (var sector in planet.EnvironmentSectors.Values)
{
if (sector.HasPhysics || sector.ServerOwned)
{
stream.WriteInt64(sector.SectorId.Pack64());
}
}
// don't know how many in advance so I will use -1 termination instead of count.
stream.WriteInt64(-1);
}
}
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:24,代码来源:MySpaceClientState.cs
示例19: EnqueueEvent
public void EnqueueEvent(BitStream stream, NetworkId objectInstance, uint eventId, EndpointId sender)
{
int requiredByteSize = stream.ByteLength - stream.BytePosition + 1;
var e = ObtainEvent();
e.Stream.ResetWrite();
e.Stream.WriteBitStream(stream);
e.Stream.ResetRead();
e.ObjectInstance = objectInstance;
e.EventId = eventId;
e.Sender = sender;
List<BufferedEvent> events;
if (!m_buffer.TryGetValue(objectInstance, out events))
{
events = ObtainList();
m_buffer.Add(objectInstance, events);
}
events.Add(e);
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:20,代码来源:MyEventBuffer.cs
示例20: ProcessEvent
internal override void ProcessEvent(BitStream stream, CallSite site, object obj, IMyNetObject sendAs, EndpointId source)
{
// Client blindly invokes everything received from server (without validation)
Invoke(site, stream, obj, source, null, false);
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:5,代码来源:MyReplicationClient.cs
注:本文中的VRage.Library.Collections.BitStream类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论