本文整理汇总了C#中VRage.Network.EndpointId类的典型用法代码示例。如果您正苦于以下问题:C# EndpointId类的具体用法?C# EndpointId怎么用?C# EndpointId使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EndpointId类属于VRage.Network命名空间,在下文中一共展示了EndpointId类的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: ClientWrite
protected override void ClientWrite(VRage.Library.Collections.BitStream stream,EndpointId forClient, uint timestamp, int maxBitPosition)
{
base.ClientWrite(stream,forClient,timestamp,maxBitPosition);
stream.Write(Entity.WorldMatrix.Translation);
MyShipController controller = MySession.Static.ControlledEntity as MyShipController;
stream.WriteBool(m_grid != null && controller != null);
if (m_grid != null && controller != null)
{
stream.WriteBool(m_grid.IsStatic);
if (m_grid.IsStatic == false)
{
stream.WriteBool(controller != null);
if (controller != null)
{
stream.WriteInt64(controller.EntityId);
Vector2 rotation = controller.RotationIndicator;
stream.WriteFloat(rotation.X);
stream.WriteFloat(rotation.Y);
stream.WriteHalf(controller.RollIndicator);
Vector3 position = controller.MoveIndicator;
stream.WriteHalf(position.X);
stream.WriteHalf(position.Y);
stream.WriteHalf(position.Z);
Vector3D gridPosition = m_grid.PositionComp.GetPosition();
MyGridPhysicsStateGroup.WriteSubgrids(m_grid, stream, ref forClient, timestamp, maxBitPosition, m_lowPositionOrientation, ref gridPosition, ref m_currentSentPosition);
}
}
}
}
示例3: MyEventContext
private MyEventContext(EndpointId sender, MyClientStateBase clientState, bool validate)
{
Sender = sender;
ClientState = clientState;
IsValidationRequired = validate;
m_validationFailed = false;
}
示例4: MyMultiplayerServerBase
/// <summary>
/// Initializes a new instance of the MyMultiplayerServerBase class.
/// </summary>
/// <param name="localClientEndpoint">Local client endpoint (for single player or lobby host) or null (for dedicated server)</param>
public MyMultiplayerServerBase(MySyncLayer syncLayer, EndpointId? localClientEndpoint)
: base(syncLayer)
{
Debug.Assert(MyEntities.GetEntities().Count == 0, "Multiplayer server must be created before any entities are loaded!");
var replication = new MyReplicationServer(this, () => MySandboxGame.Static.UpdateTime, localClientEndpoint);
if (MyFakes.MULTIPLAYER_REPLICATION_TEST)
{
replication.MaxSleepTime = MyTimeSpan.FromSeconds(30);
}
SetReplicationLayer(replication);
ClientLeft += (steamId, e) => ReplicationLayer.OnClientLeft(new EndpointId(steamId));
MyEntities.OnEntityCreate += CreateReplicableForObject;
MyEntityComponentBase.OnAfterAddedToContainer += CreateReplicableForObject;
MyExternalReplicable.Destroyed += DestroyReplicable;
foreach (var entity in MyEntities.GetEntities())
{
CreateReplicableForObject(entity);
var components = entity.Components;
if (components != null)
{
foreach (var comp in components)
CreateReplicableForObject(comp);
}
}
syncLayer.TransportLayer.Register(MyMessageId.RPC, ReplicationLayer.ProcessEvent);
syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_READY, ReplicationLayer.ReplicableReady);
syncLayer.TransportLayer.Register(MyMessageId.CLIENT_UPDATE, ReplicationLayer.OnClientUpdate);
syncLayer.TransportLayer.Register(MyMessageId.CLIENT_READY, (p) => ClientReady(p));
}
示例5: ClientWrite
protected override void ClientWrite(VRage.Library.Collections.BitStream stream, EndpointId forClient, uint timestamp, int maxBitPosition)
{
base.ClientWrite(stream, forClient,timestamp,maxBitPosition);
stream.WriteBool(m_character != null);
if (m_character != null)
{
var physGroup = MyExternalReplicable.FindByObject(m_character).FindStateGroup<MyCharacterPhysicsStateGroup>();
long? supportId = null;
if (physGroup != null)
{
physGroup.SetSupport(physGroup.FindSupportDelegate());
supportId = physGroup.GetSupportId();
}
stream.WriteBool(supportId.HasValue);
if (supportId.HasValue)
{
stream.WriteInt64(supportId.Value);
}
Vector3 position = m_character.MoveIndicator;
stream.WriteHalf(position.X);
stream.WriteHalf(position.Y);
stream.WriteHalf(position.Z);
Vector2 rotate = m_character.RotationIndicator;
stream.WriteFloat(rotate.X);
stream.WriteFloat(rotate.Y);
stream.WriteFloat(m_character.RollIndicator);
// Movement state, 2B
stream.WriteUInt16((ushort)m_character.GetNetworkMovementState());
// Movement flag.
stream.WriteUInt16((ushort)m_character.PreviousMovementFlags);
// Flags, 6 bits
bool hasJetpack = m_character.JetpackComp != null;
stream.WriteBool(hasJetpack ? m_character.JetpackComp.TurnedOn : false);
stream.WriteBool(hasJetpack ? m_character.JetpackComp.DampenersTurnedOn : false);
stream.WriteBool(m_character.LightEnabled); // TODO: Remove
stream.WriteBool(m_character.ZoomMode == MyZoomModeEnum.IronSight);
stream.WriteBool(m_character.RadioBroadcaster.WantsToBeEnabled); // TODO: Remove
stream.WriteBool(m_character.TargetFromCamera);
stream.WriteFloat(m_character.HeadLocalXAngle);
stream.WriteFloat(m_character.HeadLocalYAngle);
if ((hasJetpack && m_character.JetpackComp.TurnedOn) == false)
{
MatrixD matrix = m_character.WorldMatrix;
stream.WriteQuaternionNorm(Quaternion.CreateFromForwardUp(matrix.Forward, matrix.Up));
}
}
}
示例6: 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;
}
示例7: OnAskInfo
private static void OnAskInfo()
{
EndpointId sender;
if (MyEventContext.Current.IsLocallyInvoked)
sender = new EndpointId(Sync.MyId);
else
sender = MyEventContext.Current.Sender;
bool isRunning = MyMultiplayer.Static.ScenarioStartTime > DateTime.MinValue;
bool canJoin = !isRunning || MySession.Static.Settings.CanJoinRunning;
MyMultiplayer.RaiseStaticEvent(s => MySyncScenario.OnAnswerInfo, isRunning, canJoin, sender);
int index = (int)MyGuiScreenScenarioMpBase.Static.TimeoutCombo.GetSelectedIndex();
MyMultiplayer.RaiseStaticEvent(s => MySyncScenario.OnSetTimeoutClient, index, sender);
bool canJoinRunning = MySession.Static.Settings.CanJoinRunning;
MyMultiplayer.RaiseStaticEvent(s => MySyncScenario.OnSetJoinRunningClient, canJoinRunning, sender);
}
示例8: 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;
}
示例9:
void IReplicationServerCallback.SendStateSync(BitStream stream, EndpointId endpoint,bool reliable)
{
SyncLayer.TransportLayer.SendMessage(MyMessageId.SERVER_STATE_SYNC, stream, reliable, endpoint);
}
示例10: DispatchBlockingEvent
internal override bool DispatchBlockingEvent(BitStream stream, CallSite site, EndpointId recipient, IMyNetObject eventInstance, IMyNetObject blockedNetObj, float unreliablePriority)
{
Debug.Fail("Client should not call blocking events");
// For client this code is old. Only server can dispatch blocking events.
return DispatchEvent(stream, site, recipient, eventInstance, unreliablePriority);
}
示例11: DispatchEvent
internal override bool DispatchEvent(BitStream stream, CallSite site, EndpointId target, IMyNetObject instance, float unreliablePriority)
{
Debug.Assert(site.HasServerFlag, String.Format("Event '{0}' does not have server flag, it can't be invoked on server!", site));
if (site.HasServerFlag)
{
m_callback.SendEvent(stream, site.IsReliable);
//Client.SendMessageToServer(stream, site.Reliability, PacketPriorityEnum.LOW_PRIORITY, MyChannelEnum.Replication);
}
else if (site.HasClientFlag)
{
// Invoke locally only when it has ClientFlag and no ServerFlag
return true;
}
return false;
}
示例12: 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);
}
示例13: ClientWrite
protected virtual void ClientWrite(VRage.Library.Collections.BitStream stream, EndpointId forClient, uint timestamp, int maxBitPosition)
{
MatrixD matrix = Entity.WorldMatrix;
stream.WriteQuaternionNorm(Quaternion.CreateFromForwardUp(matrix.Forward, matrix.Up));
stream.Write(matrix.Translation);
}
示例14: Serialize
public bool Serialize(VRage.Library.Collections.BitStream stream, EndpointId forClient, uint timestamp, byte packetId, int maxBitPosition)
{
if (stream.Writing)
{
if (Sync.IsServer)
{
ServerWrite(stream, forClient.Value);
}
else
{
ClientWrite(stream, forClient, timestamp,maxBitPosition);
}
}
else
{
if (Sync.IsServer)
{
ServerRead(stream, forClient.Value,timestamp);
}
else
{
ClientRead(stream);
}
}
return true;
}
示例15: Serialize
public bool Serialize(BitStream stream, EndpointId forClient, uint timestamp, byte packetId, int maxBitPosition)
{
if (stream.Writing)
{
InventoryClientData clientData = m_clientInventoryUpdate[forClient.Value];
bool needsSplit = false;
if (clientData.FailedIncompletePackets.Count > 0)
{
InventoryDeltaInformation failedPacket = clientData.FailedIncompletePackets[0];
clientData.FailedIncompletePackets.RemoveAtFast(0);
InventoryDeltaInformation reSendPacket = WriteInventory(ref failedPacket, stream, packetId, maxBitPosition, out needsSplit);
if (needsSplit)
{
//resend split doesnt generate new id becaose it was part of allreadt sent message
clientData.FailedIncompletePackets.Add(CreateSplit(ref failedPacket, ref reSendPacket));
}
if (reSendPacket.HasChanges)
{
clientData.SendPackets[packetId] = reSendPacket;
}
}
else
{
InventoryDeltaInformation difference = CalculateInventoryDiff(ref clientData);
difference.MessageId = clientData.CurrentMessageId;
clientData.MainSendingInfo = WriteInventory(ref difference, stream, packetId, maxBitPosition,out needsSplit);
if (needsSplit)
{
//split generate new id becaose its different message
clientData.CurrentMessageId++;
InventoryDeltaInformation split = CreateSplit(ref difference, ref clientData.MainSendingInfo);
split.MessageId = clientData.CurrentMessageId;
clientData.FailedIncompletePackets.Add(split);
}
if (clientData.MainSendingInfo.HasChanges)
{
clientData.SendPackets[packetId] = clientData.MainSendingInfo;
clientData.CurrentMessageId++;
}
clientData.Dirty = false;
}
}
else
{
ReadInventory(stream);
}
return true;
}