Files
tbd-station-14/Content.Server/Commands/Physics/TestbedCommand.cs
metalgearsloth 4d064abcd7 Physics (#3485)
* 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

* Fix dupe pulling

* Zumzum's based fix

* Don't run tile friction for non-predicted bodies

* Experimental pulling improvement

* Everything's a poly now

* Optimise AI region debugging a bit

Could still be better but should improve default performance a LOT

* Mover no updater

* Crazy kinematic body idea

* Good collisions

* KinematicController

* Fix aghost

* Throwing refactor

* Pushing cleanup

* Fix throwing and footstep sounds

* Frametime in ICollideBehavior

* Fix stuff

* Actually fix weightlessness

* Optimise collision behaviors a lot

* Make open lockers still collide with walls

* powwweeerrrrr

* Merge master proper

* AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

* AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

* AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

* Ch ch ch changesss

* SHIP IT

* Fix #if DEBUG

* Fix vaulting and item locker collision

* Fix throwing

* Editing yaml by hand what can go wrong

* on

* Last yaml fixes

* Okay now it's fixed

* Linter

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
Co-authored-by: Vera Aguilera Puerto <zddm@outlook.es>
2021-03-08 04:09:59 +11:00

235 lines
8.5 KiB
C#

// MIT License
// Copyright (c) 2019 Erin Catto
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using Content.Server.Administration;
using Content.Shared.Administration;
using Content.Shared.Physics;
using Robust.Server.Player;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Dynamics.Shapes;
using Robust.Shared.Timing;
#nullable enable
namespace Content.Server.Commands.Physics
{
/*
* I didn't use blueprints because this is way easier to iterate upon as I can shit out testbed upon testbed on new maps
* and never have to leave my debugger.
*/
/// <summary>
/// Copies of Box2D's physics testbed for debugging.
/// </summary>
[AdminCommand(AdminFlags.Mapping)]
public class TestbedCommand : IConsoleCommand
{
public string Command => "testbed";
public string Description => "Loads a physics testbed and teleports your player there";
public string Help => $"{Command} <mapid> <test>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 2)
{
shell.WriteLine("Require 2 args for testbed!");
return;
}
var mapManager = IoCManager.Resolve<IMapManager>();
if (!int.TryParse(args[0], out var mapInt))
{
shell.WriteLine($"Unable to parse map {args[0]}");
return;
}
var mapId = new MapId(mapInt);
if (!mapManager.MapExists(mapId))
{
shell.WriteLine("Unable to find map {mapId}");
return;
}
if (shell.Player == null)
{
shell.WriteLine("No player found");
return;
}
var player = (IPlayerSession) shell.Player;
switch (args[1])
{
case "boxstack":
SetupPlayer(mapId, shell, player, mapManager);
CreateBoxStack(mapId);
break;
case "circlestack":
SetupPlayer(mapId, shell, player, mapManager);
CreateCircleStack(mapId);
break;
default:
shell.WriteLine($"testbed {args[0]} not found!");
return;
}
shell.WriteLine($"Testbed on map {mapId}");
}
private void SetupPlayer(MapId mapId, IConsoleShell shell, IPlayerSession? player, IMapManager mapManager)
{
var pauseManager = IoCManager.Resolve<IPauseManager>();
pauseManager.SetMapPaused(mapId, false);
var map = EntitySystem.Get<SharedPhysicsSystem>().Maps[mapId].Gravity = new Vector2(0, -4.9f);
return;
}
private void CreateBoxStack(MapId mapId)
{
var entityManager = IoCManager.Resolve<IEntityManager>();
var ground = entityManager.SpawnEntity("BlankEntity", new MapCoordinates(0, 0, mapId)).AddComponent<PhysicsComponent>();
var horizontal = new EdgeShape(new Vector2(-20, 0), new Vector2(20, 0));
var horizontalFixture = new Fixture(ground, horizontal)
{
CollisionLayer = (int) CollisionGroup.Impassable,
CollisionMask = (int) CollisionGroup.Impassable,
Hard = true
};
ground.AddFixture(horizontalFixture);
var vertical = new EdgeShape(new Vector2(10, 0), new Vector2(10, 10));
var verticalFixture = new Fixture(ground, vertical)
{
CollisionLayer = (int) CollisionGroup.Impassable,
CollisionMask = (int) CollisionGroup.Impassable,
Hard = true
};
ground.AddFixture(verticalFixture);
var xs = new[]
{
0.0f, -10.0f, -5.0f, 5.0f, 10.0f
};
var columnCount = 1;
var rowCount = 15;
PolygonShape shape;
for (var j = 0; j < columnCount; j++)
{
for (var i = 0; i < rowCount; i++)
{
var x = 0.0f;
var box = entityManager.SpawnEntity("BlankEntity",
new MapCoordinates(new Vector2(xs[j] + x, 0.55f + 2.1f * i), mapId)).AddComponent<PhysicsComponent>();
box.BodyType = BodyType.Dynamic;
box.SleepingAllowed = false;
shape = new PolygonShape();
shape.SetAsBox(0.5f, 0.5f);
box.FixedRotation = false;
// TODO: Need to detect shape and work out if we need to use fixedrotation
var fixture = new Fixture(box, shape)
{
CollisionMask = (int) CollisionGroup.Impassable,
CollisionLayer = (int) CollisionGroup.Impassable,
Hard = true,
};
box.AddFixture(fixture);
}
}
}
private void CreateCircleStack(MapId mapId)
{
var entityManager = IoCManager.Resolve<IEntityManager>();
// TODO: Need a blank entity we can spawn for testbed.
var ground = entityManager.SpawnEntity("BlankEntity", new MapCoordinates(0, 0, mapId)).AddComponent<PhysicsComponent>();
var horizontal = new EdgeShape(new Vector2(-20, 0), new Vector2(20, 0));
var horizontalFixture = new Fixture(ground, horizontal)
{
CollisionLayer = (int) CollisionGroup.Impassable,
CollisionMask = (int) CollisionGroup.Impassable,
Hard = true
};
ground.AddFixture(horizontalFixture);
var vertical = new EdgeShape(new Vector2(10, 0), new Vector2(10, 10));
var verticalFixture = new Fixture(ground, vertical)
{
CollisionLayer = (int) CollisionGroup.Impassable,
CollisionMask = (int) CollisionGroup.Impassable,
Hard = true
};
ground.AddFixture(verticalFixture);
var xs = new[]
{
0.0f, -10.0f, -5.0f, 5.0f, 10.0f
};
var columnCount = 1;
var rowCount = 15;
PhysShapeCircle shape;
for (var j = 0; j < columnCount; j++)
{
for (var i = 0; i < rowCount; i++)
{
var x = 0.0f;
var box = entityManager.SpawnEntity("BlankEntity",
new MapCoordinates(new Vector2(xs[j] + x, 0.55f + 2.1f * i), mapId)).AddComponent<PhysicsComponent>();
box.BodyType = BodyType.Dynamic;
box.SleepingAllowed = false;
shape = new PhysShapeCircle {Radius = 0.5f};
box.FixedRotation = false;
// TODO: Need to detect shape and work out if we need to use fixedrotation
var fixture = new Fixture(box, shape)
{
CollisionMask = (int) CollisionGroup.Impassable,
CollisionLayer = (int) CollisionGroup.Impassable,
Hard = true,
};
box.AddFixture(fixture);
}
}
}
}
}