Compare commits

..

4 Commits

Author SHA1 Message Date
Pieter-Jan Briers
b65e0c64ea Version: 226.2.2 2024-08-11 19:54:41 +02:00
Pieter-Jan Briers
4c388bc03d Use absolute path for explorer.exe
frick me

(cherry picked from commit 0284eb0430)
2024-08-11 19:54:41 +02:00
Pieter-Jan Briers
658dee1591 Version: 226.2.1 2024-08-11 17:54:19 +02:00
Pieter-Jan Briers
b6e5cca127 Security updates (#5353)
* Fix security bug in WritableDirProvider.OpenOsWindow()

Reported by @NarryG and @nyeogmi

* Sandbox updates

* Update ImageSharp again

(cherry picked from commit 7d778248ee)
(cherry picked from commit f66cda74e95619ddba2221bda644bf4394619805)
2024-08-11 17:54:19 +02:00
287 changed files with 1880 additions and 8118 deletions

View File

@@ -19,7 +19,6 @@
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzer.Testing" Version="1.1.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.NUnit" Version="1.1.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.NUnit" Version="1.1.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Features" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.8.0" />

View File

@@ -1,4 +1,4 @@
<Project>
<!-- This file automatically reset by Tools/version.py -->
<!-- This file automatically reset by Tools/version.py -->

View File

@@ -54,275 +54,10 @@ END TEMPLATE-->
*None yet*
## 233.0.2
## 226.2.2
### Bugfixes
* Fix exceptions in client game state handling for grids. Now they will rely upon the networked fixture data and not try to rebuild in the grid state handler.
## 233.0.1
### Bugfixes
* Fix IsHardCollidable component to EntityUid references.
## 233.0.0
### Breaking changes
* Made EntityRenamed a broadcast event & added additional args.
* Made test runs parallelizable.
* Added a debug assert that other threads aren't touching entities.
### Bugfixes
* Fix some entitylookup method transformations and add more tests.
* Fix mousehover not updating if new controls showed up under the mouse.
### Internal
* `ClientGameStateManager` now only initialises or starts entities after their parents have already been initialized. There are also some new debug asserts to try ensure that this rule isn't broken elsewhere.
* Engine version script now supports dashes.
## 232.0.0
### Breaking changes
* Obsolete method `AppearanceComponent.TryGetData` is now access-restricted to `SharedAppearanceSystem`; use `SharedAppearanceSystem.TryGetData` instead.
### New features
* Added `SharedAppearanceSystem.AppendData`, which appends non-existing `AppearanceData` from one `AppearanceComponent` to another.
* Added `AppearanceComponent.AppearanceDataInit`, which can be used to set initial `AppearanceData` entries in .yaml.
### Bugfixes
* Fix BUI interfaces not deep-copying in state handling.
* Add Robust.Xaml.csproj to the solution to fix some XAML issues.
### Other
* Serialization will now add type tags (`!type:<T>`) for necessary `NodeData` when writing (currently only for `object` nodes).
### Internal
* Added `ObjectSerializer`, which handles serialization of the generic `object` type.
## 231.1.1
### Bugfixes
* Fixed a bug where the client might not add entities to the broadphase/lookup components.
* Fixed various toolshed commands not working, including `sort`, `sortdown` `join` (for strings), and `emplace`
### Other
* Toolshed command blocks now stop executing if previous errors were not handled / cleared.
## 231.1.0
### New features
* Network `InterfaceData` on `UserInterfaceComponent`.
* Added `System.Decimal` to sandbox.
* Added XAML hot reloading.
* Added API for content to write custom files into replay through `IReplayFileWriter`.
### Other
* Optimized `EntityLookup` and other physics systems.
### Internal
* Added more tests related to physics.
## 231.0.1
### Other
* Add better logging to failed PVS sends.
## 231.0.0
### Breaking changes
* ViewSubscriber has been moved to shared; it doesn't actually do anything on the client but makes shared code easier.
### New features
* ContactEnumreator exists to iterate the contacts of a particular entity.
* Add FixturesChangeComponent as a generic way to add and remove fixtures easily.
* PointLightComponent enabling / disabling now has an attempt event if you wish to block it on content side.
* There's an OpenScreenAt overload for screen-relative coordinates.
* SpriteSystem has methods to get an entity's position in sprite terms.
* EntityManager and ComponentFactory now have additional methods that interact with ComponentRegistry and ComponentRegistryEntry.
### Bugfixes
* Fix PrototypeFlags Add not actually working.
* Fix BUIs going BRRT opening and closing repeatedly upon prediction. The closing now gets deferred to the update loop if it's still closed at the end of prediction.
## 230.2.0
### New features
* Add ProcessNow for IRobustJob as a convenience method where you may not want to run a job in the background sometimes.
* Add Vector2i helpers to all 8 neighbouring directions.
### Other
* Remove IThreadPoolWorkItem interface from IRobustJob.
## 230.1.0
### New features
* You can now pass `bool[]` parameters to shaders.
* Added `toolshed.nearby_entities_limit` CVar.
* Fix `RichTextLabel.Text` to clear and reset the message properly in all cases.
* `scene` command has tab completion now.
* `devwindow` UI inspector property catches exceptions for read properties.
* `SplitContainer.Flip()`
### Bugfixes
* Fix tile enlargement not being applied for some EntityLookup queries.
* `LocalizedEntityCommands` are now not initialized inside `RobustUnitTest`, fixing guaranteed test failures.
* Fixed issues with broadphase init breaking replays frequently.
* Fix uploaded prototypes and resources for clients connecting to a server.
### Other
* Improved error reporting for DataField analyzer.
## 230.0.1
## 230.0.0
### New features
* Added `InterpolatedStringHandlerArgumentAttribute` to the sandbox whitelist.
* `IUserInterfaceManager.Popup()` popups now have a copy to clipboard button.
### Bugfixes
* Security fixes
* Fix exception in `TimedDespawnComponent` spawning another `TimedDespawnComponent`.
* Fixed pool memory leak in physics `SolveIsland`.
## 229.1.2
### Bugfixes
* Fixed a bug where the client might not add entities to the broadphase/lookup components.
## 229.1.1
### Bugfixes
* Fix some teleportation commands not working in singleplayer or replays
### Other
* Audio entity names now include the filepath of the audio being played if relevant for debugging.
## 229.1.0
### Bugfixes
* Fix multithreading bug in ParallelTracker that caused the game to crash randomly.
* Fixed IPv6-only hosts not working properly with built-in HTTP clients.
### Other
* Added obsoletion warning for `Control.Dispose()`. New code should not rely on it.
* Reduced the default tickrate to 30 ticks.
* Encryption of network messages is now done concurrently to avoid spending main thread time. In profiles, this added up to ~8% of main thread time on RMC-14.
## 229.0.0
### Breaking changes
* Fixes large entities causing entity spawn menu to break.
* Made PhysicsHull an internal ref struct for some PolygonShape speedup.
### New features
* Audio ticks-per-second is now capped at 30 by default and controlled via `audio.tick_rate` cvar.
* Add CreateWindow and CreateDisposableControl helpers for BUIs.
* Add OnProtoReload virtual method to BUIs that gets called on prototype reloads.
* Add RemoveData to AppearanceSystem data.
## 228.0.0
### Breaking changes
* The `Color` struct's equality methods now check for exact equality. Use `MathHelper.CloseToPercent(Color, Color)` for the previous functionality.
* Added a toolshed.nearby_limit cvar to limit the maximum range of the nearby command. Defaults to 200.
### New features
* Added command usage with types to Toolshed command help.
* Add Text property to RichTextLabel.
* Whitelist System.Net.IPEndPoint.
* Add event for mass & angular inertia changes.
* Add SpriteSystem.IsVisible for layers.
* Add TryQueueDeleteEntity that checks if the entity is already deleted / queuedeleted first.
### Bugfixes
* Clients connecting to a server now always load prototype uploads after resource uploads, fixing ordering bugs that could cause various errors.
## 227.0.0
### Breaking changes
* Add a `loop` arg to SpriteSystem.GetFrame in case you don't want to get a looping animation.
* Remove obsolete VisibileSystem methods.
### New features
* Added `LocalizedEntityCommands`, which are console commands that have the ability to take entity system dependencies.
* Added `BeginRegistrationRegion` to `IConsoleHost` to allow efficient bulk-registration of console commands.
* Added `IConsoleHost.RegisterCommand` overload that takes an `IConsoleCommand`.
* Added a `Finished` boolean to `AnimationCompletedEvent` which allows distinguishing if an animation was removed prematurely or completed naturally.
* Add GetLocalTilesIntersecting for MapSystem.
* Add an analyzer for methods that should call the base implementation and use it for EntitySystems.
### Bugfixes
* Fix loading replays if string package is compressed inside a zip.
### Other
* Tab completions containing spaces are now properly quoted, so the command will actually work properly once entered.
* Mark EntityCoordinates.Offset as Pure so it shows as warnings if the variable is unused.
* Networked events will always be processed in order even if late.
## 226.3.0
### New features
* `System.Collections.IList` and `System.Collections.ICollection` are now sandbox safe, this fixes some collection expression cases.
* The sandboxing system will now report the methods responsible for references to illegal items.
## 226.2.1
## 226.2.0

View File

@@ -1,2 +0,0 @@
popup-copy-button = Copy
popup-title = Alert!

View File

@@ -1,91 +0,0 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using NUnit.Framework;
using VerifyCS =
Microsoft.CodeAnalysis.CSharp.Testing.NUnit.AnalyzerVerifier<Robust.Analyzers.DataDefinitionAnalyzer>;
namespace Robust.Analyzers.Tests;
[Parallelizable(ParallelScope.All | ParallelScope.Fixtures)]
[TestFixture]
public sealed class DataDefinitionAnalyzerTest
{
private static Task Verifier(string code, params DiagnosticResult[] expected)
{
var test = new CSharpAnalyzerTest<DataDefinitionAnalyzer, NUnitVerifier>()
{
TestState =
{
Sources = { code }
},
};
// ExpectedDiagnostics cannot be set, so we need to AddRange here...
test.TestState.ExpectedDiagnostics.AddRange(expected);
return test.RunAsync();
}
[Test]
public async Task Test()
{
const string code = """
using System;
using Robust.Shared.ViewVariables;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Robust.Shared.ViewVariables
{
public sealed class ViewVariablesAttribute : Attribute
{
public readonly VVAccess Access = VVAccess.ReadOnly;
public ViewVariablesAttribute() { }
public ViewVariablesAttribute(VVAccess access)
{
Access = access;
}
}
public enum VVAccess : byte
{
ReadOnly = 0,
ReadWrite = 1,
}
}
namespace Robust.Shared.Serialization.Manager.Attributes
{
public class DataFieldBaseAttribute : Attribute;
public class DataFieldAttribute : DataFieldBaseAttribute;
public sealed class DataDefinitionAttribute : Attribute;
}
[DataDefinition]
public sealed partial class Foo
{
[DataField, ViewVariables(VVAccess.ReadWrite)]
public int Bad;
[DataField]
public int Good;
[DataField, ViewVariables]
public int Good2;
[DataField, ViewVariables(VVAccess.ReadOnly)]
public int Good3;
[ViewVariables]
public int Good4;
}
""";
await Verifier(code,
// /0/Test0.cs(35,17): info RA0028: Data field Bad in data definition Foo has ViewVariables attribute with ReadWrite access, which is redundant
VerifyCS.Diagnostic(DataDefinitionAnalyzer.DataFieldNoVVReadWriteRule).WithSpan(35, 17, 35, 50).WithArguments("Bad", "Foo")
);
}
}

View File

@@ -1,92 +0,0 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using NUnit.Framework;
using VerifyCS =
Microsoft.CodeAnalysis.CSharp.Testing.NUnit.AnalyzerVerifier<Robust.Analyzers.MustCallBaseAnalyzer>;
namespace Robust.Analyzers.Tests;
[Parallelizable(ParallelScope.All | ParallelScope.Fixtures)]
[TestFixture]
public sealed class MustCallBaseAnalyzerTest
{
private static Task Verifier(string code, params DiagnosticResult[] expected)
{
var test = new CSharpAnalyzerTest<MustCallBaseAnalyzer, NUnitVerifier>()
{
TestState =
{
Sources = { code }
},
};
TestHelper.AddEmbeddedSources(
test.TestState,
"Robust.Shared.IoC.MustCallBaseAttribute.cs"
);
// ExpectedDiagnostics cannot be set, so we need to AddRange here...
test.TestState.ExpectedDiagnostics.AddRange(expected);
return test.RunAsync();
}
[Test]
public async Task Test()
{
const string code = """
using Robust.Shared.Analyzers;
public class Foo
{
[MustCallBase]
public virtual void Function()
{
}
[MustCallBase(true)]
public virtual void Function2()
{
}
}
public class Bar : Foo
{
public override void Function()
{
}
public override void Function2()
{
}
}
public class Baz : Foo
{
public override void Function()
{
base.Function();
}
}
public class Bal : Bar
{
public override void Function2()
{
}
}
""";
await Verifier(code,
// /0/Test0.cs(20,26): warning RA0028: Overriders of this function must always call the base function
VerifyCS.Diagnostic().WithSpan(20, 26, 20, 34),
// /0/Test0.cs(41,26): warning RA0028: Overriders of this function must always call the base function
VerifyCS.Diagnostic().WithSpan(41, 26, 41, 35));
}
}

View File

@@ -1,71 +0,0 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using NUnit.Framework;
using VerifyCS =
Microsoft.CodeAnalysis.CSharp.Testing.NUnit.AnalyzerVerifier<Robust.Analyzers.PreferNonGenericVariantForAnalyzer>;
namespace Robust.Analyzers.Tests;
[Parallelizable(ParallelScope.All | ParallelScope.Fixtures)]
[TestFixture]
public sealed class PreferNonGenericVariantForTest
{
private static Task Verifier(string code, params DiagnosticResult[] expected)
{
var test = new CSharpAnalyzerTest<PreferNonGenericVariantForAnalyzer, NUnitVerifier>()
{
TestState =
{
Sources = { code },
},
};
TestHelper.AddEmbeddedSources(
test.TestState,
"Robust.Shared.Analyzers.PreferNonGenericVariantForAttribute.cs"
);
// ExpectedDiagnostics cannot be set, so we need to AddRange here...
test.TestState.ExpectedDiagnostics.AddRange(expected);
return test.RunAsync();
}
[Test]
public async Task Test()
{
const string code = """
using Robust.Shared.Analyzers;
public class Bar { };
public class Baz { };
public class Okay { };
public static class Foo
{
[PreferNonGenericVariantFor(typeof(Bar), typeof(Baz))]
public static void DoFoo<T>() { }
}
public class Test
{
public void DoBad()
{
Foo.DoFoo<Bar>();
}
public void DoGood()
{
Foo.DoFoo<Okay>();
}
}
""";
await Verifier(code,
// /0/Test0.cs(17,9): warning RA0029: Use the non-generic variant of this method for type Bar
VerifyCS.Diagnostic().WithSpan(17, 9, 17, 25).WithArguments("Bar")
);
}
}

View File

@@ -1,62 +0,0 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using NUnit.Framework;
using VerifyCS =
Microsoft.CodeAnalysis.CSharp.Testing.NUnit.AnalyzerVerifier<Robust.Analyzers.PreferOtherTypeAnalyzer>;
namespace Robust.Analyzers.Tests;
[Parallelizable(ParallelScope.All | ParallelScope.Fixtures)]
[TestFixture]
public sealed class PreferOtherTypeAnalyzerTest
{
private static Task Verifier(string code, params DiagnosticResult[] expected)
{
var test = new CSharpAnalyzerTest<PreferOtherTypeAnalyzer, NUnitVerifier>()
{
TestState =
{
Sources = { code },
},
};
TestHelper.AddEmbeddedSources(
test.TestState,
"Robust.Shared.Analyzers.PreferOtherTypeAttribute.cs"
);
// ExpectedDiagnostics cannot be set, so we need to AddRange here...
test.TestState.ExpectedDiagnostics.AddRange(expected);
return test.RunAsync();
}
[Test]
public async Task Test()
{
const string code = """
using Robust.Shared.Analyzers;
public class EntityPrototype { };
public class EntProtoId { };
public class ReagentPrototype { };
[PreferOtherType(typeof(EntityPrototype), typeof(EntProtoId))]
public class ProtoId<T> { };
public class Test
{
public ProtoId<EntityPrototype> Bad = new();
public ProtoId<ReagentPrototype> Good = new();
}
""";
await Verifier(code,
// /0/Test0.cs(12,12): warning RA0031: Use the specific type EntProtoId instead of ProtoId when the type argument is EntityPrototype
VerifyCS.Diagnostic().WithSpan(12, 12, 12, 48).WithArguments("EntProtoId", "ProtoId", "EntityPrototype")
);
}
}

View File

@@ -1,81 +0,0 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using NUnit.Framework;
using VerifyCS =
Microsoft.CodeAnalysis.CSharp.Testing.NUnit.AnalyzerVerifier<Robust.Analyzers.PreferOtherTypeAnalyzer>;
namespace Robust.Analyzers.Tests;
public sealed class PreferOtherTypeFixerTest
{
private static Task Verifier(string code, string fixedCode, params DiagnosticResult[] expected)
{
var test = new CSharpCodeFixTest<PreferOtherTypeAnalyzer, PreferOtherTypeFixer, NUnitVerifier>()
{
TestState =
{
Sources = { code },
},
FixedState =
{
Sources = { fixedCode },
}
};
TestHelper.AddEmbeddedSources(
test.TestState,
"Robust.Shared.Analyzers.PreferOtherTypeAttribute.cs"
);
TestHelper.AddEmbeddedSources(
test.FixedState,
"Robust.Shared.Analyzers.PreferOtherTypeAttribute.cs"
);
test.TestState.ExpectedDiagnostics.AddRange(expected);
return test.RunAsync();
}
[Test]
public async Task Test()
{
const string code = """
using Robust.Shared.Analyzers;
public class EntityPrototype { };
public class EntProtoId { };
public class ReagentPrototype { };
[PreferOtherType(typeof(EntityPrototype), typeof(EntProtoId))]
public class ProtoId<T> { };
public class Test
{
public ProtoId<EntityPrototype> Foo = new();
}
""";
const string fixedCode = """
using Robust.Shared.Analyzers;
public class EntityPrototype { };
public class EntProtoId { };
public class ReagentPrototype { };
[PreferOtherType(typeof(EntityPrototype), typeof(EntProtoId))]
public class ProtoId<T> { };
public class Test
{
public EntProtoId Foo = new();
}
""";
await Verifier(code, fixedCode,
// /0/Test0.cs(12,12): error RA0031: Use the specific type EntProtoId instead of ProtoId when the type argument is EntityPrototype
VerifyCS.Diagnostic().WithSpan(12, 12, 12, 48).WithArguments("EntProtoId", "ProtoId", "EntityPrototype"));
}
}

View File

@@ -10,9 +10,6 @@
<ItemGroup>
<EmbeddedResource Include="..\Robust.Shared\Analyzers\AccessAttribute.cs" LogicalName="Robust.Shared.Analyzers.AccessAttribute.cs" LinkBase="Implementations" />
<EmbeddedResource Include="..\Robust.Shared\Analyzers\AccessPermissions.cs" LogicalName="Robust.Shared.Analyzers.AccessPermissions.cs" LinkBase="Implementations" />
<EmbeddedResource Include="..\Robust.Shared\Analyzers\MustCallBaseAttribute.cs" LogicalName="Robust.Shared.IoC.MustCallBaseAttribute.cs" LinkBase="Implementations" />
<EmbeddedResource Include="..\Robust.Shared\Analyzers\PreferNonGenericVariantForAttribute.cs" LogicalName="Robust.Shared.Analyzers.PreferNonGenericVariantForAttribute.cs" LinkBase="Implementations" />
<EmbeddedResource Include="..\Robust.Shared\Analyzers\PreferOtherTypeAttribute.cs" LogicalName="Robust.Shared.Analyzers.PreferOtherTypeAttribute.cs" LinkBase="Implementations" />
<EmbeddedResource Include="..\Robust.Shared\IoC\DependencyAttribute.cs" LogicalName="Robust.Shared.IoC.DependencyAttribute.cs" LinkBase="Implementations" />
</ItemGroup>
@@ -28,7 +25,6 @@
<PackageReference Include="Microsoft.CodeAnalysis.Analyzer.Testing"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.NUnit"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.NUnit"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces"/>
<PackageReference Include="NUnit"/>
<PackageReference Include="NUnit3TestAdapter"/>

View File

@@ -7,7 +7,6 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Robust.Roslyn.Shared;
using Robust.Shared.Serialization.Manager.Definition;
using Robust.Shared.ViewVariables;
namespace Robust.Analyzers;
@@ -17,9 +16,6 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
private const string DataDefinitionNamespace = "Robust.Shared.Serialization.Manager.Attributes.DataDefinitionAttribute";
private const string ImplicitDataDefinitionNamespace = "Robust.Shared.Serialization.Manager.Attributes.ImplicitDataDefinitionForInheritorsAttribute";
private const string DataFieldBaseNamespace = "Robust.Shared.Serialization.Manager.Attributes.DataFieldBaseAttribute";
private const string ViewVariablesNamespace = "Robust.Shared.ViewVariables.ViewVariablesAttribute";
private const string DataFieldAttributeName = "DataField";
private const string ViewVariablesAttributeName = "ViewVariables";
private static readonly DiagnosticDescriptor DataDefinitionPartialRule = new(
Diagnostics.IdDataDefinitionPartial,
@@ -70,20 +66,9 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
true,
"Make sure to remove the tag string from the data field attribute."
);
public static readonly DiagnosticDescriptor DataFieldNoVVReadWriteRule = new(
Diagnostics.IdDataFieldNoVVReadWrite,
"Data field has VV ReadWrite",
"Data field {0} in data definition {1} has ViewVariables attribute with ReadWrite access, which is redundant",
"Usage",
DiagnosticSeverity.Info,
true,
"Make sure to remove the ViewVariables attribute."
);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(
DataDefinitionPartialRule, NestedDataDefinitionPartialRule, DataFieldWritableRule, DataFieldPropertyWritableRule,
DataFieldRedundantTagRule, DataFieldNoVVReadWriteRule
DataFieldRedundantTagRule
);
public override void Initialize(AnalysisContext context)
@@ -154,14 +139,7 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
if (HasRedundantTag(fieldSymbol))
{
TryGetAttributeLocation(field, DataFieldAttributeName, out var location);
context.ReportDiagnostic(Diagnostic.Create(DataFieldRedundantTagRule, location, fieldSymbol.Name, type.Name));
}
if (HasVVReadWrite(fieldSymbol))
{
TryGetAttributeLocation(field, ViewVariablesAttributeName, out var location);
context.ReportDiagnostic(Diagnostic.Create(DataFieldNoVVReadWriteRule, location, fieldSymbol.Name, type.Name));
context.ReportDiagnostic(Diagnostic.Create(DataFieldRedundantTagRule, context.Node.GetLocation(), fieldSymbol.Name, type.Name));
}
}
}
@@ -190,14 +168,7 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
if (HasRedundantTag(propertySymbol))
{
TryGetAttributeLocation(property, DataFieldAttributeName, out var location);
context.ReportDiagnostic(Diagnostic.Create(DataFieldRedundantTagRule, location, propertySymbol.Name, type.Name));
}
if (HasVVReadWrite(propertySymbol))
{
TryGetAttributeLocation(property, ViewVariablesAttributeName, out var location);
context.ReportDiagnostic(Diagnostic.Create(DataFieldNoVVReadWriteRule, location, propertySymbol.Name, type.Name));
context.ReportDiagnostic(Diagnostic.Create(DataFieldRedundantTagRule, context.Node.GetLocation(), propertySymbol.Name, type.Name));
}
}
@@ -267,24 +238,6 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
return false;
}
private static bool TryGetAttributeLocation(MemberDeclarationSyntax syntax, string attributeName, out Location location)
{
foreach (var attributeList in syntax.AttributeLists)
{
foreach (var attribute in attributeList.Attributes)
{
if (attribute.Name.ToString() != attributeName)
continue;
location = attribute.GetLocation();
return true;
}
}
// Default to the declaration syntax's location
location = syntax.GetLocation();
return false;
}
private static bool IsReadOnlyMember(ITypeSymbol type, ISymbol member)
{
if (member is IFieldSymbol field)
@@ -339,34 +292,6 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
return explicitName == automaticName;
}
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())
{
if (attr.AttributeClass?.ToDisplayString() == ViewVariablesNamespace)
{
viewVariablesAttribute = attr;
}
}
if (viewVariablesAttribute == null)
return false;
// Default is ReadOnly, which is fine
if (viewVariablesAttribute.ConstructorArguments.Length == 0)
return false;
var accessArgument = viewVariablesAttribute.ConstructorArguments[0];
if (accessArgument.Value is not byte accessByte)
return false;
return (VVAccess)accessByte == VVAccess.ReadWrite;
}
private static bool IsImplicitDataDefinition(ITypeSymbol type)
{
if (HasAttribute(type, ImplicitDataDefinitionNamespace))

View File

@@ -15,11 +15,9 @@ public sealed class DefinitionFixer : CodeFixProvider
{
private const string DataFieldAttributeName = "DataField";
private const string ViewVariablesAttributeName = "ViewVariables";
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(
IdDataDefinitionPartial, IdNestedDataDefinitionPartial, IdDataFieldWritable, IdDataFieldPropertyWritable,
IdDataFieldRedundantTag, IdDataFieldNoVVReadWrite
IdDataFieldRedundantTag
);
public override Task RegisterCodeFixesAsync(CodeFixContext context)
@@ -38,8 +36,6 @@ public sealed class DefinitionFixer : CodeFixProvider
return RegisterDataFieldPropertyFix(context, diagnostic);
case IdDataFieldRedundantTag:
return RegisterRedundantTagFix(context, diagnostic);
case IdDataFieldNoVVReadWrite:
return RegisterVVReadWriteFix(context, diagnostic);
}
}
@@ -140,48 +136,6 @@ public sealed class DefinitionFixer : CodeFixProvider
return document.WithSyntaxRoot(root);
}
private static async Task RegisterVVReadWriteFix(CodeFixContext context, Diagnostic diagnostic)
{
var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken);
var span = diagnostic.Location.SourceSpan;
var token = root?.FindToken(span.Start).Parent?.AncestorsAndSelf().OfType<MemberDeclarationSyntax>().First();
if (token == null)
return;
context.RegisterCodeFix(CodeAction.Create(
"Remove ViewVariables attribute",
c => RemoveVVAttribute(context.Document, token, c),
"Remove ViewVariables attribute"
), diagnostic);
}
private static async Task<Document> RemoveVVAttribute(Document document, MemberDeclarationSyntax syntax, CancellationToken cancellation)
{
var root = (CompilationUnitSyntax?) await document.GetSyntaxRootAsync(cancellation);
var newLists = new SyntaxList<AttributeListSyntax>();
foreach (var attributeList in syntax.AttributeLists)
{
var attributes = new SeparatedSyntaxList<AttributeSyntax>();
foreach (var attribute in attributeList.Attributes)
{
if (attribute.Name.ToString() != ViewVariablesAttributeName)
{
attributes = attributes.Add(attribute);
}
}
// Don't add empty lists []
if (attributes.Count > 0)
newLists = newLists.Add(attributeList.WithAttributes(attributes));
}
var newSyntax = syntax.WithAttributeLists(newLists);
root = root!.ReplaceNode(syntax, newSyntax);
return document.WithSyntaxRoot(root);
}
private static async Task RegisterDataFieldFix(CodeFixContext context, Diagnostic diagnostic)
{
var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken);

