mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0936cf3c7f | ||
|
|
43b75a69c2 | ||
|
|
c17c8d7a11 | ||
|
|
223fd8126f | ||
|
|
1d5559be4a | ||
|
|
0b749ff8bb | ||
|
|
069fa89fcb | ||
|
|
80f9f24243 | ||
|
|
93018c9843 | ||
|
|
e2675271d0 | ||
|
|
d1f7edecef | ||
|
|
b5a3c0b988 |
4
Resources/Prototypes/dummy_entity.yml
Normal file
4
Resources/Prototypes/dummy_entity.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
- type: entity
|
||||
name: blank entity
|
||||
id: BlankEntity
|
||||
abstract: true
|
||||
10
Robust.Analyzers/Diagnostics.cs
Normal file
10
Robust.Analyzers/Diagnostics.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace Robust.Generators
|
||||
{
|
||||
public static class Diagnostics
|
||||
{
|
||||
public static SuppressionDescriptor MeansImplicitAssignment =>
|
||||
new SuppressionDescriptor("RADC1000", "CS0649", "Marked as implicitly assigned.");
|
||||
}
|
||||
}
|
||||
42
Robust.Analyzers/MeansImplicitAssigmentSuppressor.cs
Normal file
42
Robust.Analyzers/MeansImplicitAssigmentSuppressor.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
using Robust.Generators;
|
||||
|
||||
namespace Robust.Analyzers
|
||||
{
|
||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||
public class MeansImplicitAssigmentSuppressor : DiagnosticSuppressor
|
||||
{
|
||||
const string MeansImplicitAssignmentAttribute = "Robust.Shared.MeansImplicitAssignmentAttribute";
|
||||
|
||||
public override void ReportSuppressions(SuppressionAnalysisContext context)
|
||||
{
|
||||
var implAttr = context.Compilation.GetTypeByMetadataName(MeansImplicitAssignmentAttribute);
|
||||
foreach (var reportedDiagnostic in context.ReportedDiagnostics)
|
||||
{
|
||||
if(reportedDiagnostic.Id != Diagnostics.MeansImplicitAssignment.SuppressedDiagnosticId) continue;
|
||||
|
||||
var node = reportedDiagnostic.Location.SourceTree?.GetRoot(context.CancellationToken).FindNode(reportedDiagnostic.Location.SourceSpan);
|
||||
if (node == null) continue;
|
||||
|
||||
var symbol = context.GetSemanticModel(reportedDiagnostic.Location.SourceTree).GetDeclaredSymbol(node);
|
||||
|
||||
if (symbol == null || !symbol.GetAttributes().Any(a =>
|
||||
a.AttributeClass?.GetAttributes().Any(attr =>
|
||||
SymbolEqualityComparer.Default.Equals(attr.AttributeClass, implAttr)) == true))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
context.ReportSuppression(Suppression.Create(
|
||||
Diagnostics.MeansImplicitAssignment,
|
||||
reportedDiagnostic));
|
||||
}
|
||||
}
|
||||
|
||||
public override ImmutableArray<SuppressionDescriptor> SupportedSuppressions => ImmutableArray.Create(Diagnostics.MeansImplicitAssignment);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace Robust.Client.Animations
|
||||
/// <seealso cref="AnimationPlayerComponent"/>
|
||||
public sealed class Animation
|
||||
{
|
||||
public readonly List<AnimationTrack> AnimationTracks = new();
|
||||
public List<AnimationTrack> AnimationTracks { get; private set; } = new();
|
||||
|
||||
public TimeSpan Length { get; set; }
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Robust.Client.Animations
|
||||
/// <summary>
|
||||
/// A list of key frames for when to fire flicks.
|
||||
/// </summary>
|
||||
public readonly List<KeyFrame> KeyFrames = new();
|
||||
public List<KeyFrame> KeyFrames { get; private set; } = new();
|
||||
|
||||
public override (int KeyFrameIndex, float FramePlayingTime) InitPlayback()
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Robust.Client.Animations
|
||||
/// </summary>
|
||||
public abstract class AnimationTrackProperty : AnimationTrack
|
||||
{
|
||||
public readonly List<KeyFrame> KeyFrames = new();
|
||||
public List<KeyFrame> KeyFrames { get; protected set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// How to interpolate values when between two keyframes.
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Robust.Client.Animations
|
||||
/// <summary>
|
||||
/// A list of key frames for when to fire flicks.
|
||||
/// </summary>
|
||||
public readonly List<KeyFrame> KeyFrames = new();
|
||||
public List<KeyFrame> KeyFrames { get; private set; } = new();
|
||||
|
||||
// TODO: Should this layer key be per keyframe maybe?
|
||||
/// <summary>
|
||||
|
||||
@@ -13,6 +13,7 @@ using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
using Robust.Shared.Utility;
|
||||
using Logger = Robust.Shared.Log.Logger;
|
||||
|
||||
@@ -73,6 +74,8 @@ namespace Robust.Client.Audio.Midi
|
||||
[Dependency] private readonly IResourceManagerInternal _resourceManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
private SharedBroadPhaseSystem _broadPhaseSystem = default!;
|
||||
|
||||
public bool IsAvailable
|
||||
{
|
||||
get
|
||||
@@ -156,6 +159,7 @@ namespace Robust.Client.Audio.Midi
|
||||
_midiThread = new Thread(ThreadUpdate);
|
||||
_midiThread.Start();
|
||||
|
||||
_broadPhaseSystem = EntitySystem.Get<SharedBroadPhaseSystem>();
|
||||
FluidsynthInitialized = true;
|
||||
}
|
||||
|
||||
@@ -300,7 +304,7 @@ namespace Robust.Client.Audio.Midi
|
||||
var occlusion = 0f;
|
||||
if (sourceRelative.Length > 0)
|
||||
{
|
||||
occlusion = IoCManager.Resolve<IPhysicsManager>().IntersectRayPenetration(
|
||||
occlusion = _broadPhaseSystem.IntersectRayPenetration(
|
||||
pos.MapId,
|
||||
new CollisionRay(
|
||||
pos.Position,
|
||||
|
||||
@@ -27,6 +27,8 @@ using Robust.Shared.Network;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
|
||||
namespace Robust.Client
|
||||
{
|
||||
@@ -101,7 +103,6 @@ namespace Robust.Client
|
||||
IoCManager.Register<IViewVariablesManagerInternal, ViewVariablesManager>();
|
||||
IoCManager.Register<IClientConGroupController, ClientConGroupController>();
|
||||
IoCManager.Register<IScriptClient, ScriptClient>();
|
||||
//IoCManager.Register<IXamlCompiler, XamlCompiler>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ using Robust.Client.Input;
|
||||
using Robust.Client.Debugging;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.ResourceManagement.ResourceTypes;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
|
||||
41
Robust.Client/Console/Commands/PhysicsOverlayCommands.cs
Normal file
41
Robust.Client/Console/Commands/PhysicsOverlayCommands.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Robust.Client.Debugging;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Robust.Client.Console.Commands
|
||||
{
|
||||
public sealed class PhysicsOverlayCommands : IConsoleCommand
|
||||
{
|
||||
public string Command => "physics";
|
||||
public string Description => $"{Command} <contactnormals / contactpoints / shapes>";
|
||||
public string Help => $"{Command} <overlay>";
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 1)
|
||||
{
|
||||
shell.WriteLine($"Invalid number of args supplied");
|
||||
return;
|
||||
}
|
||||
|
||||
var system = EntitySystem.Get<DebugPhysicsSystem>();
|
||||
|
||||
switch (args[0])
|
||||
{
|
||||
case "contactnormals":
|
||||
system.Flags ^= PhysicsDebugFlags.ContactNormals;
|
||||
break;
|
||||
case "contactpoints":
|
||||
system.Flags ^= PhysicsDebugFlags.ContactPoints;
|
||||
break;
|
||||
case "shapes":
|
||||
system.Flags ^= PhysicsDebugFlags.Shapes;
|
||||
break;
|
||||
default:
|
||||
shell.WriteLine($"{args[0]} is not a recognised overlay");
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Robust.Client/Console/Commands/VelocitiesCommand.cs
Normal file
17
Robust.Client/Console/Commands/VelocitiesCommand.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Robust.Client.Console.Commands
|
||||
{
|
||||
public class VelocitiesCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "showvelocities";
|
||||
public string Description => "Displays your angular and linear velocities";
|
||||
public string Help => $"{Command}";
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
EntitySystem.Get<VelocityDebugSystem>().Enabled ^= true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,13 @@ using System.Collections.Generic;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Robust.Client.Debugging
|
||||
@@ -136,7 +139,7 @@ namespace Robust.Client.Debugging
|
||||
row++;
|
||||
DrawString(screenHandle, _font, drawPos + new Vector2(0, row * lineHeight), $"Mask: {Convert.ToString(body.CollisionMask, 2)}");
|
||||
row++;
|
||||
DrawString(screenHandle, _font, drawPos + new Vector2(0, row * lineHeight), $"Enabled: {body.CanCollide}, Hard: {body.Hard}, Anchored: {((IPhysicsComponent)body).Anchored}");
|
||||
DrawString(screenHandle, _font, drawPos + new Vector2(0, row * lineHeight), $"Enabled: {body.CanCollide}, Hard: {body.Hard}, Anchored: {(body).BodyType == BodyType.Static}");
|
||||
row++;
|
||||
}
|
||||
|
||||
@@ -158,19 +161,22 @@ namespace Robust.Client.Debugging
|
||||
|
||||
var mapId = _eyeManager.CurrentMap;
|
||||
|
||||
foreach (var physBody in _physicsManager.GetCollidingEntities(mapId, viewport))
|
||||
foreach (var physBody in EntitySystem.Get<SharedBroadPhaseSystem>().GetCollidingEntities(mapId, viewport))
|
||||
{
|
||||
// all entities have a TransformComponent
|
||||
var transform = physBody.Entity.Transform;
|
||||
|
||||
var worldBox = physBody.WorldAABB;
|
||||
var worldBox = physBody.GetWorldAABB();
|
||||
if (worldBox.IsEmpty()) continue;
|
||||
|
||||
var colorEdge = Color.Red.WithAlpha(0.33f);
|
||||
var sleepThreshold = IoCManager.Resolve<IConfigurationManager>().GetCVar(CVars.TimeToSleep);
|
||||
|
||||
foreach (var shape in physBody.PhysicsShapes)
|
||||
foreach (var fixture in physBody.Fixtures)
|
||||
{
|
||||
shape.DebugDraw(drawing, transform.WorldMatrix, in viewport, physBody.SleepAccumulator / (float) physBody.SleepThreshold);
|
||||
var shape = fixture.Shape;
|
||||
var sleepPercent = physBody.Awake ? physBody.SleepTime / sleepThreshold : 1.0f;
|
||||
shape.DebugDraw(drawing, transform.WorldMatrix, in viewport, sleepPercent);
|
||||
}
|
||||
|
||||
if (worldBox.Contains(mouseWorldPos))
|
||||
@@ -233,6 +239,16 @@ namespace Robust.Client.Debugging
|
||||
_handle.DrawCircle(origin, radius, color);
|
||||
}
|
||||
|
||||
public override void DrawPolygonShape(Vector2[] vertices, in Color color)
|
||||
{
|
||||
_handle.DrawPrimitives(DrawPrimitiveTopology.TriangleFan, vertices, color);
|
||||
}
|
||||
|
||||
public override void DrawLine(Vector2 start, Vector2 end, in Color color)
|
||||
{
|
||||
_handle.DrawLine(start, end, color);
|
||||
}
|
||||
|
||||
public override void SetTransform(in Matrix3 transform)
|
||||
{
|
||||
_handle.SetTransform(transform);
|
||||
|
||||
163
Robust.Client/Debugging/DebugPhysicsSystem.cs
Normal file
163
Robust.Client/Debugging/DebugPhysicsSystem.cs
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Farseer Physics Engine:
|
||||
* Copyright (c) 2012 Ian Qvist
|
||||
*
|
||||
* Original source Box2D:
|
||||
* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/* Heavily inspired by Farseer */
|
||||
|
||||
using System;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics.Collision;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Physics.Dynamics.Contacts;
|
||||
|
||||
namespace Robust.Client.Debugging
|
||||
{
|
||||
internal sealed class DebugPhysicsSystem : SharedDebugPhysicsSystem
|
||||
{
|
||||
/*
|
||||
* Used for debugging shapes, controllers, joints, contacts
|
||||
*/
|
||||
|
||||
private const int MaxContactPoints = 2048;
|
||||
internal int PointCount;
|
||||
|
||||
internal ContactPoint[] _points = new ContactPoint[MaxContactPoints];
|
||||
|
||||
public PhysicsDebugFlags Flags
|
||||
{
|
||||
get => _flags;
|
||||
set
|
||||
{
|
||||
if (value == _flags) return;
|
||||
|
||||
if (_flags == PhysicsDebugFlags.None)
|
||||
IoCManager.Resolve<IOverlayManager>().AddOverlay(new PhysicsDebugOverlay(this));
|
||||
|
||||
if (value == PhysicsDebugFlags.None)
|
||||
IoCManager.Resolve<IOverlayManager>().RemoveOverlay(nameof(PhysicsDebugOverlay));
|
||||
|
||||
_flags = value;
|
||||
}
|
||||
}
|
||||
|
||||
private PhysicsDebugFlags _flags;
|
||||
|
||||
public override void HandlePreSolve(Contact contact, in Manifold oldManifold)
|
||||
{
|
||||
if ((Flags & PhysicsDebugFlags.ContactPoints) != 0)
|
||||
{
|
||||
Manifold manifold = contact.Manifold;
|
||||
|
||||
if (manifold.PointCount == 0)
|
||||
return;
|
||||
|
||||
Fixture fixtureA = contact.FixtureA!;
|
||||
|
||||
PointState[] state1, state2;
|
||||
CollisionManager.GetPointStates(out state1, out state2, oldManifold, manifold);
|
||||
|
||||
Span<Vector2> points = stackalloc Vector2[2];
|
||||
Vector2 normal;
|
||||
contact.GetWorldManifold(out normal, points);
|
||||
|
||||
for (int i = 0; i < manifold.PointCount && PointCount < MaxContactPoints; ++i)
|
||||
{
|
||||
if (fixtureA == null)
|
||||
_points[i] = new ContactPoint();
|
||||
|
||||
ContactPoint cp = _points[PointCount];
|
||||
cp.Position = points[i];
|
||||
cp.Normal = normal;
|
||||
cp.State = state2[i];
|
||||
_points[PointCount] = cp;
|
||||
++PointCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal struct ContactPoint
|
||||
{
|
||||
public Vector2 Normal;
|
||||
public Vector2 Position;
|
||||
public PointState State;
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
internal enum PhysicsDebugFlags : byte
|
||||
{
|
||||
None = 0,
|
||||
ContactPoints = 1 << 0,
|
||||
ContactNormals = 1 << 1,
|
||||
Shapes = 1 << 2,
|
||||
}
|
||||
|
||||
internal sealed class PhysicsDebugOverlay : Overlay
|
||||
{
|
||||
private DebugPhysicsSystem _physics = default!;
|
||||
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpace;
|
||||
|
||||
public PhysicsDebugOverlay(DebugPhysicsSystem system) : base(nameof(PhysicsDebugOverlay))
|
||||
{
|
||||
_physics = system;
|
||||
}
|
||||
|
||||
protected override void Draw(DrawingHandleBase handle, OverlaySpace currentSpace)
|
||||
{
|
||||
if (_physics.Flags == PhysicsDebugFlags.None) return;
|
||||
|
||||
var worldHandle = (DrawingHandleWorld) handle;
|
||||
|
||||
if ((_physics.Flags & PhysicsDebugFlags.Shapes) != 0)
|
||||
{
|
||||
// Port DebugDrawing over.
|
||||
}
|
||||
|
||||
if ((_physics.Flags & PhysicsDebugFlags.ContactPoints) != 0)
|
||||
{
|
||||
const float axisScale = 0.3f;
|
||||
|
||||
for (int i = 0; i < _physics.PointCount; ++i)
|
||||
{
|
||||
DebugPhysicsSystem.ContactPoint point = _physics._points[i];
|
||||
|
||||
if (point.State == PointState.Add)
|
||||
worldHandle.DrawCircle(point.Position, 0.5f, new Color(255, 77, 243, 77));
|
||||
else if (point.State == PointState.Persist)
|
||||
worldHandle.DrawCircle(point.Position, 0.5f, new Color(255, 77, 77, 77));
|
||||
|
||||
if ((_physics.Flags & PhysicsDebugFlags.ContactNormals) != 0)
|
||||
{
|
||||
Vector2 p1 = point.Position;
|
||||
Vector2 p2 = p1 + point.Normal * axisScale;
|
||||
worldHandle.DrawLine(p1, p2, new Color(255, 102, 230, 102));
|
||||
}
|
||||
}
|
||||
|
||||
_physics.PointCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
@@ -27,6 +27,7 @@ using Robust.Shared.Map;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -44,7 +45,7 @@ namespace Robust.Client
|
||||
[Dependency] private readonly IUserInterfaceManagerInternal _userInterfaceManager = default!;
|
||||
[Dependency] private readonly IBaseClient _client = default!;
|
||||
[Dependency] private readonly IInputManager _inputManager = default!;
|
||||
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
|
||||
[Dependency] private readonly IClientConsoleHost _console = default!;
|
||||
[Dependency] private readonly ITimerManager _timerManager = default!;
|
||||
[Dependency] private readonly IClientEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IPlacementManager _placementManager = default!;
|
||||
@@ -154,6 +155,8 @@ namespace Robust.Client
|
||||
_configurationManager.LoadCVarsFromAssembly(loadedModule);
|
||||
}
|
||||
|
||||
IoCManager.Resolve<ISerializationManager>().Initialize();
|
||||
|
||||
// Call Init in game assemblies.
|
||||
_modLoader.BroadcastRunLevel(ModRunLevel.PreInit);
|
||||
_modLoader.BroadcastRunLevel(ModRunLevel.Init);
|
||||
@@ -163,7 +166,7 @@ namespace Robust.Client
|
||||
IoCManager.Resolve<INetConfigurationManager>().SetupNetworking();
|
||||
_serializer.Initialize();
|
||||
_inputManager.Initialize();
|
||||
_consoleHost.Initialize();
|
||||
_console.Initialize();
|
||||
_prototypeManager.Initialize();
|
||||
_prototypeManager.LoadDirectory(new ResourcePath(@"/Prototypes/"));
|
||||
_prototypeManager.Resync();
|
||||
@@ -320,7 +323,7 @@ namespace Robust.Client
|
||||
logManager.GetSawmill("discord").Level = LogLevel.Warning;
|
||||
logManager.GetSawmill("net.predict").Level = LogLevel.Info;
|
||||
logManager.GetSawmill("szr").Level = LogLevel.Info;
|
||||
// logManager.GetSawmill("loc").Level = LogLevel.Error;
|
||||
logManager.GetSawmill("loc").Level = LogLevel.Error;
|
||||
|
||||
#if DEBUG_ONLY_FCE_INFO
|
||||
#if DEBUG_ONLY_FCE_LOG
|
||||
|
||||
@@ -17,7 +17,6 @@ namespace Robust.Client
|
||||
RegisterReflection();
|
||||
}
|
||||
|
||||
|
||||
internal static void RegisterReflection()
|
||||
{
|
||||
// Gets a handle to the shared and the current (client) dll.
|
||||
|
||||
@@ -24,7 +24,12 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
Register<PhysicsComponent>();
|
||||
RegisterReference<PhysicsComponent, IPhysBody>();
|
||||
RegisterReference<PhysicsComponent, IPhysicsComponent>();
|
||||
|
||||
Register<CollisionWakeComponent>();
|
||||
|
||||
Register<ContainerManagerComponent>();
|
||||
RegisterReference<ContainerManagerComponent, IContainerManager>();
|
||||
|
||||
RegisterIgnore("KeyBindingInput");
|
||||
|
||||
Register<InputComponent>();
|
||||
@@ -54,7 +59,6 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
#if DEBUG
|
||||
Register<DebugExceptionOnAddComponent>();
|
||||
Register<DebugExceptionExposeDataComponent>();
|
||||
Register<DebugExceptionInitializeComponent>();
|
||||
Register<DebugExceptionStartupComponent>();
|
||||
#endif
|
||||
|
||||
@@ -4,8 +4,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
@@ -15,13 +14,11 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
[ViewVariables]
|
||||
private Dictionary<object, object> data = new();
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("visuals")]
|
||||
internal List<AppearanceVisualizer> Visualizers = new();
|
||||
|
||||
[Dependency] private readonly IReflectionManager _reflectionManager = default!;
|
||||
|
||||
private static bool _didRegisterSerializer;
|
||||
|
||||
[ViewVariables]
|
||||
private bool _appearanceDirty;
|
||||
|
||||
@@ -107,18 +104,6 @@ namespace Robust.Client.GameObjects
|
||||
_appearanceDirty = false;
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
if (!_didRegisterSerializer)
|
||||
{
|
||||
YamlObjectSerializer.RegisterTypeSerializer(typeof(AppearanceVisualizer),
|
||||
new VisualizerTypeSerializer(_reflectionManager));
|
||||
_didRegisterSerializer = true;
|
||||
}
|
||||
|
||||
serializer.DataFieldCached(ref Visualizers, "visuals", new List<AppearanceVisualizer>());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -131,78 +116,6 @@ namespace Robust.Client.GameObjects
|
||||
MarkDirty();
|
||||
}
|
||||
|
||||
class VisualizerTypeSerializer : YamlObjectSerializer.TypeSerializer
|
||||
{
|
||||
private readonly IReflectionManager _reflectionManager;
|
||||
|
||||
public VisualizerTypeSerializer(IReflectionManager reflectionManager)
|
||||
{
|
||||
_reflectionManager = reflectionManager;
|
||||
}
|
||||
|
||||
public override object NodeToType(Type type, YamlNode node, YamlObjectSerializer serializer)
|
||||
{
|
||||
var mapping = (YamlMappingNode) node;
|
||||
var nodeType = mapping.GetNode("type");
|
||||
switch (nodeType.AsString())
|
||||
{
|
||||
case SpriteLayerToggle.NAME:
|
||||
var keyString = mapping.GetNode("key").AsString();
|
||||
object key;
|
||||
if (_reflectionManager.TryParseEnumReference(keyString, out var @enum))
|
||||
{
|
||||
key = @enum;
|
||||
}
|
||||
else
|
||||
{
|
||||
key = keyString;
|
||||
}
|
||||
|
||||
var layer = mapping.GetNode("layer").AsInt();
|
||||
return new SpriteLayerToggle(key, layer);
|
||||
|
||||
default:
|
||||
var visType = _reflectionManager.LooseGetType(nodeType.AsString());
|
||||
if (!typeof(AppearanceVisualizer).IsAssignableFrom(visType))
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
var vis = (AppearanceVisualizer) Activator.CreateInstance(visType)!;
|
||||
vis.LoadData(mapping);
|
||||
return vis;
|
||||
}
|
||||
}
|
||||
|
||||
public override YamlNode TypeToNode(object obj, YamlObjectSerializer serializer)
|
||||
{
|
||||
switch (obj)
|
||||
{
|
||||
case SpriteLayerToggle spriteLayerToggle:
|
||||
YamlScalarNode key;
|
||||
if (spriteLayerToggle.Key is Enum)
|
||||
{
|
||||
var name = spriteLayerToggle.Key.GetType().FullName;
|
||||
key = new YamlScalarNode($"{name}.{spriteLayerToggle.Key}");
|
||||
}
|
||||
else
|
||||
{
|
||||
key = new YamlScalarNode(spriteLayerToggle.Key.ToString());
|
||||
}
|
||||
|
||||
return new YamlMappingNode
|
||||
{
|
||||
{new YamlScalarNode("type"), new YamlScalarNode(SpriteLayerToggle.NAME)},
|
||||
{new YamlScalarNode("key"), key},
|
||||
{new YamlScalarNode("layer"), new YamlScalarNode(spriteLayerToggle.SpriteLayer.ToString())},
|
||||
};
|
||||
default:
|
||||
// TODO: A proper way to do serialization here.
|
||||
// I can't use the ExposeData system here since that's specific to entity serializers.
|
||||
return new YamlMappingNode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class SpriteLayerToggle : AppearanceVisualizer
|
||||
{
|
||||
@@ -223,15 +136,9 @@ namespace Robust.Client.GameObjects
|
||||
/// Handles the visualization of data inside of an appearance component.
|
||||
/// Implementations of this class are NOT bound to a specific entity, they are flyweighted across multiple.
|
||||
/// </summary>
|
||||
[ImplicitDataDefinitionForInheritors]
|
||||
public abstract class AppearanceVisualizer
|
||||
{
|
||||
/// <summary>
|
||||
/// Load data from the prototype declaring this visualizer, to configure settings and such.
|
||||
/// </summary>
|
||||
public virtual void LoadData(YamlMappingNode node)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an entity to be managed by this appearance controller.
|
||||
/// DO NOT assume this is your only entity. Visualizers are shared.
|
||||
|
||||
@@ -3,7 +3,9 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Client.GameObjects
|
||||
@@ -20,7 +22,9 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
// Horrible hack to get around ordering issues.
|
||||
private bool _setCurrentOnInitialize;
|
||||
private bool _setDrawFovOnInitialize;
|
||||
[DataField("drawFov")]
|
||||
private bool _setDrawFovOnInitialize = true;
|
||||
[DataField("zoom")]
|
||||
private Vector2 _setZoomOnInitialize = Vector2.One/2f;
|
||||
private Vector2 _offset = Vector2.Zero;
|
||||
|
||||
@@ -157,15 +161,6 @@ namespace Robust.Client.GameObjects
|
||||
Current = false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataFieldCached(ref _setZoomOnInitialize, "zoom", Vector2.One/2f);
|
||||
serializer.DataFieldCached(ref _setDrawFovOnInitialize, "drawFov", true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the Eye of this entity with the transform position. This has to be called every frame to
|
||||
/// keep the view following the entity.
|
||||
|
||||
@@ -1,105 +1,51 @@
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.Utility;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Client.GameObjects
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class IconComponent : Component
|
||||
public class IconComponent : Component, ISerializationHooks
|
||||
{
|
||||
public override string Name => "Icon";
|
||||
public IDirectionalTextureProvider? Icon { get; private set; }
|
||||
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
[DataField("sprite")]
|
||||
private ResourcePath? rsi;
|
||||
[DataField("state")]
|
||||
private string? stateID;
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
if (rsi != null && stateID != null)
|
||||
{
|
||||
Icon = new SpriteSpecifier.Rsi(rsi, stateID).Frame0();
|
||||
}
|
||||
}
|
||||
|
||||
public const string LogCategory = "go.comp.icon";
|
||||
const string SerializationCache = "icon";
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
private static IRsiStateLike TextureForConfig(IconComponent compData, IResourceCache resourceCache)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
// TODO: Does this need writing?
|
||||
if (serializer.Reading)
|
||||
{
|
||||
Icon = TextureForConfig(serializer, _resourceCache);
|
||||
}
|
||||
}
|
||||
|
||||
private static IRsiStateLike TextureForConfig(ObjectSerializer serializer, IResourceCache resourceCache)
|
||||
{
|
||||
DebugTools.Assert(serializer.Reading);
|
||||
|
||||
if (serializer.TryGetCacheData<IRsiStateLike>(SerializationCache, out var dirTex))
|
||||
{
|
||||
return dirTex;
|
||||
}
|
||||
|
||||
var tex = serializer.ReadDataField<string?>("texture", null);
|
||||
if (!string.IsNullOrWhiteSpace(tex))
|
||||
{
|
||||
dirTex = resourceCache.GetResource<TextureResource>(SpriteComponent.TextureRoot / tex).Texture;
|
||||
serializer.SetCacheData(SerializationCache, dirTex);
|
||||
return dirTex;
|
||||
}
|
||||
|
||||
RSI rsi;
|
||||
|
||||
var rsiPath = serializer.ReadDataField<string?>("sprite", null);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(rsiPath))
|
||||
{
|
||||
dirTex = resourceCache.GetFallback<TextureResource>().Texture;
|
||||
serializer.SetCacheData(SerializationCache, dirTex);
|
||||
return dirTex;
|
||||
}
|
||||
|
||||
var path = SpriteComponent.TextureRoot / rsiPath;
|
||||
|
||||
try
|
||||
{
|
||||
rsi = resourceCache.GetResource<RSIResource>(path).RSI;
|
||||
}
|
||||
catch
|
||||
{
|
||||
dirTex = resourceCache.GetFallback<TextureResource>().Texture;
|
||||
serializer.SetCacheData(SerializationCache, dirTex);
|
||||
return dirTex;
|
||||
}
|
||||
|
||||
var stateId = serializer.ReadDataField<string?>("state", null);
|
||||
if (string.IsNullOrWhiteSpace(stateId))
|
||||
{
|
||||
Logger.ErrorS(LogCategory, "No state specified.");
|
||||
dirTex = resourceCache.GetFallback<TextureResource>().Texture;
|
||||
serializer.SetCacheData(SerializationCache, dirTex);
|
||||
return dirTex;
|
||||
}
|
||||
|
||||
if (rsi.TryGetState(stateId, out var state))
|
||||
{
|
||||
serializer.SetCacheData(SerializationCache, state);
|
||||
return state;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.ErrorS(LogCategory, "State '{0}' does not exist on RSI.", stateId);
|
||||
return resourceCache.GetFallback<TextureResource>().Texture;
|
||||
}
|
||||
return compData.Icon?.Default ?? resourceCache.GetFallback<TextureResource>().Texture;
|
||||
}
|
||||
|
||||
public static IRsiStateLike? GetPrototypeIcon(EntityPrototype prototype, IResourceCache resourceCache)
|
||||
{
|
||||
if (!prototype.Components.TryGetValue("Icon", out var mapping))
|
||||
if (!prototype.Components.TryGetValue("Icon", out var compData))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return TextureForConfig(YamlObjectSerializer.NewReader(mapping), resourceCache);
|
||||
|
||||
return TextureForConfig((IconComponent)compData, resourceCache);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Client.GameObjects
|
||||
@@ -17,14 +19,7 @@ namespace Robust.Client.GameObjects
|
||||
/// The context that will be made active for a client that attaches to this entity.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string ContextName { get; set; } = default!;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataReadWriteFunction("context", InputContextContainer.DefaultContextName, value => ContextName = value, () => ContextName);
|
||||
}
|
||||
[DataField("context")]
|
||||
public string ContextName { get; set; } = InputContextContainer.DefaultContextName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.Animations;
|
||||
@@ -7,13 +7,14 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Client.GameObjects
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IPointLightComponent))]
|
||||
public class PointLightComponent : Component, IPointLightComponent
|
||||
public class PointLightComponent : Component, IPointLightComponent, ISerializationHooks
|
||||
{
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
|
||||
@@ -134,16 +135,25 @@ namespace Robust.Client.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
private float _radius = 5;
|
||||
[DataField("radius")]
|
||||
private float _radius = 5f;
|
||||
[DataField("nestedvisible")]
|
||||
private bool _visibleNested = true;
|
||||
private bool _lightOnParent;
|
||||
[DataField("color")]
|
||||
private Color _color = Color.White;
|
||||
private Vector2 _offset;
|
||||
[DataField("offset")]
|
||||
private Vector2 _offset = Vector2.Zero;
|
||||
[DataField("enabled")]
|
||||
private bool _enabled = true;
|
||||
[DataField("autoRot")]
|
||||
private bool _maskAutoRotate;
|
||||
private Angle _rotation;
|
||||
private float _energy;
|
||||
private float _softness;
|
||||
[DataField("energy")]
|
||||
private float _energy = 1f;
|
||||
[DataField("softness")]
|
||||
private float _softness = 1f;
|
||||
[DataField("mask")]
|
||||
private string? _maskPath;
|
||||
|
||||
/// <summary>
|
||||
@@ -169,6 +179,14 @@ namespace Robust.Client.GameObjects
|
||||
Mask = null;
|
||||
}
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
if (_maskPath != null)
|
||||
{
|
||||
Mask = IoCManager.Resolve<IResourceCache>().GetResource<TextureResource>(_maskPath);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -180,7 +198,7 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
|
||||
if ((message is ParentChangedMessage msg))
|
||||
if (message is ParentChangedMessage msg)
|
||||
{
|
||||
HandleTransformParentChanged(msg);
|
||||
}
|
||||
@@ -204,19 +222,6 @@ namespace Robust.Client.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataFieldCached(ref _offset, "offset", Vector2.Zero);
|
||||
serializer.DataFieldCached(ref _radius, "radius", 5f);
|
||||
serializer.DataFieldCached(ref _color, "color", Color.White);
|
||||
serializer.DataFieldCached(ref _enabled, "enabled", true);
|
||||
serializer.DataFieldCached(ref _energy, "energy", 1f);
|
||||
serializer.DataFieldCached(ref _softness, "softness", 1f);
|
||||
serializer.DataFieldCached(ref _maskAutoRotate, "autoRot", false);
|
||||
serializer.DataFieldCached(ref _visibleNested, "nestedvisible", true);
|
||||
serializer.DataFieldCached(ref _maskPath, "mask", null);
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
base.OnRemove();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
@@ -17,6 +17,8 @@ using Robust.Shared.Network;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -25,8 +27,12 @@ using DrawDepthTag = Robust.Shared.GameObjects.DrawDepth;
|
||||
namespace Robust.Client.GameObjects
|
||||
{
|
||||
public sealed class SpriteComponent : SharedSpriteComponent, ISpriteComponent,
|
||||
IComponentDebug
|
||||
IComponentDebug, ISerializationHooks
|
||||
{
|
||||
[Dependency] private readonly IResourceCache resourceCache = default!;
|
||||
[Dependency] private readonly IPrototypeManager prototypes = default!;
|
||||
|
||||
[DataField("visible")]
|
||||
private bool _visible = true;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
@@ -36,6 +42,7 @@ namespace Robust.Client.GameObjects
|
||||
set => _visible = value;
|
||||
}
|
||||
|
||||
[DataFieldWithConstant("drawdepth", typeof(DrawDepthTag))]
|
||||
private int drawDepth = DrawDepthTag.Default;
|
||||
|
||||
/// <summary>
|
||||
@@ -48,6 +55,7 @@ namespace Robust.Client.GameObjects
|
||||
set => drawDepth = value;
|
||||
}
|
||||
|
||||
[DataField("scale")]
|
||||
private Vector2 scale = Vector2.One;
|
||||
|
||||
/// <summary>
|
||||
@@ -61,7 +69,8 @@ namespace Robust.Client.GameObjects
|
||||
set => scale = value;
|
||||
}
|
||||
|
||||
private Angle rotation;
|
||||
[DataField("rotation")]
|
||||
private Angle rotation = Angle.Zero;
|
||||
|
||||
[Animatable]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
@@ -71,6 +80,7 @@ namespace Robust.Client.GameObjects
|
||||
set => rotation = value;
|
||||
}
|
||||
|
||||
[DataField("offset")]
|
||||
private Vector2 offset = Vector2.Zero;
|
||||
|
||||
/// <summary>
|
||||
@@ -84,6 +94,7 @@ namespace Robust.Client.GameObjects
|
||||
set => offset = value;
|
||||
}
|
||||
|
||||
[DataField("color")]
|
||||
private Color color = Color.White;
|
||||
|
||||
[Animatable]
|
||||
@@ -108,18 +119,152 @@ namespace Robust.Client.GameObjects
|
||||
set => _directional = value;
|
||||
}
|
||||
|
||||
[DataField("directional")]
|
||||
private bool _directional = true;
|
||||
|
||||
[DataField("layerDatums")]
|
||||
private List<PrototypeLayerData> LayerDatums
|
||||
{
|
||||
get
|
||||
{
|
||||
var layerDatums = new List<PrototypeLayerData>();
|
||||
foreach (var layer in Layers)
|
||||
{
|
||||
layerDatums.Add(layer.ToPrototypeData());
|
||||
}
|
||||
|
||||
return layerDatums;
|
||||
}
|
||||
set
|
||||
{
|
||||
if(value == null) return;
|
||||
|
||||
Layers.Clear();
|
||||
foreach (var layerDatum in value)
|
||||
{
|
||||
var anyTextureAttempted = false;
|
||||
var layer = new Layer(this);
|
||||
if (!string.IsNullOrWhiteSpace(layerDatum.RsiPath))
|
||||
{
|
||||
var path = TextureRoot / layerDatum.RsiPath;
|
||||
try
|
||||
{
|
||||
layer.RSI = IoCManager.Resolve<IResourceCache>().GetResource<RSIResource>(path).RSI;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Logger.ErrorS(LogCategory, "Unable to load layer RSI '{0}'.", path);
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(layerDatum.State))
|
||||
{
|
||||
anyTextureAttempted = true;
|
||||
var theRsi = layer.RSI ?? BaseRSI;
|
||||
if (theRsi == null)
|
||||
{
|
||||
Logger.ErrorS(LogCategory,
|
||||
"Layer has no RSI to load states from. Cannot use 'state' property. ({0})",
|
||||
layerDatum.State);
|
||||
}
|
||||
else
|
||||
{
|
||||
var stateid = new RSI.StateId(layerDatum.State);
|
||||
layer.State = stateid;
|
||||
if (theRsi.TryGetState(stateid, out var state))
|
||||
{
|
||||
// Always use south because this layer will be cached in the serializer.
|
||||
layer.AnimationTimeLeft = state.GetDelay(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.ErrorS(LogCategory,
|
||||
$"State '{stateid}' not found in RSI: '{theRsi.Path}'.",
|
||||
stateid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(layerDatum.TexturePath))
|
||||
{
|
||||
anyTextureAttempted = true;
|
||||
if (layer.State.IsValid)
|
||||
{
|
||||
Logger.ErrorS(LogCategory,
|
||||
"Cannot specify 'texture' on a layer if it has an RSI state specified."
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
layer.Texture =
|
||||
IoCManager.Resolve<IResourceCache>().GetResource<TextureResource>(TextureRoot / layerDatum.TexturePath);
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(layerDatum.Shader))
|
||||
{
|
||||
if (IoCManager.Resolve<IPrototypeManager>().TryIndex<ShaderPrototype>(layerDatum.Shader, out var prototype))
|
||||
{
|
||||
layer.Shader = prototype.Instance();
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.ErrorS(LogCategory,
|
||||
"Shader prototype '{0}' does not exist.",
|
||||
layerDatum.Shader);
|
||||
}
|
||||
}
|
||||
|
||||
layer.Color = layerDatum.Color;
|
||||
layer.Rotation = layerDatum.Rotation;
|
||||
// If neither state: nor texture: were provided we assume that they want a blank invisible layer.
|
||||
layer.Visible = anyTextureAttempted && layerDatum.Visible;
|
||||
layer.Scale = layerDatum.Scale;
|
||||
|
||||
Layers.Add(layer);
|
||||
|
||||
if (layerDatum.MapKeys != null)
|
||||
{
|
||||
var index = Layers.Count - 1;
|
||||
foreach (var keyString in layerDatum.MapKeys)
|
||||
{
|
||||
object key;
|
||||
if (IoCManager.Resolve<IReflectionManager>().TryParseEnumReference(keyString, out var @enum))
|
||||
{
|
||||
key = @enum;
|
||||
}
|
||||
else
|
||||
{
|
||||
key = keyString;
|
||||
}
|
||||
|
||||
if (LayerMap.ContainsKey(key))
|
||||
{
|
||||
Logger.ErrorS(LogCategory, "Duplicate layer map key definition: {0}", key);
|
||||
continue;
|
||||
}
|
||||
|
||||
LayerMap.Add(key, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_layerMapShared = true;
|
||||
UpdateIsInert();
|
||||
}
|
||||
}
|
||||
|
||||
private RSI? _baseRsi;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("rsi", priority: 2)]
|
||||
public RSI? BaseRSI
|
||||
{
|
||||
get => _baseRsi;
|
||||
set
|
||||
{
|
||||
_baseRsi = value;
|
||||
if (Layers == null || value == null)
|
||||
if (value == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -147,6 +292,12 @@ namespace Robust.Client.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
[DataField("sprite", readOnly: true)] private string? rsi;
|
||||
[DataField("layers", readOnly: true)] private List<PrototypeLayerData> layerDatums = new ();
|
||||
|
||||
[DataField("state", readOnly: true)] private string? state;
|
||||
[DataField("texture", readOnly: true)] private string? texture;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool ContainerOccluded { get; set; }
|
||||
|
||||
@@ -158,11 +309,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
[ViewVariables] private Dictionary<object, int> LayerMap = new();
|
||||
[ViewVariables] private bool _layerMapShared;
|
||||
[ViewVariables] private List<Layer> Layers = default!;
|
||||
|
||||
[Dependency] private readonly IResourceCache resourceCache = default!;
|
||||
[Dependency] private readonly IPrototypeManager prototypes = default!;
|
||||
[Dependency] private readonly IReflectionManager reflectionManager = default!;
|
||||
[ViewVariables] private List<Layer> Layers = new();
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] public uint RenderOrder { get; set; }
|
||||
|
||||
@@ -170,10 +317,9 @@ namespace Robust.Client.GameObjects
|
||||
private static ShaderInstance? _defaultShader;
|
||||
|
||||
[ViewVariables]
|
||||
private ShaderInstance? DefaultShader => _defaultShader ??
|
||||
(_defaultShader = prototypes
|
||||
.Index<ShaderPrototype>("shaded")
|
||||
.Instance());
|
||||
private ShaderInstance? DefaultShader => _defaultShader ??= prototypes
|
||||
.Index<ShaderPrototype>("shaded")
|
||||
.Instance();
|
||||
|
||||
public const string LogCategory = "go.comp.sprite";
|
||||
const string LayerSerializationCache = "spritelayer";
|
||||
@@ -181,6 +327,46 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] public bool IsInert { get; private set; }
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(rsi))
|
||||
{
|
||||
var rsiPath = TextureRoot / rsi;
|
||||
try
|
||||
{
|
||||
BaseRSI = IoCManager.Resolve<IResourceCache>().GetResource<RSIResource>(rsiPath).RSI;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorS(SpriteComponent.LogCategory, "Unable to load RSI '{0}'. Trace:\n{1}", rsiPath, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (layerDatums.Count == 0)
|
||||
{
|
||||
if (state != null || texture != null)
|
||||
{
|
||||
layerDatums.Insert(0, new PrototypeLayerData
|
||||
{
|
||||
TexturePath = string.IsNullOrWhiteSpace(texture) ? null : texture,
|
||||
State = string.IsNullOrWhiteSpace(state) ? null : state,
|
||||
Color = Color.White,
|
||||
Scale = Vector2.One,
|
||||
Visible = true,
|
||||
});
|
||||
state = null;
|
||||
texture = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (layerDatums.Count != 0)
|
||||
{
|
||||
LayerDatums = layerDatums;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update this sprite component to visibly match the current state of other at the time
|
||||
/// this is called. Does not keep them perpetually in sync.
|
||||
@@ -1005,9 +1191,14 @@ namespace Robust.Client.GameObjects
|
||||
RenderInternal(drawingHandle, worldRotation, Vector2.Zero, overrideDirection);
|
||||
}
|
||||
|
||||
private bool _screenLock = false;
|
||||
private Direction _overrideDirection = Direction.South;
|
||||
private bool _enableOverrideDirection = false;
|
||||
[DataField("noRot")]
|
||||
private bool _screenLock = true;
|
||||
|
||||
[DataField("overrideDir")]
|
||||
private Direction _overrideDirection = Direction.East;
|
||||
|
||||
[DataField("enableOverrideDir")]
|
||||
private bool _enableOverrideDirection;
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
@@ -1153,205 +1344,6 @@ namespace Robust.Client.GameObjects
|
||||
return texture;
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataFieldCached(ref scale, "scale", Vector2.One);
|
||||
serializer.DataFieldCached(ref rotation, "rotation", Angle.Zero);
|
||||
serializer.DataFieldCached(ref offset, "offset", Vector2.Zero);
|
||||
serializer.DataFieldCached(ref drawDepth, "drawdepth", DrawDepthTag.Default,
|
||||
WithFormat.Constants<DrawDepthTag>());
|
||||
serializer.DataFieldCached(ref color, "color", Color.White);
|
||||
serializer.DataFieldCached(ref _visible, "visible", true);
|
||||
serializer.DataFieldCached(ref _directional, "directional", true); //TODO: Kill ME
|
||||
serializer.DataFieldCached(ref _screenLock, "noRot", true);
|
||||
serializer.DataFieldCached(ref _enableOverrideDirection, "enableOverrideDir", false);
|
||||
serializer.DataFieldCached(ref _overrideDirection, "overrideDir", Direction.East);
|
||||
|
||||
// TODO: Writing?
|
||||
if (!serializer.Reading)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
var rsi = serializer.ReadDataField<string?>("sprite", null);
|
||||
if (!string.IsNullOrWhiteSpace(rsi))
|
||||
{
|
||||
var rsiPath = TextureRoot / rsi;
|
||||
try
|
||||
{
|
||||
BaseRSI = resourceCache.GetResource<RSIResource>(rsiPath).RSI;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorS(LogCategory, "Unable to load RSI '{0}'. Trace:\n{1}", rsiPath, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Layer> CloneLayers(List<Layer> source)
|
||||
{
|
||||
var clone = new List<Layer>(source.Count);
|
||||
foreach (var layer in source)
|
||||
{
|
||||
clone.Add(new Layer(layer, this));
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
if (serializer.TryGetCacheData<List<Layer>>(LayerSerializationCache, out var layers))
|
||||
{
|
||||
LayerMap = serializer.GetCacheData<Dictionary<object, int>>(LayerMapSerializationCache);
|
||||
_layerMapShared = true;
|
||||
Layers = CloneLayers(layers);
|
||||
UpdateIsInert();
|
||||
return;
|
||||
}
|
||||
|
||||
layers = new List<Layer>();
|
||||
|
||||
var layerMap = new Dictionary<object, int>();
|
||||
|
||||
var layerData =
|
||||
serializer.ReadDataField("layers", new List<PrototypeLayerData>());
|
||||
|
||||
if(layerData.Count == 0){
|
||||
var baseState = serializer.ReadDataField<string?>("state", null);
|
||||
var texturePath = serializer.ReadDataField<string?>("texture", null);
|
||||
|
||||
if (baseState != null || texturePath != null)
|
||||
{
|
||||
layerData.Insert(0, new PrototypeLayerData
|
||||
{
|
||||
TexturePath = string.IsNullOrWhiteSpace(texturePath) ? null : texturePath,
|
||||
State = string.IsNullOrWhiteSpace(baseState) ? null : baseState,
|
||||
Color = Color.White,
|
||||
Scale = Vector2.One,
|
||||
Visible = true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var layerDatum in layerData)
|
||||
{
|
||||
var anyTextureAttempted = false;
|
||||
var layer = new Layer(this);
|
||||
if (!string.IsNullOrWhiteSpace(layerDatum.RsiPath))
|
||||
{
|
||||
var path = TextureRoot / layerDatum.RsiPath;
|
||||
try
|
||||
{
|
||||
layer.RSI = resourceCache.GetResource<RSIResource>(path).RSI;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Logger.ErrorS(LogCategory, "Unable to load layer RSI '{0}'.", path);
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(layerDatum.State))
|
||||
{
|
||||
anyTextureAttempted = true;
|
||||
var theRsi = layer.RSI ?? BaseRSI;
|
||||
if (theRsi == null)
|
||||
{
|
||||
Logger.ErrorS(LogCategory,
|
||||
"Layer has no RSI to load states from."
|
||||
+ "cannot use 'state' property. Prototype: '{0}'", Owner.Prototype?.ID);
|
||||
}
|
||||
else
|
||||
{
|
||||
var stateid = new RSI.StateId(layerDatum.State);
|
||||
layer.State = stateid;
|
||||
if (theRsi.TryGetState(stateid, out var state))
|
||||
{
|
||||
// Always use south because this layer will be cached in the serializer.
|
||||
layer.AnimationTimeLeft = state.GetDelay(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.ErrorS(LogCategory,
|
||||
$"State '{stateid}' not found in RSI: '{theRsi.Path}'.",
|
||||
stateid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(layerDatum.TexturePath))
|
||||
{
|
||||
anyTextureAttempted = true;
|
||||
if (layer.State.IsValid)
|
||||
{
|
||||
Logger.ErrorS(LogCategory,
|
||||
"Cannot specify 'texture' on a layer if it has an RSI state specified."
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
layer.Texture =
|
||||
resourceCache.GetResource<TextureResource>(TextureRoot / layerDatum.TexturePath);
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(layerDatum.Shader))
|
||||
{
|
||||
if (prototypes.TryIndex<ShaderPrototype>(layerDatum.Shader, out var prototype))
|
||||
{
|
||||
layer.Shader = prototype.Instance();
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.ErrorS(LogCategory,
|
||||
"Shader prototype '{0}' does not exist. Prototype: '{1}'",
|
||||
layerDatum.Shader, Owner.Prototype?.ID);
|
||||
}
|
||||
}
|
||||
|
||||
layer.Color = layerDatum.Color;
|
||||
layer.Rotation = layerDatum.Rotation;
|
||||
// If neither state: nor texture: were provided we assume that they want a blank invisible layer.
|
||||
layer.Visible = anyTextureAttempted && layerDatum.Visible;
|
||||
layer.Scale = layerDatum.Scale;
|
||||
|
||||
layers.Add(layer);
|
||||
|
||||
if (layerDatum.MapKeys != null)
|
||||
{
|
||||
var index = layers.Count - 1;
|
||||
foreach (var keyString in layerDatum.MapKeys)
|
||||
{
|
||||
object key;
|
||||
if (reflectionManager.TryParseEnumReference(keyString, out var @enum))
|
||||
{
|
||||
key = @enum;
|
||||
}
|
||||
else
|
||||
{
|
||||
key = keyString;
|
||||
}
|
||||
|
||||
if (layerMap.ContainsKey(key))
|
||||
{
|
||||
Logger.ErrorS(LogCategory, "Duplicate layer map key definition: {0}", key);
|
||||
continue;
|
||||
}
|
||||
|
||||
layerMap.Add(key, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Layers = layers;
|
||||
LayerMap = layerMap;
|
||||
_layerMapShared = true;
|
||||
serializer.SetCacheData(LayerSerializationCache, CloneLayers(Layers));
|
||||
serializer.SetCacheData(LayerMapSerializationCache, layerMap);
|
||||
UpdateIsInert();
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
base.OnRemove();
|
||||
@@ -1663,7 +1655,7 @@ namespace Robust.Client.GameObjects
|
||||
Flip = 3,
|
||||
}
|
||||
|
||||
private class Layer : ISpriteLayer
|
||||
public class Layer : ISpriteLayer
|
||||
{
|
||||
[ViewVariables] private readonly SpriteComponent _parent;
|
||||
|
||||
@@ -1730,6 +1722,22 @@ namespace Robust.Client.GameObjects
|
||||
RSI.StateId ISpriteLayer.RsiState { get => State; set => SetState(value); }
|
||||
Texture? ISpriteLayer.Texture { get => Texture; set => SetTexture(value); }
|
||||
|
||||
public PrototypeLayerData ToPrototypeData()
|
||||
{
|
||||
return new PrototypeLayerData
|
||||
{
|
||||
Color = Color,
|
||||
Rotation = Rotation,
|
||||
Scale = Scale,
|
||||
//todo Shader = Shader,
|
||||
State = State.Name,
|
||||
Visible = Visible,
|
||||
RsiPath = RSI?.Path?.ToString(),
|
||||
//todo TexturePath = Textur
|
||||
//todo MapKeys
|
||||
};
|
||||
}
|
||||
|
||||
bool ISpriteLayer.Visible
|
||||
{
|
||||
get => Visible;
|
||||
@@ -2000,7 +2008,6 @@ namespace Robust.Client.GameObjects
|
||||
}
|
||||
|
||||
return state;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2051,7 +2058,6 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
if (!anyTexture)
|
||||
yield return resourceCache.GetFallback<TextureResource>().Texture;
|
||||
|
||||
}
|
||||
|
||||
public static IRsiStateLike GetPrototypeIcon(EntityPrototype prototype, IResourceCache resourceCache)
|
||||
@@ -2098,6 +2104,7 @@ namespace Robust.Client.GameObjects
|
||||
public T AddComponent<T>() where T : Component, new()
|
||||
{
|
||||
var typeFactory = IoCManager.Resolve<IDynamicTypeFactoryInternal>();
|
||||
var serializationManager = IoCManager.Resolve<ISerializationManager>();
|
||||
var comp = (T) typeFactory.CreateInstanceUnchecked(typeof(T));
|
||||
_components[typeof(T)] = comp;
|
||||
comp.Owner = this;
|
||||
@@ -2107,9 +2114,9 @@ namespace Robust.Client.GameObjects
|
||||
_components[typeof(ISpriteComponent)] = comp;
|
||||
}
|
||||
|
||||
if (Prototype != null && Prototype.Components.TryGetValue(comp.Name, out var node))
|
||||
if (Prototype != null && Prototype.TryGetComponent<T>(comp.Name, out var node))
|
||||
{
|
||||
comp.ExposeData(YamlObjectSerializer.NewReader(node));
|
||||
comp = serializationManager.Copy(node, comp)!;
|
||||
}
|
||||
|
||||
return comp;
|
||||
|
||||
@@ -6,41 +6,31 @@ using Robust.Shared.Network;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Robust.Client.GameObjects
|
||||
{
|
||||
public class ClientUserInterfaceComponent : SharedUserInterfaceComponent
|
||||
public class ClientUserInterfaceComponent : SharedUserInterfaceComponent, ISerializationHooks
|
||||
{
|
||||
[Dependency] private readonly IReflectionManager _reflectionManager = default!;
|
||||
[Dependency] private readonly IDynamicTypeFactory _dynamicTypeFactory = default!;
|
||||
|
||||
private readonly Dictionary<object, BoundUserInterface> _openInterfaces =
|
||||
new();
|
||||
|
||||
private Dictionary<object, PrototypeData> _interfaceData = default!;
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IReflectionManager _reflectionManager = default!;
|
||||
[Dependency] private readonly IDynamicTypeFactory _dynamicTypeFactory = default!;
|
||||
#pragma warning restore 649
|
||||
private readonly Dictionary<object, PrototypeData> _interfaces = new();
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
[DataField("interfaces", readOnly: true)]
|
||||
private List<PrototypeData> _interfaceData = new();
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
_interfaces.Clear();
|
||||
|
||||
const string cache = "ui_cache";
|
||||
|
||||
if (serializer.TryGetCacheData<Dictionary<object, PrototypeData>>(cache, out var interfaceData))
|
||||
foreach (var data in _interfaceData)
|
||||
{
|
||||
_interfaceData = interfaceData;
|
||||
return;
|
||||
_interfaces[data.UiKey] = data;
|
||||
}
|
||||
|
||||
var data = serializer.ReadDataFieldCached("interfaces", new List<PrototypeData>());
|
||||
interfaceData = new Dictionary<object, PrototypeData>();
|
||||
foreach (var prototypeData in data)
|
||||
{
|
||||
interfaceData[prototypeData.UiKey] = prototypeData;
|
||||
}
|
||||
|
||||
serializer.SetCacheData(cache, interfaceData);
|
||||
_interfaceData = interfaceData;
|
||||
}
|
||||
|
||||
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel,
|
||||
@@ -81,7 +71,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
private void OpenInterface(BoundInterfaceMessageWrapMessage wrapped)
|
||||
{
|
||||
var data = _interfaceData[wrapped.UiKey];
|
||||
var data = _interfaces[wrapped.UiKey];
|
||||
// TODO: This type should be cached, but I'm too lazy.
|
||||
var type = _reflectionManager.LooseGetType(data.ClientType);
|
||||
var boundInterface = (BoundUserInterface) _dynamicTypeFactory.CreateInstance(type, new[]{this, wrapped.UiKey});
|
||||
|
||||
@@ -10,6 +10,7 @@ using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -24,17 +25,21 @@ namespace Robust.Client.GameObjects
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
private SharedBroadPhaseSystem _broadPhaseSystem = default!;
|
||||
|
||||
private readonly List<PlayingStream> _playingClydeStreams = new();
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeNetworkEvent<PlayAudioEntityMessage>(PlayAudioEntityHandler);
|
||||
SubscribeNetworkEvent<PlayAudioGlobalMessage>(PlayAudioGlobalHandler);
|
||||
SubscribeNetworkEvent<PlayAudioPositionalMessage>(PlayAudioPositionalHandler);
|
||||
SubscribeNetworkEvent<StopAudioMessageClient>(StopAudioMessageHandler);
|
||||
|
||||
SubscribeLocalEvent<SoundSystem.QueryAudioSystem>((ev => ev.Audio = this));
|
||||
_broadPhaseSystem = Get<SharedBroadPhaseSystem>();
|
||||
}
|
||||
|
||||
private void StopAudioMessageHandler(StopAudioMessageClient ev)
|
||||
@@ -141,7 +146,7 @@ namespace Robust.Client.GameObjects
|
||||
var occlusion = 0f;
|
||||
if (sourceRelative.Length > 0)
|
||||
{
|
||||
occlusion = IoCManager.Resolve<IPhysicsManager>().IntersectRayPenetration(
|
||||
occlusion = _broadPhaseSystem.IntersectRayPenetration(
|
||||
pos.MapId,
|
||||
new CollisionRay(
|
||||
pos.Position,
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Robust.Client.GameObjects
|
||||
{
|
||||
public class VelocityDebugSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
|
||||
internal bool Enabled { get; set; }
|
||||
|
||||
private Label _label = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_label = new Label();
|
||||
IoCManager.Resolve<IUserInterfaceManager>().StateRoot.AddChild(_label);
|
||||
}
|
||||
|
||||
public override void FrameUpdate(float frameTime)
|
||||
{
|
||||
base.FrameUpdate(frameTime);
|
||||
if (!Enabled)
|
||||
{
|
||||
_label.Visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var player = _playerManager.LocalPlayer?.ControlledEntity;
|
||||
|
||||
if (player == null || !player.TryGetComponent(out PhysicsComponent? body))
|
||||
{
|
||||
_label.Visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var screenPos = _eyeManager.WorldToScreen(player.Transform.WorldPosition);
|
||||
LayoutContainer.SetPosition(_label, screenPos + new Vector2(0, 50));
|
||||
_label.Visible = true;
|
||||
|
||||
_label.Text = $"Speed: {body.LinearVelocity.Length}\nLinear: {body.LinearVelocity.X:0.00}, {body.LinearVelocity.Y:0.00}\nAngular:{body.AngularVelocity}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ namespace Robust.Client.GameStates
|
||||
handle.UseShader(_shader);
|
||||
var worldHandle = (DrawingHandleWorld) handle;
|
||||
var viewport = _eyeManager.GetWorldViewport();
|
||||
foreach (var boundingBox in _componentManager.EntityQuery<IPhysicsComponent>(true))
|
||||
foreach (var boundingBox in _componentManager.EntityQuery<IPhysBody>(true))
|
||||
{
|
||||
// all entities have a TransformComponent
|
||||
var transform = ((IComponent)boundingBox).Owner.Transform;
|
||||
@@ -42,7 +42,7 @@ namespace Robust.Client.GameStates
|
||||
if(transform.LerpDestination == null)
|
||||
continue;
|
||||
|
||||
var aabb = ((IPhysBody)boundingBox).AABB;
|
||||
var aabb = boundingBox.GetWorldAABB();
|
||||
|
||||
// if not on screen, or too small, continue
|
||||
if (!aabb.Translated(transform.WorldPosition).Intersects(viewport) || aabb.IsEmpty())
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Buffers;
|
||||
using OpenToolkit.Graphics.OpenGL4;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.ResourceManagement.ResourceTypes;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using OpenToolkit.Graphics.OpenGL4;
|
||||
using Robust.Client.ResourceManagement.ResourceTypes;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
using StencilOp = Robust.Client.Graphics.StencilOp;
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.ResourceManagement.ResourceTypes;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace Robust.Client.Graphics
|
||||
{
|
||||
[Prototype("shader")]
|
||||
public sealed class ShaderPrototype : IPrototype
|
||||
public sealed class ShaderPrototype : IPrototype, ISerializationHooks
|
||||
{
|
||||
[Dependency] private readonly IClydeInternal _clyde = default!;
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
|
||||
public string ID { get; private set; } = default!;
|
||||
[ViewVariables]
|
||||
[field: DataField("id", required: true)]
|
||||
public string ID { get; } = default!;
|
||||
|
||||
private ShaderKind Kind;
|
||||
|
||||
@@ -31,11 +34,14 @@ namespace Robust.Client.Graphics
|
||||
private ShaderInstance? _cachedInstance;
|
||||
|
||||
private bool _stencilEnabled;
|
||||
private int _stencilRef;
|
||||
private int _stencilReadMask = unchecked((int) uint.MaxValue);
|
||||
private int _stencilWriteMask = unchecked((int) uint.MaxValue);
|
||||
private StencilFunc _stencilFunc = StencilFunc.Always;
|
||||
private StencilOp _stencilOp = StencilOp.Keep;
|
||||
private int _stencilRef => StencilDataHolder?.StencilRef ?? 0;
|
||||
private int _stencilReadMask => StencilDataHolder?.ReadMask ?? unchecked((int) uint.MaxValue);
|
||||
private int _stencilWriteMask => StencilDataHolder?.WriteMask ?? unchecked((int) uint.MaxValue);
|
||||
private StencilFunc _stencilFunc => StencilDataHolder?.StencilFunc ?? StencilFunc.Always;
|
||||
private StencilOp _stencilOp => StencilDataHolder?.StencilOp ?? StencilOp.Keep;
|
||||
|
||||
[DataField("stencil")]
|
||||
private StencilData? StencilDataHolder;
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a ready-to-use instance of this shader.
|
||||
@@ -64,12 +70,12 @@ namespace Robust.Client.Graphics
|
||||
switch (Kind)
|
||||
{
|
||||
case ShaderKind.Source:
|
||||
instance = _clyde.InstanceShader(Source!.ClydeHandle);
|
||||
instance = IoCManager.Resolve<IClydeInternal>().InstanceShader(Source!.ClydeHandle);
|
||||
_applyDefaultParameters(instance);
|
||||
break;
|
||||
|
||||
case ShaderKind.Canvas:
|
||||
instance = _clyde.InstanceShader(CompiledCanvasShader);
|
||||
instance = IoCManager.Resolve<IClydeInternal>().InstanceShader(CompiledCanvasShader);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -95,135 +101,108 @@ namespace Robust.Client.Graphics
|
||||
return Instance().Duplicate();
|
||||
}
|
||||
|
||||
public void LoadFrom(YamlMappingNode mapping)
|
||||
{
|
||||
ID = mapping.GetNode("id").ToString();
|
||||
[DataField("kind", readOnly: true, required: true)] private string _rawKind = default!;
|
||||
[DataField("path", readOnly: true)] private ResourcePath? path;
|
||||
[DataField("params", readOnly: true)] private Dictionary<string, string>? paramMapping;
|
||||
[DataField("light_mode", readOnly: true)] private string? rawMode;
|
||||
[DataField("blend_mode", readOnly: true)] private string? rawBlendMode;
|
||||
|
||||
var kind = mapping.GetNode("kind").AsString();
|
||||
switch (kind)
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
switch (_rawKind)
|
||||
{
|
||||
case "source":
|
||||
Kind = ShaderKind.Source;
|
||||
ReadSourceKind(mapping);
|
||||
if (path == null) throw new InvalidOperationException();
|
||||
Source = IoCManager.Resolve<IResourceCache>().GetResource<ShaderSourceResource>(path);
|
||||
|
||||
if (paramMapping != null)
|
||||
{
|
||||
ShaderParams = new Dictionary<string, object>();
|
||||
foreach (var item in paramMapping!)
|
||||
{
|
||||
var name = item.Key;
|
||||
if (!Source.ParsedShader.Uniforms.TryGetValue(name, out var uniformDefinition))
|
||||
{
|
||||
Logger.ErrorS("shader", "Shader param '{0}' does not exist on shader '{1}'", name, path);
|
||||
continue;
|
||||
}
|
||||
|
||||
var value = _parseUniformValue(item.Value, uniformDefinition.Type.Type);
|
||||
ShaderParams.Add(name, value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "canvas":
|
||||
Kind = ShaderKind.Canvas;
|
||||
ReadCanvasKind(mapping);
|
||||
var source = "";
|
||||
|
||||
if(rawMode != null)
|
||||
{
|
||||
switch (rawMode)
|
||||
{
|
||||
case "normal":
|
||||
break;
|
||||
|
||||
case "unshaded":
|
||||
source += "light_mode unshaded;\n";
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException($"Invalid light mode: '{rawMode}'");
|
||||
}
|
||||
}
|
||||
|
||||
if(rawBlendMode != null){
|
||||
switch (rawBlendMode)
|
||||
{
|
||||
case "mix":
|
||||
source += "blend_mode mix;\n";
|
||||
break;
|
||||
|
||||
case "add":
|
||||
source += "blend_mode add;\n";
|
||||
break;
|
||||
|
||||
case "subtract":
|
||||
source += "blend_mode subtract;\n";
|
||||
break;
|
||||
|
||||
case "multiply":
|
||||
source += "blend_mode multiply;\n";
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException($"Invalid blend mode: '{rawBlendMode}'");
|
||||
}
|
||||
}
|
||||
|
||||
source += "void fragment() {\n COLOR = zTexture(UV);\n}";
|
||||
|
||||
var preset = ShaderParser.Parse(source, _resourceCache);
|
||||
CompiledCanvasShader = IoCManager.Resolve<IClydeInternal>().LoadShader(preset, $"canvas_preset_{ID}");
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException($"Invalid shader kind: '{kind}'");
|
||||
throw new InvalidOperationException($"Invalid shader kind: '{_rawKind}'");
|
||||
}
|
||||
|
||||
// Load stencil data.
|
||||
if (mapping.TryGetNode("stencil", out YamlMappingNode? stencilData))
|
||||
{
|
||||
ReadStencilData(stencilData);
|
||||
}
|
||||
if (StencilDataHolder != null) _stencilEnabled = true;
|
||||
}
|
||||
|
||||
private void ReadStencilData(YamlMappingNode stencilData)
|
||||
[DataDefinition]
|
||||
public class StencilData
|
||||
{
|
||||
_stencilEnabled = true;
|
||||
[DataField("ref")] public int StencilRef;
|
||||
|
||||
if (stencilData.TryGetNode("ref", out var dataNode))
|
||||
{
|
||||
_stencilRef = dataNode.AsInt();
|
||||
}
|
||||
[DataField("op")] public StencilOp StencilOp;
|
||||
|
||||
if (stencilData.TryGetNode("op", out dataNode))
|
||||
{
|
||||
_stencilOp = dataNode.AsEnum<StencilOp>();
|
||||
}
|
||||
[DataField("func")] public StencilFunc StencilFunc;
|
||||
|
||||
if (stencilData.TryGetNode("func", out dataNode))
|
||||
{
|
||||
_stencilFunc = dataNode.AsEnum<StencilFunc>();
|
||||
}
|
||||
[DataField("readMask")] public int ReadMask = unchecked((int) uint.MaxValue);
|
||||
|
||||
if (stencilData.TryGetNode("readMask", out dataNode))
|
||||
{
|
||||
_stencilReadMask = dataNode.AsInt();
|
||||
}
|
||||
|
||||
if (stencilData.TryGetNode("writeMask", out dataNode))
|
||||
{
|
||||
_stencilWriteMask = dataNode.AsInt();
|
||||
}
|
||||
}
|
||||
|
||||
private void ReadSourceKind(YamlMappingNode mapping)
|
||||
{
|
||||
var path = mapping.GetNode("path").AsResourcePath();
|
||||
Source = _resourceCache.GetResource<ShaderSourceResource>(path);
|
||||
if (mapping.TryGetNode<YamlMappingNode>("params", out var paramMapping))
|
||||
{
|
||||
ShaderParams = new Dictionary<string, object>();
|
||||
foreach (var item in paramMapping)
|
||||
{
|
||||
var name = item.Key.AsString();
|
||||
if (!Source.ParsedShader.Uniforms.TryGetValue(name, out var uniformDefinition))
|
||||
{
|
||||
Logger.ErrorS("shader", "Shader param '{0}' does not exist on shader '{1}'", name, path);
|
||||
continue;
|
||||
}
|
||||
|
||||
var value = _parseUniformValue(item.Value, uniformDefinition.Type.Type);
|
||||
ShaderParams.Add(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ReadCanvasKind(YamlMappingNode mapping)
|
||||
{
|
||||
var source = "";
|
||||
|
||||
if (mapping.TryGetNode("light_mode", out var node))
|
||||
{
|
||||
switch (node.AsString())
|
||||
{
|
||||
case "normal":
|
||||
break;
|
||||
|
||||
case "unshaded":
|
||||
source += "light_mode unshaded;\n";
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException($"Invalid light mode: '{node.AsString()}'");
|
||||
}
|
||||
}
|
||||
|
||||
if (mapping.TryGetNode("blend_mode", out node))
|
||||
{
|
||||
switch (node.AsString())
|
||||
{
|
||||
case "mix":
|
||||
source += "blend_mode mix;\n";
|
||||
break;
|
||||
|
||||
case "add":
|
||||
source += "blend_mode add;\n";
|
||||
break;
|
||||
|
||||
case "subtract":
|
||||
source += "blend_mode subtract;\n";
|
||||
break;
|
||||
|
||||
case "multiply":
|
||||
source += "blend_mode multiply;\n";
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException($"Invalid blend mode: '{node.AsString()}'");
|
||||
}
|
||||
}
|
||||
|
||||
source += "void fragment() {\n COLOR = zTexture(UV);\n}";
|
||||
|
||||
var preset = ShaderParser.Parse(source, _resourceCache);
|
||||
CompiledCanvasShader = _clyde.LoadShader(preset, $"canvas_preset_{ID}");
|
||||
[DataField("writeMask")] public int WriteMask = unchecked((int) uint.MaxValue);
|
||||
}
|
||||
|
||||
private static object _parseUniformValue(YamlNode node, ShaderDataType dataType)
|
||||
|
||||
@@ -19,6 +19,8 @@ using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Markdown;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using YamlDotNet.Core;
|
||||
@@ -117,8 +119,8 @@ namespace Robust.Client.Input
|
||||
|
||||
public void SaveToUserData()
|
||||
{
|
||||
var mapping = new YamlMappingNode();
|
||||
var ser = YamlObjectSerializer.NewWriter(mapping);
|
||||
var mapping = new MappingDataNode();
|
||||
var serializationManager = IoCManager.Resolve<ISerializationManager>();
|
||||
|
||||
var modifiedBindings = _modifiedKeyFunctions
|
||||
.Select(p => _bindingsByFunction[p])
|
||||
@@ -141,15 +143,13 @@ namespace Robust.Client.Input
|
||||
.Where(p => _bindingsByFunction[p].Count == 0)
|
||||
.ToArray();
|
||||
|
||||
var version = 1;
|
||||
|
||||
ser.DataField(ref version, "version", 1);
|
||||
ser.DataField(ref modifiedBindings, "binds", Array.Empty<KeyBindingRegistration>());
|
||||
ser.DataField(ref leaveEmpty, "leaveEmpty", Array.Empty<BoundKeyFunction>());
|
||||
mapping.AddNode("version", new ValueDataNode("1"));
|
||||
mapping.AddNode("binds", serializationManager.WriteValue(modifiedBindings));
|
||||
mapping.AddNode("leaveEmpty", serializationManager.WriteValue(leaveEmpty));
|
||||
|
||||
var path = new ResourcePath(KeybindsPath);
|
||||
using var writer = new StreamWriter(_resourceMan.UserData.Create(path));
|
||||
var stream = new YamlStream {new(mapping)};
|
||||
var stream = new YamlStream {new(mapping.ToMappingNode())};
|
||||
stream.Save(new YamlMappingFix(new Emitter(writer)), false);
|
||||
}
|
||||
|
||||
@@ -416,12 +416,14 @@ namespace Robust.Client.Input
|
||||
|
||||
var mapping = (YamlMappingNode) yamlStream.Documents[0].RootNode;
|
||||
|
||||
var baseSerializer = YamlObjectSerializer.NewReader(mapping);
|
||||
var serializationManager = IoCManager.Resolve<ISerializationManager>();
|
||||
var robustMapping = mapping.ToDataNode() as MappingDataNode;
|
||||
if (robustMapping == null) throw new InvalidOperationException();
|
||||
|
||||
var foundBinds = baseSerializer.TryReadDataField<KeyBindingRegistration[]>("binds", out var baseKeyRegs);
|
||||
|
||||
if (foundBinds && baseKeyRegs != null && baseKeyRegs.Length > 0)
|
||||
if (robustMapping.TryGetNode("binds", out var BaseKeyRegsNode))
|
||||
{
|
||||
var baseKeyRegs = serializationManager.ReadValueOrThrow<KeyBindingRegistration[]>(BaseKeyRegsNode);
|
||||
|
||||
foreach (var reg in baseKeyRegs)
|
||||
{
|
||||
if (!NetworkBindMap.FunctionExists(reg.Function.FunctionName))
|
||||
@@ -447,11 +449,11 @@ namespace Robust.Client.Input
|
||||
}
|
||||
}
|
||||
|
||||
if (userData)
|
||||
if (userData && robustMapping.TryGetNode("leaveEmpty", out var node))
|
||||
{
|
||||
var foundLeaveEmpty = baseSerializer.TryReadDataField<BoundKeyFunction[]>("leaveEmpty", out var leaveEmpty);
|
||||
var leaveEmpty = serializationManager.ReadValueOrThrow<BoundKeyFunction[]>(node);
|
||||
|
||||
if (foundLeaveEmpty && leaveEmpty != null && leaveEmpty.Length > 0)
|
||||
if (leaveEmpty.Length > 0)
|
||||
{
|
||||
// Adding to _modifiedKeyFunctions means that these keybinds won't be loaded from the base file.
|
||||
// Because they've been explicitly cleared.
|
||||
|
||||
@@ -1,33 +1,30 @@
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Robust.Client.Input
|
||||
{
|
||||
public struct KeyBindingRegistration : IExposeData
|
||||
[DataDefinition]
|
||||
public class KeyBindingRegistration
|
||||
{
|
||||
[DataField("function")]
|
||||
public BoundKeyFunction Function;
|
||||
public KeyBindingType Type;
|
||||
[DataField("type")]
|
||||
public KeyBindingType Type = KeyBindingType.State;
|
||||
[DataField("key")]
|
||||
public Keyboard.Key BaseKey;
|
||||
[DataField("mod1")]
|
||||
public Keyboard.Key Mod1;
|
||||
[DataField("mod2")]
|
||||
public Keyboard.Key Mod2;
|
||||
[DataField("mod3")]
|
||||
public Keyboard.Key Mod3;
|
||||
[DataField("priority")]
|
||||
public int Priority;
|
||||
[DataField("canFocus")]
|
||||
public bool CanFocus;
|
||||
[DataField("canRepeat")]
|
||||
public bool CanRepeat;
|
||||
[DataField("allowSubCombs")]
|
||||
public bool AllowSubCombs;
|
||||
|
||||
void IExposeData.ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(ref Function, "function", default);
|
||||
serializer.DataField(ref Type, "type", KeyBindingType.State);
|
||||
serializer.DataField(ref BaseKey, "key", default);
|
||||
serializer.DataField(ref Mod1, "mod1", default);
|
||||
serializer.DataField(ref Mod2, "mod2", default);
|
||||
serializer.DataField(ref Mod3, "mod3", default);
|
||||
serializer.DataField(ref Priority, "priority", 0);
|
||||
serializer.DataField(ref CanFocus, "canFocus", false);
|
||||
serializer.DataField(ref CanRepeat, "canRepeat", false);
|
||||
serializer.DataField(ref AllowSubCombs, "allowSubCombs", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
13
Robust.Client/Physics/BroadPhaseSystem.cs
Normal file
13
Robust.Client/Physics/BroadPhaseSystem.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
|
||||
namespace Robust.Client.Physics
|
||||
{
|
||||
internal sealed class BroadPhaseSystem : SharedBroadPhaseSystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
UpdatesBefore.Add(typeof(PhysicsSystem));
|
||||
}
|
||||
}
|
||||
}
|
||||
135
Robust.Client/Physics/DebugPhysicsIslandSystem.cs
Normal file
135
Robust.Client/Physics/DebugPhysicsIslandSystem.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Robust.Client.Physics
|
||||
{
|
||||
internal sealed class PhysicsIslandCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "showislands";
|
||||
public string Description => "Shows the current physics bodies involved in each physics island.";
|
||||
public string Help => "showislands";
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 0)
|
||||
{
|
||||
shell.WriteLine("This command doesn't take args!");
|
||||
return;
|
||||
}
|
||||
|
||||
EntitySystem.Get<DebugPhysicsIslandSystem>().Mode ^= DebugPhysicsIslandMode.Solve;
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class DebugPhysicsIslandSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
public DebugPhysicsIslandMode Mode { get; set; } = DebugPhysicsIslandMode.None;
|
||||
|
||||
/*
|
||||
* Island solve debug:
|
||||
* This will draw above every body involved in a particular island solve.
|
||||
*/
|
||||
|
||||
public readonly Queue<(TimeSpan Time, List<IPhysBody> Bodies)> IslandSolve = new();
|
||||
public const float SolveDuration = 0.1f;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<IslandSolveMessage>(HandleIslandSolveMessage);
|
||||
IoCManager.Resolve<IOverlayManager>().AddOverlay(new PhysicsIslandOverlay());
|
||||
}
|
||||
|
||||
public override void FrameUpdate(float frameTime)
|
||||
{
|
||||
base.FrameUpdate(frameTime);
|
||||
while (IslandSolve.TryPeek(out var solve))
|
||||
{
|
||||
if (solve.Time.TotalSeconds + SolveDuration > _gameTiming.CurTime.TotalSeconds)
|
||||
{
|
||||
IslandSolve.Dequeue();
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
IoCManager.Resolve<IOverlayManager>().RemoveOverlay(nameof(PhysicsIslandOverlay));
|
||||
}
|
||||
|
||||
private void HandleIslandSolveMessage(IslandSolveMessage message)
|
||||
{
|
||||
if ((Mode & DebugPhysicsIslandMode.Solve) == 0x0) return;
|
||||
IslandSolve.Enqueue((_gameTiming.CurTime, message.Bodies));
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
internal enum DebugPhysicsIslandMode : ushort
|
||||
{
|
||||
None = 0,
|
||||
Solve = 1 << 0,
|
||||
Contacts = 1 << 1,
|
||||
}
|
||||
|
||||
internal sealed class PhysicsIslandOverlay : Overlay
|
||||
{
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
private DebugPhysicsIslandSystem _islandSystem = default!;
|
||||
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpace;
|
||||
|
||||
public PhysicsIslandOverlay() : base(nameof(PhysicsIslandOverlay))
|
||||
{
|
||||
_islandSystem = EntitySystem.Get<DebugPhysicsIslandSystem>();
|
||||
_eyeManager = IoCManager.Resolve<IEyeManager>();
|
||||
_gameTiming = IoCManager.Resolve<IGameTiming>();
|
||||
}
|
||||
|
||||
protected override void Draw(DrawingHandleBase handle, OverlaySpace currentSpace)
|
||||
{
|
||||
var worldHandle = (DrawingHandleWorld) handle;
|
||||
|
||||
DrawIslandSolve(worldHandle);
|
||||
}
|
||||
|
||||
private void DrawIslandSolve(DrawingHandleWorld handle)
|
||||
{
|
||||
if ((_islandSystem.Mode & DebugPhysicsIslandMode.Solve) == 0x0) return;
|
||||
|
||||
var viewport = _eyeManager.GetWorldViewport();
|
||||
|
||||
foreach (var solve in _islandSystem.IslandSolve)
|
||||
{
|
||||
var ratio = (float) Math.Max(
|
||||
(solve.Time.TotalSeconds + DebugPhysicsIslandSystem.SolveDuration -
|
||||
_gameTiming.CurTime.TotalSeconds) / DebugPhysicsIslandSystem.SolveDuration, 0.0f);
|
||||
|
||||
if (ratio <= 0.0f) continue;
|
||||
|
||||
foreach (var body in solve.Bodies)
|
||||
{
|
||||
var worldAABB = body.GetWorldAABB();
|
||||
if (!viewport.Intersects(worldAABB)) continue;
|
||||
|
||||
handle.DrawRect(worldAABB, Color.Green.WithAlpha(ratio * 0.5f));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Network.Messages;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Network.Messages;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Client.Placement
|
||||
{
|
||||
@@ -126,14 +124,6 @@ namespace Robust.Client.Placement
|
||||
if (value != null)
|
||||
{
|
||||
PlacementOffset = value.PlacementOffset;
|
||||
|
||||
if (value.Components.ContainsKey("BoundingBox") && value.Components.ContainsKey("Physics"))
|
||||
{
|
||||
var map = value.Components["BoundingBox"];
|
||||
var serializer = YamlObjectSerializer.NewReader(map);
|
||||
serializer.DataField(ref _colliderAABB, "aabb", new Box2(0f, 0f, 0f, 0f));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_colliderAABB = new Box2(0f, 0f, 0f, 0f);
|
||||
|
||||
@@ -4,8 +4,10 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Client.Placement
|
||||
@@ -230,7 +232,7 @@ namespace Robust.Client.Placement
|
||||
bounds.Width,
|
||||
bounds.Height);
|
||||
|
||||
return pManager.PhysicsManager.TryCollideRect(collisionBox, mapCoords.MapId);
|
||||
return EntitySystem.Get<SharedBroadPhaseSystem>().TryCollideRect(collisionBox, mapCoords.MapId);
|
||||
}
|
||||
|
||||
protected Vector2 ScreenToWorld(Vector2 point)
|
||||
|
||||
@@ -5,7 +5,7 @@ using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Client.ResourceManagement.ResourceTypes
|
||||
namespace Robust.Client.ResourceManagement
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads the **source code** of a shader.
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.Manager.Result;
|
||||
using Robust.Shared.Serialization.Markdown;
|
||||
using Robust.Shared.Serialization.Markdown.Validation;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Interfaces;
|
||||
|
||||
namespace Robust.Client.Serialization
|
||||
{
|
||||
[TypeSerializer]
|
||||
public class AppearanceVisualizerSerializer : ITypeSerializer<AppearanceVisualizer, MappingDataNode>
|
||||
{
|
||||
public DeserializationResult Read(ISerializationManager serializationManager, MappingDataNode node,
|
||||
IDependencyCollection dependencies,
|
||||
bool skipHook,
|
||||
ISerializationContext? context = null)
|
||||
{
|
||||
if (!node.TryGetNode("type", out var typeNode))
|
||||
throw new InvalidMappingException("No type specified for AppearanceVisualizer!");
|
||||
|
||||
if (typeNode is not ValueDataNode typeValueDataNode)
|
||||
throw new InvalidMappingException("Type node not a value node for AppearanceVisualizer!");
|
||||
|
||||
var type = IoCManager.Resolve<IReflectionManager>()
|
||||
.YamlTypeTagLookup(typeof(AppearanceVisualizer), typeValueDataNode.Value);
|
||||
if (type == null)
|
||||
throw new InvalidMappingException(
|
||||
$"Invalid type {typeValueDataNode.Value} specified for AppearanceVisualizer!");
|
||||
|
||||
var newNode = (MappingDataNode)node.Copy();
|
||||
newNode.RemoveNode("type");
|
||||
return serializationManager.Read(type, newNode, context, skipHook);
|
||||
}
|
||||
|
||||
public ValidationNode Validate(ISerializationManager serializationManager, MappingDataNode node,
|
||||
IDependencyCollection dependencies,
|
||||
ISerializationContext? context)
|
||||
{
|
||||
if (!node.TryGetNode("type", out var typeNode) || typeNode is not ValueDataNode valueNode)
|
||||
{
|
||||
return new ErrorNode(node, "Missing/Invalid type", true);
|
||||
}
|
||||
|
||||
var reflectionManager = IoCManager.Resolve<IReflectionManager>();
|
||||
var type = reflectionManager.YamlTypeTagLookup(typeof(AppearanceVisualizer), valueNode.Value);
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
return new ErrorNode(node, $"Failed to resolve type: {valueNode.Value}", true);
|
||||
}
|
||||
|
||||
return serializationManager.ValidateNode(type, node.CopyCast<MappingDataNode>().RemoveNode("type"));
|
||||
}
|
||||
|
||||
public DataNode Write(ISerializationManager serializationManager, AppearanceVisualizer value, bool alwaysWrite = false,
|
||||
ISerializationContext? context = null)
|
||||
{
|
||||
var mapping = serializationManager.WriteValueAs<MappingDataNode>(value.GetType(), value, alwaysWrite, context);
|
||||
mapping.AddNode("type", new ValueDataNode(value.GetType().Name));
|
||||
return mapping;
|
||||
}
|
||||
|
||||
public AppearanceVisualizer Copy(ISerializationManager serializationManager, AppearanceVisualizer source,
|
||||
AppearanceVisualizer target, bool skipHook, ISerializationContext? context = null)
|
||||
{
|
||||
return serializationManager.Copy(source, target, context)!;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,12 +26,10 @@ namespace Robust.Client.Utility
|
||||
{
|
||||
if (cache.TryGetResource<RSIResource>(
|
||||
SharedSpriteComponent.TextureRoot / rsiSpecifier.RsiPath,
|
||||
out var theRsi))
|
||||
out var theRsi) &&
|
||||
theRsi.RSI.TryGetState(rsiSpecifier.RsiState, out var state))
|
||||
{
|
||||
if (theRsi.RSI.TryGetState(rsiSpecifier.RsiState, out var state))
|
||||
{
|
||||
return state;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
Logger.Error("Failed to load RSI {0}", rsiSpecifier.RsiPath);
|
||||
|
||||
63
Robust.Generators.UnitTesting/AnalyzerTest.cs
Normal file
63
Robust.Generators.UnitTesting/AnalyzerTest.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Robust.Generators.UnitTesting
|
||||
{
|
||||
[Parallelizable]
|
||||
public abstract class AnalyzerTest
|
||||
{
|
||||
protected static Assembly GetAssemblyFromCompilation(Compilation newComp)
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
newComp.Emit(stream);
|
||||
var assembly = Assembly.Load(stream.ToArray());
|
||||
return assembly;
|
||||
}
|
||||
|
||||
protected static Compilation CreateCompilation(string source)
|
||||
{
|
||||
var dd = typeof(Enumerable).GetTypeInfo().Assembly.Location;
|
||||
var coreDir = Directory.GetParent(dd) ?? throw new Exception("Couldn't find location of coredir");
|
||||
|
||||
var references = new[]
|
||||
{
|
||||
MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location),
|
||||
MetadataReference.CreateFromFile(typeof(Enumerable).GetTypeInfo().Assembly.Location),
|
||||
MetadataReference.CreateFromFile(typeof(Dictionary<,>).GetTypeInfo().Assembly.Location),
|
||||
MetadataReference.CreateFromFile(typeof(DataFieldAttribute).GetTypeInfo().Assembly.Location),
|
||||
MetadataReference.CreateFromFile(coreDir.FullName + Path.DirectorySeparatorChar + "mscorlib.dll"),
|
||||
MetadataReference.CreateFromFile(coreDir.FullName + Path.DirectorySeparatorChar +
|
||||
"System.Runtime.dll"),
|
||||
MetadataReference.CreateFromFile(coreDir.FullName + Path.DirectorySeparatorChar +
|
||||
"System.Collections.dll"),
|
||||
};
|
||||
|
||||
var syntaxTree = CSharpSyntaxTree.ParseText(source, new CSharpParseOptions(LanguageVersion.Preview));
|
||||
return CSharpCompilation.Create(
|
||||
"comp",
|
||||
new[] {syntaxTree},
|
||||
references,
|
||||
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
|
||||
}
|
||||
|
||||
protected static (Compilation, ImmutableArray<Diagnostic> diagnostics) RunGenerators(Compilation c,
|
||||
params ISourceGenerator[] gens)
|
||||
{
|
||||
var driver = CSharpGeneratorDriver.Create(
|
||||
ImmutableArray.Create(gens),
|
||||
ImmutableArray<AdditionalText>.Empty,
|
||||
(CSharpParseOptions) c.SyntaxTrees.First().Options);
|
||||
driver.RunGeneratorsAndUpdateCompilation(c, out var d, out var diagnostics);
|
||||
return (d, diagnostics);
|
||||
}
|
||||
}
|
||||
}
|
||||
82
Robust.Generators.UnitTesting/DataClassTests.cs
Normal file
82
Robust.Generators.UnitTesting/DataClassTests.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Robust.Generators.UnitTesting
|
||||
{
|
||||
public class DataClassTests : AnalyzerTest
|
||||
{
|
||||
[Test]
|
||||
public void DCTest()
|
||||
{
|
||||
const string source = @"
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Prototypes;
|
||||
//using Robust.Shared.Serialization;
|
||||
using DrawDepthTag = Robust.Shared.GameObjects.DrawDepth;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Test{
|
||||
[DataClass]
|
||||
public class TestClass{
|
||||
[DataFieldWithConstant(""drawdepth"", typeof(DrawDepthTag))]
|
||||
private int _drawDepth = DrawDepthTag.Default;
|
||||
[DataField(""myList"")]
|
||||
public List<TestClass> testList;
|
||||
[DataField(""myList"")]
|
||||
public string abc = ""testing"";
|
||||
[DataField(""drawdepth"", constType: typeof(TestClass))]
|
||||
public int test;
|
||||
}
|
||||
}
|
||||
";
|
||||
var comp = CreateCompilation(source);
|
||||
|
||||
//Assert.IsEmpty(comp.GetDiagnostics());
|
||||
|
||||
var (newcomp, generatorDiags) = RunGenerators(comp, new DataClassGenerator());
|
||||
|
||||
Assert.IsEmpty(generatorDiags);
|
||||
|
||||
var type = newcomp.GetTypeByMetadataName("Test.TestClass_AUTODATA");
|
||||
Assert.NotNull(type);
|
||||
|
||||
var memberNames = type.MemberNames.ToArray();
|
||||
|
||||
// 3 properties
|
||||
Assert.That(memberNames, Has.Length.EqualTo(3));
|
||||
Assert.That(memberNames, Contains.Item("testList"));
|
||||
Assert.That(memberNames, Contains.Item("abc"));
|
||||
Assert.That(memberNames, Contains.Item("test"));
|
||||
|
||||
var members = type.GetMembers();
|
||||
|
||||
// 3 properties + constructor
|
||||
Assert.That(members, Has.Length.EqualTo(4));
|
||||
|
||||
var memberDictionary = members.ToDictionary(m => m.Name, m => m);
|
||||
var yamlFieldNamespace = typeof(DataFieldAttribute).FullName;
|
||||
|
||||
Assert.NotNull(yamlFieldNamespace);
|
||||
|
||||
var yamlFieldAttribute = comp.GetTypeByMetadataName(yamlFieldNamespace);
|
||||
|
||||
var testListYamlAttribute = memberDictionary["testList"].GetAttribute(yamlFieldAttribute);
|
||||
Assert.NotNull(testListYamlAttribute);
|
||||
Assert.That(testListYamlAttribute.ConstructorArguments[0].Value, Is.EqualTo("myList"));
|
||||
|
||||
var abcYamlAttribute = memberDictionary["abc"].GetAttribute(yamlFieldAttribute);
|
||||
Assert.NotNull(abcYamlAttribute);
|
||||
Assert.That(abcYamlAttribute.ConstructorArguments[0].Value, Is.EqualTo("myList"));
|
||||
|
||||
var testYamlAttribute = memberDictionary["test"].GetAttribute(yamlFieldAttribute);
|
||||
Assert.NotNull(testYamlAttribute);
|
||||
Assert.That(testYamlAttribute.ConstructorArguments[0].Value, Is.EqualTo("drawdepth"));
|
||||
Assert.NotNull(testYamlAttribute.ConstructorArguments[3].Value);
|
||||
Assert.That(testYamlAttribute.ConstructorArguments[3].Value.ToString(), Is.EqualTo("Test.TestClass"));
|
||||
|
||||
//TODO Check for dataclass & if its correct
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Robust.Generators\Robust.Generators.csproj" />
|
||||
<ProjectReference Include="..\Robust.Shared\Robust.Shared.csproj" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
|
||||
<PackageReference Include="NUnit" Version="3.12.0" />
|
||||
<PackageReference Include="NUnit.ConsoleRunner" Version="3.11.1" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="0.6.0" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\MSBuild\Robust.Engine.targets" />
|
||||
|
||||
</Project>
|
||||
11
Robust.Generators/Robust.Generators.csproj
Normal file
11
Robust.Generators/Robust.Generators.csproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,23 +1,10 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using Prometheus;
|
||||
using Robust.Server.Console;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Server.ViewVariables;
|
||||
using Robust.Shared.Asynchronous;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.Exceptions;
|
||||
using Robust.Server.Scripting;
|
||||
using Robust.Server.ServerStatus;
|
||||
using Robust.Shared;
|
||||
using Robust.Server.DataMetrics;
|
||||
using Robust.Server.Debugging;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -25,12 +12,26 @@ using Robust.Server.GameStates;
|
||||
using Robust.Server.Log;
|
||||
using Robust.Server.Placement;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Server.Scripting;
|
||||
using Robust.Server.ServerStatus;
|
||||
using Robust.Server.Utility;
|
||||
using Robust.Server.ViewVariables;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Asynchronous;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.Exceptions;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using Serilog.Debugging;
|
||||
using Serilog.Sinks.Loki;
|
||||
using Stopwatch = Robust.Shared.Timing.Stopwatch;
|
||||
@@ -298,6 +299,8 @@ namespace Robust.Server
|
||||
|
||||
_entities.Initialize();
|
||||
|
||||
IoCManager.Resolve<ISerializationManager>().Initialize();
|
||||
|
||||
// because of 'reasons' this has to be called after the last assembly is loaded
|
||||
// otherwise the prototypes will be cleared
|
||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Network.Messages;
|
||||
@@ -14,7 +14,7 @@ namespace Robust.Server.Debugging
|
||||
public void Initialize()
|
||||
{
|
||||
_net.RegisterNetMessage<MsgRay>(MsgRay.NAME);
|
||||
_physics.DebugDrawRay += data => PhysicsOnDebugDrawRay(data);
|
||||
// TODO _physics.DebugDrawRay += data => PhysicsOnDebugDrawRay(data);
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Server.GameObjects
|
||||
{
|
||||
public class EyeComponent : SharedEyeComponent
|
||||
{
|
||||
private bool _drawFov;
|
||||
private Vector2 _zoom;
|
||||
[DataField("drawFov")]
|
||||
private bool _drawFov = true;
|
||||
[DataField("zoom")]
|
||||
private Vector2 _zoom = Vector2.One/2f;
|
||||
private Vector2 _offset;
|
||||
private Angle _rotation;
|
||||
|
||||
@@ -68,13 +73,5 @@ namespace Robust.Server.GameObjects
|
||||
{
|
||||
return new EyeComponentState(DrawFov, Zoom, Offset, Rotation);
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _zoom, "zoom", Vector2.One/2f);
|
||||
serializer.DataFieldCached(ref _drawFov, "drawFov", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Server.GameObjects
|
||||
@@ -10,10 +12,14 @@ namespace Robust.Server.GameObjects
|
||||
[ComponentReference(typeof(IPointLightComponent))]
|
||||
public class PointLightComponent : Component, IPointLightComponent
|
||||
{
|
||||
private Color _color;
|
||||
private bool _enabled;
|
||||
private float _radius;
|
||||
private Vector2 _offset;
|
||||
[DataField("color")]
|
||||
private Color _color = new(200, 200, 200);
|
||||
[DataField("enabled")]
|
||||
private bool _enabled = true;
|
||||
[DataField("radius")]
|
||||
private float _radius = 10;
|
||||
[DataField("offset")]
|
||||
private Vector2 _offset = Vector2.Zero;
|
||||
|
||||
public override string Name => "PointLight";
|
||||
public override uint? NetID => NetIDs.POINT_LIGHT;
|
||||
@@ -73,17 +79,6 @@ namespace Robust.Server.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _enabled, "enabled", true);
|
||||
serializer.DataField(ref _color, "color", new Color(200, 200, 200));
|
||||
serializer.DataField(ref _radius, "radius", 10);
|
||||
serializer.DataField(ref _offset, "offset", Vector2.Zero);
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
return new PointLightComponentState(Enabled, Color, Radius, Offset);
|
||||
|
||||
@@ -4,27 +4,49 @@ using Robust.Shared.GameObjects;
|
||||
using DrawDepthTag = Robust.Shared.GameObjects.DrawDepth;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Server.GameObjects
|
||||
{
|
||||
public class SpriteComponent : SharedSpriteComponent, ISpriteRenderableComponent
|
||||
public class SpriteComponent : SharedSpriteComponent, ISpriteRenderableComponent, ISerializationHooks
|
||||
{
|
||||
const string LayerSerializationCache = "spritelayersrv";
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("layers", priority: 2, readOnly: true)]
|
||||
private List<PrototypeLayerData> Layers = new();
|
||||
|
||||
private bool _visible;
|
||||
[DataField("visible")]
|
||||
private bool _visible = true;
|
||||
|
||||
[DataFieldWithConstant("drawdepth", typeof(DrawDepthTag))]
|
||||
private int _drawDepth = DrawDepthTag.Default;
|
||||
private Vector2 _scale;
|
||||
private Vector2 _offset;
|
||||
private Color _color;
|
||||
private bool _directional;
|
||||
|
||||
[DataField("scale")]
|
||||
private Vector2 _scale = Vector2.One;
|
||||
|
||||
[DataField("offset")]
|
||||
private Vector2 _offset = Vector2.Zero;
|
||||
|
||||
[DataField("color")]
|
||||
private Color _color = Color.White;
|
||||
|
||||
[DataField("directional")]
|
||||
private bool _directional = true;
|
||||
|
||||
[DataField("sprite")]
|
||||
private string? _baseRSIPath;
|
||||
private Angle _rotation;
|
||||
|
||||
[DataField("rotation")]
|
||||
private Angle _rotation = Angle.Zero;
|
||||
|
||||
[DataField("state")] private string? state;
|
||||
[DataField("texture")] private string? texture;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int DrawDepth
|
||||
@@ -129,6 +151,31 @@ namespace Robust.Server.GameObjects
|
||||
[ViewVariables]
|
||||
public int LayerCount => Layers.Count;
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
if (Layers.Count == 0)
|
||||
{
|
||||
if (state != null || texture != null)
|
||||
{
|
||||
var layerZeroData = SharedSpriteComponent.PrototypeLayerData.New();
|
||||
if (!string.IsNullOrWhiteSpace(state))
|
||||
{
|
||||
layerZeroData.State = state;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(texture))
|
||||
{
|
||||
layerZeroData.TexturePath = texture;
|
||||
}
|
||||
|
||||
Layers.Insert(0, layerZeroData);
|
||||
|
||||
state = null;
|
||||
texture = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int AddLayerWithSprite(SpriteSpecifier specifier)
|
||||
{
|
||||
var layer = PrototypeLayerData.New();
|
||||
@@ -272,7 +319,7 @@ namespace Robust.Server.GameObjects
|
||||
{
|
||||
if (Layers.Count <= layer)
|
||||
{
|
||||
Logger.ErrorS("go.comp.sprite", "Layer with index '{0}' does not exist, cannot set set! Trace:\n{1}",
|
||||
Logger.ErrorS("go.comp.sprite", "Layer with index '{0}' does not exist, cannot set state! Trace:\n{1}",
|
||||
layer, Environment.StackTrace);
|
||||
return;
|
||||
}
|
||||
@@ -389,59 +436,6 @@ namespace Robust.Server.GameObjects
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataFieldCached(ref _visible, "visible", true);
|
||||
serializer.DataFieldCached(ref _drawDepth, "drawdepth", DrawDepthTag.Default, WithFormat.Constants<DrawDepthTag>());
|
||||
serializer.DataFieldCached(ref _offset, "offset", Vector2.Zero);
|
||||
serializer.DataFieldCached(ref _scale, "scale", Vector2.One);
|
||||
serializer.DataFieldCached(ref _color, "color", Color.White);
|
||||
serializer.DataFieldCached(ref _directional, "directional", true);
|
||||
serializer.DataFieldCached(ref _baseRSIPath, "sprite", null);
|
||||
serializer.DataFieldCached(ref _rotation, "rotation", Angle.Zero);
|
||||
|
||||
// TODO: Writing?
|
||||
if (!serializer.Reading)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (serializer.TryGetCacheData<List<PrototypeLayerData>>(LayerSerializationCache, out var layers))
|
||||
{
|
||||
Layers = layers.ShallowClone();
|
||||
return;
|
||||
}
|
||||
|
||||
var layerData =
|
||||
serializer.ReadDataField<List<PrototypeLayerData>>("layers", new List<PrototypeLayerData>());
|
||||
|
||||
if(layerData.Count == 0){
|
||||
var baseState = serializer.ReadDataField<string?>("state", null);
|
||||
var texturePath = serializer.ReadDataField<string?>("texture", null);
|
||||
|
||||
if (baseState != null || texturePath != null)
|
||||
{
|
||||
var layerZeroData = PrototypeLayerData.New();
|
||||
if (!string.IsNullOrWhiteSpace(baseState))
|
||||
{
|
||||
layerZeroData.State = baseState;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(texturePath))
|
||||
{
|
||||
layerZeroData.TexturePath = texturePath;
|
||||
}
|
||||
|
||||
layerData.Insert(0, layerZeroData);
|
||||
}
|
||||
}
|
||||
|
||||
serializer.SetCacheData(LayerSerializationCache, layerData.ShallowClone());
|
||||
Layers = layerData;
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
return new SpriteComponentState(Visible, DrawDepth, Scale, Rotation, Offset, Color,
|
||||
|
||||
@@ -10,6 +10,7 @@ using Robust.Shared.Log;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Robust.Server.GameObjects
|
||||
{
|
||||
@@ -19,27 +20,24 @@ namespace Robust.Server.GameObjects
|
||||
/// </summary>
|
||||
/// <seealso cref="BoundUserInterface"/>
|
||||
[PublicAPI]
|
||||
public sealed class ServerUserInterfaceComponent : SharedUserInterfaceComponent
|
||||
public sealed class ServerUserInterfaceComponent : SharedUserInterfaceComponent, ISerializationHooks
|
||||
{
|
||||
private readonly Dictionary<object, BoundUserInterface> _interfaces =
|
||||
new();
|
||||
|
||||
[DataField("interfaces", readOnly: true)]
|
||||
private List<PrototypeData> _interfaceData = new();
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration of all the interfaces this component provides.
|
||||
/// </summary>
|
||||
public IEnumerable<BoundUserInterface> Interfaces => _interfaces.Values;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
_interfaces.Clear();
|
||||
|
||||
if (!serializer.Reading)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var data = serializer.ReadDataFieldCached("interfaces", new List<PrototypeData>());
|
||||
foreach (var prototypeData in data)
|
||||
foreach (var prototypeData in _interfaceData)
|
||||
{
|
||||
_interfaces[prototypeData.UiKey] = new BoundUserInterface(prototypeData.UiKey, this);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Server.GameObjects
|
||||
@@ -7,6 +9,7 @@ namespace Robust.Server.GameObjects
|
||||
[RegisterComponent]
|
||||
public class VisibilityComponent : Component
|
||||
{
|
||||
[DataField("layer")]
|
||||
private int _layer = 1;
|
||||
public override string Name => "Visibility";
|
||||
|
||||
@@ -20,12 +23,5 @@ namespace Robust.Server.GameObjects
|
||||
get => _layer;
|
||||
set => _layer = value;
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _layer, "layer", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,37 @@
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
|
||||
namespace Robust.Server.GameObjects
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class PhysicsSystem : SharedPhysicsSystem
|
||||
{
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_mapManager.OnGridCreated += HandleGridCreated;
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
_mapManager.OnGridCreated -= HandleGridCreated;
|
||||
}
|
||||
|
||||
private void HandleGridCreated(GridId gridId)
|
||||
{
|
||||
if (!EntityManager.TryGetEntity(_mapManager.GetGrid(gridId).GridEntityId, out var gridEntity)) return;
|
||||
var grid = _mapManager.GetGrid(gridId);
|
||||
var collideComp = gridEntity.AddComponent<PhysicsComponent>();
|
||||
collideComp.CanCollide = true;
|
||||
collideComp.AddFixture(new Fixture(collideComp, new PhysShapeGrid(grid)) {CollisionMask = MapGridHelpers.CollisionGroup, CollisionLayer = MapGridHelpers.CollisionGroup});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
|
||||
namespace Robust.Server.GameObjects
|
||||
{
|
||||
@@ -198,8 +199,8 @@ namespace Robust.Server.GameObjects
|
||||
private Box2 GetEntityBox(IEntity entity)
|
||||
{
|
||||
// Need to clip the aabb as anything with an edge intersecting another tile might be picked up, such as walls.
|
||||
if (entity.TryGetComponent(out IPhysicsComponent? physics))
|
||||
return new Box2(physics.WorldAABB.BottomLeft + 0.01f, physics.WorldAABB.TopRight - 0.01f);
|
||||
if (entity.TryGetComponent(out IPhysBody? physics))
|
||||
return new Box2(physics.GetWorldAABB().BottomLeft + 0.01f, physics.GetWorldAABB().TopRight - 0.01f);
|
||||
|
||||
// Don't want to accidentally get neighboring tiles unless we're near an edge
|
||||
return Box2.CenteredAround(entity.Transform.Coordinates.ToMapPos(EntityManager), Vector2.One / 2);
|
||||
@@ -335,7 +336,7 @@ namespace Robust.Server.GameObjects
|
||||
return;
|
||||
}
|
||||
|
||||
var bounds = GetEntityBox(moveEvent.Sender);
|
||||
var bounds = moveEvent.WorldAABB ?? GetEntityBox(moveEvent.Sender);
|
||||
var newNodes = GetOrCreateNodes(moveEvent.NewPosition, bounds);
|
||||
|
||||
if (oldNodes.Count == newNodes.Count && oldNodes.SetEquals(newNodes))
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
using Robust.Shared.Physics;
|
||||
|
||||
namespace Robust.Server.GameObjects
|
||||
{
|
||||
public class ServerComponentFactory : ComponentFactory
|
||||
@@ -28,7 +30,13 @@ namespace Robust.Server.GameObjects
|
||||
RegisterReference<BasicActorComponent, IActorComponent>();
|
||||
|
||||
Register<PhysicsComponent>();
|
||||
RegisterReference<PhysicsComponent, IPhysicsComponent>();
|
||||
RegisterReference<PhysicsComponent, IPhysBody>();
|
||||
|
||||
Register<CollisionWakeComponent>();
|
||||
|
||||
Register<ContainerManagerComponent>();
|
||||
RegisterReference<ContainerManagerComponent, IContainerManager>();
|
||||
|
||||
Register<OccluderComponent>();
|
||||
|
||||
RegisterIgnore("Input");
|
||||
@@ -50,7 +58,6 @@ namespace Robust.Server.GameObjects
|
||||
|
||||
#if DEBUG
|
||||
Register<DebugExceptionOnAddComponent>();
|
||||
Register<DebugExceptionExposeDataComponent>();
|
||||
Register<DebugExceptionInitializeComponent>();
|
||||
Register<DebugExceptionStartupComponent>();
|
||||
#endif
|
||||
|
||||
@@ -10,6 +10,7 @@ using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
@@ -368,7 +369,7 @@ namespace Robust.Server.GameObjects
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entity.TryGetComponent(out IPhysicsComponent? body))
|
||||
if (entity.TryGetComponent(out IPhysBody? body))
|
||||
{
|
||||
if (body.LinearVelocity.EqualsApprox(Vector2.Zero, MinimumMotionForMovers))
|
||||
{
|
||||
@@ -535,7 +536,7 @@ namespace Robust.Server.GameObjects
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!entity.TryGetComponent(out IPhysicsComponent? body))
|
||||
if (!entity.TryGetComponent(out IPhysBody? body))
|
||||
{
|
||||
// can't be a mover w/o physics
|
||||
continue;
|
||||
@@ -721,10 +722,10 @@ namespace Robust.Server.GameObjects
|
||||
_deletionHistory.RemoveAll(hist => hist.tick <= toTick);
|
||||
}
|
||||
|
||||
public override bool UpdateEntityTree(IEntity entity)
|
||||
public override bool UpdateEntityTree(IEntity entity, Box2? worldAABB = null)
|
||||
{
|
||||
var currentTick = CurrentTick;
|
||||
var updated = base.UpdateEntityTree(entity);
|
||||
var updated = base.UpdateEntityTree(entity, worldAABB);
|
||||
|
||||
if (entity.Deleted
|
||||
|| !entity.Initialized
|
||||
@@ -736,6 +737,7 @@ namespace Robust.Server.GameObjects
|
||||
DebugTools.Assert(entity.Transform.Initialized);
|
||||
|
||||
// note: updated can be false even if something moved a bit
|
||||
worldAABB ??= GetWorldAabbFromEntity(entity);
|
||||
|
||||
foreach (var (player, lastSeen) in _playerLastSeen)
|
||||
{
|
||||
@@ -782,14 +784,14 @@ namespace Robust.Server.GameObjects
|
||||
// saw it previously
|
||||
|
||||
// player can't see it now
|
||||
if (!viewbox.Intersects(GetWorldAabbFromEntity(entity)))
|
||||
if (!viewbox.Intersects(worldAABB.Value))
|
||||
{
|
||||
var addToMovers = false;
|
||||
if (entity.Transform.LastModifiedTick >= currentTick)
|
||||
{
|
||||
addToMovers = true;
|
||||
}
|
||||
else if (entity.TryGetComponent(out IPhysicsComponent? physics)
|
||||
else if (entity.TryGetComponent(out IPhysBody? physics)
|
||||
&& physics.LastModifiedTick >= currentTick)
|
||||
{
|
||||
addToMovers = true;
|
||||
|
||||
@@ -1,21 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.GameObjects;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Manager.Result;
|
||||
using Robust.Shared.Serialization.Markdown;
|
||||
using Robust.Shared.Serialization.Markdown.Validation;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Interfaces;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace Robust.Server.Maps
|
||||
{
|
||||
@@ -223,7 +228,10 @@ namespace Robust.Server.Maps
|
||||
/// <summary>
|
||||
/// Handles the primary bulk of state during the map serialization process.
|
||||
/// </summary>
|
||||
private class MapContext : YamlObjectSerializer.Context, IEntityLoadContext
|
||||
private class MapContext : ISerializationContext, IEntityLoadContext,
|
||||
ITypeSerializer<GridId, ValueDataNode>,
|
||||
ITypeSerializer<EntityUid, ValueDataNode>,
|
||||
ITypeReaderWriter<IEntity, ValueDataNode>
|
||||
{
|
||||
private readonly IMapManagerInternal _mapManager;
|
||||
private readonly ITileDefinitionManager _tileDefinitionManager;
|
||||
@@ -255,6 +263,11 @@ namespace Robust.Server.Maps
|
||||
|
||||
private Dictionary<ushort, string>? _tileMap;
|
||||
|
||||
public Dictionary<(Type, Type), object> TypeReaders { get; }
|
||||
public Dictionary<Type, object> TypeWriters { get; }
|
||||
public Dictionary<Type, object> TypeCopiers => TypeWriters;
|
||||
public Dictionary<(Type, Type), object> TypeValidators => TypeReaders;
|
||||
|
||||
public bool MapIsPostInit { get; private set; }
|
||||
|
||||
public MapContext(IMapManagerInternal maps, ITileDefinitionManager tileDefs,
|
||||
@@ -269,6 +282,18 @@ namespace Robust.Server.Maps
|
||||
_prototypeManager = prototypeManager;
|
||||
|
||||
RootNode = new YamlMappingNode();
|
||||
TypeWriters = new Dictionary<Type, object>()
|
||||
{
|
||||
{typeof(IEntity), this},
|
||||
{typeof(GridId), this},
|
||||
{typeof(EntityUid), this}
|
||||
};
|
||||
TypeReaders = new Dictionary<(Type, Type), object>()
|
||||
{
|
||||
{(typeof(IEntity), typeof(ValueDataNode)), this},
|
||||
{(typeof(GridId), typeof(ValueDataNode)), this},
|
||||
{(typeof(EntityUid), typeof(ValueDataNode)), this}
|
||||
};
|
||||
}
|
||||
|
||||
public MapContext(IMapManagerInternal maps, ITileDefinitionManager tileDefs,
|
||||
@@ -286,6 +311,18 @@ namespace Robust.Server.Maps
|
||||
RootNode = node;
|
||||
TargetMap = targetMapId;
|
||||
_prototypeManager = prototypeManager;
|
||||
TypeWriters = new Dictionary<Type, object>()
|
||||
{
|
||||
{typeof(IEntity), this},
|
||||
{typeof(GridId), this},
|
||||
{typeof(EntityUid), this}
|
||||
};
|
||||
TypeReaders = new Dictionary<(Type, Type), object>()
|
||||
{
|
||||
{(typeof(IEntity), typeof(ValueDataNode)), this},
|
||||
{(typeof(GridId), typeof(ValueDataNode)), this},
|
||||
{(typeof(EntityUid), typeof(ValueDataNode)), this}
|
||||
};
|
||||
}
|
||||
|
||||
// Deserialization
|
||||
@@ -530,7 +567,10 @@ namespace Robust.Server.Maps
|
||||
{
|
||||
foreach (var compData in componentList)
|
||||
{
|
||||
CurrentReadingEntityComponents[compData["type"].AsString()] = (YamlMappingNode) compData;
|
||||
var copy = new YamlMappingNode(((YamlMappingNode)compData).AsEnumerable());
|
||||
copy.Children.Remove(new YamlScalarNode("type"));
|
||||
//TODO Paul: maybe replace mapping with datanode
|
||||
CurrentReadingEntityComponents[compData["type"].AsString()] = copy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -687,9 +727,11 @@ namespace Robust.Server.Maps
|
||||
|
||||
private void WriteEntitySection()
|
||||
{
|
||||
var serializationManager = IoCManager.Resolve<ISerializationManager>();
|
||||
var entities = new YamlSequenceNode();
|
||||
RootNode.Add("entities", entities);
|
||||
|
||||
var prototypeCompCache = new Dictionary<string, Dictionary<string, MappingDataNode>>();
|
||||
foreach (var entity in Entities.OrderBy(e => EntityUidMap[e.Uid]))
|
||||
{
|
||||
CurrentWritingEntity = entity;
|
||||
@@ -701,6 +743,14 @@ namespace Robust.Server.Maps
|
||||
if (entity.Prototype != null)
|
||||
{
|
||||
mapping.Add("type", entity.Prototype.ID);
|
||||
if (!prototypeCompCache.ContainsKey(entity.Prototype.ID))
|
||||
{
|
||||
prototypeCompCache[entity.Prototype.ID] = new Dictionary<string, MappingDataNode>();
|
||||
foreach (var (compType, comp) in entity.Prototype.Components)
|
||||
{
|
||||
prototypeCompCache[entity.Prototype.ID].Add(compType, serializationManager.WriteValueAs<MappingDataNode>(comp.GetType(), comp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var components = new YamlSequenceNode();
|
||||
@@ -710,18 +760,21 @@ namespace Robust.Server.Maps
|
||||
if (component is MapSaveIdComponent)
|
||||
continue;
|
||||
|
||||
var compMapping = new YamlMappingNode();
|
||||
CurrentWritingComponent = component.Name;
|
||||
var compSerializer = YamlObjectSerializer.NewWriter(compMapping, this);
|
||||
var compMapping = serializationManager.WriteValueAs<MappingDataNode>(component.GetType(), component, context: this);
|
||||
|
||||
component.ExposeData(compSerializer);
|
||||
if (entity.Prototype != null && prototypeCompCache[entity.Prototype.ID].TryGetValue(component.Name, out var protMapping))
|
||||
{
|
||||
compMapping = compMapping.Except(protMapping);
|
||||
if(compMapping == null) continue;
|
||||
}
|
||||
|
||||
// Don't need to write it if nothing was written!
|
||||
if (compMapping.Children.Count != 0)
|
||||
{
|
||||
compMapping.AddNode("type", new ValueDataNode(component.Name));
|
||||
// Something actually got written!
|
||||
compMapping.Add("type", component.Name);
|
||||
components.Add(compMapping);
|
||||
components.Add(compMapping.ToYamlNode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -734,140 +787,32 @@ namespace Robust.Server.Maps
|
||||
}
|
||||
}
|
||||
|
||||
public override bool TryNodeToType(YamlNode node, Type type, [NotNullWhen(true)] out object? obj)
|
||||
{
|
||||
if (type == typeof(GridId))
|
||||
{
|
||||
if (node.AsString() == "null")
|
||||
{
|
||||
obj = GridId.Invalid;
|
||||
return true;
|
||||
}
|
||||
|
||||
var val = node.AsInt();
|
||||
if (val >= Grids.Count)
|
||||
{
|
||||
Logger.ErrorS("map", "Error in map file: found local grid ID '{0}' which does not exist.", val);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = Grids[val].Index;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == typeof(EntityUid))
|
||||
{
|
||||
if (node.AsString() == "null")
|
||||
{
|
||||
obj = EntityUid.Invalid;
|
||||
return true;
|
||||
}
|
||||
|
||||
var val = node.AsInt();
|
||||
if (val >= Entities.Count)
|
||||
{
|
||||
Logger.ErrorS("map", "Error in map file: found local entity UID '{0}' which does not exist.",
|
||||
val);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = UidEntityMap[val];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof(IEntity).IsAssignableFrom(type))
|
||||
{
|
||||
var val = node.AsInt();
|
||||
if (val >= Entities.Count)
|
||||
{
|
||||
Logger.ErrorS("map", "Error in map file: found local entity UID '{0}' which does not exist.",
|
||||
val);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = Entities[val];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
obj = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool TryTypeToNode(object obj, [NotNullWhen(true)] out YamlNode? node)
|
||||
{
|
||||
switch (obj)
|
||||
{
|
||||
case GridId gridId:
|
||||
if (!GridIDMap.TryGetValue(gridId, out var gridMapped))
|
||||
{
|
||||
Logger.WarningS("map", "Cannot write grid ID '{0}', falling back to nullspace.", gridId);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
node = new YamlScalarNode(gridMapped.ToString(CultureInfo.InvariantCulture));
|
||||
return true;
|
||||
}
|
||||
|
||||
case EntityUid entityUid:
|
||||
if (!EntityUidMap.TryGetValue(entityUid, out var entityUidMapped))
|
||||
{
|
||||
// Terrible hack to mute this warning on the grids themselves when serializing blueprints.
|
||||
if (!IsBlueprintMode || !CurrentWritingEntity!.HasComponent<MapGridComponent>() ||
|
||||
CurrentWritingComponent != "Transform")
|
||||
{
|
||||
Logger.WarningS("map", "Cannot write entity UID '{0}'.", entityUid);
|
||||
}
|
||||
|
||||
node = new YamlScalarNode("null");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
node = new YamlScalarNode(entityUidMapped.ToString(CultureInfo.InvariantCulture));
|
||||
return true;
|
||||
}
|
||||
|
||||
case IEntity entity:
|
||||
if (!EntityUidMap.TryGetValue(entity.Uid, out var entityMapped))
|
||||
{
|
||||
Logger.WarningS("map", "Cannot write entity UID '{0}'.", entity.Uid);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
node = new YamlScalarNode(entityMapped.ToString(CultureInfo.InvariantCulture));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
node = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create custom object serializers that will correctly allow data to be overriden by the map file.
|
||||
ObjectSerializer IEntityLoadContext.GetComponentSerializer(string componentName, YamlMappingNode? protoData)
|
||||
IComponent IEntityLoadContext.GetComponentData(string componentName,
|
||||
IComponent? protoData)
|
||||
{
|
||||
if (CurrentReadingEntityComponents == null)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
var list = new List<YamlMappingNode>();
|
||||
var serializationManager = IoCManager.Resolve<ISerializationManager>();
|
||||
var factory = IoCManager.Resolve<IComponentFactory>();
|
||||
|
||||
IComponent data = protoData != null
|
||||
? serializationManager.CreateCopy(protoData, this)!
|
||||
: (IComponent) Activator.CreateInstance(factory.GetRegistration(componentName).Type)!;
|
||||
|
||||
if (CurrentReadingEntityComponents.TryGetValue(componentName, out var mapping))
|
||||
{
|
||||
list.Add(mapping);
|
||||
var mapData = (IDeserializedDefinition) serializationManager.Read(
|
||||
factory.GetRegistration(componentName).Type,
|
||||
mapping.ToDataNode(), this);
|
||||
var newData = serializationManager.PopulateDataDefinition(data, mapData);
|
||||
data = (IComponent) newData.RawValue!;
|
||||
}
|
||||
|
||||
if (protoData != null)
|
||||
{
|
||||
list.Add(protoData);
|
||||
}
|
||||
|
||||
return YamlObjectSerializer.NewReader(list, this);
|
||||
return data;
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetExtraComponentTypes()
|
||||
@@ -875,34 +820,6 @@ namespace Robust.Server.Maps
|
||||
return CurrentReadingEntityComponents!.Keys;
|
||||
}
|
||||
|
||||
public override bool IsValueDefault<T>(string field, T value, WithFormat<T> format)
|
||||
{
|
||||
if (CurrentWritingEntity!.Prototype == null)
|
||||
{
|
||||
// No prototype, can't be default.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CurrentWritingEntity.Prototype.Components.TryGetValue(CurrentWritingComponent!, out var compData))
|
||||
{
|
||||
// This component was added mid-game.
|
||||
return false;
|
||||
}
|
||||
|
||||
var testSer = YamlObjectSerializer.NewReader(compData);
|
||||
if (testSer.TryReadDataFieldCached(field, format, out var prototypeVal))
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return prototypeVal == null;
|
||||
}
|
||||
|
||||
return YamlObjectSerializer.IsSerializedEqual(value, prototypeVal);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsMapSavable(IEntity entity)
|
||||
{
|
||||
if (entity.Prototype?.MapSavable == false || !GridIDMap.ContainsKey(entity.Transform.GridID))
|
||||
@@ -925,6 +842,165 @@ namespace Robust.Server.Maps
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public DeserializationResult Read(ISerializationManager serializationManager, ValueDataNode node,
|
||||
IDependencyCollection dependencies,
|
||||
bool skipHook,
|
||||
ISerializationContext? context = null)
|
||||
{
|
||||
if (node.Value == "null") return new DeserializedValue<GridId>(GridId.Invalid);
|
||||
|
||||
var val = int.Parse(node.Value);
|
||||
if (val >= Grids.Count)
|
||||
{
|
||||
Logger.ErrorS("map", "Error in map file: found local grid ID '{0}' which does not exist.", val);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new DeserializedValue<GridId>(Grids[val].Index);
|
||||
}
|
||||
|
||||
return new DeserializedValue<GridId>(GridId.Invalid);
|
||||
}
|
||||
|
||||
ValidationNode ITypeValidator<IEntity, ValueDataNode>.Validate(ISerializationManager serializationManager,
|
||||
ValueDataNode node, IDependencyCollection dependencies, ISerializationContext? context)
|
||||
{
|
||||
if (!int.TryParse(node.Value, out var val) || !UidEntityMap.ContainsKey(val))
|
||||
{
|
||||
return new ErrorNode(node, "Invalid EntityUid", true);
|
||||
}
|
||||
|
||||
return new ValidatedValueNode(node);
|
||||
}
|
||||
|
||||
ValidationNode ITypeValidator<EntityUid, ValueDataNode>.Validate(ISerializationManager serializationManager,
|
||||
ValueDataNode node, IDependencyCollection dependencies, ISerializationContext? context)
|
||||
{
|
||||
if (node.Value == "null")
|
||||
{
|
||||
return new ValidatedValueNode(node);
|
||||
}
|
||||
|
||||
if (!int.TryParse(node.Value, out var val) || !UidEntityMap.ContainsKey(val))
|
||||
{
|
||||
return new ErrorNode(node, "Invalid EntityUid", true);
|
||||
}
|
||||
|
||||
return new ValidatedValueNode(node);
|
||||
}
|
||||
|
||||
ValidationNode ITypeValidator<GridId, ValueDataNode>.Validate(ISerializationManager serializationManager,
|
||||
ValueDataNode node, IDependencyCollection dependencies, ISerializationContext? context)
|
||||
{
|
||||
if (node.Value == "null") return new ValidatedValueNode(node);
|
||||
|
||||
if (!int.TryParse(node.Value, out var val) || val >= Grids.Count)
|
||||
{
|
||||
return new ErrorNode(node, "Invalid GridId", true);
|
||||
}
|
||||
|
||||
return new ValidatedValueNode(node);
|
||||
}
|
||||
|
||||
public DataNode Write(ISerializationManager serializationManager, IEntity value, bool alwaysWrite = false,
|
||||
ISerializationContext? context = null)
|
||||
{
|
||||
return Write(serializationManager, value.Uid, alwaysWrite, context);
|
||||
}
|
||||
|
||||
public DataNode Write(ISerializationManager serializationManager, EntityUid value, bool alwaysWrite = false,
|
||||
ISerializationContext? context = null)
|
||||
{
|
||||
if (!EntityUidMap.TryGetValue(value, out var entityUidMapped))
|
||||
{
|
||||
// Terrible hack to mute this warning on the grids themselves when serializing blueprints.
|
||||
if (!IsBlueprintMode || !CurrentWritingEntity!.HasComponent<MapGridComponent>() ||
|
||||
CurrentWritingComponent != "Transform")
|
||||
{
|
||||
Logger.WarningS("map", "Cannot write entity UID '{0}'.", value);
|
||||
}
|
||||
|
||||
return new ValueDataNode("null");
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ValueDataNode(entityUidMapped.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
}
|
||||
|
||||
public DataNode Write(ISerializationManager serializationManager, GridId value, bool alwaysWrite = false,
|
||||
ISerializationContext? context = null)
|
||||
{
|
||||
if (!GridIDMap.TryGetValue(value, out var gridMapped))
|
||||
{
|
||||
Logger.WarningS("map", "Cannot write grid ID '{0}', falling back to nullspace.", gridMapped);
|
||||
return new ValueDataNode("");
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ValueDataNode(gridMapped.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
}
|
||||
|
||||
DeserializationResult ITypeReader<EntityUid, ValueDataNode>.Read(ISerializationManager serializationManager,
|
||||
ValueDataNode node,
|
||||
IDependencyCollection dependencies,
|
||||
bool skipHook,
|
||||
ISerializationContext? context)
|
||||
{
|
||||
if (node.Value == "null")
|
||||
{
|
||||
return new DeserializedValue<EntityUid>(EntityUid.Invalid);
|
||||
}
|
||||
|
||||
var val = int.Parse(node.Value);
|
||||
if (val >= Entities.Count)
|
||||
{
|
||||
Logger.ErrorS("map", "Error in map file: found local entity UID '{0}' which does not exist.", val);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new DeserializedValue<EntityUid>(UidEntityMap[val]);
|
||||
}
|
||||
|
||||
return new DeserializedValue<EntityUid>(EntityUid.Invalid);
|
||||
}
|
||||
|
||||
DeserializationResult ITypeReader<IEntity, ValueDataNode>.Read(ISerializationManager serializationManager,
|
||||
ValueDataNode node,
|
||||
IDependencyCollection dependencies,
|
||||
bool skipHook,
|
||||
ISerializationContext? context)
|
||||
{
|
||||
var val = int.Parse(node.Value);
|
||||
|
||||
if (val >= Entities.Count || !UidEntityMap.ContainsKey(val) || !Entities.TryFirstOrDefault(e => e.Uid == UidEntityMap[val], out var entity))
|
||||
{
|
||||
Logger.ErrorS("map", "Error in map file: found local entity UID '{0}' which does not exist.", val);
|
||||
return null!;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new DeserializedValue<IEntity>(entity);
|
||||
}
|
||||
}
|
||||
|
||||
[MustUseReturnValue]
|
||||
public GridId Copy(ISerializationManager serializationManager, GridId source, GridId target,
|
||||
bool skipHook,
|
||||
ISerializationContext? context = null)
|
||||
{
|
||||
return new(source.Value);
|
||||
}
|
||||
|
||||
[MustUseReturnValue]
|
||||
public EntityUid Copy(ISerializationManager serializationManager, EntityUid source, EntityUid target,
|
||||
bool skipHook,
|
||||
ISerializationContext? context = null)
|
||||
{
|
||||
return new((int) source);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
14
Robust.Server/Physics/BroadPhaseSystem.cs
Normal file
14
Robust.Server/Physics/BroadPhaseSystem.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
|
||||
namespace Robust.Server.Physics
|
||||
{
|
||||
internal sealed class BroadPhaseSystem : SharedBroadPhaseSystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
UpdatesBefore.Add(typeof(PhysicsSystem));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,11 @@ namespace Robust.Shared.Maths
|
||||
|
||||
public static readonly Vector2 Infinity = new(float.PositiveInfinity, float.PositiveInfinity);
|
||||
|
||||
/// <summary>
|
||||
/// A vector with NaN X and Y.
|
||||
/// </summary>
|
||||
public static readonly Vector2 NaN = new(float.NaN, float.NaN);
|
||||
|
||||
/// <summary>
|
||||
/// Construct a vector from its coordinates.
|
||||
/// </summary>
|
||||
@@ -90,7 +95,7 @@ namespace Robust.Shared.Maths
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly Vector2 Rounded()
|
||||
{
|
||||
return new((float) MathF.Round(X), (float) MathF.Round(Y));
|
||||
return new(MathF.Round(X), MathF.Round(Y));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Robust.Shared.Serialization;
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Robust.Shared.Audio
|
||||
{
|
||||
@@ -8,43 +10,52 @@ namespace Robust.Shared.Audio
|
||||
/// Contains common audio parameters for audio playback on the client.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public struct AudioParams : IExposeData
|
||||
[DataDefinition]
|
||||
public struct AudioParams : IPopulateDefaultValues
|
||||
{
|
||||
/// <summary>
|
||||
/// Base volume to play the audio at, in dB.
|
||||
/// </summary>
|
||||
[DataField("volume")]
|
||||
public float Volume { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Scale for the audio pitch.
|
||||
/// </summary>
|
||||
[DataField("pitchscale")]
|
||||
public float PitchScale { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Audio bus to play on.
|
||||
/// </summary>
|
||||
[DataField("busname")]
|
||||
public string BusName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Only applies to positional audio.
|
||||
/// The maximum distance from which the audio is hearable.
|
||||
/// </summary>
|
||||
[DataField("maxdistance")]
|
||||
public float MaxDistance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Only applies to positional audio.
|
||||
/// Positional audio is dampened over distance with this as exponent.
|
||||
/// </summary>
|
||||
[DataField("attenuation")]
|
||||
public float Attenuation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Only applies to global (non-positional) audio.
|
||||
/// Target channels if the audio configuration has more than 2 speakers.
|
||||
/// </summary>
|
||||
[DataField("mixtarget")]
|
||||
public AudioMixTarget MixTarget { get; set; }
|
||||
|
||||
[DataField("loop")]
|
||||
public bool Loop { get; set; }
|
||||
|
||||
[DataField("playoffset")]
|
||||
public float PlayOffsetSeconds { get; set; }
|
||||
|
||||
// For the max distance value: it's 2000 in Godot, but I assume that's PIXELS due to the 2D positioning,
|
||||
@@ -54,18 +65,6 @@ namespace Robust.Shared.Audio
|
||||
/// </summary>
|
||||
public static readonly AudioParams Default = new(0, 1, "Master", 62.5f, 1, AudioMixTarget.Stereo, false, 0f);
|
||||
|
||||
void IExposeData.ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
Volume = serializer.ReadDataField("volume", 0f);
|
||||
PitchScale = serializer.ReadDataField("pitchscale", 1f);
|
||||
BusName = serializer.ReadDataField("busname", "Master");
|
||||
MaxDistance = serializer.ReadDataField("maxdistance", 62.5f);
|
||||
Attenuation = serializer.ReadDataField("attenuation", 1f);
|
||||
MixTarget = serializer.ReadDataField("mixtarget", AudioMixTarget.Stereo);
|
||||
Loop = serializer.ReadDataField("loop", false);
|
||||
PlayOffsetSeconds = serializer.ReadDataField("playoffset", 0f);
|
||||
}
|
||||
|
||||
public AudioParams(float volume, float pitchScale, string busName, float maxDistance, float attenuation,
|
||||
AudioMixTarget mixTarget, bool loop, float playOffsetSeconds) : this()
|
||||
{
|
||||
@@ -169,6 +168,15 @@ namespace Robust.Shared.Audio
|
||||
me.PlayOffsetSeconds = offset;
|
||||
return me;
|
||||
}
|
||||
|
||||
public void PopulateDefaultValues()
|
||||
{
|
||||
PitchScale = 1f;
|
||||
BusName = "Master";
|
||||
MaxDistance = 62.5f;
|
||||
Attenuation = 1f;
|
||||
MixTarget = AudioMixTarget.Stereo;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -280,6 +280,105 @@ namespace Robust.Shared
|
||||
public static readonly CVarDef<string> PlayerName =
|
||||
CVarDef.Create("player.name", "JoeGenero", CVar.ARCHIVE | CVar.CLIENTONLY);
|
||||
|
||||
/*
|
||||
* PHYSICS
|
||||
*/
|
||||
|
||||
// - Sleep
|
||||
public static readonly CVarDef<float> AngularSleepTolerance =
|
||||
CVarDef.Create("physics.angsleeptol", 2.0f / 180.0f * MathF.PI);
|
||||
|
||||
public static readonly CVarDef<float> LinearSleepTolerance =
|
||||
CVarDef.Create("physics.linsleeptol", 0.001f);
|
||||
|
||||
public static readonly CVarDef<bool> SleepAllowed =
|
||||
CVarDef.Create("physics.sleepallowed", true);
|
||||
|
||||
// Box2D default is 0.5f
|
||||
public static readonly CVarDef<float> TimeToSleep =
|
||||
CVarDef.Create("physics.timetosleep", 0.2f);
|
||||
|
||||
// - Solver
|
||||
// These are the minimum recommended by Box2D with the standard being 8 velocity 3 position iterations.
|
||||
// Trade-off is obviously performance vs how long it takes to stabilise.
|
||||
public static readonly CVarDef<int> PositionIterations =
|
||||
CVarDef.Create("physics.positer", 3);
|
||||
|
||||
public static readonly CVarDef<int> VelocityIterations =
|
||||
CVarDef.Create("physics.veliter", 8);
|
||||
|
||||
public static readonly CVarDef<bool> WarmStarting =
|
||||
CVarDef.Create("physics.warmstart", true);
|
||||
|
||||
public static readonly CVarDef<bool> AutoClearForces =
|
||||
CVarDef.Create("physics.autoclearforces", true);
|
||||
|
||||
/// <summary>
|
||||
/// A velocity threshold for elastic collisions. Any collision with a relative linear
|
||||
/// velocity below this threshold will be treated as inelastic.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<float> VelocityThreshold =
|
||||
CVarDef.Create("physics.velocitythreshold", 0.5f);
|
||||
|
||||
// TODO: Copy Box2D's comments on baumgarte I think it's on the solver class.
|
||||
/// <summary>
|
||||
/// How much overlap is resolved per tick.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<float> Baumgarte =
|
||||
CVarDef.Create("physics.baumgarte", 0.2f);
|
||||
|
||||
/// <summary>
|
||||
/// A small length used as a collision and constraint tolerance. Usually it is
|
||||
/// chosen to be numerically significant, but visually insignificant.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<float> LinearSlop =
|
||||
CVarDef.Create("physics.linearslop", 0.005f);
|
||||
|
||||
/// <summary>
|
||||
/// A small angle used as a collision and constraint tolerance. Usually it is
|
||||
/// chosen to be numerically significant, but visually insignificant.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<float> AngularSlop =
|
||||
CVarDef.Create("physics.angularslop", 2.0f / 180.0f * MathF.PI);
|
||||
|
||||
/// <summary>
|
||||
/// The radius of the polygon/edge shape skin. This should not be modified. Making
|
||||
/// this smaller means polygons will have an insufficient buffer for continuous collision.
|
||||
/// Making it larger may create artifacts for vertex collision.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Default is set to be 2 x linearslop. TODO Should we listen to linearslop changes?
|
||||
/// </remarks>
|
||||
public static readonly CVarDef<float> PolygonRadius =
|
||||
CVarDef.Create("physics.polygonradius", 2 * 0.005f);
|
||||
|
||||
/// <summary>
|
||||
/// If true, it will run a GiftWrap convex hull on all polygon inputs.
|
||||
/// This makes for a more stable engine when given random input,
|
||||
/// but if speed of the creation of polygons are more important,
|
||||
/// you might want to set this to false.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> ConvexHullPolygons =
|
||||
CVarDef.Create("physics.convexhullpolygons", true);
|
||||
|
||||
public static readonly CVarDef<int> MaxPolygonVertices =
|
||||
CVarDef.Create("physics.maxpolygonvertices", 8);
|
||||
|
||||
public static readonly CVarDef<float> MaxLinearCorrection =
|
||||
CVarDef.Create("physics.maxlinearcorrection", 0.2f);
|
||||
|
||||
public static readonly CVarDef<float> MaxAngularCorrection =
|
||||
CVarDef.Create("physics.maxangularcorrection", 8.0f / 180.0f * MathF.PI);
|
||||
|
||||
// - Maximums
|
||||
// Squared
|
||||
public static readonly CVarDef<float> MaxLinVelocity =
|
||||
CVarDef.Create("physics.maxlinvelocity", 4.0f);
|
||||
|
||||
// Squared
|
||||
public static readonly CVarDef<float> MaxAngVelocity =
|
||||
CVarDef.Create("physics.maxangvelocity", 0.5f * MathF.PI);
|
||||
|
||||
/*
|
||||
* DISCORD
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace Robust.Shared.Containers
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[field: DataField("occludes")]
|
||||
public bool OccludesLight { get; set; } = true;
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -40,6 +41,7 @@ namespace Robust.Shared.Containers
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[field: DataField("showEnts")]
|
||||
public bool ShowContents { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -165,13 +167,5 @@ namespace Robust.Shared.Containers
|
||||
Manager.Owner.SendMessage(Manager, new ContainerContentsModifiedMessage(this, toremove, true));
|
||||
Manager.Dirty();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
// ID and Manager are filled in Initialize
|
||||
serializer.DataReadWriteFunction("showEnts", false, value => ShowContents = value, () => ShowContents);
|
||||
serializer.DataReadWriteFunction("occludes", true, value => OccludesLight = value, () => OccludesLight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Robust.Shared.Containers
|
||||
{
|
||||
@@ -22,37 +21,14 @@ namespace Robust.Shared.Containers
|
||||
/// <summary>
|
||||
/// The generic container class uses a list of entities
|
||||
/// </summary>
|
||||
private List<IEntity> _containerList = new();
|
||||
[DataField("ents")]
|
||||
private readonly List<IEntity> _containerList = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IReadOnlyList<IEntity> ContainedEntities => _containerList;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ContainerType => ClassName;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
#if SERV3
|
||||
// ONLY PAUL CAN MAKE ME WHOLE
|
||||
serializer.DataField(ref _containerList, "ents", new List<IEntity>());
|
||||
#else
|
||||
if (serializer.Writing)
|
||||
{
|
||||
serializer.DataWriteFunction("ents", new List<EntityUid>(),
|
||||
() => _containerList.Select(e => e.Uid).ToList());
|
||||
}
|
||||
else
|
||||
{
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
serializer.DataReadFunction("ents", new List<EntityUid>(),
|
||||
value => _containerList = value.Select((uid => entMan.GetEntity(uid))).ToList());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void InternalInsert(IEntity toinsert)
|
||||
|
||||
@@ -7,6 +7,8 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Shared.Containers
|
||||
@@ -14,14 +16,16 @@ namespace Robust.Shared.Containers
|
||||
/// <summary>
|
||||
/// Holds data about a set of entity containers on this entity.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IContainerManager))]
|
||||
// [RegisterComponent]
|
||||
// [ComponentReference(typeof(IContainerManager))]
|
||||
public class ContainerManagerComponent : Component, IContainerManager
|
||||
{
|
||||
[Dependency] private readonly IRobustSerializer _serializer = default!;
|
||||
[Dependency] private readonly IDynamicTypeFactoryInternal _dynFactory = default!;
|
||||
|
||||
[ViewVariables] private Dictionary<string, IContainer> _containers = new();
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("containers")]
|
||||
private Dictionary<string, IContainer> _containers = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public sealed override string Name => "ContainerContainer";
|
||||
@@ -81,7 +85,7 @@ namespace Robust.Shared.Containers
|
||||
_containers.Remove(dead);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Add new containers and update existing contents.
|
||||
|
||||
foreach (var (containerType, id, showEnts, occludesLight, entityUids) in cast.ContainerSet)
|
||||
@@ -135,13 +139,6 @@ namespace Robust.Shared.Containers
|
||||
newContainer.Manager = this;
|
||||
return newContainer;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _containers, "containers", new Dictionary<string, IContainer>());
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
@@ -319,9 +316,13 @@ namespace Robust.Shared.Containers
|
||||
}
|
||||
}
|
||||
|
||||
private struct ContainerPrototypeData : IExposeData
|
||||
[DataDefinition]
|
||||
private struct ContainerPrototypeData : IPopulateDefaultValues
|
||||
{
|
||||
[DataField("entities")]
|
||||
public List<EntityUid> Entities;
|
||||
|
||||
[DataField("type")]
|
||||
public string? Type;
|
||||
|
||||
public ContainerPrototypeData(List<EntityUid> entities, string type)
|
||||
@@ -330,10 +331,9 @@ namespace Robust.Shared.Containers
|
||||
Type = type;
|
||||
}
|
||||
|
||||
void IExposeData.ExposeData(ObjectSerializer serializer)
|
||||
public void PopulateDefaultValues()
|
||||
{
|
||||
serializer.DataField(ref Entities, "entities", new List<EntityUid>());
|
||||
serializer.DataField(ref Type, "type", null);
|
||||
Entities = new List<EntityUid>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Shared.Containers
|
||||
@@ -15,8 +14,6 @@ namespace Robust.Shared.Containers
|
||||
{
|
||||
private const string ClassName = "ContainerSlot";
|
||||
|
||||
private IEntity? _containedEntity;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IReadOnlyList<IEntity> ContainedEntities
|
||||
{
|
||||
@@ -29,38 +26,11 @@ namespace Robust.Shared.Containers
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
public IEntity? ContainedEntity
|
||||
{
|
||||
get => _containedEntity;
|
||||
private set => _containedEntity = value;
|
||||
}
|
||||
[field: DataField("ent")]
|
||||
public IEntity? ContainedEntity { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ContainerType => ClassName;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
#if SERV3
|
||||
// ONLY PAUL CAN MAKE ME WHOLE
|
||||
serializer.DataField(ref _containedEntity, "ent", default);
|
||||
#else
|
||||
if (serializer.Writing)
|
||||
{
|
||||
serializer.DataWriteFunction("ents", EntityUid.Invalid,
|
||||
() => _containedEntity?.Uid ?? EntityUid.Invalid);
|
||||
}
|
||||
else
|
||||
{
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
serializer.DataReadFunction("ent", EntityUid.Invalid,
|
||||
value => _containedEntity = value != EntityUid.Invalid ? entMan.GetEntity(value) : null);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanInsert(IEntity toinsert)
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Robust.Shared.Containers
|
||||
{
|
||||
@@ -25,7 +26,8 @@ namespace Robust.Shared.Containers
|
||||
/// </remarks>
|
||||
/// <seealso cref="IContainerManager" />
|
||||
[PublicAPI]
|
||||
public interface IContainer : IExposeData
|
||||
[ImplicitDataDefinitionForInheritors]
|
||||
public interface IContainer
|
||||
{
|
||||
/// <summary>
|
||||
/// Readonly collection of all the entities contained within this specific container
|
||||
|
||||
@@ -28,6 +28,9 @@ namespace Robust.Shared.ContentPack
|
||||
/// </summary>
|
||||
internal sealed partial class AssemblyTypeChecker
|
||||
{
|
||||
// Used to be in Sandbox.yml, moved out of there to facilitate faster loading.
|
||||
private const string SystemAssemblyName = "System.Runtime";
|
||||
|
||||
private readonly IResourceManager _res;
|
||||
|
||||
/// <summary>
|
||||
@@ -43,13 +46,16 @@ namespace Robust.Shared.ContentPack
|
||||
// Necessary for loads with launcher loader.
|
||||
public Func<string, Stream?>? ExtraRobustLoader { get; init; }
|
||||
private readonly ISawmill _sawmill;
|
||||
private readonly SandboxConfig _config;
|
||||
private readonly Task<SandboxConfig> _config;
|
||||
|
||||
public AssemblyTypeChecker(IResourceManager res, ISawmill sawmill)
|
||||
{
|
||||
_res = res;
|
||||
_sawmill = sawmill;
|
||||
_config = LoadConfig();
|
||||
// Config is huge and YAML is slow so config loading is delayed.
|
||||
// This means we can parallelize config loading with IL verification
|
||||
// (first time we need the config is when we print verifier errors).
|
||||
_config = Task.Run(LoadConfig);
|
||||
}
|
||||
|
||||
private Resolver CreateResolver()
|
||||
@@ -148,12 +154,14 @@ namespace Robust.Shared.ContentPack
|
||||
return true;
|
||||
}
|
||||
|
||||
var loadedConfig = _config.Result;
|
||||
|
||||
// We still do explicit type reference scanning, even though the actual whitelists work with raw members.
|
||||
// This is so that we can simplify handling of generic type specifications during member checking:
|
||||
// we won't have to check that any types in their type arguments are whitelisted.
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (!IsTypeAccessAllowed(type, out _))
|
||||
if (!IsTypeAccessAllowed(loadedConfig, type, out _))
|
||||
{
|
||||
errors.Add(new SandboxError($"Access to type not allowed: {type}"));
|
||||
}
|
||||
@@ -161,11 +169,11 @@ namespace Robust.Shared.ContentPack
|
||||
|
||||
_sawmill.Debug($"Types... {fullStopwatch.ElapsedMilliseconds}ms");
|
||||
|
||||
CheckInheritance(inherited, errors);
|
||||
CheckInheritance(loadedConfig, inherited, errors);
|
||||
|
||||
_sawmill.Debug($"Inheritance... {fullStopwatch.ElapsedMilliseconds}ms");
|
||||
|
||||
CheckMemberReferences(members, errors);
|
||||
CheckMemberReferences(loadedConfig, members, errors);
|
||||
|
||||
foreach (var error in errors)
|
||||
{
|
||||
@@ -185,17 +193,33 @@ namespace Robust.Shared.ContentPack
|
||||
{
|
||||
_sawmill.Debug($"{name}: Verifying IL...");
|
||||
var sw = Stopwatch.StartNew();
|
||||
var ver = new Verifier(resolver);
|
||||
ver.SetSystemModuleName(new AssemblyName(_config.SystemAssemblyName));
|
||||
var verifyErrors = false;
|
||||
foreach (var res in ver.Verify(peReader))
|
||||
var bag = new ConcurrentBag<VerificationResult>();
|
||||
var partitioner = Partitioner.Create(reader.TypeDefinitions);
|
||||
|
||||
Parallel.ForEach(partitioner.GetPartitions(Environment.ProcessorCount), handle =>
|
||||
{
|
||||
if (_config.AllowedVerifierErrors.Contains(res.Code))
|
||||
var ver = new Verifier(resolver);
|
||||
ver.SetSystemModuleName(new AssemblyName(SystemAssemblyName));
|
||||
while (handle.MoveNext())
|
||||
{
|
||||
foreach (var result in ver.Verify(peReader, handle.Current, verifyMethods: true))
|
||||
{
|
||||
bag.Add(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var loadedCfg = _config.Result;
|
||||
|
||||
var verifyErrors = false;
|
||||
foreach (var res in bag)
|
||||
{
|
||||
if (loadedCfg.AllowedVerifierErrors.Contains(res.Code))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var msg = $"{name}: ILVerify: {res.Message}";
|
||||
var msg = $"{name}: ILVerify: {string.Format(res.Message, res.Args)}";
|
||||
|
||||
try
|
||||
{
|
||||
@@ -237,6 +261,7 @@ namespace Robust.Shared.ContentPack
|
||||
}
|
||||
|
||||
private void CheckMemberReferences(
|
||||
SandboxConfig sandboxConfig,
|
||||
List<MMemberRef> members,
|
||||
ConcurrentBag<SandboxError> errors)
|
||||
{
|
||||
@@ -273,7 +298,7 @@ namespace Robust.Shared.ContentPack
|
||||
|
||||
var baseTypeReferenced = (MTypeReferenced) baseType;
|
||||
|
||||
if (!IsTypeAccessAllowed(baseTypeReferenced, out var typeCfg))
|
||||
if (!IsTypeAccessAllowed(sandboxConfig, baseTypeReferenced, out var typeCfg))
|
||||
{
|
||||
// Technically this error isn't necessary since we have an earlier pass
|
||||
// checking all referenced types. That should have caught this
|
||||
@@ -338,6 +363,7 @@ namespace Robust.Shared.ContentPack
|
||||
}
|
||||
|
||||
private void CheckInheritance(
|
||||
SandboxConfig sandboxConfig,
|
||||
List<(MType type, MType parent, ArraySegment<MType> interfaceImpls)> inherited,
|
||||
ConcurrentBag<SandboxError> errors)
|
||||
{
|
||||
@@ -367,7 +393,7 @@ namespace Robust.Shared.ContentPack
|
||||
_ => throw new InvalidOperationException() // Can't happen.
|
||||
};
|
||||
|
||||
if (!IsTypeAccessAllowed(realBaseType, out var cfg))
|
||||
if (!IsTypeAccessAllowed(sandboxConfig, realBaseType, out var cfg))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -377,13 +403,13 @@ namespace Robust.Shared.ContentPack
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsTypeAccessAllowed(MTypeReferenced type, [NotNullWhen(true)] out TypeConfig? cfg)
|
||||
private bool IsTypeAccessAllowed(SandboxConfig sandboxConfig, MTypeReferenced type, [NotNullWhen(true)] out TypeConfig? cfg)
|
||||
{
|
||||
if (type.Namespace == null)
|
||||
{
|
||||
if (type.ResolutionScope is MResScopeType parentType)
|
||||
{
|
||||
if (!IsTypeAccessAllowed((MTypeReferenced) parentType.Type, out var parentCfg))
|
||||
if (!IsTypeAccessAllowed(sandboxConfig, (MTypeReferenced) parentType.Type, out var parentCfg))
|
||||
{
|
||||
cfg = null;
|
||||
return false;
|
||||
@@ -413,7 +439,7 @@ namespace Robust.Shared.ContentPack
|
||||
}
|
||||
|
||||
// Check if in whitelisted namespaces.
|
||||
foreach (var whNamespace in _config.WhitelistedNamespaces)
|
||||
foreach (var whNamespace in sandboxConfig.WhitelistedNamespaces)
|
||||
{
|
||||
if (type.Namespace.StartsWith(whNamespace))
|
||||
{
|
||||
@@ -422,7 +448,7 @@ namespace Robust.Shared.ContentPack
|
||||
}
|
||||
}
|
||||
|
||||
if (!_config.Types.TryGetValue(type.Namespace, out var nsDict))
|
||||
if (!sandboxConfig.Types.TryGetValue(type.Namespace, out var nsDict))
|
||||
{
|
||||
cfg = null;
|
||||
return false;
|
||||
@@ -749,8 +775,9 @@ namespace Robust.Shared.ContentPack
|
||||
return handle.IsNil ? null : reader.GetString(handle);
|
||||
}
|
||||
|
||||
private sealed class Resolver : ResolverBase
|
||||
private sealed class Resolver : IResolver
|
||||
{
|
||||
private readonly ConcurrentDictionary<string, PEReader?> _dictionary = new();
|
||||
private readonly AssemblyTypeChecker _parent;
|
||||
private readonly string[] _diskLoadPaths;
|
||||
private readonly ResourcePath[] _resLoadPaths;
|
||||
@@ -762,7 +789,7 @@ namespace Robust.Shared.ContentPack
|
||||
_resLoadPaths = resLoadPaths;
|
||||
}
|
||||
|
||||
protected override PEReader? ResolveCore(string simpleName)
|
||||
private PEReader? ResolveCore(string simpleName)
|
||||
{
|
||||
var dllName = $"{simpleName}.dll";
|
||||
foreach (var diskLoadPath in _diskLoadPaths)
|
||||
@@ -797,6 +824,11 @@ namespace Robust.Shared.ContentPack
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public PEReader? Resolve(string simpleName)
|
||||
{
|
||||
return _dictionary.GetOrAdd(simpleName, ResolveCore);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class TypeProvider : ISignatureTypeProvider<MType, int>
|
||||
|
||||
@@ -88,6 +88,8 @@ namespace Robust.Shared.ContentPack
|
||||
|
||||
if (_sandboxingEnabled)
|
||||
{
|
||||
var checkerSw = Stopwatch.StartNew();
|
||||
|
||||
var typeChecker = MakeTypeChecker();
|
||||
|
||||
Parallel.ForEach(files, pair =>
|
||||
@@ -100,6 +102,8 @@ namespace Robust.Shared.ContentPack
|
||||
throw new TypeCheckFailedException($"Assembly {name} failed type checks.");
|
||||
}
|
||||
});
|
||||
|
||||
Logger.DebugS("res.mod", $"Verified assemblies in {checkerSw.ElapsedMilliseconds}ms");
|
||||
}
|
||||
|
||||
// Actually load them in the order they depend on each other.
|
||||
|
||||
@@ -43,23 +43,7 @@ namespace Robust.Shared.ContentPack
|
||||
/// <returns>Enumerable of all file paths in that directory and sub directories.</returns>
|
||||
public static IEnumerable<string> GetFiles(string path)
|
||||
{
|
||||
var queue = new Queue<string>();
|
||||
queue.Enqueue(path);
|
||||
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
path = queue.Dequeue();
|
||||
|
||||
foreach (var subDir in Directory.GetDirectories(path))
|
||||
{
|
||||
queue.Enqueue(subDir);
|
||||
}
|
||||
|
||||
foreach (var file in Directory.GetFiles(path))
|
||||
{
|
||||
yield return file;
|
||||
}
|
||||
}
|
||||
return Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories);
|
||||
}
|
||||
|
||||
public static bool IsFileInUse(IOException exception)
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
# This file controls all whitelists and other rules enforced by AssemblyTypeChecker.
|
||||
# Yes, I typed most of this out by hand.
|
||||
|
||||
|
||||
SystemAssemblyName: System.Runtime
|
||||
|
||||
# ILVerify errors that are allowed.
|
||||
AllowedVerifierErrors:
|
||||
# InitOnly happens a lot when calling e.g. ToString() on a readonly field.
|
||||
# It's fine and doesn't break anything runtime related so...
|
||||
- InitOnly
|
||||
# ILVerify has problems with Default Interface Methods so...
|
||||
- InterfaceMethodNotImplemented
|
||||
|
||||
# EVERYTHING in these namespaces is allowed.
|
||||
WhitelistedNamespaces:
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
@@ -10,6 +12,7 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[Reflect(false)]
|
||||
[ImplicitDataDefinitionForInheritorsAttribute]
|
||||
public abstract class Component : IComponent
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -24,6 +27,7 @@ namespace Robust.Shared.GameObjects
|
||||
[ViewVariables]
|
||||
public virtual bool NetworkSynchronizeExistence => false;
|
||||
|
||||
[DataField("netsync")]
|
||||
private bool _netSyncEnabled = true;
|
||||
/// <inheritdoc />
|
||||
[ViewVariables]
|
||||
@@ -159,12 +163,6 @@ namespace Robust.Shared.GameObjects
|
||||
_running = false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(ref _netSyncEnabled, "netsync", true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dirty()
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
[MeansImplicitAssignment]
|
||||
public class ComponentDependencyAttribute : Attribute
|
||||
{
|
||||
public readonly string? OnAddMethodName;
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Robust.Shared.Exceptions;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
using DependencyAttribute = Robust.Shared.IoC.DependencyAttribute;
|
||||
@@ -129,13 +130,6 @@ namespace Robust.Shared.GameObjects
|
||||
ComponentAdded?.Invoke(this, new AddedComponentEventArgs(component));
|
||||
}
|
||||
|
||||
if (entity.Initialized || entity.Initializing)
|
||||
{
|
||||
var defaultSerializer = DefaultValueSerializer.Reader();
|
||||
defaultSerializer.CurrentType = component.GetType();
|
||||
component.ExposeData(defaultSerializer);
|
||||
}
|
||||
|
||||
_componentDependencyManager.OnComponentAdd(entity, component);
|
||||
|
||||
component.OnAdd();
|
||||
@@ -193,7 +187,7 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
ITransformComponent _ => 0,
|
||||
IMetaDataComponent _ => 1,
|
||||
IPhysicsComponent _ => 2,
|
||||
IPhysBody _ => 2,
|
||||
_ => int.MaxValue
|
||||
};
|
||||
|
||||
@@ -449,7 +443,7 @@ namespace Robust.Shared.GameObjects
|
||||
var comps = _entCompIndex[uid];
|
||||
foreach (var comp in comps)
|
||||
{
|
||||
if (comp.Deleted || !(comp is T tComp)) continue;
|
||||
if (comp.Deleted || comp is not T tComp) continue;
|
||||
|
||||
yield return tComp;
|
||||
}
|
||||
|
||||
@@ -2,13 +2,16 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
public class CollisionChangeMessage : EntitySystemMessage
|
||||
{
|
||||
public PhysicsComponent Body { get; }
|
||||
|
||||
public EntityUid Owner { get; }
|
||||
public bool CanCollide { get; }
|
||||
|
||||
public CollisionChangeMessage(EntityUid owner, bool canCollide)
|
||||
public CollisionChangeMessage(PhysicsComponent body, EntityUid owner, bool canCollide)
|
||||
{
|
||||
Body = body;
|
||||
Owner = owner;
|
||||
CanCollide = canCollide;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,53 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Physics.Collision;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
public interface ICollideBehavior
|
||||
/// <summary>
|
||||
/// Called every tick for colliding bodies. Called once per pair.
|
||||
/// </summary>
|
||||
public sealed class CollisionMessage : EntitySystemMessage
|
||||
{
|
||||
void CollideWith(IEntity collidedWith);
|
||||
public readonly IPhysBody BodyA;
|
||||
public readonly IPhysBody BodyB;
|
||||
public readonly float FrameTime;
|
||||
public readonly Manifold Manifold;
|
||||
|
||||
public CollisionMessage(IPhysBody bodyA, IPhysBody bodyB, float frameTime, Manifold manifold)
|
||||
{
|
||||
BodyA = bodyA;
|
||||
BodyB = bodyB;
|
||||
FrameTime = frameTime;
|
||||
Manifold = manifold;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called once when a collision starts
|
||||
/// </summary>
|
||||
public interface IStartCollide
|
||||
{
|
||||
/// <summary>
|
||||
/// Called after all collisions have been processed, as well as how many collisions occured
|
||||
/// We'll pass in both our body and the other body to save the behaviors having to get these components themselves.
|
||||
/// </summary>
|
||||
/// <param name="collisionCount"></param>
|
||||
void PostCollide(int collisionCount) { }
|
||||
void CollideWith(IPhysBody ourBody, IPhysBody otherBody, in Manifold manifold);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called once when a collision ends.
|
||||
/// </summary>
|
||||
public interface IEndCollide
|
||||
{
|
||||
/// <summary>
|
||||
/// Run behaviour after all other collision behaviors have run.
|
||||
/// </summary>
|
||||
/// <param name="ourBody"></param>
|
||||
/// <param name="otherBody"></param>
|
||||
/// <param name="manifold"></param>
|
||||
void CollideWith(IPhysBody ourBody, IPhysBody otherBody, in Manifold manifold);
|
||||
}
|
||||
|
||||
public interface ICollideSpecial
|
||||
@@ -27,483 +55,6 @@ namespace Robust.Shared.GameObjects
|
||||
bool PreventCollide(IPhysBody collidedwith);
|
||||
}
|
||||
|
||||
public partial interface IPhysicsComponent : IComponent, IPhysBody
|
||||
{
|
||||
public new bool Hard { get; set; }
|
||||
bool IsColliding(Vector2 offset, bool approximate = true);
|
||||
|
||||
IEnumerable<IEntity> GetCollidingEntities(Vector2 offset, bool approximate = true);
|
||||
bool UpdatePhysicsTree();
|
||||
|
||||
void RemovedFromPhysicsTree(MapId mapId);
|
||||
void AddedToPhysicsTree(MapId mapId);
|
||||
}
|
||||
|
||||
public partial class PhysicsComponent : Component, IPhysicsComponent
|
||||
{
|
||||
[Dependency] private readonly IPhysicsManager _physicsManager = default!;
|
||||
|
||||
private bool _canCollide;
|
||||
private bool _isHard;
|
||||
private BodyStatus _status;
|
||||
private BodyType _bodyType;
|
||||
private List<IPhysShape> _physShapes = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Physics";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override uint? NetID => NetIDs.PHYSICS;
|
||||
|
||||
public IEntity Entity => Owner;
|
||||
|
||||
/// <inheritdoc />
|
||||
public MapId MapID => Owner.Transform.MapID;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int ProxyId { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public BodyType BodyType { get; set; } = BodyType.Static;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int SleepAccumulator
|
||||
{
|
||||
get => _sleepAccumulator;
|
||||
set
|
||||
{
|
||||
if (_sleepAccumulator == value)
|
||||
return;
|
||||
|
||||
_sleepAccumulator = value;
|
||||
Awake = _physicsManager.SleepTimeThreshold > SleepAccumulator;
|
||||
}
|
||||
}
|
||||
|
||||
private int _sleepAccumulator;
|
||||
|
||||
// TODO: When SleepTimeThreshold updates we need to update Awake
|
||||
public int SleepThreshold
|
||||
{
|
||||
get => _physicsManager.SleepTimeThreshold;
|
||||
set => _physicsManager.SleepTimeThreshold = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables]
|
||||
public bool Awake
|
||||
{
|
||||
get => _awake;
|
||||
private set
|
||||
{
|
||||
if (_awake == value)
|
||||
return;
|
||||
|
||||
_awake = value;
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new PhysicsUpdateMessage(this));
|
||||
}
|
||||
}
|
||||
|
||||
private bool _awake = true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void WakeBody()
|
||||
{
|
||||
if (CanMove())
|
||||
SleepAccumulator = 0;
|
||||
}
|
||||
|
||||
public PhysicsComponent()
|
||||
{
|
||||
PhysicsShapes = new PhysShapeList(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _canCollide, "on", true);
|
||||
serializer.DataField(ref _isHard, "hard", true);
|
||||
serializer.DataField(ref _status, "status", BodyStatus.OnGround);
|
||||
serializer.DataField(ref _bodyType, "bodyType", BodyType.Static);
|
||||
serializer.DataField(ref _physShapes, "shapes", new List<IPhysShape> {new PhysShapeAabb()});
|
||||
serializer.DataField(ref _anchored, "anchored", true);
|
||||
serializer.DataField(ref _mass, "mass", 1.0f);
|
||||
}
|
||||
|
||||
/// <param name="player"></param>
|
||||
/// <inheritdoc />
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
return new PhysicsComponentState(_canCollide, _status, _physShapes, _isHard, _mass, LinearVelocity, AngularVelocity, Anchored);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
if (curState == null)
|
||||
return;
|
||||
|
||||
var newState = (PhysicsComponentState) curState;
|
||||
|
||||
_canCollide = newState.CanCollide;
|
||||
_status = newState.Status;
|
||||
_isHard = newState.Hard;
|
||||
_physShapes = newState.PhysShapes;
|
||||
|
||||
foreach (var shape in _physShapes)
|
||||
{
|
||||
shape.ApplyState();
|
||||
}
|
||||
|
||||
Dirty();
|
||||
UpdateEntityTree();
|
||||
Mass = newState.Mass / 1000f; // gram to kilogram
|
||||
|
||||
LinearVelocity = newState.LinearVelocity;
|
||||
// Logger.Debug($"{IGameTiming.TickStampStatic}: [{Owner}] {LinearVelocity}");
|
||||
AngularVelocity = newState.AngularVelocity;
|
||||
Anchored = newState.Anchored;
|
||||
// TODO: Does it make sense to reset controllers here?
|
||||
// This caused space movement to break in content and I'm not 100% sure this is a good fix.
|
||||
// Look man the CM test is in 5 hours cut me some slack.
|
||||
//_controllers = null;
|
||||
// Reset predict flag to false to avoid predicting stuff too long.
|
||||
// Another possibly bad hack for content at the moment.
|
||||
Predict = false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables]
|
||||
Box2 IPhysBody.WorldAABB
|
||||
{
|
||||
get
|
||||
{
|
||||
var pos = Owner.Transform.WorldPosition;
|
||||
return ((IPhysBody) this).AABB.Translated(pos);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables]
|
||||
Box2 IPhysBody.AABB
|
||||
{
|
||||
get
|
||||
{
|
||||
var angle = Owner.Transform.WorldRotation;
|
||||
var bounds = new Box2();
|
||||
|
||||
foreach (var shape in _physShapes)
|
||||
{
|
||||
var shapeBounds = shape.CalculateLocalBounds(angle);
|
||||
bounds = bounds.IsEmpty() ? shapeBounds : bounds.Union(shapeBounds);
|
||||
}
|
||||
|
||||
return bounds;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables]
|
||||
public IList<IPhysShape> PhysicsShapes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Enables or disabled collision processing of this component.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool CanCollide
|
||||
{
|
||||
get => _canCollide;
|
||||
set
|
||||
{
|
||||
if (_canCollide == value)
|
||||
return;
|
||||
|
||||
_canCollide = value;
|
||||
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local,
|
||||
new CollisionChangeMessage(Owner.Uid, _canCollide));
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Non-hard physics bodies will not cause action collision (e.g. blocking of movement)
|
||||
/// while still raising collision events.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is useful for triggers or such to detect collision without actually causing a blockage.
|
||||
/// </remarks>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Hard
|
||||
{
|
||||
get => _isHard;
|
||||
set
|
||||
{
|
||||
if (_isHard == value)
|
||||
return;
|
||||
|
||||
_isHard = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bitmask of the collision layers this component is a part of.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int CollisionLayer
|
||||
{
|
||||
get
|
||||
{
|
||||
var layers = 0x0;
|
||||
|
||||
foreach (var shape in _physShapes)
|
||||
layers = layers | shape.CollisionLayer;
|
||||
return layers;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bitmask of the layers this component collides with.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int CollisionMask
|
||||
{
|
||||
get
|
||||
{
|
||||
var mask = 0x0;
|
||||
|
||||
foreach (var shape in _physShapes)
|
||||
mask = mask | shape.CollisionMask;
|
||||
return mask;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
// normally ExposeData would create this
|
||||
if (_physShapes == null)
|
||||
{
|
||||
_physShapes = new List<IPhysShape> {new PhysShapeAabb()};
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var shape in _physShapes)
|
||||
{
|
||||
ShapeAdded(shape);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var controller in _controllers.Values)
|
||||
{
|
||||
controller.ControlledComponent = this;
|
||||
}
|
||||
|
||||
Dirty();
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local,
|
||||
new CollisionChangeMessage(Owner.Uid, _canCollide));
|
||||
}
|
||||
|
||||
public override void OnAdd()
|
||||
{
|
||||
base.OnAdd();
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new PhysicsUpdateMessage(this));
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
base.OnRemove();
|
||||
|
||||
// In case somebody starts sharing shapes across multiple components I guess?
|
||||
foreach (var shape in _physShapes)
|
||||
{
|
||||
ShapeRemoved(shape);
|
||||
}
|
||||
|
||||
// Should we not call this if !_canCollide? PathfindingSystem doesn't care at least.
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new CollisionChangeMessage(Owner.Uid, false));
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new PhysicsUpdateMessage(this));
|
||||
}
|
||||
|
||||
private void ShapeAdded(IPhysShape shape)
|
||||
{
|
||||
shape.OnDataChanged += ShapeDataChanged;
|
||||
}
|
||||
|
||||
private void ShapeRemoved(IPhysShape item)
|
||||
{
|
||||
item.OnDataChanged -= ShapeDataChanged;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Startup()
|
||||
{
|
||||
base.Startup();
|
||||
_physicsManager.AddBody(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Shutdown()
|
||||
{
|
||||
RemoveControllers();
|
||||
_physicsManager.RemoveBody(this);
|
||||
base.Shutdown();
|
||||
}
|
||||
|
||||
public bool IsColliding(Vector2 offset, bool approx = true)
|
||||
{
|
||||
return _physicsManager.IsColliding(this, offset, approx);
|
||||
}
|
||||
|
||||
public IEnumerable<IEntity> GetCollidingEntities(Vector2 offset, bool approx = true)
|
||||
{
|
||||
return _physicsManager.GetCollidingEntities(this, offset, approx);
|
||||
}
|
||||
|
||||
public bool UpdatePhysicsTree()
|
||||
=> _physicsManager.Update(this);
|
||||
|
||||
public void RemovedFromPhysicsTree(MapId mapId)
|
||||
{
|
||||
_physicsManager.RemovedFromMap(this, mapId);
|
||||
}
|
||||
|
||||
public void AddedToPhysicsTree(MapId mapId)
|
||||
{
|
||||
_physicsManager.AddedToMap(this, mapId);
|
||||
}
|
||||
|
||||
private bool UpdateEntityTree() => Owner.EntityManager.UpdateEntityTree(Owner);
|
||||
|
||||
public bool IsOnGround()
|
||||
{
|
||||
return Status == BodyStatus.OnGround;
|
||||
}
|
||||
|
||||
public bool IsInAir()
|
||||
{
|
||||
return Status == BodyStatus.InAir;
|
||||
}
|
||||
|
||||
private void ShapeDataChanged()
|
||||
{
|
||||
Dirty();
|
||||
UpdatePhysicsTree();
|
||||
}
|
||||
|
||||
// Custom IList<> implementation so that we can hook addition/removal of shapes.
|
||||
// To hook into their OnDataChanged event correctly.
|
||||
private sealed class PhysShapeList : IList<IPhysShape>
|
||||
{
|
||||
private readonly PhysicsComponent _owner;
|
||||
|
||||
public PhysShapeList(PhysicsComponent owner)
|
||||
{
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
public IEnumerator<IPhysShape> GetEnumerator()
|
||||
{
|
||||
return _owner._physShapes.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public void Add(IPhysShape item)
|
||||
{
|
||||
_owner._physShapes.Add(item);
|
||||
|
||||
ItemAdded(item);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
foreach (var item in _owner._physShapes)
|
||||
{
|
||||
ItemRemoved(item);
|
||||
}
|
||||
|
||||
_owner._physShapes.Clear();
|
||||
}
|
||||
|
||||
public bool Contains(IPhysShape item)
|
||||
{
|
||||
return _owner._physShapes.Contains(item);
|
||||
}
|
||||
|
||||
public void CopyTo(IPhysShape[] array, int arrayIndex)
|
||||
{
|
||||
_owner._physShapes.CopyTo(array, arrayIndex);
|
||||
}
|
||||
|
||||
public bool Remove(IPhysShape item)
|
||||
{
|
||||
var found = _owner._physShapes.Remove(item);
|
||||
|
||||
if (found)
|
||||
{
|
||||
ItemRemoved(item);
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
public int Count => _owner._physShapes.Count;
|
||||
public bool IsReadOnly => false;
|
||||
|
||||
public int IndexOf(IPhysShape item)
|
||||
{
|
||||
return _owner._physShapes.IndexOf(item);
|
||||
}
|
||||
|
||||
public void Insert(int index, IPhysShape item)
|
||||
{
|
||||
_owner._physShapes.Insert(index, item);
|
||||
ItemAdded(item);
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
var item = _owner._physShapes[index];
|
||||
ItemRemoved(item);
|
||||
|
||||
_owner._physShapes.RemoveAt(index);
|
||||
}
|
||||
|
||||
public IPhysShape this[int index]
|
||||
{
|
||||
get => _owner._physShapes[index];
|
||||
set
|
||||
{
|
||||
var oldItem = _owner._physShapes[index];
|
||||
ItemRemoved(oldItem);
|
||||
|
||||
_owner._physShapes[index] = value;
|
||||
ItemAdded(value);
|
||||
}
|
||||
}
|
||||
|
||||
private void ItemAdded(IPhysShape item)
|
||||
{
|
||||
_owner.ShapeAdded(item);
|
||||
}
|
||||
|
||||
public void ItemRemoved(IPhysShape item)
|
||||
{
|
||||
_owner.ShapeRemoved(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum BodyStatus: byte
|
||||
{
|
||||
@@ -512,15 +63,28 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sent whenever a <see cref="IPhysicsComponent"/> is changed.
|
||||
/// Sent whenever a <see cref="IPhysBody"/> is changed.
|
||||
/// </summary>
|
||||
public sealed class PhysicsUpdateMessage : EntitySystemMessage
|
||||
{
|
||||
public IPhysicsComponent Component { get; }
|
||||
public PhysicsComponent Component { get; }
|
||||
|
||||
public PhysicsUpdateMessage(IPhysicsComponent component)
|
||||
public PhysicsUpdateMessage(PhysicsComponent component)
|
||||
{
|
||||
Component = component;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class FixtureUpdateMessage : EntitySystemMessage
|
||||
{
|
||||
public PhysicsComponent Body { get; }
|
||||
|
||||
public Fixture Fixture { get; }
|
||||
|
||||
public FixtureUpdateMessage(PhysicsComponent body, Fixture fixture)
|
||||
{
|
||||
Body = body;
|
||||
Fixture = fixture;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Physics.Dynamics.Joints;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
@@ -10,10 +12,11 @@ namespace Robust.Shared.GameObjects
|
||||
public class PhysicsComponentState : ComponentState
|
||||
{
|
||||
public readonly bool CanCollide;
|
||||
public readonly bool SleepingAllowed;
|
||||
public readonly bool FixedRotation;
|
||||
public readonly BodyStatus Status;
|
||||
public readonly List<IPhysShape> PhysShapes;
|
||||
public readonly bool Hard;
|
||||
|
||||
public readonly List<Fixture> Fixtures;
|
||||
public readonly List<Joint> Joints;
|
||||
|
||||
/// <summary>
|
||||
/// Current mass of the entity, stored in grams.
|
||||
@@ -21,31 +24,45 @@ namespace Robust.Shared.GameObjects
|
||||
public readonly int Mass;
|
||||
public readonly Vector2 LinearVelocity;
|
||||
public readonly float AngularVelocity;
|
||||
public readonly bool Anchored;
|
||||
public readonly BodyType BodyType;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="canCollide"></param>
|
||||
/// <param name="sleepingAllowed"></param>
|
||||
/// <param name="fixedRotation"></param>
|
||||
/// <param name="status"></param>
|
||||
/// <param name="physShapes"></param>
|
||||
/// <param name="hard"></param>
|
||||
/// <param name="fixtures"></param>
|
||||
/// <param name="joints"></param>
|
||||
/// <param name="mass">Current Mass of the entity.</param>
|
||||
/// <param name="linearVelocity">Current linear velocity of the entity in meters per second.</param>
|
||||
/// <param name="angularVelocity">Current angular velocity of the entity in radians per sec.</param>
|
||||
/// <param name="anchored">Whether or not the entity is anchored in place.</param>
|
||||
public PhysicsComponentState(bool canCollide, BodyStatus status, List<IPhysShape> physShapes, bool hard, float mass, Vector2 linearVelocity, float angularVelocity, bool anchored)
|
||||
/// <param name="bodyType"></param>
|
||||
public PhysicsComponentState(
|
||||
bool canCollide,
|
||||
bool sleepingAllowed,
|
||||
bool fixedRotation,
|
||||
BodyStatus status,
|
||||
List<Fixture> fixtures,
|
||||
List<Joint> joints,
|
||||
float mass,
|
||||
Vector2 linearVelocity,
|
||||
float angularVelocity,
|
||||
BodyType bodyType)
|
||||
: base(NetIDs.PHYSICS)
|
||||
{
|
||||
CanCollide = canCollide;
|
||||
SleepingAllowed = sleepingAllowed;
|
||||
FixedRotation = fixedRotation;
|
||||
Status = status;
|
||||
PhysShapes = physShapes;
|
||||
Hard = hard;
|
||||
Fixtures = fixtures;
|
||||
Joints = joints;
|
||||
|
||||
LinearVelocity = linearVelocity;
|
||||
AngularVelocity = angularVelocity;
|
||||
Mass = (int)Math.Round(mass * 1000); // rounds kg to nearest gram
|
||||
Anchored = anchored;
|
||||
Mass = (int) Math.Round(mass * 1000); // rounds kg to nearest gram
|
||||
BodyType = bodyType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// An optimisation component for stuff that should be set as collidable when its awake and non-collidable when asleep.
|
||||
/// </summary>
|
||||
public sealed class CollisionWakeComponent : Component
|
||||
{
|
||||
public override string Name => "CollisionWake";
|
||||
}
|
||||
}
|
||||
@@ -20,16 +20,6 @@ namespace Robust.Shared.GameObjects
|
||||
public override void OnAdd() => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an exception in <see cref="ExposeData" />.
|
||||
/// </summary>
|
||||
public sealed class DebugExceptionExposeDataComponent : Component
|
||||
{
|
||||
public override string Name => "DebugExceptionExposeData";
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer) => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an exception in <see cref="Initialize" />.
|
||||
/// </summary>
|
||||
|
||||
@@ -13,7 +13,22 @@ namespace Robust.Shared.GameObjects
|
||||
public interface ITransformComponent : IComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Disables or enables to ability to locally rotate the entity. When set it removes any local rotation.
|
||||
/// Defer updates to the EntityTree and MoveEvent calls if toggled.
|
||||
/// </summary>
|
||||
bool DeferUpdates { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// While updating did we actually defer anything?
|
||||
/// </summary>
|
||||
bool UpdatesDeferred { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Run MoveEvent, RotateEvent, and UpdateEntityTree updates.
|
||||
/// </summary>
|
||||
void RunDeferred(Box2 worldAABB);
|
||||
|
||||
/// <summary>
|
||||
/// Disables or enables to ability to locally rotate the entity. When set it removes any local rotation.
|
||||
/// </summary>
|
||||
bool NoLocalRotation { get; set; }
|
||||
|
||||
@@ -103,25 +118,12 @@ namespace Robust.Shared.GameObjects
|
||||
/// </summary>
|
||||
GridId GridID { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether external system updates should run or not (e.g. EntityTree, Matrices, PhysicsTree).
|
||||
/// These should be manually run later.
|
||||
/// </summary>
|
||||
bool DeferUpdates { get; set; }
|
||||
bool UpdateEntityTree(Box2? worldAABB = null);
|
||||
|
||||
void AttachToGridOrMap();
|
||||
void AttachParent(ITransformComponent parent);
|
||||
void AttachParent(IEntity parent);
|
||||
|
||||
/// <summary>
|
||||
/// Run the updates marked as deferred (UpdateEntityTree and movement events).
|
||||
/// Don't call this unless you REALLY need to.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Physics optimisation so these aren't spammed during physics updates.
|
||||
/// </remarks>
|
||||
void RunPhysicsDeferred();
|
||||
|
||||
IEnumerable<ITransformComponent> Children { get; }
|
||||
int ChildCount { get; }
|
||||
IEnumerable<EntityUid> ChildEntityUids { get; }
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
@@ -12,7 +14,9 @@ namespace Robust.Shared.GameObjects
|
||||
public sealed override string Name => "Occluder";
|
||||
public sealed override uint? NetID => NetIDs.OCCLUDER;
|
||||
|
||||
[DataField("enabled")]
|
||||
private bool _enabled = true;
|
||||
[DataField("boundingBox")]
|
||||
private Box2 _boundingBox = new(-0.5f, -0.5f, 0.5f, 0.5f);
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
@@ -53,14 +57,6 @@ namespace Robust.Shared.GameObjects
|
||||
EntitySystem.Get<OccluderSystem>().AddOrUpdateEntity(Owner, Owner.Transform.Coordinates);
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _enabled, "enabled", true);
|
||||
serializer.DataField(ref _boundingBox, "boundingBox", new Box2(-0.5f, -0.5f, 0.5f, 0.5f));
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
base.OnRemove();
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Shared.GameObjects.Components.Localization
|
||||
@@ -14,27 +11,15 @@ namespace Robust.Shared.GameObjects.Components.Localization
|
||||
public override uint? NetID => NetIDs.GRAMMAR;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("localizationId")]
|
||||
public string LocalizationId = "";
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("gender")]
|
||||
public Gender? Gender = null;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("proper")]
|
||||
public bool? ProperNoun = null;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(ref LocalizationId, "localizationId", "");
|
||||
|
||||
if (serializer.TryReadDataFieldCached("gender", out string? gender0))
|
||||
{
|
||||
var refl = IoCManager.Resolve<IReflectionManager>();
|
||||
if (refl.TryParseEnumReference(gender0!, out var gender))
|
||||
{
|
||||
Gender = (Gender)gender;
|
||||
}
|
||||
}
|
||||
serializer.DataField(ref ProperNoun, "proper", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
@@ -19,7 +21,8 @@ namespace Robust.Shared.GameObjects
|
||||
public class MapComponent : Component, IMapComponent
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
private MapId _mapIndex;
|
||||
[DataField("index")]
|
||||
private MapId _mapIndex = MapId.Nullspace;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Map";
|
||||
@@ -59,14 +62,6 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
((TransformComponent) Owner.Transform).ChangeMapId(_mapIndex);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _mapIndex, "index", MapId.Nullspace);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
@@ -24,7 +26,8 @@ namespace Robust.Shared.GameObjects
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
private GridId _gridIndex;
|
||||
[DataField("index")]
|
||||
private GridId _gridIndex = GridId.Invalid;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "MapGrid";
|
||||
@@ -80,14 +83,6 @@ namespace Robust.Shared.GameObjects
|
||||
_gridIndex = state.GridIndex;
|
||||
Grid.HasGravity = state.HasGravity;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _gridIndex, "index", GridId.Invalid);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -3,6 +3,7 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
@@ -68,7 +69,9 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypes = default!;
|
||||
|
||||
[DataField("name")]
|
||||
private string? _entityName;
|
||||
[DataField("desc")]
|
||||
private string? _entityDescription;
|
||||
private EntityPrototype? _entityPrototype;
|
||||
|
||||
@@ -160,18 +163,6 @@ namespace Robust.Shared.GameObjects
|
||||
_entityPrototype = _prototypes.Index<EntityPrototype>(state.PrototypeId);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _entityName, "name", null);
|
||||
serializer.DataField(ref _entityDescription, "desc", null);
|
||||
//serializer.DataField(ref _entityPrototype, "proto", null,
|
||||
// s => _prototypes.Index<EntityPrototype>(s),
|
||||
// p => p.ID);
|
||||
}
|
||||
|
||||
internal override void ClearTicks()
|
||||
{
|
||||
// Do not clear modified ticks.
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
@@ -54,16 +55,26 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected struct PrototypeLayerData : IExposeData
|
||||
[DataDefinition]
|
||||
public class PrototypeLayerData
|
||||
{
|
||||
[DataField("shader")]
|
||||
public string? Shader;
|
||||
[DataField("texture")]
|
||||
public string? TexturePath;
|
||||
[DataField("sprite")]
|
||||
public string? RsiPath;
|
||||
[DataField("state")]
|
||||
public string? State;
|
||||
public Vector2 Scale;
|
||||
public Angle Rotation;
|
||||
public bool Visible;
|
||||
public Color Color;
|
||||
[DataField("scale")]
|
||||
public Vector2 Scale = Vector2.One;
|
||||
[DataField("rotation")]
|
||||
public Angle Rotation = Angle.Zero;
|
||||
[DataField("visible")]
|
||||
public bool Visible = true;
|
||||
[DataField("color")]
|
||||
public Color Color = Color.White;
|
||||
[DataField("map")]
|
||||
public List<string>? MapKeys;
|
||||
|
||||
public static PrototypeLayerData New()
|
||||
@@ -75,19 +86,6 @@ namespace Robust.Shared.GameObjects
|
||||
Visible = true,
|
||||
};
|
||||
}
|
||||
|
||||
void IExposeData.ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(ref Shader, "shader", null);
|
||||
serializer.DataField(ref TexturePath, "texture", null);
|
||||
serializer.DataField(ref RsiPath, "sprite", null);
|
||||
serializer.DataField(ref State, "state", null);
|
||||
serializer.DataField(ref Scale, "scale", Vector2.One);
|
||||
serializer.DataField(ref Rotation, "rotation", Angle.Zero);
|
||||
serializer.DataField(ref Visible, "visible", true);
|
||||
serializer.DataField(ref Color, "color", Color.White);
|
||||
serializer.DataField(ref MapKeys, "map", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
@@ -19,6 +21,7 @@ namespace Robust.Shared.GameObjects
|
||||
public sealed override string Name => "SnapGrid";
|
||||
|
||||
private bool IsSet;
|
||||
[DataField("offset")]
|
||||
private SnapGridOffset _offset = SnapGridOffset.Center;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
@@ -53,13 +56,6 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataFieldCached(ref _offset, "offset", SnapGridOffset.Center);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerable over all the entities which are one tile over in a certain direction.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Animations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
@@ -15,9 +18,13 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
internal class TransformComponent : Component, ITransformComponent, IComponentDebug
|
||||
{
|
||||
[DataField("parent")]
|
||||
private EntityUid _parent;
|
||||
private Vector2 _localPosition; // holds offset from grid, or offset from parent
|
||||
[DataField("pos")]
|
||||
private Vector2 _localPosition = Vector2.Zero; // holds offset from grid, or offset from parent
|
||||
[DataField("rot")]
|
||||
private Angle _localRotation; // local rotation
|
||||
[DataField("noRot")]
|
||||
private bool _noLocalRotation;
|
||||
|
||||
private Matrix3 _localMatrix = Matrix3.Identity;
|
||||
@@ -29,13 +36,18 @@ namespace Robust.Shared.GameObjects
|
||||
private Vector2 _prevPosition;
|
||||
private Angle _prevRotation;
|
||||
|
||||
// Cache changes so we can distribute them after physics is done (better cache)
|
||||
private EntityCoordinates? _oldCoords;
|
||||
private Angle? _oldLocalRotation;
|
||||
|
||||
public bool UpdatesDeferred => _oldCoords != null || _oldLocalRotation != null;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool ActivelyLerping { get; set; }
|
||||
|
||||
[ViewVariables] private readonly SortedSet<EntityUid> _children = new();
|
||||
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Transform";
|
||||
@@ -49,6 +61,7 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
private bool _mapIdInitialized;
|
||||
|
||||
public bool DeferUpdates { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables]
|
||||
@@ -73,13 +86,6 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool DeferUpdates { get; set; }
|
||||
|
||||
// Deferred fields
|
||||
private Angle? _oldLocalRotation;
|
||||
private EntityCoordinates? _oldCoords;
|
||||
|
||||
/// <inheritdoc />
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool NoLocalRotation
|
||||
@@ -120,7 +126,6 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
RebuildMatrices();
|
||||
UpdateEntityTree();
|
||||
UpdatePhysicsTree();
|
||||
Owner.EntityManager.EventBus.RaiseEvent(
|
||||
EventSource.Local, new RotateEvent(Owner, oldRotation, _localRotation));
|
||||
}
|
||||
@@ -176,7 +181,7 @@ namespace Robust.Shared.GameObjects
|
||||
public EntityUid ParentUid
|
||||
{
|
||||
get => _parent;
|
||||
set => Parent = _entityManager.GetEntity(value).Transform;
|
||||
set => Parent = Owner.EntityManager.GetEntity(value).Transform;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -265,7 +270,7 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
if (value.EntityId != _parent)
|
||||
{
|
||||
var newEntity = _entityManager.GetEntity(value.EntityId);
|
||||
var newEntity = Owner.EntityManager.GetEntity(value.EntityId);
|
||||
AttachParent(newEntity);
|
||||
}
|
||||
|
||||
@@ -283,7 +288,6 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
|
||||
UpdateEntityTree();
|
||||
UpdatePhysicsTree();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -316,7 +320,6 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
RebuildMatrices();
|
||||
UpdateEntityTree();
|
||||
UpdatePhysicsTree();
|
||||
Owner.EntityManager.EventBus.RaiseEvent(
|
||||
EventSource.Local, new MoveEvent(Owner, oldGridPos, Coordinates));
|
||||
}
|
||||
@@ -327,35 +330,6 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void RunPhysicsDeferred()
|
||||
{
|
||||
// if we resolved to (close enough) to the OG position then no update.
|
||||
if ((_oldCoords == null || _oldCoords.Equals(Coordinates)) &&
|
||||
(_oldLocalRotation == null || _oldLocalRotation.Equals(_localRotation)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RebuildMatrices();
|
||||
UpdateEntityTree();
|
||||
UpdatePhysicsTree();
|
||||
|
||||
if (_oldCoords != null)
|
||||
{
|
||||
Owner.EntityManager.EventBus.RaiseEvent(
|
||||
EventSource.Local, new MoveEvent(Owner, _oldCoords.Value, Coordinates));
|
||||
_oldCoords = null;
|
||||
}
|
||||
|
||||
if (_oldLocalRotation != null)
|
||||
{
|
||||
Owner.EntityManager.EventBus.RaiseEvent(
|
||||
EventSource.Local, new RotateEvent(Owner, _oldLocalRotation.Value, _localRotation));
|
||||
_oldLocalRotation = null;
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
public IEnumerable<ITransformComponent> Children =>
|
||||
_children.Select(u => Owner.EntityManager.GetEntity(u).Transform);
|
||||
@@ -478,6 +452,33 @@ namespace Robust.Shared.GameObjects
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
public void RunDeferred(Box2 worldAABB)
|
||||
{
|
||||
// if we resolved to (close enough) to the OG position then no update.
|
||||
if ((_oldCoords == null || _oldCoords.Equals(Coordinates)) &&
|
||||
(_oldLocalRotation == null || _oldLocalRotation.Equals(_localRotation)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RebuildMatrices();
|
||||
UpdateEntityTree(worldAABB);
|
||||
|
||||
if (_oldCoords != null)
|
||||
{
|
||||
Owner.EntityManager.EventBus.RaiseEvent(
|
||||
EventSource.Local, new MoveEvent(Owner, _oldCoords.Value, Coordinates, worldAABB));
|
||||
_oldCoords = null;
|
||||
}
|
||||
|
||||
if (_oldLocalRotation != null)
|
||||
{
|
||||
Owner.EntityManager.EventBus.RaiseEvent(
|
||||
EventSource.Local, new RotateEvent(Owner, _oldLocalRotation.Value, _localRotation, worldAABB));
|
||||
_oldLocalRotation = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detaches this entity from its parent.
|
||||
/// </summary>
|
||||
@@ -495,7 +496,7 @@ namespace Robust.Shared.GameObjects
|
||||
IEntity newMapEntity;
|
||||
if (_mapManager.TryFindGridAt(mapPos, out var mapGrid))
|
||||
{
|
||||
newMapEntity = _entityManager.GetEntity(mapGrid.GridEntityId);
|
||||
newMapEntity = Owner.EntityManager.GetEntity(mapGrid.GridEntityId);
|
||||
}
|
||||
else if (_mapManager.HasMapEntity(mapPos.MapId))
|
||||
{
|
||||
@@ -516,7 +517,10 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
AttachParent(newMapEntity);
|
||||
|
||||
// Technically we're not moving, just changing parent.
|
||||
DeferUpdates = true;
|
||||
WorldPosition = mapPos.Position;
|
||||
DeferUpdates = false;
|
||||
|
||||
Dirty();
|
||||
}
|
||||
@@ -627,24 +631,12 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
private void MapIdChanged(MapId oldId)
|
||||
{
|
||||
IPhysicsComponent? collider;
|
||||
|
||||
if (oldId != MapId.Nullspace)
|
||||
{
|
||||
_entityManager.RemoveFromEntityTree(Owner, oldId);
|
||||
|
||||
if (Initialized && Owner.TryGetComponent(out collider))
|
||||
{
|
||||
collider.RemovedFromPhysicsTree(oldId);
|
||||
}
|
||||
Owner.EntityManager.RemoveFromEntityTree(Owner, oldId);
|
||||
}
|
||||
|
||||
if (MapID != MapId.Nullspace && Initialized && Owner.TryGetComponent(out collider))
|
||||
{
|
||||
collider.AddedToPhysicsTree(MapID);
|
||||
}
|
||||
|
||||
_entityManager.EventBus.RaiseEvent(EventSource.Local, new EntMapIdChangedMessage(Owner, oldId));
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new EntMapIdChangedMessage(Owner, oldId));
|
||||
}
|
||||
|
||||
public void AttachParent(IEntity parent)
|
||||
@@ -689,16 +681,6 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _parent, "parent", new EntityUid());
|
||||
serializer.DataField(ref _localPosition, "pos", Vector2.Zero);
|
||||
serializer.DataField(ref _localRotation, "rot", new Angle());
|
||||
serializer.DataField(ref _noLocalRotation, "noRot", false);
|
||||
}
|
||||
|
||||
/// <param name="player"></param>
|
||||
/// <inheritdoc />
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
@@ -760,7 +742,6 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
Dirty();
|
||||
UpdateEntityTree();
|
||||
TryUpdatePhysicsTree();
|
||||
}
|
||||
|
||||
if (nextState is TransformComponentState nextTransform)
|
||||
@@ -782,6 +763,7 @@ namespace Robust.Shared.GameObjects
|
||||
// Hooks for GodotTransformComponent go here.
|
||||
protected virtual void SetPosition(Vector2 position)
|
||||
{
|
||||
// DebugTools.Assert(!float.IsNaN(position.X) && !float.IsNaN(position.Y));
|
||||
_localPosition = position;
|
||||
}
|
||||
|
||||
@@ -824,12 +806,7 @@ namespace Robust.Shared.GameObjects
|
||||
_invLocalMatrix = itransMat;
|
||||
}
|
||||
|
||||
private bool TryUpdatePhysicsTree() => Initialized && UpdatePhysicsTree();
|
||||
|
||||
private bool UpdatePhysicsTree() =>
|
||||
Owner.TryGetComponent(out IPhysicsComponent? collider) && collider.UpdatePhysicsTree();
|
||||
|
||||
private bool UpdateEntityTree() => _entityManager.UpdateEntityTree(Owner);
|
||||
public bool UpdateEntityTree(Box2? worldAABB = null) => Owner.EntityManager.UpdateEntityTree(Owner, worldAABB);
|
||||
|
||||
public string GetDebugString()
|
||||
{
|
||||
@@ -879,6 +856,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// <param name="localPosition">Current position offset of this entity.</param>
|
||||
/// <param name="rotation">Current direction offset of this entity.</param>
|
||||
/// <param name="parentId">Current parent transform of this entity.</param>
|
||||
/// <param name="noLocalRotation"></param>
|
||||
public TransformComponentState(Vector2 localPosition, Angle rotation, EntityUid parentId, bool noLocalRotation)
|
||||
: base(NetIDs.TRANSFORM)
|
||||
{
|
||||
@@ -890,32 +868,50 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised whenever an entity moves.
|
||||
/// There is no guarantee it will be raised if they move in worldspace, only when moved relative to their parent.
|
||||
/// </summary>
|
||||
public class MoveEvent : EntitySystemMessage
|
||||
{
|
||||
public MoveEvent(IEntity sender, EntityCoordinates oldPos, EntityCoordinates newPos)
|
||||
public MoveEvent(IEntity sender, EntityCoordinates oldPos, EntityCoordinates newPos, Box2? worldAABB = null)
|
||||
{
|
||||
Sender = sender;
|
||||
OldPosition = oldPos;
|
||||
NewPosition = newPos;
|
||||
WorldAABB = worldAABB;
|
||||
}
|
||||
|
||||
public IEntity Sender { get; }
|
||||
public EntityCoordinates OldPosition { get; }
|
||||
public EntityCoordinates NewPosition { get; }
|
||||
public bool Handled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// New AABB of the entity.
|
||||
/// </summary>
|
||||
public Box2? WorldAABB { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised whenever this entity rotates in relation to their parent.
|
||||
/// </summary>
|
||||
public class RotateEvent : EntitySystemMessage
|
||||
{
|
||||
public RotateEvent(IEntity sender, Angle oldRotation, Angle newRotation)
|
||||
public RotateEvent(IEntity sender, Angle oldRotation, Angle newRotation, Box2? worldAABB = null)
|
||||
{
|
||||
Sender = sender;
|
||||
OldRotation = oldRotation;
|
||||
NewRotation = newRotation;
|
||||
WorldAABB = worldAABB;
|
||||
}
|
||||
|
||||
public IEntity Sender { get; }
|
||||
public Angle OldRotation { get; }
|
||||
public Angle NewRotation { get; }
|
||||
/// <summary>
|
||||
/// New AABB of the entity.
|
||||
/// </summary>
|
||||
public Box2? WorldAABB { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
@@ -8,15 +11,28 @@ namespace Robust.Shared.GameObjects
|
||||
public sealed override string Name => "UserInterface";
|
||||
public sealed override uint? NetID => NetIDs.USERINTERFACE;
|
||||
|
||||
protected sealed class PrototypeData : IExposeData
|
||||
[DataDefinition]
|
||||
public sealed class PrototypeData : ISerializationHooks
|
||||
{
|
||||
public object UiKey { get; private set; } = default!;
|
||||
public string ClientType { get; private set; } = default!;
|
||||
public object UiKey { get; set; } = default!;
|
||||
|
||||
void IExposeData.ExposeData(ObjectSerializer serializer)
|
||||
[DataField("key", readOnly: true, required: true)]
|
||||
private string _uiKeyRaw = default!;
|
||||
|
||||
[DataField("type", readOnly: true, required: true)]
|
||||
public string ClientType { get; set; } = default!;
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
UiKey = serializer.ReadStringEnumKey("key");
|
||||
ClientType = serializer.ReadDataField<string>("type");
|
||||
var reflectionManager = IoCManager.Resolve<IReflectionManager>();
|
||||
|
||||
if (reflectionManager.TryParseEnumReference(_uiKeyRaw, out var @enum))
|
||||
{
|
||||
UiKey = @enum;
|
||||
return;
|
||||
}
|
||||
|
||||
UiKey = _uiKeyRaw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
@@ -129,7 +130,7 @@ namespace Robust.Shared.GameObjects
|
||||
.OrderBy(x => x switch
|
||||
{
|
||||
ITransformComponent _ => 0,
|
||||
IPhysicsComponent _ => 1,
|
||||
IPhysBody _ => 1,
|
||||
_ => int.MaxValue
|
||||
});
|
||||
|
||||
@@ -168,7 +169,7 @@ namespace Robust.Shared.GameObjects
|
||||
.OrderBy(x => x switch
|
||||
{
|
||||
ITransformComponent _ => 0,
|
||||
IPhysicsComponent _ => 1,
|
||||
IPhysBody _ => 1,
|
||||
_ => int.MaxValue
|
||||
});
|
||||
|
||||
|
||||
@@ -476,9 +476,9 @@ namespace Robust.Shared.GameObjects
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IEntity> GetEntitiesIntersecting(IEntity entity, bool approximate = false)
|
||||
{
|
||||
if (entity.TryGetComponent<IPhysicsComponent>(out var component))
|
||||
if (entity.TryGetComponent<IPhysBody>(out var component))
|
||||
{
|
||||
return GetEntitiesIntersecting(entity.Transform.MapID, component.WorldAABB, approximate);
|
||||
return GetEntitiesIntersecting(entity.Transform.MapID, component.GetWorldAABB(), approximate);
|
||||
}
|
||||
|
||||
return GetEntitiesIntersecting(entity.Transform.Coordinates, approximate);
|
||||
@@ -493,9 +493,9 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
private static bool Intersecting(IEntity entity, Vector2 mapPosition)
|
||||
{
|
||||
if (entity.TryGetComponent(out IPhysicsComponent? component))
|
||||
if (entity.TryGetComponent(out IPhysBody? component))
|
||||
{
|
||||
if (component.WorldAABB.Contains(mapPosition))
|
||||
if (component.GetWorldAABB().Contains(mapPosition))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -539,9 +539,9 @@ namespace Robust.Shared.GameObjects
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IEntity> GetEntitiesInRange(IEntity entity, float range, bool approximate = false)
|
||||
{
|
||||
if (entity.TryGetComponent<IPhysicsComponent>(out var component))
|
||||
if (entity.TryGetComponent<IPhysBody>(out var component))
|
||||
{
|
||||
return GetEntitiesInRange(entity.Transform.MapID, component.WorldAABB, range, approximate);
|
||||
return GetEntitiesInRange(entity.Transform.MapID, component.GetWorldAABB(), range, approximate);
|
||||
}
|
||||
|
||||
return GetEntitiesInRange(entity.Transform.Coordinates, range, approximate);
|
||||
@@ -570,7 +570,7 @@ namespace Robust.Shared.GameObjects
|
||||
private readonly Dictionary<MapId, DynamicTree<IEntity>> _entityTreesPerMap =
|
||||
new();
|
||||
|
||||
public virtual bool UpdateEntityTree(IEntity entity)
|
||||
public virtual bool UpdateEntityTree(IEntity entity, Box2? worldAABB = null)
|
||||
{
|
||||
if (entity.Deleted)
|
||||
{
|
||||
@@ -591,14 +591,18 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
if (!_entityTreesPerMap.TryGetValue(mapId, out var entTree))
|
||||
{
|
||||
entTree = EntityTreeFactory();
|
||||
entTree = new DynamicTree<IEntity>(
|
||||
GetWorldAabbFromEntity,
|
||||
capacity: 16,
|
||||
growthFunc: x => x == 16 ? 3840 : x + 256
|
||||
);
|
||||
_entityTreesPerMap.Add(mapId, entTree);
|
||||
}
|
||||
|
||||
// for debugging
|
||||
var necessary = 0;
|
||||
|
||||
if (entTree.AddOrUpdate(entity))
|
||||
if (entTree.AddOrUpdate(entity, worldAABB))
|
||||
{
|
||||
++necessary;
|
||||
}
|
||||
@@ -635,20 +639,13 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
private static DynamicTree<IEntity> EntityTreeFactory() =>
|
||||
new(
|
||||
GetWorldAabbFromEntity,
|
||||
capacity: 16,
|
||||
growthFunc: x => x == 16 ? 3840 : x + 256
|
||||
);
|
||||
|
||||
protected static Box2 GetWorldAabbFromEntity(in IEntity ent)
|
||||
protected Box2 GetWorldAabbFromEntity(in IEntity ent)
|
||||
{
|
||||
if (ent.Deleted)
|
||||
return new Box2(0, 0, 0, 0);
|
||||
|
||||
if (ent.TryGetComponent(out IPhysicsComponent? collider))
|
||||
return collider.WorldAABB;
|
||||
if (ent.TryGetComponent(out IPhysBody? collider))
|
||||
return collider.GetWorldAABB(_mapManager);
|
||||
|
||||
var pos = ent.Transform.WorldPosition;
|
||||
return new Box2(pos, pos);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
@@ -120,9 +121,9 @@ namespace Robust.Shared.GameObjects
|
||||
/// <inheritdoc />
|
||||
public bool Match(IEntity entity)
|
||||
{
|
||||
if(Entity.TryGetComponent<IPhysicsComponent>(out var physics))
|
||||
if(Entity.TryGetComponent<IPhysBody>(out var physics))
|
||||
{
|
||||
return physics.MapID == entity.Transform.MapID && physics.WorldAABB.Contains(entity.Transform.WorldPosition);
|
||||
return physics.MapID == entity.Transform.MapID && physics.GetWorldAABB().Contains(entity.Transform.WorldPosition);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -158,12 +158,12 @@ namespace Robust.Shared.GameObjects
|
||||
private static (IEnumerable<IEntitySystem> frameUpd, IEnumerable<IEntitySystem> upd)
|
||||
CalculateUpdateOrder(Dictionary<Type, IEntitySystem>.ValueCollection systems)
|
||||
{
|
||||
var allNodes = new List<GraphNode>();
|
||||
var typeToNode = new Dictionary<Type, GraphNode>();
|
||||
var allNodes = new List<GraphNode<IEntitySystem>>();
|
||||
var typeToNode = new Dictionary<Type, GraphNode<IEntitySystem>>();
|
||||
|
||||
foreach (var system in systems)
|
||||
{
|
||||
var node = new GraphNode(system);
|
||||
var node = new GraphNode<IEntitySystem>(system);
|
||||
|
||||
allNodes.Add(node);
|
||||
typeToNode.Add(system.GetType(), node);
|
||||
@@ -193,10 +193,10 @@ namespace Robust.Shared.GameObjects
|
||||
return (frameUpdate, update);
|
||||
}
|
||||
|
||||
private static IEnumerable<GraphNode> TopologicalSort(IEnumerable<GraphNode> nodes)
|
||||
internal static IEnumerable<GraphNode<T>> TopologicalSort<T>(IEnumerable<GraphNode<T>> nodes)
|
||||
{
|
||||
var elems = nodes.ToDictionary(node => node,
|
||||
node => new HashSet<GraphNode>(node.DependsOn));
|
||||
node => new HashSet<GraphNode<T>>(node.DependsOn));
|
||||
while (elems.Count > 0)
|
||||
{
|
||||
var elem =
|
||||
@@ -331,12 +331,12 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
|
||||
[DebuggerDisplay("GraphNode: {" + nameof(System) + "}")]
|
||||
private sealed class GraphNode
|
||||
internal sealed class GraphNode<T>
|
||||
{
|
||||
public readonly IEntitySystem System;
|
||||
public readonly List<GraphNode> DependsOn = new();
|
||||
public readonly T System;
|
||||
public readonly List<GraphNode<T>> DependsOn = new();
|
||||
|
||||
public GraphNode(IEntitySystem system)
|
||||
public GraphNode(T system)
|
||||
{
|
||||
System = system;
|
||||
}
|
||||
|
||||
@@ -100,13 +100,6 @@ namespace Robust.Shared.GameObjects
|
||||
/// </summary>
|
||||
void Initialize();
|
||||
|
||||
/// <summary>
|
||||
/// This allows setting of the component's parameters from YAML once it is instantiated.
|
||||
/// This should basically be overridden by every inheriting component, as parameters will be different
|
||||
/// across the board.
|
||||
/// </summary>
|
||||
void ExposeData(ObjectSerializer serializer);
|
||||
|
||||
/// <summary>
|
||||
/// Handles a local incoming component message.
|
||||
/// </summary>
|
||||
|
||||
@@ -3,10 +3,12 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
[CopyByRef]
|
||||
public interface IEntity
|
||||
{
|
||||
GameTick LastModifiedTick { get; }
|
||||
@@ -40,7 +42,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// True if the entity has been deleted.
|
||||
/// </summary>
|
||||
bool Deleted { get; }
|
||||
|
||||
|
||||
bool Paused { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
@@ -12,11 +14,11 @@ namespace Robust.Shared.GameObjects
|
||||
/// <summary>
|
||||
/// Gets the serializer used to ExposeData a specific component.
|
||||
/// </summary>
|
||||
ObjectSerializer GetComponentSerializer(string componentName, YamlMappingNode? protoData);
|
||||
IComponent GetComponentData(string componentName, IComponent? protoData);
|
||||
|
||||
/// <summary>
|
||||
/// Gets extra component names that must also be instantiated on top of the ones defined in the prototype,
|
||||
/// (and then deserialized with <see cref="GetComponentSerializer"/>)
|
||||
/// (and then deserialized with <see cref="GetComponentData"/>)
|
||||
/// </summary>
|
||||
IEnumerable<string> GetExtraComponentTypes();
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// <param name="range"></param>
|
||||
/// <param name="approximate">If true, will not recalculate precise entity AABBs, resulting in a perf increase. </param>
|
||||
IEnumerable<IEntity> GetEntitiesInRange(EntityCoordinates position, float range, bool approximate = false);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets entities within a certain *square* range of this entity
|
||||
/// </summary>
|
||||
@@ -218,7 +218,7 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
#region Spatial Updates
|
||||
|
||||
bool UpdateEntityTree(IEntity entity);
|
||||
bool UpdateEntityTree(IEntity entity, Box2? worldAABB = null);
|
||||
bool RemoveFromEntityTree(IEntity entity, MapId mapId);
|
||||
|
||||
#endregion
|
||||
|
||||
33
Robust.Shared/GameObjects/Systems/CollisionWakeSystem.cs
Normal file
33
Robust.Shared/GameObjects/Systems/CollisionWakeSystem.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Robust.Shared.Physics;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
public class CollisionWakeSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<PhysicsWakeMessage>(HandleWake);
|
||||
SubscribeLocalEvent<PhysicsSleepMessage>(HandleSleep);
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
UnsubscribeLocalEvent<PhysicsWakeMessage>();
|
||||
UnsubscribeLocalEvent<PhysicsSleepMessage>();
|
||||
}
|
||||
|
||||
private void HandleWake(PhysicsWakeMessage message)
|
||||
{
|
||||
if (!message.Body.Owner.HasComponent<CollisionWakeComponent>()) return;
|
||||
message.Body.CanCollide = true;
|
||||
}
|
||||
|
||||
private void HandleSleep(PhysicsSleepMessage message)
|
||||
{
|
||||
if (!message.Body.Owner.HasComponent<CollisionWakeComponent>()) return;
|
||||
message.Body.CanCollide = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Robust.Shared.Physics.Collision;
|
||||
using Robust.Shared.Physics.Dynamics.Contacts;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Only reason this exists is so we can avoid the message allocation when not needed.
|
||||
/// It's only useful for debugging and is kind of a perf sink.
|
||||
/// </summary>
|
||||
public class SharedDebugPhysicsSystem : EntitySystem
|
||||
{
|
||||
public virtual void HandlePreSolve(Contact contact, in Manifold oldManifold) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles moving entities between grids as they move around.
|
||||
/// </summary>
|
||||
internal sealed class SharedGridTraversalSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
private Queue<MoveEvent> _queuedMoveEvents = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<MoveEvent>(QueueMoveEvent);
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
UnsubscribeLocalEvent<MoveEvent>();
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
while (_queuedMoveEvents.Count > 0)
|
||||
{
|
||||
var moveEvent = _queuedMoveEvents.Dequeue();
|
||||
var entity = moveEvent.Sender;
|
||||
|
||||
if (entity.Deleted || !entity.HasComponent<PhysicsComponent>() || entity.IsInContainer()) continue;
|
||||
|
||||
var transform = entity.Transform;
|
||||
// Change parent if necessary
|
||||
// Given islands will probably have a bunch of static bodies in them then we'll verify velocities first as it's way cheaper
|
||||
|
||||
// This shoouullddnnn'''tt de-parent anything in a container because none of that should have physics applied to it.
|
||||
if (_mapManager.TryFindGridAt(transform.MapID, moveEvent.NewPosition.ToMapPos(EntityManager), out var grid) &&
|
||||
grid.GridEntityId.IsValid() &&
|
||||
grid.GridEntityId != entity.Uid)
|
||||
{
|
||||
// Also this may deparent if 2 entities are parented but not using containers so fix that
|
||||
if (grid.GridEntityId != transform.ParentUid)
|
||||
{
|
||||
transform.AttachParent(EntityManager.GetEntity(grid.GridEntityId));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.AttachParent(_mapManager.GetMapEntity(transform.MapID));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void QueueMoveEvent(MoveEvent moveEvent)
|
||||
{
|
||||
_queuedMoveEvents.Enqueue(moveEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,105 +2,250 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Physics.Collision;
|
||||
using Robust.Shared.Physics.Controllers;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Reflection;
|
||||
using DependencyAttribute = Robust.Shared.IoC.DependencyAttribute;
|
||||
using Logger = Robust.Shared.Log.Logger;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
public abstract class SharedPhysicsSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||
/*
|
||||
* TODO:
|
||||
* Port acruid's box solver in to reduce allocs for building manifolds (this one is important for perf to remove the disgusting ctors and casts)
|
||||
* Raycasts for non-box shapes.
|
||||
* SetTransformIgnoreContacts for teleports (and anything else left on the physics body in Farseer)
|
||||
* Actual center of mass for shapes (currently just assumes center coordinate)
|
||||
* Circle offsets to entity.
|
||||
* TOI Solver (continuous collision detection)
|
||||
* Poly cutting
|
||||
* Chain shape
|
||||
* (Content) grenade launcher grenades that explode after time rather than impact.
|
||||
* pulling prediction
|
||||
* PVS + Collide allocations / performance
|
||||
* When someone yeets out of disposals need to have no collision on that object until they stop colliding
|
||||
* A bunch of objects have collision on round start
|
||||
* Need a way to specify conditional non-hard collisions (i.e. so items collide with players for IThrowCollide but can still be moved through freely but walls can't collide with them)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Multi-threading notes:
|
||||
* Sources:
|
||||
* https://github.com/VelcroPhysics/VelcroPhysics/issues/29
|
||||
* Aether2D
|
||||
* Rapier
|
||||
* https://www.slideshare.net/takahiroharada/solver-34909157
|
||||
*
|
||||
* SO essentially what we should look at doing from what I can discern:
|
||||
* Build islands sequentially and then solve them all in parallel (as static bodies are the only thing shared
|
||||
* it should be okay given they're never written to)
|
||||
* After this, we can then look at doing narrowphase in parallel maybe (at least Aether2D does it) +
|
||||
* position constraints in parallel + velocity constraints in parallel
|
||||
*
|
||||
* The main issue to tackle is graph colouring; Aether2D just seems to use locks for the parallel constraints solver
|
||||
* though rapier has a graph colouring implementation (and because of this we should be able to avoid using locks) which we could try using.
|
||||
*
|
||||
* Given the kind of game SS14 is (our target game I guess) parallelising the islands will probably be the biggest benefit.
|
||||
*/
|
||||
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IPhysicsManager _physicsManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
private const float Epsilon = 1.0e-6f;
|
||||
public IReadOnlyDictionary<MapId, PhysicsMap> Maps => _maps;
|
||||
private Dictionary<MapId, PhysicsMap> _maps = new();
|
||||
|
||||
private readonly List<Manifold> _collisionCache = new();
|
||||
internal IReadOnlyList<VirtualController> Controllers => _controllers;
|
||||
private List<VirtualController> _controllers = new();
|
||||
|
||||
/// <summary>
|
||||
/// Physics objects that are awake and usable for world simulation.
|
||||
/// </summary>
|
||||
private readonly HashSet<IPhysicsComponent> _awakeBodies = new();
|
||||
|
||||
/// <summary>
|
||||
/// Physics objects that are awake and predicted and usable for world simulation.
|
||||
/// </summary>
|
||||
private readonly HashSet<IPhysicsComponent> _predictedAwakeBodies = new();
|
||||
|
||||
/// <summary>
|
||||
/// VirtualControllers on applicable <see cref="IPhysicsComponent"/>s
|
||||
/// </summary>
|
||||
private Dictionary<IPhysicsComponent, IEnumerable<VirtualController>> _controllers =
|
||||
new();
|
||||
|
||||
// We'll defer changes to IPhysicsComponent until each step is done.
|
||||
private readonly List<IPhysicsComponent> _queuedDeletions = new();
|
||||
private readonly List<IPhysicsComponent> _queuedUpdates = new();
|
||||
|
||||
/// <summary>
|
||||
/// Updates to EntityTree etc. that are deferred until the end of physics.
|
||||
/// </summary>
|
||||
private readonly HashSet<IPhysicsComponent> _deferredUpdates = new();
|
||||
|
||||
// CVars aren't replicated to client (yet) so not using a cvar server-side for this.
|
||||
private float _speedLimit = 30.0f;
|
||||
public Action<IPhysBody, IPhysBody, float, Manifold>? KinematicControllerCollision;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
// Having a nullspace map just makes a bunch of code easier, we just don't iterate on it.
|
||||
var nullMap = new PhysicsMap(MapId.Nullspace);
|
||||
_maps[MapId.Nullspace] = nullMap;
|
||||
nullMap.Initialize();
|
||||
|
||||
_mapManager.MapCreated += HandleMapCreated;
|
||||
_mapManager.MapDestroyed += HandleMapDestroyed;
|
||||
|
||||
SubscribeLocalEvent<PhysicsUpdateMessage>(HandlePhysicsUpdateMessage);
|
||||
SubscribeLocalEvent<PhysicsWakeMessage>(HandleWakeMessage);
|
||||
SubscribeLocalEvent<PhysicsSleepMessage>(HandleSleepMessage);
|
||||
SubscribeLocalEvent<EntMapIdChangedMessage>(HandleMapChange);
|
||||
|
||||
SubscribeLocalEvent<EntInsertedIntoContainerMessage>(HandleContainerInserted);
|
||||
SubscribeLocalEvent<EntRemovedFromContainerMessage>(HandleContainerRemoved);
|
||||
BuildControllers();
|
||||
Logger.DebugS("physics", $"Found {_controllers.Count} physics controllers.");
|
||||
}
|
||||
|
||||
private void BuildControllers()
|
||||
{
|
||||
var reflectionManager = IoCManager.Resolve<IReflectionManager>();
|
||||
var typeFactory = IoCManager.Resolve<IDynamicTypeFactory>();
|
||||
var allControllerTypes = new List<Type>();
|
||||
|
||||
foreach (var type in reflectionManager.GetAllChildren(typeof(VirtualController)))
|
||||
{
|
||||
if (type.IsAbstract) continue;
|
||||
allControllerTypes.Add(type);
|
||||
}
|
||||
|
||||
var instantiated = new Dictionary<Type, VirtualController>();
|
||||
|
||||
foreach (var type in allControllerTypes)
|
||||
{
|
||||
instantiated.Add(type, (VirtualController) typeFactory.CreateInstance(type));
|
||||
}
|
||||
|
||||
// Build dependency graph, copied from EntitySystemManager *COUGH
|
||||
|
||||
var nodes = new Dictionary<Type, EntitySystemManager.GraphNode<VirtualController>>();
|
||||
|
||||
foreach (var (_, controller) in instantiated)
|
||||
{
|
||||
var node = new EntitySystemManager.GraphNode<VirtualController>(controller);
|
||||
nodes[controller.GetType()] = node;
|
||||
}
|
||||
|
||||
foreach (var (type, node) in nodes)
|
||||
{
|
||||
foreach (var before in instantiated[type].UpdatesBefore)
|
||||
{
|
||||
nodes[before].DependsOn.Add(node);
|
||||
}
|
||||
|
||||
foreach (var after in instantiated[type].UpdatesAfter)
|
||||
{
|
||||
node.DependsOn.Add(nodes[after]);
|
||||
}
|
||||
}
|
||||
|
||||
_controllers = GameObjects.EntitySystemManager.TopologicalSort(nodes.Values).Select(c => c.System).ToList();
|
||||
|
||||
foreach (var controller in _controllers)
|
||||
{
|
||||
controller.Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
|
||||
_mapManager.MapCreated -= HandleMapCreated;
|
||||
_mapManager.MapDestroyed -= HandleMapDestroyed;
|
||||
|
||||
UnsubscribeLocalEvent<PhysicsUpdateMessage>();
|
||||
UnsubscribeLocalEvent<PhysicsWakeMessage>();
|
||||
UnsubscribeLocalEvent<PhysicsSleepMessage>();
|
||||
UnsubscribeLocalEvent<EntMapIdChangedMessage>();
|
||||
|
||||
UnsubscribeLocalEvent<EntInsertedIntoContainerMessage>();
|
||||
UnsubscribeLocalEvent<EntRemovedFromContainerMessage>();
|
||||
}
|
||||
|
||||
private void HandleMapCreated(object? sender, MapEventArgs eventArgs)
|
||||
{
|
||||
// Server just creates nullspace map on its own but sends it to client hence we will just ignore it.
|
||||
if (_maps.ContainsKey(eventArgs.Map)) return;
|
||||
|
||||
var map = new PhysicsMap(eventArgs.Map);
|
||||
_maps.Add(eventArgs.Map, map);
|
||||
map.Initialize();
|
||||
map.ContactManager.KinematicControllerCollision += KinematicControllerCollision;
|
||||
Logger.DebugS("physics", $"Created physics map for {eventArgs.Map}");
|
||||
}
|
||||
|
||||
private void HandleMapDestroyed(object? sender, MapEventArgs eventArgs)
|
||||
{
|
||||
var map = _maps[eventArgs.Map];
|
||||
map.ContactManager.KinematicControllerCollision -= KinematicControllerCollision;
|
||||
|
||||
_maps.Remove(eventArgs.Map);
|
||||
Logger.DebugS("physics", $"Destroyed physics map for {eventArgs.Map}");
|
||||
}
|
||||
|
||||
private void HandleMapChange(EntMapIdChangedMessage message)
|
||||
{
|
||||
if (!message.Entity.TryGetComponent(out PhysicsComponent? physicsComponent))
|
||||
return;
|
||||
|
||||
var oldMapId = message.OldMapId;
|
||||
if (oldMapId != MapId.Nullspace)
|
||||
{
|
||||
_maps[oldMapId].RemoveBody(physicsComponent);
|
||||
physicsComponent.ClearJoints();
|
||||
}
|
||||
|
||||
var newMapId = message.Entity.Transform.MapID;
|
||||
if (newMapId != MapId.Nullspace)
|
||||
{
|
||||
_maps[newMapId].AddBody(physicsComponent);
|
||||
}
|
||||
}
|
||||
|
||||
private void HandlePhysicsUpdateMessage(PhysicsUpdateMessage message)
|
||||
{
|
||||
if (message.Component.Deleted || !message.Component.Awake)
|
||||
var mapId = message.Component.Owner.Transform.MapID;
|
||||
|
||||
if (mapId == MapId.Nullspace)
|
||||
return;
|
||||
|
||||
if (message.Component.Deleted || !message.Component.CanCollide)
|
||||
{
|
||||
_queuedDeletions.Add(message.Component);
|
||||
_maps[mapId].RemoveBody(message.Component);
|
||||
}
|
||||
else
|
||||
{
|
||||
_queuedUpdates.Add(message.Component);
|
||||
_maps[mapId].AddBody(message.Component);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process the changes to cached <see cref="IPhysicsComponent"/>s
|
||||
/// </summary>
|
||||
private void ProcessQueue()
|
||||
private void HandleWakeMessage(PhysicsWakeMessage message)
|
||||
{
|
||||
// At this stage only the dynamictree cares about asleep bodies
|
||||
// Implicitly awake bodies so don't need to check .Awake again
|
||||
// Controllers should wake their body up (inside)
|
||||
foreach (var physics in _queuedUpdates)
|
||||
{
|
||||
if (physics.Predict)
|
||||
_predictedAwakeBodies.Add(physics);
|
||||
var mapId = message.Body.Owner.Transform.MapID;
|
||||
|
||||
_awakeBodies.Add(physics);
|
||||
if (mapId == MapId.Nullspace)
|
||||
return;
|
||||
|
||||
if (physics.Controllers.Count > 0 && !_controllers.ContainsKey(physics))
|
||||
_controllers.Add(physics, physics.Controllers.Values);
|
||||
_maps[mapId].AddAwakeBody(message.Body);
|
||||
}
|
||||
|
||||
}
|
||||
private void HandleSleepMessage(PhysicsSleepMessage message)
|
||||
{
|
||||
var mapId = message.Body.Owner.Transform.MapID;
|
||||
|
||||
_queuedUpdates.Clear();
|
||||
if (mapId == MapId.Nullspace)
|
||||
return;
|
||||
|
||||
foreach (var physics in _queuedDeletions)
|
||||
{
|
||||
// If an entity was swapped from awake -> sleep -> awake then it's still relevant.
|
||||
if (!physics.Deleted && physics.Awake) continue;
|
||||
_awakeBodies.Remove(physics);
|
||||
_predictedAwakeBodies.Remove(physics);
|
||||
_controllers.Remove(physics);
|
||||
}
|
||||
_maps[mapId].RemoveSleepBody(message.Body);
|
||||
}
|
||||
|
||||
_queuedDeletions.Clear();
|
||||
private void HandleContainerInserted(EntInsertedIntoContainerMessage message)
|
||||
{
|
||||
if (!message.Entity.TryGetComponent(out PhysicsComponent? physicsComponent)) return;
|
||||
|
||||
var mapId = message.Container.Owner.Transform.MapID;
|
||||
|
||||
_maps[mapId].RemoveBody(physicsComponent);
|
||||
}
|
||||
|
||||
private void HandleContainerRemoved(EntRemovedFromContainerMessage message)
|
||||
{
|
||||
if (!message.Entity.TryGetComponent(out PhysicsComponent? physicsComponent)) return;
|
||||
|
||||
var mapId = message.Container.Owner.Transform.MapID;
|
||||
|
||||
_maps[mapId].AddBody(physicsComponent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -110,361 +255,28 @@ namespace Robust.Shared.GameObjects
|
||||
/// <param name="prediction">Should only predicted entities be considered in this simulation step?</param>
|
||||
protected void SimulateWorld(float deltaTime, bool prediction)
|
||||
{
|
||||
var simulatedBodies = prediction ? _predictedAwakeBodies : _awakeBodies;
|
||||
|
||||
ProcessQueue();
|
||||
|
||||
foreach (var body in simulatedBodies)
|
||||
foreach (var controller in _controllers)
|
||||
{
|
||||
// running prediction updates will not cause a body to go to sleep.
|
||||
if(!prediction)
|
||||
body.SleepAccumulator++;
|
||||
|
||||
// if the body cannot move, nothing to do here
|
||||
if(!body.CanMove())
|
||||
continue;
|
||||
|
||||
var linearVelocity = Vector2.Zero;
|
||||
|
||||
foreach (var controller in body.Controllers.Values)
|
||||
{
|
||||
controller.UpdateBeforeProcessing();
|
||||
linearVelocity += controller.LinearVelocity;
|
||||
}
|
||||
|
||||
// i'm not sure if this is the proper way to solve this, but
|
||||
// these are not kinematic bodies, so we need to preserve the previous
|
||||
// velocity.
|
||||
//if (body.LinearVelocity.LengthSquared < linearVelocity.LengthSquared)
|
||||
body.LinearVelocity = linearVelocity;
|
||||
|
||||
// Integrate forces
|
||||
body.LinearVelocity += body.Force * body.InvMass * deltaTime;
|
||||
body.AngularVelocity += body.Torque * body.InvI * deltaTime;
|
||||
|
||||
// forces are instantaneous, so these properties are cleared
|
||||
// once integrated. If you want to apply a continuous force,
|
||||
// it has to be re-applied every tick.
|
||||
body.Force = Vector2.Zero;
|
||||
body.Torque = 0f;
|
||||
controller.UpdateBeforeSolve(prediction, deltaTime);
|
||||
}
|
||||
|
||||
// Calculate collisions and store them in the cache
|
||||
ProcessCollisions(_awakeBodies);
|
||||
|
||||
// Remove all entities that were deleted during collision handling
|
||||
ProcessQueue();
|
||||
|
||||
// Process frictional forces
|
||||
foreach (var physics in _awakeBodies)
|
||||
foreach (var (mapId, map) in _maps)
|
||||
{
|
||||
ProcessFriction(physics, deltaTime);
|
||||
if (mapId == MapId.Nullspace) continue;
|
||||
map.Step(deltaTime, prediction);
|
||||
}
|
||||
|
||||
foreach (var (_, controllers) in _controllers)
|
||||
foreach (var controller in _controllers)
|
||||
{
|
||||
foreach (var controller in controllers)
|
||||
{
|
||||
controller.UpdateAfterProcessing();
|
||||
}
|
||||
controller.UpdateAfterSolve(prediction, deltaTime);
|
||||
}
|
||||
|
||||
// Remove all entities that were deleted due to the controller
|
||||
ProcessQueue();
|
||||
|
||||
const int solveIterationsAt60 = 4;
|
||||
|
||||
var multiplier = deltaTime / (1f / 60);
|
||||
|
||||
var divisions = MathHelper.Clamp(
|
||||
MathF.Round(solveIterationsAt60 * multiplier, MidpointRounding.AwayFromZero),
|
||||
1,
|
||||
20
|
||||
);
|
||||
|
||||
if (_timing.InSimulation) divisions = 1;
|
||||
|
||||
for (var i = 0; i < divisions; i++)
|
||||
// Go through and run all of the deferred events now
|
||||
foreach (var (mapId, map) in _maps)
|
||||
{
|
||||
foreach (var physics in simulatedBodies)
|
||||
{
|
||||
if (physics.CanMove())
|
||||
{
|
||||
UpdatePosition(physics, deltaTime / divisions);
|
||||
}
|
||||
}
|
||||
|
||||
for (var j = 0; j < divisions; ++j)
|
||||
{
|
||||
if (FixClipping(_collisionCache, divisions))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (mapId == MapId.Nullspace) continue;
|
||||
map.ProcessQueue();
|
||||
}
|
||||
|
||||
// As we also defer the updates for the _collisionCache we need to update all entities
|
||||
foreach (var physics in _deferredUpdates)
|
||||
{
|
||||
var transform = physics.Owner.Transform;
|
||||
transform.DeferUpdates = false;
|
||||
transform.RunPhysicsDeferred();
|
||||
}
|
||||
|
||||
_deferredUpdates.Clear();
|
||||
}
|
||||
|
||||
// Runs collision behavior and updates cache
|
||||
private void ProcessCollisions(IEnumerable<IPhysicsComponent> awakeBodies)
|
||||
{
|
||||
_collisionCache.Clear();
|
||||
var combinations = new HashSet<(EntityUid, EntityUid)>();
|
||||
foreach (var aPhysics in awakeBodies)
|
||||
{
|
||||
foreach (var b in _physicsManager.GetCollidingEntities(aPhysics, Vector2.Zero, false))
|
||||
{
|
||||
var aUid = aPhysics.Entity.Uid;
|
||||
var bUid = b.Uid;
|
||||
|
||||
if (bUid.CompareTo(aUid) > 0)
|
||||
{
|
||||
var tmpUid = bUid;
|
||||
bUid = aUid;
|
||||
aUid = tmpUid;
|
||||
}
|
||||
|
||||
if (!combinations.Add((aUid, bUid)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var bPhysics = b.GetComponent<IPhysicsComponent>();
|
||||
_collisionCache.Add(new Manifold(aPhysics, bPhysics, aPhysics.Hard && bPhysics.Hard));
|
||||
}
|
||||
}
|
||||
|
||||
var counter = 0;
|
||||
|
||||
if (_collisionCache.Count > 0)
|
||||
{
|
||||
while(GetNextCollision(_collisionCache, counter, out var collision))
|
||||
{
|
||||
collision.A.WakeBody();
|
||||
collision.B.WakeBody();
|
||||
|
||||
counter++;
|
||||
var impulse = _physicsManager.SolveCollisionImpulse(collision);
|
||||
if (collision.A.CanMove())
|
||||
{
|
||||
collision.A.ApplyImpulse(-impulse);
|
||||
}
|
||||
|
||||
if (collision.B.CanMove())
|
||||
{
|
||||
collision.B.ApplyImpulse(impulse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var collisionsWith = new Dictionary<ICollideBehavior, int>();
|
||||
foreach (var collision in _collisionCache)
|
||||
{
|
||||
// Apply onCollide behavior
|
||||
foreach (var behavior in collision.A.Entity.GetAllComponents<ICollideBehavior>().ToArray())
|
||||
{
|
||||
var entity = collision.B.Entity;
|
||||
if (entity.Deleted) break;
|
||||
behavior.CollideWith(entity);
|
||||
if (collisionsWith.ContainsKey(behavior))
|
||||
{
|
||||
collisionsWith[behavior] += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
collisionsWith[behavior] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var behavior in collision.B.Entity.GetAllComponents<ICollideBehavior>().ToArray())
|
||||
{
|
||||
var entity = collision.A.Entity;
|
||||
if (entity.Deleted) break;
|
||||
behavior.CollideWith(entity);
|
||||
if (collisionsWith.ContainsKey(behavior))
|
||||
{
|
||||
collisionsWith[behavior] += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
collisionsWith[behavior] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var behavior in collisionsWith.Keys)
|
||||
{
|
||||
behavior.PostCollide(collisionsWith[behavior]);
|
||||
}
|
||||
}
|
||||
|
||||
private bool GetNextCollision(IReadOnlyList<Manifold> collisions, int counter, out Manifold collision)
|
||||
{
|
||||
// The *4 is completely arbitrary
|
||||
if (counter > collisions.Count * 4)
|
||||
{
|
||||
collision = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
var offset = _random.Next(collisions.Count - 1);
|
||||
for (var i = 0; i < collisions.Count; i++)
|
||||
{
|
||||
var index = (i + offset) % collisions.Count;
|
||||
if (collisions[index].Unresolved)
|
||||
{
|
||||
collision = collisions[index];
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
collision = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void ProcessFriction(IPhysicsComponent body, float deltaTime)
|
||||
{
|
||||
if (body.LinearVelocity == Vector2.Zero) return;
|
||||
|
||||
// sliding friction coefficient, and current gravity at current location
|
||||
var (friction, gravity) = GetFriction(body);
|
||||
|
||||
// friction between the two objects
|
||||
var effectiveFriction = friction * body.Friction;
|
||||
|
||||
// current acceleration due to friction
|
||||
var fAcceleration = effectiveFriction * gravity;
|
||||
|
||||
// integrate acceleration
|
||||
var fVelocity = fAcceleration * deltaTime;
|
||||
|
||||
// Clamp friction because friction can't make you accelerate backwards
|
||||
friction = Math.Min(fVelocity, body.LinearVelocity.Length);
|
||||
|
||||
if (friction == 0.0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// No multiplication/division by mass here since that would be redundant.
|
||||
var frictionVelocityChange = body.LinearVelocity.Normalized * -friction;
|
||||
|
||||
body.LinearVelocity += frictionVelocityChange;
|
||||
}
|
||||
|
||||
private void UpdatePosition(IPhysicsComponent physics, float frameTime)
|
||||
{
|
||||
var ent = physics.Entity;
|
||||
|
||||
if (!physics.CanMove() || (physics.LinearVelocity.LengthSquared < Epsilon && MathF.Abs(physics.AngularVelocity) < Epsilon))
|
||||
return;
|
||||
|
||||
if (physics.LinearVelocity != Vector2.Zero)
|
||||
{
|
||||
if (ent.IsInContainer())
|
||||
{
|
||||
var relayEntityMoveMessage = new RelayMovementEntityMessage(ent);
|
||||
ent.Transform.Parent!.Owner.SendMessage(ent.Transform, relayEntityMoveMessage);
|
||||
// This prevents redundant messages from being sent if solveIterations > 1 and also simulates the entity "colliding" against the locker door when it opens.
|
||||
physics.LinearVelocity = Vector2.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
physics.Owner.Transform.DeferUpdates = true;
|
||||
_deferredUpdates.Add(physics);
|
||||
|
||||
// Slow zone up in here
|
||||
if (physics.LinearVelocity.Length > _speedLimit)
|
||||
physics.LinearVelocity = physics.LinearVelocity.Normalized * _speedLimit;
|
||||
|
||||
var newPosition = physics.WorldPosition + physics.LinearVelocity * frameTime;
|
||||
var owner = physics.Owner;
|
||||
var transform = owner.Transform;
|
||||
|
||||
// Change parent if necessary
|
||||
if (!owner.IsInContainer())
|
||||
{
|
||||
// This shoouullddnnn'''tt de-parent anything in a container because none of that should have physics applied to it.
|
||||
if (_mapManager.TryFindGridAt(owner.Transform.MapID, newPosition, out var grid) &&
|
||||
grid.GridEntityId.IsValid() &&
|
||||
grid.GridEntityId != owner.Uid)
|
||||
{
|
||||
if (grid.GridEntityId != transform.ParentUid)
|
||||
transform.AttachParent(owner.EntityManager.GetEntity(grid.GridEntityId));
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.AttachParent(_mapManager.GetMapEntity(transform.MapID));
|
||||
}
|
||||
}
|
||||
|
||||
physics.WorldRotation += physics.AngularVelocity * frameTime;
|
||||
physics.WorldPosition = newPosition;
|
||||
}
|
||||
|
||||
// Based off of Randy Gaul's ImpulseEngine code
|
||||
// https://github.com/RandyGaul/ImpulseEngine/blob/5181fee1648acc4a889b9beec8e13cbe7dac9288/Manifold.cpp#L123a
|
||||
private bool FixClipping(List<Manifold> collisions, float divisions)
|
||||
{
|
||||
const float allowance = 1 / 128.0f;
|
||||
var percent = MathHelper.Clamp(0.4f / divisions, 0.01f, 1f);
|
||||
var done = true;
|
||||
foreach (var collision in collisions)
|
||||
{
|
||||
if (!collision.Hard)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (collision.A.Owner.Deleted || collision.B.Owner.Deleted)
|
||||
continue;
|
||||
|
||||
var penetration = _physicsManager.CalculatePenetration(collision.A, collision.B);
|
||||
|
||||
if (penetration <= allowance)
|
||||
continue;
|
||||
|
||||
done = false;
|
||||
//var correction = collision.Normal * Math.Abs(penetration) * percent;
|
||||
var correction = collision.Normal * Math.Max(penetration - allowance, 0.0f) / (collision.A.InvMass + collision.B.InvMass) * percent;
|
||||
if (collision.A.CanMove())
|
||||
{
|
||||
collision.A.Owner.Transform.DeferUpdates = true;
|
||||
_deferredUpdates.Add(collision.A);
|
||||
collision.A.Owner.Transform.WorldPosition -= correction * collision.A.InvMass;
|
||||
}
|
||||
|
||||
if (collision.B.CanMove())
|
||||
{
|
||||
collision.B.Owner.Transform.DeferUpdates = true;
|
||||
_deferredUpdates.Add(collision.B);
|
||||
collision.B.Owner.Transform.WorldPosition += correction * collision.B.InvMass;
|
||||
}
|
||||
}
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
private (float friction, float gravity) GetFriction(IPhysicsComponent body)
|
||||
{
|
||||
if (!body.OnGround)
|
||||
return (0f, 0f);
|
||||
|
||||
var location = body.Owner.Transform;
|
||||
var grid = _mapManager.GetGrid(location.Coordinates.GetGridId(EntityManager));
|
||||
var tile = grid.GetTileRef(location.Coordinates);
|
||||
var tileDef = _tileDefinitionManager[tile.Tile.TypeId];
|
||||
return (tileDef.Friction, grid.HasGravity ? 9.8f : 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,7 +427,9 @@ namespace Robust.Shared.Localization
|
||||
|
||||
var root = new ResourcePath($"/Locale/{culture.Name}/");
|
||||
|
||||
var files = resourceManager.ContentFindFiles(root).ToArray();
|
||||
var files = resourceManager.ContentFindFiles(root)
|
||||
.Where(c => c.Filename.EndsWith(".ftl", StringComparison.InvariantCultureIgnoreCase))
|
||||
.ToArray();
|
||||
|
||||
var resources = files.AsParallel().Select(path =>
|
||||
{
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user