* Content side new physics structure

* BroadPhase outline done

* But we need to fix WorldAABB

* Fix static pvs AABB

* Fix import

* Rando fixes

* B is for balloon

* Change human mob hitbox to circle

* Decent movement

* Start adding friction to player controller

I think it's the best way to go about it to keep other objects somewhat consistent for physics.

* This baby can fit so many physics bugs in it.

* Slight mob mover optimisations.

* Player mover kinda works okay.

* Beginnings of testbed

* More testbed

* Circlestack bed

* Namespaces

* BB fixes

* Pull WorldAABB

* Joint pulling

* Semi-decent movement I guess.

* Pulling better

* Bullet controller + old movement

* im too dumb for this shit

* Use kinematic mob controller again

It's probably for the best TBH

* Stashed shitcode

* Remove SlipController

* In which movement code is entirely refactored

* Singularity fix

* Fix ApplyLinearImpulse

* MoveRelay fix

* Fix door collisions

* Disable subfloor collisions

Saves on broadphase a fair bit

* Re-implement ClimbController

* Zumzum's pressure

* Laggy item throwing

* Minor atmos change

* Some caching

* Optimise controllers

* Optimise CollideWith to hell and back

* Re-do throwing and tile friction

* Landing too

* Optimise controllers

* Move CCVars and other stuff swept is beautiful

* Cleanup a bunch of controllers

* Fix shooting and high pressure movement controller

* Flashing improvements

* Stuff and things

* Combat collisions

* Combat mode collisions

* Pulling distance joint again

* Cleanup physics interfaces

* More like scuffedularity

* Shit's fucked

* Haha tests go green

* Bigmoneycrab

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2021-03-01 03:11:29 +11:00
committed by GitHub
parent 9deee05279
commit 3e64fd56a1
211 changed files with 2602 additions and 2562 deletions

View File

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

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,10 +90,12 @@ namespace Content.Server.GameObjects.Components.Singularity
/// <param name="toRepell">Entity to repell.</param>
public void TryRepell(IEntity repellFrom, IEntity toRepell)
{
if (!_fields.Contains(repellFrom) || !toRepell.TryGetComponent<IPhysicsComponent>(out var collidableComponent)) return;
// TODO: Fix this also it's fucking repel
if (!_fields.Contains(repellFrom) || !toRepell.TryGetComponent<IPhysBody>(out var collidableComponent)) return;
return;
var speed = 5;
var containmentFieldRepellController = collidableComponent.EnsureController<ContainmentFieldRepellController>();
//var containmentFieldRepellController = collidableComponent.EnsureController<ContainmentFieldRepellController>();
if (!CanRepell(toRepell))
{
@@ -106,22 +108,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,6 +10,7 @@ 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;
@@ -117,7 +118,7 @@ namespace Content.Server.GameObjects.Components.Singularity
var dirVec = direction.ToVec();
var ray = new CollisionRay(Owner.Transform.WorldPosition, dirVec, (int) CollisionGroup.MobMask);
var rawRayCastResults = _physicsManager.IntersectRay(Owner.Transform.MapID, ray, 4.5f, Owner, false);
var rawRayCastResults = EntitySystem.Get<SharedBroadPhaseSystem>().IntersectRay(Owner.Transform.MapID, ray, 4.5f, Owner, false);
var rayCastResults = rawRayCastResults as RayCastResults[] ?? rawRayCastResults.ToArray();
if(!rayCastResults.Any()) continue;
@@ -182,9 +183,9 @@ namespace Content.Server.GameObjects.Components.Singularity
}
}
public void CollideWith(IEntity collidedWith)
public void CollideWith(IPhysBody ourBody, IPhysBody otherBody)
{
if(collidedWith.HasComponent<EmitterBoltComponent>())
if (otherBody.Entity.HasComponent<EmitterBoltComponent>())
{
ReceivePower(4);
}

View File

@@ -254,7 +254,7 @@ namespace Content.Server.GameObjects.Components.Singularity
return;
}
physicsComponent.Status = BodyStatus.InAir;
physicsComponent.BodyStatus = BodyStatus.InAir;
if (!projectile.TryGetComponent<ProjectileComponent>(out var projectileComponent))
{
@@ -265,7 +265,6 @@ 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,6 +14,7 @@ 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;
@@ -38,7 +39,6 @@ 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.PhysicsShapes.Any() && _collidableComponent.PhysicsShapes[0] is PhysShapeCircle circle)
if(_collidableComponent != null && _collidableComponent.Fixtures.Any() && _collidableComponent.Fixtures[0].Shape is PhysShapeCircle circle)
{
circle.Radius = _level - 0.5f;
}
@@ -95,7 +95,6 @@ namespace Content.Server.GameObjects.Components.Singularity
_ => 0
};
private SingularityController? _singularityController;
private PhysicsComponent? _collidableComponent;
private SpriteComponent? _spriteComponent;
private RadiationPulseComponent? _radiationPulseComponent;
@@ -129,9 +128,6 @@ 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");
@@ -140,60 +136,18 @@ namespace Content.Server.GameObjects.Components.Singularity
Level = 1;
}
public void Update()
public void Update(int 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);
Energy -= EnergyDrain * seconds;
}
private readonly List<IEntity> _previousPulledEntities = new();
public void CleanupPulledEntities()
void ICollideBehavior.CollideWith(IPhysBody ourBody, IPhysBody otherBody)
{
foreach (var previousPulledEntity in _previousPulledEntities)
var otherEntity = otherBody.Entity;
if (otherEntity.TryGetComponent<IMapGridComponent>(out var mapGridComponent))
{
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))
foreach (var tile in mapGridComponent.Grid.GetTilesIntersecting(ourBody.GetWorldAABB()))
{
mapGridComponent.Grid.SetTile(tile.GridIndices, Tile.Empty);
Energy++;
@@ -201,14 +155,14 @@ namespace Content.Server.GameObjects.Components.Singularity
return;
}
if (entity.HasComponent<ContainmentFieldComponent>() || (entity.TryGetComponent<ContainmentFieldGeneratorComponent>(out var component) && component.CanRepell(Owner)))
if (otherEntity.HasComponent<ContainmentFieldComponent>() || (otherEntity.TryGetComponent<ContainmentFieldGeneratorComponent>(out var component) && component.CanRepell(Owner)))
{
return;
}
if (entity.IsInContainer()) return;
if (otherEntity.IsInContainer()) return;
entity.Delete();
otherEntity.Delete();
Energy++;
}
@@ -216,7 +170,6 @@ namespace Content.Server.GameObjects.Components.Singularity
{
_playingSound?.Stop();
_audioSystem.PlayAtCoords("/Audio/Effects/singularity_collapse.ogg", Owner.Transform.Coordinates);
CleanupPulledEntities();
base.OnRemove();
}
}