View File

@@ -1,111 +0,0 @@
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Robust.Roslyn.Shared;
namespace Robust.Analyzers;
#nullable enable
/// <summary>
/// Enforces <c>MustCallBaseAttribute</c>.
/// </summary>
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class MustCallBaseAnalyzer : DiagnosticAnalyzer
{
private const string Attribute = "Robust.Shared.Analyzers.MustCallBaseAttribute";
private static readonly DiagnosticDescriptor Rule = new(
Diagnostics.IdMustCallBase,
"No base call in overriden function",
"Overriders of this function must always call the base function",
"Usage",
DiagnosticSeverity.Warning,
isEnabledByDefault: true);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.EnableConcurrentExecution();
context.RegisterSymbolAction(AnalyzeSymbol, SymbolKind.Method);
}
private static void AnalyzeSymbol(SymbolAnalysisContext context)
{
if (context.Symbol is not IMethodSymbol { IsOverride: true } method)
return;
var attrSymbol = context.Compilation.GetTypeByMetadataName(Attribute);
if (attrSymbol == null)
return;
if (DoesMethodOverriderHaveAttribute(method, attrSymbol) is not { } data)
return;
if (data is { onlyOverrides: true, depth: < 2 })
return;
var syntax = (MethodDeclarationSyntax) method.DeclaringSyntaxReferences[0].GetSyntax();
if (HasBaseCall(syntax))
return;
var diag = Diagnostic.Create(Rule, syntax.Identifier.GetLocation());
context.ReportDiagnostic(diag);
}
private static (int depth, bool onlyOverrides)? DoesMethodOverriderHaveAttribute(
IMethodSymbol method,
INamedTypeSymbol attributeSymbol)
{
var depth = 0;
while (method.OverriddenMethod != null)
{
depth += 1;
method = method.OverriddenMethod;
if (GetAttribute(method, attributeSymbol) is not { } attribute)
continue;
var onlyOverrides = attribute.ConstructorArguments is [{Kind: TypedConstantKind.Primitive, Value: true}];
return (depth, onlyOverrides);
}
return null;
}
private static bool HasBaseCall(MethodDeclarationSyntax syntax)
{
return syntax.Accept(new BaseCallLocator());
}
private static AttributeData? GetAttribute(ISymbol namedTypeSymbol, INamedTypeSymbol attrSymbol)
{
return namedTypeSymbol.GetAttributes()
.SingleOrDefault(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, attrSymbol));
}
private sealed class BaseCallLocator : CSharpSyntaxVisitor<bool>
{
public override bool VisitBaseExpression(BaseExpressionSyntax node)
{
return true;
}
public override bool DefaultVisit(SyntaxNode node)
{
foreach (var childNode in node.ChildNodes())
{
if (childNode is not CSharpSyntaxNode cSharpSyntax)
continue;
if (cSharpSyntax.Accept(this))
return true;
}
return false;
}
}
}

View File

@@ -1,65 +0,0 @@
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Operations;
using Robust.Roslyn.Shared;
namespace Robust.Analyzers;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class PreferNonGenericVariantForAnalyzer : DiagnosticAnalyzer
{
private const string AttributeType = "Robust.Shared.Analyzers.PreferNonGenericVariantForAttribute";
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(
UseNonGenericVariantDescriptor
);
private static readonly DiagnosticDescriptor UseNonGenericVariantDescriptor = new(
Diagnostics.IdUseNonGenericVariant,
"Consider using the non-generic variant of this method",
"Use the non-generic variant of this method for type {0}",
"Usage",
DiagnosticSeverity.Warning,
true,
"Use the generic variant of this method.");
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.ReportDiagnostics | GeneratedCodeAnalysisFlags.Analyze);
context.EnableConcurrentExecution();
context.RegisterOperationAction(CheckForNonGenericVariant, OperationKind.Invocation);
}
private void CheckForNonGenericVariant(OperationAnalysisContext obj)
{
if (obj.Operation is not IInvocationOperation invocationOperation) return;
var preferNonGenericAttribute = obj.Compilation.GetTypeByMetadataName(AttributeType);
HashSet<ITypeSymbol> forTypes = [];
foreach (var attribute in invocationOperation.TargetMethod.GetAttributes())
{
if (!SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, preferNonGenericAttribute))
continue;
foreach (var type in attribute.ConstructorArguments[0].Values)
forTypes.Add((ITypeSymbol)type.Value);
break;
}
if (forTypes == null)
return;
foreach (var typeArg in invocationOperation.TargetMethod.TypeArguments)
{
if (forTypes.Contains(typeArg))
{
obj.ReportDiagnostic(
Diagnostic.Create(UseNonGenericVariantDescriptor,
invocationOperation.Syntax.GetLocation(), typeArg.Name));
}
}
}
}

View File

@@ -1,75 +0,0 @@
#nullable enable
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Robust.Roslyn.Shared;
namespace Robust.Analyzers;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class PreferOtherTypeAnalyzer : DiagnosticAnalyzer
{
private const string AttributeType = "Robust.Shared.Analyzers.PreferOtherTypeAttribute";
private static readonly DiagnosticDescriptor PreferOtherTypeDescriptor = new(
Diagnostics.IdPreferOtherType,
"Use the specific type",
"Use the specific type {0} instead of {1} when the type argument is {2}",
"Usage",
DiagnosticSeverity.Error,
true,
"Use the specific type.");
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(
PreferOtherTypeDescriptor
);
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.ReportDiagnostics | GeneratedCodeAnalysisFlags.Analyze);
context.EnableConcurrentExecution();
context.RegisterSyntaxNodeAction(AnalyzeField, SyntaxKind.VariableDeclaration);
}
private void AnalyzeField(SyntaxNodeAnalysisContext context)
{
if (context.Node is not VariableDeclarationSyntax node)
return;
// Get the type of the generic being used
if (node.Type is not GenericNameSyntax genericName)
return;
var genericSyntax = genericName.TypeArgumentList.Arguments[0];
if (context.SemanticModel.GetSymbolInfo(genericSyntax).Symbol is not { } genericType)
return;
// Look for the PreferOtherTypeAttribute
var symbolInfo = context.SemanticModel.GetSymbolInfo(node.Type);
if (symbolInfo.Symbol?.GetAttributes() is not { } attributes)
return;
var preferOtherTypeAttribute = context.Compilation.GetTypeByMetadataName(AttributeType);
foreach (var attribute in attributes)
{
if (!SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, preferOtherTypeAttribute))
continue;
// See if the generic type argument matches the type the attribute specifies
if (attribute.ConstructorArguments[0].Value is not ITypeSymbol checkedType)
return;
if (!SymbolEqualityComparer.Default.Equals(checkedType, genericType))
continue;
if (attribute.ConstructorArguments[1].Value is not ITypeSymbol replacementType)
continue;
context.ReportDiagnostic(Diagnostic.Create(PreferOtherTypeDescriptor,
context.Node.GetLocation(),
replacementType.Name,
symbolInfo.Symbol.Name,
genericType.Name));
}
}
}

View File

@@ -1,97 +0,0 @@
#nullable enable
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using static Robust.Roslyn.Shared.Diagnostics;
namespace Robust.Analyzers;
[ExportCodeFixProvider(LanguageNames.CSharp)]
public sealed class PreferOtherTypeFixer : CodeFixProvider
{
private const string PreferOtherTypeAttributeName = "PreferOtherTypeAttribute";
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(
IdPreferOtherType
);
public override FixAllProvider GetFixAllProvider()
{
return WellKnownFixAllProviders.BatchFixer;
}
public override Task RegisterCodeFixesAsync(CodeFixContext context)
{
foreach (var diagnostic in context.Diagnostics)
{
switch (diagnostic.Id)
{
case IdPreferOtherType:
return RegisterReplaceType(context, diagnostic);
}
}
return Task.CompletedTask;
}
private static async Task RegisterReplaceType(CodeFixContext context, Diagnostic diagnostic)
{
var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken);
var span = diagnostic.Location.SourceSpan;
var token = root?.FindToken(span.Start).Parent?.AncestorsAndSelf().OfType<VariableDeclarationSyntax>().First();
if (token == null)
return;
context.RegisterCodeFix(CodeAction.Create(
"Replace type",
c => ReplaceType(context.Document, token, c),
"Replace type"
), diagnostic);
}
private static async Task<Document> ReplaceType(Document document, VariableDeclarationSyntax syntax, CancellationToken cancellation)
{
var root = (CompilationUnitSyntax?) await document.GetSyntaxRootAsync(cancellation);
var model = await document.GetSemanticModelAsync(cancellation);
if (model == null)
return document;
if (syntax.Type is not GenericNameSyntax genericNameSyntax)
return document;
var genericTypeSyntax = genericNameSyntax.TypeArgumentList.Arguments[0];
if (model.GetSymbolInfo(genericTypeSyntax).Symbol is not {} genericTypeSymbol)
return document;
var symbolInfo = model.GetSymbolInfo(syntax.Type);
if (symbolInfo.Symbol?.GetAttributes() is not { } attributes)
return document;
foreach (var attribute in attributes)
{
if (attribute.AttributeClass?.Name != PreferOtherTypeAttributeName)
continue;
if (attribute.ConstructorArguments[0].Value is not ITypeSymbol checkedTypeSymbol)
continue;
if (!SymbolEqualityComparer.Default.Equals(checkedTypeSymbol, genericTypeSymbol))
continue;
if (attribute.ConstructorArguments[1].Value is not ITypeSymbol replacementTypeSymbol)
continue;
var replacementIdentifier = SyntaxFactory.IdentifierName(replacementTypeSymbol.Name);
var replacementSyntax = syntax.WithType(replacementIdentifier);
root = root!.ReplaceNode(syntax, replacementSyntax);
return document.WithSyntaxRoot(root);
}
return document;
}
}

View File

@@ -16,21 +16,9 @@
<Compile Include="..\Robust.Shared\Analyzers\PreferGenericVariantAttribute.cs" LinkBase="Implementations" />
</ItemGroup>
<ItemGroup>
<!-- Needed for PreferNonGenericVariantAnalyzer. -->
<Compile Include="..\Robust.Shared\Analyzers\PreferNonGenericVariantForAttribute.cs" LinkBase="Implementations" />
</ItemGroup>
<ItemGroup>
<!-- Needed for PreferOtherTypeAnalyzer. -->
<Compile Include="..\Robust.Shared\Analyzers\PreferOtherTypeAttribute.cs" LinkBase="Implementations" />
</ItemGroup>
<ItemGroup>
<!-- Needed for DataDefinitionAnalyzer. -->
<Compile Include="..\Robust.Shared\Serialization\Manager\Definition\DataDefinitionUtility.cs" LinkBase="Implementations" />
<Compile Include="..\Robust.Shared\ViewVariables\ViewVariablesAttribute.cs" LinkBase="Implementations" />
<Compile Include="..\Robust.Shared\Serialization\NetSerializableAttribute.cs" LinkBase="Implementations" />
</ItemGroup>
<Import Project="../Robust.Roslyn.Shared/Robust.Roslyn.Shared.props" />

View File

@@ -1,8 +1,8 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.Build.Framework;
using Robust.Xaml;
namespace Robust.Build.Tasks
{
@@ -37,12 +37,10 @@ namespace Robust.Build.Tasks
var msg = $"CompileRobustXamlTask -> AssemblyFile:{AssemblyFile}, ProjectDirectory:{ProjectDirectory}, OutputPath:{OutputPath}";
BuildEngine.LogMessage(msg, MessageImportance.High);
var res = XamlAotCompiler.Compile(
BuildEngine, input,
var res = XamlCompiler.Compile(BuildEngine, input,
File.ReadAllLines(ReferencesFilePath).Where(l => !string.IsNullOrWhiteSpace(l)).ToArray(),
OutputPath,
(SignAssembly && !DelaySign) ? AssemblyOriginatorKeyFile : null
);
ProjectDirectory, OutputPath,
(SignAssembly && !DelaySign) ? AssemblyOriginatorKeyFile : null);
if (!res.success)
return false;
if (!res.writtentofile)
@@ -67,24 +65,22 @@ namespace Robust.Build.Tasks
return true;
}
// PYREX NOTE: This project was comically null-unsafe before I touched it. I'm just marking what it did accurately
[Required]
public string ReferencesFilePath { get; set; } = null!;
public string ReferencesFilePath { get; set; }
[Required]
public string ProjectDirectory { get; set; } = null!;
public string ProjectDirectory { get; set; }
[Required]
public string AssemblyFile { get; set; } = null!;
public string AssemblyFile { get; set; }
[Required]
public string? OriginalCopyPath { get; set; } = null;
public string OriginalCopyPath { get; set; }
public string? OutputPath { get; set; }
public string UpdateBuildIndicator { get; set; } = null!;
public string OutputPath { get; set; }
public string UpdateBuildIndicator { get; set; }
public string AssemblyOriginatorKeyFile { get; set; } = null!;
public string AssemblyOriginatorKeyFile { get; set; }
public bool SignAssembly { get; set; }
public bool DelaySign { get; set; }
@@ -99,7 +95,7 @@ namespace Robust.Build.Tasks
return rv;
}
public IBuildEngine BuildEngine { get; set; } = null!;
public ITaskHost HostObject { get; set; } = null!;
public IBuildEngine BuildEngine { get; set; }
public ITaskHost HostObject { get; set; }
}
}

