private static void MoveInternal(MyEntity entity) { if (entity.Parent != null) { return; } VRage.ProfilerShort.Begin(string.Format("Move:{0}", (entity.GetTopMostParent() == entity ? "Topmost" : "Child"))); if (entity.TopMostPruningProxyId != MyConstants.PRUNING_PROXY_ID_UNITIALIZED) { BoundingBoxD bbox = GetEntityAABB(entity); if (bbox.Size == Vector3D.Zero) // remove entities with zero bounding boxes { Remove(entity); VRage.ProfilerShort.End(); return; } var voxelMap = entity as MyVoxelBase; if (voxelMap != null) { m_voxelMapsTree.MoveProxy(voxelMap.VoxelMapPruningProxyId, ref bbox, Vector3D.Zero); } if (entity.TopMostPruningProxyId != MyConstants.PRUNING_PROXY_ID_UNITIALIZED) { m_topMostEntitiesTree.MoveProxy(entity.TopMostPruningProxyId, ref bbox, Vector3D.Zero); } } VRage.ProfilerShort.End(); }
private static void MoveInternal(MyEntity entity) { if (entity.Parent != null) { return; } ProfilerShort.Begin(string.Format("Move:{0}", (entity.GetTopMostParent() == entity ? "Topmost" : "Child"))); if (entity.TopMostPruningProxyId != MyVRageConstants.PRUNING_PROXY_ID_UNITIALIZED) { BoundingBoxD bbox = GetEntityAABB(entity); if (bbox.Size == Vector3D.Zero) // remove entities with zero bounding boxes { Remove(entity); ProfilerShort.End(); return; } var voxelMap = entity as MyVoxelBase; if (voxelMap != null) { m_voxelMapsTree.MoveProxy(voxelMap.VoxelMapPruningProxyId, ref bbox, Vector3D.Zero); } if (entity.TopMostPruningProxyId != MyVRageConstants.PRUNING_PROXY_ID_UNITIALIZED) { bool stat = IsEntityStatic(entity); // Swap trees if necessary. if (stat != entity.StaticForPruningStructure) { if (entity.StaticForPruningStructure) { m_staticObjectsTree.RemoveProxy(entity.TopMostPruningProxyId); entity.TopMostPruningProxyId = m_dynamicObjectsTree.AddProxy(ref bbox, entity, 0); } else { m_dynamicObjectsTree.RemoveProxy(entity.TopMostPruningProxyId); entity.TopMostPruningProxyId = m_staticObjectsTree.AddProxy(ref bbox, entity, 0); } entity.StaticForPruningStructure = stat; } else { if (entity.StaticForPruningStructure) { m_staticObjectsTree.MoveProxy(entity.TopMostPruningProxyId, ref bbox, Vector3D.Zero); } else { m_dynamicObjectsTree.MoveProxy(entity.TopMostPruningProxyId, ref bbox, Vector3D.Zero); } } } } ProfilerShort.End(); }
public static MyDetectedEntityInfo Create(MyEntity entity, long sensorOwner, Vector3D?hitPosition = null) { if (entity == null) { return(new MyDetectedEntityInfo()); } MatrixD orientation = MatrixD.Zero; Vector3 velocity = Vector3D.Zero; int timeStamp = MySandboxGame.TotalGamePlayTimeInMilliseconds; MyDetectedEntityType type; BoundingBoxD boundingBox = entity.PositionComp.WorldAABB; MyRelationsBetweenPlayerAndBlock relationship; string name; if (entity.Physics != null) { orientation = entity.Physics.GetWorldMatrix().GetOrientation(); velocity = entity.Physics.LinearVelocity; } //using GetTopMostParent in case we are looking at a MyCubeBlock; we want the grid the block is on var grid = entity.GetTopMostParent() as MyCubeGrid; if (grid != null) { if (grid.GridSizeEnum == MyCubeSize.Small) { type = MyDetectedEntityType.SmallGrid; } else { type = MyDetectedEntityType.LargeGrid; } if (grid.BigOwners.Count == 0) { relationship = MyRelationsBetweenPlayerAndBlock.NoOwnership; } else { relationship = MyIDModule.GetRelation(sensorOwner, grid.BigOwners[0], MyOwnershipShareModeEnum.Faction); } if (relationship == MyRelationsBetweenPlayerAndBlock.Owner || relationship == MyRelationsBetweenPlayerAndBlock.FactionShare) { name = grid.DisplayName; } else { if (grid.GridSizeEnum == MyCubeSize.Small) { name = MyTexts.GetString(MySpaceTexts.DetectedEntity_SmallGrid); } else { name = MyTexts.GetString(MySpaceTexts.DetectedEntity_LargeGrid); } } return(new MyDetectedEntityInfo(grid.EntityId, name, type, hitPosition, orientation, velocity, relationship, boundingBox, timeStamp)); } var character = entity as MyCharacter; if (character != null) { if (character.IsPlayer) { type = MyDetectedEntityType.CharacterHuman; } else { type = MyDetectedEntityType.CharacterOther; } relationship = MyIDModule.GetRelation(sensorOwner, character.GetPlayerIdentityId(), MyOwnershipShareModeEnum.Faction); if (relationship == MyRelationsBetweenPlayerAndBlock.Owner || relationship == MyRelationsBetweenPlayerAndBlock.FactionShare) { name = character.DisplayNameText; } else { if (character.IsPlayer) { name = MyTexts.GetString(MySpaceTexts.DetectedEntity_CharacterHuman); } else { name = MyTexts.GetString(MySpaceTexts.DetectedEntity_CharacterOther); } } BoundingBoxD bound = character.Model.BoundingBox.Transform(character.WorldMatrix); return(new MyDetectedEntityInfo(entity.EntityId, name, type, hitPosition, orientation, velocity, relationship, bound, timeStamp)); } relationship = MyRelationsBetweenPlayerAndBlock.Neutral; var floating = entity as MyFloatingObject; if (floating != null) { type = MyDetectedEntityType.FloatingObject; name = floating.Item.Content.SubtypeName; return(new MyDetectedEntityInfo(entity.EntityId, name, type, hitPosition, orientation, velocity, relationship, boundingBox, timeStamp)); } var backpack = entity as MyInventoryBagEntity; if (backpack != null) { type = MyDetectedEntityType.FloatingObject; name = backpack.DisplayName; return(new MyDetectedEntityInfo(entity.EntityId, name, type, hitPosition, orientation, velocity, relationship, boundingBox, timeStamp)); } var planet = entity as MyPlanet; if (planet != null) { type = MyDetectedEntityType.Planet; name = MyTexts.GetString(MySpaceTexts.DetectedEntity_Planet); //shrink the planet's bounding box to only encompass terrain boundingBox = BoundingBoxD.CreateFromSphere(new BoundingSphereD(planet.PositionComp.GetPosition(), planet.MaximumRadius)); return(new MyDetectedEntityInfo(entity.EntityId, name, type, hitPosition, orientation, velocity, relationship, boundingBox, timeStamp)); } var voxelPhysics = entity as MyVoxelPhysics; if (voxelPhysics != null) { type = MyDetectedEntityType.Planet; name = MyTexts.GetString(MySpaceTexts.DetectedEntity_Planet); //shrink the planet's bounding box to only encompass terrain boundingBox = BoundingBoxD.CreateFromSphere(new BoundingSphereD(voxelPhysics.Parent.PositionComp.GetPosition(), voxelPhysics.Parent.MaximumRadius)); return(new MyDetectedEntityInfo(entity.EntityId, name, type, hitPosition, orientation, velocity, relationship, boundingBox, timeStamp)); } var voxel = entity as MyVoxelMap; if (voxel != null) { type = MyDetectedEntityType.Asteroid; name = MyTexts.GetString(MySpaceTexts.DetectedEntity_Asteroid); return(new MyDetectedEntityInfo(entity.EntityId, name, type, hitPosition, orientation, velocity, relationship, boundingBox, timeStamp)); } var meteor = entity as MyMeteor; if (meteor != null) { type = MyDetectedEntityType.Meteor; name = MyTexts.GetString(MySpaceTexts.DetectedEntity_Meteor); return(new MyDetectedEntityInfo(entity.EntityId, name, type, hitPosition, orientation, velocity, relationship, boundingBox, timeStamp)); } var missile = entity as MyMissile; if (missile != null) { type = MyDetectedEntityType.Missile; name = entity.DisplayName; return(new MyDetectedEntityInfo(entity.EntityId, name, type, hitPosition, orientation, velocity, relationship, boundingBox, timeStamp)); } //error case return(new MyDetectedEntityInfo(0, String.Empty, MyDetectedEntityType.Unknown, null, new MatrixD(), new Vector3(), MyRelationsBetweenPlayerAndBlock.NoOwnership, new BoundingBoxD(), MySandboxGame.TotalGamePlayTimeInMilliseconds)); }
private static void MoveInternal(MyEntity entity) { if (entity.Parent != null) return; VRage.ProfilerShort.Begin(string.Format("Move:{0}", (entity.GetTopMostParent() == entity ? "Topmost" : "Child"))); if (entity.TopMostPruningProxyId != MyConstants.PRUNING_PROXY_ID_UNITIALIZED) { BoundingBoxD bbox = GetEntityAABB(entity); if (bbox.Size == Vector3D.Zero) // remove entities with zero bounding boxes { Remove(entity); VRage.ProfilerShort.End(); return; } var voxelMap = entity as MyVoxelBase; if (voxelMap != null) { m_voxelMapsTree.MoveProxy(voxelMap.VoxelMapPruningProxyId, ref bbox, Vector3D.Zero); } if (entity.TopMostPruningProxyId != MyConstants.PRUNING_PROXY_ID_UNITIALIZED) { m_topMostEntitiesTree.MoveProxy(entity.TopMostPruningProxyId, ref bbox, Vector3D.Zero); } } VRage.ProfilerShort.End(); }
public void UpdateHud(bool showMyself = false) { if (MySandboxGame.IsDedicated || MyHud.MinimalHud) { return; } Clear(); foreach (var broadcaster in m_relayedBroadcasters) { MyEntity entity = (MyEntity)broadcaster.Entity; if (entity != null) { //Also ignore entity if it is preview entity or else it will update hud if (entity.GetTopMostParent() is MyCubeGrid && entity.GetTopMostParent().IsPreview) { continue; } if (!showMyself && entity == Entity) { continue; //do not show myself } bool friendly = true; if (broadcaster.Entity is IMyComponentOwner <MyIDModule> ) { MyIDModule broadcasterId; if ((broadcaster.Entity as IMyComponentOwner <MyIDModule>).GetComponent(out broadcasterId)) { VRage.Game.MyRelationsBetweenPlayerAndBlock relation = broadcasterId.GetUserRelationToOwner(MySession.Static.LocalPlayerId); if (relation == VRage.Game.MyRelationsBetweenPlayerAndBlock.Enemies || relation == VRage.Game.MyRelationsBetweenPlayerAndBlock.Neutral) { friendly = false; } } } MyLaserAntenna la = broadcaster.Entity as MyLaserAntenna; if (la != null && la.ShowOnHUD == false) { continue; } foreach (var hudParams in entity.GetHudParams(friendly)) { MyEntity hudParamsEntity = hudParams.Entity as MyEntity; if (!m_entitiesOnHud.Contains(hudParamsEntity)) { m_entitiesOnHud.Add(hudParamsEntity); if (hudParams.BlinkingTime > 0) { MyHud.HackingMarkers.RegisterMarker(hudParamsEntity, hudParams); } else if (!MyHud.HackingMarkers.MarkerEntities.ContainsKey(hudParamsEntity)) { MyHud.LocationMarkers.RegisterMarker(hudParamsEntity, hudParams); } } } } } }
public void UpdateHud(bool showMyself = false) { if (MySandboxGame.IsDedicated || MyHud.MinimalHud || MyHud.CutsceneHud) { return; } Clear(); foreach (var broadcaster in m_relayedBroadcasters) { MyEntity entity = (MyEntity)broadcaster.Entity; if (entity != null) { //Also ignore entity if it is preview entity or else it will update hud if (entity.GetTopMostParent() is MyCubeGrid && entity.GetTopMostParent().IsPreview) { continue; } if (!showMyself && entity == Entity) { continue; //do not show myself } bool friendly = true; if (broadcaster.Entity is IMyComponentOwner <MyIDModule> ) { MyIDModule broadcasterId; if ((broadcaster.Entity as IMyComponentOwner <MyIDModule>).GetComponent(out broadcasterId)) { VRage.Game.MyRelationsBetweenPlayerAndBlock relation = broadcasterId.GetUserRelationToOwner(MySession.Static.LocalPlayerId); if (relation == VRage.Game.MyRelationsBetweenPlayerAndBlock.Enemies || relation == VRage.Game.MyRelationsBetweenPlayerAndBlock.Neutral) { friendly = false; } } } MyLaserAntenna la = broadcaster.Entity as MyLaserAntenna; if (la != null && la.ShowOnHUD == false) { continue; } foreach (var hudParams in entity.GetHudParams(friendly)) { MyEntity hudParamsEntity = hudParams.Entity as MyEntity; if (!m_entitiesOnHud.Contains(hudParamsEntity)) { m_entitiesOnHud.Add(hudParamsEntity); if (hudParams.BlinkingTime > 0) { MyHud.HackingMarkers.RegisterMarker(hudParamsEntity, hudParams); } else if (!MyHud.HackingMarkers.MarkerEntities.ContainsKey(hudParamsEntity)) { MyHud.LocationMarkers.RegisterMarker(hudParamsEntity, hudParams); } } } } } //manually draw markers for players that are out of range or have broadcasting turned off if (MySession.Static.AdminSettings.HasFlag(AdminSettingsEnum.ShowPlayers)) { foreach (var player in MySession.Static.Players.GetOnlinePlayers()) { MyCharacter character = player.Character; if (character == null) { continue; } var hudParams = character.GetHudParams(false); foreach (var param in hudParams) { MyEntity hudEntity = (MyEntity)param.Entity; if (m_entitiesOnHud.Contains(hudEntity)) { continue; } m_entitiesOnHud.Add(hudEntity); MyHud.LocationMarkers.RegisterMarker(hudEntity, param); } } } }
public static MyDetectedEntityInfo Create(MyEntity entity, long sensorOwner, Vector3D?hitPosition = new Vector3D?()) { MyDetectedEntityType type; MyRelationsBetweenPlayerAndBlock neutral; string displayName; if (entity == null) { return(new MyDetectedEntityInfo()); } MatrixD zero = MatrixD.Zero; Vector3 velocity = (Vector3)Vector3D.Zero; int totalGamePlayTimeInMilliseconds = MySandboxGame.TotalGamePlayTimeInMilliseconds; BoundingBoxD worldAABB = entity.PositionComp.WorldAABB; if (entity.Physics != null) { zero = entity.Physics.GetWorldMatrix().GetOrientation(); velocity = entity.Physics.LinearVelocity; } MyCubeGrid topMostParent = entity.GetTopMostParent(null) as MyCubeGrid; if (topMostParent != null) { type = (topMostParent.GridSizeEnum != MyCubeSize.Small) ? MyDetectedEntityType.LargeGrid : MyDetectedEntityType.SmallGrid; neutral = (topMostParent.BigOwners.Count != 0) ? MyIDModule.GetRelation(sensorOwner, topMostParent.BigOwners[0], MyOwnershipShareModeEnum.Faction, MyRelationsBetweenPlayerAndBlock.Enemies, MyRelationsBetweenFactions.Enemies, MyRelationsBetweenPlayerAndBlock.FactionShare) : MyRelationsBetweenPlayerAndBlock.NoOwnership; if ((neutral == MyRelationsBetweenPlayerAndBlock.Owner) || (neutral == MyRelationsBetweenPlayerAndBlock.FactionShare)) { displayName = topMostParent.DisplayName; } else { displayName = (topMostParent.GridSizeEnum != MyCubeSize.Small) ? MyTexts.GetString(MySpaceTexts.DetectedEntity_LargeGrid) : MyTexts.GetString(MySpaceTexts.DetectedEntity_SmallGrid); } zero = topMostParent.WorldMatrix.GetOrientation(); return(new MyDetectedEntityInfo(topMostParent.EntityId, displayName, type, hitPosition, zero, topMostParent.Physics.LinearVelocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds)); } MyCharacter character = entity as MyCharacter; if (character != null) { type = !character.IsPlayer ? MyDetectedEntityType.CharacterOther : MyDetectedEntityType.CharacterHuman; neutral = MyIDModule.GetRelation(sensorOwner, character.GetPlayerIdentityId(), MyOwnershipShareModeEnum.Faction, MyRelationsBetweenPlayerAndBlock.Enemies, MyRelationsBetweenFactions.Enemies, MyRelationsBetweenPlayerAndBlock.FactionShare); if ((neutral == MyRelationsBetweenPlayerAndBlock.Owner) || (neutral == MyRelationsBetweenPlayerAndBlock.FactionShare)) { displayName = character.DisplayNameText; } else { displayName = !character.IsPlayer ? MyTexts.GetString(MySpaceTexts.DetectedEntity_CharacterOther) : MyTexts.GetString(MySpaceTexts.DetectedEntity_CharacterHuman); } return(new MyDetectedEntityInfo(entity.EntityId, displayName, type, hitPosition, zero, velocity, neutral, character.Model.BoundingBox.Transform(character.WorldMatrix), (long)totalGamePlayTimeInMilliseconds)); } neutral = MyRelationsBetweenPlayerAndBlock.Neutral; MyFloatingObject obj2 = entity as MyFloatingObject; if (obj2 != null) { displayName = obj2.Item.Content.SubtypeName; return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.FloatingObject, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds)); } MyInventoryBagEntity entity2 = entity as MyInventoryBagEntity; if (entity2 != null) { displayName = entity2.DisplayName; return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.FloatingObject, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds)); } MyPlanet planet = entity as MyPlanet; if (planet != null) { displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Planet); return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Planet, hitPosition, zero, velocity, neutral, BoundingBoxD.CreateFromSphere(new BoundingSphereD(planet.PositionComp.GetPosition(), (double)planet.MaximumRadius)), (long)totalGamePlayTimeInMilliseconds)); } MyVoxelPhysics physics = entity as MyVoxelPhysics; if (physics != null) { displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Planet); return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Planet, hitPosition, zero, velocity, neutral, BoundingBoxD.CreateFromSphere(new BoundingSphereD(physics.Parent.PositionComp.GetPosition(), (double)physics.Parent.MaximumRadius)), (long)totalGamePlayTimeInMilliseconds)); } if (entity is MyVoxelMap) { displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Asteroid); return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Asteroid, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds)); } if (entity is MyMeteor) { displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Meteor); return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Meteor, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds)); } if (entity is MyMissile) { return(new MyDetectedEntityInfo(entity.EntityId, entity.DisplayName, MyDetectedEntityType.Missile, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds)); } Vector3D?nullable = null; MatrixD orientation = new MatrixD(); Vector3 vector2 = new Vector3(); return(new MyDetectedEntityInfo(0L, string.Empty, MyDetectedEntityType.Unknown, nullable, orientation, vector2, MyRelationsBetweenPlayerAndBlock.NoOwnership, new BoundingBoxD(), (long)MySandboxGame.TotalGamePlayTimeInMilliseconds)); }