Update content for physics query namespace change (#4701)

This commit is contained in:
metalgearsloth
2021-10-10 14:18:19 +11:00
committed by GitHub
parent 801033b582
commit f0f7cd0e76
11 changed files with 17 additions and 54 deletions

View File

@@ -14,38 +14,6 @@ namespace Content.Server.AI.Utils
{
public static class Visibility
{
// Just do a simple range check, then chuck the ray out. If we get bigger than 1 tile mobs may need to adjust this
public static bool InLineOfSight(IEntity owner, IEntity target)
{
var range = 50.0f;
if (owner.Transform.GridID != target.Transform.GridID)
{
return false;
}
if (owner.TryGetComponent(out AiControllerComponent? controller))
{
var targetRange = (target.Transform.Coordinates.Position - owner.Transform.Coordinates.Position).Length;
if (targetRange > controller.VisionRadius)
{
return false;
}
range = controller.VisionRadius;
}
var angle = new Angle(target.Transform.Coordinates.Position - owner.Transform.Coordinates.Position);
var ray = new CollisionRay(
owner.Transform.Coordinates.Position,
angle.ToVec(),
(int)(CollisionGroup.Opaque | CollisionGroup.Impassable | CollisionGroup.MobImpassable));
var rayCastResults = EntitySystem.Get<SharedBroadphaseSystem>().IntersectRay(owner.Transform.MapID, ray, range, owner).ToList();
return rayCastResults.Count > 0 && rayCastResults[0].HitEntity == target;
}
// Should this be in robust or something? Fark it
public static IEnumerable<IEntity> GetNearestEntities(EntityCoordinates grid, Type component, float range)
{

View File

@@ -441,7 +441,7 @@ namespace Content.Server.Doors.Components
if (safety && Owner.TryGetComponent(out PhysicsComponent? physicsComponent))
{
var broadPhaseSystem = EntitySystem.Get<SharedBroadphaseSystem>();
var broadPhaseSystem = EntitySystem.Get<SharedPhysicsSystem>();
// Use this version so we can ignore the CanCollide being false
foreach(var e in broadPhaseSystem.GetCollidingEntities(physicsComponent.Owner.Transform.MapID, physicsComponent.GetWorldAABB()))

View File

@@ -97,7 +97,7 @@ namespace Content.Server.Singularity.Components
var dirVec = direction.ToVec();
var ray = new CollisionRay(Owner.Transform.WorldPosition, dirVec, (int) CollisionGroup.MobMask);
var rawRayCastResults = EntitySystem.Get<SharedBroadphaseSystem>().IntersectRay(Owner.Transform.MapID, ray, 4.5f, Owner, false);
var rawRayCastResults = EntitySystem.Get<SharedPhysicsSystem>().IntersectRay(Owner.Transform.MapID, ray, 4.5f, Owner, false);
var rayCastResults = rawRayCastResults as RayCastResults[] ?? rawRayCastResults.ToArray();
if(!rayCastResults.Any()) continue;

View File

@@ -137,7 +137,7 @@ namespace Content.Server.Solar.EntitySystems
// Determine if the solar panel is occluded, and zero out coverage if so.
// FIXME: The "Opaque" collision group doesn't seem to work right now.
var ray = new CollisionRay(entity.Transform.WorldPosition, TowardsSun.ToWorldVec(), (int) CollisionGroup.Opaque);
var rayCastResults = EntitySystem.Get<SharedBroadphaseSystem>().IntersectRay(entity.Transform.MapID, ray, SunOcclusionCheckDistance, entity);
var rayCastResults = Get<SharedPhysicsSystem>().IntersectRay(entity.Transform.MapID, ray, SunOcclusionCheckDistance, entity);
if (rayCastResults.Any())
coverage = 0;
}

View File

@@ -216,7 +216,7 @@ namespace Content.Server.Weapon.Melee
for (var i = 0; i < increments; i++)
{
var castAngle = new Angle(baseAngle + increment * i);
var res = Get<SharedBroadphaseSystem>().IntersectRay(mapId,
var res = Get<SharedPhysicsSystem>().IntersectRay(mapId,
new CollisionRay(position, castAngle.ToWorldVec(),
(int) (CollisionGroup.Impassable | CollisionGroup.MobImpassable)), range, ignore).ToList();

View File

@@ -384,7 +384,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
private void FireHitscan(IEntity shooter, HitscanComponent hitscan, Angle angle)
{
var ray = new CollisionRay(Owner.Transform.Coordinates.ToMapPos(Owner.EntityManager), angle.ToVec(), (int) hitscan.CollisionMask);
var physicsManager = EntitySystem.Get<SharedBroadphaseSystem>();
var physicsManager = EntitySystem.Get<SharedPhysicsSystem>();
var rayCastResults = physicsManager.IntersectRay(Owner.Transform.MapID, ray, hitscan.MaxLength, shooter, false).ToList();
if (rayCastResults.Count >= 1)

View File

@@ -33,7 +33,7 @@ namespace Content.Shared.Construction.Conditions
return false;
// now we need to check that user actually tries to build wallmount on a wall
var physics = EntitySystem.Get<SharedBroadphaseSystem>();
var physics = EntitySystem.Get<SharedPhysicsSystem>();
var rUserToObj = new CollisionRay(userWorldPosition, userToObject.Normalized, (int) CollisionGroup.Impassable);
var length = userToObject.Length;
var userToObjRaycastResults = physics.IntersectRayWithPredicate(user.Transform.MapID, rUserToObj, maxLength: length,

View File

@@ -18,7 +18,7 @@ namespace Content.Shared.Interaction
[UsedImplicitly]
public abstract class SharedInteractionSystem : EntitySystem
{
[Dependency] private readonly SharedBroadphaseSystem _sharedBroadphaseSystem = default!;
[Dependency] private readonly SharedPhysicsSystem _sharedBroadphaseSystem = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
public const float InteractionRange = 2;

View File

@@ -181,7 +181,7 @@ namespace Content.Shared.Maps
/// </summary>
public static bool IsBlockedTurf(this TileRef turf, bool filterMobs)
{
var physics = EntitySystem.Get<SharedBroadphaseSystem>();
var physics = EntitySystem.Get<SharedPhysicsSystem>();
var worldBox = GetWorldTileBox(turf);

View File

@@ -26,7 +26,7 @@ namespace Content.Shared.Movement
[Dependency] private readonly IMapManager _mapManager = default!;
private ActionBlockerSystem _blocker = default!;
private SharedBroadphaseSystem _broadPhaseSystem = default!;
private SharedPhysicsSystem _broadPhaseSystem = default!;
private bool _relativeMovement;
@@ -38,7 +38,7 @@ namespace Content.Shared.Movement
public override void Initialize()
{
base.Initialize();
_broadPhaseSystem = EntitySystem.Get<SharedBroadphaseSystem>();
_broadPhaseSystem = EntitySystem.Get<SharedPhysicsSystem>();
_blocker = EntitySystem.Get<ActionBlockerSystem>();
var configManager = IoCManager.Resolve<IConfigurationManager>();
configManager.OnValueChanged(CCVars.RelativeMovement, SetRelativeMovement, true);
@@ -161,12 +161,7 @@ namespace Content.Shared.Movement
/// <summary>
/// Used for weightlessness to determine if we are near a wall.
/// </summary>
/// <param name="broadPhaseSystem"></param>
/// <param name="transform"></param>
/// <param name="mover"></param>
/// <param name="collider"></param>
/// <returns></returns>
public static bool IsAroundCollider(SharedBroadphaseSystem broadPhaseSystem, ITransformComponent transform, IMobMoverComponent mover, IPhysBody collider)
public static bool IsAroundCollider(SharedPhysicsSystem broadPhaseSystem, ITransformComponent transform, IMobMoverComponent mover, IPhysBody collider)
{
var enlargedAABB = collider.GetWorldAABB().Enlarged(mover.GrabRange);

View File

@@ -16,9 +16,9 @@ namespace Content.Shared.Spawning
EntityCoordinates coordinates,
CollisionGroup collisionLayer,
in Box2? box = null,
SharedBroadphaseSystem? physicsManager = null)
SharedPhysicsSystem? physicsManager = null)
{
physicsManager ??= EntitySystem.Get<SharedBroadphaseSystem>();
physicsManager ??= EntitySystem.Get<SharedPhysicsSystem>();
var mapCoordinates = coordinates.ToMap(entityManager);
return entityManager.SpawnIfUnobstructed(prototypeName, mapCoordinates, collisionLayer, box, physicsManager);
@@ -30,10 +30,10 @@ namespace Content.Shared.Spawning
MapCoordinates coordinates,
CollisionGroup collisionLayer,
in Box2? box = null,
SharedBroadphaseSystem? collision = null)
SharedPhysicsSystem? collision = null)
{
var boxOrDefault = box.GetValueOrDefault(Box2.UnitCentered).Translated(coordinates.Position);
collision ??= EntitySystem.Get<SharedBroadphaseSystem>();
collision ??= EntitySystem.Get<SharedPhysicsSystem>();
foreach (var body in collision.GetCollidingEntities(coordinates.MapId, in boxOrDefault))
{
@@ -61,7 +61,7 @@ namespace Content.Shared.Spawning
CollisionGroup collisionLayer,
[NotNullWhen(true)] out IEntity? entity,
Box2? box = null,
SharedBroadphaseSystem? physicsManager = null)
SharedPhysicsSystem? physicsManager = null)
{
entity = entityManager.SpawnIfUnobstructed(prototypeName, coordinates, collisionLayer, box, physicsManager);
@@ -75,7 +75,7 @@ namespace Content.Shared.Spawning
CollisionGroup collisionLayer,
[NotNullWhen(true)] out IEntity? entity,
in Box2? box = null,
SharedBroadphaseSystem? physicsManager = null)
SharedPhysicsSystem? physicsManager = null)
{
entity = entityManager.SpawnIfUnobstructed(prototypeName, coordinates, collisionLayer, box, physicsManager);