View File

@@ -1,11 +1,11 @@
using Microsoft.Build.Framework;
namespace Robust.Xaml
namespace Robust.Build.Tasks
{
/// <summary>
/// Taken from https://github.com/AvaloniaUI/Avalonia/blob/c85fa2b9977d251a31886c2534613b4730fbaeaf/src/Avalonia.Build.Tasks/Extensions.cs
/// </summary>
internal static class Extensions
public static class Extensions
{
//shamefully copied from avalonia
public static void LogMessage(this IBuildEngine engine, string message, MessageImportance imp)

View File

@@ -0,0 +1,37 @@
using System.Linq;
using Pidgin;
using static Pidgin.Parser;
namespace Robust.Build.Tasks
{
public static class MathParsing
{
public static Parser<char, float> Single { get; } = Real.Select(c => (float) c);
public static Parser<char, float> Single1 { get; }
= Single.Between(SkipWhitespaces);
public static Parser<char, (float, float)> Single2 { get; }
= Single.Before(SkipWhitespaces).Repeat(2).Select(e =>
{
var arr = e.ToArray();
return (arr[0], arr[1]);
});
public static Parser<char, (float, float, float, float)> Single4 { get; }
= Single.Before(SkipWhitespaces).Repeat(4).Select(e =>
{
var arr = e.ToArray();
return (arr[0], arr[1], arr[2], arr[3]);
});
public static Parser<char, float[]> Thickness { get; }
= SkipWhitespaces.Then(
OneOf(
Try(Single4.Select(c => new[] {c.Item1, c.Item2, c.Item3, c.Item4})),
Try(Single2.Select(c => new[] {c.Item1, c.Item2})),
Try(Single1.Select(c => new[] {c}))
));
}
}

View File

@@ -55,11 +55,9 @@ namespace Robust.Build.Tasks
public bool BuildProjectFile(string projectFileName, string[] targetNames, IDictionary globalProperties,
IDictionary targetOutputs) => throw new NotSupportedException();
// PYREX NOTE: This project was extremely null-unsafe before I touched it. I'm just marking what it did already
// Here's the broken interface of IBuildEngine that we started with
public bool ContinueOnError => default;
public int LineNumberOfTaskNode => default;
public int ColumnNumberOfTaskNode => default;
public string ProjectFileOfTaskNode => null!;
public bool ContinueOnError { get; }
public int LineNumberOfTaskNode { get; }
public int ColumnNumberOfTaskNode { get; }
public string ProjectFileOfTaskNode { get; }
}
}

View File

