Skip to content

Commit

Permalink
Physics (space-wizards#3452)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
metalgearsloth and Metal Gear Sloth authored Feb 28, 2021
1 parent 9deee05 commit 3e64fd5
Show file tree
Hide file tree
Showing 211 changed files with 2,598 additions and 2,558 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ public override void HandleComponentState(ComponentState curState, ComponentStat
{
base.HandleComponentState(curState, nextState);

if (curState is not ClimbModeComponentState climbModeState || Body == null)
if (curState is not ClimbModeComponentState climbModeState)
{
return;
}

IsClimbing = climbModeState.Climbing;
OwnerIsTransitioning = climbModeState.IsTransitioning;
}

public override bool IsClimbing { get; set; }
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Physics;

namespace Content.Client.GameObjects.Components.Suspicion
{
Expand Down Expand Up @@ -62,7 +63,7 @@ private void DrawScreen(DrawingHandleScreen screen)
continue;
}

if (!ally.TryGetComponent(out IPhysicsComponent physics))
if (!ally.TryGetComponent(out IPhysBody physics))
{
continue;
}
Expand All @@ -82,15 +83,15 @@ private void DrawScreen(DrawingHandleScreen screen)
continue;
}

var worldBox = physics.WorldAABB;
var worldBox = physics.GetWorldAABB();

// if not on screen, or too small, continue
if (!worldBox.Intersects(in viewport) || worldBox.IsEmpty())
{
continue;
}

var screenCoordinates = _eyeManager.WorldToScreen(physics.WorldAABB.TopLeft + (0, 0.5f));
var screenCoordinates = _eyeManager.WorldToScreen(physics.GetWorldAABB().TopLeft + (0, 0.5f));
DrawString(screen, _font, screenCoordinates, _traitorText, Color.OrangeRed);
}
}
Expand Down
43 changes: 0 additions & 43 deletions Content.Client/GameObjects/EntitySystems/MoverSystem.cs

This file was deleted.

15 changes: 12 additions & 3 deletions Content.Client/GameObjects/EntitySystems/SubFloorHideSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,22 @@ private void UpdateTile(IMapGrid grid, Vector2i position)
foreach (var snapGridComponent in grid.GetSnapGridCell(position, SnapGridOffset.Center))
{
var entity = snapGridComponent.Owner;
if (!entity.TryGetComponent(out SubFloorHideComponent subFloorComponent) ||
!entity.TryGetComponent(out ISpriteComponent spriteComponent))
if (!entity.TryGetComponent(out SubFloorHideComponent subFloorComponent))
{
continue;
}

spriteComponent.Visible = EnableAll || !subFloorComponent.Running || tileDef.IsSubFloor;
var enabled = EnableAll || !subFloorComponent.Running || tileDef.IsSubFloor;

if (entity.TryGetComponent(out ISpriteComponent spriteComponent))
{
spriteComponent.Visible = enabled;
}

if (entity.TryGetComponent(out PhysicsComponent physicsComponent))
{
physicsComponent.CanCollide = enabled;
}
}
}
}
Expand Down
36 changes: 36 additions & 0 deletions Content.Client/Physics/Controllers/MoverController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#nullable enable
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.Physics.Controllers;
using Robust.Client.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Physics.Dynamics;

