public override IMyReplicable GetDependency() { if (m_physicsSync == null || Grid.IsStatic) { return(null); } MyCubeGrid master = MyGridPhysicsStateGroup.GetMasterGrid(Grid); if (master != Grid) { return(MyExternalReplicable.FindByObject(master)); } BoundingBoxD box = Grid.PositionComp.WorldAABB; var group = MyCubeGridGroups.Static.PhysicalDynamic.GetGroup(Grid); if (group != null) { foreach (var node in group.Nodes) { box.Include(node.NodeData.PositionComp.WorldAABB); } } if (m_foundEntities == null) { m_foundEntities = new List <MyEntity>(); } m_foundEntities.Clear(); MyGamePruningStructure.GetTopMostEntitiesInBox(ref box, m_foundEntities); float maxRadius = 0; MyCubeGrid biggestGrid = null; foreach (var entity in m_foundEntities) { MyCubeGrid grid = entity as MyCubeGrid; if (grid != null) { var rad = grid.PositionComp.LocalVolume.Radius; if (rad > maxRadius || (rad == maxRadius && (biggestGrid == null || grid.EntityId > biggestGrid.EntityId))) { maxRadius = rad; biggestGrid = grid; } } } if (biggestGrid != null && biggestGrid != Grid) { return(MyExternalReplicable.FindByObject(biggestGrid)); } return(null); }
protected override void ServerRead(VRage.Library.Collections.BitStream stream, ulong clientId, uint timestamp) { base.ServerRead(stream, clientId, timestamp); if (m_additionalServerClientData == null) { m_additionalServerClientData = new Dictionary <ulong, Vector3D>(); } m_additionalServerClientData[clientId] = stream.ReadVector3D(); if (stream.ReadBool()) { if (m_grid != null) { bool isStatic = stream.ReadBool(); if (isStatic == false) { if (stream.ReadBool()) { long entityId = stream.ReadInt64(); Vector2 rotation = new Vector2(); rotation.X = stream.ReadFloat(); rotation.Y = stream.ReadFloat(); float roll = stream.ReadHalf(); Vector3 move = new Vector3(); move.X = stream.ReadHalf(); move.Y = stream.ReadHalf(); move.Z = stream.ReadHalf(); Vector3D gridPos = Vector3D.Zero; MyShipController controller; if (MyEntities.TryGetEntityById <MyShipController>(entityId, out controller)) { controller.CacheMoveAndRotate(move, rotation, roll); gridPos = controller.CubeGrid.PositionComp.GetPosition(); } MyGridPhysicsStateGroup.ReadSubGrids(stream, timestamp, true, m_lowPositionOrientation, ref gridPos); } } } } }
public override float GetPriority(MyClientInfo state) { if (Grid == null || Grid.Projector != null || Grid.IsPreview) { return(0.0f); } float priority = base.GetPriority(state); if (priority == 0.0f) { MyPlayerCollection playerCollection = MySession.Static.Players; var connectedPlayers = playerCollection.GetOnlinePlayers(); foreach (var player in connectedPlayers) { if (player.Client.SteamUserId == state.EndpointId.Value && player.Character != null) { var broadcasters = player.Character.RadioReceiver.GetRelayedBroadcastersForPlayer(player.Identity.IdentityId); foreach (var broadcaster in broadcasters) { var cubeblock = broadcaster.Entity as MyCubeBlock; if (cubeblock != null && cubeblock.CubeGrid == Grid) { return(0.1f); // Minimal priority, update, but not that often } } } } } if (MyFakes.ENABLE_SENT_GROUP_AT_ONCE) { MyCubeGrid master = MyGridPhysicsStateGroup.GetMasterGrid(Grid); if (master != Grid) { return(MyExternalReplicable.FindByObject(master).GetPriority(state)); } } return(priority); }
public static MyEntity FindSupportForCharacterAABB(MyEntity entity) { if (entity == null) { return(null); } BoundingBoxD characterBox = entity.PositionComp.WorldAABB; characterBox.Inflate(1.0); m_entities.Clear(); MyEntities.GetTopMostEntitiesInBox(ref characterBox, m_entities); float maxRadius = 0; MyCubeGrid biggestGrid = null; foreach (var parent in m_entities) { MyCubeGrid grid = parent as MyCubeGrid; if (grid != null) { if (grid.Physics == null || grid.Physics.IsStatic || grid.GridSizeEnum == MyCubeSize.Small) { continue; } grid = MyGridPhysicsStateGroup.GetMasterGrid(grid); var rad = grid.PositionComp.LocalVolume.Radius; if (rad > maxRadius || (rad == maxRadius && (biggestGrid == null || grid.EntityId > biggestGrid.EntityId))) { maxRadius = rad; biggestGrid = grid; } } } if (biggestGrid != null && biggestGrid.CubeBlocks.Count > 10) { return(biggestGrid); } return(null); }
public override bool OnSave(BitStream stream) { if (MyFakes.ENABLE_SENT_GROUP_AT_ONCE) { MyCubeGrid master = MyGridPhysicsStateGroup.GetMasterGrid(Grid); if (master != Grid) { stream.WriteBool(true); stream.WriteInt64(Grid.EntityId); return(true); } } if (Grid.IsSplit) { stream.WriteBool(true); stream.WriteInt64(Grid.EntityId); return(true); } return(false); }
public void Serialize(BitStream stream) { stream.WriteBool(false); MyCubeGrid master = MyGridPhysicsStateGroup.GetMasterGrid(Grid); if (master == Grid || MyFakes.ENABLE_SENT_GROUP_AT_ONCE == false) { var builder = Grid.GetObjectBuilder(); VRage.Serialization.MySerializer.Write(stream, ref builder, MyObjectBuilderSerializer.Dynamic); var g = MyCubeGridGroups.Static.PhysicalDynamic.GetGroup(Grid); if (g == null || MyFakes.ENABLE_SENT_GROUP_AT_ONCE == false) { stream.WriteByte(0); } else { m_groups.Clear(); foreach (var node in g.Nodes) { var target = MyMultiplayer.Static.ReplicationLayer.GetProxyTarget((IMyEventProxy)node.NodeData); if (node.NodeData != Grid && !node.NodeData.IsStatic && target != null) { m_groups.Add(node.NodeData); } } stream.WriteByte((byte)m_groups.Count); // Ignoring self foreach (var node in m_groups) { builder = node.GetObjectBuilder(); VRage.Serialization.MySerializer.Write(stream, ref builder, MyObjectBuilderSerializer.Dynamic); } } } }
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); } } } }
public override float GetPriority(MyClientInfo state, bool cached) { if (Grid == null || Grid.Projector != null || Grid.IsPreview) { return(0.0f); } ulong clientEndpoint = state.EndpointId.Value; if (cached) { if (m_cachedPriorityForClient != null && m_cachedPriorityForClient.ContainsKey(clientEndpoint)) { return(m_cachedPriorityForClient[clientEndpoint]); } } if (m_cachedPriorityForClient == null) { m_cachedPriorityForClient = new Dictionary <ulong, float>(); } float priority = base.GetPriority(state, cached); m_cachedPriorityForClient[clientEndpoint] = priority; if (priority < 0.1f) { if (m_clientState == null) { m_clientState = new Dictionary <ulong, int>(); } if (m_clientState.ContainsKey(clientEndpoint)) { m_clientState[state.EndpointId.Value]++; } else { m_clientState[state.EndpointId.Value] = 0; } if (m_clientState[state.EndpointId.Value] % ANTENNA_UPDATE_TIME == 0) { m_clientState[state.EndpointId.Value] = 0; MyPlayerCollection playerCollection = MySession.Static.Players; var connectedPlayers = playerCollection.GetOnlinePlayers(); foreach (var player in connectedPlayers) { if (player.Client.SteamUserId == state.EndpointId.Value && player.Character != null) { var broadcasters = player.Character.RadioReceiver.GetRelayedBroadcastersForPlayer(player.Identity.IdentityId); foreach (var broadcaster in broadcasters) { var cubeblock = broadcaster.Entity as MyCubeBlock; if (cubeblock != null && cubeblock.CubeGrid == Grid) { m_cachedPriorityForClient[clientEndpoint] = 0.1f; return(m_cachedPriorityForClient[clientEndpoint]); // Minimal priority, update, but not that often } } } } } else { return(m_cachedPriorityForClient[clientEndpoint]); } } if (MyFakes.ENABLE_SENT_GROUP_AT_ONCE) { MyCubeGrid master = MyGridPhysicsStateGroup.GetMasterGrid(Grid); if (master != Grid) { return(MyExternalReplicable.FindByObject(master).GetPriority(state, cached)); } } return(priority); }