@@ -1,9 +1,10 @@
using XamlX.Ast;
using System.Reflection.Emit;
using XamlX.Ast;
using XamlX.Emit;
using XamlX.IL;
using XamlX.TypeSystem;
namespace Robust.Xaml
namespace Robust.Build.Tasks
{
internal class RXamlColorAstNode
: XamlAstNode, IXamlAstValueNode, IXamlAstILEmitableNode

View File

@@ -6,9 +6,9 @@ using XamlX.Emit;
using XamlX.IL;
using XamlX.TypeSystem;
namespace Robust.Xaml
namespace Robust.Build.Tasks
{
internal abstract class RXamlVecLikeConstAstNode<T>
public abstract class RXamlVecLikeConstAstNode<T>
: XamlAstNode, IXamlAstValueNode, IXamlAstILEmitableNode
where T : unmanaged
{
@@ -47,7 +47,7 @@ namespace Robust.Xaml
}
}
internal sealed class RXamlSingleVecLikeConstAstNode : RXamlVecLikeConstAstNode<float>
public sealed class RXamlSingleVecLikeConstAstNode : RXamlVecLikeConstAstNode<float>
{
public RXamlSingleVecLikeConstAstNode(
IXamlLineInfo lineInfo,
@@ -69,7 +69,7 @@ namespace Robust.Xaml
}
}
internal sealed class RXamlInt32VecLikeConstAstNode : RXamlVecLikeConstAstNode<int>
public sealed class RXamlInt32VecLikeConstAstNode : RXamlVecLikeConstAstNode<int>
{
public RXamlInt32VecLikeConstAstNode(
IXamlLineInfo lineInfo,

View File

@@ -2,9 +2,9 @@
using XamlX.Transform;
using XamlX.TypeSystem;
namespace Robust.Xaml
namespace Robust.Build.Tasks
{
internal class RXamlWellKnownTypes
class RXamlWellKnownTypes
{
public XamlTypeWellKnownTypes XamlIlTypes { get; }
public IXamlType Single { get; }

View File

@@ -1,30 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\MSBuild\Robust.Engine.props" />
<!--
PJB3005 (2024-08-24)
So the reason that Robust.Client.Injectors is NS2.0 is that Visual Studio
still ships a .NET FX based MSBuild for some godforsaken reason. This means
that when having Robust.Client.Injectors loaded directly by the main MSBuild
process... that would break.
Except we don't do that anyways right now due to file locking issues, so maybe
it's fine to give up on that. Whatever.
-->
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Framework" Version="17.8.3" />
<PackageReference Include="Mono.Cecil" Version="0.11.5" />
<PackageReference Include="Pidgin" Version="2.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\XamlX\src\XamlX.IL.Cecil\XamlX.IL.Cecil.csproj" />
<ProjectReference Include="..\Robust.Xaml\Robust.Xaml.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,4 +1,5 @@
using System.Linq;
using System.Diagnostics;
using System.Linq;
using XamlX;
using XamlX.Ast;
using XamlX.Emit;
@@ -6,7 +7,7 @@ using XamlX.IL;
using XamlX.Transform;
using XamlX.TypeSystem;
namespace Robust.Xaml
namespace Robust.Build.Tasks
{
/// <summary>
/// Emitters & Transformers based on:
@@ -14,7 +15,7 @@ namespace Robust.Xaml
/// - https://github.com/AvaloniaUI/Avalonia/blob/c85fa2b9977d251a31886c2534613b4730fbaeaf/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AddNameScopeRegistration.cs
/// - https://github.com/AvaloniaUI/Avalonia/blob/afb8ae6f3c517dae912729511483995b16cb31af/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/IgnoredDirectivesTransformer.cs
/// </summary>
internal class RobustXamlILCompiler : XamlILCompiler
public class RobustXamlILCompiler : XamlILCompiler
{
public RobustXamlILCompiler(TransformerConfiguration configuration, XamlLanguageEmitMappings<IXamlILEmitter, XamlILNodeEmitResult> emitMappings, bool fillWithDefaults) : base(configuration, emitMappings, fillWithDefaults)
{
@@ -40,9 +41,8 @@ namespace Robust.Xaml
&& mg.Children.OfType<RobustNameScopeRegistrationXamlIlNode>().Any())
return node;
IXamlAstValueNode? value = null;
IXamlAstValueNode value = null;
for (var c = 0; c < pa.Values.Count; c++)
{
if (pa.Values[c].Type.GetClrType().Equals(context.Configuration.WellKnownTypes.String))
{
value = pa.Values[c];
@@ -57,7 +57,6 @@ namespace Robust.Xaml
break;
}
}
if (value != null)
{
@@ -85,9 +84,9 @@ namespace Robust.Xaml
class RobustNameScopeRegistrationXamlIlNode : XamlAstNode, IXamlAstManipulationNode
{
public IXamlAstValueNode Name { get; set; }
public IXamlType? TargetType { get; }
public IXamlType TargetType { get; }
public RobustNameScopeRegistrationXamlIlNode(IXamlAstValueNode name, IXamlType? targetType) : base(name)
public RobustNameScopeRegistrationXamlIlNode(IXamlAstValueNode name, IXamlType targetType) : base(name)
{
TargetType = targetType;
Name = name;
@@ -105,7 +104,7 @@ namespace Robust.Xaml
{
var scopeField = context.RuntimeContext.ContextType.Fields.First(f =>
f.Name == XamlCustomizations.ContextNameScopeFieldName);
f.Name == XamlCompiler.ContextNameScopeFieldName);
var namescopeRegisterFunction = context.Configuration.TypeSystem
.FindType("Robust.Client.UserInterface.XAML.NameScope").Methods
.First(m => m.Name == "Register");
@@ -129,7 +128,7 @@ namespace Robust.Xaml
return XamlILNodeEmitResult.Void(1);
}
return default!; // PYREX NOTE: This doesn't seem safe! But it's what we were doing before Nullable
return default;
}
}
}
@@ -162,7 +161,7 @@ namespace Robust.Xaml
{
if (!(node is HandleRootObjectScopeNode))
{
return null!; // PYREX NOTE: This doesn't seem safe, but it predates Nullable on this file
return null;
}
var controlType = context.Configuration.TypeSystem.FindType("Robust.Client.UserInterface.Control");
@@ -171,7 +170,7 @@ namespace Robust.Xaml
var dontAbsorb = codeGen.DefineLabel();
var end = codeGen.DefineLabel();
var contextScopeField = context.RuntimeContext.ContextType.Fields.First(f =>
f.Name == XamlCustomizations.ContextNameScopeFieldName);
f.Name == XamlCompiler.ContextNameScopeFieldName);
var controlNameScopeField = controlType.Fields.First(f => f.Name == "NameScope");
var nameScopeType = context.Configuration.TypeSystem
.FindType("Robust.Client.UserInterface.XAML.NameScope");

View File

@@ -1,23 +1,33 @@
using System.Collections.Generic;
using System.Linq;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
using XamlX.TypeSystem;
namespace Robust.Xaml
namespace Robust.Build.Tasks
{
/// <summary>
/// Helpers taken from AvaloniaUI on GitHub.
/// </summary>
/// <remarks>
/// Helpers taken from:
/// - https://github.com/AvaloniaUI/Avalonia/blob/c85fa2b9977d251a31886c2534613b4730fbaeaf/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs
/// - https://github.com/AvaloniaUI/Avalonia/blob/c85fa2b9977d251a31886c2534613b4730fbaeaf/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.Helpers.cs
/// </remarks>
internal partial class XamlAotCompiler
/// </summary>
public partial class XamlCompiler
{
private static readonly string[] NameSuffixes = {".xaml", ".paml", ".axaml"};
static bool CheckXamlName(IResource r) => r.Name.ToLowerInvariant().EndsWith(".xaml")
|| r.Name.ToLowerInvariant().EndsWith(".paml")
|| r.Name.ToLowerInvariant().EndsWith(".axaml");
static bool CheckXamlName(IResource r) =>
NameSuffixes.Any(suffix => r.Name.ToLowerInvariant().EndsWith(suffix));
private static bool MatchThisCall(Collection<Instruction> instructions, int idx)
{
var i = instructions[idx];
// A "normal" way of passing `this` to a static method:
// ldarg.0
// call void [Avalonia.Markup.Xaml]Avalonia.Markup.Xaml.AvaloniaXamlLoader::Load(object)
return i.OpCode == OpCodes.Ldarg_0 || (i.OpCode == OpCodes.Ldarg && i.Operand?.Equals(0) == true);
}
interface IResource : IFileSource
{

View File

@@ -0,0 +1,389 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Build.Framework;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
using Pidgin;
using XamlX;
using XamlX.Ast;
using XamlX.Emit;
using XamlX.IL;
using XamlX.Parsers;
using XamlX.Transform;
using XamlX.TypeSystem;
namespace Robust.Build.Tasks
{
/// <summary>
/// Based on https://github.com/AvaloniaUI/Avalonia/blob/c85fa2b9977d251a31886c2534613b4730fbaeaf/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs
/// Adjusted for our UI-Framework
/// </summary>
public partial class XamlCompiler
{
public static (bool success, bool writtentofile) Compile(IBuildEngine engine, string input, string[] references,
string projectDirectory, string output, string strongNameKey)
{
var typeSystem = new CecilTypeSystem(references
.Where(r => !r.ToLowerInvariant().EndsWith("robust.build.tasks.dll"))
.Concat(new[] { input }), input);
var asm = typeSystem.TargetAssemblyDefinition;
if (asm.MainModule.GetType("CompiledRobustXaml", "XamlIlContext") != null)
{
// If this type exists, the assembly has already been processed by us.
// Do not run again, it would corrupt the file.
// This *shouldn't* be possible due to Inputs/Outputs dependencies in the build system,
// but better safe than sorry eh?
engine.LogWarningEvent(new BuildWarningEventArgs("XAMLIL", "", "", 0, 0, 0, 0, "Ran twice on same assembly file; ignoring.", "", ""));
return (true, false);
}
var compileRes = CompileCore(engine, typeSystem);
if (compileRes == null)
return (true, false);
if (compileRes == false)
return (false, false);
var writerParameters = new WriterParameters { WriteSymbols = asm.MainModule.HasSymbols };
if (!string.IsNullOrWhiteSpace(strongNameKey))
writerParameters.StrongNameKeyBlob = File.ReadAllBytes(strongNameKey);
asm.Write(output, writerParameters);
return (true, true);
}
static bool? CompileCore(IBuildEngine engine, CecilTypeSystem typeSystem)
{
var asm = typeSystem.TargetAssemblyDefinition;
var embrsc = new EmbeddedResources(asm);
if (embrsc.Resources.Count(CheckXamlName) == 0)
// Nothing to do
return null;
var xamlLanguage = new XamlLanguageTypeMappings(typeSystem)
{
XmlnsAttributes =
{
typeSystem.GetType("Avalonia.Metadata.XmlnsDefinitionAttribute"),
},
ContentAttributes =
{
typeSystem.GetType("Avalonia.Metadata.ContentAttribute")
},
UsableDuringInitializationAttributes =
{
typeSystem.GetType("Robust.Client.UserInterface.XAML.UsableDuringInitializationAttribute")
},
DeferredContentPropertyAttributes =
{
typeSystem.GetType("Robust.Client.UserInterface.XAML.DeferredContentAttribute")
},
RootObjectProvider = typeSystem.GetType("Robust.Client.UserInterface.XAML.ITestRootObjectProvider"),
UriContextProvider = typeSystem.GetType("Robust.Client.UserInterface.XAML.ITestUriContext"),
ProvideValueTarget = typeSystem.GetType("Robust.Client.UserInterface.XAML.ITestProvideValueTarget"),
};
var emitConfig = new XamlLanguageEmitMappings<IXamlILEmitter, XamlILNodeEmitResult>
{
ContextTypeBuilderCallback = (b,c) => EmitNameScopeField(xamlLanguage, typeSystem, b, c)
};
var transformerconfig = new TransformerConfiguration(
typeSystem,
typeSystem.TargetAssembly,
xamlLanguage,
XamlXmlnsMappings.Resolve(typeSystem, xamlLanguage), CustomValueConverter);
var contextDef = new TypeDefinition("CompiledRobustXaml", "XamlIlContext",
TypeAttributes.Class, asm.MainModule.TypeSystem.Object);
asm.MainModule.Types.Add(contextDef);
var contextClass = XamlILContextDefinition.GenerateContextClass(typeSystem.CreateTypeBuilder(contextDef), typeSystem,
xamlLanguage, emitConfig);
var compiler =
new RobustXamlILCompiler(transformerconfig, emitConfig, true);
bool CompileGroup(IResourceGroup group)
{
var typeDef = new TypeDefinition("CompiledRobustXaml", "!" + group.Name, TypeAttributes.Class,
asm.MainModule.TypeSystem.Object);
//typeDef.CustomAttributes.Add(new CustomAttribute(ed));
asm.MainModule.Types.Add(typeDef);
var builder = typeSystem.CreateTypeBuilder(typeDef);
foreach (var res in group.Resources.Where(CheckXamlName))
{
try
{
engine.LogMessage($"XAMLIL: {res.Name} -> {res.Uri}", MessageImportance.Low);
var xaml = new StreamReader(new MemoryStream(res.FileContents)).ReadToEnd();
var parsed = XDocumentXamlParser.Parse(xaml);
var initialRoot = (XamlAstObjectNode) parsed.Root;
var classDirective = initialRoot.Children.OfType<XamlAstXmlDirective>()
.FirstOrDefault(d => d.Namespace == XamlNamespaces.Xaml2006 && d.Name == "Class");
string classname;
if (classDirective != null && classDirective.Values[0] is XamlAstTextNode tn)
{
classname = tn.Text;
}
else
{
classname = res.Name.Replace(".xaml","");
}
var classType = typeSystem.TargetAssembly.FindType(classname);
if (classType == null)
throw new Exception($"Unable to find type '{classname}'");
compiler.Transform(parsed);
var populateName = $"Populate:{res.Name}";
var buildName = $"Build:{res.Name}";
var classTypeDefinition = typeSystem.GetTypeReference(classType).Resolve();
var populateBuilder = typeSystem.CreateTypeBuilder(classTypeDefinition);
compiler.Compile(parsed, contextClass,
compiler.DefinePopulateMethod(populateBuilder, parsed, populateName,
classTypeDefinition == null),
compiler.DefineBuildMethod(builder, parsed, buildName, true),
null,
(closureName, closureBaseType) =>
populateBuilder.DefineSubType(closureBaseType, closureName, false),
res.Uri, res
);
//add compiled populate method
var compiledPopulateMethod = typeSystem.GetTypeReference(populateBuilder).Resolve().Methods
.First(m => m.Name == populateName);
const string TrampolineName = "!XamlIlPopulateTrampoline";
var trampoline = new MethodDefinition(TrampolineName,
MethodAttributes.Static | MethodAttributes.Private, asm.MainModule.TypeSystem.Void);
trampoline.Parameters.Add(new ParameterDefinition(classTypeDefinition));
classTypeDefinition.Methods.Add(trampoline);
trampoline.Body.Instructions.Add(Instruction.Create(OpCodes.Ldnull));
trampoline.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
trampoline.Body.Instructions.Add(Instruction.Create(OpCodes.Call, compiledPopulateMethod));
trampoline.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
var foundXamlLoader = false;
// Find RobustXamlLoader.Load(this) and replace it with !XamlIlPopulateTrampoline(this)
foreach (var method in classTypeDefinition.Methods
.Where(m => !m.Attributes.HasFlag(MethodAttributes.Static)))
{
var i = method.Body.Instructions;
for (var c = 1; c < i.Count; c++)
{
if (i[c].OpCode == OpCodes.Call)
{
var op = i[c].Operand as MethodReference;
if (op != null
&& op.Name == TrampolineName)
{
foundXamlLoader = true;
break;
}
if (op != null
&& op.Name == "Load"
&& op.Parameters.Count == 1
&& op.Parameters[0].ParameterType.FullName == "System.Object"
&& op.DeclaringType.FullName == "Robust.Client.UserInterface.XAML.RobustXamlLoader")
{
if (MatchThisCall(i, c - 1))
{
i[c].Operand = trampoline;
foundXamlLoader = true;
}
}
}
}
}
if (!foundXamlLoader)
{
var ctors = classTypeDefinition.GetConstructors()
.Where(c => !c.IsStatic).ToList();
// We can inject xaml loader into default constructor
if (ctors.Count == 1 && ctors[0].Body.Instructions.Count(o=>o.OpCode != OpCodes.Nop) == 3)
{
var i = ctors[0].Body.Instructions;
var retIdx = i.IndexOf(i.Last(x => x.OpCode == OpCodes.Ret));
i.Insert(retIdx, Instruction.Create(OpCodes.Call, trampoline));
i.Insert(retIdx, Instruction.Create(OpCodes.Ldarg_0));
}
else
{
throw new InvalidProgramException(
$"No call to RobustXamlLoader.Load(this) call found anywhere in the type {classType.FullName} and type seems to have custom constructors.");
}
}
}
catch (Exception e)
{
engine.LogErrorEvent(new BuildErrorEventArgs("XAMLIL", "", res.FilePath, 0, 0, 0, 0,
$"{res.FilePath}: {e.Message}", "", "CompileRobustXaml"));
}
res.Remove();
}
return true;
}
if (embrsc.Resources.Count(CheckXamlName) != 0)
{
if (!CompileGroup(embrsc))
return false;
}
return true;
}
private static bool CustomValueConverter(
AstTransformationContext context,
IXamlAstValueNode node,
IXamlType type,
out IXamlAstValueNode result)
{
if (!(node is XamlAstTextNode textNode))
{
result = null;
return false;
}
var text = textNode.Text;
var types = context.GetRobustTypes();
if (type.Equals(types.Vector2))
{
var foo = MathParsing.Single2.Parse(text);
if (!foo.Success)
throw new XamlLoadException($"Unable to parse \"{text}\" as a Vector2", node);
var (x, y) = foo.Value;
result = new RXamlSingleVecLikeConstAstNode(
node,
types.Vector2, types.Vector2ConstructorFull,
types.Single, new[] {x, y});
return true;
}
if (type.Equals(types.Thickness))
{
var foo = MathParsing.Thickness.Parse(text);
if (!foo.Success)
throw new XamlLoadException($"Unable to parse \"{text}\" as a Thickness", node);
var val = foo.Value;
float[] full;
if (val.Length == 1)
{
var u = val[0];
full = new[] {u, u, u, u};
}
else if (val.Length == 2)
{
var h = val[0];
var v = val[1];
full = new[] {h, v, h, v};
}
else // 4
{
full = val;
}
result = new RXamlSingleVecLikeConstAstNode(
node,
types.Thickness, types.ThicknessConstructorFull,
types.Single, full);
return true;
}
if (type.Equals(types.Thickness))
{
var foo = MathParsing.Thickness.Parse(text);
if (!foo.Success)
throw new XamlLoadException($"Unable to parse \"{text}\" as a Thickness", node);
var val = foo.Value;
float[] full;
if (val.Length == 1)
{
var u = val[0];
full = new[] {u, u, u, u};
}
else if (val.Length == 2)
{
var h = val[0];
var v = val[1];
full = new[] {h, v, h, v};
}
else // 4
{
full = val;
}
result = new RXamlSingleVecLikeConstAstNode(
node,
types.Thickness, types.ThicknessConstructorFull,
types.Single, full);
return true;
}
if (type.Equals(types.Color))
{
// TODO: Interpret these colors at XAML compile time instead of at runtime.
result = new RXamlColorAstNode(node, types, text);
return true;
}
result = null;
return false;
}
public const string ContextNameScopeFieldName = "RobustNameScope";
private static void EmitNameScopeField(XamlLanguageTypeMappings xamlLanguage, CecilTypeSystem typeSystem, IXamlTypeBuilder<IXamlILEmitter> typeBuilder, IXamlILEmitter constructor)
{
var nameScopeType = typeSystem.FindType("Robust.Client.UserInterface.XAML.NameScope");
var field = typeBuilder.DefineField(nameScopeType,
ContextNameScopeFieldName, true, false);
constructor
.Ldarg_0()
.Newobj(nameScopeType.GetConstructor())
.Stfld(field);
}
}
interface IResource : IFileSource
{
string Uri { get; }
string Name { get; }
void Remove();
}
interface IResourceGroup
{
string Name { get; }
IEnumerable<IResource> Resources { get; }
}
}

View File

@@ -302,7 +302,7 @@ internal partial class AudioManager
}
/// <inheritdoc/>
IBufferedAudioSource? IAudioInternal.CreateBufferedAudioSource(int buffers, bool floatAudio)
IBufferedAudioSource? IAudioInternal.CreateBufferedAudioSource(int buffers, bool floatAudio=false)
{
var source = AL.GenSource();

View File

@@ -143,11 +143,12 @@ internal sealed partial class AudioManager : IAudioInternal
/// <summary>
/// Like _checkAlError but allows custom data to be passed in as relevant.
/// </summary>
internal void LogALError(ALErrorInterpolatedStringHandler message, [CallerMemberName] string callerMember = "", [CallerLineNumber] int callerLineNumber = -1)
internal void LogALError(string message, [CallerMemberName] string callerMember = "", [CallerLineNumber] int callerLineNumber = -1)
{
if (message.Error != ALError.NoError)
var error = AL.GetError();
if (error != ALError.NoError)
{
OpenALSawmill.Error("[{0}:{1}] AL error: {2}, {3}. Stacktrace is {4}", callerMember, callerLineNumber, message.Error, message.ToStringAndClear(), Environment.StackTrace);
OpenALSawmill.Error("[{0}:{1}] AL error: {2}, {3}. Stacktrace is {4}", callerMember, callerLineNumber, error, message, Environment.StackTrace);
}
}
@@ -169,32 +170,4 @@ internal sealed partial class AudioManager : IAudioInternal
BufferHandle = bufferHandle;
}
}
[InterpolatedStringHandler]
internal ref struct ALErrorInterpolatedStringHandler
{
private DefaultInterpolatedStringHandler _handler;
public ALError Error;
public ALErrorInterpolatedStringHandler(int literalLength, int formattedCount, out bool shouldAppend)
{
Error = AL.GetError();
if (Error == ALError.NoError)
{
shouldAppend = false;
_handler = default;
}
else
{
shouldAppend = true;
_handler = new DefaultInterpolatedStringHandler(literalLength, formattedCount);
}
}
public string ToStringAndClear() => _handler.ToStringAndClear();
public override string ToString() => _handler.ToString();
public void AppendLiteral(string value) => _handler.AppendLiteral(value);
public void AppendFormatted<T>(T value) => _handler.AppendFormatted(value);
public void AppendFormatted<T>(T value, string? format) => _handler.AppendFormatted(value, format);
}
}

View File

@@ -46,7 +46,7 @@ public sealed class AudioOverlay : Overlay
var screenHandle = args.ScreenHandle;
var output = new StringBuilder();
var listenerPos = _transform.GetMapCoordinates(_entManager.GetComponent<TransformComponent>(localPlayer.Value));
var listenerPos = _entManager.GetComponent<TransformComponent>(localPlayer.Value).MapPosition;
if (listenerPos.MapId != args.MapId)
return;

View File

@@ -37,6 +37,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
[Dependency] private readonly IReplayRecordingManager _replayRecording = default!;
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IParallelManager _parMan = default!;
[Dependency] private readonly IRuntimeLog _runtimeLog = default!;
[Dependency] private readonly IAudioInternal _audio = default!;
@@ -48,10 +49,9 @@ public sealed partial class AudioSystem : SharedAudioSystem
/// Per-tick cache of relevant streams.
/// </summary>
private readonly List<(EntityUid Entity, AudioComponent Component, TransformComponent Xform)> _streams = new();
private EntityUid? _listenerGrid;
private UpdateAudioJob _updateAudioJob;
private float _audioFrameTime;
private float _audioFrameTimeRemaining;
private EntityQuery<PhysicsComponent> _physicsQuery;
@@ -110,16 +110,9 @@ public sealed partial class AudioSystem : SharedAudioSystem
Subs.CVar(CfgManager, CVars.AudioAttenuation, OnAudioAttenuation, true);
Subs.CVar(CfgManager, CVars.AudioRaycastLength, OnRaycastLengthChanged, true);
Subs.CVar(CfgManager, CVars.AudioTickRate, OnAudioTickRate, true);
InitializeLimit();
}
private void OnAudioTickRate(int obj)
{
_audioFrameTime = 1f / obj;
_audioFrameTimeRemaining = MathF.Min(_audioFrameTimeRemaining, _audioFrameTime);
}
private void OnAudioState(EntityUid uid, AudioComponent component, ref AfterAutoHandleStateEvent args)
{
ApplyAudioParams(component.Params, component);
@@ -261,13 +254,6 @@ public sealed partial class AudioSystem : SharedAudioSystem
public override void FrameUpdate(float frameTime)
{
_audioFrameTimeRemaining -= frameTime;
if (_audioFrameTimeRemaining > 0f)
return;
// Clamp to 0 in case we have a really long frame.
_audioFrameTimeRemaining = MathF.Max(0f, _audioFrameTime + _audioFrameTimeRemaining);
var eye = _eyeManager.CurrentEye;
var localEntity = _playerManager.LocalEntity;
Vector2 listenerVelocity;
@@ -291,6 +277,9 @@ public sealed partial class AudioSystem : SharedAudioSystem
_streams.Add((uid, comp, xform));
}
_mapManager.TryFindGridAt(ourPos, out var gridUid, out _);
_listenerGrid = gridUid == EntityUid.Invalid ? null : gridUid;
try
{
_updateAudioJob.OurPosition = ourPos;
@@ -343,6 +332,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
Vector2 worldPos;
component.Volume = component.Params.Volume;
Vector2 delta;
// Handle grid audio differently by using grid position.
if ((component.Flags & AudioFlags.GridAudio) != 0x0)
@@ -356,7 +346,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
}
// Max distance check
var delta = worldPos - listener.Position;
delta = worldPos - listener.Position;
var distance = delta.Length();
// Out of range so just clip it for us.

View File

@@ -1,18 +1,24 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using OpenTK.Audio.OpenAL;
using OpenTK.Audio.OpenAL.Extensions.Creative.EFX;
using Robust.Client.Graphics;
using Robust.Shared.Audio.Sources;
using Robust.Shared.Maths;
namespace Robust.Client.Audio.Sources;
internal sealed class BufferedAudioSource : BaseAudioSource, IBufferedAudioSource
{
private int? SourceHandle = null;
private int[] BufferHandles;
private Dictionary<int, int> BufferMap = new();
private readonly AudioManager _master;
private bool _mono = true;
private bool _float = false;
private int FilterHandle;
public int SampleRate { get; set; } = 44100;
@@ -37,7 +43,7 @@ internal sealed class BufferedAudioSource : BaseAudioSource, IBufferedAudioSourc
get
{
_checkDisposed();
var state = AL.GetSourceState(SourceHandle);
var state = AL.GetSourceState(SourceHandle!.Value);
_master._checkAlError();
return state == ALSourceState.Playing;
}
@@ -47,7 +53,7 @@ internal sealed class BufferedAudioSource : BaseAudioSource, IBufferedAudioSourc
{
_checkDisposed();
// IDK why this stackallocs but gonna leave it for now.
AL.SourcePlay(stackalloc int[] {SourceHandle});
AL.SourcePlay(stackalloc int[] {SourceHandle!.Value});
_master._checkAlError();
}
else
@@ -55,7 +61,7 @@ internal sealed class BufferedAudioSource : BaseAudioSource, IBufferedAudioSourc
if (_isDisposed())
return;
AL.SourceStop(SourceHandle);
AL.SourceStop(SourceHandle!.Value);
_master._checkAlError();
}
}
@@ -68,13 +74,13 @@ internal sealed class BufferedAudioSource : BaseAudioSource, IBufferedAudioSourc
protected override void Dispose(bool disposing)
{
if (SourceHandle == -1)
if (SourceHandle == null)
return;
if (!_master.IsMainThread())
{
// We can't run this code inside another thread so tell Clyde to clear it up later.
_master.DeleteBufferedSourceOnMainThread(SourceHandle, FilterHandle);
_master.DeleteBufferedSourceOnMainThread(SourceHandle.Value, FilterHandle);
foreach (var handle in BufferHandles)
{
@@ -86,21 +92,21 @@ internal sealed class BufferedAudioSource : BaseAudioSource, IBufferedAudioSourc
if (FilterHandle != 0)
EFX.DeleteFilter(FilterHandle);
AL.DeleteSource(SourceHandle);
AL.DeleteSource(SourceHandle.Value);
AL.DeleteBuffers(BufferHandles);
_master.RemoveBufferedAudioSource(SourceHandle);
_master.RemoveBufferedAudioSource(SourceHandle.Value);
_master._checkAlError();
}
FilterHandle = 0;
SourceHandle = -1;
SourceHandle = null;
}
public int GetNumberOfBuffersProcessed()
{
_checkDisposed();
// ReSharper disable once PossibleInvalidOperationException
AL.GetSource(SourceHandle, ALGetSourcei.BuffersProcessed, out var buffersProcessed);
AL.GetSource(SourceHandle!.Value, ALGetSourcei.BuffersProcessed, out var buffersProcessed);
return buffersProcessed;
}
@@ -110,7 +116,7 @@ internal sealed class BufferedAudioSource : BaseAudioSource, IBufferedAudioSourc
var entries = Math.Min(Math.Min(handles.Length, BufferHandles.Length), GetNumberOfBuffersProcessed());
fixed (int* ptr = handles)
{
AL.SourceUnqueueBuffers(SourceHandle, entries, ptr);
AL.SourceUnqueueBuffers(SourceHandle!.Value, entries, ptr);
}
for (var i = 0; i < entries; i++)
@@ -177,7 +183,7 @@ internal sealed class BufferedAudioSource : BaseAudioSource, IBufferedAudioSourc
fixed (int* ptr = realHandles)
// ReSharper disable once PossibleInvalidOperationException
{
AL.SourceQueueBuffers(SourceHandle, handles.Length, ptr);
AL.SourceQueueBuffers(SourceHandle!.Value, handles.Length, ptr);
}
}

View File

@@ -26,7 +26,6 @@ using Robust.Client.Upload;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.RichText;
using Robust.Client.UserInterface.Themes;
using Robust.Client.UserInterface.XAML.Proxy;
using Robust.Client.Utility;
using Robust.Client.ViewVariables;
using Robust.Shared;
@@ -147,16 +146,6 @@ namespace Robust.Client
deps.Register<IConfigurationManagerInternal, ClientNetConfigurationManager>();
deps.Register<IClientNetConfigurationManager, ClientNetConfigurationManager>();
deps.Register<INetConfigurationManagerInternal, ClientNetConfigurationManager>();
#if TOOLS
deps.Register<IXamlProxyManager, XamlProxyManager>();
deps.Register<IXamlHotReloadManager, XamlHotReloadManager>();
#else
deps.Register<IXamlProxyManager, XamlProxyManagerStub>();
deps.Register<IXamlHotReloadManager, XamlHotReloadManagerStub>();
#endif
deps.Register<IXamlProxyHelper, XamlProxyHelper>();
deps.Register<MarkupTagManager>();
}
}

View File

@@ -291,9 +291,9 @@ namespace Robust.Client.Console.Commands
}
}
internal sealed class SnapGridGetCell : LocalizedEntityCommands
internal sealed class SnapGridGetCell : LocalizedCommands
{
[Dependency] private readonly SharedMapSystem _map = default!;
[Dependency] private readonly IEntityManager _entManager = default!;
public override string Command => "sggcell";
@@ -319,10 +319,9 @@ namespace Robust.Client.Console.Commands
return;
}
var gridEnt = EntityManager.GetEntity(gridNet);
if (EntityManager.TryGetComponent<MapGridComponent>(gridEnt, out var grid))
if (_entManager.TryGetComponent<MapGridComponent>(_entManager.GetEntity(gridNet), out var grid))
{
foreach (var entity in _map.GetAnchoredEntities(gridEnt, grid, new Vector2i(
foreach (var entity in grid.GetAnchoredEntities(new Vector2i(
int.Parse(indices.Split(',')[0], CultureInfo.InvariantCulture),
int.Parse(indices.Split(',')[1], CultureInfo.InvariantCulture))))
{
@@ -426,9 +425,9 @@ namespace Robust.Client.Console.Commands
}
}
internal sealed class GridTileCount : LocalizedEntityCommands
internal sealed class GridTileCount : LocalizedCommands
{
[Dependency] private readonly SharedMapSystem _map = default!;
[Dependency] private readonly IEntityManager _entManager = default!;
public override string Command => "gridtc";
@@ -441,15 +440,15 @@ namespace Robust.Client.Console.Commands
}
if (!NetEntity.TryParse(args[0], out var gridUidNet) ||
!EntityManager.TryGetEntity(gridUidNet, out var gridUid))
!_entManager.TryGetEntity(gridUidNet, out var gridUid))
{
shell.WriteLine($"{args[0]} is not a valid entity UID.");
return;
}
if (EntityManager.TryGetComponent<MapGridComponent>(gridUid, out var grid))
if (_entManager.TryGetComponent<MapGridComponent>(gridUid, out var grid))
{
shell.WriteLine(_map.GetAllTiles(gridUid.Value, grid).Count().ToString());
shell.WriteLine(grid.GetAllTiles().Count().ToString());
}
else
{
@@ -579,20 +578,7 @@ namespace Robust.Client.Console.Commands
private static string GetMemberValue(MemberInfo? member, Control control, string separator, string
wrap = "{0}")
{
object? value = null;
try
{
value = member?.GetValue(control);
}
catch (TargetInvocationException exception)
{
var exceptionToPrint = exception.InnerException ?? exception;
value = $"{exceptionToPrint.GetType()}: {exceptionToPrint.Message}";
}
catch (Exception exception)
{
value = $"{exception.GetType()}: {exception.Message}";
}
var value = member?.GetValue(control);
var o = value switch
{
ICollection<Control> controls => string.Join(separator,
@@ -694,12 +680,12 @@ namespace Robust.Client.Console.Commands
}
}
internal sealed class ChunkInfoCommand : LocalizedEntityCommands
internal sealed class ChunkInfoCommand : LocalizedCommands
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IMapManager _map = default!;
[Dependency] private readonly IEyeManager _eye = default!;
[Dependency] private readonly IInputManager _input = default!;
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
public override string Command => "chunkinfo";
@@ -713,8 +699,8 @@ namespace Robust.Client.Console.Commands
return;
}
var mapSystem = EntityManager.System<SharedMapSystem>();
var chunkIndex = mapSystem.LocalToChunkIndices(gridUid, grid, _mapSystem.MapToGrid(gridUid, mousePos));
var mapSystem = _entManager.System<SharedMapSystem>();
var chunkIndex = mapSystem.LocalToChunkIndices(gridUid, grid, grid.MapToGrid(mousePos));
var chunk = mapSystem.GetOrAddChunk(gridUid, grid, chunkIndex);
shell.WriteLine($"worldBounds: {mapSystem.CalcWorldAABB(gridUid, grid, chunk)} localBounds: {chunk.CachedBounds}");

View File

@@ -1,19 +1,16 @@
using Robust.Client.GameObjects;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Robust.Client.Console.Commands
{
public sealed class GridChunkBBCommand : LocalizedEntityCommands
public sealed class GridChunkBBCommand : LocalizedCommands
{
[Dependency] private readonly GridChunkBoundsDebugSystem _system = default!;
public override string Command => "showchunkbb";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
_system.Enabled ^= true;
EntitySystem.Get<GridChunkBoundsDebugSystem>().Enabled ^= true;
}
}
}

View File

@@ -204,7 +204,7 @@ Suspendisse hendrerit blandit urna ut laoreet. Suspendisse ac elit at erat males
private Control TabRichText()
{
var label = new RichTextLabel();
label.SetMessage(FormattedMessage.FromMarkupOrThrow(Lipsum));
label.SetMessage(FormattedMessage.FromMarkup(Lipsum));
TabContainer.SetTabTitle(label, "RichText");
return label;

View File

@@ -1,5 +1,4 @@
using System.Numerics;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
@@ -15,8 +14,6 @@ namespace Robust.Client.Debugging
{
[Dependency] private readonly IOverlayManager _overlayManager = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly TransformSystem _transform = default!;
private bool _debugPositions;
private bool _debugRotations;
@@ -38,7 +35,7 @@ namespace Robust.Client.Debugging
if (value && !_overlayManager.HasOverlay<EntityPositionOverlay>())
{
_overlayManager.AddOverlay(new EntityPositionOverlay(_lookup, EntityManager, _transform));
_overlayManager.AddOverlay(new EntityPositionOverlay(_lookup, EntityManager));
}
else
{
@@ -77,15 +74,13 @@ namespace Robust.Client.Debugging
{
private readonly EntityLookupSystem _lookup;
private readonly IEntityManager _entityManager;
private readonly SharedTransformSystem _transform;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
public EntityPositionOverlay(EntityLookupSystem lookup, IEntityManager entityManager, SharedTransformSystem transform)
public EntityPositionOverlay(EntityLookupSystem lookup, IEntityManager entityManager)
{
_lookup = lookup;
_entityManager = entityManager;
_transform = transform;
}
protected internal override void Draw(in OverlayDrawArgs args)
@@ -93,10 +88,11 @@ namespace Robust.Client.Debugging
const float stubLength = 0.25f;
var worldHandle = (DrawingHandleWorld) args.DrawingHandle;
var xformQuery = _entityManager.GetEntityQuery<TransformComponent>();
foreach (var entity in _lookup.GetEntitiesIntersecting(args.MapId, args.WorldBounds))
{
var (center, worldRotation) = _transform.GetWorldPositionRotation(entity);
var (center, worldRotation) = xformQuery.GetComponent(entity).GetWorldPositionRotation();
var xLine = worldRotation.RotateVec(Vector2.UnitX);
var yLine = worldRotation.RotateVec(Vector2.UnitY);

View File

@@ -47,7 +47,6 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
@@ -79,14 +78,6 @@ namespace Robust.Client.Debugging
internal int PointCount;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly EntityLookupSystem _entityLookup = default!;
[Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly IOverlayManager _overlay = default!;
[Dependency] private readonly IEyeManager _eye = default!;
[Dependency] private readonly IInputManager _input = default!;
[Dependency] private readonly IMapManager _map = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
internal ContactPoint[] Points = new ContactPoint[MaxContactPoints];
@@ -98,21 +89,20 @@ namespace Robust.Client.Debugging
if (value == _flags) return;
if (_flags == PhysicsDebugFlags.None)
_overlay.AddOverlay(
IoCManager.Resolve<IOverlayManager>().AddOverlay(
new PhysicsDebugOverlay(
EntityManager,
_eye,
_input,
_map,
_player,
_resourceCache,
IoCManager.Resolve<IEyeManager>(),
IoCManager.Resolve<IInputManager>(),
IoCManager.Resolve<IMapManager>(),
IoCManager.Resolve<IPlayerManager>(),
IoCManager.Resolve<IResourceCache>(),
this,
_entityLookup,
_physics,
_transform));
Get<EntityLookupSystem>(),
Get<SharedPhysicsSystem>()));
if (value == PhysicsDebugFlags.None)
_overlay.RemoveOverlay(typeof(PhysicsDebugOverlay));
IoCManager.Resolve<IOverlayManager>().RemoveOverlay(typeof(PhysicsDebugOverlay));
_flags = value;
}
@@ -208,7 +198,6 @@ namespace Robust.Client.Debugging
private readonly DebugPhysicsSystem _debugPhysicsSystem;
private readonly EntityLookupSystem _lookup;
private readonly SharedPhysicsSystem _physicsSystem;
private readonly SharedTransformSystem _transformSystem;
public override OverlaySpace Space => OverlaySpace.WorldSpace | OverlaySpace.ScreenSpace;
@@ -219,7 +208,7 @@ namespace Robust.Client.Debugging
private HashSet<Joint> _drawnJoints = new();
private List<Entity<MapGridComponent>> _grids = new();
public PhysicsDebugOverlay(IEntityManager entityManager, IEyeManager eyeManager, IInputManager inputManager, IMapManager mapManager, IPlayerManager playerManager, IResourceCache cache, DebugPhysicsSystem system, EntityLookupSystem lookup, SharedPhysicsSystem physicsSystem, SharedTransformSystem transformSystem)
public PhysicsDebugOverlay(IEntityManager entityManager, IEyeManager eyeManager, IInputManager inputManager, IMapManager mapManager, IPlayerManager playerManager, IResourceCache cache, DebugPhysicsSystem system, EntityLookupSystem lookup, SharedPhysicsSystem physicsSystem)
{
_entityManager = entityManager;
_eyeManager = eyeManager;
@@ -229,7 +218,6 @@ namespace Robust.Client.Debugging
_debugPhysicsSystem = system;
_lookup = lookup;
_physicsSystem = physicsSystem;
_transformSystem = transformSystem;
_font = new VectorFont(cache.GetResource<FontResource>("/EngineFonts/NotoSans/NotoSans-Regular.ttf"), 10);
}
@@ -339,7 +327,7 @@ namespace Robust.Client.Debugging
{
if (jointComponent.JointCount == 0 ||
!_entityManager.TryGetComponent(uid, out TransformComponent? xf1) ||
!viewAABB.Contains(_transformSystem.GetWorldPosition(xf1))) continue;
!viewAABB.Contains(xf1.WorldPosition)) continue;
foreach (var (_, joint) in jointComponent.Joints)
{
@@ -529,8 +517,8 @@ namespace Robust.Client.Debugging
if (!_entityManager.TryGetComponent(joint.BodyAUid, out TransformComponent? xform1) ||
!_entityManager.TryGetComponent(joint.BodyBUid, out TransformComponent? xform2)) return;
var matrix1 = _transformSystem.GetWorldMatrix(xform1);
var matrix2 = _transformSystem.GetWorldMatrix(xform2);
var matrix1 = xform1.WorldMatrix;
var matrix2 = xform2.WorldMatrix;
var xf1 = new Vector2(matrix1.M31, matrix1.M32);
var xf2 = new Vector2(matrix2.M31, matrix2.M32);
@@ -538,8 +526,8 @@ namespace Robust.Client.Debugging
var p1 = Vector2.Transform(joint.LocalAnchorA, matrix1);
var p2 = Vector2.Transform(joint.LocalAnchorB, matrix2);
var xfa = new Transform(xf1, _transformSystem.GetWorldRotation(xform1));
var xfb = new Transform(xf2, _transformSystem.GetWorldRotation(xform2));
var xfa = new Transform(xf1, xform1.WorldRotation);
var xfb = new Transform(xf2, xform2.WorldRotation);
switch (joint)
{

View File

@@ -19,7 +19,6 @@ using Robust.Client.State;
using Robust.Client.Upload;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.RichText;
using Robust.Client.UserInterface.XAML.Proxy;
using Robust.Client.Utility;
using Robust.Client.ViewVariables;
using Robust.Client.WebViewHook;
@@ -54,8 +53,6 @@ namespace Robust.Client
[Dependency] private readonly IResourceCacheInternal _resourceCache = default!;
[Dependency] private readonly IResourceManagerInternal _resManager = default!;
[Dependency] private readonly IRobustSerializer _serializer = default!;
[Dependency] private readonly IXamlProxyManager _xamlProxyManager = default!;
[Dependency] private readonly IXamlHotReloadManager _xamlHotReloadManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IClientNetManager _networkManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
@@ -174,8 +171,6 @@ namespace Robust.Client
_reflectionManager.Initialize();
_prototypeManager.Initialize();
_prototypeManager.LoadDefaultPrototypes();
_xamlProxyManager.Initialize();
_xamlHotReloadManager.Initialize();
_userInterfaceManager.Initialize();
_eyeManager.Initialize();
_entityManager.Initialize();

View File

@@ -26,9 +26,6 @@ namespace Robust.Client.GameObjects
[Dependency] private readonly IBaseClient _client = default!;
[Dependency] private readonly IReplayRecordingManager _replayRecording = default!;
internal event Action? AfterStartup;
internal event Action? AfterShutdown;
public override void Initialize()
{
SetupNetworking();
@@ -37,20 +34,6 @@ namespace Robust.Client.GameObjects
base.Initialize();
}
public override void Startup()
{
base.Startup();
AfterStartup?.Invoke();
}
public override void Shutdown()
{
base.Shutdown();
AfterShutdown?.Invoke();
}
public override void FlushEntities()
{
// Server doesn't network deletions on client shutdown so we need to
@@ -65,6 +48,16 @@ namespace Robust.Client.GameObjects
return base.CreateEntity(prototypeName, out metadata);
}
void IClientEntityManagerInternal.InitializeEntity(EntityUid entity, MetaDataComponent? meta)
{
base.InitializeEntity(entity, meta);
}
void IClientEntityManagerInternal.StartEntity(EntityUid entity)
{
base.StartEntity(entity);
}
/// <inheritdoc />
public override void DirtyEntity(EntityUid uid, MetaDataComponent? meta = null)
{
@@ -135,10 +128,7 @@ namespace Robust.Client.GameObjects
var sequence = _stateMan.SystemMessageDispatched(msg);
EntityNetManager?.SendSystemNetworkMessage(msg, sequence);
if (!_stateMan.IsPredictionEnabled && _client.RunLevel != ClientRunLevel.SinglePlayerGame)
return;
DebugTools.Assert(_gameTiming.InPrediction && _gameTiming.IsFirstTimePredicted || _client.RunLevel == ClientRunLevel.SinglePlayerGame);
DebugTools.Assert(!_stateMan.IsPredictionEnabled || _gameTiming.InPrediction && _gameTiming.IsFirstTimePredicted || _client.RunLevel != ClientRunLevel.Connected);
var eventArgs = new EntitySessionEventArgs(session!);
EventBus.RaiseEvent(EventSource.Local, msg);

View File

@@ -76,8 +76,7 @@ namespace Robust.Client.GameObjects
foreach (var key in remie)
{
component.PlayingAnimations.Remove(key);
var completedEvent = new AnimationCompletedEvent {Uid = uid, Key = key, Finished = true};
EntityManager.EventBus.RaiseLocalEvent(uid, completedEvent, true);
EntityManager.EventBus.RaiseLocalEvent(uid, new AnimationCompletedEvent {Uid = uid, Key = key}, true);
}
return false;
@@ -188,8 +187,7 @@ namespace Robust.Client.GameObjects
return;
}
var completedEvent = new AnimationCompletedEvent {Uid = entity.Owner, Key = key, Finished = false};
EntityManager.EventBus.RaiseLocalEvent(entity.Owner, completedEvent, true);
EntityManager.EventBus.RaiseLocalEvent(entity.Owner, new AnimationCompletedEvent {Uid = entity.Owner, Key = key}, true);
}
public void Stop(EntityUid uid, AnimationPlayerComponent? component, string key)
@@ -205,11 +203,5 @@ namespace Robust.Client.GameObjects
{
public EntityUid Uid { get; init; }
public string Key { get; init; } = string.Empty;
/// <summary>
/// If true, the animation finished by getting to its natural end.
/// If false, it was removed prematurely via <see cref="AnimationPlayerSystem.Stop(Robust.Client.GameObjects.AnimationPlayerComponent,string)"/> or similar overloads.
/// </summary>
public bool Finished { get; init; }
}
}

View File

@@ -2,11 +2,8 @@ using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
using Robust.Shared.GameStates;
using Robust.Shared.Utility;
using Robust.Shared.Serialization.Manager;
namespace Robust.Client.GameObjects
{
@@ -14,7 +11,6 @@ namespace Robust.Client.GameObjects
public sealed class AppearanceSystem : SharedAppearanceSystem
{
private readonly Queue<(EntityUid uid, AppearanceComponent)> _queuedUpdates = new();
[Dependency] private readonly ISerializationManager _serialization = default!;
public override void Initialize()
{
@@ -78,13 +74,10 @@ namespace Robust.Client.GameObjects
foreach (var (key, value) in data)
{
object? serializationObject;
if (value.GetType().IsValueType)
newDict[key] = value;
else if (value is ICloneable cloneable)
newDict[key] = cloneable.Clone();
else if ((serializationObject = _serialization.CreateCopy(value)) != null)
newDict[key] = serializationObject;
else
throw new NotSupportedException("Invalid object in appearance data dictionary. Appearance data must be cloneable");
}

View File

@@ -6,7 +6,6 @@ using Robust.Shared.Maths;
using Robust.Shared.Utility;
using System;
using System.Collections.Generic;
using Robust.Shared.IoC;
using static Robust.Shared.GameObjects.OccluderComponent;
namespace Robust.Client.GameObjects;
@@ -21,7 +20,6 @@ namespace Robust.Client.GameObjects;
internal sealed class ClientOccluderSystem : OccluderSystem
{
private readonly HashSet<EntityUid> _dirtyEntities = new();
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
/// <inheritdoc />
public override void Initialize()
@@ -104,8 +102,7 @@ internal sealed class ClientOccluderSystem : OccluderSystem
if (occluder.Enabled && xform.Anchored && TryComp(xform.GridUid, out grid))
{
gridId = xform.GridUid.Value;
pos = _mapSystem.TileIndicesFor(gridId, grid, xform.Coordinates);
pos = grid.TileIndicesFor(xform.Coordinates);
_dirtyEntities.Add(sender);
}
else if (occluder.LastPosition != null)
@@ -120,10 +117,10 @@ internal sealed class ClientOccluderSystem : OccluderSystem
return;
}
DirtyNeighbours(_mapSystem.GetAnchoredEntitiesEnumerator(gridId, grid, pos + new Vector2i(0, 1)), query);
DirtyNeighbours(_mapSystem.GetAnchoredEntitiesEnumerator(gridId, grid, pos + new Vector2i(0, -1)), query);
DirtyNeighbours(_mapSystem.GetAnchoredEntitiesEnumerator(gridId, grid, pos + new Vector2i(1, 0)), query);
DirtyNeighbours(_mapSystem.GetAnchoredEntitiesEnumerator(gridId, grid, pos + new Vector2i(-1, 0)), query);
DirtyNeighbours(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(0, 1)), query);
DirtyNeighbours(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(0, -1)), query);
DirtyNeighbours(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(1, 0)), query);
DirtyNeighbours(grid.GetAnchoredEntitiesEnumerator(pos + new Vector2i(-1, 0)), query);
}
private void DirtyNeighbours(AnchoredEntitiesEnumerator enumerator, EntityQuery<OccluderComponent> occluderQuery)
@@ -169,7 +166,7 @@ internal sealed class ClientOccluderSystem : OccluderSystem
return;
}
var tile = _mapSystem.TileIndicesFor(xform.GridUid.Value, grid, xform.Coordinates);
var tile = grid.TileIndicesFor(xform.Coordinates);
// TODO: Sub to parent changes instead or something.
// DebugTools.Assert(occluder.LastPosition == null
@@ -178,16 +175,16 @@ internal sealed class ClientOccluderSystem : OccluderSystem
// dir starts at the relative effective south direction;
var dir = xform.LocalRotation.GetCardinalDir();
CheckDir(dir, OccluderDir.South, tile, occluder, xform.GridUid.Value, grid, occluders, xforms);
CheckDir(dir, OccluderDir.South, tile, occluder, grid, occluders, xforms);
dir = dir.GetClockwise90Degrees();
CheckDir(dir, OccluderDir.West, tile, occluder, xform.GridUid.Value, grid, occluders, xforms);
CheckDir(dir, OccluderDir.West, tile, occluder, grid, occluders, xforms);
dir = dir.GetClockwise90Degrees();
CheckDir(dir, OccluderDir.North, tile, occluder, xform.GridUid.Value, grid, occluders, xforms);
CheckDir(dir, OccluderDir.North, tile, occluder, grid, occluders, xforms);
dir = dir.GetClockwise90Degrees();
CheckDir(dir, OccluderDir.East, tile, occluder, xform.GridUid.Value, grid, occluders, xforms);
CheckDir(dir, OccluderDir.East, tile, occluder, grid, occluders, xforms);
}
private void CheckDir(
@@ -195,7 +192,6 @@ internal sealed class ClientOccluderSystem : OccluderSystem
OccluderDir occDir,
Vector2i tile,
OccluderComponent occluder,
EntityUid gridUid,
MapGridComponent grid,
EntityQuery<OccluderComponent> query,
EntityQuery<TransformComponent> xforms)
@@ -203,7 +199,7 @@ internal sealed class ClientOccluderSystem : OccluderSystem
if ((occluder.Occluding & occDir) != 0)
return;
foreach (var neighbor in _mapSystem.GetAnchoredEntities(gridUid, grid, tile.Offset(dir)))
foreach (var neighbor in grid.GetAnchoredEntities(tile.Offset(dir)))
{
if (!query.TryGetComponent(neighbor, out var otherOccluder) || !otherOccluder.Enabled)
continue;

View File

@@ -18,8 +18,6 @@ namespace Robust.Client.GameObjects
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IOverlayManager _overlayManager = default!;
[Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
private GridChunkBoundsOverlay? _overlay;
@@ -38,9 +36,7 @@ namespace Robust.Client.GameObjects
_overlay = new GridChunkBoundsOverlay(
EntityManager,
_eyeManager,
_mapManager,
_transform,
_map);
_mapManager);
_overlayManager.AddOverlay(_overlay);
}
@@ -60,20 +56,16 @@ namespace Robust.Client.GameObjects
private readonly IEntityManager _entityManager;
private readonly IEyeManager _eyeManager;
private readonly IMapManager _mapManager;
private readonly SharedTransformSystem _transformSystem;
private readonly SharedMapSystem _mapSystem;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
private List<Entity<MapGridComponent>> _grids = new();
public GridChunkBoundsOverlay(IEntityManager entManager, IEyeManager eyeManager, IMapManager mapManager, SharedTransformSystem transformSystem, SharedMapSystem mapSystem)
public GridChunkBoundsOverlay(IEntityManager entManager, IEyeManager eyeManager, IMapManager mapManager)
{
_entityManager = entManager;
_eyeManager = eyeManager;
_mapManager = mapManager;
_transformSystem = transformSystem;
_mapSystem = mapSystem;
}
protected internal override void Draw(in OverlayDrawArgs args)
@@ -82,23 +74,20 @@ namespace Robust.Client.GameObjects
var viewport = args.WorldBounds;
var worldHandle = args.WorldHandle;
var fixturesQuery = _entityManager.GetEntityQuery<FixturesComponent>();
_grids.Clear();
_mapManager.FindGridsIntersecting(currentMap, viewport, ref _grids);
foreach (var grid in _grids)
{
var worldMatrix = _transformSystem.GetWorldMatrix(grid);
var worldMatrix = _entityManager.GetComponent<TransformComponent>(grid).WorldMatrix;
worldHandle.SetTransform(worldMatrix);
var transform = new Transform(Vector2.Zero, Angle.Zero);
var fixtures = fixturesQuery.Comp(grid.Owner);
var chunkEnumerator = _mapSystem.GetMapChunks(grid.Owner, grid.Comp, viewport);
var chunkEnumerator = grid.Comp.GetMapChunks(viewport);
while (chunkEnumerator.MoveNext(out var chunk))
{
foreach (var id in chunk.Fixtures)
foreach (var fixture in chunk.Fixtures.Values)
{
var fixture = fixtures.Fixtures[id];
var poly = (PolygonShape) fixture.Shape;
var verts = new Vector2[poly.VertexCount];

View File

@@ -196,7 +196,7 @@ namespace Robust.Client.GameObjects
wOffset = new Vector2(wX, wY);
}
var coords = _transform.ToCoordinates(pent, _transform.GetMapCoordinates(pent).Offset(wOffset));
var coords = EntityCoordinates.FromMap(pent, _transform.GetMapCoordinates(pent).Offset(wOffset), _transform, EntityManager);
var funcId = _inputManager.NetworkBindMap.KeyFunctionID(keyFunction);
var message = new ClientFullInputCmdMessage(_timing.CurTick,

View File

@@ -1,43 +0,0 @@
using System.Numerics;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
namespace Robust.Client.GameObjects;
public sealed partial class SpriteSystem
{
/// <summary>
/// Gets an entity's sprite position in world terms.
/// </summary>
public Vector2 GetSpriteWorldPosition(Entity<SpriteComponent?, TransformComponent?> entity)
{
if (!Resolve(entity, ref entity.Comp2))
return Vector2.Zero;
var (worldPos, worldRot) = _xforms.GetWorldPositionRotation(entity.Owner);
if (!Resolve(entity, ref entity.Comp1, false))
{
return worldPos;
}
if (entity.Comp1.NoRotation)
{
return worldPos + entity.Comp1.Offset;
}
return worldPos + worldRot.RotateVec(entity.Comp1.Rotation.RotateVec(entity.Comp1.Offset));
}
/// <summary>
/// Gets an entity's sprite position in screen coordinates.
/// </summary>
public ScreenCoordinates GetSpriteScreenCoordinates(Entity<SpriteComponent?, TransformComponent?> entity)
{
if (!Resolve(entity, ref entity.Comp2))
return ScreenCoordinates.Invalid;
var spriteCoords = GetSpriteWorldPosition(entity);
return _eye.MapToScreen(new MapCoordinates(spriteCoords, entity.Comp2.MapID));
}
}

View File

@@ -30,12 +30,10 @@ namespace Robust.Client.GameObjects
public sealed partial class SpriteSystem : EntitySystem
{
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IEyeManager _eye = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly SharedTransformSystem _xforms = default!;
private readonly Queue<SpriteComponent> _inertUpdateQueue = new();
@@ -68,11 +66,6 @@ namespace Robust.Client.GameObjects
_sawmill = _logManager.GetSawmill("sprite");
}
public bool IsVisible(Layer layer)
{
return layer.Visible && layer.CopyToShaderParameters == null;
}
private void OnInit(EntityUid uid, SpriteComponent component, ComponentInit args)
{
// I'm not 100% this is needed, but I CBF with this ATM. Somebody kill server sprite component please.
@@ -191,8 +184,7 @@ namespace Robust.Client.GameObjects
/// <summary>
/// Gets the specified frame for this sprite at the specified time.
/// </summary>
/// <param name="loop">Should we clamp on the last frame and not loop</param>
public Texture GetFrame(SpriteSpecifier spriteSpec, TimeSpan curTime, bool loop = true)
public Texture GetFrame(SpriteSpecifier spriteSpec, TimeSpan curTime)
{
Texture? sprite = null;
@@ -204,29 +196,19 @@ namespace Robust.Client.GameObjects
var frames = state!.GetFrames(RsiDirection.South);
var delays = state.GetDelays();
var totalDelay = delays.Sum();
var time = curTime.TotalSeconds % totalDelay;
var delaySum = 0f;
// No looping
if (!loop && curTime.TotalSeconds >= totalDelay)
for (var i = 0; i < delays.Length; i++)
{
sprite = frames[^1];
}
// Loopable
else
{
var time = curTime.TotalSeconds % totalDelay;
var delaySum = 0f;
var delay = delays[i];
delaySum += delay;
for (var i = 0; i < delays.Length; i++)
{
var delay = delays[i];
delaySum += delay;
if (time > delaySum)
continue;
if (time > delaySum)
continue;
sprite = frames[i];
break;
}
sprite = frames[i];
break;
}
sprite ??= Frame0(spriteSpec);

View File

@@ -1,38 +1,8 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;
namespace Robust.Client.GameObjects;
public sealed class UserInterfaceSystem : SharedUserInterfaceSystem
{
public override void Initialize()
{
base.Initialize();
ProtoManager.PrototypesReloaded += OnProtoReload;
}
public override void Shutdown()
{
base.Shutdown();
ProtoManager.PrototypesReloaded -= OnProtoReload;
}
private void OnProtoReload(PrototypesReloadedEventArgs obj)
{
var player = Player.LocalEntity;
if (!UserQuery.TryComp(player, out var userComp))
return;
foreach (var uid in userComp.OpenInterfaces.Keys)
{
if (!UIQuery.TryComp(uid, out var uiComp))
continue;
foreach (var bui in uiComp.ClientOpenInterfaces.Values)
{
bui.OnProtoReload(obj);
}
}
}
}

View File

@@ -14,7 +14,6 @@ namespace Robust.Client.GameObjects
{
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly TransformSystem _transform = default!;
internal bool Enabled { get; set; }
@@ -44,7 +43,7 @@ namespace Robust.Client.GameObjects
return;
}
var screenPos = _eyeManager.WorldToScreen(_transform.GetWorldPosition(Transform(player.Value)));
var screenPos = _eyeManager.WorldToScreen(EntityManager.GetComponent<TransformComponent>(player.Value).WorldPosition);
LayoutContainer.SetPosition(_label, screenPos + new Vector2(0, 50));
_label.Visible = true;

View File

@@ -1,5 +0,0 @@
using Robust.Shared.GameObjects;
namespace Robust.Client.GameObjects;
public sealed class ViewSubscriberSystem : SharedViewSubscriberSystem;

View File

@@ -7,5 +7,9 @@ namespace Robust.Client.GameObjects
// These methods are used by the Game State Manager.
EntityUid CreateEntity(string? prototypeName, out MetaDataComponent metadata);
void InitializeEntity(EntityUid entity, MetaDataComponent? meta = null);
void StartEntity(EntityUid entity);
}
}

View File

@@ -960,7 +960,7 @@ namespace Robust.Client.GameStates
// Initialize and start the newly created entities.
if (_toCreate.Count > 0)
InitializeAndStart(_toCreate, metas, xforms);
InitializeAndStart(_toCreate);
_prof.WriteValue("State Size", ProfData.Int32(curSpan.Length));
_prof.WriteValue("Entered PVS", ProfData.Int32(enteringPvs));
@@ -1188,10 +1188,7 @@ namespace Robust.Client.GameStates
}
}
private void InitializeAndStart(
Dictionary<NetEntity, EntityState> toCreate,
EntityQuery<MetaDataComponent> metas,
EntityQuery<TransformComponent> xforms)
private void InitializeAndStart(Dictionary<NetEntity, EntityState> toCreate)
{
_toStart.Clear();
@@ -1200,8 +1197,22 @@ namespace Robust.Client.GameStates
EntityUid entity = default;
foreach (var netEntity in toCreate.Keys)
{
(entity, var meta) = _entityManager.GetEntityData(netEntity);
InitializeRecursive(entity, meta, metas, xforms);
try
{
(entity, var meta) = _entityManager.GetEntityData(netEntity);
_entities.InitializeEntity(entity, meta);
_toStart.Add((entity, netEntity));
}
catch (Exception e)
{
_sawmill.Error($"Server entity threw in Init: nent={netEntity}, ent={_entities.ToPrettyString(entity)}");
_runtimeLog.LogException(e, $"{nameof(ClientGameStateManager)}.{nameof(InitializeAndStart)}");
_toCreate.Remove(netEntity);
_brokenEnts.Add(entity);
#if !EXCEPTION_TOLERANCE
throw;
#endif
}
}
}
@@ -1233,44 +1244,6 @@ namespace Robust.Client.GameStates
_brokenEnts.Clear();
}
private void InitializeRecursive(
EntityUid entity,
MetaDataComponent meta,
EntityQuery<MetaDataComponent> metas,
EntityQuery<TransformComponent> xforms)
{
var xform = xforms.GetComponent(entity);
if (xform.ParentUid is {Valid: true} parent)
{
var parentMeta = metas.GetComponent(parent);
if (parentMeta.EntityLifeStage < EntityLifeStage.Initialized)
InitializeRecursive(parent, parentMeta, metas, xforms);
}
if (meta.EntityLifeStage >= EntityLifeStage.Initialized)
{
// Was probably already initialized because one of its children appeared earlier in the list.
DebugTools.AssertEqual(_toStart.Count(x => x.Item1 == entity), 1);
return;
}
try
{
_entities.InitializeEntity(entity, meta);
_toStart.Add((entity, meta.NetEntity));
}
catch (Exception e)
{
_sawmill.Error($"Server entity threw in Init: nent={meta.NetEntity}, ent={_entities.ToPrettyString(entity)}");
_runtimeLog.LogException(e, $"{nameof(ClientGameStateManager)}.{nameof(InitializeAndStart)}");
_toCreate.Remove(meta.NetEntity);
_brokenEnts.Add(entity);
#if !EXCEPTION_TOLERANCE
throw;
#endif
}
}
private void HandleEntityState(EntityUid uid, NetEntity netEntity, MetaDataComponent meta, IEventBus bus, EntityState? curState,
EntityState? nextState, GameTick lastApplied, GameTick toTick, bool enteringPvs)
{

View File

@@ -33,7 +33,7 @@ namespace Robust.Client.Graphics.Clyde
#if EXCEPTION_TOLERANCE_LOCAL
catch (Exception e)
{
_sawmillWin.Error($"Error dispatching window event {ev.GetType().Name}:\n{e}");
Logger.ErrorS("clyde.win", $"Error dispatching window event {ev.GetType().Name}:\n{e}");
}
#endif
}

View File

@@ -5,6 +5,7 @@ using OpenToolkit.Graphics.OpenGL4;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.Graphics;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Maths;
@@ -14,6 +15,8 @@ namespace Robust.Client.Graphics.Clyde
{
internal partial class Clyde
{
[Dependency] private readonly IEntityManager _entityManager = default!;
private readonly Dictionary<EntityUid, Dictionary<Vector2i, MapChunkData>> _mapChunkData =
new();
@@ -64,7 +67,7 @@ namespace Robust.Client.Graphics.Clyde
}
var transform = _entityManager.GetComponent<TransformComponent>(mapGrid);
gridProgram.SetUniform(UniIModelMatrix, _transformSystem.GetWorldMatrix(transform));
gridProgram.SetUniform(UniIModelMatrix, transform.WorldMatrix);
var enumerator = mapSystem.GetMapChunks(mapGrid.Owner, mapGrid.Comp, worldBounds);
while (enumerator.MoveNext(out var chunk))

View File

@@ -9,7 +9,6 @@ using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.Graphics;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
@@ -514,7 +513,7 @@ namespace Robust.Client.Graphics.Clyde
if (_lightManager.Enabled && _lightManager.DrawHardFov && eye.DrawLight && eye.DrawFov)
{
var mapUid = _mapSystem.GetMap(eye.Position.MapId);
var mapUid = _mapManager.GetMapEntityId(eye.Position.MapId);
if (_entityManager.GetComponent<MapComponent>(mapUid).LightingEnabled)
ApplyFovToBuffer(viewport, eye);
}

View File

@@ -203,7 +203,7 @@ namespace Robust.Client.Graphics.Clyde
return resource.ClydeHandle;
}
_clydeSawmill.Warning($"Can't load shader {path}\n");
Logger.Warning($"Can't load shader {path}\n");
return default;
}
@@ -345,12 +345,13 @@ namespace Robust.Client.Graphics.Clyde
return;
// If this map has lighting disabled, return
var mapUid = _mapSystem.GetMapOrInvalid(mapId);
var mapUid = _mapManager.GetMapEntityId(mapId);
if (!_entityManager.TryGetComponent<MapComponent>(mapUid, out var map) || !map.LightingEnabled)
{
return;
}
(PointLightComponent light, Vector2 pos, float distanceSquared, Angle rot)[] lights;
int count;
Box2 expandedBounds;
using (_prof.Group("LightsToRender"))
@@ -540,6 +541,7 @@ namespace Robust.Client.Graphics.Clyde
Clyde clyde,
int count,
int shadowCastingCount,
TransformSystem xformSystem,
EntityQuery<TransformComponent> xforms,
Box2 worldAABB) state,
in ComponentTreeEntry<PointLightComponent> value)
@@ -552,7 +554,7 @@ namespace Robust.Client.Graphics.Clyde
return false;
var (light, transform) = value;
var (lightPos, rot) = state.clyde._transformSystem.GetWorldPositionRotation(transform, state.xforms);
var (lightPos, rot) = state.xformSystem.GetWorldPositionRotation(transform, state.xforms);
lightPos += rot.RotateVec(light.Offset);
var circle = new Circle(lightPos, light.Radius);
@@ -598,13 +600,16 @@ namespace Robust.Client.Graphics.Clyde
in Box2Rotated worldBounds,
in Box2 worldAABB)
{
var lightTreeSys = _entitySystemManager.GetEntitySystem<LightTreeSystem>();
var xformSystem = _entitySystemManager.GetEntitySystem<TransformSystem>();
// Use worldbounds for this one as we only care if the light intersects our actual bounds
var xforms = _entityManager.GetEntityQuery<TransformComponent>();
var state = (this, count: 0, shadowCastingCount: 0, xforms, worldAABB);
var state = (this, count: 0, shadowCastingCount: 0, xformSystem, xforms, worldAABB);
foreach (var (uid, comp) in _lightTreeSystem.GetIntersectingTrees(map, worldAABB))
foreach (var (uid, comp) in lightTreeSys.GetIntersectingTrees(map, worldAABB))
{
var bounds = _transformSystem.GetInvWorldMatrix(uid, xforms).TransformBox(worldBounds);
var bounds = xformSystem.GetInvWorldMatrix(uid, xforms).TransformBox(worldBounds);
comp.Tree.QueryAabb(ref state, LightQuery, bounds);
}
@@ -936,16 +941,18 @@ namespace Robust.Client.Graphics.Clyde
var imi = 0;
var amiMax = _maxOccluders * 4;
var occluderSystem = _entitySystemManager.GetEntitySystem<OccluderSystem>();
var xformSystem = _entitySystemManager.GetEntitySystem<TransformSystem>();
var xforms = _entityManager.GetEntityQuery<TransformComponent>();
try
{
foreach (var (uid, comp) in _occluderSystem.GetIntersectingTrees(map, expandedBounds))
foreach (var (uid, comp) in occluderSystem.GetIntersectingTrees(map, expandedBounds))
{
if (ami >= amiMax)
break;
var treeBounds = _transformSystem.GetInvWorldMatrix(uid).TransformBox(expandedBounds);
var treeBounds = xforms.GetComponent(uid).InvWorldMatrix.TransformBox(expandedBounds);
comp.Tree.QueryAabb((in ComponentTreeEntry<OccluderComponent> entry) =>
{
@@ -958,7 +965,7 @@ namespace Robust.Client.Graphics.Clyde
if (ami >= amiMax)
return false;
var worldTransform = _transformSystem.GetWorldMatrix(transform, xforms);
var worldTransform = xformSystem.GetWorldMatrix(transform, xforms);
var box = occluder.BoundingBox;
var tl = Vector2.Transform(box.TopLeft, worldTransform);

View File

@@ -496,9 +496,6 @@ namespace Robust.Client.Graphics.Clyde
case bool b:
program.SetUniform(name, b ? 1 : 0);
break;
case bool[] bArr:
program.SetUniform(name, bArr);
break;
case Matrix3x2 matrix3:
program.SetUniform(name, matrix3);
break;

View File

@@ -506,14 +506,6 @@ namespace Robust.Client.Graphics.Clyde
data.Parameters[name] = value;
}
private protected override void SetParameterImpl(string name, bool[] value)
{
var data = Parent._shaderInstances[Handle];
data.ParametersDirty = true;
data.Parameters[name] = value;
}
private protected override void SetParameterImpl(string name, in Matrix3x2 value)
{
var data = Parent._shaderInstances[Handle];

View File

@@ -61,11 +61,12 @@ internal partial class Clyde
var index = 0;
var added = 0;
var opts = new ParallelOptions { MaxDegreeOfParallelism = _parMan.ParallelProcessCount };
var xformSystem = _entitySystemManager.GetEntitySystem<SharedTransformSystem>();
foreach (var (treeOwner, comp) in _spriteTreeSystem.GetIntersectingTrees(map, worldBounds))
foreach (var (treeOwner, comp) in _entitySystemManager.GetEntitySystem<SpriteTreeSystem>().GetIntersectingTrees(map, worldBounds))
{
var treeXform = query.GetComponent(treeOwner);
var bounds = _transformSystem.GetInvWorldMatrix(treeOwner).TransformBox(worldBounds);
var bounds = xformSystem.GetInvWorldMatrix(treeOwner).TransformBox(worldBounds);
DebugTools.Assert(treeXform.MapUid == treeXform.ParentUid || !treeXform.ParentUid.IsValid());
treeData = treeData with

View File

@@ -1,39 +0,0 @@
using Robust.Client.ComponentTrees;
using Robust.Client.GameObjects;
namespace Robust.Client.Graphics.Clyde;
internal sealed partial class Clyde
{
// Caches entity systems required by Clyde.
private MapSystem _mapSystem = default!;
private LightTreeSystem _lightTreeSystem = default!;
private TransformSystem _transformSystem = default!;
private SpriteTreeSystem _spriteTreeSystem = default!;
private ClientOccluderSystem _occluderSystem = default!;
private void InitSystems()
{
_entityManager.AfterStartup += EntityManagerOnAfterStartup;
_entityManager.AfterShutdown += EntityManagerOnAfterShutdown;
}
private void EntityManagerOnAfterStartup()
{
_mapSystem = _entitySystemManager.GetEntitySystem<MapSystem>();
_lightTreeSystem = _entitySystemManager.GetEntitySystem<LightTreeSystem>();
_transformSystem = _entitySystemManager.GetEntitySystem<TransformSystem>();
_spriteTreeSystem = _entitySystemManager.GetEntitySystem<SpriteTreeSystem>();
_occluderSystem = _entitySystemManager.GetEntitySystem<ClientOccluderSystem>();
}
private void EntityManagerOnAfterShutdown()
{
_mapSystem = null!;
_lightTreeSystem = null!;
_transformSystem = null!;
_spriteTreeSystem = null!;
_occluderSystem = null!;
}
}

View File

@@ -188,7 +188,7 @@ namespace Robust.Client.Graphics.Clyde
{
if (!TryInitMainWindow(glSpec, out lastError))
{
_sawmillWin.Debug($"OpenGL {glSpec.OpenGLVersion} unsupported: {lastError}");
Logger.DebugS("clyde.win", $"OpenGL {glSpec.OpenGLVersion} unsupported: {lastError}");
continue;
}
@@ -199,7 +199,7 @@ namespace Robust.Client.Graphics.Clyde
else
{
if (!TryInitMainWindow(null, out lastError))
_sawmillWin.Debug($"Failed to create window: {lastError}");
Logger.DebugS("clyde.win", $"Failed to create window: {lastError}");
else
succeeded = true;
}
@@ -230,7 +230,8 @@ namespace Robust.Client.Graphics.Clyde
}
}
_sawmillWin.Fatal("Failed to create main game window! " +
Logger.FatalS("clyde.win",
"Failed to create main game window! " +
"This probably means your GPU is too old to run the game. " +
$"That or update your graphics drivers. {lastError}");

View File

@@ -5,7 +5,6 @@ using System.Runtime.InteropServices;
using System.Threading;
using OpenToolkit;
using OpenToolkit.Graphics.OpenGL4;
using Robust.Client.GameObjects;
using Robust.Client.Input;
using Robust.Client.Map;
using Robust.Client.ResourceManagement;
@@ -47,7 +46,6 @@ namespace Robust.Client.Graphics.Clyde
[Dependency] private readonly IDependencyCollection _deps = default!;
[Dependency] private readonly ILocalizationManager _loc = default!;
[Dependency] private readonly IInputManager _inputManager = default!;
[Dependency] private readonly ClientEntityManager _entityManager = default!;
private GLUniformBuffer<ProjViewMatrices> ProjViewUBO = default!;
private GLUniformBuffer<UniformConstants> UniformConstantsUBO = default!;
@@ -80,7 +78,6 @@ namespace Robust.Client.Graphics.Clyde
private ISawmill _clydeSawmill = default!;
private ISawmill _sawmillOgl = default!;
private ISawmill _sawmillWin = default!;
private IBindingsContext _glBindingsContext = default!;
private bool _earlyGLInit;
@@ -97,7 +94,6 @@ namespace Robust.Client.Graphics.Clyde
{
_clydeSawmill = _logManager.GetSawmill("clyde");
_sawmillOgl = _logManager.GetSawmill("clyde.ogl");
_sawmillWin = _logManager.GetSawmill("clyde.win");
_cfg.OnValueChanged(CVars.DisplayOGLCheckErrors, b => _checkGLErrors = b, true);
_cfg.OnValueChanged(CVars.DisplayVSync, VSyncChanged, true);
@@ -126,8 +122,6 @@ namespace Robust.Client.Graphics.Clyde
{
_gameThread = Thread.CurrentThread;
InitSystems();
InitGLContextManager();
if (!InitMainWindowAndRenderer())
return false;

View File

@@ -361,10 +361,6 @@ namespace Robust.Client.Graphics.Clyde
{
}
private protected override void SetParameterImpl(string name, bool[] value)
{
}
private protected override void SetParameterImpl(string name, in Matrix3x2 value)
{
}

View File

@@ -37,8 +37,6 @@ namespace Robust.Client.Graphics.Clyde
// NOTE: This class only handles GLES3/D3D11.
// For anything lower we just let ANGLE fall back and do the work 100%.
private readonly ISawmill _sawmill;
private IDXGIFactory1* _factory;
private IDXGIAdapter1* _adapter;
private ID3D11Device* _device;
@@ -60,7 +58,6 @@ namespace Robust.Client.Graphics.Clyde
public GLContextAngle(Clyde clyde) : base(clyde)
{
_sawmill = clyde._logManager.GetSawmill("clyde.ogl.angle");
}
public override GLContextSpec? SpecWithOpenGLVersion(RendererOpenGLVersion version)
@@ -190,7 +187,7 @@ namespace Robust.Client.Graphics.Clyde
}
catch (Exception e)
{
_sawmill.Error($"Failed to initialize custom ANGLE: {e}");
Logger.ErrorS("clyde.ogl.angle", $"Failed to initialize custom ANGLE: {e}");
Shutdown();
return false;
}
@@ -210,7 +207,7 @@ namespace Robust.Client.Graphics.Clyde
private void TryInitializeCore()
{
var extensions = Marshal.PtrToStringUTF8((nint) eglQueryString(null, EGL_EXTENSIONS));
_sawmill.Debug($"EGL client extensions: {extensions}!");
Logger.DebugS("clyde.ogl.angle", $"EGL client extensions: {extensions}!");
CreateD3D11Device();
CreateEglContext();
@@ -235,10 +232,10 @@ namespace Robust.Client.Graphics.Clyde
var version = Marshal.PtrToStringUTF8((nint) eglQueryString(_eglDisplay, EGL_VERSION));
var extensions = Marshal.PtrToStringUTF8((nint) eglQueryString(_eglDisplay, EGL_EXTENSIONS));
_sawmill.Debug("EGL initialized!");
_sawmill.Debug($"EGL vendor: {vendor}!");
_sawmill.Debug($"EGL version: {version}!");
_sawmill.Debug($"EGL extensions: {extensions}!");
Logger.DebugS("clyde.ogl.angle", "EGL initialized!");
Logger.DebugS("clyde.ogl.angle", $"EGL vendor: {vendor}!");
Logger.DebugS("clyde.ogl.angle", $"EGL version: {version}!");
Logger.DebugS("clyde.ogl.angle", $"EGL extensions: {extensions}!");
if (eglBindAPI(EGL_OPENGL_ES_API) != EGL_TRUE)
throw new Exception("eglBindAPI failed.");
@@ -265,11 +262,11 @@ namespace Robust.Client.Graphics.Clyde
if (numConfigs == 0)
throw new Exception("No compatible EGL configurations returned!");
_sawmill.Debug($"{numConfigs} EGL configs possible!");
Logger.DebugS("clyde.ogl.angle", $"{numConfigs} EGL configs possible!");
for (var i = 0; i < numConfigs; i++)
{
_sawmill.Debug(DumpEglConfig(_eglDisplay, configs[i]));
Logger.DebugS("clyde.ogl.angle", DumpEglConfig(_eglDisplay, configs[i]));
}
_eglConfig = configs[0];
@@ -289,7 +286,7 @@ namespace Robust.Client.Graphics.Clyde
if (_eglContext == (void*) EGL_NO_CONTEXT)
throw new Exception("eglCreateContext failed!");
_sawmill.Debug("EGL context created!");
Logger.DebugS("clyde.ogl.angle", "EGL context created!");
Clyde._openGLVersion = _es3 ? RendererOpenGLVersion.GLES3 : RendererOpenGLVersion.GLES2;
}
@@ -314,10 +311,11 @@ namespace Robust.Client.Graphics.Clyde
if (_adapter == null)
{
_sawmill.Warning($"Unable to find display adapter with requested name: {adapterName}");
Logger.WarningS("clyde.ogl.angle",
$"Unable to find display adapter with requested name: {adapterName}");
}
_sawmill.Debug($"Found display adapter with name: {adapterName}");
Logger.DebugS("clyde.ogl.angle", $"Found display adapter with name: {adapterName}");
}
#pragma warning disable CA1416
@@ -417,9 +415,9 @@ namespace Robust.Client.Graphics.Clyde
var descName = ((ReadOnlySpan<char>)desc.Description).TrimEnd('\0');
_sawmill.Debug("Successfully created D3D11 device!");
_sawmill.Debug($"D3D11 Device Adapter: {descName.ToString()}");
_sawmill.Debug($"D3D11 Device FL: {_deviceFl}");
Logger.DebugS("clyde.ogl.angle", "Successfully created D3D11 device!");
Logger.DebugS("clyde.ogl.angle", $"D3D11 Device Adapter: {descName.ToString()}");
Logger.DebugS("clyde.ogl.angle", $"D3D11 Device FL: {_deviceFl}");
if (_deviceFl == D3D_FEATURE_LEVEL_9_1)
{

View File

@@ -22,8 +22,6 @@ namespace Robust.Client.Graphics.Clyde
private readonly Dictionary<WindowId, WindowData> _windowData = new();
private readonly ISawmill _sawmill;
private void* _eglDisplay;
private void* _eglContext;
private void* _eglConfig;
@@ -32,7 +30,6 @@ namespace Robust.Client.Graphics.Clyde
public GLContextEgl(Clyde clyde) : base(clyde)
{
_sawmill = clyde._logManager.GetSawmill("clyde.ogl.egl");
}
public override GLContextSpec? SpecWithOpenGLVersion(RendererOpenGLVersion version)
@@ -50,7 +47,7 @@ namespace Robust.Client.Graphics.Clyde
public void InitializePublic()
{
var extensions = Marshal.PtrToStringUTF8((nint) eglQueryString(null, EGL_EXTENSIONS));
_sawmill.Debug($"EGL client extensions: {extensions}!");
Logger.DebugS("clyde.ogl.egl", $"EGL client extensions: {extensions}!");
}
public override void WindowCreated(GLContextSpec? spec, WindowReg reg)
@@ -136,10 +133,10 @@ namespace Robust.Client.Graphics.Clyde
var version = Marshal.PtrToStringUTF8((nint) eglQueryString(_eglDisplay, EGL_VERSION));
var extensions = Marshal.PtrToStringUTF8((nint) eglQueryString(_eglDisplay, EGL_EXTENSIONS));
_sawmill.Debug("EGL initialized!");
_sawmill.Debug($"EGL vendor: {vendor}!");
_sawmill.Debug($"EGL version: {version}!");
_sawmill.Debug($"EGL extensions: {extensions}!");
Logger.DebugS("clyde.ogl.egl", "EGL initialized!");
Logger.DebugS("clyde.ogl.egl", $"EGL vendor: {vendor}!");
Logger.DebugS("clyde.ogl.egl", $"EGL version: {version}!");
Logger.DebugS("clyde.ogl.egl", $"EGL extensions: {extensions}!");
if (eglBindAPI(EGL_OPENGL_ES_API) != EGL_TRUE)
throw new Exception("eglBindAPI failed.");
@@ -167,11 +164,11 @@ namespace Robust.Client.Graphics.Clyde
if (numConfigs == 0)
throw new Exception("No compatible EGL configurations returned!");
_sawmill.Debug($"{numConfigs} EGL configs possible!");
Logger.DebugS("clyde.ogl.egl", $"{numConfigs} EGL configs possible!");
for (var i = 0; i < numConfigs; i++)
{
_sawmill.Debug(DumpEglConfig(_eglDisplay, configs[i]));
Logger.DebugS("clyde.ogl.egl", DumpEglConfig(_eglDisplay, configs[i]));
}
_eglConfig = configs[0];
@@ -186,7 +183,7 @@ namespace Robust.Client.Graphics.Clyde
if (_eglContext == (void*) EGL_NO_CONTEXT)
throw new Exception("eglCreateContext failed!");
_sawmill.Debug("EGL context created!");
Logger.DebugS("clyde.ogl.egl", "EGL context created!");
}
public override void Shutdown()

View File

@@ -418,37 +418,6 @@ namespace Robust.Client.Graphics.Clyde
}
}
public void SetUniform(string uniformName, bool[] bools)
{
var uniformId = GetUniform(uniformName);
SetUniformDirect(uniformId, bools);
}
public void SetUniform(int uniformName, bool[] bools)
{
var uniformId = GetUniform(uniformName);
SetUniformDirect(uniformId, bools);
}
private void SetUniformDirect(int slot, bool[] bools)
{
Span<int> intBools = stackalloc int[bools.Length];
for (var i = 0; i < bools.Length; i++)
{
intBools[i] = bools[i] ? 1 : 0;
}
unsafe
{
fixed (int* intBoolsPtr = intBools)
{
GL.Uniform1(slot, bools.Length, intBoolsPtr);
_clyde.CheckGlError();
}
}
}
public void SetUniformTexture(string uniformName, TextureUnit textureUnit)
{
var uniformId = GetUniform(uniformName);

View File

@@ -224,8 +224,7 @@ namespace Robust.Client.Graphics
// TODO: add support for int, and vec3/4 arrays
return
(type == ShaderDataType.Float) ||
(type == ShaderDataType.Vec2) ||
(type == ShaderDataType.Bool);
(type == ShaderDataType.Vec2);
}
[SuppressMessage("ReSharper", "StringLiteralTypo")]

View File

@@ -148,13 +148,6 @@ namespace Robust.Client.Graphics
SetParameterImpl(name, value);
}
public void SetParameter(string name, bool[] value)
{
EnsureAlive();
EnsureMutable();
SetParameterImpl(name, value);
}
public void SetParameter(string name, in Matrix3x2 value)
{
EnsureAlive();
@@ -226,7 +219,6 @@ namespace Robust.Client.Graphics
private protected abstract void SetParameterImpl(string name, int value);
private protected abstract void SetParameterImpl(string name, Vector2i value);
private protected abstract void SetParameterImpl(string name, bool value);
private protected abstract void SetParameterImpl(string name, bool[] value);
private protected abstract void SetParameterImpl(string name, in Matrix3x2 value);
private protected abstract void SetParameterImpl(string name, in Matrix4 value);
private protected abstract void SetParameterImpl(string name, Texture value);

View File

@@ -21,12 +21,9 @@ using SixLabors.ImageSharp.PixelFormats;
namespace Robust.Client.Map
{
internal sealed class ClydeTileDefinitionManager : TileDefinitionManager, IClydeTileDefinitionManager, IPostInjectInit
internal sealed class ClydeTileDefinitionManager : TileDefinitionManager, IClydeTileDefinitionManager
{
[Dependency] private readonly IResourceManager _manager = default!;
[Dependency] private readonly ILogManager _logManager = default!;
private ISawmill _sawmill = default!;
private Texture? _tileTextureAtlas;
@@ -101,7 +98,8 @@ namespace Robust.Client.Map
if (imgWidth >= 2048 || imgHeight >= 2048)
{
// Sanity warning, some machines don't have textures larger than this and need multiple atlases.
_sawmill.Warning($"Tile texture atlas is ({imgWidth} x {imgHeight}), larger than 2048 x 2048. If you really need {tileCount} tiles, file an issue on RobustToolbox.");
Logger.WarningS("clyde",
$"Tile texture atlas is ({imgWidth} x {imgHeight}), larger than 2048 x 2048. If you really need {tileCount} tiles, file an issue on RobustToolbox.");
}
var column = 1;
@@ -153,11 +151,6 @@ namespace Robust.Client.Map
_tileTextureAtlas = Texture.LoadFromImage(sheet, "Tile Atlas");
}
void IPostInjectInit.PostInject()
{
_sawmill = _logManager.GetSawmill("clyde");
}
}
public sealed class ReloadTileTexturesCommand : LocalizedCommands

View File

@@ -34,13 +34,13 @@ namespace Robust.Client.Placement.Modes
{
var from = ScreenToWorld(new Vector2(a, 0));
var to = ScreenToWorld(new Vector2(a, viewportSize.Y));
args.WorldHandle.DrawLine(from, to, new Color(0, 0, 0.3f));
args.WorldHandle.DrawLine(from, to, new Color(0, 0, 1f));
}
for (var a = gridstart.Y; a < viewportSize.Y; a += SnapSize * EyeManager.PixelsPerMeter)
{
var from = ScreenToWorld(new Vector2(0, a));
var to = ScreenToWorld(new Vector2(viewportSize.X, a));
args.WorldHandle.DrawLine(from, to, new Color(0, 0, 0.3f));
args.WorldHandle.DrawLine(from, to, new Color(0, 0, 1f));
}
}

View File

@@ -167,6 +167,7 @@ namespace Robust.Client.Player
if (_client.RunLevel != ClientRunLevel.SinglePlayerGame)
Sawmill.Warning($"Attaching local player to an entity {EntManager.ToPrettyString(uid)} without an eye. This eye will not be netsynced and may cause issues.");
var eye = (EyeComponent) Factory.GetComponent(typeof(EyeComponent));
eye.Owner = uid.Value;
eye.NetSyncEnabled = false;
EntManager.AddComponent(uid.Value, eye);
}

View File

@@ -162,7 +162,9 @@ public sealed partial class ReplayLoadManager
}
using var stringFile = fileReader.Open(FileStrings);
_serializer.SetStringSerializerPackage(stringHash, stringFile.CopyToArray());
var stringData = new byte[stringFile.Length];
stringFile.ReadExactly(stringData);
_serializer.SetStringSerializerPackage(stringHash, stringData);
using var cvarsFile = fileReader.Open(FileCvars);
// Note, this does not invoke the received-initial-cvars event. But at least currently, that doesn't matter

View File

@@ -44,10 +44,6 @@
<ProjectReference Include="..\Robust.Shared\Robust.Shared.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(RobustToolsBuild)' == 'True'">
<ProjectReference Include="..\Robust.Xaml\Robust.Xaml.csproj" />
</ItemGroup>
<!-- Shader embedding -->
<ItemGroup>
<EmbeddedResource Include="Graphics\Clyde\Shaders\*" />

View File

@@ -1,33 +0,0 @@
using System;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.GameObjects;
namespace Robust.Client.UserInterface;
public static class BoundUserInterfaceExt
{
/// <summary>
/// Helper method to create a window and also handle closing the BUI when it's closed.
/// </summary>
public static T CreateWindow<T>(this BoundUserInterface bui) where T : BaseWindow, new()
{
var window = bui.CreateDisposableControl<T>();
window.OpenCentered();
window.OnClose += bui.Close;
return window;
}
/// <summary>
/// Creates a control for this BUI that will be disposed when it is disposed.
/// </summary>
/// <param name="bui"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static T CreateDisposableControl<T>(this BoundUserInterface bui) where T : Control, IDisposable, new()
{
var control = new T();
bui.Disposals ??= [];
bui.Disposals.Add(control);
return control;
}
}

View File

@@ -602,7 +602,6 @@ namespace Robust.Client.UserInterface
/// Dispose this control, its own scene control, and all its children.
/// Basically the big delete button.
/// </summary>
[Obsolete("Controls should only be removed from UI tree instead of being disposed")]
public void Dispose()
{
if (Disposed)
@@ -614,7 +613,6 @@ namespace Robust.Client.UserInterface
Disposed = true;
}
[Obsolete("Controls should only be removed from UI tree instead of being disposed")]
protected virtual void Dispose(bool disposing)
{
if (!disposing)

View File

@@ -327,7 +327,8 @@ public sealed class EntitySpawningUIController : UIController
if (_window == null || _window.Disposed)
return;
var button = _window.InsertEntityButton(prototype, insertFirst, index);
var textures = SpriteComponent.GetPrototypeTextures(prototype, _resources).Select(o => o.Default).ToList();
var button = _window.InsertEntityButton(prototype, insertFirst, index, textures);
button.ActualButton.OnToggled += OnEntityButtonToggled;
}

View File

@@ -15,36 +15,6 @@ namespace Robust.Client.UserInterface.Controls
public Label Label { get; }
public TextureRect TextureRect { get; }
/// <summary>
/// Should the checkbox be to the left or the right of the label.
/// </summary>
public bool LeftAlign
{
get => _leftAlign;
set
{
if (_leftAlign == value)
return;
_leftAlign = value;
if (value)
{
Label.HorizontalExpand = false;
TextureRect.SetPositionFirst();
Label.SetPositionInParent(1);
}
else
{
Label.HorizontalExpand = true;
Label.SetPositionFirst();
TextureRect.SetPositionInParent(1);
}
}
}
private bool _leftAlign = true;
public CheckBox()
{
ToggleMode = true;
@@ -61,21 +31,10 @@ namespace Robust.Client.UserInterface.Controls
StyleClasses = { StyleClassCheckBox },
VerticalAlignment = VAlignment.Center,
};
hBox.AddChild(TextureRect);
Label = new Label();
if (LeftAlign)
{
Label.HorizontalExpand = false;
hBox.AddChild(TextureRect);
hBox.AddChild(Label);
}
else
{
Label.HorizontalExpand = true;
hBox.AddChild(Label);
hBox.AddChild(TextureRect);
}
hBox.AddChild(Label);
}
protected override void DrawModeChanged()