namespace Content.Client.Physics.Controllers
{
public sealed class MoverController : SharedMoverController
{
[Dependency] private readonly IPlayerManager _playerManager = default!;

public override void UpdateBeforeSolve(bool prediction, float frameTime)
{
base.UpdateBeforeSolve(prediction, frameTime);

var player = _playerManager.LocalPlayer?.ControlledEntity;
if (player == null ||
!player.TryGetComponent(out IMoverComponent? mover) ||
!player.TryGetComponent(out PhysicsComponent? body)) return;

body.Predict = true; // TODO: equal prediction instead of true?

// Server-side should just be handled on its own so we'll just do this shizznit
if (player.TryGetComponent(out IMobMoverComponent? mobMover))
{
HandleMobMovement(mover, body, mobMover);
return;
}

HandleKinematicMovement(mover, body);
}
}
}
27 changes: 13 additions & 14 deletions Content.IntegrationTests/Tests/Doors/AirlockTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public class AirlockTest : ContentIntegrationTest
components:
- type: Physics
anchored: false
shapes:
- !type:PhysShapeAabb
bounds: ""-0.49,-0.49,0.49,0.49""
fixtures:
- shape:
!type:PhysShapeAabb
bounds: ""-0.49,-0.49,0.49,0.49""
layer:
- Impassable
Expand All @@ -33,9 +34,10 @@ public class AirlockTest : ContentIntegrationTest
- type: Door
- type: Airlock
- type: Physics
shapes:
- !type:PhysShapeAabb
bounds: ""-0.49,-0.49,0.49,0.49""
fixtures:
- shape:
!type:PhysShapeAabb
bounds: ""-0.49,-0.49,0.49,0.49""
mask:
- Impassable
";
Expand Down Expand Up @@ -111,9 +113,9 @@ public async Task AirlockBlockTest()
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();

IPhysBody physBody = null;
IEntity physicsDummy = null;
IEntity airlock = null;
TestController controller = null;
ServerDoorComponent doorComponent = null;

var physicsDummyStartingX = -1;
Expand All @@ -128,9 +130,7 @@ public async Task AirlockBlockTest()

airlock = entityManager.SpawnEntity("AirlockDummy", new MapCoordinates((0, 0), mapId));

Assert.True(physicsDummy.TryGetComponent(out IPhysicsComponent physics));

controller = physics.EnsureController<TestController>();
Assert.True(physicsDummy.TryGetComponent(out physBody));

Assert.True(airlock.TryGetComponent(out doorComponent));
Assert.That(doorComponent.State, Is.EqualTo(SharedDoorComponent.DoorState.Closed));
Expand All @@ -139,12 +139,13 @@ public async Task AirlockBlockTest()
await server.WaitIdleAsync();

// Push the human towards the airlock
controller.LinearVelocity = (0.5f, 0);
Assert.That(physBody != null);
physBody.LinearVelocity = (0.5f, 0);

for (var i = 0; i < 240; i += 10)
{
// Keep the airlock awake so they collide
airlock.GetComponent<IPhysicsComponent>().WakeBody();
airlock.GetComponent<IPhysBody>().WakeBody();

// Ensure that it is still closed
Assert.That(doorComponent.State, Is.EqualTo(SharedDoorComponent.DoorState.Closed));
Expand All @@ -159,7 +160,5 @@ public async Task AirlockBlockTest()
// Blocked by the airlock
Assert.That(physicsDummy.Transform.MapPosition.X, Is.Negative.Or.Zero);
}

private class TestController : VirtualController { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Physics;

namespace Content.IntegrationTests.Tests.GameObjects.Components.Movement
{
Expand Down Expand Up @@ -59,15 +60,12 @@ public async Task Test()
// Now let's make the player enter a climbing transitioning state.
climbing.IsClimbing = true;
climbing.TryMoveTo(human.Transform.WorldPosition, table.Transform.WorldPosition);
var body = human.GetComponent<IPhysicsComponent>();

Assert.That(body.HasController<ClimbController>(), "Player has no ClimbController");
var body = human.GetComponent<IPhysBody>();
// TODO: Check it's climbing

// Force the player out of climb state. It should immediately remove the ClimbController.
climbing.IsClimbing = false;

Assert.That(!body.HasController<ClimbController>(), "Player wrongly has a ClimbController");

});

await server.WaitIdleAsync();
Expand Down
79 changes: 0 additions & 79 deletions Content.IntegrationTests/Tests/Pulling/PullTest.cs

This file was deleted.

Loading

0 comments on commit 3e64fd5

Please sign in to comment.