mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 11:40:52 +01:00
Compare commits
73 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5adf0cdfa3 | ||
|
|
320543c2a6 | ||
|
|
0d0d949752 | ||
|
|
d43fc89055 | ||
|
|
f9d0dd551a | ||
|
|
b2540a6e08 | ||
|
|
66d898ee91 | ||
|
|
310dc676ea | ||
|
|
41844d2d30 | ||
|
|
c6f3af20d6 | ||
|
|
5501209b35 | ||
|
|
9b2ef75762 | ||
|
|
196e59b7e4 | ||
|
|
2c936b5973 | ||
|
|
7765e71dca | ||
|
|
d8ae71d8cd | ||
|
|
a74812ce5b | ||
|
|
a7f9b0a6db | ||
|
|
3aac92e4b2 | ||
|
|
c152fb8953 | ||
|
|
10ea5498cf | ||
|
|
324606e5a3 | ||
|
|
a8227f7faa | ||
|
|
9f55400c58 | ||
|
|
8b971f7ae7 | ||
|
|
e3c7e361ae | ||
|
|
5c48dcb211 | ||
|
|
694de028c2 | ||
|
|
d41c9e7662 | ||
|
|
76134e0f8d | ||
|
|
2983517e43 | ||
|
|
18849be0b4 | ||
|
|
c6a1d82bb1 | ||
|
|
d89e1a43c6 | ||
|
|
d894ef70ef | ||
|
|
c7ea2793ca | ||
|
|
0c61ff2bee | ||
|
|
343a34eac7 | ||
|
|
7be41f4890 | ||
|
|
293470a5fe | ||
|
|
2b8057acf0 | ||
|
|
bec3caa5da | ||
|
|
ea6126563b | ||
|
|
00494ad9eb | ||
|
|
6672b7b1bd | ||
|
|
8dc55e8748 | ||
|
|
44ea2cd396 | ||
|
|
2c5604432b | ||
|
|
c696466522 | ||
|
|
01bb98e400 | ||
|
|
af08e747de | ||
|
|
8c35c2c380 | ||
|
|
6d46d3f4a5 | ||
|
|
50e06e43fa | ||
|
|
986b0f979d | ||
|
|
a51d786dee | ||
|
|
5f5fed5d6c | ||
|
|
e475cc7898 | ||
|
|
ee8ea4ec3b | ||
|
|
7482451ec4 | ||
|
|
dddf5cd2fb | ||
|
|
01979c451d | ||
|
|
181a5ef0b4 | ||
|
|
e7c7011cc0 | ||
|
|
dc97615fd4 | ||
|
|
3b4944376b | ||
|
|
fa6bd8f7ba | ||
|
|
2398cbcf26 | ||
|
|
38ce48a83f | ||
|
|
4e7de2f272 | ||
|
|
b61075c660 | ||
|
|
7b571dc80e | ||
|
|
f1c76ca899 |
@@ -1,4 +1,4 @@
|
||||
<Project>
|
||||
|
||||
<!-- This file automatically reset by Tools/version.py -->
|
||||
<!-- This file automatically reset by Tools/version.py -->
|
||||
|
||||
|
||||
144
RELEASE-NOTES.md
144
RELEASE-NOTES.md
@@ -54,10 +54,150 @@ END TEMPLATE-->
|
||||
*None yet*
|
||||
|
||||
|
||||
## 260.2.2
|
||||
## 263.0.2
|
||||
|
||||
|
||||
## 260.2.1
|
||||
## 263.0.1
|
||||
|
||||
|
||||
## 263.0.0
|
||||
|
||||
### Breaking changes
|
||||
|
||||
* Fully removed some non-`Entity<T>` container methods.
|
||||
|
||||
### New features
|
||||
|
||||
* `IMidiRenderer.LoadSoundfont` has been split into `LoadSoundfontResource` and `LoadSoundfontUser`, the original now being deprecated.
|
||||
* Client command execution now properly catches errors instead of letting them bubble up through the input stack.
|
||||
* Added `CompletionHelper.PrototypeIdsLimited` API to allow commands to autocomplete entity prototype IDs.
|
||||
* Added `spawn:in` Toolshed command.
|
||||
* Added `MapLoaderSystem.TryLoadGeneric` overload to load from a `Stream`.
|
||||
* Added `OutputPanel.GetMessage()` and `OutputPanel.SetMessage()` to allow replacing individual messages.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fixed debug asserts when using MIDI on Windows.
|
||||
* Fixed an error getting logged on startup on macOS related to window icons.
|
||||
* `CC-BY-NC-ND-4.0` is now a valid license for the RGA validator.
|
||||
* Fixed `TabContainer.CurrentTab` clamping against the wrong value.
|
||||
* Fix culture-based parsing in `TimespanSerializer`.
|
||||
* Fixed grid rendering blowing up on tile IDs that aren't registered.
|
||||
* Fixed debug assert when loading MIDI soundfonts on Windows.
|
||||
* Make `ColorSelectorSliders` properly update the dropdown when changing `SelectorType`.
|
||||
* Fixed `tpto` allowing teleports to oneself, thereby causing them to be deleted.
|
||||
* Fix OpenAL extensions being requested incorrectly, causing an error on macOS.
|
||||
* Fixed horizontal measuring of markup controls in rich text.
|
||||
|
||||
### Other
|
||||
|
||||
* Improved logging for some audio entity errors.
|
||||
* Avoided more server stutters when using `csci`.
|
||||
* Improved physics performance.
|
||||
* Made various localization functions like `GENDER()` not throw if passed a string instead of an `EntityUid`.
|
||||
* The generic clause on `EntitySystem.AddComp<T>` has been changed to `IComponent` (from `Component`) for consistency with `IEntityManager.AddComponent<T>`.
|
||||
* `DataDefinitionAnalyzer` has been optimized somewhat.
|
||||
* Improved assert logging error message when static data fields are encountered.
|
||||
|
||||
### Internal
|
||||
|
||||
* Warning cleanup.
|
||||
* Added more tests for `DataDefinitionAnalyzer`.
|
||||
* Consistently use `EntitySystem` proxy methods in engine.
|
||||
|
||||
|
||||
## 262.0.0
|
||||
|
||||
### Breaking changes
|
||||
|
||||
* Toolshed commands will now validate that each non-generic command argument is parseable (i.e., has a corresponding type parser). This check can be disabled by explicitly marking the argument as unparseable via `CommandArgumentAttribute.Unparseable`.
|
||||
|
||||
### New features
|
||||
|
||||
* `ToolshedManager.TryParse` now also supports nullable value types.
|
||||
* Add an ignoredComponents arg to IsDefault.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fix `SpriteComponent.Layer.Visible` setter not marking a sprite's bounding box as dirty.
|
||||
* The audio params in the passed SoundSpecifier for PlayStatic(SoundSpecifier, Filter, ...) will now be used as a default like other PlayStatic overrides.
|
||||
* Fix windows not saving their positions correctly when their x position is <= 0.
|
||||
* Fix transform state handling overriding PVS detachment.
|
||||
|
||||
|
||||
## 261.2.0
|
||||
|
||||
### New features
|
||||
|
||||
* Implement IEquatable for ResolvedPathSpecifier & ResolvedCollectionSpecifier.
|
||||
* Add NearestChunkEnumerator.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fix static entities not having the center of mass updated.
|
||||
* Fix TryQueueDelete.
|
||||
* Fix tpto potentially parenting grids to non-map entities.
|
||||
|
||||
### Other
|
||||
|
||||
* TileChangedEvent is now raised once in clientside grid state handling rather than per tile.
|
||||
* Removed ITileDefinition.ID as it was redundant.
|
||||
* Change the lifestage checks on predicted entity deletion to check for terminating.
|
||||
|
||||
### Internal
|
||||
|
||||
* Update some `GetComponentName<T>` uses to generic.
|
||||
|
||||
|
||||
## 261.1.0
|
||||
|
||||
### New features
|
||||
|
||||
* Automatically create logger sawmills for `UIController`s similar to `EntitySystem`s.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fix physics forces not auto-clearing / respecting the cvar.
|
||||
|
||||
### Internal
|
||||
|
||||
* Cleanup more compiler warnings in unit tests.
|
||||
|
||||
|
||||
## 261.0.0
|
||||
|
||||
### Breaking changes
|
||||
|
||||
* Remove unused TryGetContainingContainer override.
|
||||
* Stop recursive FrameUpdates for controls that are not visible.
|
||||
* Initialize LocMgr earlier in the callstack for GameController.
|
||||
* Fix FastNoiseLise fractal bounding and remove its DataField property as it should be derived on other properties updating.
|
||||
* Make RaiseMoveEvent internal.
|
||||
* MovedGridsComponent and PhysicsMapComponent are now purged and properties on `SharedPhysicsSystem`. Additionally the TransformComponent for Awake entities is stored alongside the PhysicsComponent for them.
|
||||
* TransformComponent is now stored on physics contacts.
|
||||
* Gravity2DComponent and Gravity2DController were moved to SharedPhysicsSystem.
|
||||
|
||||
### New features
|
||||
|
||||
* `IFileDialogManager` now allows specifying `FileAccess` and `FileShare` modes.
|
||||
* Add Intersects and Enlarged to Box2i in line with Box2.
|
||||
* Make `KeyFrame`s on `AnimationTrackProperty` public settable.
|
||||
* Add the spawned entities to a returned array from `SpawnEntitiesAttachedTo`.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fixed SDL3 file dialog implementation having a memory leak and not opening files read-write.
|
||||
* Fix GetMapLinearVelocity.
|
||||
|
||||
### Other
|
||||
|
||||
* `uploadfile` and `loadprototype` commands now only open files with read access.
|
||||
* Optimize `ToMapCoordinates`.
|
||||
|
||||
### Internal
|
||||
|
||||
* Cleanup on internals of `IFileDialogManager`, removing duplicate code.
|
||||
* Fix Contacts not correctly being marked as `Touching` while contact is ongoing.
|
||||
|
||||
|
||||
## 260.2.0
|
||||
|
||||
@@ -195,6 +195,8 @@ command-description-spawn-at =
|
||||
Spawns an entity at the given coordinates.
|
||||
command-description-spawn-on =
|
||||
Spawns an entity on the given entity, at it's coordinates.
|
||||
command-description-spawn-in =
|
||||
Spawns an entity in the given container on the given entity, dropping it at its coordinates if it doesn't fit
|
||||
command-description-spawn-attached =
|
||||
Spawns an entity attached to the given entity, at (0 0) relative to it.
|
||||
command-description-mappos =
|
||||
|
||||
@@ -55,7 +55,7 @@ public sealed class DataDefinitionAnalyzerTest
|
||||
namespace Robust.Shared.Serialization.Manager.Attributes
|
||||
{
|
||||
public class DataFieldBaseAttribute : Attribute;
|
||||
public class DataFieldAttribute : DataFieldBaseAttribute;
|
||||
public class DataFieldAttribute(string? tag = null) : DataFieldBaseAttribute;
|
||||
public sealed class DataDefinitionAttribute : Attribute;
|
||||
public sealed class NotYamlSerializableAttribute : Attribute;
|
||||
}
|
||||
@@ -117,6 +117,61 @@ public sealed class DataDefinitionAnalyzerTest
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PartialDataDefinitionTest()
|
||||
{
|
||||
const string code = """
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
[DataDefinition]
|
||||
public sealed class Foo { }
|
||||
""";
|
||||
|
||||
await Verifier(code,
|
||||
// /0/Test0.cs(4,15): error RA0017: Type Foo is a DataDefinition but is not partial
|
||||
VerifyCS.Diagnostic(DataDefinitionAnalyzer.DataDefinitionPartialRule).WithSpan(4, 15, 4, 20).WithArguments("Foo")
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NestedPartialDataDefinitionTest()
|
||||
{
|
||||
const string code = """
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
public sealed class Foo
|
||||
{
|
||||
[DataDefinition]
|
||||
public sealed partial class Nested { }
|
||||
}
|
||||
""";
|
||||
|
||||
await Verifier(code,
|
||||
// /0/Test0.cs(3,15): error RA0018: Type Foo contains nested data definition Nested but is not partial
|
||||
VerifyCS.Diagnostic(DataDefinitionAnalyzer.NestedDataDefinitionPartialRule).WithSpan(3, 15, 3, 20).WithArguments("Foo", "Nested")
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RedundantDataFieldTagTest()
|
||||
{
|
||||
const string code = """
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
[DataDefinition]
|
||||
public sealed partial class Foo
|
||||
{
|
||||
[DataField("someValue")]
|
||||
public int SomeValue;
|
||||
}
|
||||
""";
|
||||
|
||||
await Verifier(code,
|
||||
// /0/Test0.cs(6,6): info RA0027: Data field SomeValue in data definition Foo has an explicitly set tag that matches autogenerated tag
|
||||
VerifyCS.Diagnostic(DataDefinitionAnalyzer.DataFieldRedundantTagRule).WithSpan(6, 6, 6, 28).WithArguments("SomeValue", "Foo")
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ReadOnlyPropertyTest()
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
|
||||
private const string DataFieldAttributeName = "DataField";
|
||||
private const string ViewVariablesAttributeName = "ViewVariables";
|
||||
|
||||
private static readonly DiagnosticDescriptor DataDefinitionPartialRule = new(
|
||||
public static readonly DiagnosticDescriptor DataDefinitionPartialRule = new(
|
||||
Diagnostics.IdDataDefinitionPartial,
|
||||
"Type must be partial",
|
||||
"Type {0} is a DataDefinition but is not partial",
|
||||
@@ -32,7 +32,7 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
|
||||
"Make sure to mark any type that is a data definition as partial."
|
||||
);
|
||||
|
||||
private static readonly DiagnosticDescriptor NestedDataDefinitionPartialRule = new(
|
||||
public static readonly DiagnosticDescriptor NestedDataDefinitionPartialRule = new(
|
||||
Diagnostics.IdNestedDataDefinitionPartial,
|
||||
"Type must be partial",
|
||||
"Type {0} contains nested data definition {1} but is not partial",
|
||||
@@ -62,7 +62,7 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
|
||||
"Make sure to add a setter."
|
||||
);
|
||||
|
||||
private static readonly DiagnosticDescriptor DataFieldRedundantTagRule = new(
|
||||
public static readonly DiagnosticDescriptor DataFieldRedundantTagRule = new(
|
||||
Diagnostics.IdDataFieldRedundantTag,
|
||||
"Data field has redundant tag specified",
|
||||
"Data field {0} in data definition {1} has an explicitly set tag that matches autogenerated tag",
|
||||
@@ -102,14 +102,23 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
|
||||
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.None);
|
||||
context.EnableConcurrentExecution();
|
||||
|
||||
context.RegisterSyntaxNodeAction(AnalyzeDataDefinition, SyntaxKind.ClassDeclaration);
|
||||
context.RegisterSyntaxNodeAction(AnalyzeDataDefinition, SyntaxKind.StructDeclaration);
|
||||
context.RegisterSyntaxNodeAction(AnalyzeDataDefinition, SyntaxKind.RecordDeclaration);
|
||||
context.RegisterSyntaxNodeAction(AnalyzeDataDefinition, SyntaxKind.RecordStructDeclaration);
|
||||
context.RegisterSyntaxNodeAction(AnalyzeDataDefinition, SyntaxKind.InterfaceDeclaration);
|
||||
context.RegisterSymbolStartAction(symbolContext =>
|
||||
{
|
||||
if (symbolContext.Symbol is not INamedTypeSymbol typeSymbol)
|
||||
return;
|
||||
|
||||
context.RegisterSyntaxNodeAction(AnalyzeDataField, SyntaxKind.FieldDeclaration);
|
||||
context.RegisterSyntaxNodeAction(AnalyzeDataFieldProperty, SyntaxKind.PropertyDeclaration);
|
||||
if (!IsDataDefinition(typeSymbol))
|
||||
return;
|
||||
|
||||
symbolContext.RegisterSyntaxNodeAction(AnalyzeDataDefinition, SyntaxKind.ClassDeclaration);
|
||||
symbolContext.RegisterSyntaxNodeAction(AnalyzeDataDefinition, SyntaxKind.StructDeclaration);
|
||||
symbolContext.RegisterSyntaxNodeAction(AnalyzeDataDefinition, SyntaxKind.RecordDeclaration);
|
||||
symbolContext.RegisterSyntaxNodeAction(AnalyzeDataDefinition, SyntaxKind.RecordStructDeclaration);
|
||||
symbolContext.RegisterSyntaxNodeAction(AnalyzeDataDefinition, SyntaxKind.InterfaceDeclaration);
|
||||
|
||||
symbolContext.RegisterSyntaxNodeAction(AnalyzeDataField, SyntaxKind.FieldDeclaration);
|
||||
symbolContext.RegisterSyntaxNodeAction(AnalyzeDataFieldProperty, SyntaxKind.PropertyDeclaration);
|
||||
}, SymbolKind.NamedType);
|
||||
}
|
||||
|
||||
private void AnalyzeDataDefinition(SyntaxNodeAnalysisContext context)
|
||||
@@ -117,8 +126,7 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
|
||||
if (context.Node is not TypeDeclarationSyntax declaration)
|
||||
return;
|
||||
|
||||
var type = context.SemanticModel.GetDeclaredSymbol(declaration)!;
|
||||
if (!IsDataDefinition(type))
|
||||
if (context.ContainingSymbol is not INamedTypeSymbol type)
|
||||
return;
|
||||
|
||||
if (!IsPartial(declaration))
|
||||
@@ -129,7 +137,7 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
|
||||
var containingType = type.ContainingType;
|
||||
while (containingType != null)
|
||||
{
|
||||
var containingTypeDeclaration = (TypeDeclarationSyntax) containingType.DeclaringSyntaxReferences[0].GetSyntax();
|
||||
var containingTypeDeclaration = (TypeDeclarationSyntax)containingType.DeclaringSyntaxReferences[0].GetSyntax();
|
||||
if (!IsPartial(containingTypeDeclaration))
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(NestedDataDefinitionPartialRule, containingTypeDeclaration.Keyword.GetLocation(), containingType.Name, type.Name));
|
||||
@@ -144,27 +152,26 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
|
||||
if (context.Node is not FieldDeclarationSyntax field)
|
||||
return;
|
||||
|
||||
var typeDeclaration = field.FirstAncestorOrSelf<TypeDeclarationSyntax>();
|
||||
if (typeDeclaration == null)
|
||||
return;
|
||||
|
||||
var type = context.SemanticModel.GetDeclaredSymbol(typeDeclaration)!;
|
||||
if (!IsDataDefinition(type))
|
||||
if (context.ContainingSymbol?.ContainingType is not INamedTypeSymbol type)
|
||||
return;
|
||||
|
||||
foreach (var variable in field.Declaration.Variables)
|
||||
{
|
||||
var fieldSymbol = context.SemanticModel.GetDeclaredSymbol(variable);
|
||||
|
||||
if (fieldSymbol == null)
|
||||
continue;
|
||||
|
||||
if (!IsDataField(fieldSymbol, out _, out var datafieldAttribute))
|
||||
continue;
|
||||
|
||||
if (IsReadOnlyDataField(type, fieldSymbol))
|
||||
{
|
||||
TryGetModifierLocation(field, SyntaxKind.ReadOnlyKeyword, out var location);
|
||||
context.ReportDiagnostic(Diagnostic.Create(DataFieldWritableRule, location, fieldSymbol.Name, type.Name));
|
||||
}
|
||||
|
||||
if (HasRedundantTag(fieldSymbol))
|
||||
if (HasRedundantTag(fieldSymbol, datafieldAttribute))
|
||||
{
|
||||
TryGetAttributeLocation(field, DataFieldAttributeName, out var location);
|
||||
context.ReportDiagnostic(Diagnostic.Create(DataFieldRedundantTagRule, location, fieldSymbol.Name, type.Name));
|
||||
@@ -196,25 +203,28 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
|
||||
if (context.Node is not PropertyDeclarationSyntax property)
|
||||
return;
|
||||
|
||||
var typeDeclaration = property.FirstAncestorOrSelf<TypeDeclarationSyntax>();
|
||||
if (typeDeclaration == null)
|
||||
if (context.ContainingSymbol is not IPropertySymbol propertySymbol)
|
||||
return;
|
||||
|
||||
var type = context.SemanticModel.GetDeclaredSymbol(typeDeclaration)!;
|
||||
if (!IsDataDefinition(type) || type.IsRecord || type.IsValueType)
|
||||
if (propertySymbol.ContainingType is not INamedTypeSymbol type)
|
||||
return;
|
||||
|
||||
if (type.IsRecord || type.IsValueType)
|
||||
return;
|
||||
|
||||
var propertySymbol = context.SemanticModel.GetDeclaredSymbol(property);
|
||||
if (propertySymbol == null)
|
||||
return;
|
||||
|
||||
if (!IsDataField(propertySymbol, out _, out var datafieldAttribute))
|
||||
return;
|
||||
|
||||
if (IsReadOnlyDataField(type, propertySymbol))
|
||||
{
|
||||
var location = property.AccessorList != null ? property.AccessorList.GetLocation() : property.GetLocation();
|
||||
context.ReportDiagnostic(Diagnostic.Create(DataFieldPropertyWritableRule, location, propertySymbol.Name, type.Name));
|
||||
}
|
||||
|
||||
if (HasRedundantTag(propertySymbol))
|
||||
if (HasRedundantTag(propertySymbol, datafieldAttribute))
|
||||
{
|
||||
TryGetAttributeLocation(property, DataFieldAttributeName, out var location);
|
||||
context.ReportDiagnostic(Diagnostic.Create(DataFieldRedundantTagRule, location, propertySymbol.Name, type.Name));
|
||||
@@ -242,9 +252,6 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
|
||||
|
||||
private static bool IsReadOnlyDataField(ITypeSymbol type, ISymbol field)
|
||||
{
|
||||
if (!IsDataField(field, out _, out _))
|
||||
return false;
|
||||
|
||||
return IsReadOnlyMember(type, field);
|
||||
}
|
||||
|
||||
@@ -369,17 +376,14 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool HasRedundantTag(ISymbol symbol)
|
||||
private static bool HasRedundantTag(ISymbol symbol, AttributeData datafieldAttribute)
|
||||
{
|
||||
if (!IsDataField(symbol, out var _, out var attribute))
|
||||
return false;
|
||||
|
||||
// No args, no problem
|
||||
if (attribute.ConstructorArguments.Length == 0)
|
||||
if (datafieldAttribute.ConstructorArguments.Length == 0)
|
||||
return false;
|
||||
|
||||
// If a tag is explicitly specified, it will be the first argument...
|
||||
var tagArgument = attribute.ConstructorArguments[0];
|
||||
var tagArgument = datafieldAttribute.ConstructorArguments[0];
|
||||
// ...but the first arg could also something else, since tag is optional
|
||||
// so we make sure that it's a string
|
||||
if (tagArgument.Value is not string explicitName)
|
||||
@@ -394,9 +398,6 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
|
||||
|
||||
private static bool HasVVReadWrite(ISymbol symbol)
|
||||
{
|
||||
if (!IsDataField(symbol, out _, out _))
|
||||
return false;
|
||||
|
||||
// Make sure it has ViewVariablesAttribute
|
||||
AttributeData? viewVariablesAttribute = null;
|
||||
foreach (var attr in symbol.GetAttributes())
|
||||
@@ -422,9 +423,6 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
|
||||
|
||||
private static bool IsNotYamlSerializable(ISymbol field, ITypeSymbol type)
|
||||
{
|
||||
if (!IsDataField(field, out _, out _))
|
||||
return false;
|
||||
|
||||
return HasAttribute(type, NotYamlSerializableName);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Robust.Client.Animations
|
||||
/// </summary>
|
||||
public abstract class AnimationTrackProperty : AnimationTrack
|
||||
{
|
||||
public List<KeyFrame> KeyFrames { get; protected set; } = new();
|
||||
public List<KeyFrame> KeyFrames { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// How to interpolate values when between two keyframes.
|
||||
|
||||
@@ -57,8 +57,8 @@ internal sealed partial class AudioManager : IAudioInternal
|
||||
_checkAlError();
|
||||
|
||||
// Load up AL context extensions.
|
||||
var s = ALC.GetString(ALDevice.Null, AlcGetString.Extensions) ?? "";
|
||||
foreach (var extension in s.Split(' '))
|
||||
var s = ALC.GetString(_openALDevice, AlcGetString.Extensions) ?? "";
|
||||
foreach (var extension in s.Split(' ', StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
_alContextExtensions.Add(extension);
|
||||
}
|
||||
|
||||
@@ -582,7 +582,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
{
|
||||
if (TerminatingOrDeleted(entity))
|
||||
{
|
||||
Log.Error($"Tried to play coordinates audio on a terminating / deleted entity {ToPrettyString(entity)}");
|
||||
LogAudioPlaybackOnInvalidEntity(specifier, entity);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -626,7 +626,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
{
|
||||
if (TerminatingOrDeleted(coordinates.EntityId))
|
||||
{
|
||||
Log.Error($"Tried to play coordinates audio on a terminating / deleted entity {ToPrettyString(coordinates.EntityId)}");
|
||||
LogAudioPlaybackOnInvalidEntity(specifier, coordinates.EntityId);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -753,6 +753,12 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
return _resourceCache.GetResource<AudioResource>(filename).AudioStream.Length;
|
||||
}
|
||||
|
||||
private void LogAudioPlaybackOnInvalidEntity(ResolvedSoundSpecifier? specifier, EntityUid entityId)
|
||||
{
|
||||
var soundInfo = specifier?.ToString() ?? "unknown sound";
|
||||
Log.Error($"Tried to play coordinates audio on a terminating / deleted entity {ToPrettyString(entityId)}. Sound: {soundInfo}. Trace: {Environment.StackTrace}");
|
||||
}
|
||||
|
||||
#region Jobs
|
||||
|
||||
private record struct UpdateAudioJob : IParallelRobustJob
|
||||
|
||||
@@ -6,6 +6,7 @@ using Robust.Shared.Audio.Midi;
|
||||
using Robust.Shared.Audio.Sources;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Client.Audio.Midi;
|
||||
|
||||
@@ -156,8 +157,13 @@ public interface IMidiRenderer : IDisposable
|
||||
/// <summary>
|
||||
/// Loads a new soundfont into the renderer.
|
||||
/// </summary>
|
||||
[Obsolete("Use LoadSoundfontResource or LoadSoundfontUser instead")]
|
||||
void LoadSoundfont(string filename, bool resetPresets = false);
|
||||
|
||||
void LoadSoundfontResource(ResPath path, bool resetPresets = false);
|
||||
|
||||
void LoadSoundfontUser(ResPath path, bool resetPresets = false);
|
||||
|
||||
/// <summary>
|
||||
/// Invoked whenever a new midi event is registered.
|
||||
/// </summary>
|
||||
|
||||
262
Robust.Client/Audio/Midi/MidiManager.SoundFontLoad.cs
Normal file
262
Robust.Client/Audio/Midi/MidiManager.SoundFontLoad.cs
Normal file
@@ -0,0 +1,262 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using NFluidsynth;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Client.Audio.Midi;
|
||||
|
||||
internal sealed partial class MidiManager
|
||||
{
|
||||
// For loading sound fonts, we have to use a callback model where we can only parse a string.
|
||||
// This API, frankly, fucking sucks.
|
||||
//
|
||||
// These prefixes are used to separate the various places a file *can* be loaded from.
|
||||
//
|
||||
// We cannot prevent Fluidsynth from trying to load prefixed paths itself if they are invalid
|
||||
// So if content specifies "/foobar.sf2" to be loaded and it doesn't exist,
|
||||
// Fluidsynth *will* try to fopen("RES:/foobar.sf2"). For this reason I'm putting in some nonsense characters
|
||||
// that will pass through Fluidsynth fine, but make sure the filename is *never* a practically valid OS path.
|
||||
//
|
||||
// NOTE: Raw disk paths *cannot* be prefixed as Fluidsynth needs to load those itself.
|
||||
// Specifically, their .dls loader doesn't respect file callbacks.
|
||||
// If you're curious why this is: it's two-fold:
|
||||
// * The Fluidsynth C code for the .dls loader just doesn't use the file callbacks, period.
|
||||
// * Even if it did, we're not specifying those file callbacks, as they're per loader,
|
||||
// and we're only adding a *new* sound font loader with file callbacks, not modifying the existing ones.
|
||||
// The loader for .sfX format and .dls format are different loader objects in Fluidsynth.
|
||||
internal const string PrefixCommon = "!/ -?\x0001";
|
||||
internal const string PrefixLegacy = PrefixCommon + "LEGACY";
|
||||
internal const string PrefixUser = PrefixCommon + "USER";
|
||||
internal const string PrefixResources = PrefixCommon + "RES";
|
||||
|
||||
private void LoadSoundFontSetup(MidiRenderer renderer)
|
||||
{
|
||||
_midiSawmill.Debug($"Loading fallback soundfont {FallbackSoundfont}");
|
||||
// Since the last loaded soundfont takes priority, we load the fallback soundfont before the soundfont.
|
||||
renderer.LoadSoundfontResource(FallbackSoundfont);
|
||||
|
||||
// Load system-specific soundfonts.
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
foreach (var filepath in LinuxSoundfonts)
|
||||
{
|
||||
if (!File.Exists(filepath) || !SoundFont.IsSoundFont(filepath))
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
_midiSawmill.Debug($"Loading OS soundfont {filepath}");
|
||||
renderer.LoadSoundfontDisk(filepath);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
if (File.Exists(OsxSoundfont) && SoundFont.IsSoundFont(OsxSoundfont))
|
||||
{
|
||||
_midiSawmill.Debug($"Loading OS soundfont {OsxSoundfont}");
|
||||
renderer.LoadSoundfontDisk(OsxSoundfont);
|
||||
}
|
||||
}
|
||||
else if (OperatingSystem.IsWindows())
|
||||
{
|
||||
if (File.Exists(WindowsSoundfont) && SoundFont.IsSoundFont(WindowsSoundfont))
|
||||
{
|
||||
_midiSawmill.Debug($"Loading OS soundfont {WindowsSoundfont}");
|
||||
renderer.LoadSoundfontDisk(WindowsSoundfont);
|
||||
}
|
||||
}
|
||||
|
||||
// Maybe load soundfont specified in environment variable.
|
||||
// Load it here so it can override system soundfonts but not content or user data soundfonts.
|
||||
if (Environment.GetEnvironmentVariable(SoundfontEnvironmentVariable) is { } soundfontOverride)
|
||||
{
|
||||
// Just to avoid funny shit: avoid people smuggling a prefix in here.
|
||||
// I wish I could separate this properly...
|
||||
var (prefix, _) = SplitPrefix(soundfontOverride);
|
||||
if (IsValidPrefix(prefix))
|
||||
{
|
||||
_midiSawmill.Error($"Not respecting {SoundfontEnvironmentVariable} env variable: invalid file path");
|
||||
}
|
||||
else if (File.Exists(soundfontOverride) && SoundFont.IsSoundFont(soundfontOverride))
|
||||
{
|
||||
_midiSawmill.Debug($"Loading environment variable soundfont {soundfontOverride}");
|
||||
renderer.LoadSoundfontDisk(soundfontOverride);
|
||||
}
|
||||
}
|
||||
|
||||
// Load content-specific custom soundfonts, which should override the system/fallback soundfont.
|
||||
_midiSawmill.Debug($"Loading soundfonts from content directory {ContentCustomSoundfontDirectory}");
|
||||
foreach (var file in _resourceManager.ContentFindFiles(ContentCustomSoundfontDirectory))
|
||||
{
|
||||
if (file.Extension != "sf2" && file.Extension != "dls" && file.Extension != "sf3") continue;
|
||||
_midiSawmill.Debug($"Loading content soundfont {file}");
|
||||
renderer.LoadSoundfontResource(file);
|
||||
}
|
||||
|
||||
// Load every soundfont from the user data directory last, since those may override any other soundfont.
|
||||
_midiSawmill.Debug($"Loading soundfonts from user data directory {CustomSoundfontDirectory}");
|
||||
var enumerator = _resourceManager.UserData.Find($"{CustomSoundfontDirectory.ToRelativePath()}*").Item1;
|
||||
foreach (var file in enumerator)
|
||||
{
|
||||
if (file.Extension != "sf2" && file.Extension != "dls" && file.Extension != "sf3") continue;
|
||||
_midiSawmill.Debug($"Loading user soundfont {file}");
|
||||
renderer.LoadSoundfontUser(file);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string PrefixPath(string prefix, string value)
|
||||
{
|
||||
return $"{prefix}:{value}";
|
||||
}
|
||||
|
||||
internal static (string prefix, string? value) SplitPrefix(string filename)
|
||||
{
|
||||
var filenameSplit = filename.Split(':', 2);
|
||||
if (filenameSplit.Length == 1)
|
||||
return (filenameSplit[0], null);
|
||||
|
||||
return (filenameSplit[0], filenameSplit[1]);
|
||||
}
|
||||
|
||||
internal static bool IsValidPrefix(string prefix)
|
||||
{
|
||||
return prefix is PrefixLegacy or PrefixUser or PrefixResources;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This class is used to load soundfonts.
|
||||
/// </summary>
|
||||
private sealed class ResourceLoaderCallbacks : SoundFontLoaderCallbacks
|
||||
{
|
||||
private readonly MidiManager _parent;
|
||||
private readonly Dictionary<int, Stream> _openStreams = new();
|
||||
private int _nextStreamId = 1;
|
||||
|
||||
public ResourceLoaderCallbacks(MidiManager parent)
|
||||
{
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
public override IntPtr Open(string filename)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filename))
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
Stream stream;
|
||||
try
|
||||
{
|
||||
stream = OpenCore(filename);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_parent._midiSawmill.Error($"Error while opening sound font: {e}");
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
var id = _nextStreamId++;
|
||||
|
||||
_openStreams.Add(id, stream);
|
||||
|
||||
return (IntPtr) id;
|
||||
}
|
||||
|
||||
private Stream OpenCore(string filename)
|
||||
{
|
||||
var (prefix, value) = SplitPrefix(filename);
|
||||
|
||||
if (!IsValidPrefix(prefix) || value == null)
|
||||
return File.OpenRead(filename);
|
||||
|
||||
var resourceCache = _parent._resourceManager;
|
||||
var resourcePath = new ResPath(value);
|
||||
|
||||
switch (prefix)
|
||||
{
|
||||
case PrefixUser:
|
||||
return resourceCache.UserData.OpenRead(resourcePath);
|
||||
case PrefixResources:
|
||||
return resourceCache.ContentFileRead(resourcePath);
|
||||
case PrefixLegacy:
|
||||
// Try resources first, then try user data.
|
||||
if (resourceCache.TryContentFileRead(resourcePath, out var stream))
|
||||
return stream;
|
||||
|
||||
return resourceCache.UserData.OpenRead(resourcePath);
|
||||
default:
|
||||
throw new UnreachableException("Invalid prefix specified!");
|
||||
}
|
||||
}
|
||||
|
||||
public override unsafe int Read(IntPtr buf, long count, IntPtr sfHandle)
|
||||
{
|
||||
var length = (int) count;
|
||||
var span = new Span<byte>(buf.ToPointer(), length);
|
||||
var stream = _openStreams[(int) sfHandle];
|
||||
|
||||
// Fluidsynth's docs state that this method should leave the buffer unmodified if it fails. (returns -1)
|
||||
try
|
||||
{
|
||||
// Fluidsynth does a LOT of tiny allocations (frankly, way too much).
|
||||
if (count < 1024)
|
||||
{
|
||||
// ReSharper disable once SuggestVarOrType_Elsewhere
|
||||
Span<byte> buffer = stackalloc byte[(int)count];
|
||||
|
||||
stream.ReadExact(buffer);
|
||||
|
||||
buffer.CopyTo(span);
|
||||
}
|
||||
else
|
||||
{
|
||||
var buffer = stream.ReadExact(length);
|
||||
|
||||
buffer.CopyTo(span);
|
||||
}
|
||||
}
|
||||
catch (EndOfStreamException)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override int Seek(IntPtr sfHandle, long offset, SeekOrigin origin)
|
||||
{
|
||||
var stream = _openStreams[(int) sfHandle];
|
||||
|
||||
stream.Seek(offset, origin);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override long Tell(IntPtr sfHandle)
|
||||
{
|
||||
var stream = _openStreams[(int) sfHandle];
|
||||
|
||||
return (long) stream.Position;
|
||||
}
|
||||
|
||||
public override int Close(IntPtr sfHandle)
|
||||
{
|
||||
if (!_openStreams.Remove((int) sfHandle, out var stream))
|
||||
return -1;
|
||||
|
||||
stream.Dispose();
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,7 +119,7 @@ internal sealed partial class MidiManager : IMidiManager
|
||||
private const string OsxSoundfont =
|
||||
"/System/Library/Components/CoreAudio.component/Contents/Resources/gs_instruments.dls";
|
||||
|
||||
private const string FallbackSoundfont = "/Midi/fallback.sf2";
|
||||
private static readonly ResPath FallbackSoundfont = new ResPath("/Midi/fallback.sf2");
|
||||
|
||||
private const string ContentCustomSoundfontDirectory = "/Audio/MidiCustom/";
|
||||
|
||||
@@ -265,81 +265,7 @@ internal sealed partial class MidiManager : IMidiManager
|
||||
|
||||
var renderer = new MidiRenderer(_settings!, soundfontLoader, mono, this, _audio, _taskManager, _midiSawmill);
|
||||
|
||||
_midiSawmill.Debug($"Loading fallback soundfont {FallbackSoundfont}");
|
||||
// Since the last loaded soundfont takes priority, we load the fallback soundfont before the soundfont.
|
||||
renderer.LoadSoundfont(FallbackSoundfont);
|
||||
|
||||
// Load system-specific soundfonts.
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
foreach (var filepath in LinuxSoundfonts)
|
||||
{
|
||||
if (!File.Exists(filepath) || !SoundFont.IsSoundFont(filepath))
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
_midiSawmill.Debug($"Loading OS soundfont {filepath}");
|
||||
renderer.LoadSoundfont(filepath);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
if (File.Exists(OsxSoundfont) && SoundFont.IsSoundFont(OsxSoundfont))
|
||||
{
|
||||
_midiSawmill.Debug($"Loading OS soundfont {OsxSoundfont}");
|
||||
renderer.LoadSoundfont(OsxSoundfont);
|
||||
}
|
||||
}
|
||||
else if (OperatingSystem.IsWindows())
|
||||
{
|
||||
if (File.Exists(WindowsSoundfont) && SoundFont.IsSoundFont(WindowsSoundfont))
|
||||
{
|
||||
_midiSawmill.Debug($"Loading OS soundfont {WindowsSoundfont}");
|
||||
renderer.LoadSoundfont(WindowsSoundfont);
|
||||
}
|
||||
}
|
||||
|
||||
// Maybe load soundfont specified in environment variable.
|
||||
// Load it here so it can override system soundfonts but not content or user data soundfonts.
|
||||
if (Environment.GetEnvironmentVariable(SoundfontEnvironmentVariable) is {} soundfontOverride)
|
||||
{
|
||||
if (File.Exists(soundfontOverride) && SoundFont.IsSoundFont(soundfontOverride))
|
||||
{
|
||||
_midiSawmill.Debug($"Loading environment variable soundfont {soundfontOverride}");
|
||||
renderer.LoadSoundfont(soundfontOverride);
|
||||
}
|
||||
}
|
||||
|
||||
// Load content-specific custom soundfonts, which should override the system/fallback soundfont.
|
||||
_midiSawmill.Debug($"Loading soundfonts from content directory {ContentCustomSoundfontDirectory}");
|
||||
foreach (var file in _resourceManager.ContentFindFiles(ContentCustomSoundfontDirectory))
|
||||
{
|
||||
if (file.Extension != "sf2" && file.Extension != "dls" && file.Extension != "sf3") continue;
|
||||
_midiSawmill.Debug($"Loading content soundfont {file}");
|
||||
renderer.LoadSoundfont(file.ToString());
|
||||
}
|
||||
|
||||
var userDataPath = _resourceManager.UserData.RootDir == null
|
||||
? CustomSoundfontDirectory
|
||||
: new ResPath(_resourceManager.UserData.RootDir) / CustomSoundfontDirectory.ToRelativePath();
|
||||
|
||||
// Load every soundfont from the user data directory last, since those may override any other soundfont.
|
||||
_midiSawmill.Debug($"Loading soundfonts from user data directory {userDataPath}");
|
||||
var enumerator = _resourceManager.UserData.Find($"{CustomSoundfontDirectory.ToRelativePath()}*").Item1;
|
||||
foreach (var file in enumerator)
|
||||
{
|
||||
if (file.Extension != "sf2" && file.Extension != "dls" && file.Extension != "sf3") continue;
|
||||
_midiSawmill.Debug($"Loading user soundfont {file}");
|
||||
renderer.LoadSoundfont(file.ToString());
|
||||
}
|
||||
LoadSoundFontSetup(renderer);
|
||||
|
||||
renderer.Source.Gain = _gain;
|
||||
|
||||
@@ -572,130 +498,6 @@ internal sealed partial class MidiManager : IMidiManager
|
||||
midiEvent.Velocity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This class is used to load soundfonts.
|
||||
/// </summary>
|
||||
private sealed class ResourceLoaderCallbacks : SoundFontLoaderCallbacks
|
||||
{
|
||||
private readonly MidiManager _parent;
|
||||
private readonly Dictionary<int, Stream> _openStreams = new();
|
||||
private int _nextStreamId = 1;
|
||||
|
||||
public ResourceLoaderCallbacks(MidiManager parent)
|
||||
{
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
public override IntPtr Open(string filename)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filename))
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
Stream? stream;
|
||||
var resourceCache = _parent._resourceManager;
|
||||
var resourcePath = new ResPath(filename);
|
||||
|
||||
if (resourcePath.IsRooted)
|
||||
{
|
||||
// is it in content?
|
||||
if (resourceCache.ContentFileExists(filename))
|
||||
{
|
||||
if (!resourceCache.TryContentFileRead(filename, out stream))
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
// is it in userdata?
|
||||
else if (resourceCache.UserData.Exists(resourcePath))
|
||||
{
|
||||
stream = resourceCache.UserData.OpenRead(resourcePath);
|
||||
}
|
||||
else if (File.Exists(filename))
|
||||
{
|
||||
stream = File.OpenRead(filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
else if (File.Exists(filename))
|
||||
{
|
||||
stream = File.OpenRead(filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
var id = _nextStreamId++;
|
||||
|
||||
_openStreams.Add(id, stream);
|
||||
|
||||
return (IntPtr) id;
|
||||
}
|
||||
|
||||
public override unsafe int Read(IntPtr buf, long count, IntPtr sfHandle)
|
||||
{
|
||||
var length = (int) count;
|
||||
var span = new Span<byte>(buf.ToPointer(), length);
|
||||
var stream = _openStreams[(int) sfHandle];
|
||||
|
||||
// Fluidsynth's docs state that this method should leave the buffer unmodified if it fails. (returns -1)
|
||||
try
|
||||
{
|
||||
// Fluidsynth does a LOT of tiny allocations (frankly, way too much).
|
||||
if (count < 1024)
|
||||
{
|
||||
// ReSharper disable once SuggestVarOrType_Elsewhere
|
||||
Span<byte> buffer = stackalloc byte[(int)count];
|
||||
|
||||
stream.ReadExact(buffer);
|
||||
|
||||
buffer.CopyTo(span);
|
||||
}
|
||||
else
|
||||
{
|
||||
var buffer = stream.ReadExact(length);
|
||||
|
||||
buffer.CopyTo(span);
|
||||
}
|
||||
}
|
||||
catch (EndOfStreamException)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override int Seek(IntPtr sfHandle, long offset, SeekOrigin origin)
|
||||
{
|
||||
var stream = _openStreams[(int) sfHandle];
|
||||
|
||||
stream.Seek(offset, origin);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override long Tell(IntPtr sfHandle)
|
||||
{
|
||||
var stream = _openStreams[(int) sfHandle];
|
||||
|
||||
return (long) stream.Position;
|
||||
}
|
||||
|
||||
public override int Close(IntPtr sfHandle)
|
||||
{
|
||||
if (!_openStreams.Remove((int) sfHandle, out var stream))
|
||||
return -1;
|
||||
|
||||
stream.Dispose();
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#region Jobs
|
||||
|
||||
private record struct MidiUpdateJob : IParallelRobustJob
|
||||
|
||||
45
Robust.Client/Audio/Midi/MidiRenderer.SoundFontLoad.cs
Normal file
45
Robust.Client/Audio/Midi/MidiRenderer.SoundFontLoad.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Client.Audio.Midi;
|
||||
|
||||
internal sealed partial class MidiRenderer
|
||||
{
|
||||
[Obsolete("Use LoadSoundfontResource or LoadSoundfontUser instead")]
|
||||
public void LoadSoundfont(string filename, bool resetPresets = true)
|
||||
{
|
||||
LoadSoundfontCore(
|
||||
MidiManager.PrefixPath(MidiManager.PrefixLegacy, filename),
|
||||
resetPresets);
|
||||
}
|
||||
|
||||
public void LoadSoundfontResource(ResPath path, bool resetPresets = false)
|
||||
{
|
||||
LoadSoundfontCore(
|
||||
MidiManager.PrefixPath(MidiManager.PrefixResources, path.ToString()),
|
||||
resetPresets);
|
||||
}
|
||||
|
||||
public void LoadSoundfontUser(ResPath path, bool resetPresets = false)
|
||||
{
|
||||
LoadSoundfontCore(
|
||||
MidiManager.PrefixPath(MidiManager.PrefixUser, path.ToString()),
|
||||
resetPresets);
|
||||
}
|
||||
|
||||
internal void LoadSoundfontDisk(string path, bool resetPresets = false)
|
||||
{
|
||||
LoadSoundfontCore(
|
||||
path,
|
||||
resetPresets);
|
||||
}
|
||||
|
||||
private void LoadSoundfontCore(string filenameString, bool resetPresets)
|
||||
{
|
||||
lock (_playerStateLock)
|
||||
{
|
||||
_synth.LoadSoundFont(filenameString, resetPresets);
|
||||
MidiSoundfont = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Client.Audio.Midi;
|
||||
|
||||
internal sealed class MidiRenderer : IMidiRenderer
|
||||
internal sealed partial class MidiRenderer : IMidiRenderer
|
||||
{
|
||||
private readonly IMidiManager _midiManager;
|
||||
private readonly ITaskManager _taskManager;
|
||||
@@ -435,15 +435,6 @@ internal sealed class MidiRenderer : IMidiRenderer
|
||||
_sequencer.RemoveEvents(SequencerClientId.Wildcard, SequencerClientId.Wildcard, -1);
|
||||
}
|
||||
|
||||
public void LoadSoundfont(string filename, bool resetPresets = true)
|
||||
{
|
||||
lock (_playerStateLock)
|
||||
{
|
||||
_synth.LoadSoundFont(filename, resetPresets);
|
||||
MidiSoundfont = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void IMidiRenderer.Render()
|
||||
{
|
||||
Render();
|
||||
|
||||
@@ -21,7 +21,7 @@ public sealed class SpriteTreeSystem : ComponentTreeSystem<SpriteTreeComponent,
|
||||
protected override Box2 ExtractAabb(in ComponentTreeEntry<SpriteComponent> entry, Vector2 pos, Angle rot)
|
||||
{
|
||||
// TODO SPRITE optimize this
|
||||
// Because the just take the BB of the rotated BB, I'mt pretty sure we do a lot of unnecessary maths.
|
||||
// Because the just take the BB of the rotated BB, I'm pretty sure we do a lot of unnecessary maths.
|
||||
return _sprite.CalculateBounds((entry.Uid, entry.Component), pos, rot, default).CalcBoundingBox();
|
||||
}
|
||||
|
||||
|
||||
@@ -191,8 +191,16 @@ namespace Robust.Client.Console
|
||||
var shell = new ConsoleShell(this, session ?? _player.LocalSession, session == null);
|
||||
var cmdArgs = args.ToArray();
|
||||
|
||||
AnyCommandExecuted?.Invoke(shell, commandName, command, cmdArgs);
|
||||
cmd.Execute(shell, command, cmdArgs);
|
||||
try
|
||||
{
|
||||
AnyCommandExecuted?.Invoke(shell, commandName, command, cmdArgs);
|
||||
cmd.Execute(shell, command, cmdArgs);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_conLogger.Error($"ExecuteError - {command}:\n{e}");
|
||||
shell.WriteError($"There was an error while executing the command: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanExecute(string cmdName)
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace Robust.Client.Debugging
|
||||
|
||||
foreach (var ent in _mapSystem.GetAnchoredEntities(gridUid, grid, spot))
|
||||
{
|
||||
if (EntityManager.TryGetComponent<MetaDataComponent>(ent, out var meta))
|
||||
if (TryComp<MetaDataComponent>(ent, out var meta))
|
||||
{
|
||||
text.AppendLine($"uid: {ent}, {meta.EntityName}");
|
||||
}
|
||||
|
||||
@@ -160,6 +160,7 @@ namespace Robust.Client
|
||||
}
|
||||
|
||||
_serializationManager.Initialize();
|
||||
_loc.Initialize();
|
||||
|
||||
// Call Init in game assemblies.
|
||||
_modLoader.BroadcastRunLevel(ModRunLevel.PreInit);
|
||||
@@ -182,7 +183,6 @@ namespace Robust.Client
|
||||
_serializer.Initialize();
|
||||
_inputManager.Initialize();
|
||||
_console.Initialize();
|
||||
_loc.Initialize();
|
||||
|
||||
// Make sure this is done before we try to load prototypes,
|
||||
// avoid any possibility of race conditions causing the check to not finish
|
||||
|
||||
@@ -296,7 +296,7 @@ namespace Robust.Client.GameObjects
|
||||
public override void PredictedDeleteEntity(Entity<MetaDataComponent?, TransformComponent?> ent)
|
||||
{
|
||||
if (!MetaQuery.Resolve(ent.Owner, ref ent.Comp1)
|
||||
|| ent.Comp1.EntityDeleted
|
||||
|| ent.Comp1.EntityLifeStage >= EntityLifeStage.Terminating
|
||||
|| !TransformQuery.Resolve(ent.Owner, ref ent.Comp2))
|
||||
{
|
||||
return;
|
||||
@@ -322,7 +322,7 @@ namespace Robust.Client.GameObjects
|
||||
{
|
||||
if (IsQueuedForDeletion(ent.Owner)
|
||||
|| !MetaQuery.Resolve(ent.Owner, ref ent.Comp1)
|
||||
|| ent.Comp1.EntityDeleted
|
||||
|| ent.Comp1.EntityLifeStage >= EntityLifeStage.Terminating
|
||||
|| !TransformQuery.Resolve(ent.Owner, ref ent.Comp2))
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -24,9 +24,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
public sealed class SpriteBoundsSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedTransformSystem _xformSystem = default!;
|
||||
[Dependency] private readonly IOverlayManager _overlayManager = default!;
|
||||
[Dependency] private readonly SpriteTreeSystem _spriteTree = default!;
|
||||
|
||||
private SpriteBoundsOverlay? _overlay;
|
||||
|
||||
@@ -42,7 +40,7 @@ namespace Robust.Client.GameObjects
|
||||
if (_enabled)
|
||||
{
|
||||
DebugTools.AssertNull(_overlay);
|
||||
_overlay = new SpriteBoundsOverlay(_spriteTree, _xformSystem);
|
||||
_overlay = new SpriteBoundsOverlay(EntityManager);
|
||||
_overlayManager.AddOverlay(_overlay);
|
||||
}
|
||||
else
|
||||
@@ -57,18 +55,13 @@ namespace Robust.Client.GameObjects
|
||||
private bool _enabled;
|
||||
}
|
||||
|
||||
public sealed class SpriteBoundsOverlay : Overlay
|
||||
public sealed class SpriteBoundsOverlay(IEntityManager entMan) : Overlay
|
||||
{
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpace;
|
||||
|
||||
private readonly SharedTransformSystem _xformSystem;
|
||||
private SpriteTreeSystem _renderTree;
|
||||
|
||||
public SpriteBoundsOverlay(SpriteTreeSystem renderTree, SharedTransformSystem xformSystem)
|
||||
{
|
||||
_renderTree = renderTree;
|
||||
_xformSystem = xformSystem;
|
||||
}
|
||||
private readonly SharedTransformSystem _xformSystem = entMan.System<SharedTransformSystem>();
|
||||
private readonly SpriteSystem _spriteSystem = entMan.System<SpriteSystem>();
|
||||
private readonly SpriteTreeSystem _renderTree = entMan.System<SpriteTreeSystem>();
|
||||
|
||||
protected internal override void Draw(in OverlayDrawArgs args)
|
||||
{
|
||||
@@ -76,10 +69,11 @@ namespace Robust.Client.GameObjects
|
||||
var currentMap = args.MapId;
|
||||
var viewport = args.WorldBounds;
|
||||
|
||||
foreach (var (sprite, xform) in _renderTree.QueryAabb(currentMap, viewport))
|
||||
foreach (var entry in _renderTree.QueryAabb(currentMap, viewport))
|
||||
{
|
||||
var (sprite, xform) = entry;
|
||||
var (worldPos, worldRot) = _xformSystem.GetWorldPositionRotation(xform);
|
||||
var bounds = sprite.CalculateRotatedBoundingBox(worldPos, worldRot, args.Viewport.Eye?.Rotation ?? default);
|
||||
var bounds = _spriteSystem.CalculateBounds((entry.Uid, sprite), worldPos, worldRot, args.Viewport.Eye?.Rotation ?? default);
|
||||
|
||||
// Get scaled down bounds used to indicate the "south" of a sprite.
|
||||
var localBound = bounds.Box;
|
||||
|
||||
@@ -1224,6 +1224,8 @@ namespace Robust.Client.GameObjects
|
||||
return;
|
||||
_visible = value;
|
||||
|
||||
Owner.Comp.BoundsDirty = true;
|
||||
|
||||
// ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
|
||||
if (_parent.Owner != EntityUid.Invalid)
|
||||
Owner.Comp.Sys?.QueueUpdateIsInert(Owner);
|
||||
@@ -1791,76 +1793,15 @@ namespace Robust.Client.GameObjects
|
||||
[Obsolete("Use SpriteSystem.GetPrototypeTextures() instead")]
|
||||
public static IEnumerable<IDirectionalTextureProvider> GetPrototypeTextures(EntityPrototype prototype, IResourceCache resourceCache, out bool noRot)
|
||||
{
|
||||
var results = new List<IDirectionalTextureProvider>();
|
||||
noRot = false;
|
||||
|
||||
// TODO when moving to a non-static method in a system, pass in IComponentFactory
|
||||
if (prototype.TryGetComponent(out IconComponent? icon))
|
||||
{
|
||||
var sys = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SpriteSystem>();
|
||||
results.Add(sys.GetIcon(icon));
|
||||
return results;
|
||||
}
|
||||
|
||||
if (!prototype.Components.TryGetValue("Sprite", out _))
|
||||
{
|
||||
results.Add(resourceCache.GetFallback<TextureResource>().Texture);
|
||||
return results;
|
||||
}
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var dummy = entityManager.SpawnEntity(prototype.ID, MapCoordinates.Nullspace);
|
||||
var spriteComponent = entityManager.EnsureComponent<SpriteComponent>(dummy);
|
||||
EntitySystem.Get<AppearanceSystem>().OnChangeData(dummy, spriteComponent);
|
||||
|
||||
foreach (var layer in spriteComponent.AllLayers)
|
||||
{
|
||||
if (!layer.Visible) continue;
|
||||
|
||||
if (layer.Texture != null)
|
||||
{
|
||||
results.Add(layer.Texture);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!layer.RsiState.IsValid) continue;
|
||||
|
||||
var rsi = layer.Rsi ?? spriteComponent.BaseRSI;
|
||||
if (rsi == null ||
|
||||
!rsi.TryGetState(layer.RsiState, out var state))
|
||||
continue;
|
||||
|
||||
results.Add(state);
|
||||
}
|
||||
|
||||
noRot = spriteComponent.NoRotation;
|
||||
|
||||
entityManager.DeleteEntity(dummy);
|
||||
|
||||
if (results.Count == 0)
|
||||
results.Add(resourceCache.GetFallback<TextureResource>().Texture);
|
||||
|
||||
return results;
|
||||
var sys = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SpriteSystem>();
|
||||
return sys.GetPrototypeTextures(prototype, out noRot);
|
||||
}
|
||||
|
||||
[Obsolete("Use SpriteSystem.GetPrototypeIcon() instead")]
|
||||
public static IRsiStateLike GetPrototypeIcon(EntityPrototype prototype, IResourceCache resourceCache)
|
||||
{
|
||||
var sys = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SpriteSystem>();
|
||||
// TODO when moving to a non-static method in a system, pass in IComponentFactory
|
||||
if (prototype.TryGetComponent(out IconComponent? icon))
|
||||
return sys.GetIcon(icon);
|
||||
|
||||
if (!prototype.Components.ContainsKey("Sprite"))
|
||||
return sys.GetFallbackState();
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var dummy = entityManager.SpawnEntity(prototype.ID, MapCoordinates.Nullspace);
|
||||
var spriteComponent = entityManager.EnsureComponent<SpriteComponent>(dummy);
|
||||
var result = spriteComponent.Icon ?? sys.GetFallbackState();
|
||||
entityManager.DeleteEntity(dummy);
|
||||
|
||||
return result;
|
||||
return sys.GetPrototypeIcon(prototype);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace Robust.Client.GameObjects
|
||||
[Obsolete("Use Play(EntityUid<AnimationPlayerComponent> ent, Animation animation, string key) instead")]
|
||||
public void Play(EntityUid uid, AnimationPlayerComponent? component, Animation animation, string key)
|
||||
{
|
||||
component ??= EntityManager.EnsureComponent<AnimationPlayerComponent>(uid);
|
||||
component ??= EnsureComp<AnimationPlayerComponent>(uid);
|
||||
Play(new Entity<AnimationPlayerComponent>(uid, component), animation, key);
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
public bool HasRunningAnimation(EntityUid uid, string key)
|
||||
{
|
||||
return EntityManager.TryGetComponent(uid, out AnimationPlayerComponent? component) &&
|
||||
return TryComp(uid, out AnimationPlayerComponent? component) &&
|
||||
component.PlayingAnimations.ContainsKey(key);
|
||||
}
|
||||
|
||||
|
||||
@@ -223,12 +223,12 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
private void SetEntityContextActive(IInputManager inputMan, EntityUid entity)
|
||||
{
|
||||
if(entity == default || !EntityManager.EntityExists(entity))
|
||||
if(entity == default || !Exists(entity))
|
||||
throw new ArgumentNullException(nameof(entity));
|
||||
|
||||
if (!EntityManager.TryGetComponent(entity, out InputComponent? inputComp))
|
||||
if (!TryComp(entity, out InputComponent? inputComp))
|
||||
{
|
||||
_sawmillInputContext.Debug($"AttachedEnt has no InputComponent: entId={entity}, entProto={EntityManager.GetComponent<MetaDataComponent>(entity).EntityPrototype}. Setting default \"{InputContextContainer.DefaultContextName}\" context...");
|
||||
_sawmillInputContext.Debug($"AttachedEnt has no InputComponent: entId={entity}, entProto={Comp<MetaDataComponent>(entity).EntityPrototype}. Setting default \"{InputContextContainer.DefaultContextName}\" context...");
|
||||
inputMan.Contexts.SetActiveContext(InputContextContainer.DefaultContextName);
|
||||
return;
|
||||
}
|
||||
@@ -239,7 +239,7 @@ namespace Robust.Client.GameObjects
|
||||
}
|
||||
else
|
||||
{
|
||||
_sawmillInputContext.Error($"Unknown context: entId={entity}, entProto={EntityManager.GetComponent<MetaDataComponent>(entity).EntityPrototype}, context={inputComp.ContextName}. . Setting default \"{InputContextContainer.DefaultContextName}\" context...");
|
||||
_sawmillInputContext.Error($"Unknown context: entId={entity}, entProto={Comp<MetaDataComponent>(entity).EntityPrototype}, context={inputComp.ContextName}. . Setting default \"{InputContextContainer.DefaultContextName}\" context...");
|
||||
inputMan.Contexts.SetActiveContext(InputContextContainer.DefaultContextName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public sealed class ShowPlayerVelocityDebugSystem : EntitySystem
|
||||
|
||||
var player = _playerManager.LocalEntity;
|
||||
|
||||
if (player == null || !EntityManager.TryGetComponent(player.Value, out PhysicsComponent? body))
|
||||
if (player == null || !TryComp(player.Value, out PhysicsComponent? body))
|
||||
{
|
||||
_label.Visible = false;
|
||||
return;
|
||||
|
||||
@@ -56,10 +56,6 @@ public sealed partial class SpriteSystem
|
||||
/// </summary>
|
||||
public IRsiStateLike GetPrototypeIcon(string prototype)
|
||||
{
|
||||
// Check if this prototype has been cached before, and if so return the result.
|
||||
if (_cachedPrototypeIcons.TryGetValue(prototype, out var cachedResult))
|
||||
return cachedResult;
|
||||
|
||||
if (!_proto.TryIndex<EntityPrototype>(prototype, out var entityPrototype))
|
||||
{
|
||||
// The specified prototype doesn't exist, return the fallback "error" sprite.
|
||||
@@ -67,11 +63,7 @@ public sealed partial class SpriteSystem
|
||||
return GetFallbackState();
|
||||
}
|
||||
|
||||
// Generate the icon and cache it in case it's ever needed again.
|
||||
var result = GetPrototypeIcon(entityPrototype);
|
||||
_cachedPrototypeIcons[prototype] = result;
|
||||
|
||||
return result;
|
||||
return GetPrototypeIcon(entityPrototype);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -79,13 +71,19 @@ public sealed partial class SpriteSystem
|
||||
/// This method does NOT cache the result.
|
||||
/// </summary>
|
||||
public IRsiStateLike GetPrototypeIcon(EntityPrototype prototype)
|
||||
{
|
||||
// This method may spawn & delete an entity to get an accruate RSI state, hence we cache the results
|
||||
if (_cachedPrototypeIcons.TryGetValue(prototype.ID, out var cachedResult))
|
||||
return cachedResult;
|
||||
|
||||
return _cachedPrototypeIcons[prototype.ID] = GetPrototypeIconInternal(prototype);
|
||||
}
|
||||
|
||||
private IRsiStateLike GetPrototypeIconInternal(EntityPrototype prototype)
|
||||
{
|
||||
// IconComponent takes precedence. If it has a valid icon, return that. Otherwise, continue as normal.
|
||||
if (prototype.Components.TryGetValue("Icon", out var compData)
|
||||
&& compData.Component is IconComponent icon)
|
||||
{
|
||||
if (prototype.TryGetComponent(out IconComponent? icon, _factory))
|
||||
return GetIcon(icon);
|
||||
}
|
||||
|
||||
// If the prototype doesn't have a SpriteComponent, then there's nothing we can do but return the fallback.
|
||||
if (!prototype.Components.ContainsKey("Sprite"))
|
||||
@@ -102,6 +100,63 @@ public sealed partial class SpriteSystem
|
||||
return result;
|
||||
}
|
||||
|
||||
public IEnumerable<IDirectionalTextureProvider> GetPrototypeTextures(EntityPrototype proto) =>
|
||||
GetPrototypeTextures(proto, out _);
|
||||
|
||||
public IEnumerable<IDirectionalTextureProvider> GetPrototypeTextures(EntityPrototype proto, out bool noRot)
|
||||
{
|
||||
var results = new List<IDirectionalTextureProvider>();
|
||||
noRot = false;
|
||||
|
||||
if (proto.TryGetComponent(out IconComponent? icon, _factory))
|
||||
{
|
||||
results.Add(GetIcon(icon));
|
||||
return results;
|
||||
}
|
||||
|
||||
if (!proto.Components.ContainsKey("Sprite"))
|
||||
{
|
||||
results.Add(_resourceCache.GetFallback<TextureResource>().Texture);
|
||||
return results;
|
||||
}
|
||||
|
||||
var dummy = Spawn(proto.ID, MapCoordinates.Nullspace);
|
||||
var spriteComponent = EnsureComp<SpriteComponent>(dummy);
|
||||
|
||||
// TODO SPRITE is this needed?
|
||||
// And if it is, shouldn't GetPrototypeIconInternal also use this?
|
||||
_appearance.OnChangeData(dummy, spriteComponent);
|
||||
|
||||
foreach (var layer in spriteComponent.AllLayers)
|
||||
{
|
||||
if (!layer.Visible)
|
||||
continue;
|
||||
|
||||
if (layer.Texture != null)
|
||||
{
|
||||
results.Add(layer.Texture);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!layer.RsiState.IsValid)
|
||||
continue;
|
||||
|
||||
var rsi = layer.Rsi ?? spriteComponent.BaseRSI;
|
||||
if (rsi == null || !rsi.TryGetState(layer.RsiState, out var state))
|
||||
continue;
|
||||
|
||||
results.Add(state);
|
||||
}
|
||||
|
||||
noRot = spriteComponent.NoRotation;
|
||||
Del(dummy);
|
||||
|
||||
if (results.Count == 0)
|
||||
results.Add(_resourceCache.GetFallback<TextureResource>().Texture);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public RSI.State GetFallbackState()
|
||||
{
|
||||
|
||||
@@ -34,8 +34,12 @@ namespace Robust.Client.GameObjects
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
[Dependency] private readonly ILogManager _logManager = default!;
|
||||
[Dependency] private readonly IComponentFactory _factory = default!;
|
||||
|
||||
// Note that any new system dependencies have to be added to RobustUnitTest.BaseSetup()
|
||||
[Dependency] private readonly SharedTransformSystem _xforms = default!;
|
||||
[Dependency] private readonly SpriteTreeSystem _tree = default!;
|
||||
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
||||
|
||||
public static readonly ProtoId<ShaderPrototype> UnshadedId = "unshaded";
|
||||
private readonly Queue<SpriteComponent> _inertUpdateQueue = new();
|
||||
|
||||
@@ -631,7 +631,7 @@ namespace Robust.Client.GameStates
|
||||
if (_sawmill.Level <= LogLevel.Debug)
|
||||
_sawmill.Debug($" A component was dirtied: {comp.GetType()}");
|
||||
|
||||
if (compState != null)
|
||||
if ((meta.Flags & MetaDataFlags.Detached) == 0 && compState != null)
|
||||
{
|
||||
var handleState = new ComponentHandleState(compState, null);
|
||||
_entities.EventBus.RaiseComponentEvent(entity, comp, ref handleState);
|
||||
|
||||
@@ -254,9 +254,9 @@ namespace Robust.Client.Graphics.Clyde
|
||||
region = regionMaybe[tile.Variant];
|
||||
}
|
||||
|
||||
var rotationMirroring = _tileDefinitionManager[tile.TypeId].AllowRotationMirror
|
||||
? tile.RotationMirroring
|
||||
: 0;
|
||||
var rotationMirroring = (_tileDefinitionManager.TryGetDefinition(tile.TypeId, out var tileDef) && tileDef.AllowRotationMirror) ?
|
||||
tile.RotationMirroring
|
||||
: 0;
|
||||
|
||||
WriteTileToBuffers(i, gridX, gridY, vertexBuffer, indexBuffer, region, rotationMirroring);
|
||||
i += 1;
|
||||
|
||||
@@ -467,7 +467,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
_windowing!.RunOnWindowThread(a);
|
||||
}
|
||||
|
||||
public IFileDialogManager? FileDialogImpl => _windowing as IFileDialogManager;
|
||||
public IFileDialogManagerImplementation? FileDialogImpl => _windowing as IFileDialogManagerImplementation;
|
||||
|
||||
private abstract class WindowReg
|
||||
{
|
||||
|
||||
@@ -307,7 +307,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
action();
|
||||
}
|
||||
|
||||
public IFileDialogManager? FileDialogImpl => null;
|
||||
public IFileDialogManagerImplementation? FileDialogImpl => null;
|
||||
|
||||
private sealed class DummyCursor : ICursor
|
||||
{
|
||||
|
||||
@@ -662,6 +662,10 @@ namespace Robust.Client.Graphics.Clyde
|
||||
{
|
||||
var icons = _clyde.LoadWindowIcons().ToArray();
|
||||
|
||||
// Done if no icon (e.g., macOS)
|
||||
if (icons.Length == 0)
|
||||
return;
|
||||
|
||||
// Turn each image into a byte[] so we can actually pin their contents.
|
||||
// Wish I knew a clean way to do this without allocations.
|
||||
var images = icons
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -12,31 +11,16 @@ namespace Robust.Client.Graphics.Clyde;
|
||||
|
||||
internal partial class Clyde
|
||||
{
|
||||
private sealed partial class Sdl3WindowingImpl : IFileDialogManager
|
||||
private sealed partial class Sdl3WindowingImpl : IFileDialogManagerImplementation
|
||||
{
|
||||
public async Task<Stream?> OpenFile(FileDialogFilters? filters = null)
|
||||
public async Task<string?> OpenFile(FileDialogFilters? filters)
|
||||
{
|
||||
var fileName = await ShowFileDialogOfType(SDL.SDL_FILEDIALOG_OPENFILE, filters);
|
||||
if (fileName == null)
|
||||
return null;
|
||||
|
||||
return File.OpenRead(fileName);
|
||||
return await ShowFileDialogOfType(SDL.SDL_FILEDIALOG_OPENFILE, filters);
|
||||
}
|
||||
|
||||
public async Task<(Stream fileStream, bool alreadyExisted)?> SaveFile(FileDialogFilters? filters = null, bool truncate = true)
|
||||
public async Task<string?> SaveFile(FileDialogFilters? filters)
|
||||
{
|
||||
var fileName = await ShowFileDialogOfType(SDL.SDL_FILEDIALOG_SAVEFILE, filters);
|
||||
if (fileName == null)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
return (File.Open(fileName, truncate ? FileMode.Truncate : FileMode.Open), true);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
return (File.Open(fileName, FileMode.Create), false);
|
||||
}
|
||||
return await ShowFileDialogOfType(SDL.SDL_FILEDIALOG_SAVEFILE, filters);
|
||||
}
|
||||
|
||||
private unsafe Task<string?> ShowFileDialogOfType(int type, FileDialogFilters? filters)
|
||||
@@ -74,6 +58,8 @@ internal partial class Clyde
|
||||
NativeMemory.Free(filter.name);
|
||||
NativeMemory.Free(filter.pattern);
|
||||
}
|
||||
|
||||
NativeMemory.Free(filtersAlloc);
|
||||
}
|
||||
|
||||
return task;
|
||||
|
||||
@@ -71,6 +71,6 @@ namespace Robust.Client.Graphics
|
||||
|
||||
void RunOnWindowThread(Action action);
|
||||
|
||||
IFileDialogManager? FileDialogImpl { get; }
|
||||
IFileDialogManagerImplementation? FileDialogImpl { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Robust.Client.Physics
|
||||
* This will draw above every body involved in a particular island solve.
|
||||
*/
|
||||
|
||||
public readonly Queue<(TimeSpan Time, List<PhysicsComponent> Bodies)> IslandSolve = new();
|
||||
public readonly Queue<(TimeSpan Time, List<Entity<PhysicsComponent, TransformComponent>> Bodies)> IslandSolve = new();
|
||||
public const float SolveDuration = 0.1f;
|
||||
|
||||
public override void Initialize()
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace Robust.Client.Physics
|
||||
|
||||
// Add new joint (if possible).
|
||||
// Need to wait for BOTH joint components to come in first before we can add it. Yay dependencies!
|
||||
if (!EntityManager.HasComponent<JointComponent>(other))
|
||||
if (!HasComp<JointComponent>(other))
|
||||
continue;
|
||||
|
||||
// TODO: if (other entity is outside of PVS range) continue;
|
||||
|
||||
@@ -90,9 +90,10 @@ public sealed partial class PhysicsSystem
|
||||
// existing contacts for predicted entities before performing any actual prediction.
|
||||
|
||||
var contacts = new List<Contact>();
|
||||
var maps = new HashSet<EntityUid>();
|
||||
|
||||
var enumerator = AllEntityQuery<PredictedPhysicsComponent, PhysicsComponent, TransformComponent>();
|
||||
_broadphase.FindNewContacts();
|
||||
|
||||
while (enumerator.MoveNext(out _, out var physics, out var xform))
|
||||
{
|
||||
DebugTools.Assert(physics.Predict);
|
||||
@@ -100,10 +101,6 @@ public sealed partial class PhysicsSystem
|
||||
if (xform.MapUid is not { } map)
|
||||
continue;
|
||||
|
||||
if (maps.Add(map) && PhysMapQuery.TryGetComponent(map, out var physMap) &&
|
||||
MapQuery.TryGetComponent(map, out var mapComp))
|
||||
_broadphase.FindNewContacts(physMap, mapComp.MapId);
|
||||
|
||||
contacts.AddRange(physics.Contacts);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Collections;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Physics;
|
||||
@@ -23,21 +24,23 @@ namespace Robust.Client.Physics
|
||||
SimulateWorld(frameTime, _gameTiming.InPrediction);
|
||||
}
|
||||
|
||||
protected override void Cleanup(PhysicsMapComponent component, float frameTime)
|
||||
protected override void Cleanup(float frameTime)
|
||||
{
|
||||
var toRemove = new List<Entity<PhysicsComponent>>();
|
||||
var toRemove = new ValueList<Entity<PhysicsComponent, TransformComponent>>();
|
||||
|
||||
// Because we're not predicting 99% of bodies its sleep timer never gets incremented so we'll just do it ourselves.
|
||||
// (and serializing it over the network isn't necessary?)
|
||||
// This is a client-only problem.
|
||||
// Also need to suss out having the client build the island anyway and just... not solving it?
|
||||
foreach (var body in component.AwakeBodies)
|
||||
foreach (var ent in AwakeBodies)
|
||||
{
|
||||
var body = ent.Comp1;
|
||||
|
||||
if (!body.SleepingAllowed || body.LinearVelocity.Length() > LinearToleranceSqr / 2f || body.AngularVelocity * body.AngularVelocity > AngularToleranceSqr / 2f) continue;
|
||||
body.SleepTime += frameTime;
|
||||
if (body.SleepTime > TimeToSleep)
|
||||
{
|
||||
toRemove.Add(new Entity<PhysicsComponent>(body.Owner, body));
|
||||
toRemove.Add(ent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,37 +49,38 @@ namespace Robust.Client.Physics
|
||||
SetAwake(body, false);
|
||||
}
|
||||
|
||||
base.Cleanup(component, frameTime);
|
||||
base.Cleanup(frameTime);
|
||||
}
|
||||
|
||||
protected override void UpdateLerpData(PhysicsMapComponent component, List<PhysicsComponent> bodies, EntityQuery<TransformComponent> xformQuery)
|
||||
protected override void UpdateLerpData(List<Entity<PhysicsComponent, TransformComponent>> bodies)
|
||||
{
|
||||
foreach (var body in bodies)
|
||||
foreach (var bodyEnt in bodies)
|
||||
{
|
||||
var body = bodyEnt.Comp1;
|
||||
var xform = bodyEnt.Comp2;
|
||||
|
||||
if (body.BodyType == BodyType.Static ||
|
||||
component.LerpData.TryGetValue(body.Owner, out var lerpData) ||
|
||||
!xformQuery.TryGetComponent(body.Owner, out var xform) ||
|
||||
lerpData.ParentUid == xform.ParentUid)
|
||||
LerpData.TryGetValue(bodyEnt, out var lerpData) ||
|
||||
lerpData == xform.ParentUid)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
component.LerpData[xform.Owner] = (xform.ParentUid, xform.LocalPosition, xform.LocalRotation);
|
||||
LerpData[bodyEnt.Owner] = xform.ParentUid;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flush all of our lerping data.
|
||||
/// </summary>
|
||||
protected override void FinalStep(PhysicsMapComponent component)
|
||||
protected override void FinalStep()
|
||||
{
|
||||
base.FinalStep(component);
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
base.FinalStep();
|
||||
|
||||
foreach (var (uid, (parentUid, position, rotation)) in component.LerpData)
|
||||
foreach (var (uid, parentUid) in LerpData)
|
||||
{
|
||||
if (!xformQuery.TryGetComponent(uid, out var xform) ||
|
||||
!parentUid.IsValid())
|
||||
// Can't just re-use xform from before as movement events may cause event subs to fire.
|
||||
if (!XformQuery.TryGetComponent(uid, out var xform) || !parentUid.IsValid())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -85,7 +89,7 @@ namespace Robust.Client.Physics
|
||||
_transform.SetLocalPositionRotation(uid, xform.LocalPosition, xform.LocalRotation, xform);
|
||||
}
|
||||
|
||||
component.LerpData.Clear();
|
||||
LerpData.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public sealed class LoadPrototypeCommand : IConsoleCommand
|
||||
var dialogManager = IoCManager.Resolve<IFileDialogManager>();
|
||||
var loadManager = IoCManager.Resolve<IGamePrototypeLoadManager>();
|
||||
|
||||
var stream = await dialogManager.OpenFile();
|
||||
var stream = await dialogManager.OpenFile(access: FileAccess.Read);
|
||||
if (stream is null)
|
||||
return;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.IO;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Configuration;
|
||||
@@ -36,7 +37,7 @@ public sealed class UploadFileCommand : IConsoleCommand
|
||||
var path = new ResPath(args[0]).ToRelativePath();
|
||||
|
||||
var filters = new FileDialogFilters(new FileDialogFilters.Group(path.Extension));
|
||||
await using var file = await _dialog.OpenFile(filters);
|
||||
await using var file = await _dialog.OpenFile(filters, FileAccess.Read);
|
||||
|
||||
if (file == null)
|
||||
{
|
||||
|
||||
@@ -994,6 +994,9 @@ namespace Robust.Client.UserInterface
|
||||
|
||||
internal int DoFrameUpdateRecursive(FrameEventArgs args)
|
||||
{
|
||||
if (!Visible)
|
||||
return 0;
|
||||
|
||||
var total = 1;
|
||||
FrameUpdate(args);
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Robust.Client.UserInterface.Controllers;
|
||||
@@ -11,11 +14,14 @@ namespace Robust.Client.UserInterface.Controllers;
|
||||
/// and <see cref="UISystemDependencyAttribute"/> to depend on <see cref="EntitySystem"/>s, which will be automatically
|
||||
/// injected once they are created.
|
||||
/// </summary>
|
||||
public abstract partial class UIController
|
||||
public abstract partial class UIController : IPostInjectInit
|
||||
{
|
||||
[Dependency] protected readonly IUserInterfaceManager UIManager = default!;
|
||||
[Dependency] protected readonly IEntitySystemManager EntitySystemManager = default!;
|
||||
[Dependency] protected readonly IEntityManager EntityManager = default!;
|
||||
[Dependency] protected readonly ILogManager LogManager = default!;
|
||||
|
||||
public ISawmill Log { get; protected set; } = default!;
|
||||
|
||||
public virtual void Initialize()
|
||||
{
|
||||
@@ -24,4 +30,39 @@ public abstract partial class UIController
|
||||
public virtual void FrameUpdate(FrameEventArgs args)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual string SawmillName
|
||||
{
|
||||
get
|
||||
{
|
||||
var name = GetType().Name;
|
||||
|
||||
// Strip trailing "UIController"
|
||||
if (name.EndsWith("UIController"))
|
||||
name = name.Substring(0, name.Length - "UIController".Length);
|
||||
|
||||
// Convert CamelCase to snake_case
|
||||
// Ignore if all uppercase, assume acronym (e.g. NPC or HTN)
|
||||
if (name.All(char.IsUpper))
|
||||
{
|
||||
name = name.ToLower(CultureInfo.InvariantCulture);
|
||||
}
|
||||
else
|
||||
{
|
||||
name = string.Concat(name.Select(x => char.IsUpper(x) ? $"_{char.ToLower(x)}" : x.ToString()));
|
||||
name = name.Trim('_');
|
||||
}
|
||||
|
||||
return $"ui.{name}";
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInject()
|
||||
{
|
||||
Log = LogManager.GetSawmill(SawmillName);
|
||||
|
||||
#if !DEBUG
|
||||
Log.Level = LogLevel.Info;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ public sealed class ColorSelectorSliders : Control
|
||||
break;
|
||||
}
|
||||
_currentType = value;
|
||||
_typeSelector.Select(_types.IndexOf(value));
|
||||
UpdateType();
|
||||
Update();
|
||||
}
|
||||
|
||||
@@ -107,6 +107,11 @@ namespace Robust.Client.UserInterface.Controls
|
||||
_scrollBar.Value = 0;
|
||||
}
|
||||
|
||||
public FormattedMessage GetMessage(Index index)
|
||||
{
|
||||
return new FormattedMessage(_entries[index].Message);
|
||||
}
|
||||
|
||||
public void RemoveEntry(Index index)
|
||||
{
|
||||
var entry = _entries[index];
|
||||
@@ -138,6 +143,31 @@ namespace Robust.Client.UserInterface.Controls
|
||||
|
||||
_entries.Add(entry);
|
||||
var font = _getFont();
|
||||
AddNewItemHeight(font, entry);
|
||||
|
||||
_scrollBar.MaxValue = Math.Max(_scrollBar.Page, _totalContentHeight);
|
||||
if (_isAtBottom && ScrollFollowing)
|
||||
{
|
||||
_scrollBar.MoveToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetMessage(Index index, FormattedMessage message, Type[]? tagsAllowed = null, Color? defaultColor = null)
|
||||
{
|
||||
var oldEntry = _entries[index];
|
||||
var font = _getFont();
|
||||
_totalContentHeight -= oldEntry.Height + font.GetLineSeparation(UIScale);
|
||||
_scrollBar.MaxValue = Math.Max(_scrollBar.Page, _totalContentHeight);
|
||||
|
||||
var entry = new RichTextEntry(message, this, _tagManager, tagsAllowed, defaultColor);
|
||||
entry.Update(_tagManager, _getFont(), _getContentBox().Width, UIScale);
|
||||
_entries[index] = entry;
|
||||
|
||||
AddNewItemHeight(font, in entry);
|
||||
}
|
||||
|
||||
private void AddNewItemHeight(Font font, in RichTextEntry entry)
|
||||
{
|
||||
_totalContentHeight += entry.Height;
|
||||
if (_firstLine)
|
||||
{
|
||||
@@ -147,12 +177,6 @@ namespace Robust.Client.UserInterface.Controls
|
||||
{
|
||||
_totalContentHeight += font.GetLineSeparation(UIScale);
|
||||
}
|
||||
|
||||
_scrollBar.MaxValue = Math.Max(_scrollBar.Page, _totalContentHeight);
|
||||
if (_isAtBottom && ScrollFollowing)
|
||||
{
|
||||
_scrollBar.MoveToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
public void ScrollToBottom()
|
||||
|
||||
@@ -30,12 +30,12 @@ namespace Robust.Client.UserInterface.Controls
|
||||
get => _currentTab;
|
||||
set
|
||||
{
|
||||
if (_currentTab < 0)
|
||||
if (value < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(value), value, "Current tab must be positive.");
|
||||
}
|
||||
|
||||
if (_currentTab >= ChildCount)
|
||||
if (value >= ChildCount)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(value), value,
|
||||
"Current tab must less than the amount of tabs.");
|
||||
|
||||
@@ -145,6 +145,11 @@ namespace Robust.Client.UserInterface.CustomControls
|
||||
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
{
|
||||
// This is to avoid unnecessarily setting a position where our size isn't yet fully updated.
|
||||
// This most commonly happens with saved window positions if your window position is <= 0.
|
||||
if (!IsMeasureValid)
|
||||
return;
|
||||
|
||||
var (spaceX, spaceY) = Parent!.Size;
|
||||
|
||||
var maxX = spaceX - ((AllowOffScreen & DirectionFlag.West) == 0 ? Size.X : WindowEdgeSeparation);
|
||||
|
||||
@@ -8,12 +8,19 @@ namespace Robust.Client.UserInterface
|
||||
/// </summary>
|
||||
internal sealed class DummyFileDialogManager : IFileDialogManager
|
||||
{
|
||||
public Task<Stream?> OpenFile(FileDialogFilters? filters = null)
|
||||
public Task<Stream?> OpenFile(
|
||||
FileDialogFilters? filters = null,
|
||||
FileAccess access = FileAccess.ReadWrite,
|
||||
FileShare? share = null)
|
||||
{
|
||||
return Task.FromResult<Stream?>(null);
|
||||
}
|
||||
|
||||
public Task<(Stream fileStream, bool alreadyExisted)?> SaveFile(FileDialogFilters? filters = null, bool truncate = true)
|
||||
public Task<(Stream fileStream, bool alreadyExisted)?> SaveFile(
|
||||
FileDialogFilters? filters = null,
|
||||
bool truncate = true,
|
||||
FileAccess access = FileAccess.ReadWrite,
|
||||
FileShare share = FileShare.None)
|
||||
{
|
||||
return Task.FromResult<(Stream fileStream, bool alreadyExisted)?>(null);
|
||||
}
|
||||
|
||||
@@ -7,9 +7,7 @@ using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Asynchronous;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Utility;
|
||||
@@ -20,28 +18,41 @@ namespace Robust.Client.UserInterface
|
||||
[SuppressMessage("ReSharper", "IdentifierTypo")]
|
||||
[SuppressMessage("ReSharper", "CommentTypo")]
|
||||
[SuppressMessage("ReSharper", "StringLiteralTypo")]
|
||||
internal sealed class FileDialogManager : IFileDialogManager
|
||||
internal sealed class FileDialogManager : IFileDialogManager, IPostInjectInit
|
||||
{
|
||||
// Uses nativefiledialog to open the file dialogs cross platform.
|
||||
// On Linux, if the kdialog command is found, it will be used instead.
|
||||
// TODO: Should we maybe try to avoid running kdialog if the DE isn't KDE?
|
||||
[Dependency] private readonly IClydeInternal _clyde = default!;
|
||||
[Dependency] private readonly ILogManager _log = default!;
|
||||
|
||||
private ISawmill _sawmill = default!;
|
||||
|
||||
private bool _kDialogAvailable;
|
||||
private bool _checkedKDialogAvailable;
|
||||
|
||||
public async Task<Stream?> OpenFile(FileDialogFilters? filters = null)
|
||||
public async Task<Stream?> OpenFile(
|
||||
FileDialogFilters? filters = null,
|
||||
FileAccess access = FileAccess.ReadWrite,
|
||||
FileShare? share = null)
|
||||
{
|
||||
if ((access & FileAccess.ReadWrite) != access)
|
||||
throw new ArgumentException("Invalid file access specified");
|
||||
|
||||
var realShare = share ?? (access == FileAccess.Read ? FileShare.Read : FileShare.None);
|
||||
if ((realShare & (FileShare.ReadWrite | FileShare.Delete)) != realShare)
|
||||
throw new ArgumentException("Invalid file share specified");
|
||||
|
||||
string? name;
|
||||
if (_clyde.FileDialogImpl is { } clydeImpl)
|
||||
return await clydeImpl.OpenFile(filters);
|
||||
name = await clydeImpl.OpenFile(filters);
|
||||
else
|
||||
name = await GetOpenFileName(filters);
|
||||
|
||||
var name = await GetOpenFileName(filters);
|
||||
if (name == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return File.Open(name, FileMode.Open);
|
||||
return File.Open(name, FileMode.Open, access, realShare);
|
||||
}
|
||||
|
||||
private async Task<string?> GetOpenFileName(FileDialogFilters? filters)
|
||||
@@ -54,24 +65,34 @@ namespace Robust.Client.UserInterface
|
||||
return await OpenFileNfd(filters);
|
||||
}
|
||||
|
||||
public async Task<(Stream, bool)?> SaveFile(FileDialogFilters? filters, bool truncate = true)
|
||||
public async Task<(Stream, bool)?> SaveFile(
|
||||
FileDialogFilters? filters,
|
||||
bool truncate = true,
|
||||
FileAccess access = FileAccess.ReadWrite,
|
||||
FileShare share = FileShare.None)
|
||||
{
|
||||
if (_clyde.FileDialogImpl is { } clydeImpl)
|
||||
return await clydeImpl.SaveFile(filters);
|
||||
if ((access & FileAccess.ReadWrite) != access)
|
||||
throw new ArgumentException("Invalid file access specified");
|
||||
|
||||
if ((share & (FileShare.ReadWrite | FileShare.Delete)) != share)
|
||||
throw new ArgumentException("Invalid file share specified");
|
||||
|
||||
string? name;
|
||||
if (_clyde.FileDialogImpl is { } clydeImpl)
|
||||
name = await clydeImpl.SaveFile(filters);
|
||||
else
|
||||
name = await GetSaveFileName(filters);
|
||||
|
||||
var name = await GetSaveFileName(filters);
|
||||
if (name == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return (File.Open(name, truncate ? FileMode.Truncate : FileMode.Open), true);
|
||||
return (File.Open(name, truncate ? FileMode.Truncate : FileMode.Open, access, share), true);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
return (File.Open(name, FileMode.Create), false);
|
||||
return (File.Open(name, FileMode.Create, access, share), false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +270,7 @@ namespace Robust.Client.UserInterface
|
||||
|
||||
if (_kDialogAvailable)
|
||||
{
|
||||
Logger.DebugS("filedialog", "kdialog available.");
|
||||
_sawmill.Debug("kdialog available.");
|
||||
}
|
||||
}
|
||||
catch
|
||||
@@ -386,6 +407,11 @@ namespace Robust.Client.UserInterface
|
||||
[DllImport("swnfd.dll")]
|
||||
private static extern unsafe void sw_NFD_Free(void* ptr);
|
||||
|
||||
public void PostInject()
|
||||
{
|
||||
_sawmill = _log.GetSawmill("filedialog");
|
||||
}
|
||||
|
||||
private enum sw_nfdresult
|
||||
{
|
||||
SW_NFD_ERROR,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Robust.Client.Graphics;
|
||||
|
||||
namespace Robust.Client.UserInterface
|
||||
{
|
||||
@@ -19,7 +20,17 @@ namespace Robust.Client.UserInterface
|
||||
/// The file stream for the file the user opened.
|
||||
/// <see langword="null" /> if the user cancelled the action.
|
||||
/// </returns>
|
||||
Task<Stream?> OpenFile(FileDialogFilters? filters = null);
|
||||
/// <param name="filters">Filters for file types that the user can select.</param>
|
||||
/// <param name="access">What access is desired from the file operation.</param>
|
||||
/// <param name="share">
|
||||
/// What sharing mode is desired from the file operation.
|
||||
/// If null is provided and <paramref name="access"/> is <see cref="FileAccess.Read"/>,
|
||||
/// <see cref="FileShare.Read"/> is selected, otherwise <see cref="FileShare.None"/>.
|
||||
/// </param>
|
||||
Task<Stream?> OpenFile(
|
||||
FileDialogFilters? filters = null,
|
||||
FileAccess access = FileAccess.ReadWrite,
|
||||
FileShare? share = null);
|
||||
|
||||
/// <summary>
|
||||
/// Open a file dialog used for saving a single file.
|
||||
@@ -29,6 +40,21 @@ namespace Robust.Client.UserInterface
|
||||
/// Null if the user cancelled the action.
|
||||
/// </returns>
|
||||
/// <param name="truncate">Should we truncate an existing file to 0-size then write or append.</param>
|
||||
Task<(Stream fileStream, bool alreadyExisted)?> SaveFile(FileDialogFilters? filters = null, bool truncate = true);
|
||||
/// <param name="access">What access is desired from the file operation.</param>
|
||||
/// <param name="share">Sharing mode for the opened file.</param>
|
||||
Task<(Stream fileStream, bool alreadyExisted)?> SaveFile(
|
||||
FileDialogFilters? filters = null,
|
||||
bool truncate = true,
|
||||
FileAccess access = FileAccess.ReadWrite,
|
||||
FileShare share = FileShare.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal implementation interface used to connect <see cref="FileDialogManager"/> and <see cref="IClydeInternal"/>.
|
||||
/// </summary>
|
||||
internal interface IFileDialogManagerImplementation
|
||||
{
|
||||
Task<string?> OpenFile(FileDialogFilters? filters);
|
||||
Task<string?> SaveFile(FileDialogFilters? filters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace Robust.Client.UserInterface
|
||||
if (Controls == null || !Controls.TryGetValue(nodeIndex, out var control))
|
||||
continue;
|
||||
|
||||
control.Measure(new Vector2(Width, Height));
|
||||
control.Measure(new Vector2(maxSizeX, Height));
|
||||
|
||||
var desiredSize = control.DesiredPixelSize;
|
||||
var controlMetrics = new CharMetrics(
|
||||
|
||||
@@ -137,7 +137,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
|
||||
if (TerminatingOrDeleted(coordinates.EntityId))
|
||||
{
|
||||
Log.Error($"Tried to play coordinates audio on a terminating / deleted entity {ToPrettyString(coordinates.EntityId)}. Trace: {Environment.StackTrace}");
|
||||
LogAudioPlaybackOnInvalidEntity(specifier, coordinates.EntityId);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
|
||||
if (TerminatingOrDeleted(coordinates.EntityId))
|
||||
{
|
||||
Log.Error($"Tried to play coordinates audio on a terminating / deleted entity {ToPrettyString(coordinates.EntityId)}. Trace: {Environment.StackTrace}");
|
||||
LogAudioPlaybackOnInvalidEntity(specifier, coordinates.EntityId);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -281,4 +281,10 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
{
|
||||
// TODO: Yeah remove this...
|
||||
}
|
||||
|
||||
private void LogAudioPlaybackOnInvalidEntity(ResolvedSoundSpecifier? specifier, EntityUid entityId)
|
||||
{
|
||||
var soundInfo = specifier?.ToString() ?? "unknown sound";
|
||||
Log.Error($"Tried to play coordinates audio on a terminating / deleted entity {ToPrettyString(entityId)}. Sound: {soundInfo}. Trace: {Environment.StackTrace}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace Robust.Server.GameObjects
|
||||
|
||||
foreach (var uid in toDelete)
|
||||
{
|
||||
EntityManager.DeleteEntity(uid);
|
||||
Del(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ namespace Robust.Server.GameObjects
|
||||
if (!_deleteEmptyGrids || TerminatingOrDeleted(uid) || HasComp<MapComponent>(uid))
|
||||
return;
|
||||
|
||||
EntityManager.DeleteEntity(args.GridId);
|
||||
Del(args.GridId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public sealed class ViewSubscriberSystem : SharedViewSubscriberSystem
|
||||
public override void AddViewSubscriber(EntityUid uid, ICommonSession session)
|
||||
{
|
||||
// If the entity doesn't have the component, it will be added.
|
||||
var viewSubscriber = EntityManager.EnsureComponent<Shared.GameObjects.ViewSubscriberComponent>(uid);
|
||||
var viewSubscriber = EnsureComp<Shared.GameObjects.ViewSubscriberComponent>(uid);
|
||||
|
||||
if (viewSubscriber.SubscribedSessions.Contains(session))
|
||||
return; // Already subscribed, do nothing else.
|
||||
@@ -36,7 +36,7 @@ public sealed class ViewSubscriberSystem : SharedViewSubscriberSystem
|
||||
/// </summary>
|
||||
public override void RemoveViewSubscriber(EntityUid uid, ICommonSession session)
|
||||
{
|
||||
if(!EntityManager.TryGetComponent(uid, out Shared.GameObjects.ViewSubscriberComponent? viewSubscriber))
|
||||
if(!TryComp(uid, out Shared.GameObjects.ViewSubscriberComponent? viewSubscriber))
|
||||
return; // Entity didn't have any subscriptions, do nothing.
|
||||
|
||||
if (!viewSubscriber.SubscribedSessions.Remove(session))
|
||||
|
||||
@@ -132,7 +132,7 @@ internal sealed partial class PvsSystem
|
||||
|
||||
if (enumerateAll)
|
||||
{
|
||||
var query = EntityManager.AllEntityQueryEnumerator<MetaDataComponent>();
|
||||
var query = AllEntityQuery<MetaDataComponent>();
|
||||
while (query.MoveNext(out var uid, out var md))
|
||||
{
|
||||
DebugTools.Assert(md.EntityLifeStage >= EntityLifeStage.Initialized, $"Entity {ToPrettyString(uid)} has not been initialized");
|
||||
|
||||
@@ -199,7 +199,7 @@ internal sealed partial class PvsSystem : EntitySystem
|
||||
|
||||
foreach (var uid in _toDelete)
|
||||
{
|
||||
EntityManager.QueueDeleteEntity(uid);
|
||||
QueueDel(uid);
|
||||
}
|
||||
_toDelete.Clear();
|
||||
|
||||
|
||||
82
Robust.Server/Physics/Commands/BoxStackCommand.cs
Normal file
82
Robust.Server/Physics/Commands/BoxStackCommand.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Collision.Shapes;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Controllers;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
|
||||
namespace Robust.Server.Physics.Commands;
|
||||
|
||||
public sealed class BoxStackCommand : IConsoleCommand
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
|
||||
public string Command => "boxstack";
|
||||
public string Description => string.Empty;
|
||||
public string Help => "boxstack [mapid] [columns] [rows]";
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 3 ||
|
||||
!int.TryParse(args[0], out var mapInt) ||
|
||||
!int.TryParse(args[1], out var columns) ||
|
||||
!int.TryParse(args[2], out var rows))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var mapId = new MapId(mapInt);
|
||||
|
||||
var fixtureSystem = _entManager.System<FixtureSystem>();
|
||||
var physSystem = _entManager.System<SharedPhysicsSystem>();
|
||||
physSystem.SetGravity(new Vector2(0f, -9.8f));
|
||||
|
||||
var groundUid = _entManager.SpawnEntity(null, new MapCoordinates(0, 0, mapId));
|
||||
var ground = _entManager.AddComponent<PhysicsComponent>(groundUid);
|
||||
var groundManager = _entManager.EnsureComponent<FixturesComponent>(groundUid);
|
||||
|
||||
var horizontal = new EdgeShape(new Vector2(-40, 0), new Vector2(40, 0));
|
||||
fixtureSystem.CreateFixture(groundUid, "fix1", new Fixture(horizontal, 1, 1, true), manager: groundManager, body: ground);
|
||||
|
||||
var vertical = new EdgeShape(new Vector2(10, 0), new Vector2(10, 10));
|
||||
fixtureSystem.CreateFixture(groundUid, "fix2", new Fixture(vertical, 1, 1, true), manager: groundManager, body: ground);
|
||||
|
||||
physSystem.WakeBody(groundUid, manager: groundManager, body: ground);
|
||||
|
||||
var xs = new[]
|
||||
{
|
||||
0.0f, -10.0f, -5.0f, 5.0f, 10.0f
|
||||
};
|
||||
|
||||
for (var j = 0; j < columns; j++)
|
||||
{
|
||||
for (var i = 0; i < rows; i++)
|
||||
{
|
||||
var x = 0.0f;
|
||||
|
||||
var boxUid = _entManager.SpawnEntity(null,
|
||||
new MapCoordinates(new Vector2(xs[j] + x, 0.55f + 2.1f * i), mapId));
|
||||
var box = _entManager.AddComponent<PhysicsComponent>(boxUid);
|
||||
var manager = _entManager.EnsureComponent<FixturesComponent>(boxUid);
|
||||
|
||||
physSystem.SetBodyType(boxUid, BodyType.Dynamic, manager: manager, body: box);
|
||||
var poly = new PolygonShape(0.001f);
|
||||
poly.Set(new List<Vector2>()
|
||||
{
|
||||
new(0.5f, -0.5f),
|
||||
new(0.5f, 0.5f),
|
||||
new(-0.5f, 0.5f),
|
||||
new(-0.5f, -0.5f),
|
||||
});
|
||||
|
||||
fixtureSystem.CreateFixture(boxUid, "fix1", new Fixture(poly, 1, 1, true), manager: manager, body: box);
|
||||
physSystem.WakeBody(boxUid, manager: manager, body: box);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,7 +140,7 @@ namespace Robust.Server.Placement
|
||||
{
|
||||
// Replace existing entities if relevant.
|
||||
if (msg.Replacement && _prototype.Index<EntityPrototype>(entityTemplateName).Components.TryGetValue(
|
||||
_factory.GetComponentName(typeof(PlacementReplacementComponent)), out var compRegistry))
|
||||
_factory.GetComponentName<PlacementReplacementComponent>(), out var compRegistry))
|
||||
{
|
||||
var key = ((PlacementReplacementComponent)compRegistry.Component).Key;
|
||||
var gridUid = _xformSystem.GetGrid(coordinates);
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Robust.Server.Player
|
||||
{
|
||||
foreach (var uid in entities)
|
||||
{
|
||||
if (EntityManager.TryGetComponent(uid, out ActorComponent? actor))
|
||||
if (TryComp(uid, out ActorComponent? actor))
|
||||
filter.AddPlayer(actor.PlayerSession);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -188,13 +189,20 @@ namespace Robust.Server.Scripting
|
||||
}
|
||||
|
||||
// Compile ahead of time so that we can do syntax highlighting correctly for the echo.
|
||||
newScript.Compile();
|
||||
await Task.Run(() =>
|
||||
{
|
||||
newScript.Compile();
|
||||
|
||||
// Echo entered script.
|
||||
var echoMessage = new FormattedMessage();
|
||||
ScriptInstanceShared.AddWithSyntaxHighlighting(newScript, echoMessage, code, instance.HighlightWorkspace);
|
||||
// Echo entered script.
|
||||
var echoMessage = new FormattedMessage();
|
||||
ScriptInstanceShared.AddWithSyntaxHighlighting(
|
||||
newScript,
|
||||
echoMessage,
|
||||
code,
|
||||
instance.HighlightWorkspace.Value);
|
||||
|
||||
replyMessage.Echo = echoMessage;
|
||||
replyMessage.Echo = echoMessage;
|
||||
});
|
||||
|
||||
var msg = new FormattedMessage();
|
||||
|
||||
@@ -332,7 +340,7 @@ namespace Robust.Server.Scripting
|
||||
|
||||
private sealed class ScriptInstance
|
||||
{
|
||||
public Workspace HighlightWorkspace { get; } = new AdhocWorkspace();
|
||||
public Lazy<Workspace> HighlightWorkspace { get; } = new(() => new AdhocWorkspace());
|
||||
public StringBuilder InputBuffer { get; } = new();
|
||||
public FormattedMessage OutputBuffer { get; } = new();
|
||||
public bool RunningScript { get; set; }
|
||||
@@ -373,7 +381,7 @@ namespace Robust.Server.Scripting
|
||||
script.Compile();
|
||||
|
||||
var syntax = new FormattedMessage();
|
||||
ScriptInstanceShared.AddWithSyntaxHighlighting(script, syntax, code, _scriptInstance.HighlightWorkspace);
|
||||
ScriptInstanceShared.AddWithSyntaxHighlighting(script, syntax, code, _scriptInstance.HighlightWorkspace.Value);
|
||||
|
||||
_scriptInstance.OutputBuffer.AddMessage(syntax);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -101,6 +102,7 @@ namespace Robust.Shared.Maths
|
||||
/// <summary>
|
||||
/// Returns the smallest rectangle that contains both of the rectangles.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
public readonly Box2i Union(in Box2i other)
|
||||
{
|
||||
var botLeft = Vector2i.ComponentMin(BottomLeft, other.BottomLeft);
|
||||
@@ -207,6 +209,7 @@ namespace Robust.Shared.Maths
|
||||
/// <summary>
|
||||
/// Multiplies each side of the box by the scalar.
|
||||
/// </summary>
|
||||
[Pure]
|
||||
public Box2i Scale(int scalar)
|
||||
{
|
||||
return new Box2i(
|
||||
@@ -215,6 +218,21 @@ namespace Robust.Shared.Maths
|
||||
Right * scalar,
|
||||
Top * scalar);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[Pure]
|
||||
public bool Intersects(in Box2i other)
|
||||
{
|
||||
return other.Bottom <= this.Top && other.Top >= this.Bottom && other.Right >= this.Left &&
|
||||
other.Left <= this.Right;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[Pure]
|
||||
public readonly Box2i Enlarged(int size)
|
||||
{
|
||||
return new(Left - size, Bottom - size, Right + size, Top + size);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -13,7 +13,8 @@ namespace Robust.Shared.Audio;
|
||||
/// <seealso cref="ResolvedPathSpecifier"/>
|
||||
/// <seealso cref="ResolvedCollectionSpecifier"/>
|
||||
[Serializable, NetSerializable]
|
||||
public abstract partial class ResolvedSoundSpecifier {
|
||||
public abstract partial class ResolvedSoundSpecifier
|
||||
{
|
||||
[Obsolete("String literals for sounds are deprecated, use a SoundSpecifier or ResolvedSoundSpecifier as appropriate instead")]
|
||||
public static implicit operator ResolvedSoundSpecifier(string s) => new ResolvedPathSpecifier(s);
|
||||
[Obsolete("String literals for sounds are deprecated, use a SoundSpecifier or ResolvedSoundSpecifier as appropriate instead")]
|
||||
@@ -22,8 +23,10 @@ public abstract partial class ResolvedSoundSpecifier {
|
||||
/// <summary>
|
||||
/// Returns whether <c>s</c> is null, or if it contains an empty path/collection ID.
|
||||
/// </summary>
|
||||
public static bool IsNullOrEmpty(ResolvedSoundSpecifier? s) {
|
||||
return s switch {
|
||||
public static bool IsNullOrEmpty(ResolvedSoundSpecifier? s)
|
||||
{
|
||||
return s switch
|
||||
{
|
||||
null => true,
|
||||
ResolvedPathSpecifier path => path.Path.ToString() == "",
|
||||
ResolvedCollectionSpecifier collection => string.IsNullOrEmpty(collection.Collection),
|
||||
@@ -37,7 +40,8 @@ public abstract partial class ResolvedSoundSpecifier {
|
||||
/// </summary>
|
||||
/// <seealso cref="ResolvedCollectionSpecifier"/>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed partial class ResolvedPathSpecifier : ResolvedSoundSpecifier {
|
||||
public sealed partial class ResolvedPathSpecifier : ResolvedSoundSpecifier, IEquatable<ResolvedPathSpecifier>
|
||||
{
|
||||
/// <summary>
|
||||
/// The resource path of the sound.
|
||||
/// </summary>
|
||||
@@ -57,6 +61,21 @@ public sealed partial class ResolvedPathSpecifier : ResolvedSoundSpecifier {
|
||||
public ResolvedPathSpecifier(string path) : this(new ResPath(path))
|
||||
{
|
||||
}
|
||||
|
||||
public bool Equals(ResolvedPathSpecifier? other)
|
||||
{
|
||||
return Path.Equals(other?.Path);
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return Equals(obj as ResolvedPathSpecifier);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Path.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -64,7 +83,9 @@ public sealed partial class ResolvedPathSpecifier : ResolvedSoundSpecifier {
|
||||
/// </summary>
|
||||
/// <seealso cref="ResolvedPathSpecifier"/>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed partial class ResolvedCollectionSpecifier : ResolvedSoundSpecifier {
|
||||
public sealed partial class ResolvedCollectionSpecifier : ResolvedSoundSpecifier, IEquatable<ResolvedCollectionSpecifier>
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The ID of the <see cref="SoundCollectionPrototype">sound collection</see> to look up.
|
||||
/// </summary>
|
||||
@@ -87,4 +108,19 @@ public sealed partial class ResolvedCollectionSpecifier : ResolvedSoundSpecifier
|
||||
Collection = collection;
|
||||
Index = index;
|
||||
}
|
||||
|
||||
public bool Equals(ResolvedCollectionSpecifier? other)
|
||||
{
|
||||
return Collection.Equals(other?.Collection) && Index.Equals(other?.Index);
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return Equals(obj as ResolvedCollectionSpecifier);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(Collection, Index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -665,7 +665,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
|
||||
/// <param name="coordinates">The coordinates at which to play the audio.</param>
|
||||
public (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(SoundSpecifier? sound, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null)
|
||||
{
|
||||
return sound == null ? null : PlayStatic(ResolveSound(sound), playerFilter, coordinates, recordReplay, audioParams);
|
||||
return sound == null ? null : PlayStatic(ResolveSound(sound), playerFilter, coordinates, recordReplay, audioParams ?? sound.Params);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -127,19 +127,20 @@ public sealed class TeleportToCommand : LocalizedEntityCommands
|
||||
{
|
||||
foreach (var victim in args)
|
||||
{
|
||||
if (victim == target)
|
||||
if (!TryGetTransformFromUidOrUsername(victim, shell, out var uid, out var victimTransform))
|
||||
continue;
|
||||
|
||||
if (!TryGetTransformFromUidOrUsername(victim, shell, out var uid, out var victimTransform))
|
||||
if (uid == targetUid)
|
||||
continue;
|
||||
|
||||
victims.Add((uid.Value, victimTransform));
|
||||
}
|
||||
}
|
||||
|
||||
var targetMapCoords = _transform.ToMapCoordinates(targetCoords);
|
||||
foreach (var victim in victims)
|
||||
{
|
||||
_transform.SetCoordinates(victim.Entity, targetCoords);
|
||||
_transform.SetMapCoordinates(victim.Entity, targetMapCoords);
|
||||
_transform.AttachToGridOrMap(victim.Entity, victim.Transform);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -155,7 +156,7 @@ public static class CompletionHelper
|
||||
/// Returns a completion list for all prototype IDs of the given type.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Don't use this for prototypes types that likely have a large number of entries, like <see cref="EntityPrototype"/>.
|
||||
/// Don't use this for prototypes types that likely have a large number of entries, like <see cref="EntityPrototype"/>, use <see cref="PrototypeIdsLimited{T}"/> instead.
|
||||
/// </remarks>
|
||||
public static IEnumerable<CompletionOption> PrototypeIDs<T>(bool sorted = true, IPrototypeManager? proto = null)
|
||||
where T: class, IPrototype
|
||||
@@ -166,6 +167,36 @@ public static class CompletionHelper
|
||||
return sorted ? protoOptions.OrderBy(o => o.Value) : protoOptions;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a completion list for all prototype IDs of the given type, limited to avoid performance problems.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is a limited alternative to <see cref="PrototypeIDs{T}"/>.
|
||||
/// The limit is applied before sorting of results, so the unfiltered results are somewhat arbitrary.
|
||||
/// </remarks>
|
||||
/// <param name="currentArgument">The argument being currently typed for the completion.</param>
|
||||
/// <param name="proto">The <see cref="IPrototypeManager"/>.</param>
|
||||
/// <param name="sorted">Whether to sort the results or not.</param>
|
||||
/// <param name="maxCount">The maximum amount of results to return at once.</param>
|
||||
/// <typeparam name="T">The type of prototype to search through.</typeparam>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<CompletionOption> PrototypeIdsLimited<T>(
|
||||
string currentArgument,
|
||||
IPrototypeManager proto,
|
||||
bool sorted = true,
|
||||
int maxCount = 30) where T : class, IPrototype
|
||||
{
|
||||
var protoOptions = proto.EnumeratePrototypes<T>()
|
||||
.Where(p => p.ID.StartsWith(currentArgument, StringComparison.OrdinalIgnoreCase))
|
||||
.Take(maxCount)
|
||||
.Select(p => new CompletionOption(p.ID));
|
||||
|
||||
if (sorted)
|
||||
protoOptions = protoOptions.OrderBy(o => o.Value);
|
||||
|
||||
return protoOptions;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of connected session names.
|
||||
/// </summary>
|
||||
|
||||
@@ -279,16 +279,6 @@ namespace Robust.Shared.Containers
|
||||
|
||||
#region Container Helpers
|
||||
|
||||
[Obsolete("Use Entity<T> variant")]
|
||||
public bool TryGetContainingContainer(
|
||||
EntityUid uid,
|
||||
[NotNullWhen(true)] out BaseContainer? container,
|
||||
MetaDataComponent? meta = null,
|
||||
TransformComponent? transform = null)
|
||||
{
|
||||
return TryGetContainingContainer((uid, transform, meta), out container);
|
||||
}
|
||||
|
||||
public bool TryGetContainingContainer(
|
||||
Entity<TransformComponent?, MetaDataComponent?> ent,
|
||||
[NotNullWhen(true)] out BaseContainer? container)
|
||||
@@ -401,13 +391,6 @@ namespace Robust.Shared.Containers
|
||||
return TryFindComponentsOnEntityContainerOrParent(xform.ParentUid, entityQuery, foundComponents);
|
||||
}
|
||||
|
||||
|
||||
[Obsolete("Use Entity<T> variant")]
|
||||
public bool IsInSameOrNoContainer(EntityUid user, EntityUid other)
|
||||
{
|
||||
return IsInSameOrNoContainer((user, null, null), (other, null, null));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the two entities are not contained, or are contained in the same container.
|
||||
/// </summary>
|
||||
@@ -428,13 +411,6 @@ namespace Robust.Shared.Containers
|
||||
return userContainer == otherContainer;
|
||||
}
|
||||
|
||||
|
||||
[Obsolete("Use Entity<T> variant")]
|
||||
public bool IsInSameOrParentContainer(EntityUid user, EntityUid other)
|
||||
{
|
||||
return IsInSameOrParentContainer((user, null), other);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the two entities are not contained, or are contained in the same container, or if one
|
||||
/// entity contains the other (i.e., is the parent).
|
||||
@@ -469,21 +445,6 @@ namespace Robust.Shared.Containers
|
||||
return userContainer == otherContainer;
|
||||
}
|
||||
|
||||
[Obsolete("Use Entity<T> variant")]
|
||||
public bool IsInSameOrTransparentContainer(
|
||||
EntityUid user,
|
||||
EntityUid other,
|
||||
BaseContainer? userContainer = null,
|
||||
BaseContainer? otherContainer = null,
|
||||
bool userSeeInsideSelf = false)
|
||||
{
|
||||
return IsInSameOrTransparentContainer((user, null),
|
||||
other,
|
||||
userContainer,
|
||||
otherContainer,
|
||||
userSeeInsideSelf);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether a given entity can see another entity despite whatever containers they may be in.
|
||||
/// </summary>
|
||||
@@ -606,7 +567,7 @@ namespace Robust.Shared.Containers
|
||||
/// <param name="force">Whether to forcibly remove the entity from the container.</param>
|
||||
/// <param name="wasInContainer">Whether the entity was actually inside a container or not.</param>
|
||||
/// <returns>If the entity could be removed. Also returns false if it wasn't inside a container.</returns>
|
||||
public bool TryRemoveFromContainer(EntityUid entity, bool force, out bool wasInContainer)
|
||||
public bool TryRemoveFromContainer(Entity<TransformComponent?, MetaDataComponent?> entity, bool force, out bool wasInContainer)
|
||||
{
|
||||
DebugTools.Assert(Exists(entity));
|
||||
|
||||
@@ -631,7 +592,7 @@ namespace Robust.Shared.Containers
|
||||
/// <param name="entity">Entity that might be inside a container.</param>
|
||||
/// <param name="force">Whether to forcibly remove the entity from the container.</param>
|
||||
/// <returns>If the entity could be removed. Also returns false if it wasn't inside a container.</returns>
|
||||
public bool TryRemoveFromContainer(EntityUid entity, bool force = false)
|
||||
public bool TryRemoveFromContainer(Entity<TransformComponent?, MetaDataComponent?> entity, bool force = false)
|
||||
{
|
||||
return TryRemoveFromContainer(entity, force, out _);
|
||||
}
|
||||
@@ -678,9 +639,8 @@ namespace Robust.Shared.Containers
|
||||
{
|
||||
// TODO make this check upwards for any container, and parent to that.
|
||||
// Currently this just checks the direct parent, so entities will still teleport through containers.
|
||||
|
||||
if (!transform.Comp.ParentUid.IsValid()
|
||||
|| !TryGetContainingContainer(transform.Comp.ParentUid, out var container)
|
||||
|| !TryGetContainingContainer((transform.Comp.ParentUid, Transform(transform.Comp.ParentUid)), out var container)
|
||||
|| !TryInsertIntoContainer(transform, container))
|
||||
{
|
||||
_transform.AttachToGridOrMap(transform, transform.Comp);
|
||||
@@ -692,8 +652,9 @@ namespace Robust.Shared.Containers
|
||||
if (Insert((transform.Owner, transform.Comp, null, null), container))
|
||||
return true;
|
||||
|
||||
if (Transform(container.Owner).ParentUid.IsValid()
|
||||
&& TryGetContainingContainer(container.Owner, out var newContainer))
|
||||
var ownerXform = Transform(container.Owner);
|
||||
if (ownerXform.ParentUid.IsValid()
|
||||
&& TryGetContainingContainer((container.Owner, ownerXform), out var newContainer))
|
||||
return TryInsertIntoContainer(transform, newContainer);
|
||||
|
||||
return false;
|
||||
|
||||
@@ -547,19 +547,20 @@ public sealed class EntityDeserializer :
|
||||
_stopwatch.Restart();
|
||||
foreach (var (entity, data) in Entities)
|
||||
{
|
||||
#if EXCEPTION_TOLERANCE
|
||||
try
|
||||
{
|
||||
#endif
|
||||
CurrentReadingEntity = data;
|
||||
LoadEntity(entity, _metaQuery.Comp(entity), data.Components, data.MissingComponents);
|
||||
#if EXCEPTION_TOLERANCE
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
#if !EXCEPTION_TOLERANCE
|
||||
throw;
|
||||
#endif
|
||||
ToDelete.Add(entity);
|
||||
_log.Error($"Encountered error while loading entity. Yaml uid: {data.YamlId}. Loaded loaded entity: {EntMan.ToPrettyString(entity)}. Error:\n{e}.");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
CurrentReadingEntity = null;
|
||||
|
||||
@@ -162,8 +162,8 @@ public sealed class EntitySerializer : ISerializationContext,
|
||||
_log = _logMan.GetSawmill("entity_serializer");
|
||||
SerializerProvider.RegisterSerializer(this);
|
||||
|
||||
_metaName = _factory.GetComponentName(typeof(MetaDataComponent));
|
||||
_xformName = _factory.GetComponentName(typeof(TransformComponent));
|
||||
_metaName = _factory.GetComponentName<MetaDataComponent>();
|
||||
_xformName = _factory.GetComponentName<TransformComponent>();
|
||||
_emptyMetaNode = _serialization.WriteValueAs<MappingDataNode>(typeof(MetaDataComponent), new MetaDataComponent(), alwaysWrite: true, context: this);
|
||||
|
||||
CurrentComponent = _xformName;
|
||||
|
||||
@@ -41,6 +41,31 @@ public sealed partial class MapLoaderSystem
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to load entities from a YAML file, taking in a raw byte stream.
|
||||
/// </summary>
|
||||
/// <param name="file">The file contents to load from.</param>
|
||||
/// <param name="fileName">
|
||||
/// The name of the file being loaded. This is used purely for logging/informational purposes.
|
||||
/// </param>
|
||||
/// <param name="result">The result of the load operation.</param>
|
||||
/// <param name="options">Options for the load operation.</param>
|
||||
/// <returns>True if the load succeeded, false otherwise.</returns>
|
||||
/// <seealso cref="M:Robust.Shared.EntitySerialization.Systems.MapLoaderSystem.TryLoadGeneric(Robust.Shared.Utility.ResPath,Robust.Shared.EntitySerialization.LoadResult@,System.Nullable{Robust.Shared.EntitySerialization.MapLoadOptions})"/>
|
||||
public bool TryLoadGeneric(
|
||||
Stream file,
|
||||
string fileName,
|
||||
[NotNullWhen(true)] out LoadResult? result,
|
||||
MapLoadOptions? options = null)
|
||||
{
|
||||
result = null;
|
||||
|
||||
if (!TryReadFile(new StreamReader(file), out var data))
|
||||
return false;
|
||||
|
||||
return TryLoadGeneric(data, fileName, out result, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to load entities from a yaml file. Whenever possible, you should try to use <see cref="TryLoadMap"/>,
|
||||
/// <see cref="TryLoadGrid"/>, or <see cref="TryLoadEntity"/> instead.
|
||||
@@ -55,6 +80,17 @@ public sealed partial class MapLoaderSystem
|
||||
if (!TryReadFile(file, out var data))
|
||||
return false;
|
||||
|
||||
return TryLoadGeneric(data, file.ToString(), out result, options);
|
||||
}
|
||||
|
||||
private bool TryLoadGeneric(
|
||||
MappingDataNode data,
|
||||
string fileName,
|
||||
[NotNullWhen(true)] out LoadResult? result,
|
||||
MapLoadOptions? options = null)
|
||||
{
|
||||
result = null;
|
||||
|
||||
_stopwatch.Restart();
|
||||
var ev = new BeforeEntityReadEvent();
|
||||
RaiseLocalEvent(ev);
|
||||
@@ -85,7 +121,7 @@ public sealed partial class MapLoaderSystem
|
||||
|
||||
if (!deserializer.TryProcessData())
|
||||
{
|
||||
Log.Debug($"Failed to process entity data in {file}");
|
||||
Log.Debug($"Failed to process entity data in {fileName}");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -95,7 +131,7 @@ public sealed partial class MapLoaderSystem
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error($"Caught exception while creating entities for map {file}: {e}");
|
||||
Log.Error($"Caught exception while creating entities for map {fileName}: {e}");
|
||||
Delete(deserializer.Result);
|
||||
throw;
|
||||
}
|
||||
@@ -103,7 +139,7 @@ public sealed partial class MapLoaderSystem
|
||||
if (opts.ExpectedCategory is { } exp && exp != deserializer.Result.Category)
|
||||
{
|
||||
// Did someone try to load a map file as a grid or vice versa?
|
||||
Log.Error($"Map {file} does not contain the expected data. Expected {exp} but got {deserializer.Result.Category}");
|
||||
Log.Error($"Map {fileName} does not contain the expected data. Expected {exp} but got {deserializer.Result.Category}");
|
||||
Delete(deserializer.Result);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -64,6 +64,13 @@ public sealed partial class MapLoaderSystem : EntitySystem
|
||||
return false;
|
||||
|
||||
Log.Info($"Loading file: {resPath}");
|
||||
return TryReadFile(reader, out data);
|
||||
}
|
||||
|
||||
private bool TryReadFile(TextReader reader, [NotNullWhen(true)] out MappingDataNode? data)
|
||||
{
|
||||
data = null;
|
||||
|
||||
_stopwatch.Restart();
|
||||
|
||||
using var textReader = reader;
|
||||
|
||||
@@ -633,7 +633,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// An invalid entity UID indicates that this entity has intentionally been removed from broadphases and should
|
||||
/// not automatically be re-added by movement events.
|
||||
/// </remarks>
|
||||
internal record struct BroadphaseData(EntityUid Uid, EntityUid PhysicsMap, bool CanCollide, bool Static)
|
||||
internal record struct BroadphaseData(EntityUid Uid, bool CanCollide, bool Static)
|
||||
{
|
||||
public bool IsValid() => Uid.IsValid();
|
||||
public bool Valid => IsValid();
|
||||
|
||||
@@ -4,6 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Robust.Shared.Collections;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
@@ -84,12 +85,17 @@ public partial class EntityManager
|
||||
return ents;
|
||||
}
|
||||
|
||||
public void SpawnEntitiesAttachedTo(EntityCoordinates coordinates, IEnumerable<EntProtoId> protoNames)
|
||||
public EntityUid[] SpawnEntitiesAttachedTo(EntityCoordinates coordinates, IEnumerable<EntProtoId> protoNames)
|
||||
{
|
||||
var ents = new ValueList<EntityUid>();
|
||||
|
||||
foreach (var protoName in protoNames)
|
||||
{
|
||||
SpawnAttachedTo(protoName, coordinates);
|
||||
var uid = SpawnAttachedTo(protoName, coordinates);
|
||||
ents.Add(uid);
|
||||
}
|
||||
|
||||
return ents.ToArray();
|
||||
}
|
||||
|
||||
public virtual EntityUid SpawnAttachedTo(string? protoName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default)
|
||||
|
||||
@@ -161,7 +161,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// <summary>
|
||||
/// Returns true if the entity's data (apart from transform) is default.
|
||||
/// </summary>
|
||||
public bool IsDefault(EntityUid uid)
|
||||
public bool IsDefault(EntityUid uid, ICollection<string>? ignoredComps = null)
|
||||
{
|
||||
if (!MetaQuery.TryGetComponent(uid, out var metadata) || metadata.EntityPrototype == null)
|
||||
return false;
|
||||
@@ -195,6 +195,9 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
var compName = _componentFactory.GetComponentName(compType);
|
||||
|
||||
if (ignoredComps?.Contains(compName) == true)
|
||||
continue;
|
||||
|
||||
// If the component isn't on the prototype then it's custom.
|
||||
if (!protoData.TryGetValue(compName, out var protoMapping))
|
||||
return false;
|
||||
@@ -498,7 +501,7 @@ namespace Robust.Shared.GameObjects
|
||||
if (Deleted(uid.Value))
|
||||
return false;
|
||||
|
||||
if (!QueuedDeletionsSet.Add(uid.Value))
|
||||
if (QueuedDeletionsSet.Contains(uid.Value))
|
||||
return false;
|
||||
|
||||
QueueDeleteEntity(uid);
|
||||
|
||||
@@ -665,7 +665,7 @@ public partial class EntitySystem
|
||||
|
||||
/// <inheritdoc cref="IEntityManager.AddComponent<T>(EntityUid)"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected T AddComp<T>(EntityUid uid) where T : Component, new()
|
||||
protected T AddComp<T>(EntityUid uid) where T : IComponent, new()
|
||||
{
|
||||
return EntityManager.AddComponent<T>(uid);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Shared.Collections;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
@@ -22,7 +23,7 @@ public partial interface IEntityManager
|
||||
EntityUid[] SpawnEntities(MapCoordinates coordinates, params string?[] protoNames);
|
||||
EntityUid[] SpawnEntities(MapCoordinates coordinates, string? prototype, int count);
|
||||
EntityUid[] SpawnEntities(MapCoordinates coordinates, List<string?> protoNames);
|
||||
void SpawnEntitiesAttachedTo(EntityCoordinates coordinates, IEnumerable<EntProtoId> protoNames);
|
||||
EntityUid[] SpawnEntitiesAttachedTo(EntityCoordinates coordinates, IEnumerable<EntProtoId> protoNames);
|
||||
EntityUid[] SpawnEntitiesAttachedTo(EntityCoordinates coordinates, params EntProtoId[] protoNames);
|
||||
EntityUid[] SpawnEntitiesAttachedTo(EntityCoordinates coordinates, List<string?> protoNames);
|
||||
EntityUid[] SpawnEntitiesAttachedTo(EntityCoordinates coordinates, params string?[] protoNames);
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
private void OnStartup(EntityUid uid, CollideOnAnchorComponent component, ComponentStartup args)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out TransformComponent? transformComponent)) return;
|
||||
if (!TryComp(uid, out TransformComponent? transformComponent)) return;
|
||||
|
||||
SetCollide(uid, component, transformComponent.Anchored);
|
||||
}
|
||||
@@ -31,7 +31,7 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
private void SetCollide(EntityUid uid, CollideOnAnchorComponent component, bool anchored)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out PhysicsComponent? body)) return;
|
||||
if (!TryComp(uid, out PhysicsComponent? body)) return;
|
||||
|
||||
var enabled = component.Enable;
|
||||
|
||||
|
||||
@@ -89,7 +89,6 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
private EntityQuery<MapGridComponent> _gridQuery;
|
||||
private EntityQuery<MetaDataComponent> _metaQuery;
|
||||
private EntityQuery<PhysicsComponent> _physicsQuery;
|
||||
private EntityQuery<PhysicsMapComponent> _physMapQuery;
|
||||
private EntityQuery<TransformComponent> _xformQuery;
|
||||
|
||||
/// <summary>
|
||||
@@ -119,7 +118,6 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
_gridQuery = GetEntityQuery<MapGridComponent>();
|
||||
_metaQuery = GetEntityQuery<MetaDataComponent>();
|
||||
_physicsQuery = GetEntityQuery<PhysicsComponent>();
|
||||
_physMapQuery = GetEntityQuery<PhysicsMapComponent>();
|
||||
_xformQuery = GetEntityQuery<TransformComponent>();
|
||||
|
||||
SubscribeLocalEvent<BroadphaseComponent, EntityTerminatingEvent>(OnBroadphaseTerminating);
|
||||
@@ -153,15 +151,12 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
private void OnBroadphaseTerminating(EntityUid uid, BroadphaseComponent component, ref EntityTerminatingEvent args)
|
||||
{
|
||||
var xform = _xformQuery.GetComponent(uid);
|
||||
var map = xform.MapUid;
|
||||
_physMapQuery.TryGetComponent(map, out var physMap);
|
||||
RemoveChildrenFromTerminatingBroadphase(xform, component, physMap);
|
||||
RemoveChildrenFromTerminatingBroadphase(xform, component);
|
||||
RemComp(uid, component);
|
||||
}
|
||||
|
||||
private void RemoveChildrenFromTerminatingBroadphase(TransformComponent xform,
|
||||
BroadphaseComponent component,
|
||||
PhysicsMapComponent? map)
|
||||
BroadphaseComponent component)
|
||||
{
|
||||
foreach (var child in xform._children)
|
||||
{
|
||||
@@ -179,19 +174,15 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
|
||||
if (childXform.Broadphase.Value.CanCollide && _fixturesQuery.TryGetComponent(child, out var fixtures))
|
||||
{
|
||||
if (map == null)
|
||||
_physMapQuery.TryGetComponent(childXform.Broadphase.Value.PhysicsMap, out map);
|
||||
|
||||
DebugTools.Assert(map == null || childXform.Broadphase.Value.PhysicsMap == map.Owner);
|
||||
var tree = childXform.Broadphase.Value.Static ? component.StaticTree : component.DynamicTree;
|
||||
foreach (var fixture in fixtures.Fixtures.Values)
|
||||
{
|
||||
DestroyProxies(fixture, tree, map);
|
||||
DestroyProxies(fixture, tree);
|
||||
}
|
||||
}
|
||||
|
||||
childXform.Broadphase = null;
|
||||
RemoveChildrenFromTerminatingBroadphase(childXform, component, map);
|
||||
RemoveChildrenFromTerminatingBroadphase(childXform, component);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,26 +218,18 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
if (xform.MapUid == null)
|
||||
return;
|
||||
|
||||
if (!_physMapQuery.TryGetComponent(xform.MapUid, out var physMap))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Broadphase's map is missing a physics map comp. Broadphase: {ToPrettyString(broadphase.Owner)}");
|
||||
}
|
||||
|
||||
var ent = new Entity<TransformComponent, BroadphaseComponent>(broadphase, xform, broadphase);
|
||||
var map = new Entity<PhysicsMapComponent>(xform.MapUid.Value, physMap);
|
||||
var enumerator = xform.ChildEnumerator;
|
||||
while (enumerator.MoveNext(out var child))
|
||||
{
|
||||
if (!_broadQuery.HasComp(child))
|
||||
InitializeChild(child, ent, map);
|
||||
InitializeChild(child, ent);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeChild(
|
||||
EntityUid child,
|
||||
Entity<TransformComponent, BroadphaseComponent> broadphase,
|
||||
Entity<PhysicsMapComponent> map)
|
||||
Entity<TransformComponent, BroadphaseComponent> broadphase)
|
||||
{
|
||||
if (LifeStage(child) <= EntityLifeStage.PreInit)
|
||||
return;
|
||||
@@ -258,7 +241,6 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
if (!xform.Broadphase.Value.IsValid())
|
||||
return; // Entity is intentionally not on a broadphase (deferred updating?).
|
||||
|
||||
_physMapQuery.TryGetComponent(xform.Broadphase.Value.PhysicsMap, out var oldPhysMap);
|
||||
if (!_broadQuery.TryGetComponent(xform.Broadphase.Value.Uid, out var oldBroadphase))
|
||||
{
|
||||
DebugTools.Assert("Encountered deleted broadphase.");
|
||||
@@ -275,16 +257,15 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
}
|
||||
else if (oldBroadphase != broadphase.Comp2)
|
||||
{
|
||||
RemoveFromEntityTree(xform.Broadphase.Value.Uid, oldBroadphase, ref oldPhysMap, child, xform);
|
||||
RemoveFromEntityTree(xform.Broadphase.Value.Uid, oldBroadphase,child, xform);
|
||||
}
|
||||
}
|
||||
|
||||
DebugTools.Assert(xform.Broadphase is not {} x || x.Uid == broadphase.Owner && (!x.CanCollide || x.PhysicsMap == map.Owner));
|
||||
DebugTools.Assert(xform.Broadphase is not {} x || x.Uid == broadphase.Owner && !x.CanCollide);
|
||||
AddOrUpdateEntityTree(
|
||||
broadphase.Owner,
|
||||
broadphase.Comp2,
|
||||
broadphase.Comp1,
|
||||
map.Comp,
|
||||
child,
|
||||
xform);
|
||||
}
|
||||
@@ -315,9 +296,6 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
if (!TryGetCurrentBroadphase(xform, out var broadphase))
|
||||
return;
|
||||
|
||||
if (!_physMapQuery.TryGetComponent(xform.MapUid, out var physMap))
|
||||
throw new InvalidOperationException();
|
||||
|
||||
var (worldPos, worldRot) = _transform.GetWorldPositionRotation(xform);
|
||||
var mapTransform = new Transform(worldPos, worldRot);
|
||||
|
||||
@@ -326,10 +304,10 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
var tree = body.BodyType == BodyType.Static ? broadphase.StaticTree : broadphase.DynamicTree;
|
||||
DebugTools.Assert(fixture.ProxyCount == 0);
|
||||
|
||||
AddOrMoveProxies(uid, fixtureId, fixture, body, tree, broadphaseTransform, mapTransform, physMap.MoveBuffer);
|
||||
AddOrMoveProxies((uid, body, xform), fixtureId, fixture, tree, broadphaseTransform);
|
||||
}
|
||||
|
||||
internal void DestroyProxies(EntityUid uid, string fixtureId, Fixture fixture, TransformComponent xform, BroadphaseComponent broadphase, PhysicsMapComponent? physicsMap)
|
||||
internal void DestroyProxies(EntityUid uid, string fixtureId, Fixture fixture, TransformComponent xform, BroadphaseComponent broadphase)
|
||||
{
|
||||
DebugTools.AssertNotNull(xform.Broadphase);
|
||||
DebugTools.Assert(xform.Broadphase!.Value.Uid == broadphase.Owner);
|
||||
@@ -344,7 +322,7 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
}
|
||||
|
||||
var tree = xform.Broadphase.Value.Static ? broadphase.StaticTree : broadphase.DynamicTree;
|
||||
DestroyProxies(fixture, tree, physicsMap);
|
||||
DestroyProxies(fixture, tree);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -395,8 +373,7 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
var fixtures = Comp<FixturesComponent>(uid);
|
||||
if (old.CanCollide)
|
||||
{
|
||||
_physMapQuery.TryGetComponent(old.PhysicsMap, out var physicsMap);
|
||||
RemoveBroadTree(broadphase, fixtures, old.Static, physicsMap);
|
||||
RemoveBroadTree(broadphase, fixtures, old.Static);
|
||||
}
|
||||
else
|
||||
(old.Static ? broadphase.StaticSundriesTree : broadphase.SundriesTree).Remove(uid);
|
||||
@@ -408,23 +385,23 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
AddOrUpdateSundriesTree(old.Uid, broadphase, uid, xform, body.BodyType == BodyType.Static);
|
||||
}
|
||||
|
||||
private void RemoveBroadTree(BroadphaseComponent lookup, FixturesComponent manager, bool staticBody, PhysicsMapComponent? map)
|
||||
private void RemoveBroadTree(BroadphaseComponent lookup, FixturesComponent manager, bool staticBody)
|
||||
{
|
||||
var tree = staticBody ? lookup.StaticTree : lookup.DynamicTree;
|
||||
foreach (var fixture in manager.Fixtures.Values)
|
||||
{
|
||||
DestroyProxies(fixture, tree, map);
|
||||
DestroyProxies(fixture, tree);
|
||||
}
|
||||
}
|
||||
|
||||
internal void DestroyProxies(Fixture fixture, IBroadPhase tree, PhysicsMapComponent? map)
|
||||
internal void DestroyProxies(Fixture fixture, IBroadPhase tree)
|
||||
{
|
||||
var buffer = map?.MoveBuffer;
|
||||
var buffer = _physics.MoveBuffer;
|
||||
for (var i = 0; i < fixture.ProxyCount; i++)
|
||||
{
|
||||
var proxy = fixture.Proxies[i];
|
||||
tree.RemoveProxy(proxy.ProxyId);
|
||||
buffer?.Remove(proxy);
|
||||
buffer.Remove(proxy);
|
||||
}
|
||||
|
||||
fixture.ProxyCount = 0;
|
||||
@@ -438,10 +415,7 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
if (broadphaseXform.MapID == MapId.Nullspace)
|
||||
return;
|
||||
|
||||
if (!_physMapQuery.TryGetComponent(broadphaseXform.MapUid, out var physMap))
|
||||
throw new InvalidOperationException($"Physics Broadphase is missing physics map. {ToPrettyString(broadUid)}");
|
||||
|
||||
AddOrUpdatePhysicsTree(uid, broadUid, broadphase, broadphaseXform, physMap, xform, body, fixtures);
|
||||
AddOrUpdatePhysicsTree(uid, broadUid, broadphase, broadphaseXform, xform, body, fixtures);
|
||||
}
|
||||
|
||||
private void AddOrUpdatePhysicsTree(
|
||||
@@ -449,16 +423,15 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
EntityUid broadUid,
|
||||
BroadphaseComponent broadphase,
|
||||
TransformComponent broadphaseXform,
|
||||
PhysicsMapComponent physicsMap,
|
||||
TransformComponent xform,
|
||||
PhysicsComponent body,
|
||||
FixturesComponent manager)
|
||||
{
|
||||
DebugTools.Assert(!_container.IsEntityOrParentInContainer(body.Owner, null, xform));
|
||||
DebugTools.Assert(xform.Broadphase == null || xform.Broadphase == new BroadphaseData(broadphase.Owner, physicsMap.Owner, body.CanCollide, body.BodyType == BodyType.Static));
|
||||
DebugTools.Assert(xform.Broadphase == null || xform.Broadphase == new BroadphaseData(broadphase.Owner, body.CanCollide, body.BodyType == BodyType.Static));
|
||||
DebugTools.Assert(broadphase.Owner == broadUid);
|
||||
|
||||
xform.Broadphase ??= new(broadUid, physicsMap.Owner, body.CanCollide, body.BodyType == BodyType.Static);
|
||||
xform.Broadphase ??= new(broadUid, body.CanCollide, body.BodyType == BodyType.Static);
|
||||
var tree = body.BodyType == BodyType.Static ? broadphase.StaticTree : broadphase.DynamicTree;
|
||||
|
||||
// TOOD optimize this. This function iterates UP through parents, while we are currently iterating down.
|
||||
@@ -470,20 +443,19 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
|
||||
foreach (var (id, fixture) in manager.Fixtures)
|
||||
{
|
||||
AddOrMoveProxies(uid, id, fixture, body, tree, broadphaseTransform, mapTransform, physicsMap.MoveBuffer);
|
||||
AddOrMoveProxies((uid, body, xform), id, fixture, tree, broadphaseTransform);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddOrMoveProxies(
|
||||
EntityUid uid,
|
||||
Entity<PhysicsComponent, TransformComponent> ent,
|
||||
string fixtureId,
|
||||
Fixture fixture,
|
||||
PhysicsComponent body,
|
||||
IBroadPhase tree,
|
||||
Transform broadphaseTransform,
|
||||
Transform mapTransform,
|
||||
Dictionary<FixtureProxy, Box2> moveBuffer)
|
||||
Transform broadphaseTransform)
|
||||
{
|
||||
var moveBuffer = _physics.MoveBuffer;
|
||||
|
||||
// Moving
|
||||
if (fixture.ProxyCount > 0)
|
||||
{
|
||||
@@ -493,7 +465,7 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
var proxy = fixture.Proxies[i];
|
||||
tree.MoveProxy(proxy.ProxyId, bounds);
|
||||
proxy.AABB = bounds;
|
||||
moveBuffer[proxy] = fixture.Shape.ComputeAABB(mapTransform, i);
|
||||
moveBuffer.Add(proxy);
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -505,11 +477,11 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var bounds = fixture.Shape.ComputeAABB(broadphaseTransform, i);
|
||||
var proxy = new FixtureProxy(uid, body, bounds, fixtureId, fixture, i);
|
||||
var proxy = new FixtureProxy(ent.Owner, ent.Comp1, ent.Comp2, bounds, fixtureId, fixture, i);
|
||||
proxy.ProxyId = tree.AddProxy(ref proxy);
|
||||
proxy.AABB = bounds;
|
||||
proxies[i] = proxy;
|
||||
moveBuffer[proxy] = fixture.Shape.ComputeAABB(mapTransform, i);
|
||||
moveBuffer.Add(proxy);
|
||||
}
|
||||
|
||||
fixture.Proxies = proxies;
|
||||
@@ -519,8 +491,8 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
private void AddOrUpdateSundriesTree(EntityUid broadUid, BroadphaseComponent broadphase, EntityUid uid, TransformComponent xform, bool staticBody, Box2? aabb = null)
|
||||
{
|
||||
DebugTools.Assert(!_container.IsEntityOrParentInContainer(uid));
|
||||
DebugTools.Assert(xform.Broadphase == null || xform.Broadphase == new BroadphaseData(broadUid, default, false, staticBody));
|
||||
xform.Broadphase ??= new(broadUid, default, false, staticBody);
|
||||
DebugTools.Assert(xform.Broadphase == null || xform.Broadphase == new BroadphaseData(broadUid, false, staticBody));
|
||||
xform.Broadphase ??= new(broadUid, false, staticBody);
|
||||
(staticBody ? broadphase.StaticSundriesTree : broadphase.SundriesTree).AddOrUpdate(uid, aabb);
|
||||
}
|
||||
|
||||
@@ -538,8 +510,12 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
{
|
||||
if (args.Component.GridUid == args.Sender)
|
||||
{
|
||||
if (args.ParentChanged) // grid changed maps, need to update children and clear the move buffer.
|
||||
// If grid changes map MoveBuffer will have incorrect worldpositions for all children.
|
||||
if (args.ParentChanged)
|
||||
{
|
||||
OnGridChangedMap(args);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
DebugTools.Assert(!_gridQuery.HasComp(args.Sender));
|
||||
@@ -563,84 +539,21 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
return;
|
||||
|
||||
// We need to recursively update the cached data and remove children from the move buffer
|
||||
DebugTools.Assert(_gridQuery.HasComp(args.Sender));
|
||||
DebugTools.Assert(!newMap.IsValid() || _mapQuery.HasComp(newMap));
|
||||
DebugTools.Assert(!oldMap.IsValid() || _mapQuery.HasComp(oldMap));
|
||||
|
||||
var oldBuffer = _physMapQuery.CompOrNull(oldMap)?.MoveBuffer;
|
||||
var newBuffer = _physMapQuery.CompOrNull(newMap)?.MoveBuffer;
|
||||
|
||||
foreach (var child in args.Component._children)
|
||||
{
|
||||
RecursiveOnGridChangedMap(child, oldMap, newMap, oldBuffer, newBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
private void RecursiveOnGridChangedMap(
|
||||
EntityUid uid,
|
||||
EntityUid oldMap,
|
||||
EntityUid newMap,
|
||||
Dictionary<FixtureProxy, Box2>? oldBuffer,
|
||||
Dictionary<FixtureProxy, Box2>? newBuffer)
|
||||
{
|
||||
if (!_xformQuery.TryGetComponent(uid, out var xform))
|
||||
return;
|
||||
|
||||
foreach (var child in xform._children)
|
||||
{
|
||||
RecursiveOnGridChangedMap(child, oldMap, newMap, oldBuffer, newBuffer);
|
||||
}
|
||||
|
||||
if (xform.Broadphase == null || !xform.Broadphase.Value.CanCollide)
|
||||
return;
|
||||
|
||||
DebugTools.Assert(_netMan.IsClient || !xform.Broadphase.Value.PhysicsMap.IsValid() || xform.Broadphase.Value.PhysicsMap == oldMap);
|
||||
xform.Broadphase = xform.Broadphase.Value with { PhysicsMap = newMap };
|
||||
|
||||
if (!_fixturesQuery.TryGetComponent(uid, out var fixtures))
|
||||
return;
|
||||
|
||||
if (oldBuffer != null)
|
||||
{
|
||||
foreach (var fix in fixtures.Fixtures.Values)
|
||||
foreach (var prox in fix.Proxies)
|
||||
{
|
||||
oldBuffer.Remove(prox);
|
||||
}
|
||||
}
|
||||
|
||||
if (newBuffer == null)
|
||||
return;
|
||||
|
||||
// TODO PERFORMANCE
|
||||
// track world position while recursively iterating down through children.
|
||||
var (worldPos, worldRot) = _transform.GetWorldPositionRotation(xform);
|
||||
var mapTransform = new Transform(worldPos, worldRot);
|
||||
|
||||
foreach (var fixture in fixtures.Fixtures.Values)
|
||||
{
|
||||
for (var i = 0; i < fixture.ProxyCount; i++)
|
||||
{
|
||||
var proxy = fixture.Proxies[i];
|
||||
newBuffer[proxy] = fixture.Shape.ComputeAABB(mapTransform, i);
|
||||
}
|
||||
}
|
||||
DebugTools.Assert(HasComp<MapGridComponent>(args.Sender));
|
||||
DebugTools.Assert(!newMap.IsValid() || HasComp<MapComponent>(newMap));
|
||||
DebugTools.Assert(!oldMap.IsValid() || HasComp<MapComponent>(oldMap));
|
||||
}
|
||||
|
||||
private void UpdateParent(EntityUid uid, TransformComponent xform)
|
||||
{
|
||||
BroadphaseComponent? oldBroadphase = null;
|
||||
PhysicsMapComponent? oldPhysMap = null;
|
||||
if (xform.Broadphase != null)
|
||||
{
|
||||
if (!xform.Broadphase.Value.IsValid())
|
||||
return; // Entity is intentionally not on a broadphase (deferred updating?).
|
||||
|
||||
_physMapQuery.TryGetComponent(xform.Broadphase.Value.PhysicsMap, out oldPhysMap);
|
||||
|
||||
if (!_broadQuery.TryGetComponent(xform.Broadphase.Value.Uid, out oldBroadphase))
|
||||
{
|
||||
|
||||
DebugTools.Assert("Encountered deleted broadphase.");
|
||||
|
||||
// broadphase was probably deleted.
|
||||
@@ -661,24 +574,18 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
|
||||
if (oldBroadphase != null && oldBroadphase != newBroadphase)
|
||||
{
|
||||
RemoveFromEntityTree(oldBroadphase.Owner, oldBroadphase, ref oldPhysMap, uid, xform);
|
||||
RemoveFromEntityTree(oldBroadphase.Owner, oldBroadphase, uid, xform);
|
||||
}
|
||||
|
||||
if (newBroadphase == null)
|
||||
return;
|
||||
|
||||
var newBroadphaseXform = _xformQuery.GetComponent(newBroadphase.Owner);
|
||||
if (!_physMapQuery.TryGetComponent(newBroadphaseXform.MapUid, out var physMap))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Broadphase's map is missing a physics map comp. Broadphase: {ToPrettyString(newBroadphase.Owner)}");
|
||||
}
|
||||
|
||||
AddOrUpdateEntityTree(
|
||||
newBroadphase.Owner,
|
||||
newBroadphase,
|
||||
newBroadphaseXform,
|
||||
physMap,
|
||||
uid,
|
||||
xform);
|
||||
}
|
||||
@@ -713,17 +620,11 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
bool recursive = true)
|
||||
{
|
||||
var broadphaseXform = _xformQuery.GetComponent(broadphase.Owner);
|
||||
if (!_physMapQuery.TryGetComponent(broadphaseXform.MapUid, out var physMap))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Broadphase's map is missing a physics map comp. Broadphase: {ToPrettyString(broadphase.Owner)}");
|
||||
}
|
||||
|
||||
AddOrUpdateEntityTree(
|
||||
broadUid,
|
||||
broadphase,
|
||||
broadphaseXform,
|
||||
physMap,
|
||||
uid,
|
||||
xform,
|
||||
recursive);
|
||||
@@ -733,7 +634,6 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
EntityUid broadUid,
|
||||
BroadphaseComponent broadphase,
|
||||
TransformComponent broadphaseXform,
|
||||
PhysicsMapComponent physicsMap,
|
||||
EntityUid uid,
|
||||
TransformComponent xform,
|
||||
bool recursive = true)
|
||||
@@ -758,7 +658,7 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
}
|
||||
else
|
||||
{
|
||||
AddOrUpdatePhysicsTree(uid, broadUid, broadphase, broadphaseXform, physicsMap, xform, body, _fixturesQuery.GetComponent(uid));
|
||||
AddOrUpdatePhysicsTree(uid, broadUid, broadphase, broadphaseXform, xform, body, _fixturesQuery.GetComponent(uid));
|
||||
}
|
||||
|
||||
if (xform.ChildCount == 0 || !recursive)
|
||||
@@ -771,7 +671,7 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
foreach (var child in xform._children)
|
||||
{
|
||||
var childXform = _xformQuery.GetComponent(child);
|
||||
AddOrUpdateEntityTree(broadUid, broadphase, broadphaseXform, physicsMap, child, childXform, recursive);
|
||||
AddOrUpdateEntityTree(broadUid, broadphase, broadphaseXform, child, childXform, recursive);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -782,7 +682,7 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
continue;
|
||||
|
||||
var childXform = _xformQuery.GetComponent(child);
|
||||
AddOrUpdateEntityTree(broadUid, broadphase, broadphaseXform, physicsMap, child, childXform, recursive);
|
||||
AddOrUpdateEntityTree(broadUid, broadphase, broadphaseXform, child, childXform, recursive);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -794,16 +694,10 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
if (!TryGetCurrentBroadphase(xform, out var broadphase))
|
||||
return;
|
||||
|
||||
DebugTools.Assert(!_gridQuery.HasComp(uid));
|
||||
DebugTools.Assert(!_mapQuery.HasComp(uid));
|
||||
PhysicsMapComponent? physMap = null;
|
||||
if (xform.Broadphase!.Value.PhysicsMap is { Valid: true } map && !_physMapQuery.TryGetComponent(map, out physMap))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Broadphase's map is missing a physics map comp. Broadphase: {ToPrettyString(broadphase.Owner)}");
|
||||
}
|
||||
DebugTools.Assert(!HasComp<MapGridComponent>(uid));
|
||||
DebugTools.Assert(!HasComp<MapComponent>(uid));
|
||||
|
||||
RemoveFromEntityTree(broadphase.Owner, broadphase, ref physMap, uid, xform);
|
||||
RemoveFromEntityTree(broadphase.Owner, broadphase, uid, xform);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -812,7 +706,6 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
private void RemoveFromEntityTree(
|
||||
EntityUid broadUid,
|
||||
BroadphaseComponent broadphase,
|
||||
ref PhysicsMapComponent? physicsMap,
|
||||
EntityUid uid,
|
||||
TransformComponent xform,
|
||||
bool recursive = true)
|
||||
@@ -833,16 +726,9 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
broadUid = old.Uid;
|
||||
}
|
||||
|
||||
if (old.PhysicsMap.IsValid() && physicsMap?.Owner != old.PhysicsMap)
|
||||
{
|
||||
if (!_physMapQuery.TryGetComponent(old.PhysicsMap, out physicsMap))
|
||||
Log.Error($"Entity {ToPrettyString(uid)} has missing physics map?");
|
||||
}
|
||||
|
||||
if (old.CanCollide)
|
||||
{
|
||||
DebugTools.Assert(old.PhysicsMap == (physicsMap?.Owner ?? default));
|
||||
RemoveBroadTree(broadphase, _fixturesQuery.GetComponent(uid), old.Static, physicsMap);
|
||||
RemoveBroadTree(broadphase, _fixturesQuery.GetComponent(uid), old.Static);
|
||||
}
|
||||
else if (old.Static)
|
||||
broadphase.StaticSundriesTree.Remove(uid);
|
||||
@@ -858,7 +744,6 @@ public sealed partial class EntityLookupSystem : EntitySystem
|
||||
RemoveFromEntityTree(
|
||||
broadUid,
|
||||
broadphase,
|
||||
ref physicsMap,
|
||||
child,
|
||||
_xformQuery.GetComponent(child));
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ internal sealed class PrototypeReloadSystem : EntitySystem
|
||||
var data = newPrototype.Components[name];
|
||||
var component = _componentFactory.GetComponent(name);
|
||||
|
||||
if (!EntityManager.HasComponent(entity, component.GetType()))
|
||||
EntityManager.AddComponent(entity, component);
|
||||
if (!HasComp(entity, component.GetType()))
|
||||
AddComp(entity, component);
|
||||
}
|
||||
|
||||
// Update entity metadata
|
||||
|
||||
@@ -69,19 +69,19 @@ namespace Robust.Shared.GameObjects
|
||||
if (!_enabled)
|
||||
return;
|
||||
|
||||
if (!EntityManager.TryGetComponent(uid, out PhysicsComponent? body))
|
||||
if (!TryComp(uid, out PhysicsComponent? body))
|
||||
{
|
||||
Log.Error($"Trying to regenerate collision for {uid} that doesn't have {nameof(body)}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EntityManager.TryGetComponent(uid, out FixturesComponent? manager))
|
||||
if (!TryComp(uid, out FixturesComponent? manager))
|
||||
{
|
||||
Log.Error($"Trying to regenerate collision for {uid} that doesn't have {nameof(manager)}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EntityManager.TryGetComponent(uid, out TransformComponent? xform))
|
||||
if (!TryComp(uid, out TransformComponent? xform))
|
||||
{
|
||||
Log.Error($"Trying to regenerate collision for {uid} that doesn't have {nameof(TransformComponent)}");
|
||||
return;
|
||||
|
||||
@@ -158,7 +158,7 @@ public abstract partial class SharedMapSystem
|
||||
// Just MapLoader things.
|
||||
if (component.MapProxy == DynamicTree.Proxy.Free) return;
|
||||
|
||||
var xform = EntityManager.GetComponent<TransformComponent>(uid);
|
||||
var xform = Comp<TransformComponent>(uid);
|
||||
var aabb = GetWorldAABB(uid, component, xform);
|
||||
|
||||
if (TryComp<GridTreeComponent>(xform.MapUid, out var gridTree))
|
||||
@@ -166,10 +166,7 @@ public abstract partial class SharedMapSystem
|
||||
gridTree.Tree.MoveProxy(component.MapProxy, in aabb);
|
||||
}
|
||||
|
||||
if (TryComp<MovedGridsComponent>(xform.MapUid, out var movedGrids))
|
||||
{
|
||||
movedGrids.MovedGrids.Add(uid);
|
||||
}
|
||||
_physics.MovedGrids.Add(uid);
|
||||
}
|
||||
|
||||
private void OnGridMove(EntityUid uid, MapGridComponent component, ref MoveEvent args)
|
||||
@@ -191,10 +188,7 @@ public abstract partial class SharedMapSystem
|
||||
gridTree.Tree.MoveProxy(component.MapProxy, in aabb);
|
||||
}
|
||||
|
||||
if (TryComp<MovedGridsComponent>(xform.MapUid, out var movedGrids))
|
||||
{
|
||||
movedGrids.MovedGrids.Add(uid);
|
||||
}
|
||||
_physics.MovedGrids.Add(uid);
|
||||
}
|
||||
|
||||
private void OnParentChange(EntityUid uid, MapGridComponent component, ref MoveEvent args)
|
||||
@@ -219,23 +213,23 @@ public abstract partial class SharedMapSystem
|
||||
|
||||
if (xform.ParentUid != xform.MapUid && meta.EntityLifeStage < EntityLifeStage.Terminating && _netManager.IsServer)
|
||||
{
|
||||
Log.Error($"Grid {ToPrettyString(uid, meta)} is not parented to {ToPrettyString(xform._parent)} which is not a map. y'all need jesus. {Environment.StackTrace}");
|
||||
Log.Error($"Grid {ToPrettyString(uid, meta)} is parented to {ToPrettyString(xform._parent)} which is not a map. y'all need jesus. {Environment.StackTrace}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure we cleanup old map for moved grid stuff.
|
||||
var oldMap = _transform.ToMapCoordinates(args.OldPosition);
|
||||
var oldMapUid = GetMapOrInvalid(oldMap.MapId);
|
||||
if (component.MapProxy != DynamicTree.Proxy.Free && TryComp<MovedGridsComponent>(oldMapUid, out var oldMovedGrids))
|
||||
if (component.MapProxy != DynamicTree.Proxy.Free)
|
||||
{
|
||||
oldMovedGrids.MovedGrids.Remove(uid);
|
||||
_physics.MovedGrids.Remove(uid);
|
||||
RemoveGrid(uid, component, oldMapUid);
|
||||
}
|
||||
|
||||
DebugTools.Assert(component.MapProxy == DynamicTree.Proxy.Free);
|
||||
if (TryComp<MovedGridsComponent>(xform.MapUid, out var newMovedGrids))
|
||||
if (xform.MapUid != null)
|
||||
{
|
||||
newMovedGrids.MovedGrids.Add(uid);
|
||||
_physics.MovedGrids.Add(uid);
|
||||
AddGrid(uid, component);
|
||||
}
|
||||
}
|
||||
@@ -344,6 +338,8 @@ public abstract partial class SharedMapSystem
|
||||
chunk.SuppressCollisionRegeneration = true;
|
||||
DebugTools.Assert(data.TileData.Any(x => !x.IsEmpty));
|
||||
DebugTools.Assert(data.TileData.Length == component.ChunkSize * component.ChunkSize);
|
||||
var changedEntry = new ValueList<TileChangedEntry>();
|
||||
|
||||
for (ushort x = 0; x < component.ChunkSize; x++)
|
||||
{
|
||||
for (ushort y = 0; y < component.ChunkSize; y++)
|
||||
@@ -352,12 +348,15 @@ public abstract partial class SharedMapSystem
|
||||
if (!chunk.TrySetTile(x, y, tile, out var oldTile, out _))
|
||||
continue;
|
||||
|
||||
var gridIndices = chunk.ChunkTileToGridTile((x, y));
|
||||
var newTileRef = new TileRef(uid, gridIndices, tile);
|
||||
_mapInternal.RaiseOnTileChanged(gridEnt, newTileRef, oldTile, index);
|
||||
|
||||
var chunkIndex = new Vector2i(x, y);
|
||||
var gridIndices = chunk.ChunkTileToGridTile(chunkIndex);
|
||||
changedEntry.Add(new TileChangedEntry(tile, oldTile, chunk.Indices, gridIndices));
|
||||
}
|
||||
}
|
||||
|
||||
var ev = new TileChangedEvent(gridEnt, changedEntry.ToArray());
|
||||
EntityManager.EventBus.RaiseLocalEvent(gridEnt.Owner, ref ev, true);
|
||||
DebugTools.Assert(chunk.Fixtures.SetEquals(data.Fixtures));
|
||||
|
||||
// These should never refer to the same object
|
||||
@@ -519,9 +518,9 @@ public abstract partial class SharedMapSystem
|
||||
component.MapProxy = proxy;
|
||||
}
|
||||
|
||||
if (TryComp<MovedGridsComponent>(xform.MapUid, out var movedGrids))
|
||||
if (xform.MapUid != null)
|
||||
{
|
||||
movedGrids.MovedGrids.Add(uid);
|
||||
_physics.MovedGrids.Add(uid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -573,9 +572,9 @@ public abstract partial class SharedMapSystem
|
||||
grid.MapProxy = proxy;
|
||||
}
|
||||
|
||||
if (TryComp<MovedGridsComponent>(xform.MapUid, out var movedGrids))
|
||||
if (xform.MapUid != null)
|
||||
{
|
||||
movedGrids.MovedGrids.Add(uid);
|
||||
_physics.MovedGrids.Add(uid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -588,9 +587,9 @@ public abstract partial class SharedMapSystem
|
||||
|
||||
grid.MapProxy = DynamicTree.Proxy.Free;
|
||||
|
||||
if (TryComp<MovedGridsComponent>(mapUid, out var movedGrids))
|
||||
if (mapUid.IsValid())
|
||||
{
|
||||
movedGrids.MovedGrids.Remove(uid);
|
||||
_physics.MovedGrids.Remove(uid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -116,9 +116,7 @@ public abstract partial class SharedMapSystem
|
||||
private void OnComponentAdd(EntityUid uid, MapComponent component, ComponentAdd args)
|
||||
{
|
||||
// ordered startups when
|
||||
EnsureComp<PhysicsMapComponent>(uid);
|
||||
EnsureComp<GridTreeComponent>(uid);
|
||||
EnsureComp<MovedGridsComponent>(uid);
|
||||
}
|
||||
|
||||
internal void AssignMapId(Entity<MapComponent> map, MapId? id = null)
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Utility;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Robust.Shared.Map.Components;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Numerics;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Robust.Shared.GameObjects;
|
||||
|
||||
@@ -217,9 +217,10 @@ public abstract partial class SharedTransformSystem
|
||||
{
|
||||
#if !EXCEPTION_TOLERANCE
|
||||
throw new Exception("Transform is initialising before map ids have been assigned?");
|
||||
#endif
|
||||
#else
|
||||
Log.Error($"Transform is initialising before map ids have been assigned?");
|
||||
_map.AssignMapId((uid, mapComp));
|
||||
#endif
|
||||
}
|
||||
|
||||
xform.MapUid = uid;
|
||||
|
||||
@@ -53,8 +53,14 @@ public abstract partial class SharedTransformSystem
|
||||
return MapCoordinates.Nullspace;
|
||||
}
|
||||
|
||||
var worldPos = Vector2.Transform(coordinates.Position, GetWorldMatrix(xform));
|
||||
return new MapCoordinates(worldPos, xform.MapID);
|
||||
Vector2 pos = xform._localRotation.RotateVec(coordinates.Position) + xform._localPosition;
|
||||
|
||||
while (xform.ParentUid != xform.MapUid && xform.ParentUid.IsValid())
|
||||
{
|
||||
xform = XformQuery.GetComponent(xform.ParentUid);
|
||||
pos = xform._localRotation.RotateVec(pos) + xform._localPosition;
|
||||
}
|
||||
return new MapCoordinates(pos, xform.MapID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,6 +73,41 @@ public abstract partial class SharedTransformSystem
|
||||
return ToMapCoordinates(eCoords);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts entity-local coordinates into map terms.
|
||||
/// The same as ToMapCoordinates(coordinates, logError).Position, but doesn't have to construct the MapCoordinates first.
|
||||
/// </summary>
|
||||
public Vector2 ToWorldPosition(EntityCoordinates coordinates, bool logError = true)
|
||||
{
|
||||
if (!TryComp(coordinates.EntityId, out TransformComponent? xform))
|
||||
{
|
||||
if (logError)
|
||||
Log.Error($"Attempted to convert coordinates with invalid entity: {coordinates}. Trace: {Environment.StackTrace}");
|
||||
return Vector2.Zero;
|
||||
}
|
||||
|
||||
Vector2 pos = xform._localRotation.RotateVec(coordinates.Position) + xform._localPosition;
|
||||
|
||||
while (xform.ParentUid != xform.MapUid && xform.ParentUid.IsValid())
|
||||
{
|
||||
xform = XformQuery.GetComponent(xform.ParentUid);
|
||||
pos = xform._localRotation.RotateVec(pos) + xform._localPosition;
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts entity-local coordinates into map terms.
|
||||
/// The same as ToMapCoordinates(coordinates).Position, but doesn't have to construct the MapCoordinates first.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Vector2 ToWorldPosition(NetCoordinates coordinates)
|
||||
{
|
||||
var eCoords = GetCoordinates(coordinates);
|
||||
return ToWorldPosition(eCoords);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates EntityCoordinates given an entity and some MapCoordinates.
|
||||
/// </summary>
|
||||
|
||||
@@ -263,7 +263,7 @@ namespace Robust.Shared.GameObjects
|
||||
return true;
|
||||
}
|
||||
|
||||
public void RaiseMoveEvent(
|
||||
internal void RaiseMoveEvent(
|
||||
Entity<TransformComponent, MetaDataComponent> ent,
|
||||
EntityUid oldParent,
|
||||
Vector2 oldPosition,
|
||||
|
||||
@@ -636,7 +636,7 @@ public abstract class SharedUserInterfaceSystem : EntitySystem
|
||||
if (!_timing.IsFirstTimePredicted)
|
||||
return;
|
||||
|
||||
EntityManager.RaisePredictiveEvent(new BoundUIWrapMessage(GetNetEntity(entity.Owner), new CloseBoundInterfaceMessage(), key));
|
||||
RaisePredictiveEvent(new BoundUIWrapMessage(GetNetEntity(entity.Owner), new CloseBoundInterfaceMessage(), key));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -685,7 +685,7 @@ public abstract class SharedUserInterfaceSystem : EntitySystem
|
||||
{
|
||||
// Not guaranteed to open so rely upon the event handling it.
|
||||
// Also lets client request it to be opened remotely too.
|
||||
EntityManager.RaisePredictiveEvent(new BoundUIWrapMessage(GetNetEntity(entity.Owner), new OpenBoundInterfaceMessage(), key));
|
||||
RaisePredictiveEvent(new BoundUIWrapMessage(GetNetEntity(entity.Owner), new OpenBoundInterfaceMessage(), key));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Robust.Shared.GameObjects
|
||||
base.Update(frameTime);
|
||||
|
||||
// Avoid a collection was modified while enumerating.
|
||||
var timers = EntityManager.EntityQueryEnumerator<TimerComponent>();
|
||||
var timers = EntityQueryEnumerator<TimerComponent>();
|
||||
var timersList = new ValueList<(EntityUid, TimerComponent)>();
|
||||
while (timers.MoveNext(out var uid, out var timer))
|
||||
{
|
||||
@@ -28,7 +28,7 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
if (!timer.Deleted && !EntityManager.Deleted(uid) && timer.RemoveOnEmpty && timer.TimerCount == 0)
|
||||
{
|
||||
EntityManager.RemoveComponent<TimerComponent>(uid);
|
||||
RemComp<TimerComponent>(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,10 +170,8 @@ namespace Robust.Shared.Localization
|
||||
if (args.Args.Count < 1) return new LocValueString(nameof(Gender.Neuter));
|
||||
|
||||
ILocValue entity0 = args.Args[0];
|
||||
if (entity0.Value != null)
|
||||
if (entity0.Value is EntityUid entity)
|
||||
{
|
||||
EntityUid entity = (EntityUid)entity0.Value;
|
||||
|
||||
if (_entMan.TryGetComponent(entity, out GrammarComponent? grammar) && grammar.Gender.HasValue)
|
||||
{
|
||||
return new LocValueString(grammar.Gender.Value.ToString().ToLowerInvariant());
|
||||
@@ -246,10 +244,8 @@ namespace Robust.Shared.Localization
|
||||
if (args.Args.Count < 1) return new LocValueString(GetString("zzzz-counter-default"));
|
||||
|
||||
ILocValue entity0 = args.Args[0];
|
||||
if (entity0.Value != null)
|
||||
if (entity0.Value is EntityUid entity)
|
||||
{
|
||||
EntityUid entity = (EntityUid)entity0.Value;
|
||||
|
||||
if (TryGetEntityLocAttrib(entity, "counter", out var counter))
|
||||
{
|
||||
return new LocValueString(counter);
|
||||
@@ -292,9 +288,8 @@ namespace Robust.Shared.Localization
|
||||
if (args.Args.Count < 2) return new LocValueString("other");
|
||||
|
||||
ILocValue entity0 = args.Args[0];
|
||||
if (entity0.Value != null)
|
||||
if (entity0.Value is EntityUid entity)
|
||||
{
|
||||
EntityUid entity = (EntityUid)entity0.Value;
|
||||
ILocValue attrib0 = args.Args[1];
|
||||
if (TryGetEntityLocAttrib(entity, attrib0.Format(new LocContext(bundle)), out var attrib))
|
||||
{
|
||||
@@ -313,10 +308,8 @@ namespace Robust.Shared.Localization
|
||||
if (args.Args.Count < 1) return new LocValueString("false");
|
||||
|
||||
ILocValue entity0 = args.Args[0];
|
||||
if (entity0.Value != null)
|
||||
if (entity0.Value is EntityUid entity)
|
||||
{
|
||||
EntityUid entity = (EntityUid)entity0.Value;
|
||||
|
||||
if (_entMan.TryGetComponent(entity, out GrammarComponent? grammar) && grammar.ProperNoun.HasValue)
|
||||
{
|
||||
return new LocValueString(grammar.ProperNoun.Value.ToString().ToLowerInvariant());
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Shared.Map.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Stores what grids moved in a tick.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed partial class MovedGridsComponent : Component
|
||||
{
|
||||
[ViewVariables]
|
||||
public HashSet<EntityUid> MovedGrids = new();
|
||||
}
|
||||
64
Robust.Shared/Map/Enumerators/NearestChunkEnumerator.cs
Normal file
64
Robust.Shared/Map/Enumerators/NearestChunkEnumerator.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Numerics;
|
||||
using Robust.Shared.Collections;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Robust.Shared.Map.Enumerators;
|
||||
|
||||
/// <summary>
|
||||
/// Iterates chunk indices but prefers ones closer towards the center first.
|
||||
/// </summary>
|
||||
public record struct NearestChunkEnumerator
|
||||
{
|
||||
private readonly Vector2i _chunkLB;
|
||||
private readonly Vector2i _chunkRT;
|
||||
|
||||
private ValueList<Vector2i> _chunks = new();
|
||||
|
||||
private int _n;
|
||||
|
||||
public NearestChunkEnumerator(Box2 localAABB, int chunkSize)
|
||||
{
|
||||
_chunkLB = (localAABB.BottomLeft / chunkSize).Floored();
|
||||
_chunkRT = (localAABB.TopRight / chunkSize).Floored();
|
||||
InitializeChunks(new Vector2i(chunkSize, chunkSize));
|
||||
}
|
||||
|
||||
public NearestChunkEnumerator(Box2 localAABB, Vector2i chunkSize)
|
||||
{
|
||||
_chunkLB = (localAABB.BottomLeft / chunkSize).Floored();
|
||||
_chunkRT = (localAABB.TopRight / chunkSize).Floored();
|
||||
InitializeChunks(chunkSize);
|
||||
}
|
||||
|
||||
private void InitializeChunks(Vector2i chunkSize)
|
||||
{
|
||||
var bl = (Vector2)_chunkLB * chunkSize;
|
||||
var tr = (Vector2)_chunkRT * chunkSize;
|
||||
var halfChunk = new Vector2(chunkSize.X / 2f, chunkSize.Y / 2f);
|
||||
|
||||
var center = (tr - bl) / 2 + bl;
|
||||
|
||||
for (var x = _chunkLB.X; x < _chunkRT.X; x++)
|
||||
{
|
||||
for (var y = _chunkLB.Y; y < _chunkRT.Y; y++)
|
||||
{
|
||||
_chunks.Add(new Vector2i(x, y) * chunkSize);
|
||||
}
|
||||
}
|
||||
|
||||
_chunks.Sort((c1, c2) => ((c1 + halfChunk) - center).LengthSquared().CompareTo(((c2 + halfChunk) - center).LengthSquared()));
|
||||
}
|
||||
|
||||
public bool MoveNext([NotNullWhen(true)] out Vector2i? indices)
|
||||
{
|
||||
if (_n >= _chunks.Count)
|
||||
{
|
||||
indices = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
indices = _chunks[_n++] ;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,6 @@ namespace Robust.Shared.Map
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Internal name of the definition.
|
||||
/// </summary>
|
||||
string ID { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The path of the sprite to draw.
|
||||
/// </summary>
|
||||
|
||||
@@ -37,7 +37,7 @@ using FNLfloat = System.Single;
|
||||
//using FNLfloat = System.Double;
|
||||
|
||||
[DataDefinition, Serializable, NetSerializable]
|
||||
public sealed partial class FastNoiseLite
|
||||
public sealed partial class FastNoiseLite : ISerializationHooks
|
||||
{
|
||||
private const short INLINE = 256; // MethodImplOptions.AggressiveInlining;
|
||||
private const short OPTIMISE = 512; // MethodImplOptions.AggressiveOptimization;
|
||||
@@ -136,7 +136,6 @@ public sealed partial class FastNoiseLite
|
||||
[DataField("pingPongStrength")]
|
||||
private float mPingPongStrength = 2.0f;
|
||||
|
||||
[DataField("fractalBounding")]
|
||||
private float mFractalBounding = 1 / 1.75f;
|
||||
|
||||
[DataField("cellularDistanceFunction")]
|
||||
@@ -170,6 +169,11 @@ public sealed partial class FastNoiseLite
|
||||
SetSeed(1337);
|
||||
}
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
CalculateFractalBounding();
|
||||
}
|
||||
|
||||
public int GetSeed() => mSeed;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
using System.Numerics;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Shared.Physics.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed partial class Gravity2DComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Applies side-view gravity to the map.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("gravity")]
|
||||
public Vector2 Gravity;
|
||||
}
|
||||
@@ -154,11 +154,6 @@ public sealed partial class PhysicsComponent : Component, IComponentDelta
|
||||
// ReSharper disable once InconsistentNaming
|
||||
internal float _inertia;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether this body ignores gravity
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)] public bool IgnoreGravity;
|
||||
|
||||
/// <summary>
|
||||
/// Inverse moment of inertia (1 / I).
|
||||
/// </summary>
|
||||
@@ -264,6 +259,9 @@ public sealed partial class PhysicsComponent : Component, IComponentDelta
|
||||
[DataField, Access(typeof(SharedPhysicsSystem), Friend = AccessPermissions.ReadWriteExecute, Other = AccessPermissions.Read)]
|
||||
public BodyStatus BodyStatus { get; set; }
|
||||
|
||||
[DataField, Access(typeof(SharedPhysicsSystem))]
|
||||
public bool IgnoreGravity;
|
||||
|
||||
[ViewVariables, Access(typeof(SharedPhysicsSystem))]
|
||||
public bool Predict;
|
||||
}
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Shared.Physics.Controllers;
|
||||
|
||||
public sealed class Gravity2DController : VirtualController
|
||||
{
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
|
||||
|
||||
private ISawmill _sawmill = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_sawmill = Logger.GetSawmill("physics");
|
||||
SubscribeLocalEvent<Gravity2DComponent, ComponentGetState>(OnGetState);
|
||||
SubscribeLocalEvent<Gravity2DComponent, ComponentHandleState>(OnHandleState);
|
||||
}
|
||||
|
||||
private void OnGetState(EntityUid uid, Gravity2DComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new Gravity2DComponentState() { Gravity = component.Gravity };
|
||||
}
|
||||
|
||||
private void OnHandleState(EntityUid uid, Gravity2DComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not Gravity2DComponentState state)
|
||||
return;
|
||||
|
||||
component.Gravity = state.Gravity;
|
||||
}
|
||||
|
||||
public Vector2 GetGravity(EntityUid uid, Gravity2DComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, false))
|
||||
return Vector2.Zero;
|
||||
|
||||
return component.Gravity;
|
||||
}
|
||||
|
||||
public void SetGravity(EntityUid uid, Vector2 value)
|
||||
{
|
||||
if (!HasComp<MapComponent>(uid))
|
||||
{
|
||||
_sawmill.Error($"Tried to set 2D gravity for an entity that isn't a map?");
|
||||
DebugTools.Assert(false);
|
||||
return;
|
||||
}
|
||||
|
||||
var gravity = EnsureComp<Gravity2DComponent>(uid);
|
||||
|
||||
if (gravity.Gravity.Equals(value))
|
||||
return;
|
||||
|
||||
gravity.Gravity = value;
|
||||
WakeBodiesRecursive(uid, GetEntityQuery<TransformComponent>(), GetEntityQuery<PhysicsComponent>());
|
||||
Dirty(uid, gravity);
|
||||
}
|
||||
|
||||
public void SetGravity(MapId mapId, Vector2 value)
|
||||
{
|
||||
var mapUid = _mapSystem.GetMap(mapId);
|
||||
var gravity = EnsureComp<Gravity2DComponent>(mapUid);
|
||||
|
||||
if (gravity.Gravity.Equals(value))
|
||||
return;
|
||||
|
||||
gravity.Gravity = value;
|
||||
WakeBodiesRecursive(mapUid, GetEntityQuery<TransformComponent>(), GetEntityQuery<PhysicsComponent>());
|
||||
Dirty(mapUid, gravity);
|
||||
}
|
||||
|
||||
private void WakeBodiesRecursive(EntityUid uid, EntityQuery<TransformComponent> xformQuery, EntityQuery<PhysicsComponent> bodyQuery)
|
||||
{
|
||||
if (bodyQuery.TryGetComponent(uid, out var body) &&
|
||||
body.BodyType == BodyType.Dynamic)
|
||||
{
|
||||
_physics.WakeBody(uid, body: body);
|
||||
}
|
||||
|
||||
var xform = xformQuery.GetComponent(uid);
|
||||
foreach (var child in xform._children)
|
||||
{
|
||||
WakeBodiesRecursive(child, xformQuery, bodyQuery);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
private sealed class Gravity2DComponentState : ComponentState
|
||||
{
|
||||
public Vector2 Gravity;
|
||||
}
|
||||
}
|
||||
@@ -35,9 +35,6 @@ namespace Robust.Shared.Physics.Controllers
|
||||
|
||||
SubscribeLocalEvent<PhysicsUpdateBeforeSolveEvent>(OnBeforeSolve, updatesBefore, updatesAfter);
|
||||
SubscribeLocalEvent<PhysicsUpdateAfterSolveEvent>(OnAfterSolve, updatesBefore, updatesAfter);
|
||||
|
||||
SubscribeLocalEvent<PhysicsUpdateBeforeMapSolveEvent>(OnBeforeMapSolve, updatesBefore, updatesAfter);
|
||||
SubscribeLocalEvent<PhysicsUpdateAfterMapSolveEvent>(OnAfterMapSolve, updatesBefore, updatesAfter);
|
||||
}
|
||||
|
||||
private void OnBeforeSolve(ref PhysicsUpdateBeforeSolveEvent ev)
|
||||
@@ -62,16 +59,6 @@ namespace Robust.Shared.Physics.Controllers
|
||||
AfterMonitor.Observe(Stopwatch.Elapsed.TotalSeconds);
|
||||
}
|
||||
|
||||
private void OnBeforeMapSolve(ref PhysicsUpdateBeforeMapSolveEvent ev)
|
||||
{
|
||||
UpdateBeforeMapSolve(ev.Prediction, ev.MapComponent, ev.DeltaTime);
|
||||
}
|
||||
|
||||
private void OnAfterMapSolve(ref PhysicsUpdateAfterMapSolveEvent ev)
|
||||
{
|
||||
UpdateAfterMapSolve(ev.Prediction, ev.MapComponent, ev.DeltaTime);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
@@ -87,21 +74,5 @@ namespace Robust.Shared.Physics.Controllers
|
||||
/// <param name="prediction"></param>
|
||||
/// <param name="frameTime"></param>
|
||||
public virtual void UpdateAfterSolve(bool prediction, float frameTime) {}
|
||||
|
||||
/// <summary>
|
||||
/// Run before a particular map starts.
|
||||
/// </summary>
|
||||
/// <param name="prediction"></param>
|
||||
/// <param name="mapComponent"></param>
|
||||
/// <param name="frameTime"></param>
|
||||
public virtual void UpdateBeforeMapSolve(bool prediction, PhysicsMapComponent mapComponent, float frameTime) {}
|
||||
|
||||
/// <summary>
|
||||
/// Run after a particular map finishes.
|
||||
/// </summary>
|
||||
/// <param name="prediction"></param>
|
||||
/// <param name="mapComponent"></param>
|
||||
/// <param name="frameTime"></param>
|
||||
public virtual void UpdateAfterMapSolve(bool prediction, PhysicsMapComponent mapComponent, float frameTime) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,9 @@ namespace Robust.Shared.Physics.Dynamics.Contacts
|
||||
public PhysicsComponent? BodyA;
|
||||
public PhysicsComponent? BodyB;
|
||||
|
||||
public TransformComponent? XformA;
|
||||
public TransformComponent? XformB;
|
||||
|
||||
public Manifold Manifold;
|
||||
|
||||
internal ContactType Type;
|
||||
@@ -253,6 +256,11 @@ namespace Robust.Shared.Physics.Dynamics.Contacts
|
||||
{
|
||||
status = ContactStatus.EndTouching;
|
||||
}
|
||||
// Still touching
|
||||
else
|
||||
{
|
||||
status = ContactStatus.Touching;
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
@@ -442,6 +450,17 @@ namespace Robust.Shared.Physics.Dynamics.Contacts
|
||||
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public TransformComponent OtherTransform(EntityUid uid)
|
||||
{
|
||||
if (uid == EntityA)
|
||||
return XformB!;
|
||||
else if (uid == EntityB)
|
||||
return XformA!;
|
||||
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
|
||||
@@ -25,43 +25,45 @@ using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Shared.Physics.Dynamics
|
||||
namespace Robust.Shared.Physics.Dynamics;
|
||||
|
||||
public sealed class FixtureProxy
|
||||
{
|
||||
public sealed class FixtureProxy
|
||||
public EntityUid Entity;
|
||||
public PhysicsComponent Body { get; internal set; }
|
||||
|
||||
public TransformComponent Xform { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Grid-based AABB of this proxy.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public Box2 AABB;
|
||||
|
||||
[ViewVariables]
|
||||
public int ChildIndex;
|
||||
|
||||
public string FixtureId;
|
||||
|
||||
/// <summary>
|
||||
/// Our parent fixture
|
||||
/// </summary>
|
||||
public Fixture Fixture;
|
||||
|
||||
/// <summary>
|
||||
/// ID of this proxy in the broadphase dynamictree.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public DynamicTree.Proxy ProxyId = DynamicTree.Proxy.Free;
|
||||
|
||||
internal FixtureProxy(EntityUid uid, PhysicsComponent body, TransformComponent xform, Box2 aabb, string fixtureId, Fixture fixture, int childIndex)
|
||||
{
|
||||
public EntityUid Entity;
|
||||
public PhysicsComponent Body;
|
||||
|
||||
/// <summary>
|
||||
/// Grid-based AABB of this proxy.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public Box2 AABB;
|
||||
|
||||
[ViewVariables]
|
||||
public int ChildIndex;
|
||||
|
||||
public string FixtureId;
|
||||
|
||||
/// <summary>
|
||||
/// Our parent fixture
|
||||
/// </summary>
|
||||
public Fixture Fixture;
|
||||
|
||||
/// <summary>
|
||||
/// ID of this proxy in the broadphase dynamictree.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public DynamicTree.Proxy ProxyId = DynamicTree.Proxy.Free;
|
||||
|
||||
public FixtureProxy(EntityUid uid, PhysicsComponent body, Box2 aabb, string fixtureId, Fixture fixture, int childIndex)
|
||||
{
|
||||
Entity = uid;
|
||||
Body = body;
|
||||
AABB = aabb;
|
||||
FixtureId = fixtureId;
|
||||
Fixture = fixture;
|
||||
ChildIndex = childIndex;
|
||||
}
|
||||
Entity = uid;
|
||||
Body = body;
|
||||
Xform = xform;
|
||||
AABB = aabb;
|
||||
FixtureId = fixtureId;
|
||||
Fixture = fixture;
|
||||
ChildIndex = childIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using PhysicsComponent = Robust.Shared.Physics.Components.PhysicsComponent;
|
||||
|
||||
namespace Robust.Shared.Physics.Dynamics;
|
||||
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed partial class PhysicsMapComponent : Component
|
||||
{
|
||||
public bool AutoClearForces;
|
||||
|
||||
/// <summary>
|
||||
/// When substepping the client needs to know about the first position to use for lerping.
|
||||
/// </summary>
|
||||
public readonly Dictionary<EntityUid, (EntityUid ParentUid, Vector2 LocalPosition, Angle LocalRotation)>
|
||||
LerpData = new();
|
||||
|
||||
/// <summary>
|
||||
/// Keep a buffer of everything that moved in a tick. This will be used to check for physics contacts.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public readonly Dictionary<FixtureProxy, Box2> MoveBuffer = new();
|
||||
|
||||
/// <summary>
|
||||
/// All awake bodies on this map.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public readonly HashSet<PhysicsComponent> AwakeBodies = new();
|
||||
|
||||
/// <summary>
|
||||
/// Store last tick's invDT
|
||||
/// </summary>
|
||||
internal float _invDt0;
|
||||
}
|
||||
|
||||
[ByRefEvent]
|
||||
public readonly struct PhysicsUpdateBeforeMapSolveEvent
|
||||
{
|
||||
public readonly bool Prediction;
|
||||
public readonly PhysicsMapComponent MapComponent;
|
||||
public readonly float DeltaTime;
|
||||
|
||||
public PhysicsUpdateBeforeMapSolveEvent(bool prediction, PhysicsMapComponent mapComponent, float deltaTime)
|
||||
{
|
||||
Prediction = prediction;
|
||||
MapComponent = mapComponent;
|
||||
DeltaTime = deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
[ByRefEvent]
|
||||
public readonly struct PhysicsUpdateAfterMapSolveEvent
|
||||
{
|
||||
public readonly bool Prediction;
|
||||
public readonly PhysicsMapComponent MapComponent;
|
||||
public readonly float DeltaTime;
|
||||
|
||||
public PhysicsUpdateAfterMapSolveEvent(bool prediction, PhysicsMapComponent mapComponent, float deltaTime)
|
||||
{
|
||||
Prediction = prediction;
|
||||
MapComponent = mapComponent;
|
||||
DeltaTime = deltaTime;
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,9 @@ namespace Robust.Shared.Physics
|
||||
{
|
||||
internal sealed class IslandSolveMessage : EntityEventArgs
|
||||
{
|
||||
public List<PhysicsComponent> Bodies { get; }
|
||||
public List<Entity<PhysicsComponent, TransformComponent>> Bodies { get; }
|
||||
|
||||
public IslandSolveMessage(List<PhysicsComponent> bodies)
|
||||
public IslandSolveMessage(List<Entity<PhysicsComponent, TransformComponent>> bodies)
|
||||
{
|
||||
Bodies = bodies;
|
||||
}
|
||||
|
||||
@@ -21,13 +21,10 @@ namespace Robust.Shared.Physics.Systems
|
||||
/// </summary>
|
||||
public sealed partial class FixtureSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||
[Dependency] private readonly SharedBroadphaseSystem _broadphase = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
#pragma warning disable CS0414
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
#pragma warning restore CS0414
|
||||
private EntityQuery<PhysicsMapComponent> _mapQuery;
|
||||
private EntityQuery<PhysicsComponent> _physicsQuery;
|
||||
private EntityQuery<FixturesComponent> _fixtureQuery;
|
||||
|
||||
@@ -38,7 +35,6 @@ namespace Robust.Shared.Physics.Systems
|
||||
SubscribeLocalEvent<FixturesComponent, ComponentShutdown>(OnShutdown);
|
||||
SubscribeLocalEvent<FixturesComponent, ComponentGetState>(OnGetState);
|
||||
SubscribeLocalEvent<FixturesComponent, ComponentHandleState>(OnHandleState);
|
||||
_mapQuery = GetEntityQuery<PhysicsMapComponent>();
|
||||
_physicsQuery = GetEntityQuery<PhysicsComponent>();
|
||||
_fixtureQuery = GetEntityQuery<FixturesComponent>();
|
||||
}
|
||||
@@ -206,8 +202,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
if (_lookup.TryGetCurrentBroadphase(xform, out var broadphase))
|
||||
{
|
||||
DebugTools.Assert(xform.MapUid == Transform(broadphase.Owner).MapUid);
|
||||
_mapQuery.TryGetComponent(xform.MapUid, out var physicsMap);
|
||||
_lookup.DestroyProxies(uid, fixtureId, fixture, xform, broadphase, physicsMap);
|
||||
_lookup.DestroyProxies(uid, fixtureId, fixture, xform, broadphase);
|
||||
}
|
||||
|
||||
if (updates)
|
||||
@@ -262,7 +257,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
if (args.Current is not FixtureManagerComponentState state)
|
||||
return;
|
||||
|
||||
if (!EntityManager.TryGetComponent(uid, out PhysicsComponent? physics))
|
||||
if (!TryComp(uid, out PhysicsComponent? physics))
|
||||
{
|
||||
Log.Error($"Tried to apply fixture state for an entity without physics: {ToPrettyString(uid)}");
|
||||
return;
|
||||
|
||||
@@ -34,10 +34,12 @@ namespace Robust.Shared.Physics.Systems
|
||||
private EntityQuery<MapGridComponent> _gridQuery;
|
||||
private EntityQuery<PhysicsComponent> _physicsQuery;
|
||||
private EntityQuery<TransformComponent> _xformQuery;
|
||||
private EntityQuery<PhysicsMapComponent> _mapQuery;
|
||||
|
||||
private float _broadphaseExpand;
|
||||
|
||||
private readonly Dictionary<EntityUid, Matrix3x2> _broadMatrices = new();
|
||||
private HashSet<FixtureProxy> _gridMoveBuffer = new();
|
||||
|
||||
/*
|
||||
* Okay so Box2D has its own "MoveProxy" stuff so you can easily find new contacts when required.
|
||||
* Our problem is that we have nested broadphases (rather than being on separate maps) which makes this
|
||||
@@ -56,6 +58,8 @@ namespace Robust.Shared.Physics.Systems
|
||||
_mapManager = _mapManager,
|
||||
System = this,
|
||||
BroadphaseExpand = _broadphaseExpand,
|
||||
// TODO: EntityManager one isn't ready yet?
|
||||
XformQuery = GetEntityQuery<TransformComponent>(),
|
||||
};
|
||||
|
||||
_broadphaseQuery = GetEntityQuery<BroadphaseComponent>();
|
||||
@@ -63,7 +67,6 @@ namespace Robust.Shared.Physics.Systems
|
||||
_gridQuery = GetEntityQuery<MapGridComponent>();
|
||||
_physicsQuery = GetEntityQuery<PhysicsComponent>();
|
||||
_xformQuery = GetEntityQuery<TransformComponent>();
|
||||
_mapQuery = GetEntityQuery<PhysicsMapComponent>();
|
||||
|
||||
UpdatesOutsidePrediction = true;
|
||||
UpdatesAfter.Add(typeof(SharedTransformSystem));
|
||||
@@ -98,87 +101,75 @@ namespace Robust.Shared.Physics.Systems
|
||||
/// <summary>
|
||||
/// Check the AABB for each moved broadphase fixture and add any colliding entities to the movebuffer in case.
|
||||
/// </summary>
|
||||
private void FindGridContacts(
|
||||
PhysicsMapComponent component,
|
||||
MapId mapId,
|
||||
HashSet<EntityUid> movedGrids,
|
||||
Dictionary<FixtureProxy, Box2> gridMoveBuffer)
|
||||
private void FindGridContacts(HashSet<EntityUid> movedGrids)
|
||||
{
|
||||
// None moved this tick
|
||||
if (movedGrids.Count == 0) return;
|
||||
|
||||
var mapBroadphase = _broadphaseQuery.GetComponent(_map.GetMapOrInvalid(mapId));
|
||||
|
||||
// This is so that if we're on a broadphase that's moving (e.g. a grid) we need to make sure anything
|
||||
// we move over is getting checked for collisions, and putting it on the movebuffer is the easiest way to do so.
|
||||
var moveBuffer = component.MoveBuffer;
|
||||
var moveBuffer = _physicsSystem.MoveBuffer;
|
||||
|
||||
foreach (var gridUid in movedGrids)
|
||||
{
|
||||
var grid = _gridQuery.GetComponent(gridUid);
|
||||
var xform = _xformQuery.GetComponent(gridUid);
|
||||
|
||||
DebugTools.Assert(xform.MapID == mapId);
|
||||
// Moved to nullspace?
|
||||
if (!_broadphaseQuery.TryComp(xform.MapUid, out var mapBroadphase))
|
||||
continue;
|
||||
|
||||
var worldAABB = _transform.GetWorldMatrix(xform).TransformBox(grid.LocalAABB);
|
||||
var enlargedAABB = worldAABB.Enlarged(_broadphaseExpand);
|
||||
var state = (moveBuffer, gridMoveBuffer);
|
||||
var state = (moveBuffer, _gridMoveBuffer);
|
||||
|
||||
QueryMapBroadphase(mapBroadphase.DynamicTree, ref state, enlargedAABB);
|
||||
QueryMapBroadphase(mapBroadphase.StaticTree, ref state, enlargedAABB);
|
||||
}
|
||||
|
||||
foreach (var (proxy, worldAABB) in gridMoveBuffer)
|
||||
foreach (var proxy in _gridMoveBuffer)
|
||||
{
|
||||
moveBuffer[proxy] = worldAABB;
|
||||
moveBuffer.Add(proxy);
|
||||
// If something is in our AABB then try grid traversal for it
|
||||
_traversal.CheckTraverse((proxy.Entity, _xformQuery.GetComponent(proxy.Entity)));
|
||||
}
|
||||
}
|
||||
|
||||
private void QueryMapBroadphase(IBroadPhase broadPhase,
|
||||
ref (Dictionary<FixtureProxy, Box2>, Dictionary<FixtureProxy, Box2>) state,
|
||||
ref (HashSet<FixtureProxy>, HashSet<FixtureProxy>) state,
|
||||
Box2 enlargedAABB)
|
||||
{
|
||||
// Easier to just not go over each proxy as we already unioned the fixture's worldaabb.
|
||||
broadPhase.QueryAabb(ref state, static (ref (
|
||||
Dictionary<FixtureProxy, Box2> moveBuffer,
|
||||
Dictionary<FixtureProxy, Box2> gridMoveBuffer) tuple,
|
||||
HashSet<FixtureProxy> moveBuffer,
|
||||
HashSet<FixtureProxy> gridMoveBuffer) tuple,
|
||||
in FixtureProxy value) =>
|
||||
{
|
||||
// 99% of the time it's just going to be the broadphase (for now the grid) itself.
|
||||
// hence this body check makes this run significantly better.
|
||||
// Also check if it's not already on the movebuffer.
|
||||
if (tuple.moveBuffer.ContainsKey(value))
|
||||
if (tuple.moveBuffer.Contains(value))
|
||||
return true;
|
||||
|
||||
// To avoid updating during iteration.
|
||||
// Don't need to transform as it's already in map terms.
|
||||
tuple.gridMoveBuffer[value] = value.AABB;
|
||||
tuple.gridMoveBuffer.Add(value);
|
||||
return true;
|
||||
}, enlargedAABB, true);
|
||||
}
|
||||
|
||||
[Obsolete("Use the overload with SharedPhysicsMapComponent")]
|
||||
internal void FindNewContacts(MapId mapId)
|
||||
{
|
||||
if (!TryComp<PhysicsMapComponent>(_map.GetMapOrInvalid(mapId), out var physicsMap))
|
||||
return;
|
||||
|
||||
FindNewContacts(physicsMap, mapId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Go through every single created, moved, or touched proxy on the map and try to find any new contacts that should be created.
|
||||
/// </summary>
|
||||
internal void FindNewContacts(PhysicsMapComponent component, MapId mapId)
|
||||
internal void FindNewContacts()
|
||||
{
|
||||
var moveBuffer = component.MoveBuffer;
|
||||
var mapUid = _map.GetMapOrInvalid(mapId);
|
||||
var movedGrids = Comp<MovedGridsComponent>(mapUid).MovedGrids;
|
||||
var gridMoveBuffer = new Dictionary<FixtureProxy, Box2>();
|
||||
var moveBuffer = _physicsSystem.MoveBuffer;
|
||||
var movedGrids = _physicsSystem.MovedGrids;
|
||||
|
||||
_gridMoveBuffer.Clear();
|
||||
|
||||
// Find any entities being driven over that might need to be considered
|
||||
FindGridContacts(component, mapId, movedGrids, gridMoveBuffer);
|
||||
FindGridContacts(movedGrids);
|
||||
|
||||
// There is some mariana trench levels of bullshit going on.
|
||||
// We essentially need to re-create Box2D's FindNewContacts but in a way that allows us to check every
|
||||
@@ -190,18 +181,29 @@ namespace Robust.Shared.Physics.Systems
|
||||
// to cache a bunch of stuff to make up for it.
|
||||
|
||||
// Handle grids first as they're not stored on map broadphase at all.
|
||||
HandleGridCollisions(mapId, movedGrids);
|
||||
HandleGridCollisions(movedGrids);
|
||||
|
||||
// EZ
|
||||
if (moveBuffer.Count == 0)
|
||||
return;
|
||||
|
||||
_contactJob.MapUid = _mapManager.GetMapEntityIdOrThrow(mapId);
|
||||
_contactJob.MoveBuffer.Clear();
|
||||
|
||||
foreach (var (proxy, aabb) in moveBuffer)
|
||||
foreach (var proxy in moveBuffer)
|
||||
{
|
||||
_contactJob.MoveBuffer.Add((proxy, aabb));
|
||||
DebugTools.Assert(_xformQuery.GetComponent(proxy.Entity).Broadphase?.Uid != null);
|
||||
_contactJob.MoveBuffer.Add(proxy);
|
||||
}
|
||||
|
||||
_broadMatrices.Clear();
|
||||
var broadQuery = AllEntityQuery<BroadphaseComponent>();
|
||||
|
||||
// Cache broadphase matrices up front.
|
||||
// We'll defer the proxy world AABBs until we get contacts rather than doing it on every single move.
|
||||
// This is because contacts are run in parallel so we can spread the work a bit more and also don't duplicate it per tick.
|
||||
while (broadQuery.MoveNext(out var bUid, out _))
|
||||
{
|
||||
_broadMatrices[bUid] = _transform.GetWorldMatrix(bUid);
|
||||
}
|
||||
|
||||
for (var i = _contactJob.ContactBuffer.Count; i < _contactJob.MoveBuffer.Count; i++)
|
||||
@@ -220,7 +222,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
if (proxies.Count == 0)
|
||||
continue;
|
||||
|
||||
var proxyA = _contactJob.MoveBuffer[i].Proxy;
|
||||
var proxyA = _contactJob.MoveBuffer[i];
|
||||
var proxyABody = proxyA.Body;
|
||||
|
||||
_fixturesQuery.TryGetComponent(proxyA.Entity, out var manager);
|
||||
@@ -234,7 +236,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
// This is because we generate a contact across 2 different broadphases where both bodies aren't
|
||||
// moving locally but are moving in world-terms.
|
||||
if (proxyA.Fixture.Hard && other.Fixture.Hard &&
|
||||
(gridMoveBuffer.ContainsKey(proxyA) || gridMoveBuffer.ContainsKey(other)))
|
||||
(_gridMoveBuffer.Contains(proxyA) || _gridMoveBuffer.Contains(other)))
|
||||
{
|
||||
_physicsSystem.WakeBody(proxyA.Entity, force: true, manager: manager, body: proxyABody);
|
||||
_physicsSystem.WakeBody(other.Entity, force: true, body: otherBody);
|
||||
@@ -248,15 +250,15 @@ namespace Robust.Shared.Physics.Systems
|
||||
movedGrids.Clear();
|
||||
}
|
||||
|
||||
private void HandleGridCollisions(
|
||||
MapId mapId,
|
||||
HashSet<EntityUid> movedGrids)
|
||||
private void HandleGridCollisions(HashSet<EntityUid> movedGrids)
|
||||
{
|
||||
foreach (var gridUid in movedGrids)
|
||||
{
|
||||
var grid = _gridQuery.GetComponent(gridUid);
|
||||
var xform = _xformQuery.GetComponent(gridUid);
|
||||
DebugTools.Assert(xform.MapID == mapId);
|
||||
|
||||
if (xform.MapID == MapId.Nullspace)
|
||||
continue;
|
||||
|
||||
var (worldPos, worldRot, worldMatrix, invWorldMatrix) = _transform.GetWorldPositionRotationMatrixWithInv(xform);
|
||||
|
||||
@@ -269,7 +271,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
|
||||
var transform = _physicsSystem.GetPhysicsTransform(gridUid);
|
||||
var state = (
|
||||
new Entity<FixturesComponent, MapGridComponent, PhysicsComponent>(gridUid, fixture, grid, physics),
|
||||
new Entity<FixturesComponent, MapGridComponent, PhysicsComponent, TransformComponent>(gridUid, fixture, grid, physics, xform),
|
||||
transform,
|
||||
worldMatrix,
|
||||
invWorldMatrix,
|
||||
@@ -280,9 +282,9 @@ namespace Robust.Shared.Physics.Systems
|
||||
_physicsQuery,
|
||||
_xformQuery);
|
||||
|
||||
_mapManager.FindGridsIntersecting(mapId, aabb, ref state,
|
||||
_mapManager.FindGridsIntersecting(xform.MapID, aabb, ref state,
|
||||
static (EntityUid uid, MapGridComponent component,
|
||||
ref (Entity<FixturesComponent, MapGridComponent, PhysicsComponent> grid,
|
||||
ref (Entity<FixturesComponent, MapGridComponent, PhysicsComponent, TransformComponent> grid,
|
||||
Transform transform,
|
||||
Matrix3x2 worldMatrix,
|
||||
Matrix3x2 invWorldMatrix,
|
||||
@@ -299,7 +301,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
return true;
|
||||
}
|
||||
|
||||
var (_, _, otherGridMatrix, otherGridInvMatrix) = tuple.xformSystem.GetWorldPositionRotationMatrixWithInv(collidingXform, tuple.xformQuery);
|
||||
var (_, _, otherGridMatrix, otherGridInvMatrix) = tuple.xformSystem.GetWorldPositionRotationMatrixWithInv(collidingXform);
|
||||
var otherGridBounds = otherGridMatrix.TransformBox(component.LocalAABB);
|
||||
var otherTransform = tuple._physicsSystem.GetPhysicsTransform(uid);
|
||||
|
||||
@@ -340,7 +342,10 @@ namespace Robust.Shared.Physics.Systems
|
||||
var otherAABB = otherFixture.Shape.ComputeAABB(otherTransform, j);
|
||||
|
||||
if (!fixAABB.Intersects(otherAABB)) continue;
|
||||
tuple._physicsSystem.AddPair(tuple.grid.Owner, uid,
|
||||
|
||||
tuple._physicsSystem.AddPair(
|
||||
(tuple.grid.Owner, tuple.grid.Comp3, tuple.grid.Comp4),
|
||||
(uid, physicsB, collidingXform),
|
||||
ourId, otherId,
|
||||
fixture, i,
|
||||
otherFixture, j,
|
||||
@@ -451,29 +456,24 @@ namespace Robust.Shared.Physics.Systems
|
||||
|
||||
_physicsSystem.SetAwake(entity!, true);
|
||||
|
||||
var matrix = _transform.GetWorldMatrix(broadphase);
|
||||
foreach (var fixture in entity.Comp2.Fixtures.Values)
|
||||
{
|
||||
TouchProxies(entity.Comp3.MapUid.Value, matrix, fixture);
|
||||
TouchProxies(fixture);
|
||||
}
|
||||
}
|
||||
|
||||
internal void TouchProxies(EntityUid mapId, Matrix3x2 broadphaseMatrix, Fixture fixture)
|
||||
internal void TouchProxies(Fixture fixture)
|
||||
{
|
||||
foreach (var proxy in fixture.Proxies)
|
||||
{
|
||||
AddToMoveBuffer(mapId, proxy, broadphaseMatrix.TransformBox(proxy.AABB));
|
||||
AddToMoveBuffer(proxy);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddToMoveBuffer(EntityUid mapId, FixtureProxy proxy, Box2 aabb)
|
||||
private void AddToMoveBuffer(FixtureProxy proxy)
|
||||
{
|
||||
if (!_mapQuery.TryGetComponent(mapId, out var physicsMap))
|
||||
return;
|
||||
|
||||
DebugTools.Assert(proxy.Body.CanCollide);
|
||||
|
||||
physicsMap.MoveBuffer[proxy] = aabb;
|
||||
_physicsSystem.MoveBuffer.Add(proxy);
|
||||
}
|
||||
|
||||
public void Refilter(EntityUid uid, Fixture fixture, TransformComponent? xform = null)
|
||||
@@ -492,8 +492,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
if (!_xformQuery.TryGetComponent(xform.Broadphase?.Uid, out var broadphase))
|
||||
return;
|
||||
|
||||
var matrix = _transform.GetWorldMatrix(broadphase);
|
||||
TouchProxies(xform.MapUid.Value, matrix, fixture);
|
||||
TouchProxies(fixture);
|
||||
}
|
||||
|
||||
internal void GetBroadphases(MapId mapId, Box2 aabb, BroadphaseCallback callback)
|
||||
@@ -560,30 +559,35 @@ namespace Robust.Shared.Physics.Systems
|
||||
private record struct BroadphaseContactJob() : IParallelRobustJob
|
||||
{
|
||||
public SharedBroadphaseSystem System = default!;
|
||||
public SharedTransformSystem TransformSys = default!;
|
||||
public IMapManager _mapManager = default!;
|
||||
|
||||
public float BroadphaseExpand;
|
||||
|
||||
public EntityUid MapUid;
|
||||
public EntityQuery<TransformComponent> XformQuery;
|
||||
|
||||
public List<List<FixtureProxy>> ContactBuffer = new();
|
||||
public List<(FixtureProxy Proxy, Box2 WorldAABB)> MoveBuffer = new();
|
||||
public List<FixtureProxy> MoveBuffer = new();
|
||||
|
||||
public int BatchSize => 8;
|
||||
|
||||
public void Execute(int index)
|
||||
{
|
||||
var (proxy, worldAABB) = MoveBuffer[index];
|
||||
var proxy = MoveBuffer[index];
|
||||
var broadphaseUid = XformQuery.GetComponent(proxy.Entity).Broadphase?.Uid;
|
||||
var worldAABB = System._broadMatrices[broadphaseUid!.Value].TransformBox(proxy.AABB);
|
||||
var buffer = ContactBuffer[index];
|
||||
buffer.Clear();
|
||||
|
||||
var mapUid = XformQuery.GetComponent(proxy.Entity).MapUid ?? EntityUid.Invalid;
|
||||
|
||||
var proxyBody = proxy.Body;
|
||||
DebugTools.Assert(!proxyBody.Deleted);
|
||||
|
||||
var state = (System, proxy, worldAABB, buffer);
|
||||
|
||||
// Get every broadphase we may be intersecting.
|
||||
_mapManager.FindGridsIntersecting(MapUid, worldAABB.Enlarged(BroadphaseExpand), ref state,
|
||||
_mapManager.FindGridsIntersecting(mapUid, worldAABB.Enlarged(BroadphaseExpand), ref state,
|
||||
static (EntityUid uid, MapGridComponent _, ref (
|
||||
SharedBroadphaseSystem system,
|
||||
FixtureProxy proxy,
|
||||
@@ -599,7 +603,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
|
||||
// Struct ref moment, I have no idea what's fastest.
|
||||
buffer = state.buffer;
|
||||
System.FindPairs(proxy, worldAABB, MapUid, buffer);
|
||||
System.FindPairs(proxy, worldAABB, mapUid, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public abstract partial class SharedJointSystem : EntitySystem
|
||||
foreach (var joint in _dirtyJoints)
|
||||
{
|
||||
if (joint.Comp.Deleted || joint.Comp.JointCount != 0) continue;
|
||||
EntityManager.RemoveComponent<JointComponent>(joint);
|
||||
RemComp<JointComponent>(joint);
|
||||
}
|
||||
|
||||
_dirtyJoints.Clear();
|
||||
@@ -551,7 +551,7 @@ public abstract partial class SharedJointSystem : EntitySystem
|
||||
_physics.WakeBody(uidA);
|
||||
}
|
||||
|
||||
if (EntityManager.TryGetComponent<PhysicsComponent>(bodyBUid, out var bodyB) &&
|
||||
if (TryComp<PhysicsComponent>(bodyBUid, out var bodyB) &&
|
||||
MetaData(bodyBUid).EntityLifeStage < EntityLifeStage.Terminating)
|
||||
{
|
||||
var uidB = jointComponentB.Relay ?? bodyBUid;
|
||||
|
||||
@@ -23,10 +23,8 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Robust.Shared.Collections;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map;
|
||||
@@ -314,13 +312,6 @@ public partial class SharedPhysicsSystem
|
||||
body._inertia += data.I;
|
||||
}
|
||||
|
||||
// Update this after re-calculating mass as content may want to use the sum of fixture masses instead.
|
||||
if (((int) body.BodyType & (int) (BodyType.Kinematic | BodyType.Static)) != 0)
|
||||
{
|
||||
body._localCenter = Vector2.Zero;
|
||||
return;
|
||||
}
|
||||
|
||||
if (body._mass > 0.0f)
|
||||
{
|
||||
body._invMass = 1.0f / body._mass;
|
||||
@@ -350,18 +341,23 @@ public partial class SharedPhysicsSystem
|
||||
var oldCenter = body._localCenter;
|
||||
body._localCenter = localCenter;
|
||||
|
||||
// Update center of mass velocity.
|
||||
var comVelocityDiff = Vector2Helpers.Cross(body.AngularVelocity, localCenter - oldCenter);
|
||||
if (((int) body.BodyType & (int) (BodyType.Kinematic | BodyType.Static)) == 0)
|
||||
{
|
||||
// Update center of mass velocity.
|
||||
var comVelocityDiff = Vector2Helpers.Cross(body.AngularVelocity, localCenter - oldCenter);
|
||||
|
||||
if (comVelocityDiff != Vector2.Zero)
|
||||
{
|
||||
body.LinearVelocity += comVelocityDiff;
|
||||
DirtyField(uid, body, nameof(PhysicsComponent.LinearVelocity));
|
||||
}
|
||||
if (comVelocityDiff != Vector2.Zero)
|
||||
{
|
||||
body.LinearVelocity += comVelocityDiff;
|
||||
DirtyField(uid, body, nameof(PhysicsComponent.LinearVelocity));
|
||||
}
|
||||
}
|
||||
|
||||
if (body._mass == oldMass && body._inertia == oldInertia && oldCenter == localCenter)
|
||||
return;
|
||||
|
||||
// we always do the full mass and COM calculation and raise this, even for static bodies as content may need the info
|
||||
// examples are stations anchored with the station anchor, shuttles landed on planets, or grids getting an atmosphere above a certain mass threshold
|
||||
var ev = new MassDataChangedEvent((uid, body, manager), oldMass, oldInertia, oldCenter);
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
}
|
||||
@@ -488,14 +484,17 @@ public partial class SharedPhysicsSystem
|
||||
body.Awake = true;
|
||||
}
|
||||
|
||||
UpdateMapAwakeState(uid, body);
|
||||
if (body.Awake)
|
||||
AddAwakeBody((uid, body, Transform(uid)));
|
||||
else
|
||||
RemoveSleepBody((uid, body, Transform(uid)));
|
||||
}
|
||||
|
||||
public void TrySetBodyType(EntityUid uid, BodyType value, FixturesComponent? manager = null, PhysicsComponent? body = null, TransformComponent? xform = null)
|
||||
{
|
||||
if (_fixturesQuery.Resolve(uid, ref manager, false) &&
|
||||
PhysicsQuery.Resolve(uid, ref body, false) &&
|
||||
_xformQuery.Resolve(uid, ref xform, false))
|
||||
XformQuery.Resolve(uid, ref xform, false))
|
||||
{
|
||||
SetBodyType(uid, value, manager, body, xform);
|
||||
}
|
||||
@@ -511,7 +510,6 @@ public partial class SharedPhysicsSystem
|
||||
|
||||
var oldType = body.BodyType;
|
||||
body.BodyType = value;
|
||||
ResetMassData(uid, manager, body);
|
||||
|
||||
body.Force = Vector2.Zero;
|
||||
body.Torque = 0f;
|
||||
@@ -705,7 +703,7 @@ public partial class SharedPhysicsSystem
|
||||
|
||||
public Transform GetRelativePhysicsTransform(Transform worldTransform, Entity<TransformComponent?> relative)
|
||||
{
|
||||
if (!_xformQuery.Resolve(relative.Owner, ref relative.Comp))
|
||||
if (!XformQuery.Resolve(relative.Owner, ref relative.Comp))
|
||||
return Physics.Transform.Empty;
|
||||
|
||||
var (_, broadphaseRot, _, broadphaseInv) = _transform.GetWorldPositionRotationMatrixWithInv(relative.Comp);
|
||||
@@ -721,8 +719,8 @@ public partial class SharedPhysicsSystem
|
||||
Entity<TransformComponent?> entity,
|
||||
Entity<TransformComponent?> relative)
|
||||
{
|
||||
if (!_xformQuery.Resolve(entity.Owner, ref entity.Comp) ||
|
||||
!_xformQuery.Resolve(relative.Owner, ref relative.Comp))
|
||||
if (!XformQuery.Resolve(entity.Owner, ref entity.Comp) ||
|
||||
!XformQuery.Resolve(relative.Owner, ref relative.Comp))
|
||||
{
|
||||
return Physics.Transform.Empty;
|
||||
}
|
||||
@@ -738,7 +736,7 @@ public partial class SharedPhysicsSystem
|
||||
/// </summary>
|
||||
public Transform GetLocalPhysicsTransform(EntityUid uid, TransformComponent? xform = null)
|
||||
{
|
||||
if (!_xformQuery.Resolve(uid, ref xform) || xform.Broadphase == null)
|
||||
if (!XformQuery.Resolve(uid, ref xform) || xform.Broadphase == null)
|
||||
return Physics.Transform.Empty;
|
||||
|
||||
var broadphase = xform.Broadphase.Value.Uid;
|
||||
@@ -753,7 +751,7 @@ public partial class SharedPhysicsSystem
|
||||
|
||||
public Transform GetPhysicsTransform(EntityUid uid, TransformComponent? xform = null)
|
||||
{
|
||||
if (!_xformQuery.Resolve(uid, ref xform))
|
||||
if (!XformQuery.Resolve(uid, ref xform))
|
||||
return Physics.Transform.Empty;
|
||||
|
||||
var (worldPos, worldRot) = _transform.GetWorldPositionRotation(xform);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user