View File

@@ -15,8 +15,6 @@ namespace Robust.Client.UserInterface.Controls
public const string StylePseudoClassHover = "hover";
public const string StylePseudoClassDisabled = "disabled";
public StyleBox? StyleBoxOverride { get; set; }
public ContainerButton()
{
DrawModeChanged();
@@ -26,11 +24,6 @@ namespace Robust.Client.UserInterface.Controls
{
get
{
if (StyleBoxOverride != null)
{
return StyleBoxOverride;
}
if (TryGetStyleProperty<StyleBox>(StylePropertyStyleBox, out var box))
{
return box;

View File

@@ -33,7 +33,10 @@ public class EntityPrototypeView : SpriteView
_currentPrototype = entProto;
SetEntity(null);
EntMan.DeleteEntity(_ourEntity);
if (_ourEntity != null)
{
EntMan.DeleteEntity(_ourEntity);
}
if (_currentPrototype != null)
{
@@ -54,6 +57,8 @@ public class EntityPrototypeView : SpriteView
protected override void ExitedTree()
{
base.ExitedTree();
EntMan.TryQueueDeleteEntity(_ourEntity);
if (!EntMan.Deleted(_ourEntity))
EntMan.QueueDeleteEntity(_ourEntity);
}
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Numerics;
using Robust.Client.Graphics;
@@ -14,7 +14,6 @@ namespace Robust.Client.UserInterface.Controls
public const string StyleClassOptionButton = "optionButton";
public const string StyleClassPopup = "optionButtonPopup";
public const string StyleClassOptionTriangle = "optionTriangle";
public const string StyleClassOptionsBackground = "optionButtonBackground";
public readonly ScrollContainer OptionsScroll;
private readonly List<ButtonData> _buttonData = new();
@@ -76,12 +75,7 @@ namespace Robust.Client.UserInterface.Controls
_popup = new Popup()
{
Children = {
new PanelContainer {
StyleClasses = { StyleClassOptionsBackground }
},
OptionsScroll
},
Children = { new PanelContainer(), OptionsScroll },
StyleClasses = { StyleClassPopup }
};
_popup.OnPopupHide += OnPopupHide;

View File

@@ -38,21 +38,6 @@ namespace Robust.Client.UserInterface.Controls
}
}
public string? Text
{
get => _message?.ToMarkup();
set
{
if (value == null)
{
_message?.Clear();
return;
}
SetMessage(FormattedMessage.FromMarkupPermissive(value));
}
}
public RichTextLabel()
{
IoCManager.InjectDependencies(this);

View File

@@ -1,3 +1,4 @@
using Robust.Shared.Maths;
using System;
using System.Collections.Generic;
using System.Numerics;
@@ -14,10 +15,9 @@ namespace Robust.Client.UserInterface.Controls
public const string RightButtonStyle = "spinbox-right";
public const string MiddleButtonStyle = "spinbox-middle";
public LineEdit LineEditControl { get; }
private List<SpinBoxButton> _leftButtons = new();
private List<SpinBoxButton> _rightButtons = new();
private List<Button> _leftButtons = new();
private List<Button> _rightButtons = new();
private int _stepSize = 1;
private bool _buttonsDisabled;
/// <summary>
/// Determines whether the SpinBox value gets changed by the input text.
@@ -30,7 +30,12 @@ namespace Robust.Client.UserInterface.Controls
get => _value;
set
{
OverrideValue(value);
if (IsValid != null && !IsValid(value))
{
return;
}
_value = value;
LineEditControl.Text = value.ToString();
ValueChanged?.Invoke(new ValueChangedEventArgs(value));
}
}
@@ -47,7 +52,6 @@ namespace Robust.Client.UserInterface.Controls
return;
}
_value = value;
UpdateButtonCanPress();
LineEditControl.Text = value.ToString();
}
@@ -83,7 +87,6 @@ namespace Robust.Client.UserInterface.Controls
ClearButtons();
AddLeftButton(-1, "-");
AddRightButton(1, "+");
UpdateButtonCanPress();
}
/// <summary>
@@ -91,8 +94,8 @@ namespace Robust.Client.UserInterface.Controls
/// </summary>
public void AddRightButton(int num, string text)
{
var button = new SpinBoxButton(num) { Text = text };
button.OnPressed += _ => Value += num;
var button = new Button { Text = text };
button.OnPressed += (args) => Value += num;
AddChild(button);
button.AddStyleClass(RightButtonStyle);
if (_rightButtons.Count > 0)
@@ -108,8 +111,8 @@ namespace Robust.Client.UserInterface.Controls
/// </summary>
public void AddLeftButton(int num, string text)
{
var button = new SpinBoxButton(num) { Text = text };
button.OnPressed += _ => Value += num;
var button = new Button { Text = text };
button.OnPressed += (args) => Value += num;
AddChild(button);
button.SetPositionInParent(_leftButtons.Count);
button.AddStyleClass(_leftButtons.Count == 0 ? LeftButtonStyle : MiddleButtonStyle);
@@ -159,24 +162,6 @@ namespace Robust.Client.UserInterface.Controls
{
rightButton.Disabled = disabled;
}
_buttonsDisabled = disabled;
}
private void UpdateButtonCanPress()
{
if (IsValid == null)
return;
foreach (var button in _leftButtons)
{
button.Disabled = !IsValid(_value + button.Value) || _buttonsDisabled;
}
foreach (var button in _rightButtons)
{
button.Disabled = !IsValid(_value + button.Value) || _buttonsDisabled;
}
}
/// <summary>
@@ -210,16 +195,6 @@ namespace Robust.Client.UserInterface.Controls
else if (args.Delta.Y < 0)
Value -= _stepSize;
}
private sealed class SpinBoxButton : Button
{
public readonly int Value;
public SpinBoxButton(int value)
{
Value = value;
}
}
}
public sealed class ValueChangedEventArgs : EventArgs

