Revert "Physics (#3452)"

This reverts commit 3e64fd56a1.
This commit is contained in:
Pieter-Jan Briers
2021-02-28 18:49:48 +01:00
parent eddec5fcce
commit 1eb0fbd8d0
211 changed files with 2560 additions and 2600 deletions

View File

@@ -1,6 +1,5 @@
#nullable enable
using Robust.Shared.GameObjects;
using Robust.Shared.Physics;
namespace Content.Server.GameObjects.Components.Singularity
{
@@ -10,7 +9,7 @@ namespace Content.Server.GameObjects.Components.Singularity
public override string Name => "ContainmentField";
public ContainmentFieldConnection? Parent;
public void CollideWith(IPhysBody ourBody, IPhysBody otherBody)
public void CollideWith(IEntity collidedWith)
{
if (Parent == null)
{
@@ -18,7 +17,7 @@ namespace Content.Server.GameObjects.Components.Singularity
return;
}
Parent.TryRepell(Owner, otherBody.Entity);
Parent.TryRepell(Owner, collidedWith);
}
}
}

View File

@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using System.Threading;
using Content.Shared.Physics;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Timer = Robust.Shared.Timing.Timer;
namespace Content.Server.GameObjects.Components.Singularity
@@ -90,12 +90,10 @@ namespace Content.Server.GameObjects.Components.Singularity
/// <param name="toRepell">Entity to repell.</param>
public void TryRepell(IEntity repellFrom, IEntity toRepell)
{
// TODO: Fix this also it's fucking repel
if (!_fields.Contains(repellFrom) || !toRepell.TryGetComponent<IPhysBody>(out var collidableComponent)) return;
if (!_fields.Contains(repellFrom) || !toRepell.TryGetComponent<IPhysicsComponent>(out var collidableComponent)) return;
return;
var speed = 5;
//var containmentFieldRepellController = collidableComponent.EnsureController<ContainmentFieldRepellController>();
var containmentFieldRepellController = collidableComponent.EnsureController<ContainmentFieldRepellController>();
if (!CanRepell(toRepell))
{
@@ -108,22 +106,22 @@ namespace Content.Server.GameObjects.Components.Singularity
{
if (repellFrom.Transform.WorldPosition.X.CompareTo(toRepell.Transform.WorldPosition.X) > 0)
{
//containmentFieldRepellController.Repell(Direction.West, speed);
containmentFieldRepellController.Repell(Direction.West, speed);
}
else
{
//containmentFieldRepellController.Repell(Direction.East, speed);
containmentFieldRepellController.Repell(Direction.East, speed);
}
}
else
{
if (repellFrom.Transform.WorldPosition.Y.CompareTo(toRepell.Transform.WorldPosition.Y) > 0)
{
//containmentFieldRepellController.Repell(Direction.South, speed);
containmentFieldRepellController.Repell(Direction.South, speed);
}
else
{
//containmentFieldRepellController.Repell(Direction.North, speed);
containmentFieldRepellController.Repell(Direction.North, speed);
}
}

View File

@@ -10,7 +10,6 @@ using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Broadphase;
using Robust.Shared.ViewVariables;
using Robust.Server.GameObjects;
@@ -118,7 +117,7 @@ namespace Content.Server.GameObjects.Components.Singularity
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 = _physicsManager.IntersectRay(Owner.Transform.MapID, ray, 4.5f, Owner, false);
var rayCastResults = rawRayCastResults as RayCastResults[] ?? rawRayCastResults.ToArray();
if(!rayCastResults.Any()) continue;
@@ -183,9 +182,9 @@ namespace Content.Server.GameObjects.Components.Singularity
}
}
public void CollideWith(IPhysBody ourBody, IPhysBody otherBody)
public void CollideWith(IEntity collidedWith)
{
if (otherBody.Entity.HasComponent<EmitterBoltComponent>())
if(collidedWith.HasComponent<EmitterBoltComponent>())
{
ReceivePower(4);
}

View File

@@ -254,7 +254,7 @@ namespace Content.Server.GameObjects.Components.Singularity
return;
}
physicsComponent.BodyStatus = BodyStatus.InAir;
physicsComponent.Status = BodyStatus.InAir;
if (!projectile.TryGetComponent<ProjectileComponent>(out var projectileComponent))
{
@@ -265,6 +265,7 @@ namespace Content.Server.GameObjects.Components.Singularity
projectileComponent.IgnoreEntity(Owner);
physicsComponent
.EnsureController<BulletController>()
.LinearVelocity = Owner.Transform.WorldRotation.ToVec() * 20f;
projectile.Transform.LocalRotation = Owner.Transform.WorldRotation;

View File

@@ -14,7 +14,6 @@ using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics.Shapes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
@@ -39,6 +38,7 @@ namespace Content.Server.GameObjects.Components.Singularity
_energy = value;
if (_energy <= 0)
{
if(_singularityController != null) _singularityController.LinearVelocity = Vector2.Zero;
_spriteComponent?.LayerSetVisible(0, false);
Owner.Delete();
@@ -75,7 +75,7 @@ namespace Content.Server.GameObjects.Components.Singularity
_spriteComponent?.LayerSetRSI(0, "Effects/Singularity/singularity_" + _level + ".rsi");
_spriteComponent?.LayerSetState(0, "singularity_" + _level);
if(_collidableComponent != null && _collidableComponent.Fixtures.Any() && _collidableComponent.Fixtures[0].Shape is PhysShapeCircle circle)
if(_collidableComponent != null && _collidableComponent.PhysicsShapes.Any() && _collidableComponent.PhysicsShapes[0] is PhysShapeCircle circle)
{
circle.Radius = _level - 0.5f;
}
@@ -95,6 +95,7 @@ namespace Content.Server.GameObjects.Components.Singularity
_ => 0
};
private SingularityController? _singularityController;
private PhysicsComponent? _collidableComponent;
private SpriteComponent? _spriteComponent;
private RadiationPulseComponent? _radiationPulseComponent;
@@ -128,6 +129,9 @@ namespace Content.Server.GameObjects.Components.Singularity
Logger.Error("SingularityComponent was spawned without SpriteComponent");
}
_singularityController = _collidableComponent?.EnsureController<SingularityController>();
if(_singularityController!=null)_singularityController.ControlledComponent = _collidableComponent;
if (!Owner.TryGetComponent(out _radiationPulseComponent))
{
Logger.Error("SingularityComponent was spawned without RadiationPulseComponent");
@@ -136,18 +140,60 @@ namespace Content.Server.GameObjects.Components.Singularity
Level = 1;
}
public void Update(int seconds)
public void Update()
{
Energy -= EnergyDrain * seconds;
Energy -= EnergyDrain;
if(Level == 1) return;
//pushing
var pushVector = new Vector2((_random.Next(-10, 10)), _random.Next(-10, 10));
while (pushVector.X == 0 && pushVector.Y == 0)
{
pushVector = new Vector2((_random.Next(-10, 10)), _random.Next(-10, 10));
}
_singularityController?.Push(pushVector.Normalized, 2);
}
void ICollideBehavior.CollideWith(IPhysBody ourBody, IPhysBody otherBody)
private readonly List<IEntity> _previousPulledEntities = new();
public void CleanupPulledEntities()
{
var otherEntity = otherBody.Entity;
if (otherEntity.TryGetComponent<IMapGridComponent>(out var mapGridComponent))
foreach (var previousPulledEntity in _previousPulledEntities)
{
foreach (var tile in mapGridComponent.Grid.GetTilesIntersecting(ourBody.GetWorldAABB()))
if(previousPulledEntity.Deleted) continue;
if (!previousPulledEntity.TryGetComponent<PhysicsComponent>(out var collidableComponent)) continue;
var controller = collidableComponent.EnsureController<SingularityPullController>();
controller.StopPull();
}
_previousPulledEntities.Clear();
}
public void PullUpdate()
{
CleanupPulledEntities();
var entitiesToPull = Owner.EntityManager.GetEntitiesInRange(Owner.Transform.Coordinates, Level * 10);
foreach (var entity in entitiesToPull)
{
if (!entity.TryGetComponent<PhysicsComponent>(out var collidableComponent)) continue;
if (entity.HasComponent<GhostComponent>()) continue;
var controller = collidableComponent.EnsureController<SingularityPullController>();
if(Owner.Transform.Coordinates.EntityId != entity.Transform.Coordinates.EntityId) continue;
var vec = (Owner.Transform.Coordinates - entity.Transform.Coordinates).Position;
if (vec == Vector2.Zero) continue;
var speed = 10 / vec.Length * Level;
controller.Pull(vec.Normalized, speed);
_previousPulledEntities.Add(entity);
}
}
void ICollideBehavior.CollideWith(IEntity entity)
{
if (_collidableComponent == null) return; //how did it even collide then? :D
if (entity.TryGetComponent<IMapGridComponent>(out var mapGridComponent))
{
foreach (var tile in mapGridComponent.Grid.GetTilesIntersecting(((IPhysBody) _collidableComponent).WorldAABB))
{
mapGridComponent.Grid.SetTile(tile.GridIndices, Tile.Empty);
Energy++;
@@ -155,14 +201,14 @@ namespace Content.Server.GameObjects.Components.Singularity
return;
}
if (otherEntity.HasComponent<ContainmentFieldComponent>() || (otherEntity.TryGetComponent<ContainmentFieldGeneratorComponent>(out var component) && component.CanRepell(Owner)))
if (entity.HasComponent<ContainmentFieldComponent>() || (entity.TryGetComponent<ContainmentFieldGeneratorComponent>(out var component) && component.CanRepell(Owner)))
{
return;
}
if (otherEntity.IsInContainer()) return;
if (entity.IsInContainer()) return;
otherEntity.Delete();
entity.Delete();
Energy++;
}
@@ -170,6 +216,7 @@ namespace Content.Server.GameObjects.Components.Singularity
{
_playingSound?.Stop();
_audioSystem.PlayAtCoords("/Audio/Effects/singularity_collapse.ogg", Owner.Transform.Coordinates);
CleanupPulledEntities();
base.OnRemove();
}
}