mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Compare commits
101 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e25ead588 | ||
|
|
cfae6e1f95 | ||
|
|
da56851846 | ||
|
|
69ed2c3c33 | ||
|
|
c558a0327b | ||
|
|
3bb7df3254 | ||
|
|
ab6bd19817 | ||
|
|
73ef69aa94 | ||
|
|
656835e7fa | ||
|
|
26c87b5858 | ||
|
|
be36001ab8 | ||
|
|
2002402af8 | ||
|
|
f659b2b58c | ||
|
|
b1e13f5b13 | ||
|
|
e5995d4edc | ||
|
|
6eb080a277 | ||
|
|
b0cb41e94a | ||
|
|
23a23f7c22 | ||
|
|
ec3a74d268 | ||
|
|
12b0bc4e0a | ||
|
|
903041dfd1 | ||
|
|
b96419f0b2 | ||
|
|
fe33ad2652 | ||
|
|
057a68b366 | ||
|
|
1a2c9008fe | ||
|
|
cd95929ebe | ||
|
|
6396ec472d | ||
|
|
d7aa5daf6a | ||
|
|
e3819f8245 | ||
|
|
57f133b742 | ||
|
|
04344ffe19 | ||
|
|
f2ee9a43f9 | ||
|
|
8d5ebd830a | ||
|
|
4d265b2210 | ||
|
|
e04caf7eb4 | ||
|
|
a4c54d3602 | ||
|
|
43fd6bc764 | ||
|
|
ff056552fe | ||
|
|
3014d9880e | ||
|
|
679c31199d | ||
|
|
0bc3c51707 | ||
|
|
140767c262 | ||
|
|
36a5b672e5 | ||
|
|
1eb63cb616 | ||
|
|
c14689f233 | ||
|
|
f03c006129 | ||
|
|
0d53c5e329 | ||
|
|
5cb1901870 | ||
|
|
d46885b96d | ||
|
|
0553600c9a | ||
|
|
580dd5f1a6 | ||
|
|
d47d488ce7 | ||
|
|
d584e51de6 | ||
|
|
2f85b94ea2 | ||
|
|
046f7a2e55 | ||
|
|
5f2881e3e4 | ||
|
|
cdb94748c8 | ||
|
|
53516d6389 | ||
|
|
efa3e010a6 | ||
|
|
4b12ff8574 | ||
|
|
59ed76c66f | ||
|
|
9781405f5e | ||
|
|
2178707937 | ||
|
|
0284eb0430 | ||
|
|
2c3cc070a6 | ||
|
|
6599f9565e | ||
|
|
85abcff5ea | ||
|
|
5b5894e2d5 | ||
|
|
7d778248ee | ||
|
|
672819d525 | ||
|
|
99e4910440 | ||
|
|
b503390837 | ||
|
|
87725f27c3 | ||
|
|
49c831b48d | ||
|
|
60a29933d8 | ||
|
|
5729e8eb19 | ||
|
|
42da4b1287 | ||
|
|
3342e1272f | ||
|
|
5c0ce43e6c | ||
|
|
0717b1fced | ||
|
|
68c03196e6 | ||
|
|
31292fe4b8 | ||
|
|
865348550f | ||
|
|
7372233782 | ||
|
|
7ebfc82dd6 | ||
|
|
807e7e888a | ||
|
|
39fefcb9c8 | ||
|
|
b6548c870c | ||
|
|
cf230b3454 | ||
|
|
16a93e86f6 | ||
|
|
2e4275a7f3 | ||
|
|
176ca6c578 | ||
|
|
2664061993 | ||
|
|
033699d7d6 | ||
|
|
f696edaa0c | ||
|
|
4920ecaa64 | ||
|
|
b8924a04cf | ||
|
|
be11cb4bca | ||
|
|
eafe395273 | ||
|
|
05cdb99252 | ||
|
|
d4c6b4a828 |
@@ -19,6 +19,7 @@
|
||||
<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" />
|
||||
@@ -55,7 +56,7 @@
|
||||
<PackageVersion Include="Serilog" Version="3.1.1" />
|
||||
<PackageVersion Include="Serilog.Sinks.Loki" Version="4.0.0-beta3" />
|
||||
<PackageVersion Include="SharpZstd.Interop" Version="1.5.2-beta2" />
|
||||
<PackageVersion Include="SixLabors.ImageSharp" Version="3.1.4" />
|
||||
<PackageVersion Include="SixLabors.ImageSharp" Version="3.1.5" />
|
||||
<PackageVersion Include="SpaceWizards.HttpListener" Version="0.1.1" />
|
||||
<PackageVersion Include="SpaceWizards.NFluidsynth" Version="0.1.1" />
|
||||
<PackageVersion Include="SpaceWizards.SharpFont" Version="1.0.2" />
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project>
|
||||
|
||||
<!-- This file automatically reset by Tools/version.py -->
|
||||
<!-- This file automatically reset by Tools/version.py -->
|
||||
|
||||
|
||||
215
RELEASE-NOTES.md
215
RELEASE-NOTES.md
@@ -54,6 +54,221 @@ END TEMPLATE-->
|
||||
*None yet*
|
||||
|
||||
|
||||
## 233.0.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
|
||||
|
||||
2
Resources/Locale/en-US/userinterface.ftl
Normal file
2
Resources/Locale/en-US/userinterface.ftl
Normal file
@@ -0,0 +1,2 @@
|
||||
popup-copy-button = Copy
|
||||
popup-title = Alert!
|
||||
@@ -84,8 +84,8 @@ public sealed class DataDefinitionAnalyzerTest
|
||||
""";
|
||||
|
||||
await Verifier(code,
|
||||
// /0/Test0.cs(35,5): info RA0028: Data field Bad in data definition Foo has ViewVariables attribute with ReadWrite access, which is redundant
|
||||
VerifyCS.Diagnostic(DataDefinitionAnalyzer.DataFieldNoVVReadWriteRule).WithSpan(35, 5, 36, 20).WithArguments("Bad", "Foo")
|
||||
// /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")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
62
Robust.Analyzers.Tests/PreferOtherTypeAnalyzerTest.cs
Normal file
62
Robust.Analyzers.Tests/PreferOtherTypeAnalyzerTest.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
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")
|
||||
);
|
||||
}
|
||||
}
|
||||
81
Robust.Analyzers.Tests/PreferOtherTypeFixerTest.cs
Normal file
81
Robust.Analyzers.Tests/PreferOtherTypeFixerTest.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
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"));
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@
|
||||
<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>
|
||||
|
||||
@@ -27,6 +28,7 @@
|
||||
<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"/>
|
||||
|
||||
@@ -18,6 +18,8 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
|
||||
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,
|
||||
@@ -152,12 +154,14 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
|
||||
|
||||
if (HasRedundantTag(fieldSymbol))
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(DataFieldRedundantTagRule, context.Node.GetLocation(), fieldSymbol.Name, type.Name));
|
||||
TryGetAttributeLocation(field, DataFieldAttributeName, out var location);
|
||||
context.ReportDiagnostic(Diagnostic.Create(DataFieldRedundantTagRule, location, fieldSymbol.Name, type.Name));
|
||||
}
|
||||
|
||||
if (HasVVReadWrite(fieldSymbol))
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(DataFieldNoVVReadWriteRule, context.Node.GetLocation(), fieldSymbol.Name, type.Name));
|
||||
TryGetAttributeLocation(field, ViewVariablesAttributeName, out var location);
|
||||
context.ReportDiagnostic(Diagnostic.Create(DataFieldNoVVReadWriteRule, location, fieldSymbol.Name, type.Name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -186,12 +190,14 @@ public sealed class DataDefinitionAnalyzer : DiagnosticAnalyzer
|
||||
|
||||
if (HasRedundantTag(propertySymbol))
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(DataFieldRedundantTagRule, context.Node.GetLocation(), propertySymbol.Name, type.Name));
|
||||
TryGetAttributeLocation(property, DataFieldAttributeName, out var location);
|
||||
context.ReportDiagnostic(Diagnostic.Create(DataFieldRedundantTagRule, location, propertySymbol.Name, type.Name));
|
||||
}
|
||||
|
||||
if (HasVVReadWrite(propertySymbol))
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(DataFieldNoVVReadWriteRule, context.Node.GetLocation(), propertySymbol.Name, type.Name));
|
||||
TryGetAttributeLocation(property, ViewVariablesAttributeName, out var location);
|
||||
context.ReportDiagnostic(Diagnostic.Create(DataFieldNoVVReadWriteRule, location, propertySymbol.Name, type.Name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,6 +267,24 @@ 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)
|
||||
|
||||
75
Robust.Analyzers/PreferOtherTypeAnalyzer.cs
Normal file
75
Robust.Analyzers/PreferOtherTypeAnalyzer.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
#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));
|
||||
}
|
||||
}
|
||||
}
|
||||
97
Robust.Analyzers/PreferOtherTypeFixer.cs
Normal file
97
Robust.Analyzers/PreferOtherTypeFixer.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
#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;
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,11 @@
|
||||
<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" />
|
||||
|
||||
@@ -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,10 +37,12 @@ namespace Robust.Build.Tasks
|
||||
var msg = $"CompileRobustXamlTask -> AssemblyFile:{AssemblyFile}, ProjectDirectory:{ProjectDirectory}, OutputPath:{OutputPath}";
|
||||
BuildEngine.LogMessage(msg, MessageImportance.High);
|
||||
|
||||
var res = XamlCompiler.Compile(BuildEngine, input,
|
||||
var res = XamlAotCompiler.Compile(
|
||||
BuildEngine, input,
|
||||
File.ReadAllLines(ReferencesFilePath).Where(l => !string.IsNullOrWhiteSpace(l)).ToArray(),
|
||||
ProjectDirectory, OutputPath,
|
||||
(SignAssembly && !DelaySign) ? AssemblyOriginatorKeyFile : null);
|
||||
OutputPath,
|
||||
(SignAssembly && !DelaySign) ? AssemblyOriginatorKeyFile : null
|
||||
);
|
||||
if (!res.success)
|
||||
return false;
|
||||
if (!res.writtentofile)
|
||||
@@ -65,22 +67,24 @@ 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; }
|
||||
public string ReferencesFilePath { get; set; } = null!;
|
||||
|
||||
[Required]
|
||||
public string ProjectDirectory { get; set; }
|
||||
|
||||
public string ProjectDirectory { get; set; } = null!;
|
||||
|
||||
[Required]
|
||||
public string AssemblyFile { get; set; }
|
||||
public string AssemblyFile { get; set; } = null!;
|
||||
|
||||
[Required]
|
||||
public string OriginalCopyPath { get; set; }
|
||||
public string? OriginalCopyPath { get; set; } = null;
|
||||
|
||||
public string OutputPath { get; set; }
|
||||
public string UpdateBuildIndicator { get; set; }
|
||||
public string? OutputPath { get; set; }
|
||||
public string UpdateBuildIndicator { get; set; } = null!;
|
||||
|
||||
public string AssemblyOriginatorKeyFile { get; set; }
|
||||
public string AssemblyOriginatorKeyFile { get; set; } = null!;
|
||||
public bool SignAssembly { get; set; }
|
||||
public bool DelaySign { get; set; }
|
||||
|
||||
@@ -95,7 +99,7 @@ namespace Robust.Build.Tasks
|
||||
return rv;
|
||||
}
|
||||
|
||||
public IBuildEngine BuildEngine { get; set; }
|
||||
public ITaskHost HostObject { get; set; }
|
||||
public IBuildEngine BuildEngine { get; set; } = null!;
|
||||
public ITaskHost HostObject { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
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}))
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -55,9 +55,11 @@ namespace Robust.Build.Tasks
|
||||
public bool BuildProjectFile(string projectFileName, string[] targetNames, IDictionary globalProperties,
|
||||
IDictionary targetOutputs) => throw new NotSupportedException();
|
||||
|
||||
public bool ContinueOnError { get; }
|
||||
public int LineNumberOfTaskNode { get; }
|
||||
public int ColumnNumberOfTaskNode { get; }
|
||||
public string ProjectFileOfTaskNode { get; }
|
||||
// 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!;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,30 @@
|
||||
<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>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
</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>
|
||||
|
||||
@@ -1,389 +0,0 @@
|
||||
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; }
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,6 @@ 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!;
|
||||
@@ -49,9 +48,10 @@ 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,9 +110,16 @@ 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);
|
||||
@@ -254,6 +261,13 @@ 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;
|
||||
@@ -277,9 +291,6 @@ 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;
|
||||
@@ -332,7 +343,6 @@ 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)
|
||||
@@ -346,7 +356,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
}
|
||||
|
||||
// Max distance check
|
||||
delta = worldPos - listener.Position;
|
||||
var delta = worldPos - listener.Position;
|
||||
var distance = delta.Length();
|
||||
|
||||
// Out of range so just clip it for us.
|
||||
|
||||
@@ -26,6 +26,7 @@ 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;
|
||||
@@ -146,6 +147,16 @@ 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>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -579,7 +579,20 @@ namespace Robust.Client.Console.Commands
|
||||
private static string GetMemberValue(MemberInfo? member, Control control, string separator, string
|
||||
wrap = "{0}")
|
||||
{
|
||||
var value = member?.GetValue(control);
|
||||
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 o = value switch
|
||||
{
|
||||
ICollection<Control> controls => string.Join(separator,
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Robust.Client.Console.Commands
|
||||
|
||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var type = Type.GetType(args[0]);
|
||||
var type = GetType(args[0]);
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
@@ -25,6 +25,17 @@ namespace Robust.Client.Console.Commands
|
||||
shell.WriteLine(sig);
|
||||
}
|
||||
}
|
||||
|
||||
private Type? GetType(string name)
|
||||
{
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
if (assembly.GetType(name) is { } type)
|
||||
return type;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ 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;
|
||||
@@ -53,6 +54,8 @@ 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!;
|
||||
@@ -171,6 +174,8 @@ namespace Robust.Client
|
||||
_reflectionManager.Initialize();
|
||||
_prototypeManager.Initialize();
|
||||
_prototypeManager.LoadDefaultPrototypes();
|
||||
_xamlProxyManager.Initialize();
|
||||
_xamlHotReloadManager.Initialize();
|
||||
_userInterfaceManager.Initialize();
|
||||
_eyeManager.Initialize();
|
||||
_entityManager.Initialize();
|
||||
|
||||
@@ -26,6 +26,9 @@ 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();
|
||||
@@ -34,6 +37,20 @@ 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
|
||||
@@ -118,7 +135,10 @@ namespace Robust.Client.GameObjects
|
||||
var sequence = _stateMan.SystemMessageDispatched(msg);
|
||||
EntityNetManager?.SendSystemNetworkMessage(msg, sequence);
|
||||
|
||||
DebugTools.Assert(!_stateMan.IsPredictionEnabled || _gameTiming.InPrediction && _gameTiming.IsFirstTimePredicted || _client.RunLevel != ClientRunLevel.Connected);
|
||||
if (!_stateMan.IsPredictionEnabled && _client.RunLevel != ClientRunLevel.SinglePlayerGame)
|
||||
return;
|
||||
|
||||
DebugTools.Assert(_gameTiming.InPrediction && _gameTiming.IsFirstTimePredicted || _client.RunLevel == ClientRunLevel.SinglePlayerGame);
|
||||
|
||||
var eventArgs = new EntitySessionEventArgs(session!);
|
||||
EventBus.RaiseEvent(EventSource.Local, msg);
|
||||
|
||||
@@ -2,8 +2,11 @@ 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
|
||||
{
|
||||
@@ -11,6 +14,7 @@ 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()
|
||||
{
|
||||
@@ -74,10 +78,13 @@ 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");
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ 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;
|
||||
@@ -20,6 +21,7 @@ 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()
|
||||
@@ -102,7 +104,8 @@ internal sealed class ClientOccluderSystem : OccluderSystem
|
||||
|
||||
if (occluder.Enabled && xform.Anchored && TryComp(xform.GridUid, out grid))
|
||||
{
|
||||
pos = grid.TileIndicesFor(xform.Coordinates);
|
||||
gridId = xform.GridUid.Value;
|
||||
pos = _mapSystem.TileIndicesFor(gridId, grid, xform.Coordinates);
|
||||
_dirtyEntities.Add(sender);
|
||||
}
|
||||
else if (occluder.LastPosition != null)
|
||||
@@ -117,10 +120,10 @@ internal sealed class ClientOccluderSystem : OccluderSystem
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
private void DirtyNeighbours(AnchoredEntitiesEnumerator enumerator, EntityQuery<OccluderComponent> occluderQuery)
|
||||
@@ -166,7 +169,7 @@ internal sealed class ClientOccluderSystem : OccluderSystem
|
||||
return;
|
||||
}
|
||||
|
||||
var tile = grid.TileIndicesFor(xform.Coordinates);
|
||||
var tile = _mapSystem.TileIndicesFor(xform.GridUid.Value, grid, xform.Coordinates);
|
||||
|
||||
// TODO: Sub to parent changes instead or something.
|
||||
// DebugTools.Assert(occluder.LastPosition == null
|
||||
@@ -175,16 +178,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, grid, occluders, xforms);
|
||||
CheckDir(dir, OccluderDir.South, tile, occluder, xform.GridUid.Value, grid, occluders, xforms);
|
||||
|
||||
dir = dir.GetClockwise90Degrees();
|
||||
CheckDir(dir, OccluderDir.West, tile, occluder, grid, occluders, xforms);
|
||||
CheckDir(dir, OccluderDir.West, tile, occluder, xform.GridUid.Value, grid, occluders, xforms);
|
||||
|
||||
dir = dir.GetClockwise90Degrees();
|
||||
CheckDir(dir, OccluderDir.North, tile, occluder, grid, occluders, xforms);
|
||||
CheckDir(dir, OccluderDir.North, tile, occluder, xform.GridUid.Value, grid, occluders, xforms);
|
||||
|
||||
dir = dir.GetClockwise90Degrees();
|
||||
CheckDir(dir, OccluderDir.East, tile, occluder, grid, occluders, xforms);
|
||||
CheckDir(dir, OccluderDir.East, tile, occluder, xform.GridUid.Value, grid, occluders, xforms);
|
||||
}
|
||||
|
||||
private void CheckDir(
|
||||
@@ -192,6 +195,7 @@ internal sealed class ClientOccluderSystem : OccluderSystem
|
||||
OccluderDir occDir,
|
||||
Vector2i tile,
|
||||
OccluderComponent occluder,
|
||||
EntityUid gridUid,
|
||||
MapGridComponent grid,
|
||||
EntityQuery<OccluderComponent> query,
|
||||
EntityQuery<TransformComponent> xforms)
|
||||
@@ -199,7 +203,7 @@ internal sealed class ClientOccluderSystem : OccluderSystem
|
||||
if ((occluder.Occluding & occDir) != 0)
|
||||
return;
|
||||
|
||||
foreach (var neighbor in grid.GetAnchoredEntities(tile.Offset(dir)))
|
||||
foreach (var neighbor in _mapSystem.GetAnchoredEntities(gridUid, grid, tile.Offset(dir)))
|
||||
{
|
||||
if (!query.TryGetComponent(neighbor, out var otherOccluder) || !otherOccluder.Enabled)
|
||||
continue;
|
||||
|
||||
@@ -82,6 +82,7 @@ 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)
|
||||
@@ -89,13 +90,15 @@ namespace Robust.Client.GameObjects
|
||||
var worldMatrix = _transformSystem.GetWorldMatrix(grid);
|
||||
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);
|
||||
|
||||
while (chunkEnumerator.MoveNext(out var chunk))
|
||||
{
|
||||
foreach (var fixture in chunk.Fixtures.Values)
|
||||
foreach (var id in chunk.Fixtures)
|
||||
{
|
||||
var fixture = fixtures.Fixtures[id];
|
||||
var poly = (PolygonShape) fixture.Shape;
|
||||
|
||||
var verts = new Vector2[poly.VertexCount];
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -30,10 +30,12 @@ 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();
|
||||
|
||||
|
||||
@@ -1,8 +1,38 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Robust.Client.GameObjects;
|
||||
|
||||
public sealed class ViewSubscriberSystem : SharedViewSubscriberSystem;
|
||||
@@ -960,7 +960,7 @@ namespace Robust.Client.GameStates
|
||||
|
||||
// Initialize and start the newly created entities.
|
||||
if (_toCreate.Count > 0)
|
||||
InitializeAndStart(_toCreate);
|
||||
InitializeAndStart(_toCreate, metas, xforms);
|
||||
|
||||
_prof.WriteValue("State Size", ProfData.Int32(curSpan.Length));
|
||||
_prof.WriteValue("Entered PVS", ProfData.Int32(enteringPvs));
|
||||
@@ -1188,7 +1188,10 @@ namespace Robust.Client.GameStates
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeAndStart(Dictionary<NetEntity, EntityState> toCreate)
|
||||
private void InitializeAndStart(
|
||||
Dictionary<NetEntity, EntityState> toCreate,
|
||||
EntityQuery<MetaDataComponent> metas,
|
||||
EntityQuery<TransformComponent> xforms)
|
||||
{
|
||||
_toStart.Clear();
|
||||
|
||||
@@ -1197,22 +1200,8 @@ namespace Robust.Client.GameStates
|
||||
EntityUid entity = default;
|
||||
foreach (var netEntity in toCreate.Keys)
|
||||
{
|
||||
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
|
||||
}
|
||||
(entity, var meta) = _entityManager.GetEntityData(netEntity);
|
||||
InitializeRecursive(entity, meta, metas, xforms);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1244,6 +1233,44 @@ 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)
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
#if EXCEPTION_TOLERANCE_LOCAL
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorS("clyde.win", $"Error dispatching window event {ev.GetType().Name}:\n{e}");
|
||||
_sawmillWin.Error($"Error dispatching window event {ev.GetType().Name}:\n{e}");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ 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;
|
||||
@@ -15,8 +14,6 @@ namespace Robust.Client.Graphics.Clyde
|
||||
{
|
||||
internal partial class Clyde
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
private readonly Dictionary<EntityUid, Dictionary<Vector2i, MapChunkData>> _mapChunkData =
|
||||
new();
|
||||
|
||||
@@ -67,7 +64,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
}
|
||||
|
||||
var transform = _entityManager.GetComponent<TransformComponent>(mapGrid);
|
||||
gridProgram.SetUniform(UniIModelMatrix, transform.WorldMatrix);
|
||||
gridProgram.SetUniform(UniIModelMatrix, _transformSystem.GetWorldMatrix(transform));
|
||||
var enumerator = mapSystem.GetMapChunks(mapGrid.Owner, mapGrid.Comp, worldBounds);
|
||||
|
||||
while (enumerator.MoveNext(out var chunk))
|
||||
|
||||
@@ -9,6 +9,7 @@ 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;
|
||||
@@ -513,7 +514,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
if (_lightManager.Enabled && _lightManager.DrawHardFov && eye.DrawLight && eye.DrawFov)
|
||||
{
|
||||
var mapUid = _mapManager.GetMapEntityId(eye.Position.MapId);
|
||||
var mapUid = _mapSystem.GetMap(eye.Position.MapId);
|
||||
if (_entityManager.GetComponent<MapComponent>(mapUid).LightingEnabled)
|
||||
ApplyFovToBuffer(viewport, eye);
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
return resource.ClydeHandle;
|
||||
}
|
||||
|
||||
Logger.Warning($"Can't load shader {path}\n");
|
||||
_clydeSawmill.Warning($"Can't load shader {path}\n");
|
||||
return default;
|
||||
}
|
||||
|
||||
@@ -345,13 +345,12 @@ namespace Robust.Client.Graphics.Clyde
|
||||
return;
|
||||
|
||||
// If this map has lighting disabled, return
|
||||
var mapUid = _mapManager.GetMapEntityId(mapId);
|
||||
var mapUid = _mapSystem.GetMapOrInvalid(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"))
|
||||
@@ -541,7 +540,6 @@ namespace Robust.Client.Graphics.Clyde
|
||||
Clyde clyde,
|
||||
int count,
|
||||
int shadowCastingCount,
|
||||
TransformSystem xformSystem,
|
||||
EntityQuery<TransformComponent> xforms,
|
||||
Box2 worldAABB) state,
|
||||
in ComponentTreeEntry<PointLightComponent> value)
|
||||
@@ -554,7 +552,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
return false;
|
||||
|
||||
var (light, transform) = value;
|
||||
var (lightPos, rot) = state.xformSystem.GetWorldPositionRotation(transform, state.xforms);
|
||||
var (lightPos, rot) = state.clyde._transformSystem.GetWorldPositionRotation(transform, state.xforms);
|
||||
lightPos += rot.RotateVec(light.Offset);
|
||||
var circle = new Circle(lightPos, light.Radius);
|
||||
|
||||
@@ -600,16 +598,13 @@ 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, xformSystem, xforms, worldAABB);
|
||||
var state = (this, count: 0, shadowCastingCount: 0, xforms, worldAABB);
|
||||
|
||||
foreach (var (uid, comp) in lightTreeSys.GetIntersectingTrees(map, worldAABB))
|
||||
foreach (var (uid, comp) in _lightTreeSystem.GetIntersectingTrees(map, worldAABB))
|
||||
{
|
||||
var bounds = xformSystem.GetInvWorldMatrix(uid, xforms).TransformBox(worldBounds);
|
||||
var bounds = _transformSystem.GetInvWorldMatrix(uid, xforms).TransformBox(worldBounds);
|
||||
comp.Tree.QueryAabb(ref state, LightQuery, bounds);
|
||||
}
|
||||
|
||||
@@ -941,18 +936,16 @@ 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 = xforms.GetComponent(uid).InvWorldMatrix.TransformBox(expandedBounds);
|
||||
var treeBounds = _transformSystem.GetInvWorldMatrix(uid).TransformBox(expandedBounds);
|
||||
|
||||
comp.Tree.QueryAabb((in ComponentTreeEntry<OccluderComponent> entry) =>
|
||||
{
|
||||
@@ -965,7 +958,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
if (ami >= amiMax)
|
||||
return false;
|
||||
|
||||
var worldTransform = xformSystem.GetWorldMatrix(transform, xforms);
|
||||
var worldTransform = _transformSystem.GetWorldMatrix(transform, xforms);
|
||||
var box = occluder.BoundingBox;
|
||||
|
||||
var tl = Vector2.Transform(box.TopLeft, worldTransform);
|
||||
|
||||
@@ -496,6 +496,9 @@ 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;
|
||||
|
||||
@@ -506,6 +506,14 @@ 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];
|
||||
|
||||
@@ -61,12 +61,11 @@ 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 _entitySystemManager.GetEntitySystem<SpriteTreeSystem>().GetIntersectingTrees(map, worldBounds))
|
||||
foreach (var (treeOwner, comp) in _spriteTreeSystem.GetIntersectingTrees(map, worldBounds))
|
||||
{
|
||||
var treeXform = query.GetComponent(treeOwner);
|
||||
var bounds = xformSystem.GetInvWorldMatrix(treeOwner).TransformBox(worldBounds);
|
||||
var bounds = _transformSystem.GetInvWorldMatrix(treeOwner).TransformBox(worldBounds);
|
||||
DebugTools.Assert(treeXform.MapUid == treeXform.ParentUid || !treeXform.ParentUid.IsValid());
|
||||
|
||||
treeData = treeData with
|
||||
|
||||
39
Robust.Client/Graphics/Clyde/Clyde.Systems.cs
Normal file
39
Robust.Client/Graphics/Clyde/Clyde.Systems.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
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!;
|
||||
}
|
||||
}
|
||||
@@ -188,7 +188,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
{
|
||||
if (!TryInitMainWindow(glSpec, out lastError))
|
||||
{
|
||||
Logger.DebugS("clyde.win", $"OpenGL {glSpec.OpenGLVersion} unsupported: {lastError}");
|
||||
_sawmillWin.Debug($"OpenGL {glSpec.OpenGLVersion} unsupported: {lastError}");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
else
|
||||
{
|
||||
if (!TryInitMainWindow(null, out lastError))
|
||||
Logger.DebugS("clyde.win", $"Failed to create window: {lastError}");
|
||||
_sawmillWin.Debug($"Failed to create window: {lastError}");
|
||||
else
|
||||
succeeded = true;
|
||||
}
|
||||
@@ -230,8 +230,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
}
|
||||
}
|
||||
|
||||
Logger.FatalS("clyde.win",
|
||||
"Failed to create main game window! " +
|
||||
_sawmillWin.Fatal("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}");
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ 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;
|
||||
@@ -46,6 +47,7 @@ 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!;
|
||||
@@ -78,6 +80,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
private ISawmill _clydeSawmill = default!;
|
||||
private ISawmill _sawmillOgl = default!;
|
||||
private ISawmill _sawmillWin = default!;
|
||||
|
||||
private IBindingsContext _glBindingsContext = default!;
|
||||
private bool _earlyGLInit;
|
||||
@@ -94,6 +97,7 @@ 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);
|
||||
@@ -122,6 +126,8 @@ namespace Robust.Client.Graphics.Clyde
|
||||
{
|
||||
_gameThread = Thread.CurrentThread;
|
||||
|
||||
InitSystems();
|
||||
|
||||
InitGLContextManager();
|
||||
if (!InitMainWindowAndRenderer())
|
||||
return false;
|
||||
|
||||
@@ -361,6 +361,10 @@ namespace Robust.Client.Graphics.Clyde
|
||||
{
|
||||
}
|
||||
|
||||
private protected override void SetParameterImpl(string name, bool[] value)
|
||||
{
|
||||
}
|
||||
|
||||
private protected override void SetParameterImpl(string name, in Matrix3x2 value)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ 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;
|
||||
@@ -58,6 +60,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
public GLContextAngle(Clyde clyde) : base(clyde)
|
||||
{
|
||||
_sawmill = clyde._logManager.GetSawmill("clyde.ogl.angle");
|
||||
}
|
||||
|
||||
public override GLContextSpec? SpecWithOpenGLVersion(RendererOpenGLVersion version)
|
||||
@@ -187,7 +190,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorS("clyde.ogl.angle", $"Failed to initialize custom ANGLE: {e}");
|
||||
_sawmill.Error($"Failed to initialize custom ANGLE: {e}");
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
@@ -207,7 +210,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
private void TryInitializeCore()
|
||||
{
|
||||
var extensions = Marshal.PtrToStringUTF8((nint) eglQueryString(null, EGL_EXTENSIONS));
|
||||
Logger.DebugS("clyde.ogl.angle", $"EGL client extensions: {extensions}!");
|
||||
_sawmill.Debug($"EGL client extensions: {extensions}!");
|
||||
|
||||
CreateD3D11Device();
|
||||
CreateEglContext();
|
||||
@@ -232,10 +235,10 @@ namespace Robust.Client.Graphics.Clyde
|
||||
var version = Marshal.PtrToStringUTF8((nint) eglQueryString(_eglDisplay, EGL_VERSION));
|
||||
var extensions = Marshal.PtrToStringUTF8((nint) eglQueryString(_eglDisplay, EGL_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}!");
|
||||
_sawmill.Debug("EGL initialized!");
|
||||
_sawmill.Debug($"EGL vendor: {vendor}!");
|
||||
_sawmill.Debug($"EGL version: {version}!");
|
||||
_sawmill.Debug($"EGL extensions: {extensions}!");
|
||||
|
||||
if (eglBindAPI(EGL_OPENGL_ES_API) != EGL_TRUE)
|
||||
throw new Exception("eglBindAPI failed.");
|
||||
@@ -262,11 +265,11 @@ namespace Robust.Client.Graphics.Clyde
|
||||
if (numConfigs == 0)
|
||||
throw new Exception("No compatible EGL configurations returned!");
|
||||
|
||||
Logger.DebugS("clyde.ogl.angle", $"{numConfigs} EGL configs possible!");
|
||||
_sawmill.Debug($"{numConfigs} EGL configs possible!");
|
||||
|
||||
for (var i = 0; i < numConfigs; i++)
|
||||
{
|
||||
Logger.DebugS("clyde.ogl.angle", DumpEglConfig(_eglDisplay, configs[i]));
|
||||
_sawmill.Debug(DumpEglConfig(_eglDisplay, configs[i]));
|
||||
}
|
||||
|
||||
_eglConfig = configs[0];
|
||||
@@ -286,7 +289,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
if (_eglContext == (void*) EGL_NO_CONTEXT)
|
||||
throw new Exception("eglCreateContext failed!");
|
||||
|
||||
Logger.DebugS("clyde.ogl.angle", "EGL context created!");
|
||||
_sawmill.Debug("EGL context created!");
|
||||
|
||||
Clyde._openGLVersion = _es3 ? RendererOpenGLVersion.GLES3 : RendererOpenGLVersion.GLES2;
|
||||
}
|
||||
@@ -311,11 +314,10 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
if (_adapter == null)
|
||||
{
|
||||
Logger.WarningS("clyde.ogl.angle",
|
||||
$"Unable to find display adapter with requested name: {adapterName}");
|
||||
_sawmill.Warning($"Unable to find display adapter with requested name: {adapterName}");
|
||||
}
|
||||
|
||||
Logger.DebugS("clyde.ogl.angle", $"Found display adapter with name: {adapterName}");
|
||||
_sawmill.Debug($"Found display adapter with name: {adapterName}");
|
||||
}
|
||||
|
||||
#pragma warning disable CA1416
|
||||
@@ -415,9 +417,9 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
var descName = ((ReadOnlySpan<char>)desc.Description).TrimEnd('\0');
|
||||
|
||||
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}");
|
||||
_sawmill.Debug("Successfully created D3D11 device!");
|
||||
_sawmill.Debug($"D3D11 Device Adapter: {descName.ToString()}");
|
||||
_sawmill.Debug($"D3D11 Device FL: {_deviceFl}");
|
||||
|
||||
if (_deviceFl == D3D_FEATURE_LEVEL_9_1)
|
||||
{
|
||||
|
||||
@@ -22,6 +22,8 @@ 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;
|
||||
@@ -30,6 +32,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
public GLContextEgl(Clyde clyde) : base(clyde)
|
||||
{
|
||||
_sawmill = clyde._logManager.GetSawmill("clyde.ogl.egl");
|
||||
}
|
||||
|
||||
public override GLContextSpec? SpecWithOpenGLVersion(RendererOpenGLVersion version)
|
||||
@@ -47,7 +50,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
public void InitializePublic()
|
||||
{
|
||||
var extensions = Marshal.PtrToStringUTF8((nint) eglQueryString(null, EGL_EXTENSIONS));
|
||||
Logger.DebugS("clyde.ogl.egl", $"EGL client extensions: {extensions}!");
|
||||
_sawmill.Debug($"EGL client extensions: {extensions}!");
|
||||
}
|
||||
|
||||
public override void WindowCreated(GLContextSpec? spec, WindowReg reg)
|
||||
@@ -133,10 +136,10 @@ namespace Robust.Client.Graphics.Clyde
|
||||
var version = Marshal.PtrToStringUTF8((nint) eglQueryString(_eglDisplay, EGL_VERSION));
|
||||
var extensions = Marshal.PtrToStringUTF8((nint) eglQueryString(_eglDisplay, EGL_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}!");
|
||||
_sawmill.Debug("EGL initialized!");
|
||||
_sawmill.Debug($"EGL vendor: {vendor}!");
|
||||
_sawmill.Debug($"EGL version: {version}!");
|
||||
_sawmill.Debug($"EGL extensions: {extensions}!");
|
||||
|
||||
if (eglBindAPI(EGL_OPENGL_ES_API) != EGL_TRUE)
|
||||
throw new Exception("eglBindAPI failed.");
|
||||
@@ -164,11 +167,11 @@ namespace Robust.Client.Graphics.Clyde
|
||||
if (numConfigs == 0)
|
||||
throw new Exception("No compatible EGL configurations returned!");
|
||||
|
||||
Logger.DebugS("clyde.ogl.egl", $"{numConfigs} EGL configs possible!");
|
||||
_sawmill.Debug($"{numConfigs} EGL configs possible!");
|
||||
|
||||
for (var i = 0; i < numConfigs; i++)
|
||||
{
|
||||
Logger.DebugS("clyde.ogl.egl", DumpEglConfig(_eglDisplay, configs[i]));
|
||||
_sawmill.Debug(DumpEglConfig(_eglDisplay, configs[i]));
|
||||
}
|
||||
|
||||
_eglConfig = configs[0];
|
||||
@@ -183,7 +186,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
if (_eglContext == (void*) EGL_NO_CONTEXT)
|
||||
throw new Exception("eglCreateContext failed!");
|
||||
|
||||
Logger.DebugS("clyde.ogl.egl", "EGL context created!");
|
||||
_sawmill.Debug("EGL context created!");
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
|
||||
@@ -418,6 +418,37 @@ 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);
|
||||
|
||||
@@ -224,7 +224,8 @@ namespace Robust.Client.Graphics
|
||||
// TODO: add support for int, and vec3/4 arrays
|
||||
return
|
||||
(type == ShaderDataType.Float) ||
|
||||
(type == ShaderDataType.Vec2);
|
||||
(type == ShaderDataType.Vec2) ||
|
||||
(type == ShaderDataType.Bool);
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "StringLiteralTypo")]
|
||||
|
||||
@@ -148,6 +148,13 @@ 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();
|
||||
@@ -219,6 +226,7 @@ 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);
|
||||
|
||||
@@ -21,9 +21,12 @@ using SixLabors.ImageSharp.PixelFormats;
|
||||
|
||||
namespace Robust.Client.Map
|
||||
{
|
||||
internal sealed class ClydeTileDefinitionManager : TileDefinitionManager, IClydeTileDefinitionManager
|
||||
internal sealed class ClydeTileDefinitionManager : TileDefinitionManager, IClydeTileDefinitionManager, IPostInjectInit
|
||||
{
|
||||
[Dependency] private readonly IResourceManager _manager = default!;
|
||||
[Dependency] private readonly ILogManager _logManager = default!;
|
||||
|
||||
private ISawmill _sawmill = default!;
|
||||
|
||||
private Texture? _tileTextureAtlas;
|
||||
|
||||
@@ -98,8 +101,7 @@ namespace Robust.Client.Map
|
||||
if (imgWidth >= 2048 || imgHeight >= 2048)
|
||||
{
|
||||
// Sanity warning, some machines don't have textures larger than this and need multiple atlases.
|
||||
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.");
|
||||
_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.");
|
||||
}
|
||||
|
||||
var column = 1;
|
||||
@@ -151,6 +153,11 @@ namespace Robust.Client.Map
|
||||
|
||||
_tileTextureAtlas = Texture.LoadFromImage(sheet, "Tile Atlas");
|
||||
}
|
||||
|
||||
void IPostInjectInit.PostInject()
|
||||
{
|
||||
_sawmill = _logManager.GetSawmill("clyde");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ReloadTileTexturesCommand : LocalizedCommands
|
||||
|
||||
@@ -167,7 +167,6 @@ 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);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,10 @@
|
||||
<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\*" />
|
||||
|
||||
33
Robust.Client/UserInterface/BoundUserInterfaceExt.cs
Normal file
33
Robust.Client/UserInterface/BoundUserInterfaceExt.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -602,6 +602,7 @@ 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)
|
||||
@@ -613,6 +614,7 @@ 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)
|
||||
|
||||
@@ -44,9 +44,12 @@ namespace Robust.Client.UserInterface.Controls
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
_message?.Clear();
|
||||
else
|
||||
_message?.AddMarkupPermissive(value);
|
||||
return;
|
||||
}
|
||||
|
||||
SetMessage(FormattedMessage.FromMarkupPermissive(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -191,6 +191,19 @@ 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)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -235,6 +236,15 @@ 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>
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace Robust.Client.UserInterface.CustomControls.DebugMonitorControls
|
||||
}
|
||||
else
|
||||
{
|
||||
mouseGridPos = new EntityCoordinates(_mapManager.GetMapEntityId(mouseWorldMap.MapId),
|
||||
mouseGridPos = new EntityCoordinates(mapSystem.GetMapOrInvalid(mouseWorldMap.MapId),
|
||||
mouseWorldMap.Position);
|
||||
tile = new TileRef(EntityUid.Invalid,
|
||||
mouseGridPos.ToVector2i(_entityManager, _mapManager, xformSystem), Tile.Empty);
|
||||
|
||||
@@ -29,7 +29,7 @@ public sealed class EntitySpawnButton : Control
|
||||
{
|
||||
(EntityTextureRects = new EntityPrototypeView
|
||||
{
|
||||
MinSize = new Vector2(32, 32),
|
||||
SetSize = new Vector2(32, 32),
|
||||
HorizontalAlignment = HAlignment.Center,
|
||||
VerticalAlignment = VAlignment.Center,
|
||||
Stretch = SpriteView.StretchMode.Fill
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Robust.Client.UserInterface
|
||||
|
||||
IDebugMonitors DebugMonitors { get; }
|
||||
|
||||
void Popup(string contents, string title = "Alert!");
|
||||
void Popup(string contents, string? title = null, bool clipboardButton = true);
|
||||
|
||||
Control? MouseGetControl(ScreenCoordinates coordinates);
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using Robust.Client.State;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -7,11 +8,12 @@ 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 reflection = IoCManager.Resolve<IReflectionManager>();
|
||||
var types = reflection.GetAllChildren(typeof(State.State));
|
||||
var types = _reflection.GetAllChildren(typeof(State.State));
|
||||
|
||||
foreach (var tryType in types)
|
||||
{
|
||||
@@ -26,5 +28,13 @@ 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]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ internal partial class UserInterfaceManager
|
||||
var newHovered = MouseGetControl(mouseMoveEventArgs.Position);
|
||||
SetHovered(newHovered);
|
||||
|
||||
var target = ControlFocused ?? newHovered;
|
||||
var target = ControlFocused ?? CurrentlyHovered;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ 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;
|
||||
@@ -53,14 +54,47 @@ internal sealed partial class UserInterfaceManager
|
||||
}
|
||||
}
|
||||
|
||||
public void Popup(string contents, string title = "Alert!")
|
||||
public void Popup(string contents, string? title = null, bool clipboardButton = true)
|
||||
{
|
||||
var popup = new DefaultWindow
|
||||
{
|
||||
Title = title
|
||||
Title = string.IsNullOrEmpty(title) ? Loc.GetString("popup-title") : title,
|
||||
};
|
||||
|
||||
popup.Contents.AddChild(new Label {Text = contents});
|
||||
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.OpenCentered();
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ 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;
|
||||
@@ -214,6 +215,9 @@ 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);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
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();
|
||||
}
|
||||
11
Robust.Client/UserInterface/XAML/Proxy/IXamlProxyHelper.cs
Normal file
11
Robust.Client/UserInterface/XAML/Proxy/IXamlProxyHelper.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
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);
|
||||
}
|
||||
76
Robust.Client/UserInterface/XAML/Proxy/IXamlProxyManager.cs
Normal file
76
Robust.Client/UserInterface/XAML/Proxy/IXamlProxyManager.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
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);
|
||||
}
|
||||
195
Robust.Client/UserInterface/XAML/Proxy/XamlHotReloadManager.cs
Normal file
195
Robust.Client/UserInterface/XAML/Proxy/XamlHotReloadManager.cs
Normal file
@@ -0,0 +1,195 @@
|
||||
#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
|
||||
@@ -0,0 +1,15 @@
|
||||
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()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
#if TOOLS
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Xaml;
|
||||
|
||||
namespace Robust.Client.UserInterface.XAML.Proxy;
|
||||
|
||||
/// <summary>
|
||||
/// This is a utility class that tracks the relationship between resource file names,
|
||||
/// Xamlx-compatible <see cref="Uri"/>s, <see cref="Type"/>s that are interested in a
|
||||
/// given file, and implementations of Populate.
|
||||
/// </summary>
|
||||
internal sealed class XamlImplementationStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// For each filename, we store its last known <see cref="Uri"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When we compile the new implementation, we will use the same <see cref="Uri"/>.
|
||||
/// </remarks>
|
||||
private readonly Dictionary<string, Uri> _fileUri = new();
|
||||
|
||||
/// <summary>
|
||||
/// For each filename, we store its last known content.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is known even for AOT-compiled code -- therefore, we can use this table
|
||||
/// to convert an AOT-compiled Control to a JIT-compiled one.
|
||||
/// </remarks>
|
||||
private readonly Dictionary<string, string> _fileContent = new();
|
||||
|
||||
/// <summary>
|
||||
/// For each filename, we store the type interested in this file.
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, Type> _fileType = new();
|
||||
|
||||
/// <summary>
|
||||
/// For each type, store the JIT-compiled implementation of Populate.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If no such implementation exists, then methods that would normally
|
||||
/// find and call a JIT'ed implementation will do nothing and return
|
||||
/// false instead. As an ultimate result, the AOT'ed implementation
|
||||
/// will be used.
|
||||
/// </remarks>
|
||||
private readonly Dictionary<Type, MethodInfo> _populateImplementations = new();
|
||||
|
||||
private readonly ISawmill _sawmill;
|
||||
private readonly XamlJitDelegate _jitDelegate;
|
||||
|
||||
/// <summary>
|
||||
/// Create the storage.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// It would be weird to call this from any type outside of
|
||||
/// <see cref="Robust.Client.UserInterface.XAML.Proxy" />.
|
||||
/// </remarks>
|
||||
/// <param name="sawmill">the (shared) logger</param>
|
||||
/// <param name="jitDelegate">
|
||||
/// a delegate that calls the
|
||||
/// <see cref="XamlJitCompiler"/>, possibly handling errors
|
||||
/// </param>
|
||||
public XamlImplementationStorage(ISawmill sawmill, XamlJitDelegate jitDelegate)
|
||||
{
|
||||
_sawmill = sawmill;
|
||||
_jitDelegate = jitDelegate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inspect <paramref name="assembly" /> for types that declare a <see cref="XamlMetadataAttribute"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// We can only do hot reloading if we know this basic information.
|
||||
///
|
||||
/// Note that even release-mode content artifacts contain this attribute.
|
||||
/// </remarks>
|
||||
/// <param name="assembly">the assembly</param>
|
||||
/// <returns>an IEnumerable of types with xaml metadata</returns>
|
||||
private IEnumerable<(Type, XamlMetadataAttribute)> TypesWithXamlMetadata(Assembly assembly)
|
||||
{
|
||||
foreach (var type in assembly.GetTypes())
|
||||
{
|
||||
if (type.GetCustomAttribute<XamlMetadataAttribute>() is not { } attr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
yield return (type, attr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add all Xaml-annotated types from <paramref name="assembly" /> to this storage.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// We don't JIT these types, but we store enough info that we could JIT
|
||||
/// them if we wanted to.
|
||||
/// </remarks>
|
||||
/// <param name="assembly">an assembly</param>
|
||||
public void Add(Assembly assembly)
|
||||
{
|
||||
foreach (var (type, metadata) in TypesWithXamlMetadata(assembly))
|
||||
{
|
||||
// this can fail, but if it does, that means something is _really_ wrong
|
||||
// with the compiler, or someone tried to write their own Xaml metadata
|
||||
Uri uri;
|
||||
try
|
||||
{
|
||||
uri = new Uri(metadata.Uri);
|
||||
}
|
||||
catch (UriFormatException)
|
||||
{
|
||||
throw new InvalidProgramException(
|
||||
$"XamlImplementationStorage encountered an malformed Uri in the metadata for {type.FullName}: " +
|
||||
$"{metadata.Uri}. this is a bug in XamlAotCompiler"
|
||||
);
|
||||
}
|
||||
|
||||
var fileName = metadata.FileName;
|
||||
var content = metadata.Content;
|
||||
|
||||
_fileUri[fileName] = uri;
|
||||
_fileContent[fileName] = content;
|
||||
|
||||
if (!_fileType.TryAdd(fileName, type))
|
||||
{
|
||||
throw new InvalidProgramException(
|
||||
$"XamlImplementationStorage observed that two types were interested in the same Xaml filename: " +
|
||||
$"{fileName}. ({type.FullName} and {_fileType[fileName].FullName}). this is a bug in XamlAotCompiler"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Quietly JIT every type with XAML metadata.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This should have no visible effect except that the <see cref="XamlJitDelegate"/>
|
||||
/// may dump some info messages into the terminal about cases where the
|
||||
/// hot reload failed.
|
||||
/// </remarks>
|
||||
public void ForceReloadAll()
|
||||
{
|
||||
foreach (var (fileName, fileContent) in _fileContent)
|
||||
{
|
||||
SetImplementation(fileName, fileContent, true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return true if calling <see cref="SetImplementation" /> on <paramref name="fileName" /> would not be a no-op.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// That is: if some type cares about the contents of <paramref name="fileName" />.
|
||||
/// </remarks>
|
||||
/// <param name="fileName">the filename</param>
|
||||
/// <returns>true if not a no-op</returns>
|
||||
public bool CanSetImplementation(string fileName)
|
||||
{
|
||||
return _fileType.ContainsKey(fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace the implementation of <paramref name="fileName"/> by JIT-ing
|
||||
/// <paramref name="fileContent"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If nothing cares about the implementation of <paramref name="fileName"/>, then this will do nothing.
|
||||
/// </remarks>
|
||||
/// <param name="fileName">the name of the file whose implementation should be replaced</param>
|
||||
/// <param name="fileContent">the new implementation</param>
|
||||
/// <param name="quiet">if true, then don't bother to log</param>
|
||||
public void SetImplementation(string fileName, string fileContent, bool quiet)
|
||||
{
|
||||
if (!_fileType.TryGetValue(fileName, out var type))
|
||||
{
|
||||
_sawmill.Warning($"SetImplementation called with {fileName}, but no types care about its contents");
|
||||
return;
|
||||
}
|
||||
|
||||
var uri =
|
||||
_fileUri.GetValueOrDefault(fileName) ??
|
||||
throw new InvalidProgramException("file URI missing (this is a bug in ImplementationStorage)");
|
||||
|
||||
if (!quiet)
|
||||
{
|
||||
_sawmill.Debug($"replacing {fileName} for {type}");
|
||||
}
|
||||
var impl = _jitDelegate(type, uri, fileName, fileContent);
|
||||
if (impl != null)
|
||||
{
|
||||
_populateImplementations[type] = impl;
|
||||
}
|
||||
_fileContent[fileName] = fileContent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Call the JITed implementation of Populate on a XAML-associated object <paramref name="o"/>.
|
||||
///
|
||||
/// If no JITed implementation exists, return false.
|
||||
/// </summary>
|
||||
/// <param name="t">the static type of <paramref name="o"/></param>
|
||||
/// <param name="o">an instance of <paramref name="t"/> (can be a subclass)</param>
|
||||
/// <returns>true if a JITed implementation existed</returns>
|
||||
public bool Populate(Type t, object o)
|
||||
{
|
||||
if (!_populateImplementations.TryGetValue(t, out var implementation))
|
||||
{
|
||||
// pop out if we never JITed anything
|
||||
return false;
|
||||
}
|
||||
|
||||
implementation.Invoke(null, [null, o]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
17
Robust.Client/UserInterface/XAML/Proxy/XamlJitDelegate.cs
Normal file
17
Robust.Client/UserInterface/XAML/Proxy/XamlJitDelegate.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Robust.Client.UserInterface.XAML.Proxy;
|
||||
|
||||
/// <summary>
|
||||
/// This callback has the approximate type of <see cref="Robust.Xaml.XamlJitCompiler.Compile"/>,
|
||||
/// but it has no error-signaling faculty.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Implementors of this delegate should inform the users of errors in their own way.
|
||||
///
|
||||
/// Hot reloading failures should not directly take down the process, so implementors
|
||||
/// should not rethrow exceptions unless they have a strong reason to believe they
|
||||
/// will be caught.
|
||||
/// </remarks>
|
||||
internal delegate MethodInfo? XamlJitDelegate(Type type, Uri uri, string filename, string content);
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
|
||||
namespace Robust.Client.UserInterface.XAML.Proxy;
|
||||
|
||||
/// <summary>
|
||||
/// Metadata to support JIT compilation of XAML resources for a type.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// We can feed XamlX data from this type, along with new content, to get new XAML
|
||||
/// resources.
|
||||
///
|
||||
/// This type is inert and is generated for release artifacts too, not just debug
|
||||
/// artifacts. Released content should support hot reloading if loaded in a debug
|
||||
/// client, but this is untested.
|
||||
/// </remarks>
|
||||
[AttributeUsage(validOn: AttributeTargets.Class, Inherited = false)]
|
||||
public sealed class XamlMetadataAttribute: System.Attribute
|
||||
{
|
||||
public readonly string Uri;
|
||||
public readonly string FileName;
|
||||
public readonly string Content;
|
||||
|
||||
public XamlMetadataAttribute(string uri, string fileName, string content)
|
||||
{
|
||||
Uri = uri;
|
||||
FileName = fileName;
|
||||
Content = content;
|
||||
}
|
||||
}
|
||||
14
Robust.Client/UserInterface/XAML/Proxy/XamlProxyHelper.cs
Normal file
14
Robust.Client/UserInterface/XAML/Proxy/XamlProxyHelper.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Robust.Client.UserInterface.XAML.Proxy;
|
||||
|
||||
internal sealed class XamlProxyHelper: IXamlProxyHelper
|
||||
{
|
||||
[Dependency] private IXamlProxyManager _xamlProxyManager = default!;
|
||||
|
||||
public bool Populate(Type t, object o)
|
||||
{
|
||||
return _xamlProxyManager.Populate(t, o);
|
||||
}
|
||||
}
|
||||
127
Robust.Client/UserInterface/XAML/Proxy/XamlProxyManager.cs
Normal file
127
Robust.Client/UserInterface/XAML/Proxy/XamlProxyManager.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
#if TOOLS
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Xaml;
|
||||
|
||||
namespace Robust.Client.UserInterface.XAML.Proxy;
|
||||
|
||||
/// <summary>
|
||||
/// The real implementation of <see cref="IXamlProxyManager"/>.
|
||||
/// </summary>
|
||||
public sealed class XamlProxyManager: IXamlProxyManager
|
||||
{
|
||||
ISawmill _sawmill = null!;
|
||||
[Dependency] IReflectionManager _reflectionManager = null!;
|
||||
[Dependency] ILogManager _logManager = null!;
|
||||
|
||||
XamlImplementationStorage _xamlImplementationStorage = null!;
|
||||
|
||||
List<Assembly> _knownAssemblies = [];
|
||||
XamlJitCompiler? _xamlJitCompiler;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize this, subscribing to assembly changes.
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
_sawmill = _logManager.GetSawmill("xamlhotreload");
|
||||
_xamlImplementationStorage = new XamlImplementationStorage(_sawmill, Compile);
|
||||
|
||||
AddAssemblies();
|
||||
_reflectionManager.OnAssemblyAdded += (_, _) => { AddAssemblies(); };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return true if setting the implementation of <paramref name="fileName" />
|
||||
/// would not be a no-op.
|
||||
/// </summary>
|
||||
/// <param name="fileName">the file name</param>
|
||||
/// <returns>true or false</returns>
|
||||
public bool CanSetImplementation(string fileName)
|
||||
{
|
||||
return _xamlImplementationStorage.CanSetImplementation(fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace the implementation of <paramref name="fileName" />, failing
|
||||
/// silently if the new content does not compile. (but still logging)
|
||||
/// </summary>
|
||||
/// <param name="fileName">the file name</param>
|
||||
/// <param name="fileContent">the new content</param>
|
||||
public void SetImplementation(string fileName, string fileContent)
|
||||
{
|
||||
_xamlImplementationStorage.SetImplementation(fileName, fileContent, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add all the types from all known assemblies, then force-JIT everything
|
||||
/// again.
|
||||
/// </summary>
|
||||
private void AddAssemblies()
|
||||
{
|
||||
foreach (var a in _reflectionManager.Assemblies)
|
||||
{
|
||||
if (!_knownAssemblies.Contains(a))
|
||||
{
|
||||
_knownAssemblies.Add(a);
|
||||
_xamlImplementationStorage.Add(a);
|
||||
|
||||
_xamlJitCompiler = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Always use the JITed versions on debug builds
|
||||
_xamlImplementationStorage.ForceReloadAll();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Populate <paramref name="o" /> using the JIT compiler, if possible.
|
||||
/// </summary>
|
||||
/// <param name="t">the static type of <paramref name="o" /></param>
|
||||
/// <param name="o">a <paramref name="t" /> instance or subclass</param>
|
||||
/// <returns>true if there was a JITed implementation</returns>
|
||||
public bool Populate(Type t, object o)
|
||||
{
|
||||
return _xamlImplementationStorage.Populate(t, o);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls <see cref="XamlJitCompiler.Compile"/> using a stored
|
||||
/// <see cref="XamlJitCompiler"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="t">the <see cref="Type"/> that cares about this Xaml</param>
|
||||
/// <param name="uri">the <see cref="Uri" /> of this xaml (from the type's metadata)</param>
|
||||
/// <param name="fileName">the filename of this xaml (from the type's metadata)</param>
|
||||
/// <param name="content">the new content of the xaml file</param>
|
||||
/// <returns>the MethodInfo for the new JITed implementation</returns>
|
||||
private MethodInfo? Compile(Type t, Uri uri, string fileName, string content)
|
||||
{
|
||||
// initialize XamlJitCompiler lazily because constructing it has
|
||||
// very high CPU cost
|
||||
XamlJitCompiler xjit;
|
||||
lock(this)
|
||||
{
|
||||
xjit = _xamlJitCompiler ??= new XamlJitCompiler();
|
||||
}
|
||||
|
||||
var result = xjit.Compile(t, uri, fileName, content);
|
||||
|
||||
if (result is XamlJitCompilerResult.Error e)
|
||||
{
|
||||
_sawmill.Info($"hot reloading failed: {t.FullName}; {fileName}; {e.Raw.Message} {e.Hint ?? ""}");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (result is XamlJitCompilerResult.Success s)
|
||||
{
|
||||
return s.MethodInfo;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException($"totally unexpected result from compiler operation: {result}");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
|
||||
namespace Robust.Client.UserInterface.XAML.Proxy;
|
||||
|
||||
/// <summary>
|
||||
/// The stub implementation of <see cref="IXamlProxyManager"/>.
|
||||
/// </summary>
|
||||
public sealed class XamlProxyManagerStub: IXamlProxyManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Do nothing.
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return false. Nothing is ever interested in a Xaml content update when
|
||||
/// hot reloading is off.
|
||||
/// </summary>
|
||||
/// <param name="fileName">the filename</param>
|
||||
/// <returns>false</returns>
|
||||
public bool CanSetImplementation(string fileName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Do nothing. A hot reload will always silently fail if hot reloading is off.
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="fileContent"></param>
|
||||
public void SetImplementation(string fileName, string fileContent)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return false.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// There will never be a JIT-ed implementation of Populate if hot reloading is off.
|
||||
/// </remarks>
|
||||
/// <param name="t">the static type of <paramref name="o" /></param>
|
||||
/// <param name="o">an instance of <paramref name="t" /> or a subclass</param>
|
||||
/// <returns>false</returns>
|
||||
public bool Populate(Type t, object o)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,16 @@ namespace Robust.Client.ViewVariables.Editors
|
||||
{
|
||||
internal sealed class VVPropEditorReference : VVPropEditor
|
||||
{
|
||||
[Dependency] private readonly IClientViewVariablesManager _vvMan = default!;
|
||||
|
||||
private object? _localValue;
|
||||
private ViewVariablesObjectSelector? _selector;
|
||||
|
||||
public VVPropEditorReference()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
protected override Control MakeUI(object? value)
|
||||
{
|
||||
if (value == null)
|
||||
@@ -36,14 +43,13 @@ namespace Robust.Client.ViewVariables.Editors
|
||||
|
||||
private void ButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
var vvm = IoCManager.Resolve<IClientViewVariablesManager>();
|
||||
if (_selector != null)
|
||||
{
|
||||
vvm.OpenVV(_selector);
|
||||
_vvMan.OpenVV(_selector);
|
||||
}
|
||||
else if (_localValue != null)
|
||||
{
|
||||
vvm.OpenVV(_localValue);
|
||||
_vvMan.OpenVV(_localValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ public static class Diagnostics
|
||||
public const string IdMustCallBase = "RA0028";
|
||||
public const string IdDataFieldNoVVReadWrite = "RA0029";
|
||||
public const string IdUseNonGenericVariant = "RA0030";
|
||||
public const string IdPreferOtherType = "RA0031";
|
||||
|
||||
public static SuppressionDescriptor MeansImplicitAssignment =>
|
||||
new SuppressionDescriptor("RADC1000", "CS0649", "Marked as implicitly assigned.");
|
||||
|
||||
@@ -104,6 +104,7 @@ namespace Robust.Server
|
||||
[Dependency] private readonly IComponentFactory _componentFactory = default!;
|
||||
[Dependency] private readonly IReplayRecordingManagerInternal _replay = default!;
|
||||
[Dependency] private readonly IGamePrototypeLoadManager _protoLoadMan = default!;
|
||||
[Dependency] private readonly UploadedContentManager _uploadedContMan = default!;
|
||||
[Dependency] private readonly NetworkResourceManager _netResMan = default!;
|
||||
[Dependency] private readonly IReflectionManager _refMan = default!;
|
||||
|
||||
@@ -393,6 +394,7 @@ namespace Robust.Server
|
||||
_scriptHost.Initialize();
|
||||
_protoLoadMan.Initialize();
|
||||
_netResMan.Initialize();
|
||||
_uploadedContMan.Initialize();
|
||||
|
||||
// String serializer has to be locked before PostInit as content can depend on it (e.g., replays that start
|
||||
// automatically recording on startup).
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Robust.Server.GameObjects
|
||||
{
|
||||
[RegisterComponent]
|
||||
internal sealed partial class ViewSubscriberComponent : Component
|
||||
{
|
||||
internal readonly HashSet<ICommonSession> SubscribedSessions = new();
|
||||
}
|
||||
}
|
||||
@@ -155,7 +155,7 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
result = Deserialize(data);
|
||||
_logLoader.Debug($"Loaded map in {sw.Elapsed}");
|
||||
|
||||
var mapEnt = _mapManager.GetMapEntityId(mapId);
|
||||
var mapEnt = _mapSystem.GetMapOrInvalid(mapId);
|
||||
var xformQuery = _serverEntityManager.GetEntityQuery<TransformComponent>();
|
||||
var rootEnts = new List<EntityUid>();
|
||||
// aeoeoeieioe content
|
||||
@@ -217,13 +217,13 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
|
||||
public void SaveMap(MapId mapId, string ymlPath)
|
||||
{
|
||||
if (!_mapManager.MapExists(mapId))
|
||||
if (!_mapSystem.TryGetMap(mapId, out var mapUid))
|
||||
{
|
||||
_logLoader.Error($"Unable to find map {mapId}");
|
||||
return;
|
||||
}
|
||||
|
||||
Save(_mapManager.GetMapEntityId(mapId), ymlPath);
|
||||
Save(mapUid.Value, ymlPath);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -422,7 +422,7 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
private HashSet<EntityUid> AllocEntities(MapData data, BeforeEntityReadEvent ev)
|
||||
{
|
||||
_stopwatch.Restart();
|
||||
var mapUid = _mapManager.GetMapEntityId(data.TargetMap);
|
||||
var mapUid = _mapSystem.GetMapOrInvalid(data.TargetMap);
|
||||
var pauseTime = mapUid.IsValid() ? _meta.GetPauseTime(mapUid) : TimeSpan.Zero;
|
||||
_context.Set(data.UidEntityMap, new Dictionary<EntityUid, int>(), data.MapIsPostInit, pauseTime, null);
|
||||
HashSet<EntityUid> deletedPrototypeUids = new();
|
||||
|
||||
@@ -1,89 +1,87 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Robust.Server.GameObjects
|
||||
namespace Robust.Server.GameObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Entity System that handles subscribing and unsubscribing to PVS views.
|
||||
/// </summary>
|
||||
public sealed class ViewSubscriberSystem : SharedViewSubscriberSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Entity System that handles subscribing and unsubscribing to PVS views.
|
||||
/// </summary>
|
||||
public sealed class ViewSubscriberSystem : EntitySystem
|
||||
public override void Initialize()
|
||||
{
|
||||
public override void Initialize()
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<ViewSubscriberComponent, ComponentShutdown>(OnViewSubscriberShutdown);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subscribes the session to get PVS updates from the point of view of the specified entity.
|
||||
/// </summary>
|
||||
public override void AddViewSubscriber(EntityUid uid, ICommonSession session)
|
||||
{
|
||||
// If the entity doesn't have the component, it will be added.
|
||||
var viewSubscriber = EntityManager.EnsureComponent<Shared.GameObjects.ViewSubscriberComponent>(uid);
|
||||
|
||||
if (viewSubscriber.SubscribedSessions.Contains(session))
|
||||
return; // Already subscribed, do nothing else.
|
||||
|
||||
viewSubscriber.SubscribedSessions.Add(session);
|
||||
session.ViewSubscriptions.Add(uid);
|
||||
|
||||
RaiseLocalEvent(uid, new ViewSubscriberAddedEvent(uid, session), true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unsubscribes the session from getting PVS updates from the point of view of the specified entity.
|
||||
/// </summary>
|
||||
public override void RemoveViewSubscriber(EntityUid uid, ICommonSession session)
|
||||
{
|
||||
if(!EntityManager.TryGetComponent(uid, out Shared.GameObjects.ViewSubscriberComponent? viewSubscriber))
|
||||
return; // Entity didn't have any subscriptions, do nothing.
|
||||
|
||||
if (!viewSubscriber.SubscribedSessions.Remove(session))
|
||||
return; // Session wasn't subscribed, do nothing.
|
||||
|
||||
session.ViewSubscriptions.Remove(uid);
|
||||
RaiseLocalEvent(uid, new ViewSubscriberRemovedEvent(uid, session), true);
|
||||
}
|
||||
|
||||
private void OnViewSubscriberShutdown(EntityUid uid, ViewSubscriberComponent component, ComponentShutdown _)
|
||||
{
|
||||
foreach (var session in component.SubscribedSessions)
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ViewSubscriberComponent, ComponentShutdown>(OnViewSubscriberShutdown);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subscribes the session to get PVS updates from the point of view of the specified entity.
|
||||
/// </summary>
|
||||
public void AddViewSubscriber(EntityUid uid, ICommonSession session)
|
||||
{
|
||||
// If the entity doesn't have the component, it will be added.
|
||||
var viewSubscriber = EntityManager.EnsureComponent<ViewSubscriberComponent>(uid);
|
||||
|
||||
if (viewSubscriber.SubscribedSessions.Contains(session))
|
||||
return; // Already subscribed, do nothing else.
|
||||
|
||||
viewSubscriber.SubscribedSessions.Add(session);
|
||||
session.ViewSubscriptions.Add(uid);
|
||||
|
||||
RaiseLocalEvent(uid, new ViewSubscriberAddedEvent(uid, session), true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unsubscribes the session from getting PVS updates from the point of view of the specified entity.
|
||||
/// </summary>
|
||||
public void RemoveViewSubscriber(EntityUid uid, ICommonSession session)
|
||||
{
|
||||
if(!EntityManager.TryGetComponent(uid, out ViewSubscriberComponent? viewSubscriber))
|
||||
return; // Entity didn't have any subscriptions, do nothing.
|
||||
|
||||
if (!viewSubscriber.SubscribedSessions.Remove(session))
|
||||
return; // Session wasn't subscribed, do nothing.
|
||||
|
||||
session.ViewSubscriptions.Remove(uid);
|
||||
RaiseLocalEvent(uid, new ViewSubscriberRemovedEvent(uid, session), true);
|
||||
}
|
||||
|
||||
private void OnViewSubscriberShutdown(EntityUid uid, ViewSubscriberComponent component, ComponentShutdown _)
|
||||
{
|
||||
foreach (var session in component.SubscribedSessions)
|
||||
{
|
||||
session.ViewSubscriptions.Remove(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when a session subscribes to an entity's PVS view.
|
||||
/// </summary>
|
||||
public sealed class ViewSubscriberAddedEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid View { get; }
|
||||
public ICommonSession Subscriber { get; }
|
||||
|
||||
public ViewSubscriberAddedEvent(EntityUid view, ICommonSession subscriber)
|
||||
{
|
||||
View = view;
|
||||
Subscriber = subscriber;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when a session is unsubscribed from an entity's PVS view.
|
||||
/// Not raised when sessions are unsubscribed due to the component being removed.
|
||||
/// </summary>
|
||||
public sealed class ViewSubscriberRemovedEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid View { get; }
|
||||
public ICommonSession Subscriber { get; }
|
||||
|
||||
public ViewSubscriberRemovedEvent(EntityUid view, ICommonSession subscriber)
|
||||
{
|
||||
View = view;
|
||||
Subscriber = subscriber;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when a session subscribes to an entity's PVS view.
|
||||
/// </summary>
|
||||
public sealed class ViewSubscriberAddedEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid View { get; }
|
||||
public ICommonSession Subscriber { get; }
|
||||
|
||||
public ViewSubscriberAddedEvent(EntityUid view, ICommonSession subscriber)
|
||||
{
|
||||
View = view;
|
||||
Subscriber = subscriber;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when a session is unsubscribed from an entity's PVS view.
|
||||
/// Not raised when sessions are unsubscribed due to the component being removed.
|
||||
/// </summary>
|
||||
public sealed class ViewSubscriberRemovedEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid View { get; }
|
||||
public ICommonSession Subscriber { get; }
|
||||
|
||||
public ViewSubscriberRemovedEvent(EntityUid view, ICommonSession subscriber)
|
||||
{
|
||||
View = view;
|
||||
Subscriber = subscriber;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
|
||||
namespace Robust.Server.GameObjects;
|
||||
|
||||
internal sealed class ServerComponentFactory : ComponentFactory
|
||||
{
|
||||
public ServerComponentFactory(IDynamicTypeFactoryInternal typeFactory, IReflectionManager reflectionManager, ILogManager logManager) : base(typeFactory, reflectionManager, logManager)
|
||||
public ServerComponentFactory(IDynamicTypeFactoryInternal typeFactory, IReflectionManager reflectionManager, ISerializationManager serManager, ILogManager logManager) : base(typeFactory, reflectionManager, serManager, logManager)
|
||||
{
|
||||
RegisterIgnore("Input");
|
||||
RegisterIgnore("AnimationPlayer");
|
||||
|
||||
@@ -81,6 +81,7 @@ namespace Robust.Server.GameObjects
|
||||
InitializeEntity(entity, meta);
|
||||
}
|
||||
|
||||
[Obsolete("Use StartEntity")]
|
||||
void IServerEntityManagerInternal.FinishEntityStartup(EntityUid entity)
|
||||
{
|
||||
StartEntity(entity);
|
||||
|
||||
@@ -78,7 +78,7 @@ internal sealed partial class PvsSystem
|
||||
|
||||
if (meta.LifeStage >= EntityLifeStage.Terminating)
|
||||
{
|
||||
Log.Error($"Attempted to send deleted entity: {ToPrettyString(ent.Uid)}");
|
||||
Log.Error($"Attempted to send deleted entity: {ToPrettyString(ent.Uid)}, lifestage is {meta.LifeStage}.\n{Environment.StackTrace}");
|
||||
EntityManager.QueueDeleteEntity(ent.Uid);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace Robust.Server.ViewVariables
|
||||
|
||||
// We don't blindly send any prototypes, we ONLY send prototypes for valid, registered variants.
|
||||
if (typeof(IPrototype).IsAssignableFrom(valType)
|
||||
&& IoCManager.Resolve<IPrototypeManager>().TryGetVariantFrom(valType, out var variant))
|
||||
&& IoCManager.Resolve<IPrototypeManager>().TryGetKindFrom(valType, out var variant))
|
||||
{
|
||||
return new ViewVariablesBlobMembers.PrototypeReferenceToken()
|
||||
{
|
||||
@@ -161,7 +161,7 @@ namespace Robust.Server.ViewVariables
|
||||
{
|
||||
var protoMan = IoCManager.Resolve<IPrototypeManager>();
|
||||
|
||||
if (protoMan.TryGetVariantFrom(type, out var variant))
|
||||
if (protoMan.TryGetKindFrom(type, out var variant))
|
||||
return new ViewVariablesBlobMembers.PrototypeReferenceToken()
|
||||
{
|
||||
ID = null, Variant = variant, Stringified = PrettyPrint.PrintUserFacing(null),
|
||||
|
||||
@@ -9,7 +9,7 @@ level = 1
|
||||
enabled = false
|
||||
|
||||
[net]
|
||||
tickrate = 60
|
||||
tickrate = 30
|
||||
port = 1212
|
||||
bindto = "::,0.0.0.0"
|
||||
max_connections = 256
|
||||
|
||||
@@ -25,6 +25,13 @@ public static class Matrix3Helpers
|
||||
return a.EqualsApprox(b, (float) tolerance);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Box2Rotated TransformBounds(this Matrix3x2 refFromBox, Box2Rotated box)
|
||||
{
|
||||
var matty = Matrix3x2.Multiply(refFromBox, box.Transform);
|
||||
return new Box2Rotated(Vector2.Transform(box.BottomLeft, matty), Vector2.Transform(box.TopRight, matty));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Box2 TransformBox(this Matrix3x2 refFromBox, Box2Rotated box)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using Robust.Shared.Utility;
|
||||
@@ -22,6 +23,7 @@ namespace Robust.Shared.Maths
|
||||
public readonly int Width => Math.Abs(Right - Left);
|
||||
public readonly int Height => Math.Abs(Top - Bottom);
|
||||
public readonly Vector2i Size => new(Width, Height);
|
||||
public readonly Vector2 Center => TopRight - BottomLeft / 2;
|
||||
|
||||
public UIBox2i(Vector2i topLeft, Vector2i bottomRight)
|
||||
{
|
||||
|
||||
@@ -27,6 +27,11 @@ namespace Robust.Shared.Maths
|
||||
public static readonly Vector2i Left = (-1, 0);
|
||||
public static readonly Vector2i Right = (1, 0);
|
||||
|
||||
public static readonly Vector2i DownLeft = (-1, -1);
|
||||
public static readonly Vector2i DownRight = (1, -1);
|
||||
public static readonly Vector2i UpRight = (1, 1);
|
||||
public static readonly Vector2i UpLeft = (-1, 1);
|
||||
|
||||
/// <summary>
|
||||
/// The X component of the Vector2i.
|
||||
/// </summary>
|
||||
|
||||
18
Robust.Shared/Analyzers/PreferOtherTypeAttribute.cs
Normal file
18
Robust.Shared/Analyzers/PreferOtherTypeAttribute.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
#if ROBUST_ANALYZERS_IMPL
|
||||
namespace Robust.Shared.Analyzers.Implementation;
|
||||
#else
|
||||
namespace Robust.Shared.Analyzers;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Marks that use of a generic Type should be replaced with a specific other Type
|
||||
/// when the type argument T is a certain Type.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
|
||||
public sealed class PreferOtherTypeAttribute(Type genericType, Type replacementType) : Attribute
|
||||
{
|
||||
public readonly Type GenericArgument = genericType;
|
||||
public readonly Type ReplacementType = replacementType;
|
||||
}
|
||||
@@ -299,6 +299,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
|
||||
{
|
||||
var uid = EntityManager.CreateEntityUninitialized("Audio", MapCoordinates.Nullspace);
|
||||
DebugTools.Assert(!string.IsNullOrEmpty(fileName) || length is not null);
|
||||
MetadataSys.SetEntityName(uid, $"Audio ({fileName})", raiseEvents: false);
|
||||
audioParams ??= AudioParams.Default;
|
||||
var comp = AddComp<AudioComponent>(uid);
|
||||
comp.FileName = fileName ?? string.Empty;
|
||||
|
||||
@@ -289,7 +289,7 @@ namespace Robust.Shared
|
||||
/// This influences both how frequently game code processes, and how frequently updates are sent to clients.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<int> NetTickrate =
|
||||
CVarDef.Create("net.tickrate", 60, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
|
||||
CVarDef.Create("net.tickrate", 30, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
|
||||
|
||||
/// <summary>
|
||||
/// Offset CurTime at server start by this amount (in seconds).
|
||||
@@ -382,6 +382,18 @@ namespace Robust.Shared
|
||||
public static readonly CVarDef<bool> NetLidgrenLogError =
|
||||
CVarDef.Create("net.lidgren_log_error", true);
|
||||
|
||||
/// <summary>
|
||||
/// If true, run network message encryption on another thread.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> NetEncryptionThread =
|
||||
CVarDef.Create("net.encryption_thread", true);
|
||||
|
||||
/// <summary>
|
||||
/// Outstanding buffer size used by <see cref="NetEncryptionThread"/>.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<int> NetEncryptionThreadChannelSize =
|
||||
CVarDef.Create("net.encryption_thread_channel_size", 16);
|
||||
|
||||
/**
|
||||
* SUS
|
||||
*/
|
||||
@@ -1157,6 +1169,13 @@ namespace Robust.Shared
|
||||
public static readonly CVarDef<float> AudioRaycastLength =
|
||||
CVarDef.Create("audio.raycast_length", SharedAudioSystem.DefaultSoundRange, CVar.ARCHIVE | CVar.CLIENTONLY);
|
||||
|
||||
/// <summary>
|
||||
/// Tickrate for audio calculations.
|
||||
/// OpenAL recommends 30TPS. This is to avoid running raycasts every frame especially for high-refresh rate monitors.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<int> AudioTickRate =
|
||||
CVarDef.Create("audio.tick_rate", 30, CVar.CLIENTONLY);
|
||||
|
||||
public static readonly CVarDef<float> AudioZOffset =
|
||||
CVarDef.Create("audio.z_offset", -5f, CVar.REPLICATED);
|
||||
|
||||
@@ -1769,5 +1788,12 @@ namespace Robust.Shared
|
||||
/// </summary>
|
||||
public static readonly CVarDef<int> ToolshedNearbyLimit =
|
||||
CVarDef.Create("toolshed.nearby_limit", 200, CVar.SERVER | CVar.REPLICATED);
|
||||
|
||||
/// <summary>
|
||||
/// The max amount of entities that can be passed to the nearby toolshed command.
|
||||
/// Any higher value will cause an exception.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<int> ToolshedNearbyEntitiesLimit =
|
||||
CVarDef.Create("toolshed.nearby_entities_limit", 5, CVar.SERVER | CVar.REPLICATED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ public sealed class TeleportToCommand : LocalizedEntityCommands
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_players.Sessions.TryFirstOrDefault(x => x.Channel.UserName == str, out var session)
|
||||
if (_players.TryGetSessionByUsername(str, out var session)
|
||||
&& _entities.TryGetComponent(session.AttachedEntity, out transform))
|
||||
{
|
||||
victimUid = session.AttachedEntity;
|
||||
|
||||
@@ -21,10 +21,21 @@ internal sealed class EntityConsoleHost
|
||||
|
||||
private readonly HashSet<string> _entityCommands = [];
|
||||
|
||||
/// <summary>
|
||||
/// If disabled, don't automatically discover commands via reflection.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This gets disabled in certain unit tests.
|
||||
/// </remarks>
|
||||
public bool DiscoverCommands { get; set; } = true;
|
||||
|
||||
public void Startup()
|
||||
{
|
||||
DebugTools.Assert(_entityCommands.Count == 0);
|
||||
|
||||
if (!DiscoverCommands)
|
||||
return;
|
||||
|
||||
var deps = ((EntitySystemManager)_entitySystemManager).SystemDependencyCollection;
|
||||
|
||||
_consoleHost.BeginRegistrationRegion();
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Robust.Shared.ContentPack
|
||||
String("short").ThenReturn(PrimitiveTypeCode.Int16);
|
||||
|
||||
private static readonly Parser<char, PrimitiveTypeCode> UInt16TypeParser =
|
||||
String("ushort").ThenReturn(PrimitiveTypeCode.UInt32);
|
||||
String("ushort").ThenReturn(PrimitiveTypeCode.UInt16);
|
||||
|
||||
private static readonly Parser<char, PrimitiveTypeCode> Int32TypeParser =
|
||||
String("int").ThenReturn(PrimitiveTypeCode.Int32);
|
||||
|
||||
@@ -10,6 +10,8 @@ AllowedVerifierErrors:
|
||||
- InterfaceMethodNotImplemented
|
||||
|
||||
# EVERYTHING in these namespaces is allowed.
|
||||
# Note that, due to a historical bug in the sandbox, any namespace _prefixed_ with one of these
|
||||
# is also allowed. (For instance, RobustBats.X, or ContentFarm.Y)
|
||||
WhitelistedNamespaces:
|
||||
- Robust
|
||||
- Content
|
||||
@@ -84,12 +86,146 @@ Types:
|
||||
- "bool get_HasContents()"
|
||||
Lidgren.Network:
|
||||
NetBuffer:
|
||||
All: True
|
||||
Methods:
|
||||
- "byte[] get_Data()"
|
||||
- "void set_Data(byte[])"
|
||||
- "int get_LengthBytes()"
|
||||
- "void set_LengthBytes(int)"
|
||||
- "int get_LengthBits()"
|
||||
- "void set_LengthBits(int)"
|
||||
- "long get_Position()"
|
||||
- "void set_Position(long)"
|
||||
- "int get_PositionInBytes()"
|
||||
- "byte[] PeekDataBuffer()"
|
||||
- "bool PeekBoolean()"
|
||||
- "byte PeekByte()"
|
||||
- "sbyte PeekSByte()"
|
||||
- "byte PeekByte(int)"
|
||||
- "System.Span`1<byte> PeekBytes(System.Span`1<byte>)"
|
||||
- "byte[] PeekBytes(int)"
|
||||
- "void PeekBytes(byte[], int, int)"
|
||||
- "short PeekInt16()"
|
||||
- "ushort PeekUInt16()"
|
||||
- "int PeekInt32()"
|
||||
- "int PeekInt32(int)"
|
||||
- "uint PeekUInt32()"
|
||||
- "uint PeekUInt32(int)"
|
||||
- "ulong PeekUInt64()"
|
||||
- "long PeekInt64()"
|
||||
- "ulong PeekUInt64(int)"
|
||||
- "long PeekInt64(int)"
|
||||
- "float PeekFloat()"
|
||||
- "System.Half PeekHalf()"
|
||||
- "float PeekSingle()"
|
||||
- "double PeekDouble()"
|
||||
- "string PeekString()"
|
||||
- "int PeekStringSize()"
|
||||
- "bool ReadBoolean()"
|
||||
- "byte ReadByte()"
|
||||
- "bool ReadByte(ref byte)"
|
||||
- "sbyte ReadSByte()"
|
||||
- "byte ReadByte(int)"
|
||||
- "System.Span`1<byte> ReadBytes(System.Span`1<byte>)"
|
||||
- "byte[] ReadBytes(int)"
|
||||
- "bool ReadBytes(int, ref byte[])"
|
||||
- "bool TryReadBytes(System.Span`1<byte>)"
|
||||
- "void ReadBytes(byte[], int, int)"
|
||||
- "void ReadBits(System.Span`1<byte>, int)"
|
||||
- "void ReadBits(byte[], int, int)"
|
||||
- "short ReadInt16()"
|
||||
- "ushort ReadUInt16()"
|
||||
- "int ReadInt32()"
|
||||
- "bool ReadInt32(ref int)"
|
||||
- "int ReadInt32(int)"
|
||||
- "uint ReadUInt32()"
|
||||
- "bool ReadUInt32(ref uint)"
|
||||
- "uint ReadUInt32(int)"
|
||||
- "ulong ReadUInt64()"
|
||||
- "long ReadInt64()"
|
||||
- "ulong ReadUInt64(int)"
|
||||
- "long ReadInt64(int)"
|
||||
- "float ReadFloat()"
|
||||
- "System.Half ReadHalf()"
|
||||
- "float ReadSingle()"
|
||||
- "bool ReadSingle(ref float)"
|
||||
- "double ReadDouble()"
|
||||
- "uint ReadVariableUInt32()"
|
||||
- "bool ReadVariableUInt32(ref uint)"
|
||||
- "int ReadVariableInt32()"
|
||||
- "long ReadVariableInt64()"
|
||||
- "ulong ReadVariableUInt64()"
|
||||
- "float ReadSignedSingle(int)"
|
||||
- "float ReadUnitSingle(int)"
|
||||
- "float ReadRangedSingle(float, float, int)"
|
||||
- "int ReadRangedInteger(int, int)"
|
||||
- "long ReadRangedInteger(long, long)"
|
||||
- "string ReadString()"
|
||||
- "bool ReadString(ref string)"
|
||||
- "double ReadTime(Lidgren.Network.NetConnection, bool)"
|
||||
- "System.Net.IPEndPoint ReadIPEndPoint()"
|
||||
- "void SkipPadBits()"
|
||||
- "void ReadPadBits()"
|
||||
- "void SkipPadBits(int)"
|
||||
- "void EnsureBufferSize(int)"
|
||||
- "void Write(bool)"
|
||||
- "void Write(byte)"
|
||||
- "void WriteAt(int, byte)"
|
||||
- "void Write(sbyte)"
|
||||
- "void Write(byte, int)"
|
||||
- "void Write(byte[])"
|
||||
- "void Write(System.ReadOnlySpan`1<byte>)"
|
||||
- "void Write(byte[], int, int)"
|
||||
- "void Write(ushort)"
|
||||
- "void WriteAt(int, ushort)"
|
||||
- "void Write(ushort, int)"
|
||||
- "void Write(short)"
|
||||
- "void WriteAt(int, short)"
|
||||
- "void Write(int)"
|
||||
- "void WriteAt(int, int)"
|
||||
- "void Write(uint)"
|
||||
- "void WriteAt(int, uint)"
|
||||
- "void Write(uint, int)"
|
||||
- "void Write(int, int)"
|
||||
- "void Write(ulong)"
|
||||
- "void WriteAt(int, ulong)"
|
||||
- "void Write(ulong, int)"
|
||||
- "void Write(long)"
|
||||
- "void Write(long, int)"
|
||||
- "void Write(System.Half)"
|
||||
- "void Write(float)"
|
||||
- "void Write(double)"
|
||||
- "int WriteVariableUInt32(uint)"
|
||||
- "int WriteVariableInt32(int)"
|
||||
- "int WriteVariableInt64(long)"
|
||||
- "int WriteVariableUInt64(ulong)"
|
||||
- "void WriteSignedSingle(float, int)"
|
||||
- "void WriteUnitSingle(float, int)"
|
||||
- "void WriteRangedSingle(float, float, float, int)"
|
||||
- "int WriteRangedInteger(int, int, int)"
|
||||
- "int WriteRangedInteger(long, long, long)"
|
||||
- "void Write(string)"
|
||||
- "void Write(System.Net.IPEndPoint)"
|
||||
- "void WriteTime(bool)"
|
||||
- "void WriteTime(double, bool)"
|
||||
- "void WritePadBits()"
|
||||
- "void WritePadBits(int)"
|
||||
- "void Write(Lidgren.Network.NetBuffer)"
|
||||
- "void Zero(int)"
|
||||
- "void .ctor()"
|
||||
NetDeliveryMethod: { }
|
||||
NetIncomingMessage:
|
||||
All: True
|
||||
Methods:
|
||||
- "Lidgren.Network.NetIncomingMessageType get_MessageType()"
|
||||
- "Lidgren.Network.NetDeliveryMethod get_DeliveryMethod()"
|
||||
- "int get_SequenceChannel()"
|
||||
- "System.Net.IPEndPoint get_SenderEndPoint()"
|
||||
- "Lidgren.Network.NetConnection get_SenderConnection()"
|
||||
- "double get_ReceiveTime()"
|
||||
- "double ReadTime(bool)"
|
||||
- "string ToString()"
|
||||
NetOutgoingMessage:
|
||||
All: True
|
||||
Methods:
|
||||
- "string ToString()"
|
||||
Nett:
|
||||
CommentLocation: { } # Enum
|
||||
Toml:
|
||||
@@ -507,6 +643,7 @@ Types:
|
||||
IAsyncStateMachine: { All: True }
|
||||
InternalsVisibleToAttribute: { All: True }
|
||||
InterpolatedStringHandlerAttribute: { All: True }
|
||||
InterpolatedStringHandlerArgumentAttribute: { All: True }
|
||||
IsByRefLikeAttribute: { All: True }
|
||||
IsExternalInit: { All: True }
|
||||
IsReadOnlyAttribute: { All: True }
|
||||
@@ -919,6 +1056,7 @@ Types:
|
||||
DateTime: { All: True }
|
||||
DateTimeKind: { } # Enum
|
||||
DateTimeOffset: { All: True }
|
||||
Decimal: { All: True }
|
||||
Delegate:
|
||||
Methods:
|
||||
- "System.Delegate Combine(System.Delegate, System.Delegate)"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Shared.ContentPack
|
||||
@@ -135,11 +136,37 @@ namespace Robust.Shared.ContentPack
|
||||
path = path.Directory;
|
||||
|
||||
var fullPath = GetFullPath(path);
|
||||
Process.Start(new ProcessStartInfo
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
UseShellExecute = true,
|
||||
FileName = fullPath,
|
||||
});
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = $"{Environment.GetEnvironmentVariable("SystemRoot")}\\explorer.exe",
|
||||
Arguments = ".",
|
||||
WorkingDirectory = fullPath,
|
||||
});
|
||||
}
|
||||
else if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "open",
|
||||
Arguments = ".",
|
||||
WorkingDirectory = fullPath,
|
||||
});
|
||||
}
|
||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsFreeBSD())
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "xdg-open",
|
||||
Arguments = ".",
|
||||
WorkingDirectory = fullPath,
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException("Opening OS windows not supported on this OS");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -8,7 +8,9 @@ using JetBrains.Annotations;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -18,6 +20,7 @@ namespace Robust.Shared.GameObjects
|
||||
internal class ComponentFactory(
|
||||
IDynamicTypeFactoryInternal _typeFactory,
|
||||
IReflectionManager _reflectionManager,
|
||||
ISerializationManager _serManager,
|
||||
ILogManager logManager) : IComponentFactory
|
||||
{
|
||||
private readonly ISawmill _sawmill = logManager.GetSawmill("ent.componentFactory");
|
||||
@@ -181,6 +184,13 @@ namespace Robust.Shared.GameObjects
|
||||
_ignoreMissingComponentPostfix = postfix ?? throw new ArgumentNullException(nameof(postfix));
|
||||
}
|
||||
|
||||
public IComponent GetComponent(EntityPrototype.ComponentRegistryEntry entry)
|
||||
{
|
||||
var copy = GetComponent(entry.Component.GetType());
|
||||
_serManager.CopyTo(entry.Component, ref copy, notNullableOverride: true);
|
||||
return copy;
|
||||
}
|
||||
|
||||
public void RegisterIgnore(params string[] names)
|
||||
{
|
||||
foreach (var name in names)
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Shared.GameObjects;
|
||||
@@ -15,6 +16,7 @@ namespace Robust.Shared.GameObjects;
|
||||
/// Visualization works client side with derivatives of the <see cref="Robust.Client.GameObjects.VisualizerSystem">VisualizerSystem</see> class and corresponding components.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[Access(typeof(SharedAppearanceSystem))]
|
||||
public sealed partial class AppearanceComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
@@ -32,6 +34,19 @@ public sealed partial class AppearanceComponent : Component
|
||||
|
||||
[ViewVariables] internal Dictionary<Enum, object> AppearanceData = new();
|
||||
|
||||
private Dictionary<Enum, object>? _appearanceDataInit;
|
||||
|
||||
/// <summary>
|
||||
/// Sets starting values for AppearanceData.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Should only be filled in via prototype .yaml; subsequent data must be set via SharedAppearanceSystem.SetData().
|
||||
/// </remarks>
|
||||
[DataField(readOnly: true)] public Dictionary<Enum, object>? AppearanceDataInit {
|
||||
get { return _appearanceDataInit; }
|
||||
set { AppearanceData = value ?? AppearanceData; _appearanceDataInit = value; }
|
||||
}
|
||||
|
||||
[Obsolete("Use SharedAppearanceSystem instead")]
|
||||
public bool TryGetData<T>(Enum key, [NotNullWhen(true)] out T data)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Robust.Shared.GameObjects;
|
||||
|
||||
// Not networked because doesn't do anything on client.
|
||||
[RegisterComponent]
|
||||
internal sealed partial class ViewSubscriberComponent : Component
|
||||
{
|
||||
internal readonly HashSet<ICommonSession> SubscribedSessions = new();
|
||||
}
|
||||
@@ -95,6 +95,15 @@ namespace Robust.Shared.GameObjects
|
||||
public string? MaskPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised directed on an entity when attempting to enable / disable it.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct AttemptPointLightToggleEvent(bool Enabled)
|
||||
{
|
||||
public bool Cancelled;
|
||||
}
|
||||
|
||||
public sealed class PointLightToggleEvent : EntityEventArgs
|
||||
{
|
||||
public bool Enabled;
|
||||
|
||||
@@ -415,25 +415,6 @@ namespace Robust.Shared.GameObjects
|
||||
_entMan.EntitySysManager.GetEntitySystem<SharedTransformSystem>().SetParent(Owner, this, newParent.Owner, newParent);
|
||||
}
|
||||
|
||||
internal void ChangeMapId(MapId newMapId, EntityQuery<TransformComponent> xformQuery)
|
||||
{
|
||||
if (newMapId == MapID)
|
||||
return;
|
||||
|
||||
EntityUid? newUid = newMapId == MapId.Nullspace ? null : _mapManager.GetMapEntityId(newMapId);
|
||||
|
||||
//Set Paused state
|
||||
var mapPaused = _mapManager.IsMapPaused(newMapId);
|
||||
var metaEnts = _entMan.GetEntityQuery<MetaDataComponent>();
|
||||
var metaData = metaEnts.GetComponent(Owner);
|
||||
var metaSystem = _entMan.EntitySysManager.GetEntitySystem<MetaDataSystem>();
|
||||
metaSystem.SetEntityPaused(Owner, mapPaused, metaData);
|
||||
|
||||
MapUid = newUid;
|
||||
MapID = newMapId;
|
||||
UpdateChildMapIdsRecursive(MapID, newUid, mapPaused, xformQuery, metaEnts, metaSystem);
|
||||
}
|
||||
|
||||
internal void UpdateChildMapIdsRecursive(
|
||||
MapId newMapId,
|
||||
EntityUid? newUid,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user