View File

@@ -191,19 +191,6 @@ namespace Robust.Client.UserInterface.Controls
_splitDragArea.OnMouseMove += OnMove;
}
/// <summary>
/// Swaps the position of the first and zeroeth children; for a 2-control viewport it effectively flips them.
/// </summary>
public void Flip()
{
if (ChildCount < 3)
return;
DebugTools.Assert(ChildCount <= 3);
GetChild(1).SetPositionFirst();
InvalidateArrange();
}
private void OnMove(GUIMouseMoveEventArgs args)
{
if (ResizeMode == SplitResizeMode.NotResizable)

View File

@@ -65,10 +65,6 @@ namespace Robust.Client.UserInterface.Controls
}
}
public StyleBox? PanelStyleBoxOverride { get; set; }
public Color? TabFontColorOverride { get; set; }
public Color? TabFontColorInactiveOverride { get; set; }
public event Action<int>? OnTabChanged;
public TabContainer()
@@ -365,9 +361,6 @@ namespace Robust.Client.UserInterface.Controls
[System.Diagnostics.Contracts.Pure]
private Color _getTabFontColorActive()
{
if (TabFontColorOverride != null)
return TabFontColorOverride.Value;
if (TryGetStyleProperty(stylePropertyTabFontColor, out Color color))
{
return color;
@@ -378,9 +371,6 @@ namespace Robust.Client.UserInterface.Controls
[System.Diagnostics.Contracts.Pure]
private Color _getTabFontColorInactive()
{
if (TabFontColorInactiveOverride != null)
return TabFontColorInactiveOverride.Value;
if (TryGetStyleProperty(StylePropertyTabFontColorInactive, out Color color))
{
return color;
@@ -391,9 +381,6 @@ namespace Robust.Client.UserInterface.Controls
[System.Diagnostics.Contracts.Pure]
private StyleBox? _getPanel()
{
if (PanelStyleBoxOverride != null)
return PanelStyleBoxOverride;
TryGetStyleProperty<StyleBox>(StylePropertyPanelStyleBox, out var box);
return box;
}

View File

@@ -1,6 +1,5 @@
using System;
using System.Numerics;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input;
using Robust.Shared.IoC;
@@ -236,15 +235,6 @@ namespace Robust.Client.UserInterface.CustomControls
public void OpenToRight() => OpenCenteredAt(new Vector2(1, 0.5f));
public void OpenCenteredRight() => OpenCenteredAt(new Vector2(0.75f, 0.5f));
/// <summary>
/// Opens a window and centers it relative to the screen position.
/// </summary>
public void OpenScreenAt(Vector2 relativePosition, IClyde clyde)
{
var adjusted = relativePosition / clyde.ScreenSize;
OpenCenteredAt(adjusted);
}
/// <summary>
/// Opens a window, attempting to place the center of the window at some relative point on the screen.
/// </summary>

View File

@@ -277,21 +277,8 @@ public sealed partial class DebugConsole
CommandBar.CursorPosition = lastRange.end;
CommandBar.SelectionStart = lastRange.start;
var insertValue = CommandParsing.Escape(completion);
// If the replacement contains a space, we must quote it to treat it as a single argument.
var mustQuote = insertValue.Contains(' ');
if ((completionFlags & CompletionOptionFlags.PartialCompletion) == 0)
{
if (mustQuote)
insertValue = $"\"{insertValue}\"";
insertValue += " ";
}
else if (mustQuote)
{
// If it's a partial completion, only quote the start.
insertValue = '"' + insertValue;
}
CommandBar.InsertAtCursor(insertValue);

View File

@@ -83,7 +83,7 @@ namespace Robust.Client.UserInterface.CustomControls.DebugMonitorControls
}
else
{
mouseGridPos = new EntityCoordinates(mapSystem.GetMapOrInvalid(mouseWorldMap.MapId),
mouseGridPos = new EntityCoordinates(_mapManager.GetMapEntityId(mouseWorldMap.MapId),
mouseWorldMap.Position);
tile = new TileRef(EntityUid.Invalid,
mouseGridPos.ToVector2i(_entityManager, _mapManager, xformSystem), Tile.Empty);

View File

@@ -12,7 +12,7 @@ public sealed class EntitySpawnButton : Control
public EntityPrototype Prototype { get; set; } = default!;
public Button ActualButton { get; private set; }
public Label EntityLabel { get; private set; }
public EntityPrototypeView EntityTextureRects {get; private set; }
public LayeredTextureRect EntityTextureRects { get; private set; }
public int Index { get; set; }
public EntitySpawnButton()
@@ -27,12 +27,13 @@ public sealed class EntitySpawnButton : Control
Orientation = BoxContainer.LayoutOrientation.Horizontal,
Children =
{
(EntityTextureRects = new EntityPrototypeView
(EntityTextureRects = new LayeredTextureRect
{
SetSize = new Vector2(32, 32),
MinSize = new Vector2(32, 32),
HorizontalAlignment = HAlignment.Center,
VerticalAlignment = VAlignment.Center,
Stretch = SpriteView.StretchMode.Fill
Stretch = TextureRect.StretchMode.KeepAspectCentered,
CanShrink = true
}),
(EntityLabel = new Label
{

View File

@@ -44,7 +44,7 @@ namespace Robust.Client.UserInterface.CustomControls
}
// Create a spawn button and insert it into the start or end of the list.
public EntitySpawnButton InsertEntityButton(EntityPrototype prototype, bool insertFirst, int index)
public EntitySpawnButton InsertEntityButton(EntityPrototype prototype, bool insertFirst, int index, List<Texture> textures)
{
var button = new EntitySpawnButton
{
@@ -67,7 +67,7 @@ namespace Robust.Client.UserInterface.CustomControls
}
var rect = button.EntityTextureRects;
rect.SetPrototype(prototype.ID);
rect.Textures = textures;
PrototypeList.AddChild(button);
if (insertFirst)

View File

@@ -64,7 +64,7 @@ namespace Robust.Client.UserInterface
IDebugMonitors DebugMonitors { get; }
void Popup(string contents, string? title = null, bool clipboardButton = true);
void Popup(string contents, string title = "Alert!");
Control? MouseGetControl(ScreenCoordinates coordinates);

View File

@@ -1,4 +1,3 @@
using System.Linq;
using Robust.Client.State;
using Robust.Shared.Console;
using Robust.Shared.IoC;
@@ -8,12 +7,11 @@ namespace Robust.Client.UserInterface
{
sealed class ChangeSceneCommpand : LocalizedCommands
{
[Dependency] private readonly IReflectionManager _reflection = default!;
public override string Command => "scene";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
var types = _reflection.GetAllChildren(typeof(State.State));
var reflection = IoCManager.Resolve<IReflectionManager>();
var types = reflection.GetAllChildren(typeof(State.State));
foreach (var tryType in types)
{
@@ -28,13 +26,5 @@ namespace Robust.Client.UserInterface
shell.WriteError($"No scene child class type ends with {args[0]}");
}
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length != 1)
return CompletionResult.Empty;
var types = _reflection.GetAllChildren(typeof(State.State));
return CompletionResult.FromHintOptions(types.Select(x => x.Name), "[State name]");
}
}
}

View File

@@ -148,7 +148,7 @@ internal partial class UserInterfaceManager
var newHovered = MouseGetControl(mouseMoveEventArgs.Position);
SetHovered(newHovered);
var target = ControlFocused ?? CurrentlyHovered;
var target = ControlFocused ?? newHovered;
if (target != null)
{
var pos = mouseMoveEventArgs.Position.Position;
@@ -164,7 +164,7 @@ internal partial class UserInterfaceManager
public void UpdateHovered()
{
var ctrl = MouseGetControl(_inputManager.MouseScreenPosition);
var ctrl = MouseGetControl(_inputManager.MouseScreenPosition);
SetHovered(ctrl);
}

View File

@@ -4,7 +4,6 @@ using System.Numerics;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Profiling;
@@ -54,47 +53,14 @@ internal sealed partial class UserInterfaceManager
}
}
public void Popup(string contents, string? title = null, bool clipboardButton = true)
public void Popup(string contents, string title = "Alert!")
{
var popup = new DefaultWindow
{
Title = string.IsNullOrEmpty(title) ? Loc.GetString("popup-title") : title,
Title = title
};
var label = new Label { Text = contents };
var vBox = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Vertical,
};
vBox.AddChild(label);
if (clipboardButton)
{
var copyButton = new Button
{
Text = Loc.GetString("popup-copy-button"),
HorizontalExpand = true,
};
copyButton.OnPressed += _ =>
{
_clipboard.SetText(contents);
};
var hBox = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Horizontal,
HorizontalAlignment = Control.HAlignment.Right,
};
hBox.AddChild(copyButton);
vBox.AddChild(hBox);
}
popup.Contents.AddChild(vBox);
popup.Contents.AddChild(new Label {Text = contents});
popup.OpenCentered();
}

View File

@@ -54,7 +54,6 @@ namespace Robust.Client.UserInterface
[Dependency] private readonly IEntitySystemManager _systemManager = default!;
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly IRuntimeLog _runtime = default!;
[Dependency] private readonly IClipboardManager _clipboard = null!;
private IAudioSource? _clickSource;
private IAudioSource? _hoverSource;
@@ -215,9 +214,6 @@ namespace Robust.Client.UserInterface
{
using (_prof.Group("Update"))
{
// Update hovered. Can't rely upon mouse movement due to New controls potentially coming up.
UpdateHovered();
foreach (var root in _roots)
{
CheckRootUIScaleUpdate(root);

View File

@@ -1,20 +0,0 @@
namespace Robust.Client.UserInterface.XAML.Proxy;
/// <summary>
/// This service locates the SS14 source tree and watches for changes to its xaml files.
/// </summary>
/// <remarks>
/// It then reloads them instantly.
///
/// It depends on <see cref="IXamlProxyManager"/> and is stubbed on non-TOOLS builds.
/// </remarks>
interface IXamlHotReloadManager
{
/// <summary>
/// Initialize the hot reload manager.
/// </summary>
/// <remarks>
/// You can't do anything with this once it's started, including turn it off.
/// </remarks>
void Initialize();
}

View File

@@ -1,11 +0,0 @@
using System;
namespace Robust.Client.UserInterface.XAML.Proxy;
/// <summary>
/// Reexport the Populate method of <see cref="IXamlProxyManager"/> and nothing else.
/// </summary>
public interface IXamlProxyHelper
{
bool Populate(Type t, object o);
}

View File

@@ -1,76 +0,0 @@
using System;
namespace Robust.Client.UserInterface.XAML.Proxy;
/// <summary>
/// This service provides a proxy for Populate, which is the generated function that
/// initializes the UI objects of a Xaml widget.
/// </summary>
/// <remarks>
/// The proxy can always return false: in that case, a Xaml widget will self-populate
/// as usual. This is the behavior on Release builds.
///
/// However, it can also call into an externally-provided implementation of the Xaml
/// widget.
///
/// No source of externally-provided implementations actually exists, by default --
/// you will need to call SetImplementation with a blob of xaml source code to provide
/// one. <see cref="IXamlHotReloadManager" /> is an example of a service that calls into
/// that functionality.
/// </remarks>
internal interface IXamlProxyManager
{
/// <summary>
/// Initialize creates the <see cref="IXamlProxyManager"/>.
/// </summary>
/// <remarks>
/// If the <see cref="IXamlProxyManager" /> is not a stub, then it will spy on the
/// assembly list (from <see cref="Robust.Shared.Reflection.IReflectionManager" />)
/// and find <see cref="XamlMetadataAttribute" /> entries on the loaded types.
/// </remarks>
void Initialize();
/// <summary>
/// Return true if at least one <see cref="Type"/> in the current project expects its XAML
/// to come from a file with the given name.
/// </summary>
/// <remarks>
/// This method supports code that is trying to figure out what name the build process
/// would have assigned to a resource file. A caller can try a few candidate names and use
/// its "yes" to continue.
///
/// This method is very fast, so it's OK to hammer it!
///
/// Also, on a non-tools build, this always returns false.
/// </remarks>
/// <param name="fileName">the filename</param>
/// <returns>true if expected</returns>
bool CanSetImplementation(string fileName);
/// <summary>
/// Replace the implementation of <paramref name="fileName"/> with <paramref name="fileContent" />,
/// compiling it if needed.
///
/// All types based on <paramref name="fileName" /> will be recompiled.
/// </summary>
/// <remarks>
/// This may fail and the caller won't be notified. (There will usually be logs.)
///
/// On a non-tools build, this fails silently.
/// </remarks>
/// <param name="fileName">the name of the file</param>
/// <param name="fileContent">the new content of the file</param>
void SetImplementation(string fileName, string fileContent);
/// <summary>
/// If we have a JIT version of the XAML code for <paramref name="t" />, then call
/// the new implementation on <paramref name="o" />.
/// </summary>
/// <remarks>
/// <paramref name="o" /> may be a subclass of <paramref name="t" />.
/// </remarks>
/// <param name="t">the static type of the object</param>
/// <param name="o">the object</param>
/// <returns>true if we called a hot reloaded implementation</returns>
bool Populate(Type t, object o);
}

View File

@@ -1,195 +0,0 @@
#if TOOLS
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Robust.Shared.Asynchronous;
using Robust.Shared.ContentPack;
using Robust.Shared.IoC;
using Robust.Shared.Log;
namespace Robust.Client.UserInterface.XAML.Proxy;
/// <summary>
/// The real implementation of <see cref="IXamlHotReloadManager" />.
/// </summary>
/// <remarks>
/// Its behavior is described there.
/// </remarks>
internal sealed class XamlHotReloadManager : IXamlHotReloadManager
{
private const string MarkerFileName = "SpaceStation14.sln";
[Dependency] ILogManager _logManager = null!;
[Dependency] private readonly IResourceManager _resources = null!;
[Dependency] private readonly ITaskManager _taskManager = null!;
[Dependency] private readonly IXamlProxyManager _xamlProxyManager = null!;
private ISawmill _sawmill = null!;
private FileSystemWatcher? _watcher;
public void Initialize()
{
_sawmill = _logManager.GetSawmill("xamlhotreload");
var codeLocation = InferCodeLocation();
if (codeLocation == null)
{
_sawmill.Warning($"could not find code -- where is {MarkerFileName}?");
return;
}
_sawmill.Info($"code location: {codeLocation}");
// must not be gc'ed or else it will stop reporting
// therefore: keep a reference
_watcher = CreateWatcher(codeLocation);
}
/// <summary>
/// Create a file system watcher that identifies XAML changes in a given
/// location.
/// </summary>
/// <param name="location">the location (a real path on the OS file system)</param>
/// <returns>the new watcher</returns>
/// <exception cref="ArgumentOutOfRangeException">if <see cref="FileSystemWatcher"/> violates its type-related postconditions</exception>
private FileSystemWatcher CreateWatcher(string location)
{
var watcher = new FileSystemWatcher(location)
{
IncludeSubdirectories = true,
NotifyFilter = NotifyFilters.LastWrite,
};
watcher.Changed += (_, args) =>
{
switch (args.ChangeType)
{
case WatcherChangeTypes.Renamed:
case WatcherChangeTypes.Deleted:
return;
case WatcherChangeTypes.Created:
case WatcherChangeTypes.Changed:
case WatcherChangeTypes.All:
break;
default:
throw new ArgumentOutOfRangeException(nameof(args));
}
_taskManager.RunOnMainThread(() =>
{
var resourceFileName =
ResourceFileName(location, args.FullPath, _xamlProxyManager.CanSetImplementation);
if (resourceFileName == null)
{
return;
}
string newText;
try
{
newText = File.ReadAllText(args.FullPath);
}
catch (IOException ie)
{
_sawmill.Warning($"error attempting a hot reload -- skipped: {ie}");
return;
}
_xamlProxyManager.SetImplementation(resourceFileName, newText);
});
};
watcher.EnableRaisingEvents = true;
return watcher;
}
/// <summary>
/// Using the content roots of the project, infer the location of its code.
/// </summary>
/// <remarks>
/// This kind of introspection is almost universally a bad idea, but we don't
/// feasibly have other options, so I've buried it in a private method.
/// </remarks>
/// <returns>the inferred code location or null</returns>
private string? InferCodeLocation()
{
// ascend upwards from each content root until the solution file is found
foreach (var contentRoot in _resources.GetContentRoots())
{
var systemPath = contentRoot.ToRelativeSystemPath();
while (true)
{
var files = Array.Empty<string>();
try
{
files = Directory.GetFiles(systemPath);
}
catch (IOException) { } // this is allowed to fail, and if so we just keep going up
if (files.Any(f => Path.GetFileName(f).Equals(MarkerFileName, StringComparison.InvariantCultureIgnoreCase)))
{
return systemPath;
}
DirectoryInfo? newPath = null;
try
{
newPath = Directory.GetParent(systemPath);
}
catch (IOException) { } // ditto here. if we don't find it, we're in the wrong place
if (newPath == null)
{
break;
}
systemPath = newPath.FullName;
}
}
return null;
}
/// <summary>
/// Infer the name of the resource file associated with the XAML item at the given path.
/// </summary>
/// <param name="codeLocation">the code location</param>
/// <param name="realPath">the real path of the file</param>
/// <param name="isDesired">a function returning true if something expects this file</param>
/// <returns>the name of a desired resource that matches this file, or null</returns>
private string? ResourceFileName(string codeLocation, string realPath, Predicate<string> isDesired)
{
// start with the name of the file and systematically add each super-directory until we reach
// the inferred code location.
//
// for /home/pyrex/ss14/Content.Client/Instruments/UI/InstrumentMenu.xaml, the following names
// will be tried:
//
// - InstrumentMenu.xaml
// - UI.InstrumentMenu.xaml
// - Instruments.UI.InstrumentMenu.xaml
// - Content.Client.Instruments.UI.InstrumentMenu.xaml
var resourceFileName = Path.GetFileName(realPath);
var super = Directory.GetParent(realPath);
var canonicalCodeLocation = Path.GetFullPath(codeLocation);
while (true)
{
// did someone want it: OK, jump out
if (isDesired(resourceFileName))
{
return resourceFileName;
}
if (super == null || Path.GetFullPath(super.FullName) == canonicalCodeLocation)
{
return null;
}
resourceFileName = super.Name + "." + resourceFileName;
super = super.Parent;
}
}
}
#endif

View File

@@ -1,15 +0,0 @@
namespace Robust.Client.UserInterface.XAML.Proxy;
/// <summary>
/// A stub implementation of <see cref="XamlHotReloadManager"/>. Its
/// behavior is to do nothing.
/// </summary>
internal sealed class XamlHotReloadManagerStub : IXamlHotReloadManager
{
/// <summary>
/// Do nothing.
/// </summary>
public void Initialize()
{
}
}

Some files were not shown because too many files have changed in this diff Show More