Compare commits

..

4 Commits

Author SHA1 Message Date
DrSmugleaf
190c35dbdf Version: 240.1.3-source-gen-debug 2025-01-21 19:11:31 -08:00
DrSmugleaf
b52c26d0eb Merge branch 'master' of https://github.com/space-wizards/RobustToolbox into serialization-source-gen-debug 2025-01-21 19:11:05 -08:00
DrSmugleaf
35c983d2fd Version: 240.1.2-source-gen-debug 2025-01-21 18:47:40 -08:00
DrSmugleaf
88cfd04f01 Source gen changes 2025-01-21 18:47:25 -08:00
253 changed files with 3932 additions and 12298 deletions

View File

@@ -57,7 +57,7 @@
<PackageVersion Include="SharpZstd.Interop" Version="1.5.2-beta2" />
<PackageVersion Include="SixLabors.ImageSharp" Version="3.1.6" />
<PackageVersion Include="SpaceWizards.HttpListener" Version="0.1.1" />
<PackageVersion Include="SpaceWizards.NFluidsynth" Version="0.2.2" />
<PackageVersion Include="SpaceWizards.NFluidsynth" Version="0.1.1" />
<PackageVersion Include="SpaceWizards.SharpFont" Version="1.0.2" />
<PackageVersion Include="SpaceWizards.Sodium" Version="0.2.1" />
<PackageVersion Include="TerraFX.Interop.Windows" Version="10.0.26100.1" />

View File

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

View File

