mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 11:40:52 +01:00
Compare commits
65 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99c5b0ad08 | ||
|
|
9e2ab2a917 | ||
|
|
36eb857b55 | ||
|
|
92d7f2723a | ||
|
|
91d3f67a94 | ||
|
|
b28b5ed09b | ||
|
|
30eed7957f | ||
|
|
73c1449811 | ||
|
|
958b5dd06d | ||
|
|
4002cbddb9 | ||
|
|
c38a14e78f | ||
|
|
5164d99996 | ||
|
|
c79217ab66 | ||
|
|
9ef7f7cb37 | ||
|
|
02ac314b1a | ||
|
|
8607ba1f16 | ||
|
|
2a9de462d5 | ||
|
|
c59ef5ab2d | ||
|
|
eba1d866fb | ||
|
|
ab2bff8f40 | ||
|
|
536fca4115 | ||
|
|
7a0d02463c | ||
|
|
6df53d60ed | ||
|
|
ff38e9f12a | ||
|
|
00c58c76a8 | ||
|
|
0bf99e173c | ||
|
|
eee771c5f1 | ||
|
|
2946cd866c | ||
|
|
9a2a3d658d | ||
|
|
d933f03a54 | ||
|
|
25bbb21dc8 | ||
|
|
4460454563 | ||
|
|
a2d8fa7a9b | ||
|
|
71f0491f10 | ||
|
|
b4c1618338 | ||
|
|
df0945f3cd | ||
|
|
8d477716b0 | ||
|
|
5c1a5e9826 | ||
|
|
6daa3ad2fc | ||
|
|
033a617102 | ||
|
|
b9b565d53e | ||
|
|
b7ea4d0cca | ||
|
|
919ec01477 | ||
|
|
e484eac29c | ||
|
|
eedadb250f | ||
|
|
3097784cd7 | ||
|
|
0fb41e06c8 | ||
|
|
0a79382a62 | ||
|
|
1f2b38a6d1 | ||
|
|
f760929527 | ||
|
|
f5ade69f6d | ||
|
|
9bfe889c86 | ||
|
|
e3954494e7 | ||
|
|
6697e36e84 | ||
|
|
dae4041e61 | ||
|
|
390f399750 | ||
|
|
28cf7442ce | ||
|
|
d8b03be651 | ||
|
|
16c7c71ca6 | ||
|
|
0245c371ae | ||
|
|
c8cb13f832 | ||
|
|
86ecfaa56b | ||
|
|
43a32e7015 | ||
|
|
83371885fa | ||
|
|
e686e1b4cc |
Submodule Lidgren.Network/Lidgren.Network updated: 45f89ca263...61a56c60bd
@@ -1,4 +1,4 @@
|
||||
<Project>
|
||||
|
||||
<!-- This file automatically reset by Tools/version.py -->
|
||||
<!-- This file automatically reset by Tools/version.py -->
|
||||
|
||||
|
||||
149
RELEASE-NOTES.md
149
RELEASE-NOTES.md
@@ -1,4 +1,4 @@
|
||||
# Release notes for RobustToolbox.
|
||||
# Release notes for RobustToolbox.
|
||||
|
||||
<!--
|
||||
NOTE: automatically updated sometimes by version.py.
|
||||
@@ -54,6 +54,153 @@ END TEMPLATE-->
|
||||
*None yet*
|
||||
|
||||
|
||||
## 217.2.0
|
||||
|
||||
### New features
|
||||
|
||||
* Added `AddComponents` and `RemoveComponents` methods to EntityManager that handle EntityPrototype / ComponentRegistry bulk component changes.
|
||||
* Add double-clicking to LineEdit.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Properly ignore non-hard fixtures for IntersectRayWithPredicate.
|
||||
* Fix nullable TimeSpan addition on some platforms.
|
||||
|
||||
|
||||
## 217.1.0
|
||||
|
||||
### New features
|
||||
|
||||
* Added `IRobustRandom.GetItems` extension methods for randomly picking multiple items from a collections.
|
||||
* Added `SharedPhysicsSystem.EffectiveCurTime`. This is effectively a variation of `IGameTiming.CurTime` that takes into account the current physics sub-step.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fix `MapComponent.LightingEnabled` not leaving FOV rendering in a broken state.
|
||||
|
||||
### Internal
|
||||
|
||||
* `Shuffle<T>(Span<T>, System.Random)` has been removed, just use the builtin method.
|
||||
|
||||
|
||||
## 217.0.0
|
||||
|
||||
### Breaking changes
|
||||
|
||||
* TransformSystem.SetWorldPosition and SetWorldPositionRotation will now also perform parent updates as necessary. Previously it would just set the entity's LocalPosition which may break if they were inside of a container. Now they will be removed from their container and TryFindGridAt will run to correctly parent them to the new position. If the old functionality is desired then you can use GetInvWorldMatrix to update the LocalPosition (bearing in mind containers may prevent this).
|
||||
|
||||
### New features
|
||||
|
||||
* Implement VV for AudioParams on SoundSpecifiers.
|
||||
* Add AddUi to the shared UI system.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fix the first measure of ScrollContainer bars.
|
||||
|
||||
|
||||
## 216.0.0
|
||||
|
||||
### Breaking changes
|
||||
|
||||
* The `net.low_lod_distance` cvar has been replaced with a new `net.pvs_priority_range`. Instead of limiting the range at which all entities are sent to a player, it now extends the range at which high priorities can be sent. The default value of this new cvar is 32.5, which is larger than the default `net.pvs_range` value of 25.
|
||||
|
||||
### New features
|
||||
|
||||
* You can now specify a component to not be saved to map files with `[UnsavedComponent]`.
|
||||
* Added `ITileDefinitionManager.TryGetDefinition`.
|
||||
* The map loader now tries to preserve the `tilemap` contents of map files, which should reduce diffs when re-saving a map after the game's internal tile IDs have changed.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fix buffered audio sources not being disposed.
|
||||
|
||||
|
||||
## 215.3.1
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Revert zstd update.
|
||||
|
||||
|
||||
## 215.3.0
|
||||
|
||||
### New features
|
||||
|
||||
* `EntityQuery<T>` now has `HasComp` and `TryComp` methods that are shorter than its existing ones.
|
||||
* Added `PlacementInformation.UseEditorContext`.
|
||||
* Added `Vector2Helpers` functions for comparing ranges between vectors.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* `Texture.GetPixel()`: fixed off-by-one with Y coordinate.
|
||||
* `Texture.GetPixel()`: fix stack overflow when reading large images.
|
||||
* `Texture.GetPixel()`: use more widely compatible OpenGL calls.
|
||||
|
||||
### Other
|
||||
|
||||
* Disabled `net.mtu_expand` again by default, as it was causing issues.
|
||||
* Updated `SharpZstd` dependency.
|
||||
|
||||
|
||||
## 215.2.0
|
||||
|
||||
### New features
|
||||
|
||||
* Implement basic VV for SoundSpecifiers.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fix QueueDel during EndCollideEvents from throwing while removing contacts.
|
||||
|
||||
|
||||
## 215.1.0
|
||||
|
||||
### New features
|
||||
|
||||
* Add a CompletionHelper for audio filepaths that handles server packaging.
|
||||
* Add Random.NextAngle(min, max) method and Pick for `ValueList<T>`.
|
||||
* Added an `ICommonSession` parser for toolshed commands.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
|
||||
## 215.0.0
|
||||
|
||||
### Breaking changes
|
||||
|
||||
* Update Lidgren to 0.3.0
|
||||
|
||||
### New features
|
||||
|
||||
* Made a new `IMetricsManager` interface with an `UpdateMetrics` event that can be used to update Prometheus metrics whenever they are scraped.
|
||||
* Also added a `metrics.update_interval` CVar to go along with this, when metrics are scraped without usage of Prometheus directly.
|
||||
* IoC now contains an `IMeterFactory` implementation that you can use to instantiate metric meters.
|
||||
* `net.mtu_ipv6` CVar allows specifying a different MTU value for IPv6.
|
||||
* Allows `player:entity` to take a parameter representing the player name.
|
||||
* Add collection parsing to the dev window for UI.
|
||||
* Add a debug assert to Dirty(uid, comp) to catch mismatches being passed in.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Support transform states with unknown parents.
|
||||
* Fix serialization error logging.
|
||||
* Fix naming of ResizableMemoryRegion metrics.
|
||||
* Fix uncaught overflow exception when parsing NetEntities.
|
||||
|
||||
### Other
|
||||
|
||||
* The replay system now allows loading a replay with a mismatching serializer type hash. This means replays should be more robust against future version updates (engine security patches or .NET updates).
|
||||
* `CheckBox`'s interior texture is now vertically centered.
|
||||
* Lidgren.Network has been updated to [`v0.3.0`](https://github.com/space-wizards/SpaceWizards.Lidgren.Network/blob/v0.3.0/RELEASE-NOTES.md).
|
||||
* Lowered default IPv4 MTU to 900 (from 1000).
|
||||
* Automatic MTU expansion (`net.mtu_expand`) is now enabled by default.
|
||||
|
||||
### Internal
|
||||
|
||||
* Cleanup some Dirty component calls internally.
|
||||
|
||||
|
||||
## 214.2.0
|
||||
|
||||
### New features
|
||||
|
||||
@@ -11,6 +11,7 @@ cmd-parse-failure-uid = {$arg} is not a valid entity UID.
|
||||
cmd-parse-failure-mapid = {$arg} is not a valid MapId.
|
||||
cmd-parse-failure-grid = {$arg} is not a valid grid.
|
||||
cmd-parse-failure-entity-exist = UID {$arg} does not correspond to an existing entity.
|
||||
cmd-parse-failure-session = There is no session with username: {$username}
|
||||
|
||||
cmd-error-file-not-found = Could not find file: {$file}.
|
||||
cmd-error-dir-not-found = Could not find directory: {$dir}.
|
||||
|
||||
@@ -10,3 +10,18 @@ view-variable-instance-entity-client-components-search-bar-placeholder = Search
|
||||
view-variable-instance-entity-server-components-search-bar-placeholder = Search
|
||||
view-variable-instance-entity-add-window-server-components = Add Component [S]
|
||||
view-variable-instance-entity-add-window-client-components = Add Component [C]
|
||||
|
||||
|
||||
## SoundSpecifier
|
||||
vv-sound-none = None
|
||||
vv-sound-path = Path
|
||||
vv-sound-collection = Collection
|
||||
|
||||
vv-sound-volume = volume
|
||||
vv-sound-pitch = Pitch
|
||||
vv-sound-max-distance = Max Distance
|
||||
vv-sound-rolloff-factor = Rolloff Factor
|
||||
vv-sound-reference-distance = Reference Distance
|
||||
vv-sound-loop = Loop
|
||||
vv-sound-play-offset = Play Offset (s)
|
||||
vv-sound-variation = Pitch variation
|
||||
|
||||
@@ -173,7 +173,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
private void SetupSource(Entity<AudioComponent> entity, AudioResource audioResource, TimeSpan? length = null)
|
||||
{
|
||||
var component = entity.Comp;
|
||||
|
||||
|
||||
if (TryAudioLimit(component.FileName))
|
||||
{
|
||||
var newSource = _audio.CreateAudioSource(audioResource);
|
||||
@@ -427,13 +427,13 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
return false;
|
||||
}
|
||||
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string filename, EntityCoordinates coordinates,
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string? filename, EntityCoordinates coordinates,
|
||||
AudioParams? audioParams = null)
|
||||
{
|
||||
return PlayStatic(filename, Filter.Local(), coordinates, true, audioParams);
|
||||
}
|
||||
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string filename, EntityUid uid, AudioParams? audioParams = null)
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string? filename, EntityUid uid, AudioParams? audioParams = null)
|
||||
{
|
||||
return PlayEntity(filename, Filter.Local(), uid, true, audioParams);
|
||||
}
|
||||
@@ -460,8 +460,11 @@ 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(string filename, AudioParams? audioParams = null, bool recordReplay = true)
|
||||
private (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, AudioParams? audioParams = null, bool recordReplay = true)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filename))
|
||||
return null;
|
||||
|
||||
if (recordReplay && _replayRecording.IsRecording)
|
||||
{
|
||||
_replayRecording.RecordReplayMessage(new PlayAudioGlobalMessage
|
||||
@@ -493,8 +496,11 @@ 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(string filename, 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 (string.IsNullOrEmpty(filename))
|
||||
return null;
|
||||
|
||||
if (recordReplay && _replayRecording.IsRecording)
|
||||
{
|
||||
_replayRecording.RecordReplayMessage(new PlayAudioEntityMessage
|
||||
@@ -534,8 +540,11 @@ 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(string filename, 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 (string.IsNullOrEmpty(filename))
|
||||
return null;
|
||||
|
||||
if (recordReplay && _replayRecording.IsRecording)
|
||||
{
|
||||
_replayRecording.RecordReplayMessage(new PlayAudioPositionalMessage
|
||||
@@ -569,25 +578,25 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string filename, 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(filename, audioParams);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string filename, 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(filename, entity, audioParams);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string filename, 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(filename, coordinates, audioParams);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string filename, ICommonSession recipient, AudioParams? audioParams = null)
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, ICommonSession recipient, AudioParams? audioParams = null)
|
||||
{
|
||||
return PlayGlobal(filename, audioParams);
|
||||
}
|
||||
@@ -603,31 +612,31 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string filename, EntityUid recipient, AudioParams? audioParams = null)
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, EntityUid recipient, AudioParams? audioParams = null)
|
||||
{
|
||||
return PlayGlobal(filename, audioParams);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string 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, uid, audioParams);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string filename, 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(filename, uid, audioParams);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string 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, coordinates, audioParams);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string filename, 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(filename, coordinates, audioParams);
|
||||
}
|
||||
|
||||
@@ -294,7 +294,6 @@ namespace Robust.Client.Console.Commands
|
||||
internal sealed class SnapGridGetCell : LocalizedCommands
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
[Dependency] private readonly IMapManager _map = default!;
|
||||
|
||||
public override string Command => "sggcell";
|
||||
|
||||
@@ -320,7 +319,7 @@ namespace Robust.Client.Console.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
if (_map.TryGetGrid(_entManager.GetEntity(gridNet), out var grid))
|
||||
if (_entManager.TryGetComponent<MapGridComponent>(_entManager.GetEntity(gridNet), out var grid))
|
||||
{
|
||||
foreach (var entity in grid.GetAnchoredEntities(new Vector2i(
|
||||
int.Parse(indices.Split(',')[0], CultureInfo.InvariantCulture),
|
||||
@@ -429,7 +428,6 @@ namespace Robust.Client.Console.Commands
|
||||
internal sealed class GridTileCount : LocalizedCommands
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
[Dependency] private readonly IMapManager _map = default!;
|
||||
|
||||
public override string Command => "gridtc";
|
||||
|
||||
@@ -448,7 +446,7 @@ namespace Robust.Client.Console.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
if (_map.TryGetGrid(gridUid, out var grid))
|
||||
if (_entManager.TryGetComponent<MapGridComponent>(gridUid, out var grid))
|
||||
{
|
||||
shell.WriteLine(grid.GetAllTiles().Count().ToString());
|
||||
}
|
||||
@@ -555,7 +553,7 @@ namespace Robust.Client.Console.Commands
|
||||
if (type != typeof(Control))
|
||||
cname = $"Control > {cname}";
|
||||
|
||||
returnVal.GetOrNew(cname).Add((member.Name, member.GetValue(control)?.ToString() ?? "null"));
|
||||
returnVal.GetOrNew(cname).Add((member.Name, GetMemberValue(member, control, ", ")));
|
||||
}
|
||||
|
||||
foreach (var (attachedProperty, value) in control.AllAttachedProperties)
|
||||
@@ -570,6 +568,28 @@ namespace Robust.Client.Console.Commands
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
internal static string PropertyValuesString(Control control, string key)
|
||||
{
|
||||
var member = GetAllMembers(control).Find(m => m.Name == key);
|
||||
return GetMemberValue(member, control, "\n", "\"{0}\"");
|
||||
}
|
||||
|
||||
private static string GetMemberValue(MemberInfo? member, Control control, string separator, string
|
||||
wrap = "{0}")
|
||||
{
|
||||
var value = member?.GetValue(control);
|
||||
var o = value switch
|
||||
{
|
||||
ICollection<Control> controls => string.Join(separator,
|
||||
controls.Select(ctrl => $"{ctrl.Name}({ctrl.GetType()})")),
|
||||
ICollection<string> list => string.Join(separator, list),
|
||||
null => null,
|
||||
_ => value.ToString()
|
||||
};
|
||||
// Convert to quote surrounded string or null with no quotes
|
||||
return o is not null ? string.Format(wrap, o) : "null";
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class SetClipboardCommand : LocalizedCommands
|
||||
|
||||
@@ -612,6 +612,8 @@ namespace Robust.Client
|
||||
{
|
||||
_modLoader.BroadcastUpdate(ModUpdateLevel.FramePostEngine, frameEventArgs);
|
||||
}
|
||||
|
||||
_audio.FlushALDisposeQueues();
|
||||
}
|
||||
|
||||
internal static void SetupLogging(
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace Robust.Client.GameObjects
|
||||
[Dependency] private readonly IConsoleHost _conHost = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly ILogManager _logManager = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
|
||||
private ISawmill _sawmillInputContext = default!;
|
||||
|
||||
@@ -151,7 +152,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
var pxform = Transform(pent);
|
||||
var wPos = pxform.WorldPosition + new Vector2(float.Parse(args[2]), float.Parse(args[3]));
|
||||
var coords = EntityCoordinates.FromMap(EntityManager, pent, new MapCoordinates(wPos, pxform.MapID));
|
||||
var coords = EntityCoordinates.FromMap(pent, new MapCoordinates(wPos, pxform.MapID), _transform, EntityManager);
|
||||
|
||||
var funcId = _inputManager.NetworkBindMap.KeyFunctionID(keyFunction);
|
||||
|
||||
|
||||
@@ -700,7 +700,7 @@ namespace Robust.Client.GameStates
|
||||
{
|
||||
using var _ = _timing.StartStateApplicationArea();
|
||||
|
||||
// TODO repays optimize this.
|
||||
// TODO replays optimize this.
|
||||
// This currently just saves game states as they are applied.
|
||||
// However this is inefficient and may have redundant data.
|
||||
// E.g., we may record states: [10 to 15] [11 to 16] *error* [0 to 18] [18 to 19] [18 to 20] ...
|
||||
|
||||
@@ -11,6 +11,7 @@ using Robust.Shared;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Graphics;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Profiling;
|
||||
using Robust.Shared.Utility;
|
||||
@@ -514,7 +515,9 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
if (_lightManager.Enabled && _lightManager.DrawHardFov && eye.DrawLight && eye.DrawFov)
|
||||
{
|
||||
ApplyFovToBuffer(viewport, eye);
|
||||
var mapUid = _mapManager.GetMapEntityId(eye.Position.MapId);
|
||||
if (_entityManager.GetComponent<MapComponent>(mapUid).LightingEnabled)
|
||||
ApplyFovToBuffer(viewport, eye);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -649,24 +649,30 @@ namespace Robust.Client.Graphics.Clyde
|
||||
return $"ClydeTexture: ({TextureId})";
|
||||
}
|
||||
|
||||
public override Color GetPixel(int x, int y)
|
||||
public override unsafe Color GetPixel(int x, int y)
|
||||
{
|
||||
if (!_clyde._loadedTextures.TryGetValue(TextureId, out var loaded))
|
||||
{
|
||||
throw new DataException("Texture not found");
|
||||
}
|
||||
|
||||
Span<byte> rgba = stackalloc byte[4*this.Size.X*this.Size.Y];
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* p = rgba)
|
||||
{
|
||||
var curTexture2D = GL.GetInteger(GetPName.TextureBinding2D);
|
||||
var bufSize = 4 * loaded.Size.X * loaded.Size.Y;
|
||||
var buffer = ArrayPool<byte>.Shared.Rent(bufSize);
|
||||
|
||||
GL.GetTextureImage(loaded.OpenGLObject.Handle, 0, PF.Rgba, PT.UnsignedByte, 4*this.Size.X*this.Size.Y, (IntPtr) p);
|
||||
}
|
||||
GL.BindTexture(TextureTarget.Texture2D, loaded.OpenGLObject.Handle);
|
||||
|
||||
fixed (byte* p = buffer)
|
||||
{
|
||||
GL.GetnTexImage(TextureTarget.Texture2D, 0, PF.Rgba, PT.UnsignedByte, bufSize, (IntPtr) p);
|
||||
}
|
||||
int pixelPos = (this.Size.X*(this.Size.Y-y) + x)*4;
|
||||
return new Color(rgba[pixelPos+0], rgba[pixelPos+1], rgba[pixelPos+2], rgba[pixelPos+3]);
|
||||
|
||||
GL.BindTexture(TextureTarget.Texture2D, curTexture2D);
|
||||
|
||||
var pixelPos = (loaded.Size.X * (loaded.Size.Y - y - 1) + x) * 4;
|
||||
var color = new Color(buffer[pixelPos+0], buffer[pixelPos+1], buffer[pixelPos+2], buffer[pixelPos+3]);
|
||||
ArrayPool<byte>.Shared.Return(buffer);
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Robust.Client.Placement.Modes
|
||||
|
||||
var snapToEntities = EntitySystem.Get<EntityLookupSystem>().GetEntitiesInRange(MouseCoords, SnapToRange)
|
||||
.Where(entity => pManager.EntityManager.GetComponent<MetaDataComponent>(entity).EntityPrototype == pManager.CurrentPrototype && pManager.EntityManager.GetComponent<TransformComponent>(entity).MapID == mapId)
|
||||
.OrderBy(entity => (pManager.EntityManager.GetComponent<TransformComponent>(entity).WorldPosition - MouseCoords.ToMapPos(pManager.EntityManager)).LengthSquared())
|
||||
.OrderBy(entity => (pManager.EntityManager.GetComponent<TransformComponent>(entity).WorldPosition - MouseCoords.ToMapPos(pManager.EntityManager, pManager.EntityManager.System<SharedTransformSystem>())).LengthSquared())
|
||||
.ToList();
|
||||
|
||||
if (snapToEntities.Count == 0)
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Numerics;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Robust.Client.Placement.Modes
|
||||
@@ -24,7 +25,7 @@ namespace Robust.Client.Placement.Modes
|
||||
SnapSize = 1f;
|
||||
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
|
||||
{
|
||||
Grid = pManager.MapManager.GetGrid(gridId);
|
||||
Grid = pManager.EntityManager.GetComponent<MapGridComponent>(gridId);
|
||||
SnapSize = Grid.TileSize; //Find snap size for the grid.
|
||||
}
|
||||
else
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Robust.Client.Placement.Modes
|
||||
SnapSize = 1f;
|
||||
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
|
||||
{
|
||||
Grid = pManager.MapManager.GetGrid(gridId);
|
||||
Grid = pManager.EntityManager.GetComponent<MapGridComponent>(gridId);
|
||||
SnapSize = Grid.TileSize; //Find snap size for the grid.
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Numerics;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
|
||||
namespace Robust.Client.Placement.Modes
|
||||
{
|
||||
@@ -19,7 +20,7 @@ namespace Robust.Client.Placement.Modes
|
||||
|
||||
var gridId = MouseCoords.GetGridUid(pManager.EntityManager);
|
||||
|
||||
if (!pManager.MapManager.TryGetGrid(gridId, out var mapGrid))
|
||||
if (!pManager.EntityManager.TryGetComponent<MapGridComponent>(gridId, out var mapGrid))
|
||||
return;
|
||||
|
||||
CurrentTile = mapGrid.GetTileRef(MouseCoords);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Numerics;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
|
||||
namespace Robust.Client.Placement.Modes
|
||||
{
|
||||
@@ -20,7 +21,7 @@ namespace Robust.Client.Placement.Modes
|
||||
|
||||
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
|
||||
{
|
||||
var mapGrid = pManager.MapManager.GetGrid(gridId);
|
||||
var mapGrid = pManager.EntityManager.GetComponent<MapGridComponent>(gridId);
|
||||
tileSize = mapGrid.TileSize; //convert from ushort to float
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Robust.Client.Placement.Modes
|
||||
@@ -22,7 +23,7 @@ namespace Robust.Client.Placement.Modes
|
||||
|
||||
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
|
||||
{
|
||||
var mapGrid = pManager.MapManager.GetGrid(gridId);
|
||||
var mapGrid = pManager.EntityManager.GetComponent<MapGridComponent>(gridId);
|
||||
CurrentTile = mapGrid.GetTileRef(MouseCoords);
|
||||
tileSize = mapGrid.TileSize; //convert from ushort to float
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Numerics;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
|
||||
namespace Robust.Client.Placement.Modes
|
||||
{
|
||||
@@ -20,7 +21,7 @@ namespace Robust.Client.Placement.Modes
|
||||
var gridIdOpt = MouseCoords.GetGridUid(pManager.EntityManager);
|
||||
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
|
||||
{
|
||||
var mapGrid = pManager.MapManager.GetGrid(gridId);
|
||||
var mapGrid = pManager.EntityManager.GetComponent<MapGridComponent>(gridId);
|
||||
tileSize = mapGrid.TileSize; //convert from ushort to float
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.Log;
|
||||
using Direction = Robust.Shared.Maths.Direction;
|
||||
using Robust.Shared.Map.Components;
|
||||
|
||||
namespace Robust.Client.Placement
|
||||
{
|
||||
@@ -79,6 +80,10 @@ namespace Robust.Client.Placement
|
||||
private set
|
||||
{
|
||||
_isActive = value;
|
||||
|
||||
if (CurrentPermission?.UseEditorContext is false)
|
||||
return;
|
||||
|
||||
SwitchEditorContext(value);
|
||||
}
|
||||
}
|
||||
@@ -332,7 +337,7 @@ namespace Robust.Client.Placement
|
||||
|
||||
private void HandleTileChanged(ref TileChangedEvent args)
|
||||
{
|
||||
var coords = MapManager.GetGrid(args.NewTile.GridUid).GridTileToLocal(args.NewTile.GridIndices);
|
||||
var coords = EntityManager.GetComponent<MapGridComponent>(args.NewTile.GridUid).GridTileToLocal(args.NewTile.GridIndices);
|
||||
_pendingTileChanges.RemoveAll(c => c.Item1 == coords);
|
||||
}
|
||||
|
||||
@@ -753,7 +758,7 @@ namespace Robust.Client.Placement
|
||||
// If we have actually placed something on a valid grid...
|
||||
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
|
||||
{
|
||||
var grid = MapManager.GetGrid(gridId);
|
||||
var grid = EntityManager.GetComponent<MapGridComponent>(gridId);
|
||||
|
||||
// no point changing the tile to the same thing.
|
||||
if (grid.GetTileRef(coordinates).Tile.TypeId == CurrentPermission.TileType)
|
||||
|
||||
@@ -11,6 +11,7 @@ using Robust.Shared.Graphics;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Utility;
|
||||
@@ -115,11 +116,12 @@ namespace Robust.Client.Placement
|
||||
|
||||
var dirAng = pManager.Direction.ToAngle();
|
||||
var spriteSys = pManager.EntityManager.System<SpriteSystem>();
|
||||
var transformSys = pManager.EntityManager.System<SharedTransformSystem>();
|
||||
foreach (var coordinate in locationcollection)
|
||||
{
|
||||
if (!coordinate.IsValid(pManager.EntityManager))
|
||||
return; // Just some paranoia just in case
|
||||
var worldPos = coordinate.ToMapPos(pManager.EntityManager);
|
||||
var worldPos = coordinate.ToMapPos(pManager.EntityManager, transformSys);
|
||||
var worldRot = pManager.EntityManager.GetComponent<TransformComponent>(coordinate.EntityId).WorldRotation + dirAng;
|
||||
|
||||
sprite.Color = IsValidPosition(coordinate) ? ValidPlaceColor : InvalidPlaceColor;
|
||||
@@ -136,11 +138,12 @@ namespace Robust.Client.Placement
|
||||
{
|
||||
var mouseScreen = pManager.InputManager.MouseScreenPosition;
|
||||
var mousePos = pManager.EyeManager.PixelToMap(mouseScreen);
|
||||
var transformSys = pManager.EntityManager.System<SharedTransformSystem>();
|
||||
|
||||
if (mousePos.MapId == MapId.Nullspace)
|
||||
yield break;
|
||||
|
||||
var (_, (x, y)) = EntityCoordinates.FromMap(pManager.StartPoint.EntityId, mousePos, pManager.EntityManager) - 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))
|
||||
@@ -167,11 +170,12 @@ namespace Robust.Client.Placement
|
||||
{
|
||||
var mouseScreen = pManager.InputManager.MouseScreenPosition;
|
||||
var mousePos = pManager.EyeManager.PixelToMap(mouseScreen);
|
||||
var transformSys = pManager.EntityManager.System<SharedTransformSystem>();
|
||||
|
||||
if (mousePos.MapId == MapId.Nullspace)
|
||||
yield break;
|
||||
|
||||
var placementdiff = EntityCoordinates.FromMap(pManager.StartPoint.EntityId, mousePos, pManager.EntityManager) - 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);
|
||||
@@ -193,9 +197,9 @@ namespace Robust.Client.Placement
|
||||
public TileRef GetTileRef(EntityCoordinates coordinates)
|
||||
{
|
||||
var gridUidOpt = coordinates.GetGridUid(pManager.EntityManager);
|
||||
return gridUidOpt is EntityUid gridUid && gridUid.IsValid() ? pManager.MapManager.GetGrid(gridUid).GetTileRef(MouseCoords)
|
||||
return gridUidOpt is EntityUid gridUid && gridUid.IsValid() ? pManager.EntityManager.GetComponent<MapGridComponent>(gridUid).GetTileRef(MouseCoords)
|
||||
: new TileRef(gridUidOpt ?? EntityUid.Invalid,
|
||||
MouseCoords.ToVector2i(pManager.EntityManager, pManager.MapManager), Tile.Empty);
|
||||
MouseCoords.ToVector2i(pManager.EntityManager, pManager.MapManager, pManager.EntityManager.System<SharedTransformSystem>()), Tile.Empty);
|
||||
}
|
||||
|
||||
public TextureResource GetSprite(string key)
|
||||
@@ -223,7 +227,8 @@ namespace Robust.Client.Placement
|
||||
}
|
||||
|
||||
var range = pManager.CurrentPermission!.Range;
|
||||
if (range > 0 && !pManager.EntityManager.GetComponent<TransformComponent>(controlled).Coordinates.InRange(pManager.EntityManager, coordinates, range))
|
||||
var transformSys = pManager.EntityManager.System<SharedTransformSystem>();
|
||||
if (range > 0 && !pManager.EntityManager.GetComponent<TransformComponent>(controlled).Coordinates.InRange(pManager.EntityManager, transformSys, coordinates, range))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@@ -231,7 +236,8 @@ namespace Robust.Client.Placement
|
||||
public bool IsColliding(EntityCoordinates coordinates)
|
||||
{
|
||||
var bounds = pManager.ColliderAABB;
|
||||
var mapCoords = coordinates.ToMap(pManager.EntityManager);
|
||||
var transformSys = pManager.EntityManager.System<SharedTransformSystem>();
|
||||
var mapCoords = coordinates.ToMap(pManager.EntityManager, transformSys);
|
||||
var (x, y) = mapCoords.Position;
|
||||
|
||||
var collisionBox = Box2.FromDimensions(
|
||||
@@ -261,7 +267,8 @@ namespace Robust.Client.Placement
|
||||
return EntityCoordinates.FromMap(pManager.MapManager, mapCoords);
|
||||
}
|
||||
|
||||
return EntityCoordinates.FromMap(pManager.EntityManager, gridUid, mapCoords);
|
||||
var transformSys = pManager.EntityManager.System<SharedTransformSystem>();
|
||||
return EntityCoordinates.FromMap(gridUid, mapCoords, transformSys, pManager.EntityManager);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public sealed partial class ReplayLoadManager
|
||||
return parsed.FirstOrDefault()?.Root as MappingDataNode;
|
||||
}
|
||||
|
||||
private (MappingDataNode YamlData, HashSet<string> CVars, TimeSpan Duration, TimeSpan StartTime, bool ClientSide)
|
||||
private (MappingDataNode YamlData, HashSet<string> CVars, TimeSpan? Duration, TimeSpan StartTime, bool ClientSide)
|
||||
LoadMetadata(IReplayFileReader fileReader)
|
||||
{
|
||||
_sawmill.Info($"Reading replay metadata");
|
||||
@@ -137,23 +137,16 @@ public sealed partial class ReplayLoadManager
|
||||
if (data == null)
|
||||
throw new Exception("Failed to load yaml metadata");
|
||||
|
||||
TimeSpan duration;
|
||||
var finalData = LoadYamlFinalMetadata(fileReader);
|
||||
TimeSpan? duration = finalData == null
|
||||
? null
|
||||
: TimeSpan.Parse(((ValueDataNode) finalData[MetaFinalKeyDuration]).Value);
|
||||
|
||||
if (finalData == null)
|
||||
{
|
||||
var msg = "Failed to load final yaml metadata";
|
||||
if (!_confMan.GetCVar(CVars.ReplayIgnoreErrors))
|
||||
throw new Exception(msg);
|
||||
_sawmill.Warning("Failed to load final yaml metadata. Partial/incomplete replay?");
|
||||
|
||||
_sawmill.Error(msg);
|
||||
duration = TimeSpan.FromDays(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
duration = TimeSpan.Parse(((ValueDataNode) finalData[MetaFinalKeyDuration]).Value);
|
||||
}
|
||||
|
||||
var typeHash = Convert.FromHexString(((ValueDataNode) data[MetaKeyTypeHash]).Value);
|
||||
var typeHashString = ((ValueDataNode) data[MetaKeyTypeHash]).Value;
|
||||
var typeHash = Convert.FromHexString(typeHashString);
|
||||
var stringHash = Convert.FromHexString(((ValueDataNode) data[MetaKeyStringHash]).Value);
|
||||
var startTick = ((ValueDataNode) data[MetaKeyStartTick]).Value;
|
||||
var timeBaseTick = ((ValueDataNode) data[MetaKeyBaseTick]).Value;
|
||||
@@ -161,7 +154,12 @@ public sealed partial class ReplayLoadManager
|
||||
var clientSide = bool.Parse(((ValueDataNode) data[MetaKeyIsClientRecording]).Value);
|
||||
|
||||
if (!typeHash.SequenceEqual(_serializer.GetSerializableTypesHash()))
|
||||
throw new Exception($"{nameof(IRobustSerializer)} hashes do not match. Loading replays using a bad replay-client version?");
|
||||
{
|
||||
if (!_confMan.GetCVar(CVars.ReplayIgnoreErrors))
|
||||
throw new Exception($"RobustSerializer hash mismatch. do not match. Client hash: {_serializer.GetSerializableTypesHashString()}, replay hash: {typeHashString}.");
|
||||
|
||||
_sawmill.Warning($"RobustSerializer hash mismatch. Replay may fail to load!");
|
||||
}
|
||||
|
||||
using var stringFile = fileReader.Open(FileStrings);
|
||||
var stringData = new byte[stringFile.Length];
|
||||
|
||||
@@ -90,6 +90,7 @@ public sealed partial class ReplayControlWidget : UIWidget // AKA Tardis - The f
|
||||
var maxIndex = Math.Max(1, replay.States.Count - 1);
|
||||
var state = replay.States[index];
|
||||
var replayTime = TimeSpan.FromSeconds(TickSlider.Value);
|
||||
var end = replay.Duration == null ? "N/A" : replay.Duration.Value.ToString(TimeFormat);
|
||||
|
||||
IndexLabel.Text = Loc.GetString("replay-time-box-index-label",
|
||||
("current", index), ("total", maxIndex), ("percentage", percentage));
|
||||
@@ -98,10 +99,10 @@ public sealed partial class ReplayControlWidget : UIWidget // AKA Tardis - The f
|
||||
("current", state.ToSequence), ("total", replay.States[^1].ToSequence), ("percentage", percentage));
|
||||
|
||||
TimeLabel.Text = Loc.GetString("replay-time-box-replay-time-label",
|
||||
("current", replayTime.ToString(TimeFormat)), ("end", replay.Duration.ToString(TimeFormat)), ("percentage", percentage));
|
||||
("current", replayTime.ToString(TimeFormat)), ("end", end), ("percentage", percentage));
|
||||
|
||||
var serverTime = (replayTime + replay.StartTime).ToString(TimeFormat);
|
||||
var duration = (replay.Duration + replay.StartTime).ToString(TimeFormat);
|
||||
string duration = replay.Duration == null ? "N/A" : (replay.Duration + replay.StartTime).Value.ToString(TimeFormat);
|
||||
ServerTimeLabel.Text = Loc.GetString("replay-time-box-server-time-label",
|
||||
("current", serverTime), ("end", duration), ("percentage", percentage));
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<PackageReference Include="Robust.Natives" />
|
||||
<PackageReference Include="System.Numerics.Vectors" />
|
||||
<PackageReference Include="TerraFX.Interop.Windows" PrivateAssets="compile" />
|
||||
<PackageReference Condition="'$(FullRelease)' != 'True'" Include="JetBrains.Profiler.Api" PrivateAssets="compile" />
|
||||
<PackageReference Condition="'$(RobustToolsBuild)' == 'True'" Include="JetBrains.Profiler.Api" PrivateAssets="compile" />
|
||||
<PackageReference Include="SpaceWizards.Sodium" PrivateAssets="compile" />
|
||||
<PackageReference Include="Microsoft.NET.ILLink.Tasks" />
|
||||
<PackageReference Include="TerraFX.Interop.Xlib" />
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace Robust.Client.UserInterface.Controls
|
||||
TextureRect = new TextureRect
|
||||
{
|
||||
StyleClasses = { StyleClassCheckBox },
|
||||
VerticalAlignment = VAlignment.Center,
|
||||
};
|
||||
hBox.AddChild(TextureRect);
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ using System.Numerics;
|
||||
using System.Text;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
@@ -20,6 +22,8 @@ namespace Robust.Client.UserInterface.Controls
|
||||
public class LineEdit : Control
|
||||
{
|
||||
[Dependency] private readonly IClyde _clyde = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfgManager = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
private const float MouseScrollDelay = 0.001f;
|
||||
|
||||
@@ -46,6 +50,9 @@ namespace Robust.Client.UserInterface.Controls
|
||||
private bool _mouseSelectingText;
|
||||
private float _lastMousePosition;
|
||||
|
||||
private TimeSpan? _lastClickTime;
|
||||
private Vector2? _lastClickPosition;
|
||||
|
||||
private bool IsPlaceHolderVisible => string.IsNullOrEmpty(_text) && _placeHolder != null;
|
||||
|
||||
public event Action<LineEditEventArgs>? OnTextChanged;
|
||||
@@ -685,8 +692,26 @@ namespace Robust.Client.UserInterface.Controls
|
||||
args.Handle();
|
||||
}
|
||||
}
|
||||
// Double-clicking. Clicks delay should be <= 250ms and the distance < 10 pixels.
|
||||
else if (args.Function == EngineKeyFunctions.UIClick && _lastClickPosition != null && _lastClickTime != null
|
||||
&& _timing.RealTime - _lastClickTime <= TimeSpan.FromMilliseconds(_cfgManager.GetCVar(CVars.DoubleClickDelay))
|
||||
&& (_lastClickPosition.Value - args.PointerLocation.Position).IsShorterThan(_cfgManager.GetCVar(CVars.DoubleClickRange)))
|
||||
{
|
||||
_lastClickTime = _timing.RealTime;
|
||||
_lastClickPosition = args.PointerLocation.Position;
|
||||
|
||||
_lastMousePosition = args.RelativePosition.X;
|
||||
|
||||
_selectionStart = TextEditShared.PrevWordPosition(_text, GetIndexAtPos(args.RelativePosition.X));
|
||||
_cursorPosition = TextEditShared.EndWordPosition(_text, GetIndexAtPos(args.RelativePosition.X));
|
||||
|
||||
args.Handle();
|
||||
}
|
||||
else
|
||||
{
|
||||
_lastClickTime = _timing.RealTime;
|
||||
_lastClickPosition = args.PointerLocation.Position;
|
||||
|
||||
_mouseSelectingText = true;
|
||||
_lastMousePosition = args.RelativePosition.X;
|
||||
|
||||
|
||||
@@ -123,10 +123,10 @@ namespace Robust.Client.UserInterface.Controls
|
||||
if (!ReturnMeasure)
|
||||
return Vector2.Zero;
|
||||
|
||||
if (_vScrollEnabled)
|
||||
if (_vScrollEnabled && size.Y >= availableSize.Y)
|
||||
size.X += _vScrollBar.DesiredSize.X;
|
||||
|
||||
if (_hScrollEnabled)
|
||||
if (_hScrollEnabled && size.X >= availableSize.X)
|
||||
size.Y += _hScrollBar.DesiredSize.Y;
|
||||
|
||||
return size;
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace Robust.Client.UserInterface.CustomControls.DebugMonitorControls
|
||||
contents.TextMemory = FormatHelpers.FormatIntoMem(_textBuffer,
|
||||
$@"UP: {sentBytes / ONE_KIBIBYTE:N} KiB/s, {sentPackets} pckt/s, {LastSentBytes / ONE_KIBIBYTE:N} KiB, {LastSentPackets} pckt
|
||||
DOWN: {receivedBytes / ONE_KIBIBYTE:N} KiB/s, {receivedPackets} pckt/s, {LastReceivedBytes / ONE_KIBIBYTE:N} KiB, {LastReceivedPackets} pckt
|
||||
PING: {NetManager.ServerChannel?.Ping ?? -1} ms");
|
||||
PING: {NetManager.ServerChannel?.Ping ?? -1} ms, MTU: {NetManager.ServerChannel?.CurrentMtu} B");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,14 @@
|
||||
<BoxContainer Name="ControlTreeRoot" Orientation="Vertical" MouseFilter="Stop" />
|
||||
</PanelContainer>
|
||||
</ScrollContainer>
|
||||
<ScrollContainer HScrollEnabled="False">
|
||||
<ScrollContainer>
|
||||
<BoxContainer Name="ControlProperties" Orientation="Vertical" MouseFilter="Stop" />
|
||||
</ScrollContainer>
|
||||
</SplitContainer>
|
||||
</BoxContainer>
|
||||
</PanelContainer>
|
||||
<!-- TODO Remove and replace with a popup container on WindowRoot -->
|
||||
<PopupContainer Name="PopupContainer" Access="Public">
|
||||
<DevWindowTabUIPopup Name="UIPopup" />
|
||||
</PopupContainer>
|
||||
</Control>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Console.Commands;
|
||||
using Robust.Client.Graphics;
|
||||
@@ -208,25 +209,40 @@ public sealed partial class DevWindowTabUI : Control
|
||||
});
|
||||
foreach (var (prop, value) in values)
|
||||
{
|
||||
ControlProperties.AddChild(new BoxContainer
|
||||
var button = new ContainerButton
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
||||
SeparationOverride = 3,
|
||||
Margin = new Thickness(3, 1),
|
||||
Children =
|
||||
{
|
||||
new BoxContainer
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
||||
SeparationOverride = 3,
|
||||
Margin = new Thickness(3, 1),
|
||||
Children =
|
||||
{
|
||||
new Label { Text = $"{prop}", FontColorOverride = Color.GreenYellow },
|
||||
new Label { Text = ":" }, // this is for the non colored ":", intentional
|
||||
new BoxContainer
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
new Label { Text = $"{prop}", FontColorOverride = Color.GreenYellow },
|
||||
new Label { Text = ":" }, // this is for the non colored ":", intentional
|
||||
}
|
||||
},
|
||||
new Label { Text = $"{value}" },
|
||||
}
|
||||
},
|
||||
new Label { Text = $"{value}" },
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
button.OnPressed += _ =>
|
||||
{
|
||||
// TODO replace with parenting to popup container on WindowRoot
|
||||
UIPopup.Text = GuiDumpCommand.PropertyValuesString(SelectedControl, prop);
|
||||
var box = UIBox2.FromDimensions(UserInterfaceManager.MousePositionScaled.Position
|
||||
- GlobalPosition, Vector2.One);
|
||||
UIPopup.Open(box);
|
||||
};
|
||||
ControlProperties.AddChild(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<DevWindowTabUIPopup xmlns="https://spacestation14.io"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="Robust.Client.UserInterface.DevWindowTabUIPopup"
|
||||
xmlns:gfx="clr-namespace:Robust.Client.Graphics">
|
||||
<PanelContainer>
|
||||
<PanelContainer.PanelOverride>
|
||||
<gfx:StyleBoxFlat BackgroundColor="#40404C" />
|
||||
</PanelContainer.PanelOverride>
|
||||
</PanelContainer>
|
||||
<Label Name="TextLabel" />
|
||||
</DevWindowTabUIPopup>
|
||||
@@ -0,0 +1,20 @@
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Robust.Client.UserInterface;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
internal sealed partial class DevWindowTabUIPopup : Popup
|
||||
{
|
||||
public string? Text
|
||||
{
|
||||
get => TextLabel.Text;
|
||||
set => TextLabel.Text = value;
|
||||
}
|
||||
|
||||
public DevWindowTabUIPopup()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.ViewVariables.Editors;
|
||||
using Robust.Client.ViewVariables.Instances;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
@@ -29,6 +31,8 @@ namespace Robust.Client.ViewVariables
|
||||
[Dependency] private readonly IClientNetManager _netManager = default!;
|
||||
[Dependency] private readonly IRobustSerializer _robustSerializer = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
||||
[Dependency] private readonly IResourceManager _resManager = default!;
|
||||
|
||||
private uint _nextReqId = 1;
|
||||
private readonly Vector2i _defaultWindowSize = (640, 420);
|
||||
@@ -126,8 +130,12 @@ namespace Robust.Client.ViewVariables
|
||||
return new VVPropEditorString();
|
||||
}
|
||||
|
||||
if (type == typeof(EntProtoId) ||
|
||||
type == typeof(EntProtoId?))
|
||||
if (type == typeof(EntProtoId?))
|
||||
{
|
||||
return new VVPropEditorNullableEntProtoId();
|
||||
}
|
||||
|
||||
if (type == typeof(EntProtoId))
|
||||
{
|
||||
return new VVPropEditorEntProtoId();
|
||||
}
|
||||
@@ -222,6 +230,12 @@ namespace Robust.Client.ViewVariables
|
||||
return new VVPropEditorTimeSpan();
|
||||
}
|
||||
|
||||
if (typeof(SoundSpecifier).IsAssignableFrom(type))
|
||||
{
|
||||
var control = new VVPropEditorSoundSpecifier(_protoManager, _resManager);
|
||||
return control;
|
||||
}
|
||||
|
||||
if (type == typeof(ViewVariablesBlobMembers.ServerKeyValuePairToken) ||
|
||||
type.IsGenericType && type.GetGenericTypeDefinition() == typeof(KeyValuePair<,>))
|
||||
{
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Robust.Client.ViewVariables.Editors;
|
||||
|
||||
internal sealed class VVPropEditorNullableEntProtoId : VVPropEditor
|
||||
{
|
||||
protected override Control MakeUI(object? value)
|
||||
{
|
||||
var lineEdit = new LineEdit
|
||||
{
|
||||
Text = value is EntProtoId protoId ? protoId.Id : "",
|
||||
Editable = !ReadOnly,
|
||||
HorizontalExpand = true,
|
||||
};
|
||||
|
||||
if (!ReadOnly)
|
||||
{
|
||||
lineEdit.OnTextEntered += e =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(e.Text))
|
||||
{
|
||||
ValueChanged(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
ValueChanged((EntProtoId) e.Text);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return lineEdit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,393 @@
|
||||
using System.Globalization;
|
||||
using System.Numerics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Client.ViewVariables.Editors;
|
||||
|
||||
public sealed class VVPropEditorSoundSpecifier : VVPropEditor
|
||||
{
|
||||
private readonly IPrototypeManager _protoManager;
|
||||
private readonly IResourceManager _resManager;
|
||||
|
||||
// Need to cache to some level just to make sure each edit doesn't reset the specifier to the default.
|
||||
|
||||
private SoundSpecifier? _specifier;
|
||||
|
||||
public VVPropEditorSoundSpecifier(IPrototypeManager protoManager, IResourceManager resManager)
|
||||
{
|
||||
_protoManager = protoManager;
|
||||
_resManager = resManager;
|
||||
}
|
||||
|
||||
protected override Control MakeUI(object? value)
|
||||
{
|
||||
var typeButton = new OptionButton()
|
||||
{
|
||||
Disabled = ReadOnly,
|
||||
};
|
||||
|
||||
typeButton.AddItem(Loc.GetString("vv-sound-none"));
|
||||
typeButton.AddItem(Loc.GetString("vv-sound-collection"), 1);
|
||||
typeButton.AddItem(Loc.GetString("vv-sound-path"), 2);
|
||||
|
||||
var editBox = new LineEdit()
|
||||
{
|
||||
HorizontalExpand = true,
|
||||
Editable = !ReadOnly,
|
||||
};
|
||||
|
||||
var pathControls = new BoxContainer()
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
typeButton,
|
||||
editBox
|
||||
},
|
||||
SetSize = new Vector2(384f, 32f)
|
||||
};
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case SoundCollectionSpecifier collection:
|
||||
typeButton.SelectId(1);
|
||||
editBox.Text = collection.Collection ?? string.Empty;
|
||||
_specifier = collection;
|
||||
break;
|
||||
case SoundPathSpecifier path:
|
||||
typeButton.SelectId(2);
|
||||
editBox.Text = path.Path.ToString();
|
||||
_specifier = path;
|
||||
break;
|
||||
default:
|
||||
_specifier = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
typeButton.OnItemSelected += args =>
|
||||
{
|
||||
typeButton.SelectId(args.Id);
|
||||
editBox.Text = string.Empty;
|
||||
|
||||
editBox.Editable = !ReadOnly && typeButton.SelectedId > 0;
|
||||
|
||||
if (typeButton.SelectedId == 0)
|
||||
{
|
||||
// Dummy value
|
||||
ValueChanged(new SoundPathSpecifier(""));
|
||||
}
|
||||
};
|
||||
|
||||
editBox.OnTextEntered += args =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(args.Text))
|
||||
return;
|
||||
|
||||
switch (typeButton.SelectedId)
|
||||
{
|
||||
case 1:
|
||||
if (!_protoManager.HasIndex<SoundCollectionPrototype>(args.Text))
|
||||
return;
|
||||
|
||||
_specifier = new SoundCollectionSpecifier(args.Text)
|
||||
{
|
||||
Params = _specifier?.Params ?? AudioParams.Default,
|
||||
};
|
||||
ValueChanged(_specifier);
|
||||
break;
|
||||
case 2:
|
||||
var path = new ResPath(args.Text);
|
||||
|
||||
if (!_resManager.ContentFileExists(path))
|
||||
return;
|
||||
|
||||
_specifier = new SoundPathSpecifier(args.Text)
|
||||
{
|
||||
Params = _specifier?.Params ?? AudioParams.Default,
|
||||
};
|
||||
|
||||
ValueChanged(_specifier);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// Audio params
|
||||
|
||||
/* Volume */
|
||||
|
||||
var volumeEdit = new LineEdit()
|
||||
{
|
||||
Text = _specifier?.Params.Volume.ToString(CultureInfo.InvariantCulture) ?? string.Empty,
|
||||
HorizontalExpand = true,
|
||||
Editable = !ReadOnly && _specifier != null,
|
||||
};
|
||||
|
||||
volumeEdit.OnTextEntered += args =>
|
||||
{
|
||||
if (!float.TryParse(args.Text, out var floatValue) || _specifier == null)
|
||||
return;
|
||||
|
||||
_specifier.Params = _specifier.Params.WithVolume(floatValue);
|
||||
ValueChanged(_specifier);
|
||||
};
|
||||
|
||||
var volumeContainer = new BoxContainer()
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
new Label()
|
||||
{
|
||||
Text = Loc.GetString("vv-sound-volume"),
|
||||
},
|
||||
volumeEdit,
|
||||
}
|
||||
};
|
||||
|
||||
/* Pitch */
|
||||
|
||||
var pitchEdit = new LineEdit()
|
||||
{
|
||||
Text = _specifier?.Params.Pitch.ToString(CultureInfo.InvariantCulture) ?? string.Empty,
|
||||
HorizontalExpand = true,
|
||||
Editable = !ReadOnly && _specifier != null,
|
||||
};
|
||||
|
||||
pitchEdit.OnTextEntered += args =>
|
||||
{
|
||||
if (!float.TryParse(args.Text, out var floatValue) || _specifier == null)
|
||||
return;
|
||||
|
||||
_specifier.Params = _specifier.Params.WithPitchScale(floatValue);
|
||||
ValueChanged(_specifier);
|
||||
};
|
||||
|
||||
var pitchContainer = new BoxContainer()
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
new Label()
|
||||
{
|
||||
Text = Loc.GetString("vv-sound-pitch"),
|
||||
},
|
||||
pitchEdit,
|
||||
}
|
||||
};
|
||||
|
||||
/* MaxDistance */
|
||||
|
||||
var maxDistanceEdit = new LineEdit()
|
||||
{
|
||||
Text = _specifier?.Params.MaxDistance.ToString(CultureInfo.InvariantCulture) ?? string.Empty,
|
||||
HorizontalExpand = true,
|
||||
Editable = !ReadOnly && _specifier != null,
|
||||
};
|
||||
|
||||
maxDistanceEdit.OnTextEntered += args =>
|
||||
{
|
||||
if (!float.TryParse(args.Text, out var floatValue) || _specifier == null)
|
||||
return;
|
||||
|
||||
_specifier.Params = _specifier.Params.WithMaxDistance(floatValue);
|
||||
ValueChanged(_specifier);
|
||||
};
|
||||
|
||||
var maxDistanceContainer = new BoxContainer()
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
new Label()
|
||||
{
|
||||
Text = Loc.GetString("vv-sound-max-distance"),
|
||||
},
|
||||
maxDistanceEdit,
|
||||
}
|
||||
};
|
||||
|
||||
/* RolloffFactor */
|
||||
|
||||
var rolloffFactorEdit = new LineEdit()
|
||||
{
|
||||
Text = _specifier?.Params.RolloffFactor.ToString(CultureInfo.InvariantCulture) ?? string.Empty,
|
||||
HorizontalExpand = true,
|
||||
Editable = !ReadOnly && _specifier != null,
|
||||
};
|
||||
|
||||
rolloffFactorEdit.OnTextEntered += args =>
|
||||
{
|
||||
if (!float.TryParse(args.Text, out var floatValue) || _specifier == null)
|
||||
return;
|
||||
|
||||
_specifier.Params = _specifier.Params.WithRolloffFactor(floatValue);
|
||||
ValueChanged(_specifier);
|
||||
};
|
||||
|
||||
var rolloffFactorContainer = new BoxContainer()
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
new Label()
|
||||
{
|
||||
Text = Loc.GetString("vv-sound-rolloff-factor"),
|
||||
},
|
||||
rolloffFactorEdit,
|
||||
}
|
||||
};
|
||||
|
||||
/* ReferenceDistance */
|
||||
|
||||
var referenceDistanceEdit = new LineEdit()
|
||||
{
|
||||
Text = _specifier?.Params.ReferenceDistance.ToString(CultureInfo.InvariantCulture) ?? string.Empty,
|
||||
HorizontalExpand = true,
|
||||
Editable = !ReadOnly && _specifier != null,
|
||||
};
|
||||
|
||||
referenceDistanceEdit.OnTextEntered += args =>
|
||||
{
|
||||
if (!float.TryParse(args.Text, out var floatValue) || _specifier == null)
|
||||
return;
|
||||
|
||||
_specifier.Params = _specifier.Params.WithReferenceDistance(floatValue);
|
||||
ValueChanged(_specifier);
|
||||
};
|
||||
|
||||
var referenceDistanceContainer = new BoxContainer()
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
new Label()
|
||||
{
|
||||
Text = Loc.GetString("vv-sound-reference-distance"),
|
||||
},
|
||||
referenceDistanceEdit,
|
||||
}
|
||||
};
|
||||
|
||||
/* Loop */
|
||||
|
||||
var loopButton = new Button()
|
||||
{
|
||||
Text = Loc.GetString("vv-sound-loop"),
|
||||
Pressed = _specifier?.Params.Loop ?? false,
|
||||
ToggleMode = true,
|
||||
Disabled = ReadOnly || _specifier == null,
|
||||
};
|
||||
|
||||
loopButton.OnPressed += args =>
|
||||
{
|
||||
if (_specifier == null)
|
||||
return;
|
||||
|
||||
_specifier.Params = _specifier.Params.WithLoop(args.Button.Pressed);
|
||||
ValueChanged(_specifier);
|
||||
};
|
||||
|
||||
/* PlayOffsetSeconds */
|
||||
|
||||
var playOffsetEdit = new LineEdit()
|
||||
{
|
||||
Text = _specifier?.Params.PlayOffsetSeconds.ToString(CultureInfo.InvariantCulture) ?? string.Empty,
|
||||
HorizontalExpand = true,
|
||||
Editable = !ReadOnly && _specifier != null,
|
||||
};
|
||||
|
||||
playOffsetEdit.OnTextEntered += args =>
|
||||
{
|
||||
if (!float.TryParse(args.Text, out var floatValue) || _specifier == null)
|
||||
return;
|
||||
|
||||
_specifier.Params = _specifier.Params.WithPlayOffset(floatValue);
|
||||
ValueChanged(_specifier);
|
||||
};
|
||||
|
||||
var playOffsetContainer = new BoxContainer()
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
new Label()
|
||||
{
|
||||
Text = Loc.GetString("vv-sound-play-offset"),
|
||||
},
|
||||
playOffsetEdit,
|
||||
}
|
||||
};
|
||||
|
||||
/* Variation */
|
||||
|
||||
var variationEdit = new LineEdit()
|
||||
{
|
||||
Text = _specifier?.Params.Variation.ToString() ?? string.Empty,
|
||||
HorizontalExpand = true,
|
||||
Editable = !ReadOnly && _specifier != null,
|
||||
};
|
||||
|
||||
variationEdit.OnTextEntered += args =>
|
||||
{
|
||||
if (!float.TryParse(args.Text, out var floatValue) || _specifier == null)
|
||||
return;
|
||||
|
||||
_specifier.Params = _specifier.Params.WithVariation(floatValue);
|
||||
ValueChanged(_specifier);
|
||||
};
|
||||
|
||||
var variationContainer = new BoxContainer()
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
new Label()
|
||||
{
|
||||
Text = Loc.GetString("vv-sound-variation"),
|
||||
},
|
||||
variationEdit,
|
||||
}
|
||||
};
|
||||
|
||||
var audioParamsControls = new BoxContainer()
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Vertical,
|
||||
Children =
|
||||
{
|
||||
volumeContainer,
|
||||
pitchContainer,
|
||||
maxDistanceContainer,
|
||||
rolloffFactorContainer,
|
||||
referenceDistanceContainer,
|
||||
loopButton,
|
||||
playOffsetContainer,
|
||||
variationContainer,
|
||||
}
|
||||
};
|
||||
|
||||
var controls = new BoxContainer()
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Vertical,
|
||||
Children =
|
||||
{
|
||||
pathControls,
|
||||
audioParamsControls,
|
||||
}
|
||||
};
|
||||
|
||||
return controls;
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string filename, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null)
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null)
|
||||
{
|
||||
var entity = Spawn("Audio", MapCoordinates.Nullspace);
|
||||
var audio = SetupAudio(entity, filename, audioParams);
|
||||
@@ -78,8 +78,11 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string filename, 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 (string.IsNullOrEmpty(filename))
|
||||
return null;
|
||||
|
||||
if (TerminatingOrDeleted(uid))
|
||||
{
|
||||
Log.Error($"Tried to play audio on a terminating / deleted entity {ToPrettyString(uid)}. Trace: {Environment.StackTrace}");
|
||||
@@ -94,8 +97,11 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string filename, EntityUid uid, AudioParams? audioParams = null)
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string? filename, EntityUid uid, AudioParams? audioParams = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filename))
|
||||
return null;
|
||||
|
||||
if (TerminatingOrDeleted(uid))
|
||||
{
|
||||
Log.Error($"Tried to play audio on a terminating / deleted entity {ToPrettyString(uid)}. Trace: {Environment.StackTrace}");
|
||||
@@ -109,8 +115,11 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string filename, 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 (string.IsNullOrEmpty(filename))
|
||||
return null;
|
||||
|
||||
if (TerminatingOrDeleted(coordinates.EntityId))
|
||||
{
|
||||
Log.Error($"Tried to play coordinates audio on a terminating / deleted entity {ToPrettyString(coordinates.EntityId)}. Trace: {Environment.StackTrace}");
|
||||
@@ -128,9 +137,12 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string filename, EntityCoordinates coordinates,
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string? filename, EntityCoordinates coordinates,
|
||||
AudioParams? audioParams = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filename))
|
||||
return null;
|
||||
|
||||
if (TerminatingOrDeleted(coordinates.EntityId))
|
||||
{
|
||||
Log.Error($"Tried to play coordinates audio on a terminating / deleted entity {ToPrettyString(coordinates.EntityId)}. Trace: {Environment.StackTrace}");
|
||||
@@ -176,12 +188,12 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
return audio;
|
||||
}
|
||||
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string 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(string 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);
|
||||
@@ -189,12 +201,12 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
return null;
|
||||
}
|
||||
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string 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(string 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);
|
||||
@@ -202,12 +214,12 @@ public sealed partial class AudioSystem : SharedAudioSystem
|
||||
return null;
|
||||
}
|
||||
|
||||
public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string 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(string 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);
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace Robust.Server
|
||||
[Dependency] private readonly IWatchdogApi _watchdogApi = default!;
|
||||
[Dependency] private readonly HubManager _hubManager = default!;
|
||||
[Dependency] private readonly IScriptHost _scriptHost = default!;
|
||||
[Dependency] private readonly IMetricsManager _metricsManager = default!;
|
||||
[Dependency] private readonly IMetricsManagerInternal _metricsManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IRobustMappedStringSerializer _stringSerializer = default!;
|
||||
[Dependency] private readonly ILocalizationManagerInternal _loc = default!;
|
||||
@@ -749,6 +749,8 @@ namespace Robust.Server
|
||||
_hubManager.Heartbeat();
|
||||
|
||||
_modLoader.BroadcastUpdate(ModUpdateLevel.FramePostEngine, frameEventArgs);
|
||||
|
||||
_metricsManager.FrameUpdate();
|
||||
}
|
||||
|
||||
void IPostInjectInit.PostInject()
|
||||
|
||||
@@ -66,7 +66,7 @@ public sealed class SpinCommand : LocalizedCommands
|
||||
}
|
||||
|
||||
var physicsSystem = _entities.System<SharedPhysicsSystem>();
|
||||
physicsSystem.SetAngularDamping(physics, drag);
|
||||
physicsSystem.SetAngularDamping(target.Value, physics, drag);
|
||||
physicsSystem.SetAngularVelocity(target.Value, speed, body: physics);
|
||||
}
|
||||
}
|
||||
|
||||
89
Robust.Server/DataMetrics/MetricsManager.Factory.cs
Normal file
89
Robust.Server/DataMetrics/MetricsManager.Factory.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Metrics;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Server.DataMetrics;
|
||||
|
||||
internal sealed partial class MetricsManager : IMeterFactory
|
||||
{
|
||||
private readonly Dictionary<string, List<CachedMeter>> _meterCache = new();
|
||||
private readonly object _meterCacheLock = new();
|
||||
|
||||
Meter IMeterFactory.Create(MeterOptions options)
|
||||
{
|
||||
if (options.Scope != null && options.Scope != this)
|
||||
throw new InvalidOperationException("Cannot specify a custom scope when creating a meter");
|
||||
|
||||
lock (_meterCacheLock)
|
||||
{
|
||||
if (LockedFindCachedMeter(options) is { } cached)
|
||||
return cached.Meter;
|
||||
|
||||
var meter = new Meter(options.Name, options.Version, options.Tags, this);
|
||||
var meterList = _meterCache.GetOrNew(options.Name);
|
||||
meterList.Add(new CachedMeter(options.Version, TagsToDict(options.Tags), meter));
|
||||
return meter;
|
||||
}
|
||||
}
|
||||
|
||||
private CachedMeter? LockedFindCachedMeter(MeterOptions options)
|
||||
{
|
||||
if (!_meterCache.TryGetValue(options.Name, out var metersList))
|
||||
return null;
|
||||
|
||||
var tagsDict = TagsToDict(options.Tags);
|
||||
|
||||
foreach (var cachedMeter in metersList)
|
||||
{
|
||||
if (cachedMeter.Version == options.Version && TagsMatch(tagsDict, cachedMeter.Tags))
|
||||
return cachedMeter;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool TagsMatch(Dictionary<string, object?> a, Dictionary<string, object?> b)
|
||||
{
|
||||
if (a.Count != b.Count)
|
||||
return false;
|
||||
|
||||
foreach (var (key, valueA) in a)
|
||||
{
|
||||
if (!b.TryGetValue(key, out var valueB))
|
||||
return false;
|
||||
|
||||
if (!Equals(valueA, valueB))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Dictionary<string, object?> TagsToDict(IEnumerable<KeyValuePair<string, object?>>? tags)
|
||||
{
|
||||
return tags?.ToDictionary() ?? [];
|
||||
}
|
||||
|
||||
private void DisposeMeters()
|
||||
{
|
||||
lock (_meterCacheLock)
|
||||
{
|
||||
foreach (var meters in _meterCache.Values)
|
||||
{
|
||||
foreach (var meter in meters)
|
||||
{
|
||||
meter.Meter.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class CachedMeter(string? version, Dictionary<string, object?> tags, Meter meter)
|
||||
{
|
||||
public readonly string? Version = version;
|
||||
public readonly Dictionary<string, object?> Tags = tags;
|
||||
public readonly Meter Meter = meter;
|
||||
}
|
||||
}
|
||||
@@ -18,13 +18,20 @@ internal sealed partial class MetricsManager
|
||||
private sealed class ManagedHttpListenerMetricsServer : MetricHandler
|
||||
{
|
||||
private readonly ISawmill _sawmill;
|
||||
private readonly Func<CancellationToken, Task>? _beforeCollect;
|
||||
private readonly HttpListener _listener;
|
||||
private readonly CollectorRegistry _registry;
|
||||
|
||||
public ManagedHttpListenerMetricsServer(ISawmill sawmill, string host, int port, string url = "metrics/",
|
||||
CollectorRegistry? registry = null)
|
||||
public ManagedHttpListenerMetricsServer(
|
||||
ISawmill sawmill,
|
||||
string host,
|
||||
int port,
|
||||
string url = "metrics/",
|
||||
CollectorRegistry? registry = null,
|
||||
Func<CancellationToken, Task>? beforeCollect = null)
|
||||
{
|
||||
_sawmill = sawmill;
|
||||
_beforeCollect = beforeCollect;
|
||||
_listener = new HttpListener();
|
||||
_listener.Prefixes.Add($"http://{host}:{port}/{url}");
|
||||
_registry = registry ?? Metrics.DefaultRegistry;
|
||||
@@ -57,6 +64,12 @@ internal sealed partial class MetricsManager
|
||||
{
|
||||
MetricsEvents.Log.ScrapeStart();
|
||||
|
||||
// prometheus-net does have a "before collect" callback of its own.
|
||||
// But it doesn't get ran before stuff like their System.Diagnostics.Metrics integration,
|
||||
// So I'm just gonna make my own here.
|
||||
if (_beforeCollect != null)
|
||||
await _beforeCollect(cancel);
|
||||
|
||||
var stream = resp.OutputStream;
|
||||
// prometheus-net is a terrible library and have to do all this insanity,
|
||||
// just to handle the ScrapeFailedException correctly.
|
||||
|
||||
62
Robust.Server/DataMetrics/MetricsManager.UpdateMetrics.cs
Normal file
62
Robust.Server/DataMetrics/MetricsManager.UpdateMetrics.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Asynchronous;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Robust.Server.DataMetrics;
|
||||
|
||||
internal sealed partial class MetricsManager
|
||||
{
|
||||
//
|
||||
// Handles the implementation of the "UpdateMetrics" callback.
|
||||
//
|
||||
|
||||
public event Action? UpdateMetrics;
|
||||
|
||||
private TimeSpan _fixedUpdateInterval;
|
||||
private TimeSpan _nextFixedUpdate;
|
||||
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
private void InitializeUpdateMetrics()
|
||||
{
|
||||
_cfg.OnValueChanged(
|
||||
CVars.MetricsUpdateInterval,
|
||||
seconds =>
|
||||
{
|
||||
_fixedUpdateInterval = TimeSpan.FromSeconds(seconds);
|
||||
_nextFixedUpdate = _gameTiming.RealTime + _fixedUpdateInterval;
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
public void FrameUpdate()
|
||||
{
|
||||
if (_fixedUpdateInterval == TimeSpan.Zero)
|
||||
return;
|
||||
|
||||
var time = _gameTiming.RealTime;
|
||||
|
||||
if (_nextFixedUpdate > time)
|
||||
return;
|
||||
|
||||
_nextFixedUpdate = time + _fixedUpdateInterval;
|
||||
|
||||
_sawmill.Verbose("Running fixed metrics update");
|
||||
UpdateMetrics?.Invoke();
|
||||
}
|
||||
|
||||
private async Task BeforeCollectCallback(CancellationToken cancel)
|
||||
{
|
||||
if (UpdateMetrics == null)
|
||||
return;
|
||||
|
||||
await _taskManager.TaskOnMainThread(() =>
|
||||
{
|
||||
UpdateMetrics?.Invoke();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,54 @@
|
||||
using System;
|
||||
using System.Diagnostics.Metrics;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Prometheus;
|
||||
using Prometheus.DotNetRuntime;
|
||||
using Prometheus.DotNetRuntime.Metrics.Producers;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Asynchronous;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using EventSource = System.Diagnostics.Tracing.EventSource;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Robust.Server.DataMetrics;
|
||||
|
||||
internal sealed partial class MetricsManager : IMetricsManager, IDisposable
|
||||
/// <summary>
|
||||
/// Manages OpenTelemetry metrics exposure.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// If enabled via <see cref="CVars.MetricsEnabled"/>, metrics about the game server are exposed via a HTTP server
|
||||
/// in an OpenTelemetry-compatible format (Prometheus).
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Metrics can be added through the types in <c>System.Diagnostics.Metrics</c> or <c>Prometheus</c>.
|
||||
/// IoC contains an implementation of <see cref="IMeterFactory"/> that can be used to instantiate meters.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public interface IMetricsManager
|
||||
{
|
||||
/// <summary>
|
||||
/// An event that gets raised on the main thread when complex metrics should be updated.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This event is raised on the main thread before a Prometheus collection happens,
|
||||
/// and also with a fixed interval if <see cref="CVars.MetricsUpdateInterval"/> is set.
|
||||
/// You can use it to update complex metrics that can't "just" be stuffed into a counter.
|
||||
/// </remarks>
|
||||
event Action UpdateMetrics;
|
||||
}
|
||||
|
||||
internal sealed partial class MetricsManager : IMetricsManagerInternal, IDisposable
|
||||
{
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
||||
[Dependency] private readonly ILogManager _logManager = default!;
|
||||
[Dependency] private readonly ITaskManager _taskManager = default!;
|
||||
|
||||
private bool _initialized;
|
||||
|
||||
@@ -55,6 +83,8 @@ internal sealed partial class MetricsManager : IMetricsManager, IDisposable
|
||||
{
|
||||
_cfg.OnValueChanged(cVar, _ => Reload());
|
||||
}
|
||||
|
||||
InitializeUpdateMetrics();
|
||||
}
|
||||
|
||||
private async Task Stop()
|
||||
@@ -73,6 +103,8 @@ internal sealed partial class MetricsManager : IMetricsManager, IDisposable
|
||||
|
||||
async void IDisposable.Dispose()
|
||||
{
|
||||
DisposeMeters();
|
||||
|
||||
await Stop();
|
||||
|
||||
_initialized = false;
|
||||
@@ -100,7 +132,12 @@ internal sealed partial class MetricsManager : IMetricsManager, IDisposable
|
||||
|
||||
_sawmill.Info("Prometheus metrics enabled, host: {1} port: {0}", port, host);
|
||||
var sawmill = Logger.GetSawmill("metrics.server");
|
||||
_metricServer = new ManagedHttpListenerMetricsServer(sawmill, host, port);
|
||||
_metricServer = new ManagedHttpListenerMetricsServer(
|
||||
sawmill,
|
||||
host,
|
||||
port,
|
||||
registry: Metrics.DefaultRegistry,
|
||||
beforeCollect: BeforeCollectCallback);
|
||||
_metricServer.Start();
|
||||
|
||||
if (_cfg.GetCVar(CVars.MetricsRuntime))
|
||||
@@ -190,7 +227,8 @@ internal sealed partial class MetricsManager : IMetricsManager, IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
internal interface IMetricsManager
|
||||
internal interface IMetricsManagerInternal : IMetricsManager
|
||||
{
|
||||
void Initialize();
|
||||
void FrameUpdate();
|
||||
}
|
||||
|
||||
@@ -280,6 +280,9 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
// Load the prototype data onto entities, e.g. transform parents, etc.
|
||||
LoadEntities(data);
|
||||
|
||||
// Assign MapSaveTileMapComponent to all read grids.
|
||||
SaveGridTileMap(data);
|
||||
|
||||
// Build the scene graph / transform hierarchy to know the order to startup entities.
|
||||
// This also allows us to swap out the root node up front if necessary.
|
||||
BuildEntityHierarchy(data);
|
||||
@@ -576,6 +579,19 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
meta.LastComponentRemoved = _timing.CurTick;
|
||||
}
|
||||
|
||||
private void SaveGridTileMap(MapData mapData)
|
||||
{
|
||||
DebugTools.Assert(_context.TileMap != null);
|
||||
|
||||
foreach (var entity in mapData.EntitiesToDeserialize.Keys)
|
||||
{
|
||||
if (HasComp<MapGridComponent>(entity))
|
||||
{
|
||||
EnsureComp<MapSaveTileMapComponent>(entity).TileMap = _context.TileMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildEntityHierarchy(MapData mapData)
|
||||
{
|
||||
_stopwatch.Restart();
|
||||
@@ -981,28 +997,74 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
var gridQuery = GetEntityQuery<MapGridComponent>();
|
||||
var tileDefs = new HashSet<int>();
|
||||
|
||||
Dictionary<int, string>? origTileMap = null;
|
||||
foreach (var ent in entities)
|
||||
{
|
||||
if (!gridQuery.TryGetComponent(ent, out var grid))
|
||||
continue;
|
||||
|
||||
var tileEnumerator = grid.GetAllTilesEnumerator(false);
|
||||
|
||||
var tileEnumerator = _mapSystem.GetAllTilesEnumerator(ent, grid, ignoreEmpty: false);
|
||||
while (tileEnumerator.MoveNext(out var tileRef))
|
||||
{
|
||||
tileDefs.Add(tileRef.Value.Tile.TypeId);
|
||||
}
|
||||
|
||||
if (TryComp(ent, out MapSaveTileMapComponent? saveTileMap))
|
||||
origTileMap ??= saveTileMap.TileMap;
|
||||
}
|
||||
|
||||
Dictionary<int, int> tileIdMap;
|
||||
if (origTileMap != null)
|
||||
{
|
||||
tileIdMap = new Dictionary<int, int>();
|
||||
|
||||
// We are re-saving a map, so we have an original tile map we can preserve.
|
||||
foreach (var (origId, prototypeId) in origTileMap)
|
||||
{
|
||||
// Skip removed tile definitions.
|
||||
if (!_tileDefManager.TryGetDefinition(prototypeId, out var definition))
|
||||
continue;
|
||||
|
||||
tileIdMap.Add(definition.TileId, origId);
|
||||
}
|
||||
|
||||
// Assign new IDs for all new tile types.
|
||||
var nextId = 0;
|
||||
foreach (var tileId in tileDefs)
|
||||
{
|
||||
if (tileIdMap.ContainsKey(tileId))
|
||||
continue;
|
||||
|
||||
// New tile, assign new ID that isn't taken by original tile map.
|
||||
while (origTileMap.ContainsKey(nextId))
|
||||
{
|
||||
nextId += 1;
|
||||
}
|
||||
|
||||
tileIdMap.Add(tileId, nextId);
|
||||
nextId += 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Make no-op tile ID map.
|
||||
tileIdMap = tileDefs.ToDictionary(x => x, x => x);
|
||||
}
|
||||
|
||||
DebugTools.Assert(
|
||||
tileIdMap.Count == tileIdMap.Values.Distinct().Count(),
|
||||
"Tile ID map has double mapped values??");
|
||||
|
||||
_context.TileWriteMap = tileIdMap;
|
||||
|
||||
var tileMap = new MappingDataNode();
|
||||
rootNode.Add("tilemap", tileMap);
|
||||
var ordered = new List<int>(tileDefs);
|
||||
ordered.Sort();
|
||||
|
||||
foreach (var tyleId in ordered)
|
||||
foreach (var (nativeId, mapId) in tileIdMap.OrderBy(x => x.Key))
|
||||
{
|
||||
var tileDef = _tileDefManager[tyleId];
|
||||
tileMap.Add(tyleId.ToString(CultureInfo.InvariantCulture), tileDef.ID);
|
||||
tileMap.Add(
|
||||
mapId.ToString(CultureInfo.InvariantCulture),
|
||||
_tileDefManager[nativeId].ID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1176,11 +1238,12 @@ public sealed class MapLoaderSystem : EntitySystem
|
||||
|
||||
foreach (var component in EntityManager.GetComponents(entityUid))
|
||||
{
|
||||
if (component is MapSaveIdComponent)
|
||||
var compType = component.GetType();
|
||||
var registration = _factory.GetRegistration(compType);
|
||||
if (registration.Unsaved)
|
||||
continue;
|
||||
|
||||
var compType = component.GetType();
|
||||
var compName = _factory.GetComponentName(compType);
|
||||
var compName = registration.Name;
|
||||
_context.CurrentComponent = compName;
|
||||
MappingDataNode? compMapping;
|
||||
MappingDataNode? protMapping = null;
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Robust.Server.GameObjects
|
||||
/// 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]
|
||||
[RegisterComponent, UnsavedComponent]
|
||||
public sealed partial class MapSaveIdComponent : Component
|
||||
{
|
||||
public int Uid { get; set; }
|
||||
|
||||
24
Robust.Server/GameObjects/MapSaveTileMapComponent.cs
Normal file
24
Robust.Server/GameObjects/MapSaveTileMapComponent.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Robust.Server.GameObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Used by <see cref="MapLoaderSystem"/> to track the original tile map from when a map was loaded.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This component is used to reduce differences on map saving, by making it so that a tile map can be re-used between map saves even if internal engine IDs change.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This component is created on every grid entity read during map load.
|
||||
/// This means loading a multi-grid map will create multiple of these components.
|
||||
/// When re-saving the map, the map loader will arbitrarily choose which available <see cref="MapSaveTileMapComponent"/>
|
||||
/// to use.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
[RegisterComponent, UnsavedComponent]
|
||||
internal sealed partial class MapSaveTileMapComponent : Component
|
||||
{
|
||||
public Dictionary<int, string> TileMap = [];
|
||||
}
|
||||
@@ -48,30 +48,17 @@ internal sealed partial class PvsSystem
|
||||
// We add chunk-size here so that its consistent with the normal PVS range setting.
|
||||
// I.e., distance here is the Chebyshev distance to the centre of each chunk, but the normal pvs range only
|
||||
// required that the chunk be touching the box, not the centre.
|
||||
var limit = distance < (_lowLodDistance + ChunkSize) / 2
|
||||
var count = distance <= (_viewSize + ChunkSize) / 2
|
||||
? chunk.Contents.Count
|
||||
: chunk.LodCounts[0];
|
||||
|
||||
// If the PVS budget is exceeded, it should still be safe to send all of the chunk's direct children, though
|
||||
// after that we have no guarantee that an entity's parent got sent.
|
||||
var directChildren = Math.Min(limit, chunk.LodCounts[2]);
|
||||
|
||||
// Send entities on the chunk.
|
||||
var span = CollectionsMarshal.AsSpan(chunk.Contents);
|
||||
for (var i = 0; i < limit; i++)
|
||||
var span = CollectionsMarshal.AsSpan(chunk.Contents)[..count];
|
||||
foreach (ref var ent in span)
|
||||
{
|
||||
var ent = span[i];
|
||||
ref var meta = ref _metadataMemory.GetRef(ent.Ptr.Index);
|
||||
|
||||
if ((mask & meta.VisMask) != meta.VisMask)
|
||||
continue;
|
||||
|
||||
// TODO PVS improve this somehow
|
||||
// Having entities "leave" pvs view just because the pvs entry budget was exceeded sucks.
|
||||
// This probably requires changing client game state manager to support receiving entities with unknown parents.
|
||||
// Probably needs to do something similar to pending net entity states, but for entity spawning.
|
||||
if (!AddEntity(session, ref ent, ref meta, fromTick))
|
||||
limit = directChildren;
|
||||
if ((mask & meta.VisMask) == meta.VisMask)
|
||||
AddEntity(session, ref ent, ref meta, fromTick);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,26 +67,26 @@ internal sealed partial class PvsSystem
|
||||
/// </summary>
|
||||
/// <returns>Returns false if the entity would exceed the client's PVS budget.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private bool AddEntity(PvsSession session, ref PvsChunk.ChunkEntity ent, ref PvsMetadata meta,
|
||||
private void AddEntity(PvsSession session, ref PvsChunk.ChunkEntity ent, ref PvsMetadata meta,
|
||||
GameTick fromTick)
|
||||
{
|
||||
DebugTools.Assert(fromTick < _gameTiming.CurTick);
|
||||
ref var data = ref session.DataMemory.GetRef(ent.Ptr.Index);
|
||||
|
||||
if (data.LastSeen == _gameTiming.CurTick)
|
||||
return true;
|
||||
return;
|
||||
|
||||
if (meta.LifeStage >= EntityLifeStage.Terminating)
|
||||
{
|
||||
Log.Error($"Attempted to send deleted entity: {ToPrettyString(ent.Uid)}");
|
||||
EntityManager.QueueDeleteEntity(ent.Uid);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
var (entered,budgetExceeded) = IsEnteringPvsRange(ref data, fromTick, ref session.Budget);
|
||||
|
||||
if (budgetExceeded)
|
||||
return false;
|
||||
return;
|
||||
|
||||
data.LastSeen = _gameTiming.CurTick;
|
||||
session.ToSend!.Add(ent.Ptr);
|
||||
@@ -108,25 +95,23 @@ internal sealed partial class PvsSystem
|
||||
{
|
||||
var state = GetFullEntityState(session.Session, ent.Uid, ent.Meta);
|
||||
session.States.Add(state);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (entered)
|
||||
{
|
||||
var state = GetEntityState(session.Session, ent.Uid, data.EntityLastAcked, ent.Meta);
|
||||
session.States.Add(state);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (meta.LastModifiedTick <= fromTick)
|
||||
return true;
|
||||
return;
|
||||
|
||||
var entState = GetEntityState(session.Session, ent.Uid, fromTick , ent.Meta);
|
||||
|
||||
if (!entState.Empty)
|
||||
session.States.Add(entState);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -62,12 +62,14 @@ internal sealed partial class PvsSystem : EntitySystem
|
||||
public bool CullingEnabled { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Size of the side of the view bounds square.
|
||||
/// Size of the side of the view bounds square. Related to <see cref="CVars.NetMaxUpdateRange"/>
|
||||
/// </summary>
|
||||
private float _viewSize;
|
||||
|
||||
// see CVars.NetLowLodDistance
|
||||
private float _lowLodDistance;
|
||||
/// <summary>
|
||||
/// Size of the side of the priority view bounds square. Related to <see cref="CVars.NetPvsPriorityRange"/>
|
||||
/// </summary>
|
||||
private float _priorityViewSize;
|
||||
|
||||
/// <summary>
|
||||
/// Per-tick ack data to avoid re-allocating.
|
||||
@@ -139,7 +141,7 @@ internal sealed partial class PvsSystem : EntitySystem
|
||||
|
||||
Subs.CVar(_configManager, CVars.NetPVS, SetPvs, true);
|
||||
Subs.CVar(_configManager, CVars.NetMaxUpdateRange, OnViewsizeChanged, true);
|
||||
Subs.CVar(_configManager, CVars.NetLowLodRange, OnLodChanged, true);
|
||||
Subs.CVar(_configManager, CVars.NetPvsPriorityRange, OnPriorityRangeChanged, true);
|
||||
Subs.CVar(_configManager, CVars.NetForceAckThreshold, OnForceAckChanged, true);
|
||||
Subs.CVar(_configManager, CVars.NetPvsAsync, OnAsyncChanged, true);
|
||||
Subs.CVar(_configManager, CVars.NetPvsCompressLevel, ResetParallelism, true);
|
||||
@@ -276,12 +278,13 @@ internal sealed partial class PvsSystem : EntitySystem
|
||||
|
||||
private void OnViewsizeChanged(float value)
|
||||
{
|
||||
_viewSize = value;
|
||||
_viewSize = Math.Max(ChunkSize, value);
|
||||
OnPriorityRangeChanged(_configManager.GetCVar(CVars.NetPvsPriorityRange));
|
||||
}
|
||||
|
||||
private void OnLodChanged(float value)
|
||||
private void OnPriorityRangeChanged(float value)
|
||||
{
|
||||
_lowLodDistance = Math.Clamp(value, ChunkSize, 100f);
|
||||
_priorityViewSize = Math.Max(_viewSize, value);
|
||||
}
|
||||
|
||||
private void OnForceAckChanged(int value)
|
||||
@@ -372,13 +375,6 @@ internal sealed partial class PvsSystem : EntitySystem
|
||||
{
|
||||
ref var data = ref pvsSession.DataMemory.GetRef(intPtr.Index);
|
||||
DebugTools.AssertEqual(data.LastSeen, _gameTiming.CurTick);
|
||||
|
||||
// if an entity is visible, its parents should always be visible.
|
||||
if (_xformQuery.GetComponent(GetEntity(IndexToNetEntity(intPtr))).ParentUid is not {Valid: true} pUid)
|
||||
continue;
|
||||
|
||||
DebugTools.Assert(toSendSet.Contains(GetNetEntity(pUid)),
|
||||
$"Attempted to send an entity without sending it's parents. Entity: {ToPrettyString(pUid)}.");
|
||||
}
|
||||
|
||||
pvsSession.PreviouslySent.TryGetValue(_gameTiming.CurTick - 1, out var lastSent);
|
||||
@@ -394,7 +390,7 @@ internal sealed partial class PvsSystem : EntitySystem
|
||||
|
||||
private (Vector2 worldPos, float range, EntityUid? map) CalcViewBounds(Entity<TransformComponent, EyeComponent?> eye)
|
||||
{
|
||||
var size = Math.Max(eye.Comp2?.PvsSize ?? _viewSize, 1);
|
||||
var size = Math.Max(eye.Comp2?.PvsSize ?? _priorityViewSize, 1);
|
||||
return (_transform.GetWorldPosition(eye.Comp1), size / 2f, eye.Comp1.MapUid);
|
||||
}
|
||||
|
||||
|
||||
@@ -104,12 +104,16 @@ internal sealed class MapChunkSerializer : ITypeSerializer<MapChunk, MappingData
|
||||
|
||||
root.Add("version", new ValueDataNode("6"));
|
||||
|
||||
gridNode.Value = SerializeTiles(value);
|
||||
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)
|
||||
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;
|
||||
@@ -125,7 +129,11 @@ internal sealed class MapChunkSerializer : ITypeSerializer<MapChunk, MappingData
|
||||
for (ushort x = 0; x < chunk.ChunkSize; x++)
|
||||
{
|
||||
var tile = chunk.GetTile(x, y);
|
||||
writer.Write(tile.TypeId);
|
||||
var typeId = tile.TypeId;
|
||||
if (tileWriteMap != null)
|
||||
typeId = tileWriteMap[typeId];
|
||||
|
||||
writer.Write(typeId);
|
||||
writer.Write((byte)tile.Flags);
|
||||
writer.Write(tile.Variant);
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ namespace Robust.Server.Physics
|
||||
grids.Add(foundSplits);
|
||||
}
|
||||
|
||||
var oldGrid = _mapManager.GetGrid(uid);
|
||||
var oldGrid = Comp<MapGridComponent>(uid);
|
||||
var oldGridUid = uid;
|
||||
|
||||
// Split time
|
||||
@@ -605,7 +605,7 @@ namespace Robust.Server.Physics
|
||||
|
||||
DebugTools.Assert(chunk.FilledTiles > 0);
|
||||
|
||||
var grid = _mapManager.GetGrid(gridEuid);
|
||||
var grid = Comp<MapGridComponent>(gridEuid);
|
||||
var group = CreateNodes(gridEuid, grid, chunk);
|
||||
_nodes[gridEuid][chunk.Indices] = group;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.ObjectPool" PrivateAssets="compile" />
|
||||
<PackageReference Include="SpaceWizards.Sodium" PrivateAssets="compile" />
|
||||
<PackageReference Include="SharpZstd.Interop" PrivateAssets="compile" />
|
||||
<PackageReference Condition="'$(FullRelease)' != 'True'" Include="JetBrains.Profiler.Api" />
|
||||
<PackageReference Condition="'$(RobustToolsBuild)' == 'True'" Include="JetBrains.Profiler.Api" />
|
||||
<PackageReference Include="Microsoft.NET.ILLink.Tasks" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics.Metrics;
|
||||
using Robust.Server.Configuration;
|
||||
using Robust.Server.Console;
|
||||
using Robust.Server.DataMetrics;
|
||||
@@ -80,6 +81,8 @@ namespace Robust.Server
|
||||
deps.Register<IWatchdogApi, WatchdogApi>();
|
||||
deps.Register<IScriptHost, ScriptHost>();
|
||||
deps.Register<IMetricsManager, MetricsManager>();
|
||||
deps.Register<IMetricsManagerInternal, MetricsManager>();
|
||||
deps.Register<IMeterFactory, MetricsManager>();
|
||||
deps.Register<IAuthManager, AuthManager>();
|
||||
deps.Register<HubManager, HubManager>();
|
||||
deps.Register<IRobustSerializer, ServerRobustSerializer>();
|
||||
|
||||
@@ -69,6 +69,12 @@ public sealed class PlayerCommand : ToolshedCommand
|
||||
{
|
||||
return sessions.AttachedEntity ?? default;
|
||||
}
|
||||
|
||||
[CommandImplementation("entity")]
|
||||
public EntityUid GetPlayerEntity([CommandInvocationContext] IInvocationContext ctx, [CommandArgument] string username)
|
||||
{
|
||||
return GetPlayerEntity(Immediate(ctx, username));
|
||||
}
|
||||
}
|
||||
|
||||
public record struct NoSuchPlayerError(string Username) : IConError
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Server.Console;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -296,7 +297,6 @@ namespace Robust.Server.ViewVariables
|
||||
|
||||
output = prototype;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Server.ViewVariables.Traits;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Network.Messages;
|
||||
@@ -96,6 +97,9 @@ namespace Robust.Server.ViewVariables
|
||||
if (value is EntityUid uid)
|
||||
return IoCManager.Resolve<IEntityManager>().GetComponentOrNull<MetaDataComponent>(uid)?.NetEntity ?? NetEntity.Invalid;
|
||||
|
||||
if (value is SoundSpecifier)
|
||||
return value;
|
||||
|
||||
var valType = value.GetType();
|
||||
if (!valType.IsValueType)
|
||||
{
|
||||
|
||||
@@ -59,6 +59,192 @@ public static class Vector2Helpers
|
||||
return length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares the lengths of two vectors.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Avoids square root computations by using squared lengths.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// a positive value if <paramref name="a"/> is longer than <paramref name="b"/>,
|
||||
/// a negative value if <paramref name="b"/> is longer than <paramref name="a"/>,
|
||||
/// or 0 if <paramref name="a"/> and <paramref name="b"/> have equal lengths.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float CompareLength(Vector2 a, Vector2 b)
|
||||
{
|
||||
return a.LengthSquared() - b.LengthSquared();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares the length of a vector with a scalar.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Avoids a square root computation by using squared length.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// a positive value if <paramref name="vec"/> is longer than <paramref name="scalar"/>,
|
||||
/// a negative value if <paramref name="vec"/> is shorter than <paramref name="scalar"/>,
|
||||
/// or 0 if <paramref name="vec"/> has a length equal to <paramref name="scalar"/>.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float CompareLength(Vector2 vec, float scalar)
|
||||
{
|
||||
return vec.LengthSquared() - (scalar * scalar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares the length of this vector with a scalar.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Avoids a square root computation by using squared length.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// a positive value if this vector is longer than <paramref name="scalar"/>,
|
||||
/// a negative value if this vector is shorter than <paramref name="scalar"/>,
|
||||
/// or 0 if this vector has a length equal to <paramref name="scalar"/>.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float CompareLengthTo(this Vector2 vec, float scalar)
|
||||
{
|
||||
return CompareLength(vec, scalar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares the length of this vector with another.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Avoids square root computations by using squared lengths.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// a positive value if this vector is longer than <paramref name="otherVec"/>,
|
||||
/// a negative value if this vector is shorter than <paramref name="otherVec"/>,
|
||||
/// or 0 if this vector and <paramref name="otherVec"/> have equal lengths.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float CompareLengthTo(this Vector2 thisVec, Vector2 otherVec)
|
||||
{
|
||||
return CompareLength(thisVec, otherVec);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is the length of this vector greater than <paramref name="scalar"/>?
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsLongerThan(this Vector2 vec, float scalar)
|
||||
{
|
||||
return CompareLength(vec, scalar) > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is the length of this vector greater than the length of <paramref name="otherVec"/>?
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsLongerThan(this Vector2 thisVec, Vector2 otherVec)
|
||||
{
|
||||
return CompareLength(thisVec, otherVec) > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is the length of this vector greater than or equal to <paramref name="scalar"/>?
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsLongerThanOrEqualTo(this Vector2 vec, float scalar)
|
||||
{
|
||||
return CompareLength(vec, scalar) >= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is the length of this vector greater than or equal to the length of <paramref name="otherVec"/>?
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsLongerThanOrEqualTo(this Vector2 thisVec, Vector2 otherVec)
|
||||
{
|
||||
return CompareLength(thisVec, otherVec) >= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is the length of this vector less than <paramref name="scalar"/>?
|
||||
/// </summary>
|
||||
/// <param name="vec"></param>
|
||||
/// <param name="scalar"></param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsShorterThan(this Vector2 vec, float scalar)
|
||||
{
|
||||
return CompareLength(vec, scalar) < 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is the length of this vector less than the length of <paramref name="otherVec"/>?
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsShorterThan(this Vector2 thisVec, Vector2 otherVec)
|
||||
{
|
||||
return CompareLength(thisVec, otherVec) < 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is the length of this vector less than or equal to <paramref name="scalar"/>?
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsShorterThanOrEqualTo(this Vector2 vec, float scalar)
|
||||
{
|
||||
return CompareLength(vec, scalar) <= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is the length of this vector less than or equal to the length of <paramref name="otherVec"/>?
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsShorterThanOrEqualTo(this Vector2 thisVec, Vector2 otherVec)
|
||||
{
|
||||
return CompareLength(thisVec, otherVec) <= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if this vector's length is equal to <paramref name="scalar"/>.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool LengthEquals(this Vector2 thisVec, float scalar)
|
||||
{
|
||||
return CompareLength(thisVec, scalar) == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is this vector the same length as <paramref name="otherVec"/>?
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsEqualLengthTo(this Vector2 thisVec, Vector2 otherVec)
|
||||
{
|
||||
return CompareLength(thisVec, otherVec) == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares the length of a vector with a scalar.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Avoids a square root computation by using squared length.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// a positive value if <paramref name="vec"/> is shorter than <paramref name="scalar"/>,
|
||||
/// a negative value if <paramref name="vec"/> is longer than <paramref name="scalar"/>,
|
||||
/// or 0 if <paramref name="vec"/> has a length equal to <paramref name="scalar"/>.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float CompareLength(float scalar, Vector2 vec)
|
||||
{
|
||||
return (scalar * scalar) - vec.LengthSquared();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is the length of this vector zero?
|
||||
/// </summary>
|
||||
public static bool IsLengthZero(this Vector2 vec)
|
||||
{
|
||||
return vec.LengthSquared() == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform the cross product on a scalar and a vector. In 2D this produces
|
||||
/// a vector.
|
||||
|
||||
@@ -67,12 +67,12 @@ namespace Robust.Shared.Scripting
|
||||
|
||||
public MapGridComponent getgrid(int i)
|
||||
{
|
||||
return map.GetGrid(new EntityUid(i));
|
||||
return ent.GetComponent<MapGridComponent>(new EntityUid(i));
|
||||
}
|
||||
|
||||
public MapGridComponent getgrid(EntityUid mapId)
|
||||
{
|
||||
return map.GetGrid(mapId);
|
||||
return ent.GetComponent<MapGridComponent>(mapId);
|
||||
}
|
||||
|
||||
public T res<T>()
|
||||
|
||||
@@ -74,4 +74,31 @@ namespace Robust.Shared.Asynchronous
|
||||
/// </remarks>
|
||||
void BlockWaitOnTask(Task task);
|
||||
}
|
||||
|
||||
internal static class TaskManagerExt
|
||||
{
|
||||
/// <summary>
|
||||
/// Run a callback on the main thread, returning a task that represents its completion.
|
||||
/// </summary>
|
||||
/// <seealso cref="ITaskManager.RunOnMainThread"/>
|
||||
public static Task TaskOnMainThread(this ITaskManager taskManager, Action callback)
|
||||
{
|
||||
var tcs = new TaskCompletionSource();
|
||||
|
||||
taskManager.RunOnMainThread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
callback();
|
||||
tcs.SetResult();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
tcs.TrySetException(e);
|
||||
}
|
||||
});
|
||||
|
||||
return tcs.Task;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,12 +29,6 @@ namespace Robust.Shared.Audio
|
||||
[DataDefinition]
|
||||
public partial struct AudioParams
|
||||
{
|
||||
/// <summary>
|
||||
/// The DistanceModel to use for this specific source.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public Attenuation Attenuation { get; set; } = Attenuation.LinearDistanceClamped;
|
||||
|
||||
/// <summary>
|
||||
/// Base volume to play the audio at, in dB.
|
||||
/// </summary>
|
||||
@@ -45,13 +39,13 @@ namespace Robust.Shared.Audio
|
||||
/// Scale for the audio pitch.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public float Pitch { get; set; } = Default.Pitch;
|
||||
public float Pitch
|
||||
{
|
||||
get => _pitch;
|
||||
set => _pitch = MathF.Max(0f, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Audio bus to play on.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string BusName { get; set; } = Default.BusName;
|
||||
private float _pitch = Default.Pitch;
|
||||
|
||||
/// <summary>
|
||||
/// Only applies to positional audio.
|
||||
@@ -89,7 +83,7 @@ namespace Robust.Shared.Audio
|
||||
/// <summary>
|
||||
/// The "default" audio configuration.
|
||||
/// </summary>
|
||||
public static readonly AudioParams Default = new(0, 1, "Master", SharedAudioSystem.DefaultSoundRange, 1, 1, false, 0f);
|
||||
public static readonly AudioParams Default = new(0, 1, SharedAudioSystem.DefaultSoundRange, 1, 1, false, 0f);
|
||||
|
||||
// explicit parameterless constructor required so that default values get set properly.
|
||||
public AudioParams() { }
|
||||
@@ -97,21 +91,19 @@ namespace Robust.Shared.Audio
|
||||
public AudioParams(
|
||||
float volume,
|
||||
float pitch,
|
||||
string busName,
|
||||
float maxDistance,
|
||||
float refDistance,
|
||||
bool loop,
|
||||
float playOffsetSeconds,
|
||||
float? variation = null)
|
||||
: this(volume, pitch, busName, maxDistance, 1, refDistance, loop, playOffsetSeconds, variation)
|
||||
: this(volume, pitch, maxDistance, 1, refDistance, loop, playOffsetSeconds, variation)
|
||||
{
|
||||
}
|
||||
|
||||
public AudioParams(float volume, float pitch, string busName, float maxDistance,float rolloffFactor, float refDistance, bool loop, float playOffsetSeconds, float? variation = null) : this()
|
||||
public AudioParams(float volume, float pitch, float maxDistance,float rolloffFactor, float refDistance, bool loop, float playOffsetSeconds, float? variation = null) : this()
|
||||
{
|
||||
Volume = volume;
|
||||
Pitch = pitch;
|
||||
BusName = busName;
|
||||
MaxDistance = maxDistance;
|
||||
RolloffFactor = rolloffFactor;
|
||||
ReferenceDistance = refDistance;
|
||||
@@ -167,18 +159,6 @@ namespace Robust.Shared.Audio
|
||||
return me;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of this instance with a new bus name set, for easy chaining.
|
||||
/// </summary>
|
||||
/// <param name="bus">The new bus name.</param>
|
||||
[Pure]
|
||||
public readonly AudioParams WithBusName(string bus)
|
||||
{
|
||||
var me = this;
|
||||
me.BusName = bus;
|
||||
return me;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of this instance with a new max distance set, for easy chaining.
|
||||
/// </summary>
|
||||
@@ -227,18 +207,6 @@ namespace Robust.Shared.Audio
|
||||
return me;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of this instance with attenuation set, for easy chaining.
|
||||
/// </summary>
|
||||
/// <param name="attenuation">The new attenuation.</param>
|
||||
[Pure]
|
||||
public readonly AudioParams WithAttenuation(Attenuation attenuation)
|
||||
{
|
||||
var me = this;
|
||||
me.Attenuation = attenuation;
|
||||
return me;
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public readonly AudioParams WithPlayOffset(float offset)
|
||||
{
|
||||
|
||||
@@ -234,7 +234,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>
|
||||
[return: NotNullIfNotNull("filename")]
|
||||
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string 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.
|
||||
@@ -253,7 +253,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>
|
||||
[return: NotNullIfNotNull("filename")]
|
||||
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string 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.
|
||||
@@ -274,7 +274,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>
|
||||
[return: NotNullIfNotNull("filename")]
|
||||
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string 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.
|
||||
@@ -294,7 +294,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
|
||||
/// <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>
|
||||
[return: NotNullIfNotNull("filename")]
|
||||
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string 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.
|
||||
@@ -303,7 +303,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
|
||||
/// <param name="recipient">The player that will hear the sound.</param>
|
||||
/// <param name="uid">The UID of the entity "emitting" the audio.</param>
|
||||
[return: NotNullIfNotNull("filename")]
|
||||
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string 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.
|
||||
@@ -312,7 +312,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
|
||||
/// <param name="recipient">The player that will hear the sound.</param>
|
||||
/// <param name="uid">The UID of the entity "emitting" the audio.</param>
|
||||
[return: NotNullIfNotNull("filename")]
|
||||
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string 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.
|
||||
@@ -378,7 +378,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
|
||||
/// <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>
|
||||
[return: NotNullIfNotNull("filename")]
|
||||
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(string filename,
|
||||
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(string? filename,
|
||||
EntityCoordinates coordinates, AudioParams? audioParams = null);
|
||||
|
||||
/// <summary>
|
||||
@@ -387,7 +387,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
|
||||
/// <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>
|
||||
[return: NotNullIfNotNull("filename")]
|
||||
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(string filename, EntityUid uid,
|
||||
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(string? filename, EntityUid uid,
|
||||
AudioParams? audioParams = null);
|
||||
|
||||
/// <summary>
|
||||
@@ -419,7 +419,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
|
||||
/// <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>
|
||||
[return: NotNullIfNotNull("filename")]
|
||||
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string 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.
|
||||
@@ -428,7 +428,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
|
||||
/// <param name="recipient">The player that will hear the sound.</param>
|
||||
/// <param name="coordinates">The coordinates at which to play the audio.</param>
|
||||
[return: NotNullIfNotNull("filename")]
|
||||
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string 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.
|
||||
@@ -437,7 +437,7 @@ public abstract partial class SharedAudioSystem : EntitySystem
|
||||
/// <param name="recipient">The player that will hear the sound.</param>
|
||||
/// <param name="coordinates">The coordinates at which to play the audio.</param>
|
||||
[return: NotNullIfNotNull("filename")]
|
||||
public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string 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.
|
||||
|
||||
@@ -65,16 +65,26 @@ namespace Robust.Shared
|
||||
CVarDef.Create("net.pool_size", 512, CVar.CLIENT | CVar.SERVER);
|
||||
|
||||
/// <summary>
|
||||
/// Maximum UDP payload size to send.
|
||||
/// Maximum UDP payload size to send by default, for IPv4.
|
||||
/// </summary>
|
||||
/// <seealso cref="NetMtuExpand"/>
|
||||
/// <seealso cref="NetMtuIpv6"/>
|
||||
public static readonly CVarDef<int> NetMtu =
|
||||
CVarDef.Create("net.mtu", 1000, CVar.ARCHIVE);
|
||||
CVarDef.Create("net.mtu", 900, CVar.ARCHIVE);
|
||||
|
||||
/// <summary>
|
||||
/// Maximum UDP payload size to send by default, for IPv6.
|
||||
/// </summary>
|
||||
/// <seealso cref="NetMtu"/>
|
||||
/// <seealso cref="NetMtuExpand"/>
|
||||
public static readonly CVarDef<int> NetMtuIpv6 =
|
||||
CVarDef.Create("net.mtu_ipv6", NetPeerConfiguration.kDefaultMTUV6, CVar.ARCHIVE);
|
||||
|
||||
/// <summary>
|
||||
/// If set, automatically try to detect MTU above <see cref="NetMtu"/>.
|
||||
/// </summary>
|
||||
/// <seealso cref="NetMtu"/>
|
||||
/// <seealso cref="NetMtuIpv6"/>
|
||||
/// <seealso cref="NetMtuExpandFrequency"/>
|
||||
/// <seealso cref="NetMtuExpandFailAttempts"/>
|
||||
public static readonly CVarDef<bool> NetMtuExpand =
|
||||
@@ -215,18 +225,24 @@ namespace Robust.Shared
|
||||
CVarDef.Create("net.pvs_async", true, CVar.ARCHIVE | CVar.SERVERONLY);
|
||||
|
||||
/// <summary>
|
||||
/// View size to take for PVS calculations,
|
||||
/// as the size of the sides of a square centered on the view points of clients.
|
||||
/// View size to take for PVS calculations, as the size of the sides of a square centered on the view points of
|
||||
/// clients. See also <see cref="NetPvsPriorityRange"/>.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<float> NetMaxUpdateRange =
|
||||
CVarDef.Create("net.pvs_range", 25f, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
|
||||
|
||||
/// <summary>
|
||||
/// Chunks whose centre is further than this distance away from a player's eye will contain fewer entities.
|
||||
/// This has no effect if it is smaller than <see cref="NetMaxUpdateRange"/>
|
||||
/// A variant of <see cref="NetMaxUpdateRange"/> that is used to limit the view-distance of entities with the
|
||||
/// <see cref="MetaDataFlags.PvsPriority"/> flag set. This can be used to extend the range at which certain
|
||||
/// entities become visible.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<float> NetLowLodRange =
|
||||
CVarDef.Create("net.low_lod_distance", 100f, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
|
||||
/// <remarks>
|
||||
/// This is useful for entities like lights and occluders to try and prevent noticeable pop-in as players
|
||||
/// move around. Note that this has no effect if it is less than <see cref="NetMaxUpdateRange"/>, and that this
|
||||
/// only works for entities that are directly parented to a grid or map.
|
||||
/// </remarks>
|
||||
public static readonly CVarDef<float> NetPvsPriorityRange =
|
||||
CVarDef.Create("net.pvs_priority_range", 32.5f, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
|
||||
|
||||
/// <summary>
|
||||
/// Maximum allowed delay between the current tick and a client's last acknowledged tick before we send the
|
||||
@@ -416,6 +432,35 @@ namespace Robust.Shared
|
||||
public static readonly CVarDef<int> MetricsPort =
|
||||
CVarDef.Create("metrics.port", 44880, CVar.SERVERONLY);
|
||||
|
||||
/// <summary>
|
||||
/// Sets a fixed interval (seconds) for internal collection of certain metrics,
|
||||
/// when not using the Prometheus metrics server.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Most metrics are internally implemented directly via the prometheus-net library.
|
||||
/// These metrics can only be scraped by the Prometheus metrics server (<see cref="MetricsEnabled"/>).
|
||||
/// However, newer metrics are implemented with the <c>System.Diagnostics.Metrics</c> library in the .NET runtime.
|
||||
/// These metrics can be scraped through more means, such as <c>dotnet counters</c>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// While many metrics are simple counters that can "just" be reported,
|
||||
/// some metrics require more advanced internal work and need some code to be ran internally
|
||||
/// before their values are made current. When collecting metrics via a
|
||||
/// method other than the Prometheus metrics server, these metrics pose a problem,
|
||||
/// as there is no way for the game to update them before collection properly.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This CVar acts as a fallback: if set to a value other than 0 (disabled),
|
||||
/// these metrics will be internally updated at the interval provided.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This does not need to be enabled if metrics are collected exclusively via the Prometheus metrics server.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public static readonly CVarDef<float> MetricsUpdateInterval =
|
||||
CVarDef.Create("metrics.update_interval", 0f, CVar.SERVERONLY);
|
||||
|
||||
/// <summary>
|
||||
/// Enable detailed runtime metrics. Empty to disable.
|
||||
/// </summary>
|
||||
@@ -841,6 +886,22 @@ namespace Robust.Shared
|
||||
public static readonly CVarDef<string> RenderFOVColor =
|
||||
CVarDef.Create("render.fov_color", Color.Black.ToHex(), CVar.ARCHIVE | CVar.CLIENTONLY);
|
||||
|
||||
/*
|
||||
* CONTROLS
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// Milliseconds to wait to consider double-click delays.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<int> DoubleClickDelay =
|
||||
CVarDef.Create("controls.double_click_delay", 250, CVar.ARCHIVE | CVar.CLIENTONLY);
|
||||
|
||||
/// <summary>
|
||||
/// Range in pixels for double-clicks
|
||||
/// </summary>
|
||||
public static readonly CVarDef<int> DoubleClickRange =
|
||||
CVarDef.Create("controls.double_click_range", 10, CVar.ARCHIVE | CVar.CLIENTONLY);
|
||||
|
||||
/*
|
||||
* DISPLAY
|
||||
*/
|
||||
@@ -1611,7 +1672,8 @@ namespace Robust.Shared
|
||||
/// original exception rather than sending people on a wild-goose chase to find a non-existent bug.
|
||||
/// </remarks>
|
||||
public static readonly CVarDef<bool> ReplayIgnoreErrors =
|
||||
CVarDef.Create("replay.ignore_errors", false, CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
CVarDef.Create("replay.ignore_errors", false, CVar.CLIENTONLY);
|
||||
|
||||
/*
|
||||
* CFG
|
||||
*/
|
||||
|
||||
@@ -607,4 +607,12 @@ public struct ValueList<T> : IEnumerable<T>
|
||||
region.Clear();
|
||||
Count = newCount;
|
||||
}
|
||||
|
||||
public void AddRange(IEnumerable<T> select)
|
||||
{
|
||||
foreach (var result in select)
|
||||
{
|
||||
Add(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
@@ -12,11 +12,16 @@ internal sealed class DumpSerializerTypeMapCommand : LocalizedCommands
|
||||
|
||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
foreach (var (type, index) in _robustSerializer.GetTypeMap().OrderBy(x => x.Value))
|
||||
{
|
||||
shell.WriteLine($"{index}: {type}");
|
||||
}
|
||||
var stream = new MemoryStream();
|
||||
((RobustSerializer)_robustSerializer).GetHashManifest(stream, true);
|
||||
stream.Position = 0;
|
||||
|
||||
using var streamReader = new StreamReader(stream);
|
||||
shell.WriteLine($"Hash: {_robustSerializer.GetSerializableTypesHashString()}");
|
||||
shell.WriteLine("Manifest:");
|
||||
while (streamReader.ReadLine() is { } line)
|
||||
{
|
||||
shell.WriteLine(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ sealed class RemoveGridCommand : LocalizedCommands
|
||||
|
||||
var gridIdNet = NetEntity.Parse(args[0]);
|
||||
|
||||
if (!_entManager.TryGetEntity(gridIdNet, out var gridId) || !_map.GridExists(gridId))
|
||||
if (!_entManager.TryGetEntity(gridIdNet, out var gridId) || !_entManager.HasComponent<MapGridComponent>(gridId))
|
||||
{
|
||||
shell.WriteError($"Grid {gridId} does not exist.");
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Collections;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -23,7 +26,34 @@ public static class CompletionHelper
|
||||
public static IEnumerable<CompletionOption> Booleans => new[]
|
||||
{ new CompletionOption(bool.FalseString), new CompletionOption(bool.TrueString) };
|
||||
|
||||
public static IEnumerable<CompletionOption> ContentFilePath(string arg, IResourceManager res)
|
||||
/// <summary>
|
||||
/// Special-cased file handler for audio that accounts for serverside completion.
|
||||
/// </summary>
|
||||
public static IEnumerable<CompletionOption> AudioFilePath(string arg, IPrototypeManager protoManager,
|
||||
IResourceManager res)
|
||||
{
|
||||
var resPath = GetUpdatedPath(arg);
|
||||
var paths = new HashSet<string>();
|
||||
|
||||
foreach (var path in res.ContentGetDirectoryEntries(resPath))
|
||||
{
|
||||
paths.Add(path);
|
||||
}
|
||||
|
||||
foreach (var audioProto in protoManager.EnumeratePrototypes<AudioMetadataPrototype>())
|
||||
{
|
||||
var hero = new ResPath(audioProto.ID);
|
||||
|
||||
if (!hero.TryRelativeTo(resPath, out _))
|
||||
continue;
|
||||
|
||||
paths.Add(hero.GetNextSegment(resPath).ToString());
|
||||
}
|
||||
|
||||
return GetPaths(resPath, paths, res);
|
||||
}
|
||||
|
||||
private static ResPath GetUpdatedPath(string arg)
|
||||
{
|
||||
var curPath = arg;
|
||||
if (!curPath.StartsWith("/"))
|
||||
@@ -31,12 +61,18 @@ public static class CompletionHelper
|
||||
|
||||
var resPath = new ResPath(curPath);
|
||||
|
||||
if (!curPath.EndsWith("/")){
|
||||
if (!curPath.EndsWith("/"))
|
||||
{
|
||||
resPath /= "..";
|
||||
resPath = resPath.Clean();
|
||||
}
|
||||
|
||||
var options = res.ContentGetDirectoryEntries(resPath)
|
||||
return resPath;
|
||||
}
|
||||
|
||||
private static IEnumerable<CompletionOption> GetPaths(ResPath resPath, IEnumerable<string> inputs, IResourceManager res)
|
||||
{
|
||||
var options = inputs
|
||||
.OrderBy(c => c)
|
||||
.Select(c =>
|
||||
{
|
||||
@@ -51,6 +87,12 @@ public static class CompletionHelper
|
||||
return options;
|
||||
}
|
||||
|
||||
public static IEnumerable<CompletionOption> ContentFilePath(string arg, IResourceManager res)
|
||||
{
|
||||
var resPath = GetUpdatedPath(arg);
|
||||
return GetPaths(resPath, res.ContentGetDirectoryEntries(resPath), res);
|
||||
}
|
||||
|
||||
public static IEnumerable<CompletionOption> ContentDirPath(string arg, IResourceManager res)
|
||||
{
|
||||
var curPath = arg;
|
||||
|
||||
@@ -38,7 +38,7 @@ public sealed record CompletionResult(CompletionOption[] Options, string? Hint)
|
||||
/// <summary>
|
||||
/// Possible option to tab-complete in a <see cref="CompletionResult"/>.
|
||||
/// </summary>
|
||||
public record struct CompletionOption(string Value, string? Hint = null, CompletionOptionFlags Flags = default)
|
||||
public record struct CompletionOption(string Value, string? Hint = null, CompletionOptionFlags Flags = default) : IComparable<CompletionOption>
|
||||
{
|
||||
/// <summary>
|
||||
/// The value that will be filled in if completed.
|
||||
@@ -54,6 +54,12 @@ public record struct CompletionOption(string Value, string? Hint = null, Complet
|
||||
/// Flags that control how this completion is used.
|
||||
/// </summary>
|
||||
public CompletionOptionFlags Flags { get; set; } = Flags;
|
||||
|
||||
public int CompareTo(CompletionOption other)
|
||||
{
|
||||
var valueComparison = string.Compare(Value, other.Value, StringComparison.CurrentCultureIgnoreCase);
|
||||
return valueComparison;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,15 +1,46 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Robust.Shared.Enums
|
||||
namespace Robust.Shared.Enums;
|
||||
|
||||
public sealed class PlacementInformation
|
||||
{
|
||||
public sealed class PlacementInformation
|
||||
{
|
||||
public string? EntityType { get; set; }
|
||||
public bool IsTile { get; set; }
|
||||
public EntityUid MobUid { get; set; }
|
||||
public string? PlacementOption { get; set; }
|
||||
public int Range { get; set; }
|
||||
public int TileType { get; set; }
|
||||
public int Uses { get; set; } = 1;
|
||||
}
|
||||
/// <summary>
|
||||
/// Entity prototype to be placed
|
||||
/// </summary>
|
||||
public string? EntityType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indiciates if the entity prototype to be placed is in fact a tile
|
||||
/// </summary>
|
||||
public bool IsTile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ID of the mob that has permission to place the prototype
|
||||
/// </summary>
|
||||
public EntityUid MobUid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the placement alignment
|
||||
/// </summary>
|
||||
public string? PlacementOption { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines the max range at which the entity prototype can be placed
|
||||
/// </summary>
|
||||
public int Range { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int TileType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of times the entity can be placed
|
||||
/// </summary>
|
||||
public int Uses { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether the input context should switch to 'editor' mode
|
||||
/// </summary>
|
||||
public bool UseEditorContext { get; set; } = true;
|
||||
}
|
||||
|
||||
28
Robust.Shared/GameObjects/ComponentAttributes.cs
Normal file
28
Robust.Shared/GameObjects/ComponentAttributes.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Robust.Shared.GameObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Marks a component as being automatically registered by <see cref="IComponentFactory.DoAutoRegistrations" />
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
||||
[BaseTypeRequired(typeof(IComponent))]
|
||||
[MeansImplicitUse]
|
||||
public sealed class RegisterComponentAttribute : Attribute;
|
||||
|
||||
/// <summary>
|
||||
/// Defines Name that this component is represented with in prototypes.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public sealed class ComponentProtoNameAttribute(string prototypeName) : Attribute
|
||||
{
|
||||
public string PrototypeName { get; } = prototypeName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks a component as not being saved when saving maps/grids.
|
||||
/// </summary>
|
||||
/// <seealso cref="ComponentRegistration.Unsaved"/>
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
||||
public sealed class UnsavedComponentAttribute : Attribute;
|
||||
@@ -121,9 +121,11 @@ namespace Robust.Shared.GameObjects
|
||||
if (!overwrite && lowerCaseNames.TryGetValue(lowerCaseName, out var prevName))
|
||||
throw new InvalidOperationException($"{lowerCaseName} is already registered, previous: {prevName}");
|
||||
|
||||
var unsaved = type.HasCustomAttribute<UnsavedComponentAttribute>();
|
||||
|
||||
var idx = CompIdx.Index(type);
|
||||
|
||||
var registration = new ComponentRegistration(name, type, idx);
|
||||
var registration = new ComponentRegistration(name, type, idx, unsaved);
|
||||
|
||||
idxToType[idx] = type;
|
||||
names[name] = registration;
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines Name that this component is represented with in prototypes.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public sealed class ComponentProtoNameAttribute : Attribute
|
||||
{
|
||||
public string PrototypeName { get; }
|
||||
|
||||
public ComponentProtoNameAttribute(string prototypeName)
|
||||
{
|
||||
PrototypeName = prototypeName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,12 @@ public sealed class ComponentRegistration
|
||||
|
||||
public CompIdx Idx { get; }
|
||||
|
||||
/// <summary>
|
||||
/// If this is true, the component will not be saved when saving a map/grid.
|
||||
/// </summary>
|
||||
/// <seealso cref="UnsavedComponentAttribute"/>
|
||||
public bool Unsaved { get; }
|
||||
|
||||
/// <summary>
|
||||
/// ID used to reference the component type across the network.
|
||||
/// If null, no network synchronization will be available for this component.
|
||||
@@ -35,11 +41,12 @@ public sealed class ComponentRegistration
|
||||
|
||||
// Internal for sandboxing.
|
||||
// Avoid content passing an instance of this to ComponentFactory to get any type they want instantiated.
|
||||
internal ComponentRegistration(string name, Type type, CompIdx idx)
|
||||
internal ComponentRegistration(string name, Type type, CompIdx idx, bool unsaved = false)
|
||||
{
|
||||
Name = name;
|
||||
Type = type;
|
||||
Idx = idx;
|
||||
Unsaved = unsaved;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
||||
@@ -11,6 +11,7 @@ using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
#if EXCEPTION_TOLERANCE
|
||||
@@ -176,6 +177,60 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void AddComponents(EntityUid target, EntityPrototype prototype, bool removeExisting = true)
|
||||
{
|
||||
AddComponents(target, prototype.Components, removeExisting);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void AddComponents(EntityUid target, ComponentRegistry registry, bool removeExisting = true)
|
||||
{
|
||||
if (registry.Count == 0)
|
||||
return;
|
||||
|
||||
var metadata = MetaQuery.GetComponent(target);
|
||||
|
||||
foreach (var (name, entry) in registry)
|
||||
{
|
||||
var reg = _componentFactory.GetRegistration(name);
|
||||
|
||||
if (HasComponent(target, reg.Type))
|
||||
{
|
||||
if (!removeExisting)
|
||||
continue;
|
||||
|
||||
RemoveComponent(target, reg.Type, metadata);
|
||||
}
|
||||
|
||||
var comp = _componentFactory.GetComponent(reg);
|
||||
_serManager.CopyTo(entry.Component, ref comp, notNullableOverride: true);
|
||||
AddComponent(target, comp, metadata: metadata);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void RemoveComponents(EntityUid target, EntityPrototype prototype)
|
||||
{
|
||||
RemoveComponents(target, prototype.Components);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void RemoveComponents(EntityUid target, ComponentRegistry registry)
|
||||
{
|
||||
if (registry.Count == 0)
|
||||
return;
|
||||
|
||||
var metadata = MetaQuery.GetComponent(target);
|
||||
|
||||
foreach (var entry in registry.Values)
|
||||
{
|
||||
RemoveComponent(target, entry.Component.GetType(), metadata);
|
||||
}
|
||||
}
|
||||
|
||||
public IComponent AddComponent(EntityUid uid, ushort netId, MetaDataComponent? meta = null)
|
||||
{
|
||||
var newComponent = _componentFactory.GetComponent(netId);
|
||||
@@ -1452,6 +1507,24 @@ namespace Robust.Shared.GameObjects
|
||||
return false;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[Pure]
|
||||
public bool TryComp(EntityUid uid, [NotNullWhen(true)] out TComp1? component)
|
||||
=> TryGetComponent(uid, out component);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[Pure]
|
||||
public bool TryComp(EntityUid? uid, [NotNullWhen(true)] out TComp1? component)
|
||||
=> TryGetComponent(uid, out component);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[Pure]
|
||||
public bool HasComp(EntityUid uid) => HasComponent(uid);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[Pure]
|
||||
public bool HasComp(EntityUid? uid) => HasComponent(uid);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[Pure]
|
||||
public bool HasComponent(EntityUid uid)
|
||||
|
||||
@@ -354,7 +354,7 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[Obsolete("use override with an EntityUid")]
|
||||
[Obsolete("use override with an EntityUid or Entity<T>")]
|
||||
public void Dirty(IComponent component, MetaDataComponent? meta = null)
|
||||
{
|
||||
Dirty(component.Owner, component, meta);
|
||||
@@ -365,6 +365,7 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
DebugTools.Assert(component.GetType().HasCustomAttribute<NetworkedComponentAttribute>(),
|
||||
$"Attempted to dirty a non-networked component: {component.GetType()}");
|
||||
DebugTools.AssertOwner(uid, component);
|
||||
|
||||
if (component.LifeStage >= ComponentLifeStage.Removing || !component.NetSyncEnabled)
|
||||
return;
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
@@ -38,6 +39,26 @@ namespace Robust.Shared.GameObjects
|
||||
/// </summary>
|
||||
int Count(Type component);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified components from the <see cref="EntityPrototype"/>
|
||||
/// </summary>
|
||||
void AddComponents(EntityUid target, EntityPrototype prototype, bool removeExisting = true);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified registry components to the target entity.
|
||||
/// </summary>
|
||||
void AddComponents(EntityUid target, ComponentRegistry registry, bool removeExisting = true);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the specified entity prototype components from the target entity.
|
||||
/// </summary>
|
||||
void RemoveComponents(EntityUid target, EntityPrototype prototype);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the specified registry components from the target entity.
|
||||
/// </summary>
|
||||
void RemoveComponents(EntityUid target, ComponentRegistry registry);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a Component type to an entity. If the entity is already Initialized, the component will
|
||||
/// automatically be Initialized and Started.
|
||||
|
||||
@@ -68,7 +68,7 @@ public readonly struct NetEntity : IEquatable<NetEntity>, IComparable<NetEntity>
|
||||
entity = Parse(uid);
|
||||
return true;
|
||||
}
|
||||
catch (FormatException)
|
||||
catch (Exception ex) when (ex is FormatException or OverflowException)
|
||||
{
|
||||
entity = Invalid;
|
||||
return false;
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Marks a component as being automatically registered by <see cref="IComponentFactory.DoAutoRegistrations" />
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
||||
[BaseTypeRequired(typeof(IComponent))]
|
||||
[MeansImplicitUse]
|
||||
public sealed class RegisterComponentAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,13 +11,14 @@ public abstract partial class SharedMapSystem
|
||||
{
|
||||
public void SetAmbientLight(MapId mapId, Color color)
|
||||
{
|
||||
var mapComp = EnsureComp<MapLightComponent>(MapManager.GetMapEntityId(mapId));
|
||||
var mapUid = MapManager.GetMapEntityId(mapId);
|
||||
var mapComp = EnsureComp<MapLightComponent>(mapUid);
|
||||
|
||||
if (mapComp.AmbientLightColor.Equals(color))
|
||||
return;
|
||||
|
||||
mapComp.AmbientLightColor = color;
|
||||
Dirty(mapComp);
|
||||
Dirty(mapUid, mapComp);
|
||||
}
|
||||
|
||||
private void OnMapLightGetState(EntityUid uid, MapLightComponent component, ref ComponentGetState args)
|
||||
|
||||
@@ -722,10 +722,7 @@ public abstract partial class SharedTransformSystem
|
||||
{
|
||||
if (args.Current is TransformComponentState newState)
|
||||
{
|
||||
var parent = GetEntity(newState.ParentID);
|
||||
if (!parent.IsValid() && newState.ParentID.IsValid())
|
||||
Log.Error($"Received transform component state with an unknown parent Id. Entity: {ToPrettyString(uid)}. Net parent: {newState.ParentID}");
|
||||
|
||||
var parent = EnsureEntity<TransformComponent>(newState.ParentID, uid);
|
||||
var oldAnchored = xform.Anchored;
|
||||
|
||||
// update actual position data, if required
|
||||
@@ -978,36 +975,25 @@ public abstract partial class SharedTransformSystem
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetWorldPosition(EntityUid uid, Vector2 worldPos)
|
||||
{
|
||||
var xform = Transform(uid);
|
||||
var xform = XformQuery.GetComponent(uid);
|
||||
SetWorldPosition(xform, worldPos);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetWorldPosition(EntityUid uid, Vector2 worldPos, EntityQuery<TransformComponent> xformQuery)
|
||||
{
|
||||
var component = xformQuery.GetComponent(uid);
|
||||
SetWorldPosition(component, worldPos, xformQuery);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetWorldPosition(TransformComponent component, Vector2 worldPos)
|
||||
{
|
||||
SetWorldPosition(component, worldPos, XformQuery);
|
||||
SetWorldPosition((component.Owner, component), worldPos);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the position of the entity in world-terms to the specified position.
|
||||
/// May also de-parent the entity.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetWorldPosition(TransformComponent component, Vector2 worldPos, EntityQuery<TransformComponent> xformQuery)
|
||||
public void SetWorldPosition(Entity<TransformComponent> entity, Vector2 worldPos)
|
||||
{
|
||||
if (!component._parent.IsValid())
|
||||
{
|
||||
DebugTools.Assert("Parent is invalid while attempting to set WorldPosition - did you try to move root node?");
|
||||
return;
|
||||
}
|
||||
|
||||
var (curWorldPos, curWorldRot) = GetWorldPositionRotation(component, xformQuery);
|
||||
var negativeParentWorldRot = component._localRotation - curWorldRot;
|
||||
var newLocalPos = component._localPosition + negativeParentWorldRot.RotateVec(worldPos - curWorldPos);
|
||||
SetLocalPosition(component, newLocalPos);
|
||||
SetWorldPositionRotation(entity.Owner, worldPos, entity.Comp.LocalRotation, entity.Comp);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -1097,20 +1083,24 @@ public abstract partial class SharedTransformSystem
|
||||
if (!XformQuery.Resolve(uid, ref component))
|
||||
return;
|
||||
|
||||
if (!component._parent.IsValid())
|
||||
if (!component._parent.IsValid() || component.MapUid == null)
|
||||
{
|
||||
DebugTools.Assert("Parent is invalid while attempting to set WorldPosition - did you try to move root node?");
|
||||
return;
|
||||
}
|
||||
|
||||
var (curWorldPos, curWorldRot) = GetWorldPositionRotation(component);
|
||||
|
||||
var negativeParentWorldRot = component.LocalRotation - curWorldRot;
|
||||
|
||||
var newLocalPos = component.LocalPosition + negativeParentWorldRot.RotateVec(worldPos - curWorldPos);
|
||||
var newLocalRot = component.LocalRotation + worldRot - curWorldRot;
|
||||
|
||||
SetLocalPositionRotation(uid, newLocalPos, newLocalRot, component);
|
||||
if (component.GridUid != uid && _mapManager.TryFindGridAt(component.MapUid.Value, worldPos, out var targetGrid, out _))
|
||||
{
|
||||
var targetGridXform = XformQuery.GetComponent(targetGrid);
|
||||
var invLocalMatrix = targetGridXform.InvLocalMatrix;
|
||||
var gridRot = targetGridXform.LocalRotation;
|
||||
var localRot = worldRot - gridRot;
|
||||
SetCoordinates(uid, component, new EntityCoordinates(targetGrid, invLocalMatrix.Transform(worldPos)), rotation: localRot);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCoordinates(uid, component, new EntityCoordinates(component.MapUid.Value, worldPos), rotation: worldRot);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use override with EntityUid")]
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// </remarks>
|
||||
private void DeparentAllEntsOnTile(EntityUid gridId, Vector2i tileIndices)
|
||||
{
|
||||
if (!TryComp(gridId, out BroadphaseComponent? lookup) || !_mapManager.TryGetGrid(gridId, out var grid))
|
||||
if (!TryComp(gridId, out BroadphaseComponent? lookup) || !TryComp<MapGridComponent>(gridId, out var grid))
|
||||
return;
|
||||
|
||||
if (!XformQuery.TryGetComponent(gridId, out var gridXform))
|
||||
|
||||
@@ -25,8 +25,7 @@ public abstract class SharedUserInterfaceSystem : EntitySystem
|
||||
|
||||
foreach (var prototypeData in component.InterfaceData)
|
||||
{
|
||||
component.Interfaces[prototypeData.UiKey] = new PlayerBoundUserInterface(prototypeData, uid);
|
||||
component.MappedInterfaceData[prototypeData.UiKey] = prototypeData;
|
||||
AddUi((uid, component), prototypeData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +104,19 @@ public abstract class SharedUserInterfaceSystem : EntitySystem
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a UI after an entity has been created.
|
||||
/// It cannot be added already.
|
||||
/// </summary>
|
||||
public void AddUi(Entity<UserInterfaceComponent?> ent, PrototypeData data)
|
||||
{
|
||||
if (!Resolve(ent, ref ent.Comp))
|
||||
return;
|
||||
|
||||
ent.Comp.Interfaces[data.UiKey] = new PlayerBoundUserInterface(data, ent);
|
||||
ent.Comp.MappedInterfaceData[data.UiKey] = data;
|
||||
}
|
||||
|
||||
public bool TryGetUi(EntityUid uid, Enum uiKey, [NotNullWhen(true)] out PlayerBoundUserInterface? bui, UserInterfaceComponent? ui = null)
|
||||
{
|
||||
bui = null;
|
||||
|
||||
@@ -77,6 +77,10 @@ namespace Robust.Shared.Log
|
||||
return;
|
||||
|
||||
var msg = new LogEvent(DateTimeOffset.Now, level.ToSerilog(), exception, parsedTemplate, properties);
|
||||
|
||||
if (level < GetPracticalLevel())
|
||||
return;
|
||||
|
||||
LogInternal(Name, msg);
|
||||
}
|
||||
|
||||
@@ -99,11 +103,6 @@ namespace Robust.Shared.Log
|
||||
|
||||
private void LogInternal(string sourceSawmill, LogEvent message)
|
||||
{
|
||||
if (message.Level.ToRobust() < GetPracticalLevel())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_handlerLock.EnterReadLock();
|
||||
try
|
||||
{
|
||||
|
||||
@@ -15,12 +15,13 @@ namespace Robust.Shared.Map
|
||||
var gridId = coords.GetGridUid(entityManager);
|
||||
var mapSystem = entityManager.System<SharedMapSystem>();
|
||||
|
||||
if (mapManager.TryGetGrid(gridId, out var mapGrid))
|
||||
if (entityManager.TryGetComponent<MapGridComponent>(gridId, out var mapGrid))
|
||||
{
|
||||
return mapSystem.GridTileToLocal(gridId.Value, mapGrid, mapSystem.CoordinatesToTile(gridId.Value, mapGrid, coords));
|
||||
}
|
||||
|
||||
var mapCoords = coords.ToMap(entityManager);
|
||||
var transformSystem = entityManager.System<SharedTransformSystem>();
|
||||
var mapCoords = coords.ToMap(entityManager, transformSystem);
|
||||
|
||||
if (mapManager.TryFindGridAt(mapCoords, out var gridUid, out mapGrid))
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Numerics;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
@@ -110,7 +111,7 @@ namespace Robust.Shared.Map
|
||||
[Obsolete("Use ToMapPos() with TransformSystem overload")]
|
||||
public Vector2 ToMapPos(IEntityManager entityManager)
|
||||
{
|
||||
return ToMap(entityManager).Position;
|
||||
return ToMap(entityManager, entityManager.System<SharedTransformSystem>()).Position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -160,7 +161,7 @@ namespace Robust.Shared.Map
|
||||
[Obsolete("Use overload with other parameter order.")]
|
||||
public static EntityCoordinates FromMap(IEntityManager entityManager, EntityUid entityUid, MapCoordinates coordinates)
|
||||
{
|
||||
return FromMap(entityUid, coordinates, entityManager);
|
||||
return FromMap(entityUid, coordinates, entityManager.System<SharedTransformSystem>(), entityManager);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -200,7 +201,7 @@ namespace Robust.Shared.Map
|
||||
var gridIdOpt = GetGridUid(entityManager);
|
||||
if (gridIdOpt is { } gridId && gridId.IsValid())
|
||||
{
|
||||
var grid = mapManager.GetGrid(gridId);
|
||||
var grid = entityManager.GetComponent<MapGridComponent>(gridId);
|
||||
return mapSystem.GetTileRef(gridId, grid, this).GridIndices;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Robust.Shared.Map
|
||||
@@ -22,6 +23,7 @@ namespace Robust.Shared.Map
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the tile definition.</param>
|
||||
/// <returns>The named tile definition.</returns>
|
||||
/// <seealso cref="TryGetDefinition(string,out Robust.Shared.Map.ITileDefinition?)"/>
|
||||
ITileDefinition this[string name] { get; }
|
||||
|
||||
/// <summary>
|
||||
@@ -29,8 +31,29 @@ namespace Robust.Shared.Map
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the tile definition.</param>
|
||||
/// <returns>The tile definition.</returns>
|
||||
/// <seealso cref="TryGetDefinition(int,out Robust.Shared.Map.ITileDefinition?)"/>
|
||||
ITileDefinition this[int id] { get; }
|
||||
// TODO add a try get and get-or-null variant.
|
||||
|
||||
/// <summary>
|
||||
/// Try to retrieve a tile definition by name.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Note: In the presence of tile aliases, this[A].ID does not necessarily equal A.
|
||||
/// </remarks>
|
||||
/// <param name="name">The name of the tile definition to look up.</param>
|
||||
/// <param name="definition">The found tile definition, if it exists.</param>
|
||||
/// <returns>True if a tile definition was resolved, false otherwise.</returns>
|
||||
/// <seealso cref="this[string]"/>
|
||||
bool TryGetDefinition(string name, [NotNullWhen(true)] out ITileDefinition? definition);
|
||||
|
||||
/// <summary>
|
||||
/// Try to retrieve a tile definition by tile ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the tile definition to look up.</param>
|
||||
/// <param name="definition">The found tile definition, if it exists.</param>
|
||||
/// <returns>True if a tile definition was resolved, false otherwise.</returns>
|
||||
/// <seealso cref="this[int]"/>
|
||||
bool TryGetDefinition(int id, [NotNullWhen(true)] out ITileDefinition? definition);
|
||||
|
||||
/// <summary>
|
||||
/// The number of tile definitions contained inside of this manager.
|
||||
|
||||
@@ -113,7 +113,7 @@ internal partial class MapManager
|
||||
#endif
|
||||
|
||||
// Possible the grid was already deleted / is invalid
|
||||
if (!TryGetGrid(euid, out var iGrid))
|
||||
if (!EntityManager.TryGetComponent<MapGridComponent>(euid, out var iGrid))
|
||||
{
|
||||
DebugTools.Assert($"Calling {nameof(DeleteGrid)} with unknown uid {euid}.");
|
||||
return; // Silently fail on release
|
||||
|
||||
@@ -33,6 +33,9 @@ internal sealed class MapSerializationContext : ISerializationContext, IEntityLo
|
||||
private Dictionary<int, EntityUid> _uidEntityMap = new();
|
||||
private Dictionary<EntityUid, int> _entityUidMap = new();
|
||||
|
||||
// Native tile ID -> map tile ID map for writing maps.
|
||||
public Dictionary<int, int> TileWriteMap = [];
|
||||
|
||||
/// <summary>
|
||||
/// Are we currently iterating prototypes or entities for writing.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
@@ -111,6 +112,23 @@ namespace Robust.Shared.Map
|
||||
|
||||
public ITileDefinition this[int id] => TileDefs[id];
|
||||
|
||||
public bool TryGetDefinition(string name, [NotNullWhen(true)] out ITileDefinition? definition)
|
||||
{
|
||||
return _tileNames.TryGetValue(name, out definition);
|
||||
}
|
||||
|
||||
public bool TryGetDefinition(int id, [NotNullWhen(true)] out ITileDefinition? definition)
|
||||
{
|
||||
if (id >= TileDefs.Count)
|
||||
{
|
||||
definition = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
definition = TileDefs[id];
|
||||
return true;
|
||||
}
|
||||
|
||||
public int Count => TileDefs.Count;
|
||||
|
||||
public IEnumerator<ITileDefinition> GetEnumerator()
|
||||
|
||||
@@ -67,6 +67,13 @@ namespace Robust.Shared.Network
|
||||
/// </summary>
|
||||
bool IsHandshakeComplete { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Diagnostic indicating the maximum transmission unit being used for this connection.
|
||||
/// </summary>
|
||||
/// <seealso cref="CVars.NetMtu"/>
|
||||
[ViewVariables]
|
||||
public int CurrentMtu { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new NetMessage to be filled up and sent.
|
||||
/// </summary>
|
||||
@@ -94,6 +101,5 @@ namespace Robust.Shared.Network
|
||||
/// <param name="reason">Reason why it was disconnected.</param>
|
||||
/// <param name="sendBye">If false, we ghost the remote client and don't tell them they got disconnected properly.</param>
|
||||
void Disconnect(string reason, bool sendBye);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,8 @@ namespace Robust.Shared.Network
|
||||
// Only used on server, contains the encryption to use for this channel.
|
||||
public NetEncryption? Encryption { get; set; }
|
||||
|
||||
[ViewVariables] public int CurrentMtu => _connection.CurrentMTU;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of a NetChannel.
|
||||
/// </summary>
|
||||
|
||||
@@ -619,6 +619,7 @@ namespace Robust.Shared.Network
|
||||
|
||||
// MTU stuff.
|
||||
netConfig.MaximumTransmissionUnit = _config.GetCVar(CVars.NetMtu);
|
||||
netConfig.MaximumTransmissionUnitV6 = _config.GetCVar(CVars.NetMtuIpv6);
|
||||
netConfig.AutoExpandMTU = _config.GetCVar(CVars.NetMtuExpand);
|
||||
netConfig.ExpandMTUFrequency = _config.GetCVar(CVars.NetMtuExpandFrequency);
|
||||
netConfig.ExpandMTUFailAttempts = _config.GetCVar(CVars.NetMtuExpandFailAttempts);
|
||||
|
||||
@@ -67,7 +67,7 @@ public sealed class Gravity2DController : VirtualController
|
||||
|
||||
gravity.Gravity = value;
|
||||
WakeBodiesRecursive(uid, GetEntityQuery<TransformComponent>(), GetEntityQuery<PhysicsComponent>());
|
||||
Dirty(gravity);
|
||||
Dirty(uid, gravity);
|
||||
}
|
||||
|
||||
public void SetGravity(MapId mapId, Vector2 value)
|
||||
@@ -80,7 +80,7 @@ public sealed class Gravity2DController : VirtualController
|
||||
|
||||
gravity.Gravity = value;
|
||||
WakeBodiesRecursive(mapUid, GetEntityQuery<TransformComponent>(), GetEntityQuery<PhysicsComponent>());
|
||||
Dirty(gravity);
|
||||
Dirty(mapUid, gravity);
|
||||
}
|
||||
|
||||
private void WakeBodiesRecursive(EntityUid uid, EntityQuery<TransformComponent> xformQuery, EntityQuery<PhysicsComponent> bodyQuery)
|
||||
|
||||
@@ -376,6 +376,9 @@ namespace Robust.Shared.Physics.Dynamics.Contacts
|
||||
/// </summary>
|
||||
Grid = 1 << 3,
|
||||
|
||||
/// <summary>
|
||||
/// Set right before the contact is deleted
|
||||
/// </summary>
|
||||
Deleting = 1 << 4,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
// Don't need to dirty here as we'll just manually call it after (we 100% need to call it).
|
||||
FixtureUpdate(uid, false, manager: manager, body: body);
|
||||
// Don't need to ResetMassData as FixtureUpdate already does it.
|
||||
Dirty(manager);
|
||||
Dirty(uid, manager);
|
||||
}
|
||||
// TODO: Set newcontacts to true.
|
||||
}
|
||||
@@ -361,7 +361,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
}
|
||||
|
||||
if (dirty)
|
||||
Dirty(manager);
|
||||
Dirty(uid, manager);
|
||||
}
|
||||
|
||||
public int GetFixtureCount(EntityUid uid, FixturesComponent? manager = null)
|
||||
|
||||
@@ -99,9 +99,9 @@ public partial class SharedPhysicsSystem
|
||||
SetLinearVelocity(uid, newState.LinearVelocity, body: component, manager: manager);
|
||||
SetAngularVelocity(uid, newState.AngularVelocity, body: component, manager: manager);
|
||||
SetBodyType(uid, newState.BodyType, manager, component);
|
||||
SetFriction(component, newState.Friction);
|
||||
SetLinearDamping(component, newState.LinearDamping);
|
||||
SetAngularDamping(component, newState.AngularDamping);
|
||||
SetFriction(uid, component, newState.Friction);
|
||||
SetLinearDamping(uid, component, newState.LinearDamping);
|
||||
SetAngularDamping(uid, component, newState.AngularDamping);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -132,7 +132,7 @@ public partial class SharedPhysicsSystem
|
||||
|
||||
body.Force += force;
|
||||
body.Torque += Vector2Helpers.Cross(point - body._localCenter, force);
|
||||
Dirty(body);
|
||||
Dirty(uid, body);
|
||||
}
|
||||
|
||||
public void ApplyForce(EntityUid uid, Vector2 force, FixturesComponent? manager = null, PhysicsComponent? body = null)
|
||||
@@ -143,7 +143,7 @@ public partial class SharedPhysicsSystem
|
||||
}
|
||||
|
||||
body.Force += force;
|
||||
Dirty(body);
|
||||
Dirty(uid, body);
|
||||
}
|
||||
|
||||
public void ApplyTorque(EntityUid uid, float torque, FixturesComponent? manager = null, PhysicsComponent? body = null)
|
||||
@@ -154,7 +154,7 @@ public partial class SharedPhysicsSystem
|
||||
}
|
||||
|
||||
body.Torque += torque;
|
||||
Dirty(body);
|
||||
Dirty(uid, body);
|
||||
}
|
||||
|
||||
public void ApplyLinearImpulse(EntityUid uid, Vector2 impulse, FixturesComponent? manager = null, PhysicsComponent? body = null)
|
||||
@@ -186,23 +186,31 @@ public partial class SharedPhysicsSystem
|
||||
{
|
||||
if (body.Contacts.Count == 0) return;
|
||||
|
||||
// This variable is only used in edge-case scenario when contact flagged Deleting raises
|
||||
// EndCollideEvent which will QueueDelete contact's entity
|
||||
ushort contactsFlaggedDeleting = 0;
|
||||
var node = body.Contacts.First;
|
||||
|
||||
while (node != null)
|
||||
{
|
||||
var contact = node.Value;
|
||||
node = node.Next;
|
||||
|
||||
// Destroy last so the linked-list doesn't get touched.
|
||||
DestroyContact(contact);
|
||||
if (!DestroyContact(contact))
|
||||
{
|
||||
contactsFlaggedDeleting++;
|
||||
}
|
||||
}
|
||||
|
||||
DebugTools.Assert(body.Contacts.Count == 0);
|
||||
// This contact will be deleted before SimulateWorld runs since it is already set to be Deleted
|
||||
DebugTools.Assert(body.Contacts.Count == contactsFlaggedDeleting);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Completely resets a dynamic body.
|
||||
/// </summary>
|
||||
public void ResetDynamics(PhysicsComponent body, bool dirty = true)
|
||||
public void ResetDynamics(EntityUid uid, PhysicsComponent body, bool dirty = true)
|
||||
{
|
||||
var updated = false;
|
||||
|
||||
@@ -231,7 +239,13 @@ public partial class SharedPhysicsSystem
|
||||
}
|
||||
|
||||
if (updated && dirty)
|
||||
Dirty(body);
|
||||
Dirty(uid, body);
|
||||
}
|
||||
|
||||
[Obsolete("Use overload that takes EntityUid")]
|
||||
public void ResetDynamics(PhysicsComponent body, bool dirty = true)
|
||||
{
|
||||
ResetDynamics(body.Owner, body, dirty);
|
||||
}
|
||||
|
||||
public void ResetMassData(EntityUid uid, FixturesComponent? manager = null, PhysicsComponent? body = null)
|
||||
@@ -261,7 +275,7 @@ public partial class SharedPhysicsSystem
|
||||
if (((int) body.BodyType & (int) (BodyType.Kinematic | BodyType.Static)) != 0)
|
||||
{
|
||||
body._localCenter = Vector2.Zero;
|
||||
Dirty(body);
|
||||
Dirty(uid, body);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -296,7 +310,7 @@ public partial class SharedPhysicsSystem
|
||||
|
||||
// Update center of mass velocity.
|
||||
body.LinearVelocity += Vector2Helpers.Cross(body.AngularVelocity, localCenter - oldCenter);
|
||||
Dirty(body);
|
||||
Dirty(uid, body);
|
||||
}
|
||||
|
||||
public void SetAngularVelocity(EntityUid uid, float value, bool dirty = true, FixturesComponent? manager = null, PhysicsComponent? body = null)
|
||||
@@ -350,7 +364,7 @@ public partial class SharedPhysicsSystem
|
||||
Dirty(uid, body);
|
||||
}
|
||||
|
||||
public void SetAngularDamping(PhysicsComponent body, float value, bool dirty = true)
|
||||
public void SetAngularDamping(EntityUid uid, PhysicsComponent body, float value, bool dirty = true)
|
||||
{
|
||||
if (MathHelper.CloseTo(body.AngularDamping, value))
|
||||
return;
|
||||
@@ -358,10 +372,16 @@ public partial class SharedPhysicsSystem
|
||||
body.AngularDamping = value;
|
||||
|
||||
if (dirty)
|
||||
Dirty(body);
|
||||
Dirty(uid, body);
|
||||
}
|
||||
|
||||
public void SetLinearDamping(PhysicsComponent body, float value, bool dirty = true)
|
||||
[Obsolete("Use overload that takes EntityUid")]
|
||||
public void SetAngularDamping(PhysicsComponent body, float value, bool dirty = true)
|
||||
{
|
||||
SetAngularDamping(body.Owner, body, value, dirty);
|
||||
}
|
||||
|
||||
public void SetLinearDamping(EntityUid uid, PhysicsComponent body, float value, bool dirty = true)
|
||||
{
|
||||
if (MathHelper.CloseTo(body.LinearDamping, value))
|
||||
return;
|
||||
@@ -369,7 +389,13 @@ public partial class SharedPhysicsSystem
|
||||
body.LinearDamping = value;
|
||||
|
||||
if (dirty)
|
||||
Dirty(body);
|
||||
Dirty(uid, body);
|
||||
}
|
||||
|
||||
[Obsolete("Use overload that takes EntityUid")]
|
||||
public void SetLinearDamping(PhysicsComponent body, float value, bool dirty = true)
|
||||
{
|
||||
SetLinearDamping(body.Owner, body, value, dirty);
|
||||
}
|
||||
|
||||
[Obsolete("Use SetAwake with EntityUid<PhysicsComponent>")]
|
||||
@@ -403,7 +429,7 @@ public partial class SharedPhysicsSystem
|
||||
{
|
||||
var ev = new PhysicsSleepEvent(uid, body);
|
||||
RaiseLocalEvent(uid, ref ev, true);
|
||||
ResetDynamics(body, dirty: false);
|
||||
ResetDynamics(ent, body, dirty: false);
|
||||
}
|
||||
|
||||
// Update wake system last, if sleeping but still colliding.
|
||||
@@ -470,7 +496,7 @@ public partial class SharedPhysicsSystem
|
||||
}
|
||||
}
|
||||
|
||||
public void SetBodyStatus(PhysicsComponent body, BodyStatus status, bool dirty = true)
|
||||
public void SetBodyStatus(EntityUid uid, PhysicsComponent body, BodyStatus status, bool dirty = true)
|
||||
{
|
||||
if (body.BodyStatus == status)
|
||||
return;
|
||||
@@ -478,7 +504,13 @@ public partial class SharedPhysicsSystem
|
||||
body.BodyStatus = status;
|
||||
|
||||
if (dirty)
|
||||
Dirty(body);
|
||||
Dirty(uid, body);
|
||||
}
|
||||
|
||||
[Obsolete("Use overload that takes EntityUid")]
|
||||
public void SetBodyStatus(PhysicsComponent body, BodyStatus status, bool dirty = true)
|
||||
{
|
||||
SetBodyStatus(body.Owner, body, status, dirty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -531,7 +563,7 @@ public partial class SharedPhysicsSystem
|
||||
}
|
||||
|
||||
if (dirty)
|
||||
Dirty(body);
|
||||
Dirty(uid, body);
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -546,10 +578,10 @@ public partial class SharedPhysicsSystem
|
||||
ResetMassData(uid, manager: manager, body: body);
|
||||
|
||||
if (dirty)
|
||||
Dirty(body);
|
||||
Dirty(uid, body);
|
||||
}
|
||||
|
||||
public void SetFriction(PhysicsComponent body, float value, bool dirty = true)
|
||||
public void SetFriction(EntityUid uid, PhysicsComponent body, float value, bool dirty = true)
|
||||
{
|
||||
if (MathHelper.CloseTo(body.Friction, value))
|
||||
return;
|
||||
@@ -557,10 +589,16 @@ public partial class SharedPhysicsSystem
|
||||
body._friction = value;
|
||||
|
||||
if (dirty)
|
||||
Dirty(body);
|
||||
Dirty(uid, body);
|
||||
}
|
||||
|
||||
public void SetInertia(PhysicsComponent body, float value, bool dirty = true)
|
||||
[Obsolete("Use overload that takes EntityUid")]
|
||||
public void SetFriction(PhysicsComponent body, float value, bool dirty = true)
|
||||
{
|
||||
SetFriction(body.Owner, body, value, dirty);
|
||||
}
|
||||
|
||||
public void SetInertia(EntityUid uid, PhysicsComponent body, float value, bool dirty = true)
|
||||
{
|
||||
DebugTools.Assert(!float.IsNaN(value));
|
||||
|
||||
@@ -575,10 +613,16 @@ public partial class SharedPhysicsSystem
|
||||
body.InvI = 1.0f / body._inertia;
|
||||
|
||||
if (dirty)
|
||||
Dirty(body);
|
||||
Dirty(uid, body);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use overload that takes EntityUid")]
|
||||
public void SetInertia(PhysicsComponent body, float value, bool dirty = true)
|
||||
{
|
||||
SetInertia(body.Owner, body, value, dirty);
|
||||
}
|
||||
|
||||
public void SetLocalCenter(EntityUid uid, PhysicsComponent body, Vector2 value)
|
||||
{
|
||||
if (body.BodyType != BodyType.Dynamic) return;
|
||||
@@ -599,7 +643,7 @@ public partial class SharedPhysicsSystem
|
||||
body.SleepingAllowed = value;
|
||||
|
||||
if (dirty)
|
||||
Dirty(body);
|
||||
Dirty(uid, body);
|
||||
}
|
||||
|
||||
public void SetSleepTime(PhysicsComponent body, float value)
|
||||
@@ -693,7 +737,7 @@ public partial class SharedPhysicsSystem
|
||||
|
||||
public (int Layer, int Mask) GetHardCollision(EntityUid uid, FixturesComponent? manager = null)
|
||||
{
|
||||
if (!Resolve(uid, ref manager))
|
||||
if (!_fixturesQuery.Resolve(uid, ref manager, false))
|
||||
{
|
||||
return (0, 0);
|
||||
}
|
||||
|
||||
@@ -310,11 +310,10 @@ public abstract partial class SharedPhysicsSystem
|
||||
(fixtureB.CollisionMask & fixtureA.CollisionLayer) == 0x0);
|
||||
}
|
||||
|
||||
public void DestroyContact(Contact contact)
|
||||
public bool DestroyContact(Contact contact)
|
||||
{
|
||||
// Don't recursive update or we're in for a bad time.
|
||||
if ((contact.Flags & ContactFlags.Deleting) != 0x0)
|
||||
return;
|
||||
return false;
|
||||
|
||||
Fixture fixtureA = contact.FixtureA!;
|
||||
Fixture fixtureB = contact.FixtureB!;
|
||||
@@ -326,7 +325,7 @@ public abstract partial class SharedPhysicsSystem
|
||||
|
||||
if (contact.IsTouching)
|
||||
{
|
||||
var ev1 = new EndCollideEvent(aUid, bUid, contact.FixtureAId, contact.FixtureBId ,fixtureA, fixtureB, bodyA, bodyB);
|
||||
var ev1 = new EndCollideEvent(aUid, bUid, contact.FixtureAId, contact.FixtureBId, fixtureA, fixtureB, bodyA, bodyB);
|
||||
var ev2 = new EndCollideEvent(bUid, aUid, contact.FixtureBId, contact.FixtureAId, fixtureB, fixtureA, bodyB, bodyA);
|
||||
RaiseLocalEvent(aUid, ref ev1);
|
||||
RaiseLocalEvent(bUid, ref ev2);
|
||||
@@ -335,10 +334,10 @@ public abstract partial class SharedPhysicsSystem
|
||||
if (contact.Manifold.PointCount > 0 && contact.FixtureA?.Hard == true && contact.FixtureB?.Hard == true)
|
||||
{
|
||||
if (bodyA.CanCollide)
|
||||
SetAwake(aUid, bodyA, true);
|
||||
SetAwake((aUid, bodyA), true);
|
||||
|
||||
if (bodyB.CanCollide)
|
||||
SetAwake(bUid, bodyB, true);
|
||||
SetAwake((bUid, bodyB), true);
|
||||
}
|
||||
|
||||
// Remove from the world
|
||||
@@ -347,16 +346,19 @@ public abstract partial class SharedPhysicsSystem
|
||||
// Remove from body 1
|
||||
DebugTools.Assert(fixtureA.Contacts.ContainsKey(fixtureB));
|
||||
fixtureA.Contacts.Remove(fixtureB);
|
||||
DebugTools.Assert(bodyA.Contacts.Contains(contact.BodyANode!.Value));
|
||||
DebugTools.Assert(bodyA.Contacts.Contains(contact.BodyANode.Value));
|
||||
bodyA.Contacts.Remove(contact.BodyANode);
|
||||
|
||||
// Remove from body 2
|
||||
DebugTools.Assert(fixtureB.Contacts.ContainsKey(fixtureA));
|
||||
fixtureB.Contacts.Remove(fixtureA);
|
||||
DebugTools.Assert(bodyB.Contacts.Contains(contact.BodyBNode.Value));
|
||||
bodyB.Contacts.Remove(contact.BodyBNode);
|
||||
|
||||
// Insert into the pool.
|
||||
_contactPool.Return(contact);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
internal void CollideContacts()
|
||||
|
||||
@@ -1049,7 +1049,7 @@ public abstract partial class SharedPhysicsSystem
|
||||
}
|
||||
|
||||
// TODO: Should check if the values update.
|
||||
Dirty(body, metaQuery.GetComponent(uid));
|
||||
Dirty(uid, body, metaQuery.GetComponent(uid));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -291,7 +291,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
if ((proxy.Fixture.CollisionLayer & ray.CollisionMask) == 0x0)
|
||||
return true;
|
||||
|
||||
if (!proxy.Body.Hard)
|
||||
if (!proxy.Fixture.Hard)
|
||||
return true;
|
||||
|
||||
if (predicate.Invoke(proxy.Entity, state) == true)
|
||||
@@ -319,7 +319,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
if ((proxy.Fixture.CollisionLayer & ray.CollisionMask) == 0x0)
|
||||
return true;
|
||||
|
||||
if (!proxy.Body.Hard)
|
||||
if (!proxy.Fixture.Hard)
|
||||
return true;
|
||||
|
||||
if (predicate.Invoke(proxy.Entity, state) == true)
|
||||
@@ -567,6 +567,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
// No requirement on collision being enabled so chainshapes will fail
|
||||
foreach (var fixtureA in manager.Fixtures.Values)
|
||||
{
|
||||
// We ignore non-hard fixtures if there is at least one hard fixture (i.e., if the body is hard)
|
||||
if (body.Hard && !fixtureA.Hard)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public abstract partial class SharedPhysicsSystem
|
||||
_lookup.CreateProxies(uid, fixtureId, fixture, xform, body);
|
||||
}
|
||||
|
||||
Dirty(manager);
|
||||
Dirty(uid, manager);
|
||||
}
|
||||
|
||||
public void SetPosition(
|
||||
@@ -91,7 +91,7 @@ public abstract partial class SharedPhysicsSystem
|
||||
_lookup.CreateProxies(uid, fixtureId, fixture, xform, body);
|
||||
}
|
||||
|
||||
Dirty(manager);
|
||||
Dirty(uid, manager);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -13,6 +13,7 @@ using Robust.Shared.Physics.Controllers;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Physics.Events;
|
||||
using Robust.Shared.Threading;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using DependencyAttribute = Robust.Shared.IoC.DependencyAttribute;
|
||||
|
||||
@@ -60,6 +61,12 @@ namespace Robust.Shared.Physics.Systems
|
||||
|
||||
private int _substeps;
|
||||
|
||||
/// <summary>
|
||||
/// A variation of <see cref="IGameTiming.CurTime"/> that takes into account the current physics sub-step.
|
||||
/// Useful for some entities that need to interpolate their positions during sub-steps.
|
||||
/// </summary>
|
||||
public TimeSpan? EffectiveCurTime;
|
||||
|
||||
public bool MetricsEnabled { get; protected set; }
|
||||
|
||||
private EntityQuery<FixturesComponent> _fixturesQuery;
|
||||
@@ -284,6 +291,7 @@ namespace Robust.Shared.Physics.Systems
|
||||
{
|
||||
var frameTime = deltaTime / _substeps;
|
||||
|
||||
EffectiveCurTime = _gameTiming.CurTime;
|
||||
for (int i = 0; i < _substeps; i++)
|
||||
{
|
||||
var updateBeforeSolve = new PhysicsUpdateBeforeSolveEvent(prediction, frameTime);
|
||||
@@ -323,7 +331,11 @@ namespace Robust.Shared.Physics.Systems
|
||||
FinalStep(comp);
|
||||
}
|
||||
}
|
||||
|
||||
EffectiveCurTime = EffectiveCurTime.Value + TimeSpan.FromSeconds(frameTime);
|
||||
}
|
||||
|
||||
EffectiveCurTime = null;
|
||||
}
|
||||
|
||||
protected virtual void FinalStep(PhysicsMapComponent component)
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Robust.Shared.Player
|
||||
public Filter AddPlayersByPvs(EntityCoordinates origin, float rangeMultiplier = 2f, IEntityManager? entityMan = null, ISharedPlayerManager? playerMan = null)
|
||||
{
|
||||
IoCManager.Resolve(ref entityMan, ref playerMan);
|
||||
return AddPlayersByPvs(origin.ToMap(entityMan), rangeMultiplier, entityMan, playerMan);
|
||||
return AddPlayersByPvs(origin.ToMap(entityMan, entityMan.System<SharedTransformSystem>()), rangeMultiplier, entityMan, playerMan);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -36,7 +36,7 @@ public partial class PrototypeManager
|
||||
.ToArray();
|
||||
|
||||
// Shuffle to avoid input data patterns causing uneven thread workloads.
|
||||
RandomExtensions.Shuffle(streams.AsSpan(), new System.Random());
|
||||
(new System.Random()).Shuffle(streams.AsSpan());
|
||||
|
||||
var sawmill = _logManager.GetSawmill("eng");
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user