@@ -54,249 +54,10 @@ END TEMPLATE-->
*None yet*
## 247.2.4
## 240.1.3-source-gen-debug
## 247.2.3
## 247.2.2
## 247.2.1
## 247.2.0
### New features
* Added functions for copying components to `IEntityManager` and `EntitySystem`.
* Sound played from sound collections is now sent as "collection ID + index" over the network instead of the final filename.
* This enables integration of future accessibility systems.
* Added a new `ResolvedSoundSpecifier` to represent played sounds. Methods that previously took a filename now take a `ResolvedSoundSpecifier`, with an implicit cast from string being interpreted as a raw filename.
* `VisibilitySystem` has been made accessible to shared as `SharedVisibilitySystem`.
* `ScrollContainer` now has properties exposing `Value` and `ValueTarget` on its internal scroll bars.
### Bugfixes
* Fix prototype hot reload crashing when adding a new component already exists on an entity.
* Fix maps failing to save in some cases related to tilemap IDs.
* Fix `Regex.Escape(string)` not being available in sandbox.
* Prototypes that parent themselves directly won't cause the game to hang on an infinite loop anymore.
* Fixed disconnecting during a connection attempt leaving the client stuck in a phantom state.
### Internal
* More warning cleanup.
## 247.1.0
### New features
* Added support for `Color[]` shader uniforms
* Added optional minimumDistance parameter to `SharedJointSystem.CreateDistanceJoint()`
### Bugfixes
* Fixed `EntitySystem.DirtyFields()` not actually marking fields as dirty.
### Other
* Updated the Yamale map file format validator to support v7 map/grid files.
## 247.0.0
### Breaking changes
* `ITileDefinitionManager.AssignAlias` and general tile alias functionality has been removed. `TileAliasPrototype` still exist, but are only used during entity deserialization.
* `IMapManager.AddUninitializedMap` has been removed. Use the map-init options on `CreateMap()` instead.
* Re-using a MapId will now log a warning. This may cause some integration tests to fail if they are configured to fail
when warnings are logged.
* The minimum supported map format / version has been increased from 2 to 3.
* The server-side `MapLoaderSystem` and associated classes & structs has been moved to `Robust.Shared`, and has been significantly modified.
* The `TryLoad` and `Save` methods have been replaced with grid, map, generic entity variants. I.e, `SaveGrid`, `SaveMap`, and `SaveEntities`.
* Most of the serialization logic and methods have been moved out of `MapLoaderSystem` and into new `EntitySerializer`
and `EntityDeserializer` classes, which also replace the old `MapSerializationContext`.
* The `MapLoadOptions` class has been split into `MapLoadOptions`, `SerializationOptions`, and `DeserializationOptions`
structs.
* The interaction between PVS overrides and visibility masks / layers have changed:
* Any forced entities (i.e., `PvsOverrideSystem.AddForceSend()`) now ignore visibility masks.
* Any global & session overrides (`PvsOverrideSystem.AddGlobalOverride()` & `PvsOverrideSystem.AddSessionOverride()`) now respect visibility masks.
* Entities added via the `ExpandPvsEvent` respect visibility masks.
* The mask used for any global/session overrides can be modified via `ExpandPvsEvent.Mask`.
* Toolshed Changes:
* The signature of Toolshed type parsers have changed. Instead of taking in an optional command argument name string, they now take in a `CommandArgument` struct.
* Toolshed commands can no longer contain a '|', as this symbol is now used for explicitly piping the output of one command to another. command pipes. The existing `|` and '|~' commands have been renamed to `bitor` and `bitnotor`.
* Semicolon terminated command blocks in toolshed commands no longer return anything. I.e., `i { i 2 ; }` is no longer a valid command, as the block has no return value.
### New features
* The current map format/version has increased from 6 to 7 and now contains more information to try support serialization of maps with null-space entities and full game saves.
* `IEntitySystemManager` now provides access to the system `IDependencyCollection`.
* Toolshed commands now support optional and `params T[]` arguments. optional / variable length commands can be terminated using ';' or '|'.
### Bugfixes
* Fixed entity deserialization for components with a data fields that have a AlwaysPushInheritance Attribute
* Audio entities attached to invisible / masked entities should no longer be able to temporarily make those entities visible to all players.
* The map-like Toolshed commands now work when a collection is piped in.
* Fixed a bug in toolshed that could cause it to preferentially use the incorrect command implementation.
* E.g., passing a concrete enumerable type would previously use the command implementation that takes in an unconstrained generic parameter `T` instead of a dedicated `IEnumeerable<T>` implementation.
### Other
* `MapChangedEvent` has been marked as obsolete, and should be replaced with `MapCreatedEvent` and `MapRemovedEvent.
* The default auto-completion hint for Toolshed commands have been changed and somewhat standardized. Most parsers should now generate a hint of the form:
* `<name (Type)>` for mandatory arguments
* `[name (Type)]` for optional arguments
* `[name (Type)]...` for variable length arguments (i.e., for `params T[]`)
## 246.0.0
### Breaking changes
* The fixes to renderer state may have inadvertantly broken some rendering code that relied upon the old behavior.
* TileRenderFlag has been removed and now it's just a byte flag on the tile for content usage.
### New features
* Add BeforeLighting overlay draw space for overlays that need to draw directly to lighting and want to do it immediately beforehand.
* Change BlurLights to BlurRenderTarget and make it public for content usage.
* Add ContentFlag to tiles for content-flag usage.
* Add a basic mix shader for doing canvas blends.
* Add GetClearColorEvent for content to override the clear color behavior.
### Bugfixes
* Fix pushing renderer state not restoring stencil status, blend status, queued shader instance scissor state.
## 245.1.0
### New features
* Add more info to the AnchorEntity debug message.
* Make ParseObject public where it will parse a supplied Type and string into the specified object.
### Bugfixes
* Fix EntityPrototypeView not always updating the entity correctly.
* Tweak BUI shutdown to potentially avoid skipping closing.
### Other
* Increase Audio entity despawn buffer to avoid clipping.
## 245.0.0
### Breaking changes
* `BoundUserInterface.Open()` now has the `MustCallBase` attribute
### Bugfixes
* Fixed an error in `MappingDataNode.TryAddCopy()`, which was causing yaml inheritance/deserialization bugs.
## 244.0.0
### Breaking changes
* Increase physics speedcap default from 35m/s to 400m/s in-line with box2d v3.
### New features
* Add EntityManager overloads for ComponentRegistration that's faster than the generic methods.
* Add CreateWindowCenteredRight for BUIs.
### Bugfixes
* Avoid calling UpdateState before opening a BUI.
## 243.0.1
### Bugfixes
* Fixed `BaseWindow` sometimes not properly updating the mouse cursor shape.
* Revert `BaseWindow` OnClose ordering due to prior reliance upon the ordering.
## 243.0.0
### Breaking changes
* RemoveChild is called after OnClose for BaseWindow.
### New features
* BUIs now have their positions saved when closed and re-used when opened when using the `CreateWindow<T>` helper or via manually registering it via RegisterControl.
### Other
* Ensure grid fixtures get updated in client state handling even if exceptions occur.
## 242.0.1
### Bugfixes
* Fixed prototype reloading/hotloading not properly handling data-fields with the `AlwaysPushInheritanceAttribute`
* Fix the pooled polygons using incorrect vertices for EntityLookup and MapManager.
### Internal
* Avoid normalizing angles constructed from vectors.
## 242.0.0
### Breaking changes
* The order in which the client initialises networked entities has changed. It will now always apply component states, initialise, and start an entity's parent before processing any children. This might break anything that was relying on the old behaviour where all component states were applied before any entities were initialised & started.
* `IClydeViewport` overlay rendering methods now take in an `IRenderHandle` instead of a world/screen handle.
* The `OverlayDrawArgs` struct now has an internal constructor.
### New features
* Controls can now be manually restyled via `Control.InvalidateStyleSheet()` and `Control.DoStyleUpdate()`
* Added `IUserInterfaceManager.RenderControl()` for manually drawing controls.
* `OverlayDrawArgs` struct now has an `IRenderHandle` field such that overlays can use the new `RenderControl()` methods.
* TileSpawnWindow will now take focus when opened.
### Bugfixes
* Fixed a client-side bug where `TransformComponent.GridUid` does not get set properly when an existing entity is attached to a new entity outside of the player's PVS range.
* EntityPrototypeView will only create entities when it's on the UI tree and not when the prototype is set.
* Make CollisionWake not log errors if it can't resolve.
### Other
* Replace IPhysShape API with generics on IMapManager and EntityLookupSystem.
### Internal
* Significantly reduce allocations for Box2 / Box2Rotated queries.
## 241.0.0
### Breaking changes
* Remove DeferredClose from BUIs.
### New features
* Added `EntityManager.DirtyFields()`, which allows components with delta states to simultaneously mark several fields as dirty at the same time.
* Add `CloserUserUIs<T>` to close keys of a specific key.
### Bugfixes
* Fixed `RaisePredictiveEvent()` not properly re-raising events during prediction for event handlers that did not take an `EntitySessionEventArgs` argument.
* BUI openings are now deferred to avoid having slight desync between deferred closes and opens occurring in the same tick.
## 240.1.2-source-gen-debug
## 240.1.2

View File

@@ -4,12 +4,6 @@
kind: canvas
light_mode: unshaded
# Simple mix blend
- type: shader
id: Mix
kind: canvas
blend_mode: Mix
- type: shader
id: shaded
kind: canvas

View File

@@ -42,7 +42,8 @@ command-description-as =
command-description-count =
Counts the amount of entries in it's input, returning an integer.
command-description-map =
Maps the input over the given block.
Maps the input over the given block, with the provided expected return type.
This command may be modified to not need an explicit return type in the future.
command-description-select =
Selects N objects or N% of objects from the input.
One can additionally invert this command with not to make it select everything except N objects instead.
@@ -148,7 +149,7 @@ command-description-max =
Returns the maximum of two values.
command-description-BitAndCommand =
Performs bitwise AND.
command-description-bitor =
command-description-BitOrCommand =
Performs bitwise OR.
command-description-BitXorCommand =
Performs bitwise XOR.
@@ -202,11 +203,11 @@ command-description-mappos =
command-description-pos =
Returns an entity's coordinates.
command-description-tp-coords =
Teleports the given entities to the target coordinates.
Teleports the target to the given coordinates.
command-description-tp-to =
Teleports the given entities to the target entity.
Teleports the target to the given other entity.
command-description-tp-into =
Teleports the given entities "into" the target entity, attaching it at (0 0) relative to it.
Teleports the target "into" the given other entity, attaching it at (0 0) relative to it.
command-description-comp-get =
Gets the given component from the given entity.
command-description-comp-add =
@@ -276,7 +277,7 @@ command-description-ModVecCommand =
Performs the modulus operation over the input with the given constant right-hand value.
command-description-BitAndNotCommand =
Performs bitwise AND-NOT over the input.
command-description-bitornot =
command-description-BitOrNotCommand =
Performs bitwise OR-NOT over the input.
command-description-BitXnorCommand =
Performs bitwise XNOR over the input.

View File

@@ -1,96 +0,0 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using JetBrains.Annotations;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.UnitTesting.Server;
namespace Robust.Benchmarks.EntityManager;
[Virtual]
public partial class HasComponentBenchmark
{
private static readonly Consumer Consumer = new();
private ISimulation _simulation = default!;
private IEntityManager _entityManager = default!;
private ComponentRegistration _compReg = default!;
private A _dummyA = new();
[UsedImplicitly]
[Params(1, 10, 100, 1000)]
public int N;
[GlobalSetup]
public void GlobalSetup()
{
_simulation = RobustServerSimulation
.NewSimulation()
.RegisterComponents(f => f.RegisterClass<A>())
.InitializeInstance();
_entityManager = _simulation.Resolve<IEntityManager>();
var map = _simulation.CreateMap().Uid;
var coords = new EntityCoordinates(map, default);
_compReg = _entityManager.ComponentFactory.GetRegistration(typeof(A));
for (var i = 0; i < N; i++)
{
var uid = _entityManager.SpawnEntity(null, coords);
_entityManager.AddComponent<A>(uid);
}
}
[Benchmark]
public void HasComponentGeneric()
{
for (var i = 2; i <= N+1; i++)
{
var uid = new EntityUid(i);
var result = _entityManager.HasComponent<A>(uid);
Consumer.Consume(result);
}
}
[Benchmark]
public void HasComponentCompReg()
{
for (var i = 2; i <= N+1; i++)
{
var uid = new EntityUid(i);
var result = _entityManager.HasComponent(uid, _compReg);
Consumer.Consume(result);
}
}
[Benchmark]
public void HasComponentType()
{
for (var i = 2; i <= N+1; i++)
{
var uid = new EntityUid(i);
var result = _entityManager.HasComponent(uid, typeof(A));
Consumer.Consume(result);
}
}
[Benchmark]
public void HasComponentGetType()
{
for (var i = 2; i <= N+1; i++)
{
var uid = new EntityUid(i);
var type = _dummyA.GetType();
var result = _entityManager.HasComponent(uid, type);
Consumer.Consume(result);
}
}
[ComponentProtoName("A")]
public sealed partial class A : Component
{
}
}

View File

@@ -6,7 +6,7 @@ using Xilium.CefGlue;
namespace Robust.Client.WebView.Cef
{
internal static class Program
public static class Program
{
// This was supposed to be the main entry for the subprocess program... It doesn't work.
public static int Main(string[] args)

View File

@@ -5,7 +5,6 @@ using System.Net;
using System.Reflection;
using System.Text;
using Robust.Client.Console;
using Robust.Client.Utility;
using Robust.Shared.Configuration;
using Robust.Shared.ContentPack;
using Robust.Shared.IoC;
@@ -25,7 +24,6 @@ namespace Robust.Client.WebView.Cef
[Dependency] private readonly IDependencyCollection _dependencyCollection = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IGameControllerInternal _gameController = default!;
[Dependency] private readonly IResourceManagerInternal _resourceManager = default!;
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
@@ -63,10 +61,7 @@ namespace Robust.Client.WebView.Cef
var cachePath = "";
if (_resourceManager.UserData is WritableDirProvider userData)
{
var rootDir = UserDataDir.GetRootUserDataDir(_gameController);
cachePath = Path.Combine(rootDir, "cef_cache", "0");
}
cachePath = userData.GetFullPath(new ResPath("/cef_cache"));
var settings = new CefSettings()
{

View File

@@ -40,7 +40,11 @@ namespace Robust.Client.Animations
var keyFrame = KeyFrames[keyFrameIndex];
var audioParams = keyFrame.AudioParamsFunc.Invoke();
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>().PlayEntity(keyFrame.Specifier, Filter.Local(), entity, true, audioParams);
var audio = new SoundPathSpecifier(keyFrame.Resource)
{
Params = audioParams
};
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>().PlayEntity(audio, Filter.Local(), entity, true);
}
return (keyFrameIndex, playingTime);
@@ -51,7 +55,7 @@ namespace Robust.Client.Animations
/// <summary>
/// The RSI state to play when this keyframe gets triggered.
/// </summary>
public readonly ResolvedSoundSpecifier Specifier;
public readonly string Resource;
/// <summary>
/// A function that returns the audio parameter to be used.
@@ -65,9 +69,9 @@ namespace Robust.Client.Animations
/// </summary>
public readonly float KeyTime;
public KeyFrame(ResolvedSoundSpecifier specifier, float keyTime, Func<AudioParams>? audioParams = null)
public KeyFrame(string resource, float keyTime, Func<AudioParams>? audioParams = null)
{
Specifier = specifier;
Resource = resource;
KeyTime = keyTime;
AudioParamsFunc = audioParams ?? (() => AudioParams.Default);
}

View File

@@ -415,16 +415,6 @@ public sealed partial class AudioSystem : SharedAudioSystem
return occlusion;
}
private bool TryGetAudio(ResolvedSoundSpecifier specifier, [NotNullWhen(true)] out AudioResource? audio)
{
var filename = GetAudioPath(specifier);
if (_resourceCache.TryGetResource(new ResPath(filename), out audio))
return true;
Log.Error($"Server tried to play audio file {filename} which does not exist.");
return false;
}
private bool TryGetAudio(string filename, [NotNullWhen(true)] out AudioResource? audio)
{
if (_resourceCache.TryGetResource(new ResPath(filename), out audio))
@@ -443,15 +433,15 @@ public sealed partial class AudioSystem : SharedAudioSystem
return false;
}
public override (EntityUid Entity, AudioComponent Component)? PlayPvs(ResolvedSoundSpecifier? specifier, EntityCoordinates coordinates,
public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string? filename, EntityCoordinates coordinates,
AudioParams? audioParams = null)
{
return PlayStatic(specifier, Filter.Local(), coordinates, true, audioParams);
return PlayStatic(filename, Filter.Local(), coordinates, true, audioParams);
}
public override (EntityUid Entity, AudioComponent Component)? PlayPvs(ResolvedSoundSpecifier? specifier, EntityUid uid, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string? filename, EntityUid uid, AudioParams? audioParams = null)
{
return PlayEntity(specifier, Filter.Local(), uid, true, audioParams);
return PlayEntity(filename, Filter.Local(), uid, true, audioParams);
}
/// <inheritdoc />
@@ -487,21 +477,21 @@ public sealed partial class AudioSystem : SharedAudioSystem
/// </summary>
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
/// <param name="audioParams"></param>
private (EntityUid Entity, AudioComponent Component)? PlayGlobal(ResolvedSoundSpecifier? specifier, AudioParams? audioParams = null, bool recordReplay = true)
private (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, AudioParams? audioParams = null, bool recordReplay = true)
{
if (specifier is null)
if (string.IsNullOrEmpty(filename))
return null;
if (recordReplay && _replayRecording.IsRecording)
{
_replayRecording.RecordReplayMessage(new PlayAudioGlobalMessage
{
Specifier = specifier,
FileName = filename,
AudioParams = audioParams ?? AudioParams.Default
});
}
return TryGetAudio(specifier, out var audio) ? PlayGlobal(audio, specifier, audioParams) : default;
return TryGetAudio(filename, out var audio) ? PlayGlobal(audio, audioParams) : default;
}
/// <summary>
@@ -509,9 +499,9 @@ public sealed partial class AudioSystem : SharedAudioSystem
/// </summary>
/// <param name="stream">The audio stream to play.</param>
/// <param name="audioParams"></param>
public (EntityUid Entity, AudioComponent Component)? PlayGlobal(AudioStream stream, ResolvedSoundSpecifier? specifier, AudioParams? audioParams = null)
public (EntityUid Entity, AudioComponent Component)? PlayGlobal(AudioStream stream, AudioParams? audioParams = null)
{
var (entity, component) = CreateAndStartPlayingStream(audioParams, specifier, stream);
var (entity, component) = CreateAndStartPlayingStream(audioParams, stream);
component.Global = true;
component.Source.Global = true;
DirtyField(entity, component, nameof(AudioComponent.Global));
@@ -523,22 +513,22 @@ public sealed partial class AudioSystem : SharedAudioSystem
/// </summary>
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
/// <param name="entity">The entity "emitting" the audio.</param>
private (EntityUid Entity, AudioComponent Component)? PlayEntity(ResolvedSoundSpecifier? specifier, EntityUid entity, AudioParams? audioParams = null, bool recordReplay = true)
private (EntityUid Entity, AudioComponent Component)? PlayEntity(string? filename, EntityUid entity, AudioParams? audioParams = null, bool recordReplay = true)
{
if (specifier is null)
if (string.IsNullOrEmpty(filename))
return null;
if (recordReplay && _replayRecording.IsRecording)
{
_replayRecording.RecordReplayMessage(new PlayAudioEntityMessage
{
Specifier = specifier,
FileName = filename,
NetEntity = GetNetEntity(entity),
AudioParams = audioParams ?? AudioParams.Default
});
}
return TryGetAudio(specifier, out var audio) ? PlayEntity(audio, entity, specifier, audioParams) : default;
return TryGetAudio(filename, out var audio) ? PlayEntity(audio, entity, audioParams) : default;
}
/// <summary>
@@ -547,7 +537,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
/// <param name="stream">The audio stream to play.</param>
/// <param name="entity">The entity "emitting" the audio.</param>
/// <param name="audioParams"></param>
public (EntityUid Entity, AudioComponent Component)? PlayEntity(AudioStream stream, EntityUid entity, ResolvedSoundSpecifier? specifier, AudioParams? audioParams = null)
public (EntityUid Entity, AudioComponent Component)? PlayEntity(AudioStream stream, EntityUid entity, AudioParams? audioParams = null)
{
if (TerminatingOrDeleted(entity))
{
@@ -555,7 +545,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
return null;
}
var playing = CreateAndStartPlayingStream(audioParams, specifier, stream);
var playing = CreateAndStartPlayingStream(audioParams, stream);
_xformSys.SetCoordinates(playing.Entity, new EntityCoordinates(entity, Vector2.Zero));
return playing;
@@ -567,22 +557,22 @@ public sealed partial class AudioSystem : SharedAudioSystem
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
/// <param name="coordinates">The coordinates at which to play the audio.</param>
/// <param name="audioParams"></param>
private (EntityUid Entity, AudioComponent Component)? PlayStatic(ResolvedSoundSpecifier? specifier, EntityCoordinates coordinates, AudioParams? audioParams = null, bool recordReplay = true)
private (EntityUid Entity, AudioComponent Component)? PlayStatic(string? filename, EntityCoordinates coordinates, AudioParams? audioParams = null, bool recordReplay = true)
{
if (specifier is null)
if (string.IsNullOrEmpty(filename))
return null;
if (recordReplay && _replayRecording.IsRecording)
{
_replayRecording.RecordReplayMessage(new PlayAudioPositionalMessage
{
Specifier = specifier,
FileName = filename,
Coordinates = GetNetCoordinates(coordinates),
AudioParams = audioParams ?? AudioParams.Default
});
}
return TryGetAudio(specifier, out var audio) ? PlayStatic(audio, coordinates, specifier, audioParams) : default;
return TryGetAudio(filename, out var audio) ? PlayStatic(audio, coordinates, audioParams) : default;
}
/// <summary>
@@ -591,7 +581,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
/// <param name="stream">The audio stream to play.</param>
/// <param name="coordinates">The coordinates at which to play the audio.</param>
/// <param name="audioParams"></param>
public (EntityUid Entity, AudioComponent Component)? PlayStatic(AudioStream stream, EntityCoordinates coordinates, ResolvedSoundSpecifier? specifier, AudioParams? audioParams = null)
public (EntityUid Entity, AudioComponent Component)? PlayStatic(AudioStream stream, EntityCoordinates coordinates, AudioParams? audioParams = null)
{
if (TerminatingOrDeleted(coordinates.EntityId))
{
@@ -599,33 +589,33 @@ public sealed partial class AudioSystem : SharedAudioSystem
return null;
}
var playing = CreateAndStartPlayingStream(audioParams, specifier, stream);
var playing = CreateAndStartPlayingStream(audioParams, stream);
_xformSys.SetCoordinates(playing.Entity, coordinates);
return playing;
}
/// <inheritdoc />
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(ResolvedSoundSpecifier? specifier, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null)
{
return PlayGlobal(specifier, audioParams);
return PlayGlobal(filename, audioParams);
}
/// <inheritdoc />
public override (EntityUid Entity, AudioComponent Component)? PlayEntity(ResolvedSoundSpecifier? specifier, Filter playerFilter, EntityUid entity, bool recordReplay, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string? filename, Filter playerFilter, EntityUid entity, bool recordReplay, AudioParams? audioParams = null)
{
return PlayEntity(specifier, entity, audioParams);
return PlayEntity(filename, entity, audioParams);
}
/// <inheritdoc />
public override (EntityUid Entity, AudioComponent Component)? PlayStatic(ResolvedSoundSpecifier? specifier, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string? filename, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null)
{
return PlayStatic(specifier, coordinates, audioParams);
return PlayStatic(filename, coordinates, audioParams);
}
/// <inheritdoc />
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(ResolvedSoundSpecifier? specifier, ICommonSession recipient, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, ICommonSession recipient, AudioParams? audioParams = null)
{
return PlayGlobal(specifier, audioParams);
return PlayGlobal(filename, audioParams);
}
public override void LoadStream<T>(Entity<AudioComponent> entity, T stream)
@@ -639,39 +629,39 @@ public sealed partial class AudioSystem : SharedAudioSystem
}
/// <inheritdoc />
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(ResolvedSoundSpecifier? specifier, EntityUid recipient, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, EntityUid recipient, AudioParams? audioParams = null)
{
return PlayGlobal(specifier, audioParams);
return PlayGlobal(filename, audioParams);
}
/// <inheritdoc />
public override (EntityUid Entity, AudioComponent Component)? PlayEntity(ResolvedSoundSpecifier? specifier, ICommonSession recipient, EntityUid uid, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string? filename, ICommonSession recipient, EntityUid uid, AudioParams? audioParams = null)
{
return PlayEntity(specifier, uid, audioParams);
return PlayEntity(filename, uid, audioParams);
}
/// <inheritdoc />
public override (EntityUid Entity, AudioComponent Component)? PlayEntity(ResolvedSoundSpecifier? specifier, EntityUid recipient, EntityUid uid, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string? filename, EntityUid recipient, EntityUid uid, AudioParams? audioParams = null)
{
return PlayEntity(specifier, uid, audioParams);
return PlayEntity(filename, uid, audioParams);
}
/// <inheritdoc />
public override (EntityUid Entity, AudioComponent Component)? PlayStatic(ResolvedSoundSpecifier? specifier, ICommonSession recipient, EntityCoordinates coordinates, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string? filename, ICommonSession recipient, EntityCoordinates coordinates, AudioParams? audioParams = null)
{
return PlayStatic(specifier, coordinates, audioParams);
return PlayStatic(filename, coordinates, audioParams);
}
/// <inheritdoc />
public override (EntityUid Entity, AudioComponent Component)? PlayStatic(ResolvedSoundSpecifier? specifier, EntityUid recipient, EntityCoordinates coordinates, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string? filename, EntityUid recipient, EntityCoordinates coordinates, AudioParams? audioParams = null)
{
return PlayStatic(specifier, coordinates, audioParams);
return PlayStatic(filename, coordinates, audioParams);
}
private (EntityUid Entity, AudioComponent Component) CreateAndStartPlayingStream(AudioParams? audioParams, ResolvedSoundSpecifier? specifier, AudioStream stream)
private (EntityUid Entity, AudioComponent Component) CreateAndStartPlayingStream(AudioParams? audioParams, AudioStream stream)
{
var audioP = audioParams ?? AudioParams.Default;
var entity = SetupAudio(specifier, audioP, initialize: false, length: stream.Length);
var entity = SetupAudio(null, audioP, initialize: false, length: stream.Length);
LoadStream(entity, stream);
EntityManager.InitializeAndStartEntity(entity);
var comp = entity.Comp;
@@ -704,17 +694,17 @@ public sealed partial class AudioSystem : SharedAudioSystem
private void OnEntityCoordinates(PlayAudioPositionalMessage ev)
{
PlayStatic(ev.Specifier, GetCoordinates(ev.Coordinates), ev.AudioParams, false);
PlayStatic(ev.FileName, GetCoordinates(ev.Coordinates), ev.AudioParams, false);
}
private void OnEntityAudio(PlayAudioEntityMessage ev)
{
PlayEntity(ev.Specifier, GetEntity(ev.NetEntity), ev.AudioParams, false);
PlayEntity(ev.FileName, GetEntity(ev.NetEntity), ev.AudioParams, false);
}
private void OnGlobalAudio(PlayAudioGlobalMessage ev)
{
PlayGlobal(ev.Specifier, ev.AudioParams, false);
PlayGlobal(ev.FileName, ev.AudioParams, false);
}
protected override TimeSpan GetAudioLengthImpl(string filename)

View File

@@ -115,6 +115,10 @@ namespace Robust.Client
/// <inheritdoc />
public void DisconnectFromServer(string reason)
{
DebugTools.Assert(RunLevel > ClientRunLevel.Initialize);
DebugTools.Assert(_net.IsConnected);
// run level changed in OnNetDisconnect()
// are both of these *really* needed?
_net.ClientDisconnect(reason);
}

View File

@@ -382,7 +382,7 @@ namespace Robust.Client
_prof.Initialize();
_resManager.Initialize(Options.LoadConfigAndUserData ? userDataDir : null, hideUserDataDir: true);
_resManager.Initialize(Options.LoadConfigAndUserData ? userDataDir : null);
var mountOptions = _commandLineArgs != null
? MountOptions.Merge(_commandLineArgs.MountOptions, Options.MountOptions)

View File

@@ -101,33 +101,11 @@ namespace Robust.Client.GameObjects
/// <inheritdoc />
public override void Dirty<T>(Entity<T> ent, MetaDataComponent? meta = null)
{
// Client only dirties during prediction
// Client only dirties during prediction
if (_gameTiming.InPrediction)
base.Dirty(ent, meta);
}
public override void DirtyField<T>(EntityUid uid, T comp, string fieldName, MetaDataComponent? metadata = null)
{
// TODO Prediction
// does the client actually need to dirty the field?
// I.e., can't it just dirty the whole component to trigger a reset?
// Client only dirties during prediction
if (_gameTiming.InPrediction)
base.DirtyField(uid, comp, fieldName, metadata);
}
public override void DirtyFields<T>(EntityUid uid, T comp, MetaDataComponent? meta, params ReadOnlySpan<string> fields)
{
// TODO Prediction
// does the client actually need to dirty the field?
// I.e., can't it just dirty the whole component to trigger a reset?
// Client only dirties during prediction
if (_gameTiming.InPrediction)
base.DirtyFields(uid, comp, meta, fields);
}
/// <inheritdoc />
public override void Dirty<T1, T2>(Entity<T1, T2> ent, MetaDataComponent? meta = null)
{

View File

@@ -17,7 +17,7 @@ public sealed class MapSystem : SharedMapSystem
{
// Client-side map entities use negative map Ids to avoid conflict with server-side maps.
var id = new MapId(--LastMapId);
while (MapExists(id) || UsedIds.Contains(id))
while (MapManager.MapExists(id))
{
id = new MapId(--LastMapId);
}

View File

@@ -1,18 +1,10 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using Robust.Client.UserInterface;
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Robust.Client.GameObjects;
public sealed class UserInterfaceSystem : SharedUserInterfaceSystem
{
private Dictionary<EntityUid, Dictionary<Enum, Vector2>> _savedPositions = new();
private Dictionary<BoundUserInterface, Control> _registeredControls = new();
public override void Initialize()
{
base.Initialize();
@@ -25,59 +17,6 @@ public sealed class UserInterfaceSystem : SharedUserInterfaceSystem
ProtoManager.PrototypesReloaded -= OnProtoReload;
}
protected override void OnUserInterfaceShutdown(Entity<UserInterfaceComponent> ent, ref ComponentShutdown args)
{
base.OnUserInterfaceShutdown(ent, ref args);
_savedPositions.Remove(ent.Owner);
}
/// <inheritdoc />
public override void OpenUi(Entity<UserInterfaceComponent?> entity, Enum key, bool predicted = false)
{
var player = Player.LocalEntity;
if (player == null)
return;
OpenUi(entity, key, player.Value, predicted);
}
protected override void SavePosition(BoundUserInterface bui)
{
if (!_registeredControls.Remove(bui, out var control))
return;
var keyed = _savedPositions[bui.Owner];
keyed[bui.UiKey] = control.Position;
}
/// <summary>
/// Registers a control so it will later have its position stored by <see cref="SavePosition"/> when the BUI is closed.
/// </summary>
public void RegisterControl(BoundUserInterface bui, Control control)
{
DebugTools.Assert(!_registeredControls.ContainsKey(bui));
_registeredControls[bui] = control;
_savedPositions.GetOrNew(bui.Owner);
}
public override bool TryGetPosition(Entity<UserInterfaceComponent?> entity, Enum key, out Vector2 position)
{
position = default;
if (!_savedPositions.TryGetValue(entity.Owner, out var keyed))
{
return false;
}
if (!keyed.TryGetValue(key, out position))
{
return false;
}
return true;
}
private void OnProtoReload(PrototypesReloadedEventArgs obj)
{
var player = Player.LocalEntity;

View File

@@ -1,8 +0,0 @@
using Robust.Shared.GameObjects;
namespace Robust.Client.GameObjects;
public sealed class VisibilitySystem : SharedVisibilitySystem
{
}

View File

@@ -23,6 +23,7 @@ using Robust.Shared.Input;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Network.Messages;
using Robust.Shared.Profiling;
@@ -41,13 +42,13 @@ namespace Robust.Client.GameStates
private uint _nextInputCmdSeq = 1;
private readonly Queue<FullInputCmdMessage> _pendingInputs = new();
private readonly Queue<(uint sequence, GameTick sourceTick, object msg, object sessionMsg)>
private readonly Queue<(uint sequence, GameTick sourceTick, EntityEventArgs msg, object sessionMsg)>
_pendingSystemMessages
= new();
// Game state dictionaries that get used every tick.
private readonly Dictionary<EntityUid, StateData> _toApply = new();
private StateData[] _toApplySorted = default!;
private readonly Dictionary<EntityUid, (NetEntity NetEntity, MetaDataComponent Meta, bool EnteringPvs, GameTick LastApplied, EntityState? curState, EntityState? nextState)> _toApply = new();
private readonly Dictionary<NetEntity, EntityState> _toCreate = new();
private readonly Dictionary<ushort, (IComponent Component, IComponentState? curState, IComponentState? nextState)> _compStateWork = new();
private readonly Dictionary<EntityUid, HashSet<Type>> _pendingReapplyNetStates = new();
private readonly HashSet<NetEntity> _stateEnts = new();
@@ -55,29 +56,15 @@ namespace Robust.Client.GameStates
private readonly List<IComponent> _toRemove = new();
private readonly Dictionary<NetEntity, Dictionary<ushort, IComponentState?>> _outputData = new();
private readonly List<(EntityUid, TransformComponent)> _queuedBroadphaseUpdates = new();
private readonly HashSet<EntityUid> _sorted = new();
private readonly List<NetEntity> _created = new();
private readonly List<NetEntity> _detached = new();
private readonly record struct StateData(
EntityUid Uid,
NetEntity NetEntity,
MetaDataComponent Meta,
bool Created,
bool EnteringPvs,
GameTick LastApplied,
EntityState? CurState,
EntityState? NextState,
HashSet<Type>? PendingReapply);
private readonly ObjectPool<Dictionary<ushort, IComponentState?>> _compDataPool =
new DefaultObjectPool<Dictionary<ushort, IComponentState?>>(new DictPolicy<ushort, IComponentState?>(), 256);
private uint _metaCompNetId;
private uint _xformCompNetId;
[Dependency] private readonly IReplayRecordingManager _replayRecording = default!;
[Dependency] private readonly IComponentFactory _compFactory = default!;
[Dependency] private readonly IClientEntityManagerInternal _entities = default!;
[Dependency] private readonly IPlayerManager _players = default!;
[Dependency] private readonly IClientNetManager _network = default!;
[Dependency] private readonly IBaseClient _client = default!;
@@ -85,7 +72,7 @@ namespace Robust.Client.GameStates
[Dependency] private readonly INetConfigurationManager _config = default!;
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
[Dependency] private readonly IConsoleHost _conHost = default!;
[Dependency] private readonly ClientEntityManager _entities = default!;
[Dependency] private readonly ClientEntityManager _entityManager = default!;
[Dependency] private readonly IInputManager _inputManager = default!;
[Dependency] private readonly ProfManager _prof = default!;
[Dependency] private readonly IRuntimeLog _runtimeLog = default!;
@@ -139,6 +126,7 @@ namespace Robust.Client.GameStates
private bool _resettingPredictedEntities;
private readonly List<EntityUid> _brokenEnts = new();
private readonly List<(EntityUid, NetEntity)> _toStart = new();
/// <inheritdoc />
public void Initialize()
@@ -184,12 +172,6 @@ namespace Robust.Client.GameStates
throw new InvalidOperationException("MetaDataComponent does not have a NetId.");
_metaCompNetId = metaId.Value;
var xformId = _compFactory.GetRegistration(typeof(TransformComponent)).NetID;
if (!xformId.HasValue)
throw new InvalidOperationException("TransformComponent does not have a NetId.");
_xformCompNetId = xformId.Value;
}
private void OnComponentAdded(AddedComponentEventArgs args)
@@ -201,11 +183,11 @@ namespace Robust.Client.GameStates
if (comp.NetID == null)
return;
if (_entities.IsClientSide(args.BaseArgs.Owner))
if (_entityManager.IsClientSide(args.BaseArgs.Owner))
return;
_sawmill.Error($"""
Added component {comp.Name} to entity {_entities.ToPrettyString(args.BaseArgs.Owner)} while resetting predicted entities.
Added component {comp.Name} to entity {_entityManager.ToPrettyString(args.BaseArgs.Owner)} while resetting predicted entities.
Stack trace:
{Environment.StackTrace}
""");
@@ -403,7 +385,7 @@ namespace Robust.Client.GameStates
try
{
#endif
ApplyGameState(curState, nextState);
createdEntities = ApplyGameState(curState, nextState);
#if EXCEPTION_TOLERANCE
}
catch (MissingMetadataException e)
@@ -417,7 +399,7 @@ namespace Robust.Client.GameStates
using (_prof.Group("MergeImplicitData"))
{
MergeImplicitData();
GenerateImplicitStates(createdEntities);
}
if (_lastProcessedInput < curState.LastProcessedInput)
@@ -474,7 +456,7 @@ namespace Robust.Client.GameStates
using (_prof.Group("Tick"))
{
_entities.TickUpdate((float) _timing.TickPeriod.TotalSeconds, noPredictions: !IsPredictionEnabled, histogram: null);
_entities.TickUpdate((float) _timing.TickPeriod.TotalSeconds, noPredictions: !IsPredictionEnabled);
}
}
@@ -522,7 +504,9 @@ namespace Robust.Client.GameStates
while (hasPendingMessage && pendingMessagesEnumerator.Current.sourceTick <= _timing.CurTick)
{
_entities.EventBus.RaiseEvent(EventSource.Local, pendingMessagesEnumerator.Current.msg);
var msg = pendingMessagesEnumerator.Current.msg;
_entities.EventBus.RaiseEvent(EventSource.Local, msg);
_entities.EventBus.RaiseEvent(EventSource.Local, pendingMessagesEnumerator.Current.sessionMsg);
hasPendingMessage = pendingMessagesEnumerator.MoveNext();
}
@@ -561,7 +545,7 @@ namespace Robust.Client.GameStates
PredictionNeedsResetting = false;
var countReset = 0;
var system = _entitySystemManager.GetEntitySystem<ClientDirtySystem>();
var metaQuery = _entities.GetEntityQuery<MetaDataComponent>();
var metaQuery = _entityManager.GetEntityQuery<MetaDataComponent>();
RemQueue<IComponent> toRemove = new();
foreach (var entity in system.DirtyEntities)
@@ -648,7 +632,7 @@ namespace Robust.Client.GameStates
if (!last.TryGetValue(netId, out var state))
continue;
var comp = _entities.AddComponent(entity, netId, meta);
var comp = _entityManager.AddComponent(entity, netId, meta);
if (_sawmill.Level <= LogLevel.Debug)
_sawmill.Debug($" A component was removed: {comp.GetType()}");
@@ -668,7 +652,7 @@ namespace Robust.Client.GameStates
meta.EntityLastModifiedTick = _timing.LastRealTick;
}
_entities.System<PhysicsSystem>().ResetContacts();
_entityManager.System<PhysicsSystem>().ResetContacts();
// TODO maybe reset more of physics?
// E.g., warm impulses for warm starting?
@@ -687,21 +671,21 @@ namespace Robust.Client.GameStates
/// initial server state for any newly created entity. It does this by simply using the standard <see
/// cref="IEntityManager.GetComponentState"/>.
/// </remarks>
public void MergeImplicitData()
public void GenerateImplicitStates(IEnumerable<NetEntity> createdEntities)
{
var bus = _entities.EventBus;
var bus = _entityManager.EventBus;
foreach (var netEntity in _created)
foreach (var netEntity in createdEntities)
{
if (!_entities.TryGetEntityData(netEntity, out _, out var meta))
#if EXCEPTION_TOLERANCE
if (!_entityManager.TryGetEntityData(netEntity, out _, out var meta))
{
_sawmill.Error($"Encountered deleted entity while merging implicit data! NetEntity: {netEntity}");
#if !EXCEPTION_TOLERANCE
throw new KeyNotFoundException();
#endif
continue;
}
#else
var (_, meta) = _entityManager.GetEntityData(netEntity);
#endif
var compData = _compDataPool.Get();
_outputData.Add(netEntity, compData);
@@ -710,13 +694,12 @@ namespace Robust.Client.GameStates
{
DebugTools.Assert(component.NetSyncEnabled);
var state = _entities.GetComponentState(bus, component, null, GameTick.Zero);
var state = _entityManager.GetComponentState(bus, component, null, GameTick.Zero);
DebugTools.Assert(state is not IComponentDeltaState);
compData.Add(netId, state);
}
}
_created.Clear();
_processor.MergeImplicitData(_outputData);
foreach (var data in _outputData.Values)
@@ -752,9 +735,10 @@ namespace Robust.Client.GameStates
_config.TickProcessMessages();
}
(IEnumerable<NetEntity> Created, List<NetEntity> Detached) output;
using (_prof.Group("Entity"))
{
ApplyEntityStates(curState, nextState);
output = ApplyEntityStates(curState, nextState);
}
using (_prof.Group("Player"))
@@ -764,13 +748,13 @@ namespace Robust.Client.GameStates
using (_prof.Group("Callback"))
{
GameStateApplied?.Invoke(new GameStateAppliedArgs(curState, _detached));
GameStateApplied?.Invoke(new GameStateAppliedArgs(curState, output.Detached));
}
return _created;
return output.Created;
}
private void ApplyEntityStates(GameState curState, GameState? nextState)
private (IEnumerable<NetEntity> Created, List<NetEntity> Detached) ApplyEntityStates(GameState curState, GameState? nextState)
{
var metas = _entities.GetEntityQuery<MetaDataComponent>();
var xforms = _entities.GetEntityQuery<TransformComponent>();
@@ -778,74 +762,90 @@ namespace Robust.Client.GameStates
var enteringPvs = 0;
_toApply.Clear();
_created.Clear();
_toCreate.Clear();
_pendingReapplyNetStates.Clear();
var curSpan = curState.EntityStates.Span;
// Create new entities
// This is done BEFORE state application to ensure any new parents exist before existing children have their states applied, otherwise, we may have issues with entity transforms!
using (_prof.Group("Create uninitialized entities"))
{
var created = 0;
using var _ = _prof.Group("Create uninitialized entities");
var count = 0;
foreach (var es in curSpan)
{
if (_entities.TryGetEntity(es.NetEntity, out var nUid))
if (_entityManager.TryGetEntity(es.NetEntity, out var nUid))
{
DebugTools.Assert(_entities.EntityExists(nUid));
DebugTools.Assert(_entityManager.EntityExists(nUid));
continue;
}
created++;
CreateNewEntity(es, curState.ToSequence);
count++;
var metaState = (MetaDataComponentState?)es.ComponentChanges.Value?.FirstOrDefault(c => c.NetID == _metaCompNetId).State;
if (metaState == null)
throw new MissingMetadataException(es.NetEntity);
var uid = _entities.CreateEntity(metaState.PrototypeId, out var newMeta);
_toCreate.Add(es.NetEntity, es);
_toApply.Add(uid, (es.NetEntity, newMeta, false, GameTick.Zero, es, null));
// Client creates a client-side net entity for the newly created entity.
// We need to clear this mapping before assigning the real net id.
// TODO NetEntity Jank: prevent the client from creating this in the first place.
_entityManager.ClearNetEntity(newMeta.NetEntity);
_entityManager.SetNetEntity(uid, es.NetEntity, newMeta);
newMeta.LastStateApplied = curState.ToSequence;
// Check if there's any component states awaiting this entity.
if (_entityManager.PendingNetEntityStates.Remove(es.NetEntity, out var value))
{
foreach (var (type, owner) in value)
{
var pending = _pendingReapplyNetStates.GetOrNew(owner);
pending.Add(type);
}
}
}
_prof.WriteValue("Count", ProfData.Int32(created));
_prof.WriteValue("Count", ProfData.Int32(count));
}
// Add entity entities that aren't new to _toCreate.
// In the process, we also check if these entities are re-entering PVS range.
foreach (var es in curSpan)
{
if (!_entities.TryGetEntityData(es.NetEntity, out var uid, out var meta))
if (_toCreate.ContainsKey(es.NetEntity))
continue;
var isEnteringPvs = (meta.Flags & MetaDataFlags.Detached) != 0;
if (!_entityManager.TryGetEntityData(es.NetEntity, out var uid, out var meta))
continue;
bool isEnteringPvs = (meta.Flags & MetaDataFlags.Detached) != 0;
if (isEnteringPvs)
{
// _toApply already contains newly created entities, but these should never be "entering PVS"
DebugTools.Assert(!_toApply.ContainsKey(uid.Value));
meta.Flags &= ~MetaDataFlags.Detached;
enteringPvs++;
}
else if (meta.LastStateApplied >= es.EntityLastModified && meta.LastStateApplied != GameTick.Zero)
{
// _toApply already contains newly created entities, but for those this set should have no effect
DebugTools.Assert(!_toApply.ContainsKey(uid.Value) || meta.LastStateApplied == curState.ToSequence);
meta.LastStateApplied = curState.ToSequence;
continue;
}
// Any newly created entities already added to _toApply should've already been caught by the previous continue
DebugTools.Assert(!_toApply.ContainsKey(uid.Value));
_toApply.Add(uid.Value, new(uid.Value, es.NetEntity, meta, false, isEnteringPvs, meta.LastStateApplied, es, null, null));
_toApply.Add(uid.Value, (es.NetEntity, meta, isEnteringPvs, meta.LastStateApplied, es, null));
meta.LastStateApplied = curState.ToSequence;
}
// Detach entities to null space
var containerSys = _entitySystemManager.GetEntitySystem<ContainerSystem>();
var lookupSys = _entitySystemManager.GetEntitySystem<EntityLookupSystem>();
ProcessPvsDeparture(curState.ToSequence, metas, xforms, xformSys, containerSys, lookupSys);
var detached = ProcessPvsDeparture(curState.ToSequence, metas, xforms, xformSys, containerSys, lookupSys);
// Check next state (AFTER having created new entities introduced in curstate)
if (nextState != null)
{
foreach (var es in nextState.EntityStates.Span)
{
if (!_entities.TryGetEntityData(es.NetEntity, out var uid, out var meta))
if (!_entityManager.TryGetEntityData(es.NetEntity, out var uid, out var meta))
continue;
// Does the next state actually have any future information about this entity that could be used for interpolation?
@@ -854,14 +854,15 @@ namespace Robust.Client.GameStates
ref var state = ref CollectionsMarshal.GetValueRefOrAddDefault(_toApply, uid.Value, out var exists);
state = exists
? state with {NextState = es}
: new(uid.Value, es.NetEntity, meta, false, false, GameTick.Zero, null, es, null);
if (exists)
state = (es.NetEntity, meta, state.EnteringPvs, state.LastApplied, state.curState, es);
else
state = (es.NetEntity, meta, false, GameTick.Zero, null, es);
}
}
// Check pending states and see if we need to force any entities to re-run component states.
foreach (var (uid, pending) in _pendingReapplyNetStates)
foreach (var uid in _pendingReapplyNetStates.Keys)
{
// Original entity referencing the NetEntity may have been deleted.
if (!metas.TryGetComponent(uid, out var meta))
@@ -878,30 +879,51 @@ namespace Robust.Client.GameStates
DebugTools.Assert(!curState.EntityDeletions.Value.Contains(meta.NetEntity));
// State already being re-applied so don't bulldoze it.
ref var state = ref CollectionsMarshal.GetValueRefOrAddDefault(_toApply, uid, out var exists);
state = exists
? state with {PendingReapply = pending}
: new(uid, meta.NetEntity, meta, false, false, GameTick.Zero, null, null, pending);
if (exists)
continue;
state = (meta.NetEntity, meta, false, GameTick.Zero, null, null);
}
_queuedBroadphaseUpdates.Clear();
using (_prof.Group("Sort States"))
{
SortStates(_toApply);
}
// Apply entity states.
using (_prof.Group("Apply States"))
{
var span = _toApplySorted.AsSpan(0, _toApply.Count);
foreach (ref var data in span)
foreach (var (entity, data) in _toApply)
{
ApplyEntState(data, curState.ToSequence);
#if EXCEPTION_TOLERANCE
try
{
#endif
HandleEntityState(entity, data.NetEntity, data.Meta, _entities.EventBus, data.curState,
data.nextState, data.LastApplied, curState.ToSequence, data.EnteringPvs);
#if EXCEPTION_TOLERANCE
}
catch (Exception e)
{
_sawmill.Error($"Caught exception while applying entity state. Entity: {_entities.ToPrettyString(entity)}. Exception: {e}");
_entityManager.DeleteEntity(entity);
RequestFullState();
continue;
}
#endif
if (!data.EnteringPvs)
continue;
// Now that things like collision data, fixtures, and positions have been updated, we queue a
// broadphase update. However, if this entity is parented to some other entity also re-entering PVS,
// we only need to update it's parent (as it recursively updates children anyways).
var xform = xforms.GetComponent(entity);
DebugTools.Assert(xform.Broadphase == BroadphaseData.Invalid);
xform.Broadphase = null;
if (!_toApply.TryGetValue(xform.ParentUid, out var parent) || !parent.EnteringPvs)
_queuedBroadphaseUpdates.Add((entity, xform));
}
Array.Clear(_toApplySorted, 0, _toApply.Count);
_prof.WriteValue("Count", ProfData.Int32(_toApply.Count));
}
@@ -936,166 +958,14 @@ namespace Robust.Client.GameStates
}
}
// Delete any entities that failed to properly initialize/start
foreach (var entity in _brokenEnts)
{
_entities.DeleteEntity(entity);
}
_brokenEnts.Clear();
// Initialize and start the newly created entities.
if (_toCreate.Count > 0)
InitializeAndStart(_toCreate, metas, xforms);
_prof.WriteValue("State Size", ProfData.Int32(curSpan.Length));
_prof.WriteValue("Entered PVS", ProfData.Int32(enteringPvs));
}
private void ApplyEntState(in StateData data, GameTick toTick)
{
try
{
HandleEntityState(data, _entities.EventBus, toTick);
}
catch (Exception e)
{
_sawmill.Error($"Caught exception while applying entity state. Entity: {_entities.ToPrettyString(data.Uid)}. Exception: {e}");
_brokenEnts.Add(data.Uid);
RequestFullState();
#if !EXCEPTION_TOLERANCE
throw;
#endif
return;
}
if (data.Created)
{
try
{
_entities.InitializeEntity(data.Uid, data.Meta);
_entities.StartEntity(data.Uid);
}
catch (Exception e)
{
_sawmill.Error(
$"Caught exception while initializing or starting entity: {_entities.ToPrettyString(data.Uid)}. Exception: {e}");
_brokenEnts.Add(data.Uid);
RequestFullState();
#if !EXCEPTION_TOLERANCE
throw;
#endif
return;
}
}
if (!data.EnteringPvs)
return;
// Now that things like collision data, fixtures, and positions have been updated, we queue a
// broadphase update. However, if this entity is parented to some other entity also re-entering PVS,
// we only need to update it's parent (as it recursively updates children anyways).
var xform = _entities.TransformQuery.Comp(data.Uid);
DebugTools.Assert(xform.Broadphase == BroadphaseData.Invalid);
xform.Broadphase = null;
if (!_toApply.TryGetValue(xform.ParentUid, out var parent) || !parent.EnteringPvs)
_queuedBroadphaseUpdates.Add((data.Uid, xform));
}
private void CreateNewEntity(EntityState state, GameTick toTick)
{
// TODO GAME STATE
// store MetaData & Transform information separately.
var metaState =
(MetaDataComponentState?) state.ComponentChanges.Value?.FirstOrDefault(c => c.NetID == _metaCompNetId)
.State;
if (metaState == null)
throw new MissingMetadataException(state.NetEntity);
var uid = _entities.CreateEntity(metaState.PrototypeId, out var newMeta);
_toApply.Add(uid, new(uid, state.NetEntity, newMeta, true, false, GameTick.Zero, state, null, null));
_created.Add(state.NetEntity);
// Client creates a client-side net entity for the newly created entity.
// We need to clear this mapping before assigning the real net id.
// TODO NetEntity Jank: prevent the client from creating this in the first place.
_entities.ClearNetEntity(newMeta.NetEntity);
_entities.SetNetEntity(uid, state.NetEntity, newMeta);
newMeta.LastStateApplied = toTick;
// Check if there's any component states awaiting this entity.
if (!_entities.PendingNetEntityStates.Remove(state.NetEntity, out var value))
return;
foreach (var (type, owner) in value)
{
var pending = _pendingReapplyNetStates.GetOrNew(owner);
pending.Add(type);
}
}
/// <summary>
/// Sort states to ensure that we always apply states, initialize, and start parent entities before any of their
/// children.
/// </summary>
private void SortStates(Dictionary<EntityUid, StateData> toApply)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (_toApplySorted == null || _toApplySorted.Length < toApply.Count)
Array.Resize(ref _toApplySorted, toApply.Count);
_sorted.Clear();
var i = 0;
foreach (var (ent, data) in toApply)
{
AddToSorted(ent, data, ref i);
}
DebugTools.AssertEqual(i, toApply.Count);
}
private void AddToSorted(EntityUid ent, in StateData data, ref int i)
{
if (!_sorted.Add(ent))
return;
EnsureParentsSorted(ent, data, ref i);
_toApplySorted[i++] = data;
}
private void EnsureParentsSorted(EntityUid ent, in StateData data, ref int i)
{
var parent = GetStateParent(ent, data);
while (parent != EntityUid.Invalid)
{
if (_toApply.TryGetValue(parent, out var parentData))
{
AddToSorted(parent, parentData, ref i);
// The above method will handle the rest of the transform hierarchy, so we can just return early.
return;
}
parent = _entities.TransformQuery.GetComponent(parent).ParentUid;
}
}
/// <summary>
/// Get the entity's parent in the game state that is being applies. I.e., if the state contains a new
/// transform state, get the parent from that. Otherwise, return the entity's current parent.
/// </summary>
private EntityUid GetStateParent(EntityUid uid, in StateData data)
{
// TODO GAME STATE
// store MetaData & Transform information separately.
if (data.CurState != null
&& data.CurState.ComponentChanges.Value
.TryFirstOrNull(c => c.NetID == _xformCompNetId, out var found))
{
var state = (TransformComponentState) found.Value.State!;
return _entities.GetEntity(state.ParentID);
}
return _entities.TransformQuery.GetComponent(uid).ParentUid;
return (_toCreate.Keys, detached);
}
/// <inheritdoc />
@@ -1130,7 +1000,7 @@ namespace Robust.Client.GameStates
_toDelete.Clear();
// Client side entities won't need the transform, but that should always be a tiny minority of entities
var metaQuery = _entities.AllEntityQueryEnumerator<MetaDataComponent, TransformComponent>();
var metaQuery = _entityManager.AllEntityQueryEnumerator<MetaDataComponent, TransformComponent>();
while (metaQuery.MoveNext(out var ent, out var metadata, out var xform))
{
@@ -1197,9 +1067,9 @@ namespace Robust.Client.GameStates
foreach (var netEntity in delSpan)
{
// Don't worry about this for later.
_entities.PendingNetEntityStates.Remove(netEntity);
_entityManager.PendingNetEntityStates.Remove(netEntity);
if (!_entities.TryGetEntity(netEntity, out var id))
if (!_entityManager.TryGetEntity(netEntity, out var id))
continue;
if (!xforms.TryGetComponent(id, out var xform))
@@ -1229,10 +1099,9 @@ namespace Robust.Client.GameStates
var containerSys = _entitySystemManager.GetEntitySystem<ContainerSystem>();
var lookupSys = _entitySystemManager.GetEntitySystem<EntityLookupSystem>();
Detach(GameTick.MaxValue, null, entities, metas, xforms, xformSys, containerSys, lookupSys);
_detached.Clear();
}
private void ProcessPvsDeparture(
private List<NetEntity> ProcessPvsDeparture(
GameTick toTick,
EntityQuery<MetaDataComponent> metas,
EntityQuery<TransformComponent> xforms,
@@ -1241,23 +1110,25 @@ namespace Robust.Client.GameStates
EntityLookupSystem lookupSys)
{
var toDetach = _processor.GetEntitiesToDetach(toTick, _pvsDetachBudget);
var detached = new List<NetEntity>();
if (toDetach.Count == 0)
return;
return detached;
// TODO optimize
// If an entity is leaving PVS, so are all of its children. If we can preserve the hierarchy we can avoid
// things like container insertion and ejection.
using var _ = _prof.Group("Leave PVS");
detached.EnsureCapacity(toDetach.Count);
_detached.Clear();
foreach (var (tick, ents) in toDetach)
{
Detach(tick, toTick, ents, metas, xforms, xformSys, containerSys, lookupSys);
Detach(tick, toTick, ents, metas, xforms, xformSys, containerSys, lookupSys, detached);
}
_prof.WriteValue("Count", ProfData.Int32(_detached.Count));
_prof.WriteValue("Count", ProfData.Int32(detached.Count));
return detached;
}
private void Detach(GameTick maxTick,
@@ -1267,11 +1138,12 @@ namespace Robust.Client.GameStates
EntityQuery<TransformComponent> xforms,
SharedTransformSystem xformSys,
ContainerSystem containerSys,
EntityLookupSystem lookupSys)
EntityLookupSystem lookupSys,
List<NetEntity>? detached = null)
{
foreach (var netEntity in entities)
{
if (!_entities.TryGetEntityData(netEntity, out var ent, out var meta))
if (!_entityManager.TryGetEntityData(netEntity, out var ent, out var meta))
continue;
if (meta.LastStateApplied > maxTick)
@@ -1312,75 +1184,159 @@ namespace Robust.Client.GameStates
containerSys.AddExpectedEntity(netEntity, container);
}
_detached.Add(netEntity);
detached?.Add(netEntity);
}
}
private void HandleEntityState(in StateData data, IEventBus bus, GameTick toTick)
private void InitializeAndStart(
Dictionary<NetEntity, EntityState> toCreate,
EntityQuery<MetaDataComponent> metas,
EntityQuery<TransformComponent> xforms)
{
_toStart.Clear();
using (_prof.Group("Initialize Entity"))
{
EntityUid entity = default;
foreach (var netEntity in toCreate.Keys)
{
(entity, var meta) = _entityManager.GetEntityData(netEntity);
InitializeRecursive(entity, meta, metas, xforms);
}
}
using (_prof.Group("Start Entity"))
{
foreach (var (entity, netEntity) in _toStart)
{
try
{
_entities.StartEntity(entity);
}
catch (Exception e)
{
_sawmill.Error($"Server entity threw in Start: nent={netEntity}, ent={_entityManager.ToPrettyString(entity)}");
_runtimeLog.LogException(e, $"{nameof(ClientGameStateManager)}.{nameof(InitializeAndStart)}");
_toCreate.Remove(netEntity);
_brokenEnts.Add(entity);
#if !EXCEPTION_TOLERANCE
throw;
#endif
}
}
}
foreach (var entity in _brokenEnts)
{
_entityManager.DeleteEntity(entity);
}
_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)
{
_compStateWork.Clear();
// First remove any deleted components
if (data.CurState?.NetComponents is {} netComps)
if (curState?.NetComponents != null)
{
_toRemove.Clear();
foreach (var (id, comp) in data.Meta.NetComponents)
foreach (var (id, comp) in meta.NetComponents)
{
DebugTools.Assert(comp.NetSyncEnabled);
if (!netComps.Contains(id))
if (!curState.NetComponents.Contains(id))
_toRemove.Add(comp);
}
foreach (var comp in _toRemove)
{
_entities.RemoveComponent(data.Uid, comp, data.Meta);
_entities.RemoveComponent(uid, comp, meta);
}
}
if (data.EnteringPvs)
if (enteringPvs)
{
// last-server state has already been updated with new information from curState
// --> simply reset to the most recent server state.
//
// as to why we need to reset: because in the process of detaching to null-space, we will have dirtied
// the entity. most notably, all entities will have been ejected from their containers.
foreach (var (id, state) in _processor.GetLastServerStates(data.NetEntity))
foreach (var (id, state) in _processor.GetLastServerStates(netEntity))
{
if (!data.Meta.NetComponents.TryGetValue(id, out var comp))
if (!meta.NetComponents.TryGetValue(id, out var comp))
{
comp = _compFactory.GetComponent(id);
_entities.AddComponent(data.Uid, comp, true, metadata: data.Meta);
_entityManager.AddComponent(uid, comp, true, metadata: meta);
}
_compStateWork[id] = (comp, state, null);
}
}
else if (data.CurState != null)
else if (curState != null)
{
foreach (var compChange in data.CurState.ComponentChanges.Span)
foreach (var compChange in curState.ComponentChanges.Span)
{
if (!data.Meta.NetComponents.TryGetValue(compChange.NetID, out var comp))
if (!meta.NetComponents.TryGetValue(compChange.NetID, out var comp))
{
comp = _compFactory.GetComponent(compChange.NetID);
_entities.AddComponent(data.Uid, comp, true, metadata: data.Meta);
_entityManager.AddComponent(uid, comp, true, metadata:meta);
}
else if (compChange.LastModifiedTick <= data.LastApplied && data.LastApplied != GameTick.Zero)
else if (compChange.LastModifiedTick <= lastApplied && lastApplied != GameTick.Zero)
continue;
_compStateWork[compChange.NetID] = (comp, compChange.State, null);
}
}
if (data.NextState != null)
if (nextState != null)
{
foreach (var compState in data.NextState.ComponentChanges.Span)
foreach (var compState in nextState.ComponentChanges.Span)
{
if (compState.LastModifiedTick != toTick + 1)
continue;
if (!data.Meta.NetComponents.TryGetValue(compState.NetID, out var comp))
if (!meta.NetComponents.TryGetValue(compState.NetID, out var comp))
{
// The component can be null here due to interp, because the NEXT state will have a new
// component, but the component does not yet exist.
@@ -1398,10 +1354,9 @@ namespace Robust.Client.GameStates
}
// If we have a NetEntity we reference come in then apply their state.
DebugTools.Assert(_pendingReapplyNetStates.ContainsKey(data.Uid) == (data.PendingReapply != null));
if (data.PendingReapply is {} reapplyTypes)
if (_pendingReapplyNetStates.TryGetValue(uid, out var reapplyTypes))
{
var lastState = _processor.GetLastServerStates(data.NetEntity);
var lastState = _processor.GetLastServerStates(netEntity);
foreach (var type in reapplyTypes)
{
@@ -1411,7 +1366,7 @@ namespace Robust.Client.GameStates
if (netId == null)
continue;
if (!data.Meta.NetComponents.TryGetValue(netId.Value, out var comp) ||
if (!meta.NetComponents.TryGetValue(netId.Value, out var comp) ||
!lastState.TryGetValue(netId.Value, out var lastCompState))
{
continue;
@@ -1433,7 +1388,7 @@ namespace Robust.Client.GameStates
continue;
var handleState = new ComponentHandleState(cur, next);
bus.RaiseComponentEvent(data.Uid, comp, ref handleState);
bus.RaiseComponentEvent(uid, comp, ref handleState);
}
}
@@ -1555,7 +1510,7 @@ namespace Robust.Client.GameStates
{
using var _ = _timing.StartStateApplicationArea();
var query = _entities.AllEntityQueryEnumerator<MetaDataComponent>();
var query = _entityManager.AllEntityQueryEnumerator<MetaDataComponent>();
while (query.MoveNext(out var uid, out var meta))
{
@@ -1581,14 +1536,14 @@ namespace Robust.Client.GameStates
if (!meta.NetComponents.TryGetValue(id, out var comp))
{
comp = _compFactory.GetComponent(id);
_entities.AddComponent(uid, comp, true, meta);
_entityManager.AddComponent(uid, comp, true, meta);
}
if (state == null)
continue;
var handleState = new ComponentHandleState(state, null);
_entities.EventBus.RaiseComponentEvent(uid, comp, ref handleState);
_entityManager.EventBus.RaiseComponentEvent(uid, comp, ref handleState);
}
// ensure we don't have any extra components

View File

@@ -82,7 +82,11 @@ namespace Robust.Client.GameStates
/// </summary>
IEnumerable<NetEntity> ApplyGameState(GameState curState, GameState? nextState);
void MergeImplicitData();
/// <summary>
/// Generates implicit component states for newly created entities.
/// This should always be called after running <see cref="ApplyGameState(GameState, GameState)"/>.
/// </summary>
void GenerateImplicitStates(IEnumerable<NetEntity> states);
/// <summary>
/// Resets any entities that have changed while predicting future ticks.

View File

@@ -1,5 +0,0 @@
using Robust.Shared.GameStates;
namespace Robust.Client.GameStates;
public sealed partial class PvsOverrideSystem : SharedPvsOverrideSystem;

View File

@@ -125,8 +125,7 @@ namespace Robust.Client.Graphics.Clyde
{
DebugTools.Assert(space != OverlaySpace.ScreenSpaceBelowWorld && space != OverlaySpace.ScreenSpace);
var mapId = vp.Eye!.Position.MapId;
var args = new OverlayDrawArgs(space, null, vp, _renderHandle, new UIBox2i((0, 0), vp.Size), _mapManager.GetMapEntityIdOrThrow(mapId), mapId, worldBox, worldBounds);
var args = new OverlayDrawArgs(space, null, vp, _renderHandle.DrawingHandleWorld, new UIBox2i((0, 0), vp.Size), vp.Eye!.Position.MapId, worldBox, worldBounds);
if (!overlay.BeforeDraw(args))
return;
@@ -166,7 +165,7 @@ namespace Robust.Client.Graphics.Clyde
private void RenderOverlaysDirect(
Viewport vp,
IViewportControl vpControl,
IRenderHandle handle,
DrawingHandleBase handle,
OverlaySpace space,
in UIBox2i bounds)
{
@@ -176,9 +175,8 @@ namespace Robust.Client.Graphics.Clyde
var worldBounds = CalcWorldBounds(vp);
var worldAABB = worldBounds.CalcBoundingBox();
var mapId = vp.Eye!.Position.MapId;
var args = new OverlayDrawArgs(space, vpControl, vp, handle, bounds, _mapManager.GetMapEntityIdOrThrow(mapId), mapId, worldAABB, worldBounds);
var args = new OverlayDrawArgs(space, vpControl, vp, handle, bounds, vp.Eye!.Position.MapId, worldAABB, worldBounds);
foreach (var overlay in list)
{
@@ -423,19 +421,12 @@ namespace Robust.Client.Graphics.Clyde
var oldTransform = _currentMatrixModel;
var oldScissor = _currentScissorState;
var oldMatrixProj = _currentMatrixProj;
var oldMatrixView = _currentMatrixView;
var oldBoundTarget = _currentBoundRenderTarget;
var oldRenderTarget = _currentRenderTarget;
var oldShader = _queuedShaderInstance;
var oldCaps = _glCaps;
// Need to get state before flushing render queue in case they modify the original state.
var state = PushRenderStateFull();
// Have to flush the render queue so that all commands finish rendering to the previous framebuffer.
FlushRenderQueue();
var state = PushRenderStateFull();
{
BindRenderTargetFull(RtToLoaded(rt));
if (clearColor is not null)
@@ -457,16 +448,8 @@ namespace Robust.Client.Graphics.Clyde
PopRenderStateFull(state);
_updateUniformConstants(_currentRenderTarget.Size);
SetScissorFull(oldScissor);
_currentMatrixModel = oldTransform;
DebugTools.Assert(oldCaps.Equals(_glCaps));
DebugTools.Assert(_currentMatrixModel.Equals(oldTransform));
DebugTools.Assert(_currentScissorState.Equals(oldScissor));
DebugTools.Assert(_currentMatrixProj.Equals(oldMatrixProj));
DebugTools.Assert(oldMatrixView.Equals(_currentMatrixView));
DebugTools.Assert(oldRenderTarget.Equals(_currentRenderTarget));
DebugTools.Assert(oldBoundTarget.Equals(_currentBoundRenderTarget));
DebugTools.Assert(oldShader.Equals(_queuedShaderInstance));
}
private void RenderViewport(Viewport viewport)

View File

@@ -1,19 +1,21 @@
using System;
using System.Collections.Generic;
using System.Buffers;
using System.Diagnostics.Contracts;
using System.Numerics;
using OpenToolkit.Graphics.OpenGL4;
using Robust.Client.GameObjects;
using Robust.Client.ResourceManagement;
using Robust.Shared;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Maths;
using OGLTextureWrapMode = OpenToolkit.Graphics.OpenGL.TextureWrapMode;
using TKStencilOp = OpenToolkit.Graphics.OpenGL4.StencilOp;
using Robust.Shared.Physics;
using Robust.Shared.Enums;
using Robust.Client.ComponentTrees;
using Robust.Shared.Graphics;
using static Robust.Shared.GameObjects.OccluderComponent;
using Robust.Shared.Utility;
@@ -277,7 +279,8 @@ namespace Robust.Client.Graphics.Clyde
{
const float arbitraryDistanceMax = 1234;
IsBlending = false;
GL.Disable(EnableCap.Blend);
CheckGlError();
GL.Enable(EnableCap.DepthTest);
CheckGlError();
@@ -326,7 +329,8 @@ namespace Robust.Client.Graphics.Clyde
GL.Disable(EnableCap.DepthTest);
CheckGlError();
IsBlending = true;
GL.Enable(EnableCap.Blend);
CheckGlError();
}
private void DrawLightsAndFov(Viewport viewport, Box2Rotated worldBounds, Box2 worldAABB, IEye eye)
@@ -390,43 +394,21 @@ namespace Robust.Client.Graphics.Clyde
FinalizeDepthDraw();
}
IsStencilling = true;
GL.Enable(EnableCap.StencilTest);
_isStencilling = true;
var (lightW, lightH) = GetLightMapSize(viewport.Size);
GL.Viewport(0, 0, lightW, lightH);
CheckGlError();
BindRenderTargetImmediate(RtToLoaded(viewport.LightRenderTarget));
DebugTools.Assert(_currentBoundRenderTarget.TextureHandle.Equals(viewport.LightRenderTarget.Texture.TextureId));
CheckGlError();
var clearEv = new GetClearColorEvent();
_entityManager.EventBus.RaiseEvent(EventSource.Local, ref clearEv);
var clearColor = clearEv.Color ?? GetClearColor(mapUid);
GLClearColor(clearColor);
GLClearColor(_entityManager.GetComponentOrNull<MapLightComponent>(mapUid)?.AmbientLightColor ?? MapLightComponent.DefaultColor);
GL.ClearStencil(0xFF);
GL.StencilMask(0xFF);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.StencilBufferBit);
CheckGlError();
var oldTarget = _currentRenderTarget;
var oldProj = _currentMatrixProj;
var oldShader = _queuedShaderInstance;
var oldModel = _currentMatrixModel;
var oldScissor = _currentScissorState;
var state = PushRenderStateFull();
RenderOverlays(viewport, OverlaySpace.BeforeLighting, worldAABB, worldBounds);
PopRenderStateFull(state);
DebugTools.Assert(oldScissor.Equals(_currentScissorState));
DebugTools.Assert(oldModel.Equals(_currentMatrixModel));
DebugTools.Assert(oldShader.Equals(_queuedShaderInstance));
DebugTools.Assert(oldProj.Equals(_currentMatrixProj));
DebugTools.Assert(oldTarget.Equals(_currentRenderTarget));
DebugTools.Assert(_currentBoundRenderTarget.TextureHandle.Equals(viewport.LightRenderTarget.Texture.TextureId));
ApplyLightingFovToBuffer(viewport, eye);
var lightShader = _loadedShaders[_enableSoftShadows ? _lightSoftShaderHandle : _lightHardShaderHandle]
@@ -527,12 +509,13 @@ namespace Robust.Client.Graphics.Clyde
}
ResetBlendFunc();
IsStencilling = false;
GL.Disable(EnableCap.StencilTest);
_isStencilling = false;
CheckGlError();
if (_cfg.GetCVar(CVars.LightBlur))
BlurRenderTarget(viewport, viewport.LightRenderTarget, viewport.LightBlurTarget, eye, 14f);
BlurLights(viewport, eye);
using (_prof.Group("BlurOntoWalls"))
{
@@ -548,8 +531,9 @@ namespace Robust.Client.Graphics.Clyde
GL.Viewport(0, 0, viewport.Size.X, viewport.Size.Y);
CheckGlError();
_lightingReady = true;
Array.Clear(_lightsToRenderList, 0, count);
_lightingReady = true;
}
private static bool LightQuery(ref (
@@ -659,33 +643,21 @@ namespace Robust.Client.Graphics.Clyde
return (state.count, expandedBounds);
}
/// <inheritdoc/>
[Pure]
public Color GetClearColor(EntityUid mapUid)
private void BlurLights(Viewport viewport, IEye eye)
{
return _entityManager.GetComponentOrNull<MapLightComponent>(mapUid)?.AmbientLightColor ??
MapLightComponent.DefaultColor;
}
using var _ = DebugGroup(nameof(BlurLights));
/// <inheritdoc/>
public void BlurRenderTarget(IClydeViewport viewport, IRenderTarget target, IRenderTarget blurBuffer, IEye eye, float multiplier)
{
if (target is not RenderTexture rTexture || blurBuffer is not RenderTexture blurTexture)
return;
using var _ = DebugGroup(nameof(BlurRenderTarget));
var state = PushRenderStateFull();
IsBlending = false;
GL.Disable(EnableCap.Blend);
CheckGlError();
CalcScreenMatrices(viewport.Size, out var proj, out var view);
SetProjViewBuffer(proj, view);
var shader = _loadedShaders[_lightBlurShaderHandle].Program;
shader.Use();
SetupGlobalUniformsImmediate(shader, rTexture.Texture);
SetupGlobalUniformsImmediate(shader, viewport.LightRenderTarget.Texture);
var size = target.Size;
var size = viewport.LightRenderTarget.Size;
shader.SetUniformMaybe("size", (Vector2)size);
shader.SetUniformTextureMaybe(UniIMainTexture, TextureUnit.Texture0);
@@ -695,13 +667,14 @@ namespace Robust.Client.Graphics.Clyde
// Initially we're pulling from the light render target.
// So we set it out of the loop so
// _wallBleedIntermediateRenderTarget2 gets bound at the end of the loop body.
SetTexture(TextureUnit.Texture0, rTexture.Texture);
SetTexture(TextureUnit.Texture0, viewport.LightRenderTarget.Texture);
// Have to scale the blurring radius based on viewport size and camera zoom.
const float refCameraHeight = 14;
var facBase = _cfg.GetCVar(CVars.LightBlurFactor);
var cameraSize = eye.Zoom.Y * viewport.Size.Y * (1 / viewport.RenderScale.Y) / EyeManager.PixelsPerMeter;
// 7e-3f is just a magic factor that makes it look ok.
var factor = facBase * (multiplier / cameraSize);
var factor = facBase * (refCameraHeight / cameraSize);
// Multi-iteration gaussian blur.
for (var i = 3; i > 0; i--)
@@ -710,31 +683,35 @@ namespace Robust.Client.Graphics.Clyde
// Set factor.
shader.SetUniformMaybe("radius", scale);
BindRenderTargetImmediate(RtToLoaded(blurBuffer));
BindRenderTargetFull(viewport.LightBlurTarget);
// Blur horizontally to _wallBleedIntermediateRenderTarget1.
shader.SetUniformMaybe("direction", Vector2.UnitX);
_drawQuad(Vector2.Zero, viewport.Size, Matrix3x2.Identity, shader);
SetTexture(TextureUnit.Texture0, blurTexture.Texture);
SetTexture(TextureUnit.Texture0, viewport.LightBlurTarget.Texture);
BindRenderTargetImmediate(RtToLoaded(rTexture));
BindRenderTargetFull(viewport.LightRenderTarget);
// Blur vertically to _wallBleedIntermediateRenderTarget2.
shader.SetUniformMaybe("direction", Vector2.UnitY);
_drawQuad(Vector2.Zero, viewport.Size, Matrix3x2.Identity, shader);
SetTexture(TextureUnit.Texture0, rTexture.Texture);
SetTexture(TextureUnit.Texture0, viewport.LightRenderTarget.Texture);
}
PopRenderStateFull(state);
GL.Enable(EnableCap.Blend);
CheckGlError();
// We didn't trample over the old _currentMatrices so just roll it back.
SetProjViewBuffer(_currentMatrixProj, _currentMatrixView);
}
private void BlurOntoWalls(Viewport viewport, IEye eye)
{
using var _ = DebugGroup(nameof(BlurOntoWalls));
IsBlending = false;
GL.Disable(EnableCap.Blend);
CheckGlError();
CalcScreenMatrices(viewport.Size, out var proj, out var view);
SetProjViewBuffer(proj, view);
@@ -784,7 +761,8 @@ namespace Robust.Client.Graphics.Clyde
SetTexture(TextureUnit.Texture0, viewport.WallBleedIntermediateRenderTarget2.Texture);
}
IsBlending = true;
GL.Enable(EnableCap.Blend);
CheckGlError();
// We didn't trample over the old _currentMatrices so just roll it back.
SetProjViewBuffer(_currentMatrixProj, _currentMatrixView);
}
@@ -797,7 +775,8 @@ namespace Robust.Client.Graphics.Clyde
GL.Viewport(0, 0, viewport.LightRenderTarget.Size.X, viewport.LightRenderTarget.Size.Y);
CheckGlError();
IsBlending = false;
GL.Disable(EnableCap.Blend);
CheckGlError();
var shader = _loadedShaders[_mergeWallLayerShaderHandle].Program;
shader.Use();
@@ -817,7 +796,8 @@ namespace Robust.Client.Graphics.Clyde
IntPtr.Zero);
CheckGlError();
IsBlending = true;
GL.Enable(EnableCap.Blend);
CheckGlError();
}
private void ApplyFovToBuffer(Viewport viewport, IEye eye)
@@ -847,7 +827,8 @@ namespace Robust.Client.Graphics.Clyde
FovSetTransformAndBlit(viewport, eye.Position.Position, fovShader);
GL.StencilMask(0x00);
IsStencilling = false;
GL.Disable(EnableCap.StencilTest);
_isStencilling = false;
}
private void ApplyLightingFovToBuffer(Viewport viewport, IEye eye)
@@ -1154,20 +1135,22 @@ namespace Robust.Client.Graphics.Clyde
var lightMapSize = GetLightMapSize(viewport.Size);
var lightMapSizeQuart = GetLightMapSize(viewport.Size, true);
viewport.LightRenderTarget?.Dispose();
viewport.WallMaskRenderTarget?.Dispose();
viewport.WallBleedIntermediateRenderTarget1?.Dispose();
viewport.WallBleedIntermediateRenderTarget2?.Dispose();
var lightMapColorFormat = _hasGLFloatFramebuffers
? RenderTargetColorFormat.R11FG11FB10F
: RenderTargetColorFormat.Rgba8;
var lightMapSampleParameters = new TextureSampleParameters { Filter = true };
viewport.LightRenderTarget?.Dispose();
viewport.WallMaskRenderTarget?.Dispose();
viewport.WallBleedIntermediateRenderTarget1?.Dispose();
viewport.WallBleedIntermediateRenderTarget2?.Dispose();
viewport.WallMaskRenderTarget = CreateRenderTarget(viewport.Size, RenderTargetColorFormat.R8,
name: $"{viewport.Name}-{nameof(viewport.WallMaskRenderTarget)}");
viewport.LightRenderTarget = (RenderTexture) CreateLightRenderTarget(lightMapSize,
viewport.LightRenderTarget = CreateRenderTarget(lightMapSize,
new RenderTargetFormatParameters(lightMapColorFormat, hasDepthStencil: true),
lightMapSampleParameters,
$"{viewport.Name}-{nameof(viewport.LightRenderTarget)}");
viewport.LightBlurTarget = CreateRenderTarget(lightMapSize,
@@ -1175,13 +1158,11 @@ namespace Robust.Client.Graphics.Clyde
lightMapSampleParameters,
$"{viewport.Name}-{nameof(viewport.LightBlurTarget)}");
viewport.WallBleedIntermediateRenderTarget1 = CreateRenderTarget(lightMapSizeQuart,
new RenderTargetFormatParameters(lightMapColorFormat),
viewport.WallBleedIntermediateRenderTarget1 = CreateRenderTarget(lightMapSizeQuart, lightMapColorFormat,
lightMapSampleParameters,
$"{viewport.Name}-{nameof(viewport.WallBleedIntermediateRenderTarget1)}");
viewport.WallBleedIntermediateRenderTarget2 = CreateRenderTarget(lightMapSizeQuart,
new RenderTargetFormatParameters(lightMapColorFormat),
viewport.WallBleedIntermediateRenderTarget2 = CreateRenderTarget(lightMapSizeQuart, lightMapColorFormat,
lightMapSampleParameters,
$"{viewport.Name}-{nameof(viewport.WallBleedIntermediateRenderTarget2)}");
}

View File

@@ -30,20 +30,6 @@ namespace Robust.Client.Graphics.Clyde
// It, like _mainWindowRenderTarget, is initialized in Clyde's constructor
private LoadedRenderTarget _currentBoundRenderTarget;
public IRenderTexture CreateLightRenderTarget(Vector2i size, string? name = null, bool depthStencil = true)
{
var lightMapColorFormat = _hasGLFloatFramebuffers
? RTCF.R11FG11FB10F
: RTCF.Rgba8;
var lightMapSampleParameters = new TextureSampleParameters { Filter = true };
return CreateRenderTarget(size,
new RenderTargetFormatParameters(lightMapColorFormat, hasDepthStencil: depthStencil),
lightMapSampleParameters,
name: name);
}
IRenderTexture IClyde.CreateRenderTarget(Vector2i size, RenderTargetFormatParameters format,
TextureSampleParameters? sampleParameters, string? name)
{
@@ -218,8 +204,7 @@ namespace Robust.Client.Graphics.Clyde
Size = size,
TextureHandle = textureObject.TextureId,
MemoryPressure = pressure,
ColorFormat = format.ColorFormat,
SampleParameters = sampleParameters,
ColorFormat = format.ColorFormat
};
//GC.AddMemoryPressure(pressure);
@@ -266,15 +251,9 @@ namespace Robust.Client.Graphics.Clyde
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private LoadedRenderTarget RtToLoaded(IRenderTarget rt)
private LoadedRenderTarget RtToLoaded(RenderTargetBase rt)
{
switch (rt)
{
case RenderTargetBase based:
return _renderTargets[based.Handle];
default:
throw new NotImplementedException();
}
return _renderTargets[rt.Handle];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -323,8 +302,6 @@ namespace Robust.Client.Graphics.Clyde
// Renderbuffer handle
public GLHandle DepthStencilHandle;
public long MemoryPressure;
public TextureSampleParameters? SampleParameters;
}
private abstract class RenderTargetBase : IRenderTarget

View File

@@ -90,61 +90,9 @@ namespace Robust.Client.Graphics.Clyde
// (queue) and (misc), current state of the scissor test. Null if disabled.
private UIBox2i? _currentScissorState;
/// <summary>
/// Tracks enabled GL capabilities for renderer state.
/// </summary>
private GLCaps _glCaps = GLCaps.None;
private bool IsStencilling
{
get => (_glCaps & GLCaps.Stencilling) == GLCaps.Stencilling;
set
{
if (value == IsStencilling)
return;
if (value)
{
_glCaps |= GLCaps.Stencilling;
GL.Enable(EnableCap.StencilTest);
}
else
{
_glCaps &= ~GLCaps.Stencilling;
GL.Disable(EnableCap.StencilTest);
}
CheckGlError();
}
}
private bool IsBlending
{
get => (_glCaps & GLCaps.Blending) == GLCaps.Blending;
set
{
if (value == IsBlending)
return;
if (value)
{
_glCaps |= GLCaps.Blending;
GL.Enable(EnableCap.Blend);
}
else
{
_glCaps &= ~GLCaps.Blending;
GL.Disable(EnableCap.Blend);
}
CheckGlError();
}
}
private bool IsScissoring
{
get => _currentScissorState != null;
}
// Some simple flags that basically just tracks the current state of glEnable(GL_STENCIL/GL_SCISSOR_TEST)
private bool _isScissoring;
private bool _isStencilling;
private readonly RefList<RenderCommand> _queuedRenderCommands = new RefList<RenderCommand>();
@@ -416,17 +364,16 @@ namespace Robust.Client.Graphics.Clyde
private void SetScissorImmediate(bool enable, in UIBox2i box)
{
if (enable)
var oldIsScissoring = _isScissoring;
_isScissoring = enable;
if (_isScissoring)
{
GL.Enable(EnableCap.ScissorTest);
}
else
{
GL.Disable(EnableCap.ScissorTest);
}
if (!oldIsScissoring)
{
GL.Enable(EnableCap.ScissorTest);
CheckGlError();
}
if (enable)
{
// Don't forget to flip it, these coordinates have bottom left as origin.
// TODO: Broken when rendering to non-screen render targets.
@@ -440,6 +387,11 @@ namespace Robust.Client.Graphics.Clyde
}
CheckGlError();
}
else if (oldIsScissoring)
{
GL.Disable(EnableCap.ScissorTest);
CheckGlError();
}
}
// NOTE: sRGB IS IN LINEAR IF FRAMEBUFFER_SRGB IS ACTIVE.
@@ -468,11 +420,17 @@ namespace Robust.Client.Graphics.Clyde
var program = shader.Program;
program.Use();
IsStencilling = instance.Stencil.Enabled;
// Handle stencil parameters.
if (instance.Stencil.Enabled)
{
if (!_isStencilling)
{
GL.Enable(EnableCap.StencilTest);
CheckGlError();
_isStencilling = true;
}
GL.StencilMask(instance.Stencil.WriteMask);
CheckGlError();
GL.StencilFunc(ToGLStencilFunc(instance.Stencil.Func), instance.Stencil.Ref, instance.Stencil.ReadMask);
@@ -480,6 +438,12 @@ namespace Robust.Client.Graphics.Clyde
GL.StencilOp(TKStencilOp.Keep, TKStencilOp.Keep, ToGLStencilOp(instance.Stencil.Op));
CheckGlError();
}
else if (_isStencilling)
{
GL.Disable(EnableCap.StencilTest);
CheckGlError();
_isStencilling = false;
}
if (instance.Parameters.Count == 0)
return (program, instance);
@@ -523,9 +487,6 @@ namespace Robust.Client.Graphics.Clyde
case Color color:
program.SetUniform(name, color);
break;
case Color[] colorArr:
program.SetUniform(name, colorArr);
break;
case int i:
program.SetUniform(name, i);
break;
@@ -898,34 +859,17 @@ namespace Robust.Client.Graphics.Clyde
private FullStoredRendererState PushRenderStateFull()
{
return new FullStoredRendererState(
_currentMatrixProj,
_currentMatrixView,
_currentBoundRenderTarget,
_currentRenderTarget,
_queuedShaderInstance,
_currentScissorState,
_glCaps);
return new FullStoredRendererState(_currentMatrixProj, _currentMatrixView, _currentRenderTarget);
}
private void PopRenderStateFull(in FullStoredRendererState state)
{
SetProjViewFull(state.ProjMatrix, state.ViewMatrix);
BindRenderTargetImmediate(state.BoundRenderTarget);
BindRenderTargetFull(state.RenderTarget);
_queuedShaderInstance = state.QueuedShaderInstance;
_currentRenderTarget = state.RenderTarget;
var (width, height) = state.BoundRenderTarget.Size;
var (width, height) = state.RenderTarget.Size;
GL.Viewport(0, 0, width, height);
IsStencilling = (state.GLCaps & GLCaps.Stencilling) == GLCaps.Stencilling;
IsBlending = (state.GLCaps & GLCaps.Blending) == GLCaps.Blending;
SetScissorFull(state.ScissorState);
GL.ClearStencil(0xFF);
GL.StencilMask(0xFF);
GL.Clear(ClearBufferMask.StencilBufferBit);
CheckGlError();
}
private void SetViewportImmediate(Box2i box)
@@ -1117,44 +1061,15 @@ namespace Robust.Client.Graphics.Clyde
{
public readonly Matrix3x2 ProjMatrix;
public readonly Matrix3x2 ViewMatrix;
public readonly LoadedRenderTarget BoundRenderTarget;
public readonly LoadedRenderTarget RenderTarget;
public readonly ClydeShaderInstance QueuedShaderInstance;
public readonly UIBox2i? ScissorState;
public readonly GLCaps GLCaps;
public FullStoredRendererState(
in Matrix3x2 projMatrix,
in Matrix3x2 viewMatrix,
LoadedRenderTarget boundRenderTarget,
LoadedRenderTarget renderTarget,
ClydeShaderInstance queuedShaderInstance,
UIBox2i? scissorState,
GLCaps glcaps
)
public FullStoredRendererState(in Matrix3x2 projMatrix, in Matrix3x2 viewMatrix,
LoadedRenderTarget renderTarget)
{
ProjMatrix = projMatrix;
ViewMatrix = viewMatrix;
BoundRenderTarget = boundRenderTarget;
RenderTarget = renderTarget;
QueuedShaderInstance = queuedShaderInstance;
ScissorState = scissorState;
GLCaps = glcaps;
}
}
[Flags]
private enum GLCaps : ushort
{
// If you add flags here make sure to update PopRenderState!
None = 0,
Blending = 1 << 0,
Stencilling = 1 << 2,
}
}
}

View File

@@ -485,13 +485,6 @@ namespace Robust.Client.Graphics.Clyde
data.Parameters[name] = value;
}
private protected override void SetParameterImpl(string name, Color[] value)
{
var data = Parent._shaderInstances[Handle];
data.ParametersDirty = true;
data.Parameters[name] = value;
}
private protected override void SetParameterImpl(string name, int value)
{
var data = Parent._shaderInstances[Handle];

View File

@@ -171,7 +171,7 @@ namespace Robust.Client.Graphics.Clyde
}
public void RenderScreenOverlaysBelow(
IRenderHandle handle,
DrawingHandleScreen handle,
IViewportControl control,
in UIBox2i viewportBounds)
{
@@ -179,7 +179,7 @@ namespace Robust.Client.Graphics.Clyde
}
public void RenderScreenOverlaysAbove(
IRenderHandle handle,
DrawingHandleScreen handle,
IViewportControl control,
in UIBox2i viewportBounds)
{

View File

@@ -21,7 +21,6 @@ using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Profiling;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using TextureWrapMode = Robust.Shared.Graphics.TextureWrapMode;
@@ -246,7 +245,7 @@ namespace Robust.Client.Graphics.Clyde
overrideVersion != null,
_windowing!.GetDescription());
IsBlending = true;
GL.Enable(EnableCap.Blend);
if (_hasGLSrgb && !_isGLES)
{
GL.Enable(EnableCap.FramebufferSrgb);

View File

@@ -9,7 +9,6 @@ using Robust.Client.Input;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.GameObjects;
using Robust.Shared.Graphics;
using Robust.Shared.Map;
using Robust.Shared.Maths;
@@ -190,22 +189,6 @@ namespace Robust.Client.Graphics.Clyde
return new DummyTexture(size);
}
/// <inheritdoc />
public Color GetClearColor(EntityUid mapUid)
{
return Color.Transparent;
}
public void BlurRenderTarget(IClydeViewport viewport, IRenderTarget target, IRenderTarget blurBuffer, IEye eye, float multiplier)
{
// NOOP
}
public IRenderTexture CreateLightRenderTarget(Vector2i size, string? name = null, bool depthStencil = true)
{
return CreateRenderTarget(size, new RenderTargetFormatParameters(RenderTargetColorFormat.R8, hasDepthStencil: depthStencil), null, name: name);
}
public IRenderTexture CreateRenderTarget(Vector2i size, RenderTargetFormatParameters format,
TextureSampleParameters? sampleParameters = null, string? name = null)
{
@@ -369,10 +352,6 @@ namespace Robust.Client.Graphics.Clyde
{
}
private protected override void SetParameterImpl(string name, Color[] value)
{
}
private protected override void SetParameterImpl(string name, int value)
{
}
@@ -518,7 +497,7 @@ namespace Robust.Client.Graphics.Clyde
}
public void RenderScreenOverlaysBelow(
IRenderHandle handle,
DrawingHandleScreen handle,
IViewportControl control,
in UIBox2i viewportBounds)
{
@@ -526,7 +505,7 @@ namespace Robust.Client.Graphics.Clyde
}
public void RenderScreenOverlaysAbove(
IRenderHandle handle,
DrawingHandleScreen handle,
IViewportControl control,
in UIBox2i viewportBounds)
{

View File

@@ -334,7 +334,7 @@ namespace Robust.Client.Graphics.Clyde
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetUniformDirect(int slot, in Color color, bool convertToLinear = true)
private void SetUniformDirect(int slot, in Color color, bool convertToLinear=true)
{
var converted = color;
if (convertToLinear)
@@ -349,39 +349,6 @@ namespace Robust.Client.Graphics.Clyde
}
}
public void SetUniform(string uniformName, Color[] colors)
{
var uniformId = GetUniform(uniformName);
SetUniformDirect(uniformId, colors);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetUniformDirect(int slot, Color[] colors, bool convertToLinear = true)
{
scoped Span<Color> colorsToPass;
if (convertToLinear)
{
colorsToPass = stackalloc Color[colors.Length];
for (int i = 0; i < colors.Length; i++)
{
colorsToPass[i] = Color.FromSrgb(colors[i]);
}
}
else
{
colorsToPass = colors;
}
unsafe
{
fixed (Color* ptr = &colorsToPass[0])
{
GL.Uniform4(slot, colorsToPass.Length, (float*)ptr);
_clyde.CheckGlError();
}
}
}
public void SetUniform(string uniformName, in Vector3 vector)
{
var uniformId = GetUniform(uniformName);

View File

@@ -1,15 +1,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.IO;
using System.Numerics;
using System.Threading.Tasks;
using Robust.Shared.GameObjects;
using Robust.Shared.Graphics;
using Robust.Shared.Maths;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using Color = Robust.Shared.Maths.Color;
namespace Robust.Client.Graphics
{
@@ -74,24 +71,6 @@ namespace Robust.Client.Graphics
in TextureLoadParameters? loadParams = null)
where T : unmanaged, IPixel<T>;
/// <summary>
/// Gets the clear color for the specified map viewport.
/// </summary>
[Pure]
Color GetClearColor(EntityUid mapUid);
/// <summary>
/// Applies a blur to the specified render target. Requires a separate buffer with similar properties to draw intermediate steps into.
/// </summary>
/// <param name="viewport">The viewport being used for drawing.</param>
/// <param name="target">The blur target.</param>
/// <param name="blurBuffer">The separate buffer to draw into.</param>
/// <param name="eye">The eye being drawn with.</param>
/// <param name="multiplier">Scale of how much blur to blur by.</param>
void BlurRenderTarget(IClydeViewport viewport, IRenderTarget target, IRenderTarget blurBuffer, IEye eye, float multiplier);
IRenderTexture CreateLightRenderTarget(Vector2i size, string? name = null, bool depthStencil = true);
IRenderTexture CreateRenderTarget(Vector2i size, RenderTargetFormatParameters format,
TextureSampleParameters? sampleParameters = null, string? name = null);

View File

@@ -18,7 +18,6 @@ namespace Robust.Client.Graphics
/// </summary>
IRenderTexture RenderTarget { get; }
IRenderTexture LightRenderTarget { get; }
IEye? Eye { get; set; }
Vector2i Size { get; }
@@ -67,7 +66,7 @@ namespace Robust.Client.Graphics
/// Not relative to the current transform of <see cref="handle"/>.
/// </param>
public void RenderScreenOverlaysBelow(
IRenderHandle handle,
DrawingHandleScreen handle,
IViewportControl control,
in UIBox2i viewportBounds);
@@ -81,7 +80,7 @@ namespace Robust.Client.Graphics
/// Not relative to the current transform of <see cref="handle"/>.
/// </param>
public void RenderScreenOverlaysAbove(
IRenderHandle handle,
DrawingHandleScreen handle,
IViewportControl control,
in UIBox2i viewportBounds);
}

View File

@@ -1,6 +1,4 @@
using System;
using System.Numerics;
using Robust.Shared.Graphics;
using Robust.Shared.Maths;
using SixLabors.ImageSharp.PixelFormats;
@@ -17,42 +15,5 @@ namespace Robust.Client.Graphics
Vector2i Size { get; }
void CopyPixelsToMemory<T>(CopyPixelsDelegate<T> callback, UIBox2i? subRegion = null) where T : unmanaged, IPixel<T>;
public Vector2 LocalToWorld(IEye eye, Vector2 point, Vector2 scale)
{
var newPoint = point;
// (inlined version of UiProjMatrix^-1)
newPoint -= Size / 2f;
newPoint *= new Vector2(1, -1) / EyeManager.PixelsPerMeter;
// view matrix
eye.GetViewMatrixInv(out var viewMatrixInv, scale);
newPoint = Vector2.Transform(newPoint, viewMatrixInv);
return newPoint;
}
public Vector2 WorldToLocal(Vector2 point, IEye eye, Vector2 scale)
{
var newPoint = point;
eye.GetViewMatrix(out var viewMatrix, scale);
newPoint = Vector2.Transform(newPoint, viewMatrix);
// (inlined version of UiProjMatrix)
newPoint *= new Vector2(1, -1) * EyeManager.PixelsPerMeter;
newPoint += Size / 2f;
return newPoint;
}
public Matrix3x2 GetWorldToLocalMatrix(IEye eye, Vector2 scale)
{
eye.GetViewMatrix(out var viewMatrix, scale * new Vector2(EyeManager.PixelsPerMeter, -EyeManager.PixelsPerMeter));
viewMatrix.M31 += Size.X / 2f;
viewMatrix.M32 += Size.Y / 2f;
return viewMatrix;
}
}
}

View File

@@ -1,13 +0,0 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
namespace Robust.Client.Graphics;
/// <summary>
/// Raised by the engine if content wishes to override the default clear color.
/// </summary>
[ByRefEvent]
public record struct GetClearColorEvent
{
public Color? Color;
}

View File

@@ -9,5 +9,6 @@ namespace Robust.Client.Graphics
public bool DrawHardFov { get; set; } = true;
public bool DrawLighting { get; set; } = true;
public bool LockConsoleAccess { get; set; } = false;
public Color AmbientLightColor { get; set; } = Color.FromSrgb(Color.Black);
}
}

View File

@@ -1,7 +1,6 @@
using JetBrains.Annotations;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
@@ -40,8 +39,6 @@ namespace Robust.Client.Graphics
/// </summary>
public readonly UIBox2i ViewportBounds;
public readonly EntityUid MapUid;
/// <summary>
/// <see cref="MapId"/> of the viewport's eye.
/// </summary>
@@ -57,32 +54,24 @@ namespace Robust.Client.Graphics
/// </summary>
public readonly Box2Rotated WorldBounds;
public readonly IRenderHandle RenderHandle;
public DrawingHandleScreen ScreenHandle => (DrawingHandleScreen) DrawingHandle;
public DrawingHandleWorld WorldHandle => (DrawingHandleWorld) DrawingHandle;
internal OverlayDrawArgs(
public OverlayDrawArgs(
OverlaySpace space,
IViewportControl? viewportControl,
IClydeViewport viewport,
IRenderHandle renderHandle,
DrawingHandleBase drawingHandle,
in UIBox2i viewportBounds,
in EntityUid mapUid,
in MapId mapId,
in Box2 worldAabb,
in Box2Rotated worldBounds)
{
DrawingHandle = space is OverlaySpace.ScreenSpace or OverlaySpace.ScreenSpaceBelowWorld
? renderHandle.DrawingHandleScreen
: renderHandle.DrawingHandleWorld;
Space = space;
ViewportControl = viewportControl;
Viewport = viewport;
RenderHandle = renderHandle;
DrawingHandle = drawingHandle;
ViewportBounds = viewportBounds;
MapUid = mapUid;
MapId = mapId;
WorldAABB = worldAabb;
WorldBounds = worldBounds;

View File

@@ -221,12 +221,11 @@ namespace Robust.Client.Graphics
public static bool TypeSupportsArrays(this ShaderDataType type)
{
// TODO: add support for int, and vec3 arrays
// TODO: add support for int, and vec3/4 arrays
return
(type == ShaderDataType.Float) ||
(type == ShaderDataType.Vec2) ||
(type == ShaderDataType.Bool) ||
(type == ShaderDataType.Vec4);
(type == ShaderDataType.Bool);
}
[SuppressMessage("ReSharper", "StringLiteralTypo")]

View File

@@ -113,13 +113,6 @@ namespace Robust.Client.Graphics
SetParameterImpl(name, value);
}
public void SetParameter(string name, Color[] value)
{
EnsureAlive();
EnsureMutable();
SetParameterImpl(name, value);
}
public void SetParameter(string name, Vector4 value)
{
EnsureAlive();
@@ -230,7 +223,6 @@ namespace Robust.Client.Graphics
private protected abstract void SetParameterImpl(string name, Vector3 value);
private protected abstract void SetParameterImpl(string name, Vector4 value);
private protected abstract void SetParameterImpl(string name, Color value);
private protected abstract void SetParameterImpl(string name, Color[] value);
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);

View File

@@ -93,7 +93,7 @@ public sealed partial class PhysicsSystem
var maps = new HashSet<EntityUid>();
var enumerator = AllEntityQuery<PredictedPhysicsComponent, PhysicsComponent, TransformComponent>();
while (enumerator.MoveNext(out _, out var physics, out var xform))
while (enumerator.MoveNext(out var _, out var physics, out var xform))
{
DebugTools.Assert(physics.Predict);

View File

@@ -144,7 +144,7 @@ namespace Robust.Client.Placement
if (mousePos.MapId == MapId.Nullspace)
yield break;
var (_, (x, y)) = transformSys.ToCoordinates(pManager.StartPoint.EntityId, mousePos) - pManager.StartPoint;
var (_, (x, y)) = EntityCoordinates.FromMap(pManager.StartPoint.EntityId, mousePos, transformSys, pManager.EntityManager) - pManager.StartPoint;
float iterations;
Vector2 distance;
if (Math.Abs(x) > Math.Abs(y))
@@ -176,7 +176,7 @@ namespace Robust.Client.Placement
if (mousePos.MapId == MapId.Nullspace)
yield break;
var placementdiff = transformSys.ToCoordinates(pManager.StartPoint.EntityId, mousePos) - pManager.StartPoint;
var placementdiff = EntityCoordinates.FromMap(pManager.StartPoint.EntityId, mousePos, transformSys, pManager.EntityManager) - pManager.StartPoint;
var xSign = Math.Sign(placementdiff.X);
var ySign = Math.Sign(placementdiff.Y);
@@ -264,15 +264,13 @@ namespace Robust.Client.Placement
protected EntityCoordinates ScreenToCursorGrid(ScreenCoordinates coords)
{
var mapCoords = pManager.EyeManager.PixelToMap(coords.Position);
var transformSys = pManager.EntityManager.System<SharedTransformSystem>();
if (!pManager.MapManager.TryFindGridAt(mapCoords, out var gridUid, out var grid))
{
return transformSys.ToCoordinates(mapCoords);
return EntityCoordinates.FromMap(pManager.MapManager, mapCoords);
}
return transformSys.ToCoordinates(gridUid, mapCoords);
var transformSys = pManager.EntityManager.System<SharedTransformSystem>();
return EntityCoordinates.FromMap(gridUid, mapCoords, transformSys, pManager.EntityManager);
}
}
}

View File

@@ -352,9 +352,6 @@ public sealed partial class ReplayLoadManager
// prototype changes when jumping around in time. This also requires reworking how the initial
// implicit state data is generated, because we can't simply cache it anymore.
// Also, does reloading prototypes in release mode modify existing entities?
// Yes, yes it does. See PrototypeReloadSystem.UpdateEntity()
// Its just not supported ATM.
// TBH it'd be easier if overriding existing prototypes in release mode was just forbidden.
var msg = $"Overwriting an existing prototype! Kind: {kind.Name}. Ids: {string.Join(", ", ids)}";
if (_confMan.GetCVar(CVars.ReplayIgnoreErrors))
@@ -364,6 +361,7 @@ public sealed partial class ReplayLoadManager
}
}
_protoMan.ResolveResults();
_protoMan.ReloadPrototypes(changed);
_locMan.ReloadLocalizations();
}

View File

@@ -44,8 +44,8 @@ internal sealed partial class ReplayPlaybackManager
_gameState.UpdateFullRep(state, cloneDelta: true);
var next = Replay.NextState;
BeforeApplyState?.Invoke((state, next));
_gameState.ApplyGameState(state, next);
_gameState.MergeImplicitData();
var created = _gameState.ApplyGameState(state, next);
_gameState.GenerateImplicitStates(created);
DebugTools.Assert(Replay.LastApplied >= state.FromSequence);
DebugTools.Assert(Replay.LastApplied + 1 <= state.ToSequence);
Replay.LastApplied = state.ToSequence;

View File

@@ -1,5 +1,4 @@
using System;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.GameObjects;
@@ -7,63 +6,14 @@ namespace Robust.Client.UserInterface;
public static class BoundUserInterfaceExt
{
private static T GetWindow<T>(BoundUserInterface bui) where T : BaseWindow, new()
{
var window = bui.CreateDisposableControl<T>();
window.OnClose += bui.Close;
var system = bui.EntMan.System<UserInterfaceSystem>();
system.RegisterControl(bui, window);
return window;
}
/// <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 = GetWindow<T>(bui);
if (bui.EntMan.System<UserInterfaceSystem>().TryGetPosition(bui.Owner, bui.UiKey, out var position))
{
window.Open(position);
}
else
{
window.OpenCentered();
}
return window;
}
public static T CreateWindowCenteredLeft<T>(this BoundUserInterface bui) where T : BaseWindow, new()
{
var window = GetWindow<T>(bui);
if (bui.EntMan.System<UserInterfaceSystem>().TryGetPosition(bui.Owner, bui.UiKey, out var position))
{
window.Open(position);
}
else
{
window.OpenCenteredLeft();
}
return window;
}
public static T CreateWindowCenteredRight<T>(this BoundUserInterface bui) where T : BaseWindow, new()
{
var window = GetWindow<T>(bui);
if (bui.EntMan.System<UserInterfaceSystem>().TryGetPosition(bui.Owner, bui.UiKey, out var position))
{
window.Open(position);
}
else
{
window.OpenCenteredRight();
}
var window = bui.CreateDisposableControl<T>();
window.OpenCentered();
window.OnClose += bui.Close;
return window;
}

View File

@@ -128,7 +128,7 @@ namespace Robust.Client.UserInterface
UserInterfaceManagerInternal.QueueStyleUpdate(this);
}
public void InvalidateStyleSheet()
internal void StyleSheetUpdate()
{
_stylesheetUpdateNeeded = true;
@@ -137,7 +137,7 @@ namespace Robust.Client.UserInterface
internal void StylesheetUpdateRecursive()
{
InvalidateStyleSheet();
StyleSheetUpdate();
foreach (var child in Children)
{
@@ -149,7 +149,7 @@ namespace Robust.Client.UserInterface
}
}
public void DoStyleUpdate()
internal void DoStyleUpdate()
{
_styleProperties.Clear();

View File

@@ -549,7 +549,7 @@ namespace Robust.Client.UserInterface
{
}
protected internal virtual void Draw(IRenderHandle renderHandle)
internal virtual void DrawInternal(IRenderHandle renderHandle)
{
Draw(renderHandle.DrawingHandleScreen);
}

View File

@@ -87,6 +87,7 @@ public sealed class TileSpawningUIController : UIController
return;
_window = UIManager.CreateWindow<TileSpawnWindow>();
LayoutContainer.SetAnchorPreset(_window,LayoutContainer.LayoutPreset.CenterLeft);
_window.SearchBar.GrabKeyboardFocus();
_window.ClearButton.OnPressed += OnTileClearPressed;
_window.SearchBar.OnTextChanged += OnTileSearchChanged;
_window.TileList.OnItemSelected += OnTileItemSelected;

View File

@@ -9,7 +9,6 @@ public class EntityPrototypeView : SpriteView
{
private string? _currentPrototype;
private EntityUid? _ourEntity;
private bool _isShowing;
public EntityPrototypeView()
{
@@ -23,6 +22,8 @@ public class EntityPrototypeView : SpriteView
public void SetPrototype(EntProtoId? entProto)
{
SpriteSystem ??= EntMan.System<SpriteSystem>();
if (entProto == _currentPrototype
&& EntMan.TryGetComponent(Entity?.Owner, out MetaDataComponent? meta)
&& meta.EntityPrototype?.ID == _currentPrototype)
@@ -31,10 +32,14 @@ public class EntityPrototypeView : SpriteView
}
_currentPrototype = entProto;
SetEntity(null);
EntMan.DeleteEntity(_ourEntity);
if (_ourEntity != null || _isShowing)
if (_currentPrototype != null)
{
UpdateEntity();
_ourEntity = EntMan.Spawn(_currentPrototype);
SpriteSystem.ForceUpdate(_ourEntity.Value);
SetEntity(_ourEntity);
}
}
@@ -43,38 +48,12 @@ public class EntityPrototypeView : SpriteView
base.EnteredTree();
if (_currentPrototype != null)
{
UpdateEntity();
}
_isShowing = true;
SetPrototype(_currentPrototype);
}
protected override void ExitedTree()
{
base.ExitedTree();
EntMan.TryQueueDeleteEntity(_ourEntity);
_ourEntity = null;
_isShowing = false;
}
private void UpdateEntity()
{
SetEntity(null);
EntMan.DeleteEntity(_ourEntity);
if (_currentPrototype != null)
{
SpriteSystem ??= EntMan.System<SpriteSystem>();
_ourEntity = EntMan.Spawn(_currentPrototype);
SpriteSystem.ForceUpdate(_ourEntity.Value);
SetEntity(_ourEntity);
}
else
{
_ourEntity = null;
}
}
}

View File

@@ -28,30 +28,6 @@ namespace Robust.Client.UserInterface.Controls
public int ScrollSpeedX { get; set; } = 50;
public int ScrollSpeedY { get; set; } = 50;
public float VScroll
{
get => _vScrollBar.Value;
set => _vScrollBar.Value = value;
}
public float VScrollTarget
{
get => _vScrollBar.ValueTarget;
set => _vScrollBar.ValueTarget = value;
}
public float HScroll
{
get => _hScrollBar.Value;
set => _hScrollBar.Value = value;
}
public float HScrollTarget
{
get => _hScrollBar.ValueTarget;
set => _hScrollBar.ValueTarget = value;
}
private bool _reserveScrollbarSpace;
public bool ReserveScrollbarSpace
{

View File

@@ -224,7 +224,7 @@ namespace Robust.Client.UserInterface.Controls
_spriteSize = new Vector2(longestRotatedSide, longestRotatedSide);
}
protected internal override void Draw(IRenderHandle renderHandle)
internal override void DrawInternal(IRenderHandle renderHandle)
{
if (!ResolveEntity(out var uid, out var sprite, out var xform))
return;

View File

@@ -5,7 +5,6 @@ using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Timing;
@@ -103,8 +102,6 @@ namespace Robust.Client.UserInterface.CustomControls
{
var cursor = CursorShape.Arrow;
var previewDragMode = GetDragModeFor(args.RelativePosition);
previewDragMode &= ~DragMode.Move;
switch (previewDragMode)
{
case DragMode.Top:
@@ -119,6 +116,9 @@ namespace Robust.Client.UserInterface.CustomControls
case DragMode.Bottom | DragMode.Left:
case DragMode.Top | DragMode.Right:
cursor = CursorShape.Crosshair;
break;
case DragMode.Bottom | DragMode.Right:
case DragMode.Top | DragMode.Left:
cursor = CursorShape.Crosshair;
@@ -160,6 +160,15 @@ namespace Robust.Client.UserInterface.CustomControls
var rect = new UIBox2(left, top, right, bottom);
LayoutContainer.SetPosition(this, rect.TopLeft);
SetSize = rect.Size;
/*
var timing = IoCManager.Resolve<IGameTiming>();
var l = GetValue<float>(LayoutContainer.MarginLeftProperty);
var t = GetValue<float>(LayoutContainer.MarginTopProperty);
Logger.Debug($"{timing.CurFrame}: {rect.TopLeft}/({l}, {t}), {rect.Size}/{SetSize}");
*/
}
}
@@ -220,16 +229,6 @@ namespace Robust.Client.UserInterface.CustomControls
OnOpen?.Invoke();
}
/// <summary>
/// Opens the window and places it at the specified position.
/// </summary>
public void Open(Vector2 position)
{
Measure(Vector2Helpers.Infinity);
Open();
LayoutContainer.SetPosition(this, position);
}
public void OpenCentered() => OpenCenteredAt(new Vector2(0.5f, 0.5f));
public void OpenToLeft() => OpenCenteredAt(new Vector2(0, 0.5f));

View File

@@ -10,11 +10,4 @@ public sealed partial class TileSpawnWindow : DefaultWindow
{
RobustXamlLoader.Load(this);
}
protected override void Opened()
{
base.Opened();
SearchBar.GrabKeyboardFocus();
}
}

View File

@@ -65,13 +65,13 @@ namespace Robust.Client.UserInterface.CustomControls
// -- Handlers: Out --
protected internal override void Draw(IRenderHandle handle)
protected internal override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
if (Viewport == null)
{
handle.DrawingHandleScreen.DrawRect(UIBox2.FromDimensions(new Vector2(0, 0), Size * UIScale), Color.Red);
handle.DrawRect(UIBox2.FromDimensions(new Vector2(0, 0), Size * UIScale), Color.Red);
}
else
{
@@ -82,7 +82,7 @@ namespace Robust.Client.UserInterface.CustomControls
Viewport.RenderScreenOverlaysBelow(handle, this, viewportBounds);
Viewport.Render();
handle.DrawingHandleScreen.DrawTextureRect(Viewport.RenderTarget.Texture,
handle.DrawTextureRect(Viewport.RenderTarget.Texture,
UIBox2.FromDimensions(new Vector2(0, 0), (Vector2i) (Viewport.Size / _viewportResolution)));
Viewport.RenderScreenOverlaysAbove(handle, this, viewportBounds);

View File

@@ -7,7 +7,6 @@ using Robust.Client.UserInterface.CustomControls;
using Robust.Shared;
using Robust.Shared.Audio.Sources;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Robust.Client.UserInterface
{
@@ -147,16 +146,6 @@ namespace Robust.Client.UserInterface
/// but not necessarily a new or existing control is rearranged.
/// </summary>
void UpdateHovered();
/// <summary>
/// Render a control and all of its children.
/// </summary>
void RenderControl(in Control.ControlRenderArguments args, Control control);
/// <summary>
/// Render a control and all of its children.
/// </summary>
void RenderControl(IRenderHandle handle, Control control, Vector2i position);
}
public readonly struct PostDrawUIRootEventArgs

View File

@@ -313,10 +313,7 @@ internal partial class UserInterfaceManager
private void _clearTooltip()
{
_resetTooltipTimer();
if (!_showingTooltip)
return;
if (!_showingTooltip) return;
if (_suppliedTooltip != null)
{
@@ -325,6 +322,7 @@ internal partial class UserInterfaceManager
}
CurrentlyHovered?.PerformHideTooltip();
_resetTooltipTimer();
_showingTooltip = false;
}

View File

@@ -37,7 +37,7 @@ internal sealed partial class UserInterfaceManager
_roots.Add(newRoot);
_windowsToRoot.Add(window.Id, newRoot);
newRoot.InvalidateStyleSheet();
newRoot.StyleSheetUpdate();
newRoot.InvalidateMeasure();
QueueMeasureUpdate(newRoot);
QueueArrangeUpdate(newRoot);

View File

@@ -335,30 +335,6 @@ namespace Robust.Client.UserInterface
}
}
public void RenderControl(in Control.ControlRenderArguments args, Control control)
{
var _ = 0;
RenderControl(args.Handle,
ref _,
control,
args.Position,
args.Modulate,
args.ScissorBox,
args.CoordinateTransform);
}
public void RenderControl(IRenderHandle handle, Control control, Vector2i position)
{
var _ = 0;
RenderControl(handle,
ref _,
control,
position,
Color.White,
null,
Matrix3x2.Identity);
}
public void RenderControl(IRenderHandle renderHandle, ref int total, Control control, Vector2i position, Color modulate,
UIBox2i? scissorBox, Matrix3x2 coordinateTransform)
{
@@ -417,7 +393,7 @@ namespace Robust.Client.UserInterface
// Handle modulation with care.
var oldMod = handle.Modulate;
handle.Modulate = modulate * control.ActualModulateSelf;
control.Draw(renderHandle);
control.DrawInternal(renderHandle);
handle.Modulate = oldMod;
handle.UseShader(null);
}
@@ -433,11 +409,10 @@ namespace Robust.Client.UserInterface
control.PreRenderChildren(ref args);
for (var index = 0; index < control.ChildCount; index++)
foreach (var child in control.Children)
{
var child = control.GetChild(index);
var pos = position + (Vector2i)Vector2.Transform(child.PixelPosition, coordinateTransform);
control.RenderChildOverride(ref args, index, pos);
control.RenderChildOverride(ref args, child.GetPositionInParent(), pos);
}
control.PostRenderChildren(ref args);

View File

@@ -19,112 +19,117 @@ public class Generator : IIncrementalGenerator
public void Initialize(IncrementalGeneratorInitializationContext initContext)
{
IncrementalValuesProvider<(string name, string code)?> dataDefinitions = initContext.SyntaxProvider
.CreateSyntaxProvider(
static (node, _) => node is TypeDeclarationSyntax,
static (context, _) =>
{
var type = (TypeDeclarationSyntax)context.Node;
var symbol = (ITypeSymbol)context.SemanticModel.GetDeclaredSymbol(type)!;
if (!IsDataDefinition(symbol))
return null;
return GenerateForDataDefinition(type, symbol);
}
)
.Where(static type => type != null);
IncrementalValuesProvider<TypeDeclarationSyntax> dataDefinitions = initContext.SyntaxProvider.CreateSyntaxProvider(
static (node, _) => node is TypeDeclarationSyntax,
static (context, _) =>
{
var type = (TypeDeclarationSyntax) context.Node;
var symbol = (ITypeSymbol) context.SemanticModel.GetDeclaredSymbol(type)!;
return IsDataDefinition(symbol) ? type : null;
}
).Where(static type => type != null)!;
var comparer = new DataDefinitionComparer();
initContext.RegisterSourceOutput(
dataDefinitions,
initContext.CompilationProvider.Combine(dataDefinitions.WithComparer(comparer).Collect()),
static (sourceContext, source) =>
{
// TODO: deduplicate based on name?
var (name, code) = source!.Value;
var (compilation, declarations) = source;
var builder = new StringBuilder();
var containingTypes = new Stack<INamedTypeSymbol>();
var declarationsGenerated = new HashSet<string>();
var deltaType = compilation.GetTypeByMetadataName(ComponentDeltaInterfaceName)!;
sourceContext.AddSource(name, code);
foreach (var declaration in declarations)
{
builder.Clear();
containingTypes.Clear();
var type = compilation.GetSemanticModel(declaration.SyntaxTree).GetDeclaredSymbol(declaration)!;
var symbolName = type
.ToDisplayString()
.Replace('<', '{')
.Replace('>', '}');
if (!declarationsGenerated.Add(symbolName))
continue;
var nonPartial = !IsPartial(declaration);
var namespaceString = type.ContainingNamespace.IsGlobalNamespace
? string.Empty
: $"namespace {type.ContainingNamespace.ToDisplayString()};";
var containingType = type.ContainingType;
while (containingType != null)
{
containingTypes.Push(containingType);
containingType = containingType.ContainingType;
}
var containingTypesStart = new StringBuilder();
var containingTypesEnd = new StringBuilder();
foreach (var parent in containingTypes)
{
var syntax = (ClassDeclarationSyntax) parent.DeclaringSyntaxReferences[0].GetSyntax();
if (!IsPartial(syntax))
{
nonPartial = true;
continue;
}
containingTypesStart.AppendLine($"{GetPartialTypeDefinitionLine(parent)}\n{{");
containingTypesEnd.AppendLine("}");
}
var definition = GetDataDefinition(type);
if (nonPartial || definition.InvalidFields)
continue;
builder.AppendLine($$"""
#nullable enable
using System;
using Robust.Shared.Analyzers;
using Robust.Shared.IoC;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager;
using Robust.Shared.Serialization.Manager.Exceptions;
using Robust.Shared.Serialization.TypeSerializers.Interfaces;
#pragma warning disable CS0618 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0108 // Member hides inherited member; missing new keyword
#pragma warning disable RA0002 // Robust access analyzer
{{namespaceString}}
{{containingTypesStart}}
{{GetPartialTypeDefinitionLine(type)}} : ISerializationGenerated<{{definition.GenericTypeName}}>
{
{{GetConstructor(definition)}}
{{GetCopyMethods(definition, deltaType)}}
{{GetInstantiators(definition, deltaType)}}
}
{{containingTypesEnd}}
""");
var sourceText = CSharpSyntaxTree
.ParseText(builder.ToString())
.GetRoot()
.NormalizeWhitespace()
.ToFullString();
sourceContext.AddSource($"{symbolName}.g.cs", sourceText);
}
}
);
}
private static (string, string)? GenerateForDataDefinition(
TypeDeclarationSyntax declaration,
ITypeSymbol type)
{
var builder = new StringBuilder();
var containingTypes = new Stack<INamedTypeSymbol>();
containingTypes.Clear();
var symbolName = type
.ToDisplayString()
.Replace('<', '{')
.Replace('>', '}');
var nonPartial = !IsPartial(declaration);
var namespaceString = type.ContainingNamespace.IsGlobalNamespace
? string.Empty
: $"namespace {type.ContainingNamespace.ToDisplayString()};";
var containingType = type.ContainingType;
while (containingType != null)
{
containingTypes.Push(containingType);
containingType = containingType.ContainingType;
}
var containingTypesStart = new StringBuilder();
var containingTypesEnd = new StringBuilder();
foreach (var parent in containingTypes)
{
var syntax = (ClassDeclarationSyntax)parent.DeclaringSyntaxReferences[0].GetSyntax();
if (!IsPartial(syntax))
{
nonPartial = true;
continue;
}
containingTypesStart.AppendLine($"{GetPartialTypeDefinitionLine(parent)}\n{{");
containingTypesEnd.AppendLine("}");
}
var definition = GetDataDefinition(type);
if (nonPartial || definition.InvalidFields)
return null;
builder.AppendLine($$"""
#nullable enable
using System;
using Robust.Shared.Analyzers;
using Robust.Shared.IoC;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager;
using Robust.Shared.Serialization.Manager.Exceptions;
using Robust.Shared.Serialization.TypeSerializers.Interfaces;
#pragma warning disable CS0618 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0108 // Member hides inherited member; missing new keyword
#pragma warning disable RA0002 // Robust access analyzer
{{namespaceString}}
{{containingTypesStart}}
{{GetPartialTypeDefinitionLine(type)}} : ISerializationGenerated<{{definition.GenericTypeName}}>
{
{{GetConstructor(definition)}}
{{GetCopyMethods(definition)}}
{{GetInstantiators(definition)}}
}
{{containingTypesEnd}}
""");
return ($"{symbolName}.g.cs", builder.ToString());
}
private static DataDefinition GetDataDefinition(ITypeSymbol definition)
{
var fields = new List<DataField>();
@@ -191,7 +196,7 @@ public class Generator : IIncrementalGenerator
return builder.ToString();
}
private static string GetCopyMethods(DataDefinition definition)
private static string GetCopyMethods(DataDefinition definition, ITypeSymbol deltaType)
{
var builder = new StringBuilder();
@@ -262,36 +267,36 @@ public class Generator : IIncrementalGenerator
{{baseCopy}}
""");
foreach (var interfaceName in InternalGetImplicitDataDefinitionInterfaces(definition.Type, true))
foreach (var @interface in InternalGetImplicitDataDefinitionInterfaces(definition.Type, true, deltaType))
{
var interfaceModifiers = baseType != null &&
baseType.AllInterfaces.Any(i => i.ToDisplayString() == interfaceName)
var interfaceModifiers = baseType != null && baseType.AllInterfaces.Contains(@interface, SymbolEqualityComparer.Default)
? "override "
: modifiers;
var interfaceName = @interface.ToDisplayString();
builder.AppendLine($$"""
/// <seealso cref="ISerializationManager.CopyTo"/>
[Obsolete("Use ISerializationManager.CopyTo instead")]
public {{interfaceModifiers}} void InternalCopy(ref {{interfaceName}} target, ISerializationManager serialization, SerializationHookContext hookCtx, ISerializationContext? context = null)
{
var def = ({{definition.GenericTypeName}}) target;
Copy(ref def, serialization, hookCtx, context);
target = def;
}
/// <seealso cref="ISerializationManager.CopyTo"/>
[Obsolete("Use ISerializationManager.CopyTo instead")]
public {{interfaceModifiers}} void InternalCopy(ref {{interfaceName}} target, ISerializationManager serialization, SerializationHookContext hookCtx, ISerializationContext? context = null)
{
var def = ({{definition.GenericTypeName}}) target;
Copy(ref def, serialization, hookCtx, context);
target = def;
}
/// <seealso cref="ISerializationManager.CopyTo"/>
[Obsolete("Use ISerializationManager.CopyTo instead")]
public {{interfaceModifiers}} void Copy(ref {{interfaceName}} target, ISerializationManager serialization, SerializationHookContext hookCtx, ISerializationContext? context = null)
{
InternalCopy(ref target, serialization, hookCtx, context);
}
""");
/// <seealso cref="ISerializationManager.CopyTo"/>
[Obsolete("Use ISerializationManager.CopyTo instead")]
public {{interfaceModifiers}} void Copy(ref {{interfaceName}} target, ISerializationManager serialization, SerializationHookContext hookCtx, ISerializationContext? context = null)
{
InternalCopy(ref target, serialization, hookCtx, context);
}
""");
}
return builder.ToString();
}
private static string GetInstantiators(DataDefinition definition)
private static string GetInstantiators(DataDefinition definition, ITypeSymbol deltaType)
{
var builder = new StringBuilder();
var modifiers = string.Empty;
@@ -325,28 +330,27 @@ public class Generator : IIncrementalGenerator
""");
}
foreach (var interfaceName in InternalGetImplicitDataDefinitionInterfaces(definition.Type, false))
foreach (var @interface in InternalGetImplicitDataDefinitionInterfaces(definition.Type, false, deltaType))
{
var interfaceName = @interface.ToDisplayString();
builder.AppendLine($$"""
{{interfaceName}} {{interfaceName}}.Instantiate()
{
return Instantiate();
}
{{interfaceName}} {{interfaceName}}.Instantiate()
{
return Instantiate();
}
{{interfaceName}} ISerializationGenerated<{{interfaceName}}>.Instantiate()
{
return Instantiate();
}
""");
{{interfaceName}} ISerializationGenerated<{{interfaceName}}>.Instantiate()
{
return Instantiate();
}
""");
}
return builder.ToString();
}
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
private static IEnumerable<string> InternalGetImplicitDataDefinitionInterfaces(
ITypeSymbol type,
bool all)
private static IEnumerable<ITypeSymbol> InternalGetImplicitDataDefinitionInterfaces(ITypeSymbol type, bool all, ITypeSymbol deltaType)
{
var symbols = GetImplicitDataDefinitionInterfaces(type, all);
@@ -364,10 +368,10 @@ public class Generator : IIncrementalGenerator
return symbols;
}
if (symbols.Any(x => x == ComponentDeltaInterfaceName))
if (symbols.Any(x => x.ToDisplayString() == deltaType.ToDisplayString()))
return symbols;
return symbols.Append(ComponentDeltaInterfaceName);
return symbols.Append(deltaType);
}
// TODO serveronly? do we care? who knows!!

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -94,13 +93,13 @@ internal static class Types
return false;
}
internal static IEnumerable<string> GetImplicitDataDefinitionInterfaces(ITypeSymbol type, bool all)
internal static IEnumerable<ITypeSymbol> GetImplicitDataDefinitionInterfaces(ITypeSymbol type, bool all)
{
var interfaces = all ? type.AllInterfaces : type.Interfaces;
foreach (var @interface in interfaces)
{
if (IsImplicitDataDefinitionInterface(@interface))
yield return @interface.ToDisplayString();
yield return @interface;
}
}

View File

@@ -81,58 +81,53 @@ public sealed partial class AudioSystem : SharedAudioSystem
}
/// <inheritdoc />
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(ResolvedSoundSpecifier? specifier, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null)
{
if (specifier is null)
if (string.IsNullOrEmpty(filename))
return null;
var entity = SetupAudio(specifier, audioParams);
var entity = SetupAudio(filename, audioParams);
AddAudioFilter(entity, entity.Comp, playerFilter);
entity.Comp.Global = true;
return (entity, entity.Comp);
}
/// <inheritdoc />
public override (EntityUid Entity, AudioComponent Component)? PlayEntity(ResolvedSoundSpecifier? specifier, Filter playerFilter, EntityUid uid, bool recordReplay, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string? filename, Filter playerFilter, EntityUid uid, bool recordReplay, AudioParams? audioParams = null)
{
if (specifier is null)
if (string.IsNullOrEmpty(filename))
return null;
if (TerminatingOrDeleted(uid))
return null;
var entity = SetupAudio(specifier, audioParams);
var entity = SetupAudio(filename, audioParams);
// Move it after setting it up
XformSystem.SetCoordinates(entity, new EntityCoordinates(uid, Vector2.Zero));
// TODO AUDIO
// Add methods that allow for custom audio range.
// Some methods try to reduce the audio range, resulting in a custom filter which then unnecessarily has to
// use PVS overrides. PlayEntity with a reduced range shouldn't need PVS overrides at all.
AddAudioFilter(entity, entity.Comp, playerFilter);
return (entity, entity.Comp);
}
/// <inheritdoc />
public override (EntityUid Entity, AudioComponent Component)? PlayPvs(ResolvedSoundSpecifier? specifier, EntityUid uid, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string? filename, EntityUid uid, AudioParams? audioParams = null)
{
if (specifier is null)
if (string.IsNullOrEmpty(filename))
return null;
if (TerminatingOrDeleted(uid))
return null;
var entity = SetupAudio(specifier, audioParams);
var entity = SetupAudio(filename, audioParams);
XformSystem.SetCoordinates(entity, new EntityCoordinates(uid, Vector2.Zero));
return (entity, entity.Comp);
}
/// <inheritdoc />
public override (EntityUid Entity, AudioComponent Component)? PlayStatic(ResolvedSoundSpecifier? specifier, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string? filename, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null)
{
if (specifier is null)
if (string.IsNullOrEmpty(filename))
return null;
if (TerminatingOrDeleted(coordinates.EntityId))
@@ -144,7 +139,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
if (!coordinates.IsValid(EntityManager))
return null;
var entity = SetupAudio(specifier, audioParams);
var entity = SetupAudio(filename, audioParams);
XformSystem.SetCoordinates(entity, coordinates);
AddAudioFilter(entity, entity.Comp, playerFilter);
@@ -152,10 +147,10 @@ public sealed partial class AudioSystem : SharedAudioSystem
}
/// <inheritdoc />
public override (EntityUid Entity, AudioComponent Component)? PlayPvs(ResolvedSoundSpecifier? specifier, EntityCoordinates coordinates,
public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string? filename, EntityCoordinates coordinates,
AudioParams? audioParams = null)
{
if (specifier is null)
if (string.IsNullOrEmpty(filename))
return null;
if (TerminatingOrDeleted(coordinates.EntityId))
@@ -168,7 +163,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
return null;
// TODO: Transform TryFindGridAt mess + optimisation required.
var entity = SetupAudio(specifier, audioParams);
var entity = SetupAudio(filename, audioParams);
XformSystem.SetCoordinates(entity, coordinates);
return (entity, entity.Comp);
@@ -191,7 +186,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
if (sound == null)
return null;
var audio = PlayPvs(ResolveSound(sound), source, audioParams ?? sound.Params);
var audio = PlayPvs(GetSound(sound), source, audioParams ?? sound.Params);
if (audio == null)
return null;
@@ -206,7 +201,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
if (sound == null)
return null;
var audio = PlayPvs(ResolveSound(sound), coordinates, audioParams ?? sound.Params);
var audio = PlayPvs(GetSound(sound), coordinates, audioParams ?? sound.Params);
if (audio == null)
return null;
@@ -215,12 +210,12 @@ public sealed partial class AudioSystem : SharedAudioSystem
return audio;
}
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(ResolvedSoundSpecifier? filename, ICommonSession recipient, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, ICommonSession recipient, AudioParams? audioParams = null)
{
return PlayGlobal(filename, Filter.SinglePlayer(recipient), false, audioParams);
}
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(ResolvedSoundSpecifier? filename, EntityUid recipient, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, EntityUid recipient, AudioParams? audioParams = null)
{
if (TryComp(recipient, out ActorComponent? actor))
return PlayGlobal(filename, actor.PlayerSession, audioParams);
@@ -228,12 +223,12 @@ public sealed partial class AudioSystem : SharedAudioSystem
return null;
}
public override (EntityUid Entity, AudioComponent Component)? PlayEntity(ResolvedSoundSpecifier? filename, ICommonSession recipient, EntityUid uid, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string? filename, ICommonSession recipient, EntityUid uid, AudioParams? audioParams = null)
{
return PlayEntity(filename, Filter.SinglePlayer(recipient), uid, false, audioParams);
}
public override (EntityUid Entity, AudioComponent Component)? PlayEntity(ResolvedSoundSpecifier? filename, EntityUid recipient, EntityUid uid, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string? filename, EntityUid recipient, EntityUid uid, AudioParams? audioParams = null)
{
if (TryComp(recipient, out ActorComponent? actor))
return PlayEntity(filename, actor.PlayerSession, uid, audioParams);
@@ -241,12 +236,12 @@ public sealed partial class AudioSystem : SharedAudioSystem
return null;
}
public override (EntityUid Entity, AudioComponent Component)? PlayStatic(ResolvedSoundSpecifier? filename, ICommonSession recipient, EntityCoordinates coordinates, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string? filename, ICommonSession recipient, EntityCoordinates coordinates, AudioParams? audioParams = null)
{
return PlayStatic(filename, Filter.SinglePlayer(recipient), coordinates, false, audioParams);
}
public override (EntityUid Entity, AudioComponent Component)? PlayStatic(ResolvedSoundSpecifier? filename, EntityUid recipient, EntityCoordinates coordinates, AudioParams? audioParams = null)
public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string? filename, EntityUid recipient, EntityCoordinates coordinates, AudioParams? audioParams = null)
{
if (TryComp(recipient, out ActorComponent? actor))
return PlayStatic(filename, actor.PlayerSession, coordinates, audioParams);

View File

@@ -297,7 +297,7 @@ namespace Robust.Server
: null;
// Set up the VFS
_resources.Initialize(dataDir, hideUserDataDir: false);
_resources.Initialize(dataDir);
var mountOptions = _commandLineArgs != null
? MountOptions.Merge(_commandLineArgs.MountOptions, Options.MountOptions) : Options.MountOptions;

View File

@@ -1,15 +1,14 @@
using System.Linq;
using System.Numerics;
using Robust.Server.GameObjects;
using Robust.Server.Maps;
using Robust.Shared.Console;
using Robust.Shared.ContentPack;
using Robust.Shared.EntitySerialization;
using Robust.Shared.EntitySerialization.Systems;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
namespace Robust.Server.Console.Commands
{
@@ -43,7 +42,7 @@ namespace Robust.Server.Console.Commands
return;
}
_ent.System<MapLoaderSystem>().TrySaveGrid(uid, new ResPath(args[1]));
_ent.System<MapLoaderSystem>().Save(uid, args[1]);
shell.WriteLine("Save successful. Look in the user data directory.");
}
@@ -64,6 +63,7 @@ namespace Robust.Server.Console.Commands
public sealed class LoadGridCommand : LocalizedCommands
{
[Dependency] private readonly IEntitySystemManager _system = default!;
[Dependency] private readonly IMapManager _map = default!;
[Dependency] private readonly IResourceManager _resource = default!;
public override string Command => "loadgrid";
@@ -91,14 +91,13 @@ namespace Robust.Server.Console.Commands
return;
}
var sys = _system.GetEntitySystem<SharedMapSystem>();
if (!sys.MapExists(mapId))
if (!_map.MapExists(mapId))
{
shell.WriteError("Target map does not exist.");
return;
}
Vector2 offset = default;
var loadOptions = new MapLoadOptions();
if (args.Length >= 4)
{
if (!float.TryParse(args[2], out var x))
@@ -113,10 +112,9 @@ namespace Robust.Server.Console.Commands
return;
}
offset = new Vector2(x, y);
loadOptions.Offset = new Vector2(x, y);
}
Angle rot = default;
if (args.Length >= 5)
{
if (!float.TryParse(args[4], out var rotation))
@@ -125,10 +123,9 @@ namespace Robust.Server.Console.Commands
return;
}
rot = Angle.FromDegrees(rotation);
loadOptions.Rotation = Angle.FromDegrees(rotation);
}
var opts = DeserializationOptions.Default;
if (args.Length >= 6)
{
if (!bool.TryParse(args[5], out var storeUids))
@@ -137,11 +134,10 @@ namespace Robust.Server.Console.Commands
return;
}
opts.StoreYamlUids = storeUids;
loadOptions.StoreMapUids = storeUids;
}
var path = new ResPath(args[1]);
_system.GetEntitySystem<MapLoaderSystem>().TryLoadGrid(mapId, path, out _, opts, offset, rot);
_system.GetEntitySystem<MapLoaderSystem>().Load(mapId, args[1], loadOptions);
}
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
@@ -153,6 +149,7 @@ namespace Robust.Server.Console.Commands
public sealed class SaveMap : LocalizedCommands
{
[Dependency] private readonly IEntitySystemManager _system = default!;
[Dependency] private readonly IMapManager _map = default!;
[Dependency] private readonly IResourceManager _resource = default!;
public override string Command => "savemap";
@@ -192,14 +189,13 @@ namespace Robust.Server.Console.Commands
if (mapId == MapId.Nullspace)
return;
var sys = _system.GetEntitySystem<SharedMapSystem>();
if (!sys.MapExists(mapId))
if (!_map.MapExists(mapId))
{
shell.WriteError(Loc.GetString("cmd-savemap-not-exist"));
return;
}
if (sys.IsInitialized(mapId) &&
if (_map.IsMapInitialized(mapId) &&
( args.Length < 3 || !bool.TryParse(args[2], out var force) || !force))
{
shell.WriteError(Loc.GetString("cmd-savemap-init-warning"));
@@ -207,7 +203,7 @@ namespace Robust.Server.Console.Commands
}
shell.WriteLine(Loc.GetString("cmd-savemap-attempt", ("mapId", mapId), ("path", args[1])));
_system.GetEntitySystem<MapLoaderSystem>().TrySaveMap(mapId, new ResPath(args[1]));
_system.GetEntitySystem<MapLoaderSystem>().SaveMap(mapId, args[1]);
shell.WriteLine(Loc.GetString("cmd-savemap-success"));
}
}
@@ -215,6 +211,7 @@ namespace Robust.Server.Console.Commands
public sealed class LoadMap : LocalizedCommands
{
[Dependency] private readonly IEntitySystemManager _system = default!;
[Dependency] private readonly IMapManager _map = default!;
[Dependency] private readonly IResourceManager _resource = default!;
public override string Command => "loadmap";
@@ -270,49 +267,61 @@ namespace Robust.Server.Console.Commands
return;
}
var sys = _system.GetEntitySystem<SharedMapSystem>();
if (sys.MapExists(mapId))
if (_map.MapExists(mapId))
{
shell.WriteError(Loc.GetString("cmd-loadmap-exists", ("mapId", mapId)));
return;
}
float x = 0;
if (args.Length >= 3 && !float.TryParse(args[2], out x))
var loadOptions = new MapLoadOptions();
float x = 0, y = 0;
if (args.Length >= 3)
{
shell.WriteError(Loc.GetString("cmd-parse-failure-float", ("arg", args[2])));
return;
if (!float.TryParse(args[2], out x))
{
shell.WriteError(Loc.GetString("cmd-parse-failure-float", ("arg", args[2])));
return;
}
}
float y = 0;
if (args.Length >= 4 && !float.TryParse(args[3], out y))
if (args.Length >= 4)
{
shell.WriteError(Loc.GetString("cmd-parse-failure-float", ("arg", args[3])));
return;
}
var offset = new Vector2(x, y);
float rotation = 0;
if (args.Length >= 5 && !float.TryParse(args[4], out rotation))
{
shell.WriteError(Loc.GetString("cmd-parse-failure-float", ("arg", args[4])));
return;
}
var rot = new Angle(rotation);
bool storeUids = false;
if (args.Length >= 6 && !bool.TryParse(args[5], out storeUids))
{
shell.WriteError(Loc.GetString("cmd-parse-failure-bool", ("arg", args[5])));
return;
if (!float.TryParse(args[3], out y))
{
shell.WriteError(Loc.GetString("cmd-parse-failure-float", ("arg", args[3])));
return;
}
}
var opts = new DeserializationOptions {StoreYamlUids = storeUids};
loadOptions.Offset = new Vector2(x, y);
var path = new ResPath(args[1]);
_system.GetEntitySystem<MapLoaderSystem>().TryLoadMapWithId(mapId, path, out _, out _, opts, offset, rot);
if (args.Length >= 5)
{
if (!float.TryParse(args[4], out var rotation))
{
shell.WriteError(Loc.GetString("cmd-parse-failure-float", ("arg", args[4])));
return;
}
if (sys.MapExists(mapId))
loadOptions.Rotation = new Angle(rotation);
}
if (args.Length >= 6)
{
if (!bool.TryParse(args[5], out var storeUids))
{
shell.WriteError(Loc.GetString("cmd-parse-failure-bool", ("arg", args[5])));
return;
}
loadOptions.StoreMapUids = storeUids;
}
_system.GetEntitySystem<MapLoaderSystem>().TryLoad(mapId, args[1], out _, loadOptions);
if (_map.MapExists(mapId))
shell.WriteLine(Loc.GetString("cmd-loadmap-success", ("mapId", mapId), ("path", args[1])));
else
shell.WriteLine(Loc.GetString("cmd-loadmap-error", ("path", args[1])));

View File

@@ -1,13 +1,14 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Robust.Shared.GameObjects
namespace Robust.Server.GameObjects
{
/// <summary>
/// Controls PVS visibility of entities. THIS COMPONENT CONTROLS WHETHER ENTITIES ARE NETWORKED TO PLAYERS
/// AND SHOULD NOT BE USED AS THE SOLE WAY TO HIDE AN ENTITY FROM A PLAYER.
/// </summary>
[RegisterComponent]
[Access(typeof(SharedVisibilitySystem))]
[Access(typeof(VisibilitySystem))]
public sealed partial class VisibilityComponent : Component
{
/// <summary>

File diff suppressed because it is too large Load Diff

View File

@@ -21,7 +21,7 @@ namespace Robust.Server.GameObjects
protected override MapId GetNextMapId()
{
var id = new MapId(++LastMapId);
while (MapExists(id) || UsedIds.Contains(id))
while (MapManager.MapExists(id))
{
id = new MapId(++LastMapId);
}

View File

@@ -6,7 +6,7 @@ using Robust.Shared.ViewVariables;
namespace Robust.Server.GameObjects
{
public sealed class VisibilitySystem : SharedVisibilitySystem
public sealed class VisibilitySystem : EntitySystem
{
[Dependency] private readonly PvsSystem _pvs = default!;
[Dependency] private readonly IViewVariablesManager _vvManager = default!;
@@ -40,7 +40,7 @@ namespace Robust.Server.GameObjects
EntityManager.EntityInitialized -= OnEntityInit;
}
public override void AddLayer(Entity<VisibilityComponent?> ent, ushort layer, bool refresh = true)
public void AddLayer(Entity<VisibilityComponent?> ent, ushort layer, bool refresh = true)
{
ent.Comp ??= _visibilityQuery.CompOrNull(ent.Owner) ?? AddComp<VisibilityComponent>(ent.Owner);
@@ -53,7 +53,7 @@ namespace Robust.Server.GameObjects
RefreshVisibility(ent);
}
public override void RemoveLayer(Entity<VisibilityComponent?> ent, ushort layer, bool refresh = true)
public void RemoveLayer(Entity<VisibilityComponent?> ent, ushort layer, bool refresh = true)
{
if (!_visibilityQuery.Resolve(ent.Owner, ref ent.Comp, false))
return;
@@ -67,7 +67,7 @@ namespace Robust.Server.GameObjects
RefreshVisibility(ent);
}
public override void SetLayer(Entity<VisibilityComponent?> ent, ushort layer, bool refresh = true)
public void SetLayer(Entity<VisibilityComponent?> ent, ushort layer, bool refresh = true)
{
ent.Comp ??= _visibilityQuery.CompOrNull(ent.Owner) ?? AddComp<VisibilityComponent>(ent.Owner);
@@ -90,14 +90,14 @@ namespace Robust.Server.GameObjects
RefreshVisibility(ent.Owner, null, ent.Comp);
}
public override void RefreshVisibility(EntityUid uid,
public void RefreshVisibility(EntityUid uid,
VisibilityComponent? visibilityComponent = null,
MetaDataComponent? meta = null)
{
RefreshVisibility((uid, visibilityComponent, meta));
}
public override void RefreshVisibility(Entity<VisibilityComponent?, MetaDataComponent?> ent)
public void RefreshVisibility(Entity<VisibilityComponent?, MetaDataComponent?> ent)
{
if (!_metaQuery.Resolve(ent, ref ent.Comp2, false))
return;

View File

@@ -0,0 +1,21 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;
namespace Robust.Server.GameObjects
{
internal interface IServerEntityManagerInternal : IServerEntityManager
{
// These methods are used by the map loader to do multi-stage entity construction during map load.
// I would recommend you refer to the MapLoader for usage.
EntityUid AllocEntity(EntityPrototype? prototype);
void FinishEntityLoad(EntityUid entity, IEntityLoadContext? context = null);
void FinishEntityLoad(EntityUid entity, EntityPrototype? prototype, IEntityLoadContext? context = null);
void FinishEntityInitialization(EntityUid entity, MetaDataComponent? meta = null);
void FinishEntityStartup(EntityUid entity);
}
}

View File

@@ -0,0 +1,17 @@
using Robust.Shared.GameObjects;
namespace Robust.Server.GameObjects
{
/// <summary>
/// Metadata component used to keep consistent UIDs inside map files cross saving.
/// </summary>
/// <remarks>
/// This component stores the previous map UID of entities from map load.
/// This can then be used to re-serialize the entity with the same UID for the merge driver to recognize.
/// </remarks>
[RegisterComponent, UnsavedComponent]
public sealed partial class MapSaveIdComponent : Component
{
public int Uid { get; set; }
}
}

View File

@@ -1,8 +1,7 @@
using System.Collections.Generic;
using Robust.Shared.EntitySerialization.Systems;
using Robust.Shared.GameObjects;
namespace Robust.Shared.EntitySerialization.Components;
namespace Robust.Server.GameObjects;
/// <summary>
/// Used by <see cref="MapLoaderSystem"/> to track the original tile map from when a map was loaded.

View File

@@ -27,7 +27,7 @@ namespace Robust.Server.GameObjects
/// Manager for entities -- controls things like template loading and instantiation
/// </summary>
[UsedImplicitly] // DI Container
public sealed class ServerEntityManager : EntityManager, IServerEntityManager
public sealed class ServerEntityManager : EntityManager, IServerEntityManagerInternal
{
private static readonly Gauge EntitiesCount = Metrics.CreateGauge(
"robust_entities_count",
@@ -61,6 +61,32 @@ namespace Robust.Server.GameObjects
_pvs = System<PvsSystem>();
}
EntityUid IServerEntityManagerInternal.AllocEntity(EntityPrototype? prototype)
{
return AllocEntity(prototype, out _);
}
void IServerEntityManagerInternal.FinishEntityLoad(EntityUid entity, IEntityLoadContext? context)
{
LoadEntity(entity, context);
}
void IServerEntityManagerInternal.FinishEntityLoad(EntityUid entity, EntityPrototype? prototype, IEntityLoadContext? context)
{
LoadEntity(entity, context, prototype);
}
void IServerEntityManagerInternal.FinishEntityInitialization(EntityUid entity, MetaDataComponent? meta)
{
InitializeEntity(entity, meta);
}
[Obsolete("Use StartEntity")]
void IServerEntityManagerInternal.FinishEntityStartup(EntityUid entity)
{
StartEntity(entity);
}
internal override EntityUid CreateEntity(string? prototypeName, out MetaDataComponent metadata, IEntityLoadContext? context = null)
{
if (prototypeName == null)

View File

@@ -20,10 +20,6 @@ namespace Robust.Server.GameStates;
/// </summary>
internal sealed class PvsSession(ICommonSession session, ResizableMemoryRegion<PvsData> memoryRegion)
{
#if DEBUG
public HashSet<NetEntity> ToSendSet = new();
#endif
public readonly ICommonSession Session = session;
public readonly ResizableMemoryRegion<PvsData> DataMemory = memoryRegion;
@@ -184,9 +180,6 @@ internal struct PvsMetadata
public NetEntity NetEntity;
public GameTick LastModifiedTick;
// TODO PVS maybe store as int?
// Theres extra space anyways, and the mask checks always need to convert to an int first, so it'd probably be faster too.
public ushort VisMask;
public EntityLifeStage LifeStage;
#if DEBUG
@@ -204,7 +197,7 @@ internal struct PvsMetadata
{
DebugTools.AssertEqual(NetEntity, comp.NetEntity);
DebugTools.AssertEqual(VisMask, comp.VisibilityMask);
DebugTools.Assert(LifeStage == comp.EntityLifeStage);
DebugTools.AssertEqual(LifeStage, comp.EntityLifeStage);
DebugTools.Assert(LastModifiedTick == comp.EntityLastModifiedTick || LastModifiedTick.Value == 0);
}
}

View File

@@ -5,14 +5,13 @@ using Robust.Server.Player;
using Robust.Shared.Console;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Player;
using Robust.Shared.Utility;
namespace Robust.Server.GameStates;
public sealed class PvsOverrideSystem : SharedPvsOverrideSystem
public sealed class PvsOverrideSystem : EntitySystem
{
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IConsoleHost _console = default!;
@@ -29,8 +28,7 @@ public sealed class PvsOverrideSystem : SharedPvsOverrideSystem
base.Initialize();
EntityManager.EntityDeleted += OnDeleted;
_player.PlayerStatusChanged += OnPlayerStatusChanged;
SubscribeLocalEvent<MapRemovedEvent>(OnMapRemoved);
SubscribeLocalEvent<MapCreatedEvent>(OnMapCreated);
SubscribeLocalEvent<MapChangedEvent>(OnMapChanged);
SubscribeLocalEvent<GridInitializeEvent>(OnGridCreated);
SubscribeLocalEvent<GridRemovalEvent>(OnGridRemoved);
@@ -134,12 +132,10 @@ public sealed class PvsOverrideSystem : SharedPvsOverrideSystem
/// <summary>
/// Forces the entity, all of its parents, and all of its children to ignore normal PVS range limitations,
/// causing them to be sent to all clients. This will still respect visibility masks, it only overrides the range.
/// causing them to always be sent to all clients.
/// </summary>
public override void AddGlobalOverride(EntityUid uid)
public void AddGlobalOverride(EntityUid uid)
{
base.AddGlobalOverride(uid);
if (GlobalOverride.Add(uid))
_hasOverride.Add(uid);
}
@@ -147,10 +143,8 @@ public sealed class PvsOverrideSystem : SharedPvsOverrideSystem
/// <summary>
/// Removes an entity from the global overrides.
/// </summary>
public override void RemoveGlobalOverride(EntityUid uid)
public void RemoveGlobalOverride(EntityUid uid)
{
base.RemoveGlobalOverride(uid);
GlobalOverride.Remove(uid);
// Not bothering to clear _hasOverride, as we'd have to check all the other collections, and at that point we
// might as well just do that when the entity gets deleted anyways.
@@ -160,9 +154,8 @@ public sealed class PvsOverrideSystem : SharedPvsOverrideSystem
/// This causes an entity and all of its parents to always be sent to all players.
/// </summary>
/// <remarks>
/// This differs from <see cref="AddGlobalOverride"/> as it does not send children, will ignore a players usual
/// PVS budget, and ignores visibility masks. You generally shouldn't use this unless an entity absolutely always
/// needs to be sent to all clients.
/// This differs from <see cref="AddGlobalOverride"/> as it does not send children, and will ignore a players usual
/// PVS budget. You generally shouldn't use this unless an entity absolutely always needs to be sent to all clients.
/// </remarks>
public void AddForceSend(EntityUid uid)
{
@@ -178,12 +171,11 @@ public sealed class PvsOverrideSystem : SharedPvsOverrideSystem
}
/// <summary>
/// This causes an entity and all of its parents to always be sent to a player.
/// This causes an entity and all of its parents to always be sent to a player..
/// </summary>
/// <remarks>
/// This differs from <see cref="AddSessionOverride"/> as it does not send children, will ignore a players usual
/// PVS budget, and ignores visibility masks. You generally shouldn't use this unless an entity absolutely always
/// needs to be sent to a client.
/// This differs from <see cref="AddSessionOverride"/> as it does not send children, and will ignore a players usual
/// PVS budget. You generally shouldn't use this unless an entity absolutely always needs to be sent to a client.
/// </remarks>
public void AddForceSend(EntityUid uid, ICommonSession session)
{
@@ -209,12 +201,10 @@ public sealed class PvsOverrideSystem : SharedPvsOverrideSystem
/// <summary>
/// Forces the entity, all of its parents, and all of its children to ignore normal PVS range limitations for a
/// specific session. This will still respect visibility masks, it only overrides the range.
/// specific session.
/// </summary>
public override void AddSessionOverride(EntityUid uid, ICommonSession session)
public void AddSessionOverride(EntityUid uid, ICommonSession session)
{
base.AddSessionOverride(uid, session);
if (SessionOverrides.GetOrNew(session).Add(uid))
_hasOverride.Add(uid);
}
@@ -222,10 +212,8 @@ public sealed class PvsOverrideSystem : SharedPvsOverrideSystem
/// <summary>
/// Removes an entity from a session's overrides.
/// </summary>
public override void RemoveSessionOverride(EntityUid uid, ICommonSession session)
public void RemoveSessionOverride(EntityUid uid, ICommonSession session)
{
base.RemoveSessionOverride(uid, session);
if (!SessionOverrides.TryGetValue(session, out var overrides))
return;
@@ -238,17 +226,13 @@ public sealed class PvsOverrideSystem : SharedPvsOverrideSystem
/// <summary>
/// Forces the entity, all of its parents, and all of its children to ignore normal PVS range limitations,
/// causing them to always be sent to the specified clients. This will still respect visibility masks, it only
/// overrides the range.
/// causing them to always be sent to all clients.
/// </summary>
public override void AddSessionOverrides(EntityUid uid, Filter filter)
public void AddSessionOverrides(EntityUid uid, Filter filter)
{
_hasOverride.Add(uid);
base.AddSessionOverrides(uid, filter);
foreach (var session in filter.Recipients)
{
SessionOverrides.GetOrNew(session).Add(uid);
AddSessionOverride(uid, session);
}
}
@@ -275,6 +259,14 @@ public sealed class PvsOverrideSystem : SharedPvsOverrideSystem
#region Map/Grid Events
private void OnMapChanged(MapChangedEvent ev)
{
if (ev.Created)
OnMapCreated(ev);
else
OnMapDestroyed(ev);
}
private void OnGridRemoved(GridRemovalEvent ev)
{
RemoveForceSend(ev.EntityUid);
@@ -287,12 +279,12 @@ public sealed class PvsOverrideSystem : SharedPvsOverrideSystem
AddForceSend(ev.EntityUid);
}
private void OnMapRemoved(MapRemovedEvent ev)
private void OnMapDestroyed(MapChangedEvent ev)
{
RemoveForceSend(ev.Uid);
}
private void OnMapCreated(MapCreatedEvent ev)
private void OnMapCreated(MapChangedEvent ev)
{
// TODO PVS remove this requirement.
// I think this just required refactoring client game state logic so it doesn't sending maps/grids to nullspace.

View File

@@ -303,8 +303,11 @@ internal sealed partial class PvsSystem
RemoveRoot(ev.EntityUid);
}
private void OnMapChanged(MapRemovedEvent ev)
private void OnMapChanged(MapChangedEvent ev)
{
if (!ev.Destroyed)
return;
RemoveRoot(ev.Uid);
}

View File

@@ -19,15 +19,14 @@ internal sealed partial class PvsSystem
private void AddAllOverrides(PvsSession session)
{
var mask = session.VisMask;
var fromTick = session.FromTick;
var mask = RaiseExpandEvent(session, fromTick);
RaiseExpandEvent(session, fromTick);
foreach (ref var ent in CollectionsMarshal.AsSpan(_cachedGlobalOverride))
{
ref var meta = ref _metadataMemory.GetRef(ent.Ptr.Index);
meta.Validate(ent.Meta);
// PVS overrides still respect visibility masks
if ((mask & meta.VisMask) == meta.VisMask)
AddEntity(session, ref ent, ref meta, fromTick);
}
@@ -37,7 +36,7 @@ internal sealed partial class PvsSystem
foreach (var uid in sessionOverrides)
{
RecursivelyAddOverride(session, uid, fromTick, addChildren: true, mask);
RecursivelyAddOverride(session, uid, fromTick, addChildren: true);
}
}
@@ -46,23 +45,22 @@ internal sealed partial class PvsSystem
/// </summary>
private void AddForcedEntities(PvsSession session)
{
// Forced overrides do not respect visibility masks, so we set all bits.
var mask = -1;
// Ignore PVS budgets
session.Budget = new() {NewLimit = int.MaxValue, EnterLimit = int.MaxValue};
var mask = session.VisMask;
var fromTick = session.FromTick;
foreach (ref var ent in CollectionsMarshal.AsSpan(_cachedForceOverride))
{
ref var meta = ref _metadataMemory.GetRef(ent.Ptr.Index);
meta.Validate(ent.Meta);
AddEntity(session, ref ent, ref meta, fromTick);
if ((mask & meta.VisMask) == meta.VisMask)
AddEntity(session, ref ent, ref meta, fromTick);
}
foreach (var uid in session.Viewers)
{
RecursivelyAddOverride(session, uid, fromTick, addChildren: false, mask);
RecursivelyAddOverride(session, uid, fromTick, addChildren: false);
}
if (!_pvsOverride.SessionForceSend.TryGetValue(session.Session, out var sessionForce))
@@ -70,13 +68,13 @@ internal sealed partial class PvsSystem
foreach (var uid in sessionForce)
{
RecursivelyAddOverride(session, uid, fromTick, addChildren: false, mask);
RecursivelyAddOverride(session, uid, fromTick, addChildren: false);
}
}
private int RaiseExpandEvent(PvsSession session, GameTick fromTick)
private void RaiseExpandEvent(PvsSession session, GameTick fromTick)
{
var expandEvent = new ExpandPvsEvent(session.Session, session.VisMask);
var expandEvent = new ExpandPvsEvent(session.Session);
if (session.Session.AttachedEntity != null)
RaiseLocalEvent(session.Session.AttachedEntity.Value, ref expandEvent, true);
@@ -87,25 +85,23 @@ internal sealed partial class PvsSystem
{
foreach (var uid in expandEvent.Entities)
{
RecursivelyAddOverride(session, uid, fromTick, addChildren: false, expandEvent.VisMask);
RecursivelyAddOverride(session, uid, fromTick, addChildren: false);
}
}
if (expandEvent.RecursiveEntities == null)
return expandEvent.VisMask;
return;
foreach (var uid in expandEvent.RecursiveEntities)
{
RecursivelyAddOverride(session, uid, fromTick, addChildren: true, expandEvent.VisMask);
RecursivelyAddOverride(session, uid, fromTick, addChildren: true);
}
return expandEvent.VisMask;
}
/// <summary>
/// Recursively add an entity and all of its parents to the to-send set. This optionally also adds all children.
/// </summary>
private bool RecursivelyAddOverride(PvsSession session, EntityUid uid, GameTick fromTick, bool addChildren, int mask)
private bool RecursivelyAddOverride(PvsSession session, EntityUid uid, GameTick fromTick, bool addChildren)
{
if (!_xformQuery.TryGetComponent(uid, out var xform))
{
@@ -120,20 +116,17 @@ internal sealed partial class PvsSystem
// to the toSend set, it doesn't guarantee that its parents have been. E.g., if a player ghost just teleported
// to follow a far away entity, the player's own entity is still being sent, but we need to ensure that we also
// send the new parents, which may otherwise be delayed because of the PVS budget.
if (parent.IsValid() && !RecursivelyAddOverride(session, parent, fromTick, false, mask))
if (parent.IsValid() && !RecursivelyAddOverride(session, parent, fromTick, false))
return false;
if (!_metaQuery.TryGetComponent(uid, out var meta))
return false;
if ((mask & meta.VisibilityMask) != meta.VisibilityMask)
return false;
if (!AddEntity(session, (uid, meta), fromTick))
return false;
if (addChildren)
RecursivelyAddChildren(session, xform, fromTick, mask);
RecursivelyAddChildren(session, xform, fromTick);
return true;
}
@@ -141,7 +134,7 @@ internal sealed partial class PvsSystem
/// <summary>
/// Recursively add an entity and all of its children to the to-send set.
/// </summary>
private void RecursivelyAddChildren(PvsSession session, TransformComponent xform, GameTick fromTick, int mask)
private void RecursivelyAddChildren(PvsSession session, TransformComponent xform, GameTick fromTick)
{
foreach (var child in xform._children)
{
@@ -152,14 +145,10 @@ internal sealed partial class PvsSystem
}
var metadata = _metaQuery.GetComponent(child);
if ((mask & metadata.VisibilityMask) != metadata.VisibilityMask)
continue;
if (!AddEntity(session, (child, metadata), fromTick))
return; // Budget was exceeded (or some error occurred) -> return instead of continue.
return;
RecursivelyAddChildren(session, childXform, fromTick, mask);
RecursivelyAddChildren(session, childXform, fromTick);
}
}

View File

@@ -142,32 +142,18 @@ internal sealed partial class PvsSystem
if (meta.EntityLifeStage >= EntityLifeStage.Terminating)
{
var rep = new EntityStringRepresentation(entity);
Log.Error($"Attempted to add a deleted entity to PVS send set: '{rep}'. Deletion queued: {EntityManager.IsQueuedForDeletion(uid)}. Trace:\n{Environment.StackTrace}");
// This can happen if some entity was some removed from it's parent while that parent was being deleted.
// As a result the entity was marked for deletion but was never actually properly deleted.
bool queued;
lock (_toDelete)
{
queued = EntityManager.IsQueuedForDeletion(uid) || _toDelete.Contains(uid);
if (!queued)
_toDelete.Add(uid);
}
var rep = new EntityStringRepresentation(entity);
Log.Error($"Attempted to add a deleted entity to PVS send set: '{rep}'. Deletion queued: {queued}. Trace:\n{Environment.StackTrace}");
EntityManager.QueueDeleteEntity(uid);
return false;
}
data.LastSeen = _gameTiming.CurTick;
session.ToSend!.Add(entity.Comp.PvsData);
// TODO PVS PERFORMANCE
// Investigate whether its better to defer actually creating the entity state & populating session.States here?
// I.e., should be be constructing the to-send list & to-get-states lists, and then separately getting all states
// after we have gotten all entities? If the CPU can focus on only processing data in session.DataMemory without
// having to access miscellaneous component info, maybe it will be faster?
// Though for that to work I guess it also has to avoid accessing the metadata component's lifestage?
if (session.RequestedFull)
{
var state = GetFullEntityState(session.Session, uid, meta);

View File

@@ -94,8 +94,6 @@ internal sealed partial class PvsSystem : EntitySystem
/// </summary>
private readonly List<GameTick> _deletedTick = new();
private readonly HashSet<EntityUid> _toDelete = new();
/// <summary>
/// The sessions that are currently being processed. Note that this is in general used by parallel & async tasks.
/// Hence player disconnection processing is deferred and only run via <see cref="ProcessDisconnections"/>.
@@ -129,7 +127,7 @@ internal sealed partial class PvsSystem : EntitySystem
_metaQuery = GetEntityQuery<MetaDataComponent>();
_xformQuery = GetEntityQuery<TransformComponent>();
SubscribeLocalEvent<MapRemovedEvent>(OnMapChanged);
SubscribeLocalEvent<MapChangedEvent>(OnMapChanged);
SubscribeLocalEvent<GridRemovalEvent>(OnGridRemoved);
SubscribeLocalEvent<TransformComponent, TransformStartupEvent>(OnTransformStartup);
@@ -197,12 +195,6 @@ internal sealed partial class PvsSystem : EntitySystem
// Construct & serialize the game state for each player (and for the replay).
SerializeStates();
foreach (var uid in _toDelete)
{
EntityManager.QueueDeleteEntity(uid);
}
_toDelete.Clear();
// Compress & send the states.
SendStates();
@@ -310,9 +302,7 @@ internal sealed partial class PvsSystem : EntitySystem
// Process all entities in visible PVS chunks
AddPvsChunks(session);
#if DEBUG
VerifySessionData(session);
#endif
var toSend = session.ToSend!;
session.ToSend = null;
@@ -342,12 +332,11 @@ internal sealed partial class PvsSystem : EntitySystem
session.Overflow = oldEntry.Value;
}
#if DEBUG
[Conditional("DEBUG")]
private void VerifySessionData(PvsSession pvsSession)
{
var toSend = pvsSession.ToSend!;
var toSendSet = pvsSession.ToSendSet;
toSendSet.Clear();
var toSend = pvsSession.ToSend;
var toSendSet = new HashSet<NetEntity>(toSend!.Count);
foreach (var intPtr in toSend)
{
@@ -371,7 +360,6 @@ internal sealed partial class PvsSystem : EntitySystem
|| data.LastSeen == _gameTiming.CurTick - 1);
}
}
#endif
private (Vector2 worldPos, float range, EntityUid? map) CalcViewBounds(Entity<TransformComponent, EyeComponent?> eye)
{
@@ -473,27 +461,18 @@ internal sealed partial class PvsSystem : EntitySystem
}
[ByRefEvent]
public struct ExpandPvsEvent(ICommonSession session, int mask)
public struct ExpandPvsEvent(ICommonSession session)
{
public readonly ICommonSession Session = session;
/// <summary>
/// List of entities that will get added to this session's PVS set. This will still respect visibility masks.
/// List of entities that will get added to this session's PVS set.
/// </summary>
public List<EntityUid>? Entities;
/// <summary>
/// List of entities that will get added to this session's PVS set. Unlike <see cref="Entities"/> this will also
/// recursively add all children of the given entity. This will still respect visibility masks.
/// recursively add all children of the given entity.
/// </summary>
public List<EntityUid>? RecursiveEntities;
/// <summary>
/// Visibility mask to use when adding entities. Defaults to the usual visibility mask for that client.
/// </summary>
/// <remarks>
/// Note that this mask will affect all global & session overrides from <see cref="PvsOverrideSystem"/> for this
/// client, not just the entities in <see cref="Entities"/> and <see cref="RecursiveEntities"/>.
/// </remarks>
public int VisMask = mask;
}

View File

@@ -0,0 +1,12 @@
using Robust.Shared.GameObjects;
namespace Robust.Server.Maps;
/// <summary>
/// Added to Maps that were loaded by MapLoaderSystem. If not present then this map was created externally.
/// </summary>
[RegisterComponent]
public sealed partial class LoadedMapComponent : Component
{
}

View File

@@ -14,25 +14,19 @@ using Robust.Shared.Serialization.Markdown.Value;
using Robust.Shared.Serialization.TypeSerializers.Interfaces;
using Robust.Shared.Utility;
namespace Robust.Shared.EntitySerialization;
namespace Robust.Server.Maps;
[TypeSerializer]
internal sealed class MapChunkSerializer : ITypeSerializer<MapChunk, MappingDataNode>, ITypeCopyCreator<MapChunk>
{
public ValidationNode Validate(
ISerializationManager serializationManager,
MappingDataNode node,
IDependencyCollection dependencies,
ISerializationContext? context = null)
public ValidationNode Validate(ISerializationManager serializationManager, MappingDataNode node,
IDependencyCollection dependencies, ISerializationContext? context = null)
{
throw new NotImplementedException();
}
public MapChunk Read(ISerializationManager serializationManager, MappingDataNode node,
IDependencyCollection dependencies,
SerializationHookContext hookCtx,
ISerializationContext? context = null,
ISerializationManager.InstantiationDelegate<MapChunk>? instantiationDelegate = null)
IDependencyCollection dependencies, SerializationHookContext hookCtx, ISerializationContext? context = null, ISerializationManager.InstantiationDelegate<MapChunk>? instantiationDelegate = null)
{
var ind = (Vector2i) serializationManager.Read(typeof(Vector2i), node["ind"], hookCtx, context)!;
var tileNode = (ValueDataNode)node["tiles"];
@@ -56,8 +50,10 @@ internal sealed class MapChunkSerializer : ITypeSerializer<MapChunk, MappingData
IReadOnlyDictionary<int, string>? tileMap = null;
if (context is EntityDeserializer serContext)
if (context is MapSerializationContext serContext)
{
tileMap = serContext.TileMap;
}
if (tileMap == null)
{
@@ -77,7 +73,7 @@ internal sealed class MapChunkSerializer : ITypeSerializer<MapChunk, MappingData
for (ushort x = 0; x < chunk.ChunkSize; x++)
{
var id = version < 6 ? reader.ReadUInt16() : reader.ReadInt32();
var flags = reader.ReadByte();
var flags = (TileRenderFlag)reader.ReadByte();
var variant = reader.ReadByte();
var defName = tileMap[id];
@@ -108,12 +104,16 @@ internal sealed class MapChunkSerializer : ITypeSerializer<MapChunk, MappingData
root.Add("version", new ValueDataNode("6"));
gridNode.Value = SerializeTiles(value, context as EntitySerializer);
Dictionary<int, int>? tileWriteMap = null;
if (context is MapSerializationContext mapContext)
tileWriteMap = mapContext.TileWriteMap;
gridNode.Value = SerializeTiles(value, tileWriteMap);
return root;
}
private static string SerializeTiles(MapChunk chunk, EntitySerializer? serializer)
private static string SerializeTiles(MapChunk chunk, Dictionary<int, int>? tileWriteMap)
{
// number of bytes written per tile, because sizeof(Tile) is useless.
const int structSize = 6;
@@ -124,34 +124,17 @@ internal sealed class MapChunkSerializer : ITypeSerializer<MapChunk, MappingData
using (var stream = new MemoryStream(barr))
using (var writer = new BinaryWriter(stream))
{
if (serializer == null)
{
for (ushort y = 0; y < chunk.ChunkSize; y++)
{
for (ushort x = 0; x < chunk.ChunkSize; x++)
{
var tile = chunk.GetTile(x, y);
writer.Write(tile.TypeId);
writer.Write((byte) tile.Flags);
writer.Write(tile.Variant);
}
}
return Convert.ToBase64String(barr);
}
var lastTile = -1;
var yamlId = -1;
for (ushort y = 0; y < chunk.ChunkSize; y++)
{
for (ushort x = 0; x < chunk.ChunkSize; x++)
{
var tile = chunk.GetTile(x, y);
if (tile.TypeId != lastTile)
yamlId = serializer.GetYamlTileId(tile.TypeId);
var typeId = tile.TypeId;
if (tileWriteMap != null)
typeId = tileWriteMap[typeId];
lastTile = tile.TypeId;
writer.Write(yamlId);
writer.Write((byte) tile.Flags);
writer.Write(typeId);
writer.Write((byte)tile.Flags);
writer.Write(tile.Variant);
}
}
@@ -160,12 +143,8 @@ internal sealed class MapChunkSerializer : ITypeSerializer<MapChunk, MappingData
return Convert.ToBase64String(barr);
}
public MapChunk CreateCopy(
ISerializationManager serializationManager,
MapChunk source,
IDependencyCollection dependencies,
SerializationHookContext hookCtx,
ISerializationContext? context = null)
public MapChunk CreateCopy(ISerializationManager serializationManager, MapChunk source,
IDependencyCollection dependencies, SerializationHookContext hookCtx, ISerializationContext? context = null)
{
var mapManager = dependencies.Resolve<IMapManager>();
mapManager.SuppressOnTileChanged = true;

View File

@@ -0,0 +1,59 @@
using System.Numerics;
using JetBrains.Annotations;
using Robust.Shared.Maths;
namespace Robust.Server.Maps
{
[PublicAPI]
public sealed class MapLoadOptions
{
/// <summary>
/// If true, UID components will be created for loaded entities
/// to maintain consistency upon subsequent savings.
/// </summary>
public bool StoreMapUids { get; set; }
/// <summary>
/// Offset to apply to the loaded objects.
/// </summary>
public Vector2 Offset
{
get => _offset;
set
{
TransformMatrix = Matrix3Helpers.CreateTransform(value, Rotation);
_offset = value;
}
}
private Vector2 _offset = Vector2.Zero;
/// <summary>
/// Rotation to apply to the loaded objects as a collective, around 0, 0.
/// </summary>
/// <remarks>Setting this overrides </remarks>
public Angle Rotation
{
get => _rotation;
set
{
TransformMatrix = Matrix3Helpers.CreateTransform(Offset, value);
_rotation = value;
}
}
private Angle _rotation = Angle.Zero;
public Matrix3x2 TransformMatrix { get; set; } = Matrix3x2.Identity;
/// <summary>
/// If there is a map entity serialized should we also load it.
/// </summary>
/// <remarks>
/// This should be set to false if you want to load a map file onto an existing map and do not wish to overwrite the existing entity.
/// </remarks>
public bool LoadMap { get; set; } = true;
public bool DoMapInit = false;
}
}

View File

View File

@@ -67,6 +67,7 @@ namespace Robust.Server
deps.Register<IResourceManagerInternal, ResourceManager>();
deps.Register<EntityManager, ServerEntityManager>();
deps.Register<IServerEntityManager, ServerEntityManager>();
deps.Register<IServerEntityManagerInternal, ServerEntityManager>();
deps.Register<IServerGameStateManager, ServerGameStateManager>();
deps.Register<IReplayRecordingManager, ReplayRecordingManager>();
deps.Register<IReplayRecordingManagerInternal, ReplayRecordingManager>();

View File

@@ -50,9 +50,6 @@ public sealed class GamePrototypeLoadManager : SharedPrototypeLoadManager
internal void SendToNewUser(INetChannel channel)
{
if (LoadedPrototypes.Count == 0)
return;
// Just dump all the prototypes on connect, before them missing could be an issue.
var msg = new GamePrototypeLoadMessage
{

View File

@@ -39,6 +39,7 @@ namespace Robust.Shared.Maths
/// <param name="dir"></param>
public Angle(Vector2 dir)
{
dir = dir.Normalized();
Theta = Math.Atan2(dir.Y, dir.X);
}

View File

@@ -6,3 +6,4 @@
[assembly: InternalsVisibleTo("Robust.Client")]
[assembly: InternalsVisibleTo("Robust.UnitTesting")]
[assembly: InternalsVisibleTo("Content.Benchmarks")]

View File

@@ -1,90 +0,0 @@
using System;
using JetBrains.Annotations;
using Robust.Shared.Utility;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Prototypes;
namespace Robust.Shared.Audio;
/// <summary>
/// Represents a path to a sound resource, either as a literal path or as a collection ID and index.
/// </summary>
/// <seealso cref="ResolvedPathSpecifier"/>
/// <seealso cref="ResolvedCollectionSpecifier"/>
[Serializable, NetSerializable]
public abstract partial class ResolvedSoundSpecifier {
[Obsolete("String literals for sounds are deprecated, use a SoundSpecifier or ResolvedSoundSpecifier as appropriate instead")]
public static implicit operator ResolvedSoundSpecifier(string s) => new ResolvedPathSpecifier(s);
[Obsolete("String literals for sounds are deprecated, use a SoundSpecifier or ResolvedSoundSpecifier as appropriate instead")]
public static implicit operator ResolvedSoundSpecifier(ResPath s) => new ResolvedPathSpecifier(s);
/// <summary>
/// Returns whether <c>s</c> is null, or if it contains an empty path/collection ID.
/// </summary>
public static bool IsNullOrEmpty(ResolvedSoundSpecifier? s) {
return s switch {
null => true,
ResolvedPathSpecifier path => path.Path.ToString() == "",
ResolvedCollectionSpecifier collection => string.IsNullOrEmpty(collection.Collection),
_ => throw new ArgumentOutOfRangeException("s", s, "argument is not a ResolvedPathSpecifier or a ResolvedCollectionSpecifier"),
};
}
}
/// <summary>
/// Represents a path to a sound resource as a literal path.
/// </summary>
/// <seealso cref="ResolvedCollectionSpecifier"/>
[Serializable, NetSerializable]
public sealed partial class ResolvedPathSpecifier : ResolvedSoundSpecifier {
/// <summary>
/// The resource path of the sound.
/// </summary>
public ResPath Path { get; private set; }
override public string ToString() =>
$"ResolvedPathSpecifier({Path})";
[UsedImplicitly]
private ResolvedPathSpecifier()
{
}
public ResolvedPathSpecifier(ResPath path)
{
Path = path;
}
public ResolvedPathSpecifier(string path) : this(new ResPath(path))
{
}
}
/// <summary>
/// Represents a path to a sound resource as a collection ID and index.
/// </summary>
/// <seealso cref="ResolvedPathSpecifier"/>
[Serializable, NetSerializable]
public sealed partial class ResolvedCollectionSpecifier : ResolvedSoundSpecifier {
/// <summary>
/// The ID of the <see cref="SoundCollectionPrototype">sound collection</see> to look up.
/// </summary>
public ProtoId<SoundCollectionPrototype>? Collection { get; private set; }
/// <summary>
/// The index of the file in the associated sound collection to play.
/// </summary>
public int Index { get; private set; }
override public string ToString() =>
$"ResolvedCollectionSpecifier({Collection}, {Index})";
[UsedImplicitly]
private ResolvedCollectionSpecifier()
{
}
public ResolvedCollectionSpecifier(string collection, int index)
{
Collection = collection;
Index = index;
}
}

View File

@@ -27,9 +27,6 @@ public sealed partial class SoundPathSpecifier : SoundSpecifier
[DataField(Node, customTypeSerializer: typeof(ResPathSerializer), required: true)]
public ResPath Path { get; private set; }
override public string ToString() =>
$"SoundPathSpecifier({Path})";
[UsedImplicitly]
private SoundPathSpecifier()
{
@@ -55,9 +52,6 @@ public sealed partial class SoundCollectionSpecifier : SoundSpecifier
[DataField(Node, customTypeSerializer: typeof(PrototypeIdSerializer<SoundCollectionPrototype>), required: true)]
public string? Collection { get; private set; }
override public string ToString() =>
$"SoundCollectionSpecifier({Collection})";
[UsedImplicitly]
public SoundCollectionSpecifier() { }

View File

@@ -37,8 +37,6 @@ public abstract partial class SharedAudioSystem : EntitySystem
[Dependency] protected readonly MetaDataSystem MetadataSys = default!;
[Dependency] protected readonly SharedTransformSystem XformSystem = default!;
private const float AudioDespawnBuffer = 1f;
/// <summary>
/// Default max range at which the sound can be heard.
/// </summary>
@@ -236,7 +234,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
{
var timed = EnsureComp<TimedDespawnComponent>(entity.Value);
var audioLength = GetAudioLength(component.FileName);
timed.Lifetime = (float) audioLength.TotalSeconds + AudioDespawnBuffer;
timed.Lifetime = (float) audioLength.TotalSeconds + 0.01f;
}
break;
}
@@ -283,60 +281,33 @@ public abstract partial class SharedAudioSystem : EntitySystem
}
/// <summary>
/// Resolve a sound specifier so it can be consistently played back on all clients.
/// Resolves the filepath to a sound file.
/// </summary>
public ResolvedSoundSpecifier ResolveSound(SoundSpecifier specifier)
public string GetSound(SoundSpecifier specifier)
{
switch (specifier)
{
case SoundPathSpecifier path:
return new ResolvedPathSpecifier(path.Path == default ? string.Empty : path.Path.ToString());
return path.Path == default ? string.Empty : path.Path.ToString();
case SoundCollectionSpecifier collection:
{
if (collection.Collection == null)
return new ResolvedPathSpecifier(string.Empty);
return string.Empty;
var soundCollection = ProtoMan.Index<SoundCollectionPrototype>(collection.Collection);
var index = RandMan.Next(soundCollection.PickFiles.Count);
return new ResolvedCollectionSpecifier(collection.Collection, index);
return RandMan.Pick(soundCollection.PickFiles).ToString();
}
}
return new ResolvedPathSpecifier(string.Empty);
}
/// <summary>
/// Resolves the filepath to a sound file.
/// </summary>
[Obsolete("Use ResolveSound() and pass around resolved sound specifiers instead.")]
public string GetSound(SoundSpecifier specifier)
{
var resolved = ResolveSound(specifier);
return GetAudioPath(resolved);
return string.Empty;
}
#region AudioParams
[return: NotNullIfNotNull(nameof(specifier))]
public string? GetAudioPath(ResolvedSoundSpecifier? specifier)
{
return specifier switch {
ResolvedPathSpecifier path =>
path.Path.ToString(),
ResolvedCollectionSpecifier collection =>
collection.Collection is null ?
string.Empty :
ProtoMan.Index<SoundCollectionPrototype>(collection.Collection).PickFiles[collection.Index].ToString(),
null => null,
_ => throw new ArgumentOutOfRangeException("specifier", specifier, "argument is not a ResolvedPathSpecifier or a ResolvedCollectionSpecifier"),
};
}
protected Entity<AudioComponent> SetupAudio(ResolvedSoundSpecifier? specifier, AudioParams? audioParams, bool initialize = true, TimeSpan? length = null)
protected Entity<AudioComponent> SetupAudio(string? fileName, AudioParams? audioParams, bool initialize = true, TimeSpan? length = null)
{
var uid = EntityManager.CreateEntityUninitialized("Audio", MapCoordinates.Nullspace);
var fileName = GetAudioPath(specifier);
DebugTools.Assert(!string.IsNullOrEmpty(fileName) || length is not null);
MetadataSys.SetEntityName(uid, $"Audio ({fileName})", raiseEvents: false);
audioParams ??= AudioParams.Default;
@@ -351,7 +322,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
var despawn = AddComp<TimedDespawnComponent>(uid);
// Don't want to clip audio too short due to imprecision.
despawn.Lifetime = (float) length.Value.TotalSeconds + AudioDespawnBuffer;
despawn.Lifetime = (float) length.Value.TotalSeconds + 0.01f;
}
if (comp.Params.Variation != null && comp.Params.Variation.Value != 0f)
@@ -422,9 +393,8 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <summary>
/// Gets the timespan of the specified audio.
/// </summary>
public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
public TimeSpan GetAudioLength(string filename)
{
var filename = GetAudioPath(specifier) ?? string.Empty;
if (!filename.StartsWith("/"))
throw new ArgumentException("Path must be rooted");
@@ -457,7 +427,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// </summary>
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
/// <param name="playerFilter">The set of players that will hear the sound.</param>
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(ResolvedSoundSpecifier? filename, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null);
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string? filename, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null);
/// <summary>
/// Play an audio file globally, without position.
@@ -466,7 +436,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <param name="playerFilter">The set of players that will hear the sound.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(SoundSpecifier? sound, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null)
{
return sound == null ? null : PlayGlobal(ResolveSound(sound), playerFilter, recordReplay, audioParams ?? sound.Params);
return sound == null ? null : PlayGlobal(GetSound(sound), playerFilter, recordReplay, audioParams ?? sound.Params);
}
/// <summary>
@@ -474,7 +444,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// </summary>
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
/// <param name="recipient">The player that will hear the sound.</param>
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(ResolvedSoundSpecifier? filename, ICommonSession recipient, AudioParams? audioParams = null);
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string? filename, ICommonSession recipient, AudioParams? audioParams = null);
/// <summary>
/// Play an audio file globally, without position.
@@ -483,7 +453,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <param name="recipient">The player that will hear the sound.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(SoundSpecifier? sound, ICommonSession recipient, AudioParams? audioParams = null)
{
return sound == null ? null : PlayGlobal(ResolveSound(sound), recipient, audioParams ?? sound.Params);
return sound == null ? null : PlayGlobal(GetSound(sound), recipient, audioParams ?? sound.Params);
}
public abstract void LoadStream<T>(Entity<AudioComponent> entity, T stream);
@@ -493,7 +463,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// </summary>
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
/// <param name="recipient">The player that will hear the sound.</param>
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(ResolvedSoundSpecifier? filename, EntityUid recipient, AudioParams? audioParams = null);
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string? filename, EntityUid recipient, AudioParams? audioParams = null);
/// <summary>
/// Play an audio file globally, without position.
@@ -502,7 +472,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <param name="recipient">The player that will hear the sound.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(SoundSpecifier? sound, EntityUid recipient, AudioParams? audioParams = null)
{
return sound == null ? null : PlayGlobal(ResolveSound(sound), recipient, audioParams ?? sound.Params);
return sound == null ? null : PlayGlobal(GetSound(sound), recipient, audioParams ?? sound.Params);
}
/// <summary>
@@ -511,7 +481,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
/// <param name="playerFilter">The set of players that will hear the sound.</param>
/// <param name="uid">The UID of the entity "emitting" the audio.</param>
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(ResolvedSoundSpecifier? filename, Filter playerFilter, EntityUid uid, bool recordReplay, AudioParams? audioParams = null);
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string? filename, Filter playerFilter, EntityUid uid, bool recordReplay, AudioParams? audioParams = null);
/// <summary>
/// Play an audio file following an entity.
@@ -519,7 +489,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
/// <param name="recipient">The player that will hear the sound.</param>
/// <param name="uid">The UID of the entity "emitting" the audio.</param>
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(ResolvedSoundSpecifier? filename, ICommonSession recipient, EntityUid uid, AudioParams? audioParams = null);
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string? filename, ICommonSession recipient, EntityUid uid, AudioParams? audioParams = null);
/// <summary>
/// Play an audio file following an entity.
@@ -527,7 +497,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
/// <param name="recipient">The player that will hear the sound.</param>
/// <param name="uid">The UID of the entity "emitting" the audio.</param>
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(ResolvedSoundSpecifier? filename, EntityUid recipient, EntityUid uid, AudioParams? audioParams = null);
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string? filename, EntityUid recipient, EntityUid uid, AudioParams? audioParams = null);
/// <summary>
/// Play an audio file following an entity.
@@ -537,7 +507,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <param name="uid">The UID of the entity "emitting" the audio.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(SoundSpecifier? sound, Filter playerFilter, EntityUid uid, bool recordReplay, AudioParams? audioParams = null)
{
return sound == null ? null : PlayEntity(ResolveSound(sound), playerFilter, uid, recordReplay, audioParams ?? sound.Params);
return sound == null ? null : PlayEntity(GetSound(sound), playerFilter, uid, recordReplay, audioParams ?? sound.Params);
}
/// <summary>
@@ -548,7 +518,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <param name="uid">The UID of the entity "emitting" the audio.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(SoundSpecifier? sound, ICommonSession recipient, EntityUid uid, AudioParams? audioParams = null)
{
return sound == null ? null : PlayEntity(ResolveSound(sound), recipient, uid, audioParams ?? sound.Params);
return sound == null ? null : PlayEntity(GetSound(sound), recipient, uid, audioParams ?? sound.Params);
}
/// <summary>
@@ -559,7 +529,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <param name="uid">The UID of the entity "emitting" the audio.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(SoundSpecifier? sound, EntityUid recipient, EntityUid uid, AudioParams? audioParams = null)
{
return sound == null ? null : PlayEntity(ResolveSound(sound), recipient, uid, audioParams ?? sound.Params);
return sound == null ? null : PlayEntity(GetSound(sound), recipient, uid, audioParams ?? sound.Params);
}
/// <summary>
@@ -569,7 +539,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <param name="uid">The UID of the entity "emitting" the audio.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(SoundSpecifier? sound, EntityUid uid, AudioParams? audioParams = null)
{
return sound == null ? null : PlayPvs(ResolveSound(sound), uid, audioParams ?? sound.Params);
return sound == null ? null : PlayPvs(GetSound(sound), uid, audioParams ?? sound.Params);
}
/// <summary>
@@ -579,7 +549,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <param name="coordinates">The EntityCoordinates to attach the audio source to.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(SoundSpecifier? sound, EntityCoordinates coordinates, AudioParams? audioParams = null)
{
return sound == null ? null : PlayPvs(ResolveSound(sound), coordinates, audioParams ?? sound.Params);
return sound == null ? null : PlayPvs(GetSound(sound), coordinates, audioParams ?? sound.Params);
}
/// <summary>
@@ -587,7 +557,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// </summary>
/// <param name="sound">The sound specifier that points the audio file(s) that should be played.</param>
/// <param name="coordinates">The EntityCoordinates to attach the audio source to.</param>
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(ResolvedSoundSpecifier? filename,
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(string? filename,
EntityCoordinates coordinates, AudioParams? audioParams = null);
/// <summary>
@@ -595,7 +565,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// </summary>
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
/// <param name="uid">The UID of the entity "emitting" the audio.</param>
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(ResolvedSoundSpecifier? filename, EntityUid uid,
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(string? filename, EntityUid uid,
AudioParams? audioParams = null);
/// <summary>
@@ -632,7 +602,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
/// <param name="playerFilter">The set of players that will hear the sound.</param>
/// <param name="coordinates">The coordinates at which to play the audio.</param>
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(ResolvedSoundSpecifier? filename, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null);
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string? filename, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null);
/// <summary>
/// Play an audio file at a static position.
@@ -640,7 +610,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
/// <param name="recipient">The player that will hear the sound.</param>
/// <param name="coordinates">The coordinates at which to play the audio.</param>
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(ResolvedSoundSpecifier? filename, ICommonSession recipient, EntityCoordinates coordinates, AudioParams? audioParams = null);
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string? filename, ICommonSession recipient, EntityCoordinates coordinates, AudioParams? audioParams = null);
/// <summary>
/// Play an audio file at a static position.
@@ -648,7 +618,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
/// <param name="recipient">The player that will hear the sound.</param>
/// <param name="coordinates">The coordinates at which to play the audio.</param>
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(ResolvedSoundSpecifier? filename, EntityUid recipient, EntityCoordinates coordinates, AudioParams? audioParams = null);
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string? filename, EntityUid recipient, EntityCoordinates coordinates, AudioParams? audioParams = null);
/// <summary>
/// Play an audio file at a static position.
@@ -658,7 +628,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <param name="coordinates">The coordinates at which to play the audio.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(SoundSpecifier? sound, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null)
{
return sound == null ? null : PlayStatic(ResolveSound(sound), playerFilter, coordinates, recordReplay, audioParams);
return sound == null ? null : PlayStatic(GetSound(sound), playerFilter, coordinates, recordReplay, audioParams);
}
/// <summary>
@@ -669,7 +639,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <param name="coordinates">The coordinates at which to play the audio.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(SoundSpecifier? sound, ICommonSession recipient, EntityCoordinates coordinates, AudioParams? audioParams = null)
{
return sound == null ? null : PlayStatic(ResolveSound(sound), recipient, coordinates, audioParams ?? sound.Params);
return sound == null ? null : PlayStatic(GetSound(sound), recipient, coordinates, audioParams ?? sound.Params);
}
/// <summary>
@@ -680,7 +650,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
/// <param name="coordinates">The coordinates at which to play the audio.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(SoundSpecifier? sound, EntityUid recipient, EntityCoordinates coordinates, AudioParams? audioParams = null)
{
return sound == null ? null : PlayStatic(ResolveSound(sound), recipient, coordinates, audioParams ?? sound.Params);
return sound == null ? null : PlayStatic(GetSound(sound), recipient, coordinates, audioParams ?? sound.Params);
}
// These are just here for replays now.
@@ -693,7 +663,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
[NetSerializable, Serializable]
protected abstract class AudioMessage : EntityEventArgs
{
public ResolvedSoundSpecifier Specifier = new ResolvedPathSpecifier(string.Empty);
public string FileName = string.Empty;
public AudioParams AudioParams;
}

View File

@@ -1349,10 +1349,10 @@ namespace Robust.Shared
/// MaxLinVelocity is compared to the dot product of linearVelocity * frameTime.
/// </summary>
/// <remarks>
/// Default is 400 m/s in-line with Box2c. Box2d used 120m/s.
/// Default is 35 m/s. Around half a tile per tick at 60 ticks per second.
/// </remarks>
public static readonly CVarDef<float> MaxLinVelocity =
CVarDef.Create("physics.maxlinvelocity", 400f, CVar.SERVER | CVar.REPLICATED);
CVarDef.Create("physics.maxlinvelocity", 35f, CVar.SERVER | CVar.REPLICATED);
/// <summary>
/// Maximum angular velocity in full rotations per second.
@@ -1364,6 +1364,7 @@ namespace Robust.Shared
public static readonly CVarDef<float> MaxAngVelocity =
CVarDef.Create("physics.maxangvelocity", 15f);
/*
* User interface
*/

View File

@@ -59,7 +59,7 @@ public abstract class ComponentTreeSystem<TTreeComp, TComp> : EntitySystem
UpdatesAfter.Add(typeof(SharedTransformSystem));
UpdatesAfter.Add(typeof(SharedPhysicsSystem));
SubscribeLocalEvent<MapCreatedEvent>(MapManagerOnMapCreated);
SubscribeLocalEvent<MapChangedEvent>(MapManagerOnMapCreated);
SubscribeLocalEvent<GridInitializeEvent>(MapManagerOnGridCreated);
SubscribeLocalEvent<TComp, ComponentStartup>(OnCompStartup);
@@ -143,8 +143,11 @@ public abstract class ComponentTreeSystem<TTreeComp, TComp> : EntitySystem
RemComp(uid, component);
}
private void MapManagerOnMapCreated(MapCreatedEvent e)
private void MapManagerOnMapCreated(MapChangedEvent e)
{
if (e.Destroyed || e.Map == MapId.Nullspace)
return;
EnsureComp<TTreeComp>(e.Uid);
}

View File

@@ -8,58 +8,6 @@ using Robust.Shared.Utility;
namespace Robust.Shared.Configuration
{
public static class CVarCommandUtil
{
/// <summary>
/// Parses a string into an object of the given type.
/// </summary>
/// <exception cref="FormatException">Thrown if the string could not be parsed into the given type.</exception>
/// <exception cref="NotSupportedException">Thrown if the type is not supported.</exception>
public static object ParseObject(Type type, string input)
{
if (type == typeof(bool))
{
if (bool.TryParse(input, out var val))
return val;
if (Parse.TryInt32(input, out var intVal))
{
if (intVal == 0) return false;
if (intVal == 1) return true;
}
throw new FormatException($"Could not parse bool value: {input}");
}
if (type == typeof(string))
{
return input;
}
if (type == typeof(int))
{
return Parse.Int32(input);
}
if (type == typeof(float))
{
return Parse.Float(input);
}
if (type == typeof(long))
{
return long.Parse(input);
}
if (type == typeof(ushort))
{
return ushort.Parse(input);
}
throw new NotSupportedException();
}
}
[SuppressMessage("ReSharper", "StringLiteralTypo")]
internal sealed class CVarCommand : LocalizedCommands
{
@@ -103,7 +51,7 @@ namespace Robust.Shared.Configuration
var type = _cfg.GetCVarType(name);
try
{
var parsed = CVarCommandUtil.ParseObject(type, value);
var parsed = ParseObject(type, value);
_cfg.SetCVar(name, parsed);
}
catch (FormatException)
@@ -147,6 +95,50 @@ namespace Robust.Shared.Configuration
return value;
}
private static object ParseObject(Type type, string input)
{
if (type == typeof(bool))
{
if (bool.TryParse(input, out var val))
return val;
if (Parse.TryInt32(input, out var intVal))
{
if (intVal == 0) return false;
if (intVal == 1) return true;
}
throw new FormatException($"Could not parse bool value: {input}");
}
if (type == typeof(string))
{
return input;
}
if (type == typeof(int))
{
return Parse.Int32(input);
}
if (type == typeof(float))
{
return Parse.Float(input);
}
if (type == typeof(long))
{
return long.Parse(input);
}
if (type == typeof(ushort))
{
return ushort.Parse(input);
}
throw new NotSupportedException();
}
}
internal sealed class CVarSubsCommand : LocalizedCommands

View File

@@ -138,7 +138,7 @@ internal sealed class ListMapsCommand : LocalizedEntityCommands
{
var msg = new StringBuilder();
foreach (var mapId in _mapSystem.GetAllMapIds().OrderBy(id => id.Value))
foreach (var mapId in _map.GetAllMapIds().OrderBy(id => id.Value))
{
if (!_mapSystem.TryGetMap(mapId, out var mapUid))
continue;

View File

@@ -197,10 +197,6 @@ public abstract partial class SharedContainerSystem
{
if (entity.Comp2 is { } physics)
{
// TODO CONTAINER
// Is this actually needed?
// I.e., shouldn't this just do a if (_timing.ApplyingState) return
// Here we intentionally don't dirty the physics comp. Client-side state handling will apply these same
// changes. This also ensures that the server doesn't have to send the physics comp state to every
// player for any entity inside of a container during init.

View File

@@ -88,7 +88,6 @@ namespace Robust.Shared.ContentPack
public string SystemAssemblyName = default!;
public HashSet<VerifierError> AllowedVerifierErrors = default!;
public List<string> WhitelistedNamespaces = default!;
public List<string> AllowedAssemblyPrefixes = default!;
public Dictionary<string, Dictionary<string, TypeConfig>> Types = default!;
}

View File

@@ -131,16 +131,6 @@ namespace Robust.Shared.ContentPack
return false;
}
#pragma warning disable RA0004
var loadedConfig = _config.Result;
#pragma warning restore RA0004
if (!loadedConfig.AllowedAssemblyPrefixes.Any(allowedNamePrefix => asmName.StartsWith(allowedNamePrefix)))
{
_sawmill.Error($"Assembly name '{asmName}' is not allowed for a content assembly");
return false;
}
if (VerifyIL)
{
if (!DoVerifyIL(asmName, resolver, peReader, reader))
@@ -189,6 +179,10 @@ namespace Robust.Shared.ContentPack
return true;
}
#pragma warning disable RA0004
var loadedConfig = _config.Result;
#pragma warning restore RA0004
var badRefs = new ConcurrentBag<EntityHandle>();
// We still do explicit type reference scanning, even though the actual whitelists work with raw members.

View File

@@ -60,7 +60,7 @@ namespace Robust.Shared.ContentPack
internal string GetPath(ResPath relPath)
{
return PathHelpers.SafeGetResourcePath(_directory.FullName, relPath);
return Path.GetFullPath(Path.Combine(_directory.FullName, relPath.ToRelativeSystemPath()));
}
/// <inheritdoc />

View File

@@ -14,11 +14,7 @@ namespace Robust.Shared.ContentPack
/// The directory to use for user data.
/// If null, a virtual temporary file system is used instead.
/// </param>
/// <param name="hideUserDataDir">
/// If true, <see cref="IWritableDirProvider.RootDir"/> will be hidden on
/// <see cref="IResourceManager.UserData"/>.
/// </param>
void Initialize(string? userData, bool hideUserDataDir);
void Initialize(string? userData);
/// <summary>
/// Mounts a single stream as a content file. Useful for unit testing.

View File

@@ -13,7 +13,7 @@ namespace Robust.Shared.ContentPack
{
/// <summary>
/// The root path of this provider.
/// Can be null if it's a virtual provider or the path is protected (e.g. on the client).
/// Can be null if it's a virtual provider.
/// </summary>
string? RootDir { get; }

View File

@@ -93,23 +93,19 @@ namespace Robust.Shared.ContentPack
{
var sw = Stopwatch.StartNew();
Sawmill.Debug("LOADING modules");
var files = new Dictionary<string, (ResPath Path, MemoryStream data, string[] references)>();
var files = new Dictionary<string, (ResPath Path, string[] references)>();
// Find all modules we want to load.
foreach (var fullPath in paths)
{
using var asmFile = _res.ContentFileRead(fullPath);
var ms = new MemoryStream();
asmFile.CopyTo(ms);
ms.Position = 0;
var refData = GetAssemblyReferenceData(ms);
var refData = GetAssemblyReferenceData(asmFile);
if (refData == null)
continue;
var (asmRefs, asmName) = refData.Value;
if (!files.TryAdd(asmName, (fullPath, ms, asmRefs)))
if (!files.TryAdd(asmName, (fullPath, asmRefs)))
{
Sawmill.Error("Found multiple modules with the same assembly name " +
$"'{asmName}', A: {files[asmName].Path}, B: {fullPath}.");
@@ -126,10 +122,10 @@ namespace Robust.Shared.ContentPack
Parallel.ForEach(files, pair =>
{
var (name, (_, data, _)) = pair;
var (name, (path, _)) = pair;
data.Position = 0;
if (!typeChecker.CheckAssembly(data, resolver))
using var stream = _res.ContentFileRead(path);
if (!typeChecker.CheckAssembly(stream, resolver))
{
throw new TypeCheckFailedException($"Assembly {name} failed type checks.");
}
@@ -141,15 +137,14 @@ namespace Robust.Shared.ContentPack
var nodes = TopologicalSort.FromBeforeAfter(
files,
kv => kv.Key,
kv => kv.Value,
kv => kv.Value.Path,
_ => Array.Empty<string>(),
kv => kv.Value.references,
allowMissing: true); // missing refs would be non-content assemblies so allow that.
// Actually load them in the order they depend on each other.
foreach (var item in TopologicalSort.Sort(nodes))
foreach (var path in TopologicalSort.Sort(nodes))
{
var (path, memory, _) = item;
Sawmill.Debug($"Loading module: '{path}'");
try
{
@@ -161,9 +156,9 @@ namespace Robust.Shared.ContentPack
}
else
{
memory.Position = 0;
using var assemblyStream = _res.ContentFileRead(path);
using var symbolsStream = _res.ContentFileReadOrNull(path.WithExtension("pdb"));
LoadGameAssembly(memory, symbolsStream, skipVerify: true);
LoadGameAssembly(assemblyStream, symbolsStream, skipVerify: true);
}
}
catch (Exception e)
@@ -179,7 +174,7 @@ namespace Robust.Shared.ContentPack
private (string[] refs, string name)? GetAssemblyReferenceData(Stream stream)
{
using var reader = ModLoader.MakePEReader(stream, leaveOpen: true);
using var reader = ModLoader.MakePEReader(stream);
var metaReader = reader.GetMetadataReader();
var name = metaReader.GetString(metaReader.GetAssemblyDefinition().Name);

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using Robust.Shared.Utility;
namespace Robust.Shared.ContentPack
{
@@ -64,27 +63,5 @@ namespace Robust.Shared.ContentPack
!OperatingSystem.IsWindows()
&& !OperatingSystem.IsMacOS();
internal static string SafeGetResourcePath(string baseDir, ResPath path)
{
var relSysPath = path.ToRelativeSystemPath();
if (relSysPath.Contains("\\..") || relSysPath.Contains("/.."))
{
// Hard cap on any exploit smuggling a .. in there.
// Since that could allow leaving sandbox.
throw new InvalidOperationException($"This branch should never be reached. Path: {path}");
}
var retPath = Path.GetFullPath(Path.Join(baseDir, relSysPath));
// better safe than sorry check
if (!retPath.StartsWith(baseDir))
{
// Allow path to match if it's just missing the directory separator at the end.
if (retPath != baseDir.TrimEnd(Path.DirectorySeparatorChar))
throw new InvalidOperationException($"This branch should never be reached. Path: {path}");
}
return retPath;
}
}
}

View File

@@ -41,13 +41,13 @@ namespace Robust.Shared.ContentPack
public IWritableDirProvider UserData { get; private set; } = default!;
/// <inheritdoc />
public virtual void Initialize(string? userData, bool hideRootDir)
public virtual void Initialize(string? userData)
{
Sawmill = _logManager.GetSawmill("res");
if (userData != null)
{
UserData = new WritableDirProvider(Directory.CreateDirectory(userData), hideRootDir);
UserData = new WritableDirProvider(Directory.CreateDirectory(userData));
}
else
{
@@ -379,13 +379,7 @@ namespace Robust.Shared.ContentPack
{
if (root is DirLoader loader)
{
var rootDir = loader.GetPath(new ResPath(@"/"));
// TODO: GET RID OF THIS.
// This code shouldn't be passing OS disk paths through ResPath.
rootDir = rootDir.Replace(Path.DirectorySeparatorChar, '/');
yield return new ResPath(rootDir);
yield return new ResPath(loader.GetPath(new ResPath(@"/")));
}
}
}

View File

@@ -17,10 +17,6 @@ WhitelistedNamespaces:
- Content
- OpenDreamShared
AllowedAssemblyPrefixes:
- OpenDream
- Content
# The type whitelist does NOT care about which assembly types come from.
# This is because types switch assembly all the time.
# Just look up stuff like StreamReader on https://apisof.net.
@@ -700,7 +696,7 @@ Types:
- "bool IsMatch(string, string, System.Text.RegularExpressions.RegexOptions, System.TimeSpan)"
- "int GroupNumberFromName(string)"
- "int[] GetGroupNumbers()"
- "string Escape(string)"
- "string Escape()"
- "string GroupNameFromNumber(int)"
- "string Replace(string, string)"
- "string Replace(string, string, int)"

View File

@@ -10,22 +10,17 @@ namespace Robust.Shared.ContentPack
/// <inheritdoc />
internal sealed class WritableDirProvider : IWritableDirProvider
{
private readonly bool _hideRootDir;
/// <inheritdoc />
public string RootDir { get; }
string? IWritableDirProvider.RootDir => _hideRootDir ? null : RootDir;
/// <summary>
/// Constructs an instance of <see cref="WritableDirProvider"/>.
/// </summary>
/// <param name="rootDir">Root file system directory to allow writing.</param>
/// <param name="hideRootDir">If true, <see cref="IWritableDirProvider.RootDir"/> is reported as null.</param>
public WritableDirProvider(DirectoryInfo rootDir, bool hideRootDir)
public WritableDirProvider(DirectoryInfo rootDir)
{
// FullName does not have a trailing separator, and we MUST have a separator.
RootDir = rootDir.FullName + Path.DirectorySeparatorChar.ToString();
_hideRootDir = hideRootDir;
}
#region File Access
@@ -124,7 +119,7 @@ namespace Robust.Shared.ContentPack
throw new FileNotFoundException();
var dirInfo = new DirectoryInfo(GetFullPath(path));
return new WritableDirProvider(dirInfo, _hideRootDir);
return new WritableDirProvider(dirInfo);
}
/// <inheritdoc />
@@ -185,7 +180,20 @@ namespace Robust.Shared.ContentPack
path = path.Clean();
return PathHelpers.SafeGetResourcePath(RootDir, path);
return GetFullPath(RootDir, path);
}
private static string GetFullPath(string root, ResPath path)
{
var relPath = path.ToRelativeSystemPath();
if (relPath.Contains("\\..") || relPath.Contains("/.."))
{
// Hard cap on any exploit smuggling a .. in there.
// Since that could allow leaving sandbox.
throw new InvalidOperationException($"This branch should never be reached. Path: {path}");
}
return Path.GetFullPath(Path.Combine(root, relPath));
}
}
}

View File

@@ -1,12 +0,0 @@
using Robust.Shared.EntitySerialization.Systems;
using Robust.Shared.GameObjects;
namespace Robust.Shared.EntitySerialization.Components;
/// <summary>
/// Added to Maps that were loaded by <see cref="MapLoaderSystem"/>. If not present then this map was created externally.
/// </summary>
[RegisterComponent, UnsavedComponent]
public sealed partial class LoadedMapComponent : Component
{
}

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