Compare commits

...

26 Commits

Author SHA1 Message Date
PJB3005
ee330d0ae9 Make DOOM work
I think I lost this work originally
2025-01-15 23:08:44 +01:00
metalgearsloth
6c44dd9665 RenderingTreeSystem cleanup (#1759)
* RenderingTreeSystem cleanup

10% less bad but 100% still boilerplate

* Slight changies

* Even better

* New shit just got made

* Apply revews
2021-05-20 18:57:29 +10:00
Acruid
c81413b0b4 Fixes bug where the net_entityreport red PVS range square was drawn at half the actual range. 2021-05-19 15:52:44 -07:00
Vera Aguilera Puerto
88b3a557da Fixes bug with PrototypeIdListSerializer where lists wouldn't be copied at all. 2021-05-19 12:12:13 +02:00
Vera Aguilera Puerto
572eb01290 Opens SCSI window centered
- Kinda fixes it getting NaN'd on resize... This isn't a proper fix, however.
2021-05-19 11:11:35 +02:00
Vera Aguilera Puerto
9dab74c9d5 Fixes SS14Window going off-screen. 2021-05-19 10:55:41 +02:00
Paul
e1cb1e1b9c fixes xamlui nuking itself when one (1) (singular) partial declaration is missing 2021-05-18 20:19:50 +02:00
Vera Aguilera Puerto
a23da702b1 MidiManager now has a Volume property which changes the general midi volume.
- Adds VV attributes to MidiManager and MidiRenderer.
2021-05-18 20:03:20 +02:00
Vera Aguilera Puerto
ae9c2423ff Fixes EntityLookup not being restarted correctly on reconnect. 2021-05-18 17:55:24 +02:00
metalgearsloth
a6dae8e30a GridId caching (#1678)
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
2021-05-17 11:43:22 +02:00
Pieter-Jan Briers
96c0a4ae1f Automatically unsubscribe event bus registrations in entity system shutdown. (#1758)
* Automatically unsubscribe event bus registrations in entity system shutdown.

* Fix incorrect unsubscription of local events, obsolete unsubscribe methods.

That's what we got tests for.

* = null instead of .Clear()
2021-05-17 11:01:22 +02:00
Vera Aguilera Puerto
c26ebcbc78 QueueDelete method for entities (#1757) 2021-05-17 09:20:55 +02:00
Vera Aguilera Puerto
8334050411 MIDI improvements (#1756) 2021-05-16 19:28:14 +02:00
Vera Aguilera Puerto
cc67edfc2c Unsubscribe from directed event in UI System. 2021-05-15 12:40:35 +02:00
Vera Aguilera Puerto
943ea9e6c8 Shutdown and dispose of BoundUserInterfaces correctly when the UI component gets shutdown. 2021-05-14 14:25:53 +02:00
Pieter-Jan Briers
3aa5cefe03 Stop using component messages in bound UI code. 2021-05-13 03:29:38 +02:00
Pieter-Jan Briers
c5b34bab69 More obsoletions component messages. 2021-05-13 02:24:35 +02:00
Pieter-Jan Briers
e4f24ec125 Remove IPlayerSession on client. 2021-05-13 02:16:55 +02:00
Pieter-Jan Briers
250971ade7 Remove anchored APIs from physics. 2021-05-13 02:13:18 +02:00
Pieter-Jan Briers
718adf9740 Deprecate component messages harder. 2021-05-13 01:24:20 +02:00
20kdc
5d63aa8c95 Deferred Input Context Switches (fixes spawn entities menu while moving) (#1755) 2021-05-12 18:40:26 +02:00
Vera Aguilera Puerto
17af3612a5 Remove IActorComponent, rename BasicActorComponent to ActorComponent. (#1752)
Rename playerSession to PlayerSession.
2021-05-12 13:40:16 +02:00
Pieter-Jan Briers
d2ecf6b9b1 Remove CollidesOnMask
Only usage was a unit test.
2021-05-12 01:58:12 +02:00
Pieter-Jan Briers
2a1eda0d38 Fix tests 2021-05-12 01:57:03 +02:00
Pieter-Jan Briers
f0180abeb0 Missed a spot while fixing warnings. 2021-05-12 00:26:47 +02:00
Pieter-Jan Briers
720f1b1d05 Fix a bunch of compiler warnings. 2021-05-12 00:16:12 +02:00
106 changed files with 1232 additions and 926 deletions

View File

@@ -247,7 +247,6 @@ namespace {nameSpace}
DiagnosticSeverity.Error,
true),
Location.None));
return null;
}
}

View File

@@ -11,9 +11,11 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Broadphase;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
using Logger = Robust.Shared.Log.Logger;
namespace Robust.Client.Audio.Midi
@@ -32,24 +34,6 @@ namespace Robust.Client.Audio.Midi
/// </returns>
IMidiRenderer? GetNewRenderer();
/*
/// <summary>
/// Checks whether the file at the given path is a valid midi file or not.
/// </summary>
/// <remarks>
/// We add this here so content doesn't need to reference NFluidsynth.
/// </remarks>
bool IsMidiFile(string filename);
/// <summary>
/// Checks whether the file at the given path is a valid midi file or not.
/// </summary>
/// <remarks>
/// We add this here so content doesn't need to reference NFluidsynth.
/// </remarks>
bool IsSoundfontFile(string filename);
*/
/// <summary>
/// Method called every frame.
/// Should be used to update positional audio.
@@ -57,6 +41,11 @@ namespace Robust.Client.Audio.Midi
/// <param name="frameTime"></param>
void FrameUpdate(float frameTime);
/// <summary>
/// Volume, in db.
/// </summary>
float Volume { get; set; }
/// <summary>
/// If true, MIDI support is available.
/// </summary>
@@ -75,6 +64,7 @@ namespace Robust.Client.Audio.Midi
private SharedBroadPhaseSystem _broadPhaseSystem = default!;
[ViewVariables]
public bool IsAvailable
{
get
@@ -85,12 +75,29 @@ namespace Robust.Client.Audio.Midi
}
}
private readonly List<MidiRenderer> _renderers = new();
[ViewVariables]
private readonly List<IMidiRenderer> _renderers = new();
private bool _alive = true;
private Settings? _settings;
private Thread? _midiThread;
private ISawmill _midiSawmill = default!;
private float _volume = 0f;
private bool _volumeDirty = true;
[ViewVariables(VVAccess.ReadWrite)]
public float Volume
{
get => _volume;
set
{
if (MathHelper.CloseTo(_volume, value))
return;
_volume = value;
_volumeDirty = true;
}
}
private static readonly string[] LinuxSoundfonts =
{
@@ -117,6 +124,7 @@ namespace Robust.Client.Audio.Midi
private NFluidsynth.Logger.LoggerDelegate _loggerDelegate = default!;
private ISawmill _sawmill = default!;
[ViewVariables(VVAccess.ReadWrite)]
public int OcclusionCollisionMask { get; set; }
private void InitializeFluidsynth()
@@ -175,18 +183,6 @@ namespace Robust.Client.Audio.Midi
_sawmill.Log(rLevel, message);
}
/*
public bool IsMidiFile(string filename)
{
return SoundFont.IsMidiFile(filename);
}
public bool IsSoundfontFile(string filename)
{
return SoundFont.IsSoundFont(filename);
}
*/
public IMidiRenderer? GetNewRenderer()
{
if (!FluidsynthInitialized)
@@ -250,7 +246,9 @@ namespace Robust.Client.Audio.Midi
}
lock (_renderers)
{
_renderers.Add(renderer);
}
return renderer;
}
@@ -268,74 +266,79 @@ namespace Robust.Client.Audio.Midi
}
// Update positions of streams every frame.
lock (_renderers)
foreach (var renderer in _renderers)
foreach (var renderer in _renderers)
{
if (renderer.Disposed)
continue;
if(_volumeDirty)
renderer.Source.SetVolume(Volume);
if (!renderer.Mono)
{
if (renderer.Disposed)
continue;
if (!renderer.Mono)
{
renderer.Source.SetGlobal();
continue;
}
MapCoordinates? mapPos = null;
if (renderer.TrackingCoordinates != null)
{
mapPos = renderer.TrackingCoordinates.Value.ToMap(_entityManager);
}
else if (renderer.TrackingEntity != null)
{
mapPos = renderer.TrackingEntity.Transform.MapPosition;
}
if (mapPos != null)
{
var pos = mapPos.Value;
if (pos.MapId != _eyeManager.CurrentMap)
{
renderer.Source.SetVolume(-10000000);
}
else
{
var sourceRelative = _eyeManager.CurrentEye.Position.Position - pos.Position;
var occlusion = 0f;
if (sourceRelative.Length > 0)
{
occlusion = _broadPhaseSystem.IntersectRayPenetration(
pos.MapId,
new CollisionRay(
pos.Position,
sourceRelative.Normalized,
OcclusionCollisionMask),
sourceRelative.Length,
renderer.TrackingEntity);
}
renderer.Source.SetOcclusion(occlusion);
}
if (renderer.Source.SetPosition(pos.Position))
{
continue;
}
if (renderer.TrackingEntity != null)
{
renderer.Source.SetVelocity(renderer.TrackingEntity.GlobalLinearVelocity());
}
if (float.IsNaN(pos.Position.X) || float.IsNaN(pos.Position.Y))
{
// just duck out instead of move to NaN
renderer.Source.SetOcclusion(float.MaxValue);
continue;
}
_midiSawmill?.Warning("Interrupting positional audio, can't set position.");
renderer.Source.StopPlaying();
}
renderer.Source.SetGlobal();
continue;
}
MapCoordinates? mapPos = null;
if (renderer.TrackingCoordinates != null)
{
mapPos = renderer.TrackingCoordinates.Value.ToMap(_entityManager);
}
else if (renderer.TrackingEntity != null)
{
mapPos = renderer.TrackingEntity.Transform.MapPosition;
}
if (mapPos != null)
{
var pos = mapPos.Value;
if (pos.MapId != _eyeManager.CurrentMap)
{
renderer.Source.SetVolume(-10000000);
}
else
{
var sourceRelative = _eyeManager.CurrentEye.Position.Position - pos.Position;
var occlusion = 0f;
if (sourceRelative.Length > 0)
{
occlusion = _broadPhaseSystem.IntersectRayPenetration(
pos.MapId,
new CollisionRay(
pos.Position,
sourceRelative.Normalized,
OcclusionCollisionMask),
sourceRelative.Length,
renderer.TrackingEntity);
}
renderer.Source.SetOcclusion(occlusion);
}
if (renderer.Source.SetPosition(pos.Position))
{
continue;
}
if (renderer.TrackingEntity != null)
{
renderer.Source.SetVelocity(renderer.TrackingEntity.GlobalLinearVelocity());
}
if (float.IsNaN(pos.Position.X) || float.IsNaN(pos.Position.Y))
{
// just duck out instead of move to NaN
renderer.Source.SetOcclusion(float.MaxValue);
continue;
}
_midiSawmill?.Warning("Interrupting positional audio, can't set position.");
renderer.Source.StopPlaying();
}
}
_volumeDirty = false;
}
/// <summary>
@@ -346,6 +349,7 @@ namespace Robust.Client.Audio.Midi
while (_alive)
{
lock (_renderers)
{
for (var i = 0; i < _renderers.Count; i++)
{
var renderer = _renderers[i];
@@ -353,10 +357,11 @@ namespace Robust.Client.Audio.Midi
renderer.Render();
else
{
((IMidiRenderer)renderer).InternalDispose();
renderer.InternalDispose();
_renderers.Remove(renderer);
}
}
}
Thread.Sleep(1);
}
@@ -367,9 +372,13 @@ namespace Robust.Client.Audio.Midi
_alive = false;
_midiThread?.Join();
_settings?.Dispose();
foreach (var renderer in _renderers)
lock (_renderers)
{
renderer?.Dispose();
foreach (var renderer in _renderers)
{
renderer?.Dispose();
}
}
if (FluidsynthInitialized && !_failedInitialize)
@@ -424,6 +433,7 @@ namespace Robust.Client.Audio.Midi
var span = new Span<byte>(buf.ToPointer(), length);
var stream = _openStreams[(int) sfHandle];
// Fluidsynth's docs state that this method should leave the buffer unmodified if it fails. (returns -1)
try
{
// Fluidsynth does a LOT of tiny allocations (frankly, way too much).
@@ -447,6 +457,7 @@ namespace Robust.Client.Audio.Midi
{
return -1;
}
return 0;
}
@@ -468,10 +479,12 @@ namespace Robust.Client.Audio.Midi
public override int Close(IntPtr sfHandle)
{
var stream = _openStreams[(int) sfHandle];
if (!_openStreams.Remove((int) sfHandle, out var stream))
return -1;
stream.Dispose();
_openStreams.Remove((int) sfHandle);
return 0;
}
}
}

View File

@@ -8,6 +8,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
using MidiEvent = NFluidsynth.MidiEvent;
namespace Robust.Client.Audio.Midi
@@ -21,6 +22,17 @@ namespace Robust.Client.Audio.Midi
public interface IMidiRenderer : IDisposable
{
/// <summary>
/// The buffered audio source of this renderer.
/// </summary>
internal IClydeBufferedAudioSource Source { get; }
/// <summary>
/// Whether this renderer has been disposed or not.
/// </summary>
bool Disposed { get; }
/// <summary>
/// This controls whether the midi file being played will loop or not.
/// </summary>
@@ -110,6 +122,11 @@ namespace Robust.Client.Audio.Midi
/// </summary>
void StopAllNotes();
/// <summary>
/// Render and play MIDI to the audio source.
/// </summary>
internal void Render();
/// <summary>
/// Loads a new soundfont into the renderer.
/// </summary>
@@ -159,7 +176,7 @@ namespace Robust.Client.Audio.Midi
internal void InternalDispose();
}
public class MidiRenderer : IMidiRenderer
internal class MidiRenderer : IMidiRenderer
{
[Dependency] private readonly IClydeAudio _clydeAudio = default!;
[Dependency] private readonly ITaskManager _taskManager = default!;
@@ -188,8 +205,12 @@ namespace Robust.Client.Audio.Midi
private readonly object _playerStateLock = new();
private SequencerClientId _synthRegister;
public IClydeBufferedAudioSource Source { get; set; }
IClydeBufferedAudioSource IMidiRenderer.Source => Source;
[ViewVariables]
public bool Disposed { get; private set; } = false;
[ViewVariables(VVAccess.ReadWrite)]
public byte MidiProgram
{
get => _midiProgram;
@@ -203,6 +224,7 @@ namespace Robust.Client.Audio.Midi
}
}
[ViewVariables(VVAccess.ReadWrite)]
public byte MidiBank
{
get => _midiBank;
@@ -216,6 +238,7 @@ namespace Robust.Client.Audio.Midi
}
}
[ViewVariables(VVAccess.ReadWrite)]
public uint MidiSoundfont
{
get => _midiSoundfont;
@@ -229,10 +252,16 @@ namespace Robust.Client.Audio.Midi
}
}
[ViewVariables(VVAccess.ReadWrite)]
public bool DisablePercussionChannel { get; set; } = true;
[ViewVariables(VVAccess.ReadWrite)]
public bool DisableProgramChangeEvent { get; set; } = true;
[ViewVariables(VVAccess.ReadWrite)]
public int PlayerTotalTick => _player?.GetTotalTicks ?? 0;
[ViewVariables(VVAccess.ReadWrite)]
public int PlayerTick
{
get => _player?.CurrentTick ?? 0;
@@ -243,12 +272,19 @@ namespace Robust.Client.Audio.Midi
}
}
[ViewVariables(VVAccess.ReadWrite)]
public uint SequencerTick => _sequencer?.Tick ?? 0;
[ViewVariables(VVAccess.ReadWrite)]
public double SequencerTimeScale => _sequencer?.TimeScale ?? 0;
[ViewVariables(VVAccess.ReadWrite)]
public bool Mono { get; set; }
[ViewVariables]
public MidiRendererStatus Status { get; private set; } = MidiRendererStatus.None;
[ViewVariables(VVAccess.ReadWrite)]
public bool LoopMidi
{
get => _loopMidi;
@@ -260,10 +296,11 @@ namespace Robust.Client.Audio.Midi
}
}
[ViewVariables(VVAccess.ReadWrite)]
public IEntity? TrackingEntity { get; set; } = null;
public EntityCoordinates? TrackingCoordinates { get; set; } = null;
internal bool Free { get; set; } = false;
[ViewVariables(VVAccess.ReadWrite)]
public EntityCoordinates? TrackingCoordinates { get; set; } = null;
internal MidiRenderer(Settings settings, SoundFontLoader soundFontLoader, bool mono = true)
{
@@ -294,7 +331,11 @@ namespace Robust.Client.Audio.Midi
Status = MidiRendererStatus.Input;
StopAllNotes();
_driver = new MidiDriver(_settings, MidiDriverEventHandler);
lock (_playerStateLock)
{
_driver = new MidiDriver(_settings, MidiDriverEventHandler);
}
return true;
}
@@ -332,8 +373,13 @@ namespace Robust.Client.Audio.Midi
{
if (Status != MidiRendererStatus.Input) return false;
Status = MidiRendererStatus.None;
_driver?.Dispose();
_driver = null;
lock (_playerStateLock)
{
_driver?.Dispose();
_driver = null;
}
StopAllNotes();
return true;
}
@@ -357,7 +403,8 @@ namespace Robust.Client.Audio.Midi
public void StopAllNotes()
{
_synth.AllNotesOff(-1);
lock(_playerStateLock)
_synth.AllNotesOff(-1);
}
public void LoadSoundfont(string filename, bool resetPresets = false)
@@ -372,7 +419,12 @@ namespace Robust.Client.Audio.Midi
public event Action<Shared.Audio.Midi.MidiEvent>? OnMidiEvent;
public event Action? OnMidiPlayerFinished;
internal void Render(int length = SampleRate / 250)
void IMidiRenderer.Render()
{
Render();
}
private void Render(int length = SampleRate / 250)
{
if (Disposed) return;
@@ -452,6 +504,7 @@ namespace Robust.Client.Audio.Midi
var timestamp = SequencerTick;
var midiEv = (Shared.Audio.Midi.MidiEvent) midiEvent;
midiEv.Tick = timestamp;
midiEvent.Dispose();
SendMidiEvent(midiEv);
return 0;
}
@@ -462,6 +515,7 @@ namespace Robust.Client.Audio.Midi
var timestamp = SequencerTick;
var midiEv = (Shared.Audio.Midi.MidiEvent) midiEvent;
midiEv.Tick = timestamp;
midiEvent.Dispose();
SendMidiEvent(midiEv);
return 0;
}

View File

@@ -13,6 +13,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Players;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
@@ -25,6 +26,7 @@ namespace Robust.Client
[Dependency] private readonly IPlayerManager _playMan = default!;
[Dependency] private readonly INetConfigurationManager _configManager = default!;
[Dependency] private readonly IClientEntityManager _entityManager = default!;
[Dependency] private readonly IEntityLookup _entityLookup = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IDiscordRichPresence _discord = default!;
[Dependency] private readonly IGameTiming _timing = default!;
@@ -165,7 +167,7 @@ namespace Robust.Client
/// receiving states when they join the lobby.
/// </summary>
/// <param name="session">Session of the player.</param>
private void OnPlayerJoinedServer(IPlayerSession session)
private void OnPlayerJoinedServer(ICommonSession session)
{
DebugTools.Assert(RunLevel < ClientRunLevel.Connected);
OnRunLevelChanged(ClientRunLevel.Connected);
@@ -175,20 +177,11 @@ namespace Robust.Client
PlayerJoinedServer?.Invoke(this, new PlayerEventArgs(session));
}
private void GameStartedSetup()
{
_entityManager.Startup();
_mapManager.Startup();
_timing.ResetSimTime();
_timing.Paused = false;
}
/// <summary>
/// Player is joining the game
/// </summary>
/// <param name="session">Session of the player.</param>
private void OnPlayerJoinedGame(IPlayerSession session)
private void OnPlayerJoinedGame(ICommonSession session)
{
DebugTools.Assert(RunLevel >= ClientRunLevel.Connected);
OnRunLevelChanged(ClientRunLevel.InGame);
@@ -218,12 +211,22 @@ namespace Robust.Client
GameStoppedReset();
}
private void GameStartedSetup()
{
_entityManager.Startup();
_mapManager.Startup();
_entityLookup.Startup();
_timing.ResetSimTime();
_timing.Paused = false;
}
private void GameStoppedReset()
{
IoCManager.Resolve<INetConfigurationManager>().FlushMessages();
_gameStates.Reset();
_playMan.Shutdown();
IoCManager.Resolve<IEntityLookup>().Shutdown();
_entityLookup.Shutdown();
_entityManager.Shutdown();
_mapManager.Shutdown();
_discord.ClearPresence();
@@ -295,12 +298,12 @@ namespace Robust.Client
/// <summary>
/// The session that triggered the event.
/// </summary>
private IPlayerSession? Session { get; }
private ICommonSession? Session { get; }
/// <summary>
/// Constructs a new instance of the class.
/// </summary>
public PlayerEventArgs(IPlayerSession? session)
public PlayerEventArgs(ICommonSession? session)
{
Session = session;
}

View File

@@ -45,7 +45,7 @@ namespace Robust.Client
IoCManager.Register<IMapManagerInternal, ClientMapManager>();
IoCManager.Register<IClientMapManager, ClientMapManager>();
IoCManager.Register<IEntityManager, ClientEntityManager>();
IoCManager.Register<IEntityLookup, SharedEntityLookup>();
IoCManager.Register<IEntityLookup, EntityLookup>();
IoCManager.Register<IComponentFactory, ClientComponentFactory>();
IoCManager.Register<ITileDefinitionManager, ClydeTileDefinitionManager>();
IoCManager.Register<IClydeTileDefinitionManager, ClydeTileDefinitionManager>();

View File

@@ -30,7 +30,8 @@ namespace Robust.Client.Console
var console = new ScriptConsoleServer(this, session);
_activeConsoles.Add(session, console);
console.Open();
// FIXME: When this is Open(), resizing the window will cause its position to get NaN'd.
console.OpenCentered();
}
private void ReceiveScriptResponse(MsgScriptResponse message)

View File

@@ -93,7 +93,7 @@ namespace Robust.Client
// Disable load context usage on content start.
// This prevents Content.Client being loaded twice and things like csi blowing up because of it.
_modLoader.SetUseLoadContext(!ContentStart);
_modLoader.SetEnableSandboxing(Options.Sandboxing);
_modLoader.SetEnableSandboxing(false && Options.Sandboxing);
if (!_modLoader.TryLoadModulesFrom(new ResourcePath("/Assemblies/"), Options.ContentModulePrefix))
{
@@ -125,7 +125,6 @@ namespace Robust.Client
_prototypeManager.Resync();
_mapManager.Initialize();
_entityManager.Initialize();
IoCManager.Resolve<IEntityLookup>().Initialize();
_gameStateManager.Initialize();
_placementManager.Initialize();
_viewVariablesManager.Initialize();

View File

@@ -9,58 +9,30 @@ namespace Robust.Client.GameObjects
public ClientComponentFactory()
{
// Required for the engine to work
Register<MetaDataComponent>();
RegisterReference<MetaDataComponent, IMetaDataComponent>();
// Required for the engine to work
Register<TransformComponent>();
RegisterReference<TransformComponent, ITransformComponent>();
Register<MapComponent>();
RegisterReference<MapComponent, IMapComponent>();
Register<MapGridComponent>();
RegisterReference<MapGridComponent, IMapGridComponent>();
Register<PhysicsComponent>();
RegisterReference<PhysicsComponent, IPhysBody>();
Register<CollisionWakeComponent>();
Register<ContainerManagerComponent>();
RegisterReference<ContainerManagerComponent, IContainerManager>();
RegisterIgnore("KeyBindingInput");
Register<InputComponent>();
Register<SpriteComponent>();
RegisterReference<SpriteComponent, SharedSpriteComponent>();
RegisterReference<SpriteComponent, ISpriteComponent>();
Register<ClientOccluderComponent>();
RegisterReference<ClientOccluderComponent, OccluderComponent>();
Register<EyeComponent>();
RegisterReference<EyeComponent, SharedEyeComponent>();
Register<AppearanceComponent>();
RegisterReference<AppearanceComponent, SharedAppearanceComponent>();
Register<AppearanceTestComponent>();
Register<SnapGridComponent>();
Register<ClientUserInterfaceComponent>();
RegisterReference<ClientUserInterfaceComponent, SharedUserInterfaceComponent>();
Register<AnimationPlayerComponent>();
Register<TimerComponent>();
RegisterClass<MetaDataComponent>();
RegisterClass<TransformComponent>();
RegisterClass<MapComponent>();
RegisterClass<MapGridComponent>();
RegisterClass<PhysicsComponent>();
RegisterClass<CollisionWakeComponent>();
RegisterClass<ClientUserInterfaceComponent>();
RegisterClass<ContainerManagerComponent>();
RegisterClass<InputComponent>();
RegisterClass<SpriteComponent>();
RegisterClass<ClientOccluderComponent>();
RegisterClass<EyeComponent>();
RegisterClass<AppearanceComponent>();
RegisterClass<AppearanceTestComponent>();
RegisterClass<SnapGridComponent>();
RegisterClass<AnimationPlayerComponent>();
RegisterClass<TimerComponent>();
#if DEBUG
Register<DebugExceptionOnAddComponent>();
Register<DebugExceptionInitializeComponent>();
Register<DebugExceptionStartupComponent>();
RegisterClass<DebugExceptionOnAddComponent>();
RegisterClass<DebugExceptionInitializeComponent>();
RegisterClass<DebugExceptionStartupComponent>();
#endif
}

View File

@@ -109,6 +109,7 @@ namespace Robust.Client.GameObjects
}
/// <inheritdoc />
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public void SendComponentNetworkMessage(INetChannel? channel, IEntity entity, IComponent component, ComponentMessage message)
{
if (!component.NetID.HasValue)

View File

@@ -10,6 +10,7 @@ using YamlDotNet.RepresentationModel;
namespace Robust.Client.GameObjects
{
[ComponentReference(typeof(SharedAppearanceComponent))]
public sealed class AppearanceComponent : SharedAppearanceComponent
{
[ViewVariables]

View File

@@ -10,6 +10,7 @@ using Robust.Shared.ViewVariables;
namespace Robust.Client.GameObjects
{
[ComponentReference(typeof(SharedEyeComponent))]
public class EyeComponent : SharedEyeComponent
{
[Dependency] private readonly IEyeManager _eyeManager = default!;

View File

@@ -8,10 +8,11 @@ using Robust.Shared.ViewVariables;
namespace Robust.Client.GameObjects
{
[ComponentReference(typeof(OccluderComponent))]
internal sealed class ClientOccluderComponent : OccluderComponent
{
[Dependency] private readonly IMapManager _mapManager = default!;
[ViewVariables] private (GridId, Vector2i) _lastPosition;
[ViewVariables] internal OccluderDir Occluding { get; private set; }
[ViewVariables] internal uint UpdateGeneration { get; set; }

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Shared.Animations;
@@ -167,7 +168,7 @@ namespace Robust.Client.GameObjects
set
{
_radius = MathF.Max(value, 0.01f); // setting radius to 0 causes exceptions, so just use a value close enough to zero that it's unnoticeable.
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new PointLightRadiusChangedMessage(this));
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new PointLightRadiusChangedEvent(this));
}
}
@@ -179,6 +180,18 @@ namespace Robust.Client.GameObjects
Mask = null;
}
/// <summary>
/// What MapId we are intersecting for RenderingTreeSystem.
/// </summary>
[ViewVariables]
internal MapId IntersectingMapId { get; set; } = MapId.Nullspace;
/// <summary>
/// What grids we're on for RenderingTreeSystem.
/// </summary>
[ViewVariables]
internal List<GridId> IntersectingGrids = new();
void ISerializationHooks.AfterDeserialization()
{
if (_maskPath != null)
@@ -230,7 +243,7 @@ namespace Robust.Client.GameObjects
if (map != MapId.Nullspace)
{
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local,
new RenderTreeRemoveLightMessage(this, map));
new RenderTreeRemoveLightEvent(this, map));
}
}
@@ -248,11 +261,11 @@ namespace Robust.Client.GameObjects
}
}
public struct PointLightRadiusChangedMessage
public class PointLightRadiusChangedEvent : EntityEventArgs
{
public PointLightComponent PointLightComponent { get; }
public PointLightRadiusChangedMessage(PointLightComponent pointLightComponent)
public PointLightRadiusChangedEvent(PointLightComponent pointLightComponent)
{
PointLightComponent = pointLightComponent;
}

View File

@@ -27,6 +27,8 @@ using DrawDepthTag = Robust.Shared.GameObjects.DrawDepth;
namespace Robust.Client.GameObjects
{
[ComponentReference(typeof(SharedSpriteComponent))]
[ComponentReference(typeof(ISpriteComponent))]
public sealed class SpriteComponent : SharedSpriteComponent, ISpriteComponent,
IComponentDebug, ISerializationHooks
{
@@ -123,6 +125,18 @@ namespace Robust.Client.GameObjects
[DataField("directional")]
private bool _directional = true;
/// <summary>
/// What MapId we are intersecting for RenderingTreeSystem.
/// </summary>
[ViewVariables]
internal MapId IntersectingMapId { get; set; } = MapId.Nullspace;
/// <summary>
/// What grids we're on for RenderingTreeSystem.
/// </summary>
[ViewVariables]
internal List<GridId> IntersectingGrids { get; } = new();
[DataField("layerDatums")]
private List<PrototypeLayerData> LayerDatums
{
@@ -1353,7 +1367,7 @@ namespace Robust.Client.GameObjects
if (map != MapId.Nullspace)
{
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local,
new RenderTreeRemoveSpriteMessage(this, map));
new RenderTreeRemoveSpriteEvent(this, map));
}
}
@@ -1576,9 +1590,10 @@ namespace Robust.Client.GameObjects
{
var builder = new StringBuilder();
builder.AppendFormat(
"vis/depth/scl/rot/ofs/col/diral/dir: {0}/{1}/{2}/{3}/{4}/{5}/{6}/{7}\n",
"vis/depth/scl/rot/ofs/col/norot/override/dir: {0}/{1}/{2}/{3}/{4}/{5}/{6}/{8}/{7}\n",
Visible, DrawDepth, Scale, Rotation, Offset,
Color, Directional, GetDir(RSI.State.DirectionType.Dir8, Owner.Transform.WorldRotation)
Color, NoRotation, GetDir(RSI.State.DirectionType.Dir8, Owner.Transform.WorldRotation),
DirectionOverride
);
foreach (var layer in Layers)
@@ -2176,6 +2191,10 @@ namespace Robust.Client.GameObjects
return null;
}
public void QueueDelete()
{
}
public void Delete()
{
}
@@ -2190,10 +2209,12 @@ namespace Robust.Client.GameObjects
return Enumerable.Empty<T>();
}
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public void SendMessage(IComponent? owner, ComponentMessage message)
{
}
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public void SendNetworkMessage(IComponent owner, ComponentMessage message, INetChannel? channel = null)
{
}

View File

@@ -2,14 +2,14 @@
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Network;
using Robust.Shared.Players;
using Robust.Shared.Reflection;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Robust.Client.GameObjects
{
[ComponentReference(typeof(SharedUserInterfaceComponent))]
public class ClientUserInterfaceComponent : SharedUserInterfaceComponent, ISerializationHooks
{
[Dependency] private readonly IReflectionManager _reflectionManager = default!;
@@ -23,6 +23,9 @@ namespace Robust.Client.GameObjects
[DataField("interfaces", readOnly: true)]
private List<PrototypeData> _interfaceData = new();
[ViewVariables]
public IEnumerable<BoundUserInterface> Interfaces => _openInterfaces.Values;
void ISerializationHooks.AfterDeserialization()
{
_interfaces.Clear();
@@ -33,48 +36,40 @@ namespace Robust.Client.GameObjects
}
}
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel,
ICommonSession? session = null)
internal void MessageReceived(BoundUIWrapMessage msg)
{
base.HandleNetworkMessage(message, netChannel, session);
switch (message)
switch (msg.Message)
{
case BoundInterfaceMessageWrapMessage wrapped:
// Double nested switches who needs readability anyways.
switch (wrapped.Message)
case OpenBoundInterfaceMessage _:
if (_openInterfaces.ContainsKey(msg.UiKey))
{
case OpenBoundInterfaceMessage _:
if (_openInterfaces.ContainsKey(wrapped.UiKey))
{
return;
}
return;
}
OpenInterface(wrapped);
break;
OpenInterface(msg);
break;
case CloseBoundInterfaceMessage _:
Close(wrapped.UiKey, true);
break;
case CloseBoundInterfaceMessage _:
Close(msg.UiKey, true);
break;
default:
if (_openInterfaces.TryGetValue(wrapped.UiKey, out var bi))
{
bi.InternalReceiveMessage(wrapped.Message);
}
break;
default:
if (_openInterfaces.TryGetValue(msg.UiKey, out var bi))
{
bi.InternalReceiveMessage(msg.Message);
}
break;
}
}
private void OpenInterface(BoundInterfaceMessageWrapMessage wrapped)
private void OpenInterface(BoundUIWrapMessage wrapped)
{
var data = _interfaces[wrapped.UiKey];
// TODO: This type should be cached, but I'm too lazy.
var type = _reflectionManager.LooseGetType(data.ClientType);
var boundInterface = (BoundUserInterface) _dynamicTypeFactory.CreateInstance(type, new[]{this, wrapped.UiKey});
var boundInterface =
(BoundUserInterface) _dynamicTypeFactory.CreateInstance(type, new[] {this, wrapped.UiKey});
boundInterface.Open();
_openInterfaces[wrapped.UiKey] = boundInterface;
}
@@ -86,7 +81,7 @@ namespace Robust.Client.GameObjects
return;
}
if(!remoteCall)
if (!remoteCall)
SendMessage(new CloseBoundInterfaceMessage(), uiKey);
_openInterfaces.Remove(uiKey);
boundUserInterface.Dispose();
@@ -94,7 +89,8 @@ namespace Robust.Client.GameObjects
internal void SendMessage(BoundUserInterfaceMessage message, object uiKey)
{
SendNetworkMessage(new BoundInterfaceMessageWrapMessage(message, uiKey));
EntitySystem.Get<UserInterfaceSystem>()
.Send(new BoundUIWrapMessage(Owner.Uid, message, uiKey));
}
}

View File

@@ -41,17 +41,6 @@ namespace Robust.Client.GameObjects
_broadPhaseSystem = Get<SharedBroadPhaseSystem>();
}
public override void Shutdown()
{
base.Shutdown();
UnsubscribeNetworkEvent<PlayAudioEntityMessage>();
UnsubscribeNetworkEvent<PlayAudioGlobalMessage>();
UnsubscribeNetworkEvent<PlayAudioPositionalMessage>();
UnsubscribeNetworkEvent<StopAudioMessageClient>();
UnsubscribeLocalEvent<SoundSystem.QueryAudioSystem>();
}
private void StopAudioMessageHandler(StopAudioMessageClient ev)
{
var stream = _playingClydeStreams.Find(p => p.NetIdentifier == ev.Identifier);

View File

@@ -38,15 +38,6 @@ namespace Robust.Client.GameObjects
SubscribeLocalEvent<ClientOccluderComponent, SnapGridPositionChangedEvent>(HandleSnapGridMove);
}
/// <inheritdoc />
public override void Shutdown()
{
UnsubscribeLocalEvent<OccluderDirtyEvent>();
UnsubscribeLocalEvent<ClientOccluderComponent, SnapGridPositionChangedEvent>();
base.Shutdown();
}
public override void FrameUpdate(float frameTime)
{
base.FrameUpdate(frameTime);

View File

@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using JetBrains.Annotations;
using Robust.Client.Physics;
using Robust.Shared.GameObjects;
@@ -6,6 +8,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Utility;
namespace Robust.Client.GameObjects
{
@@ -47,14 +50,148 @@ namespace Robust.Client.GameObjects
_mapManager.OnGridCreated += MapManagerOnGridCreated;
_mapManager.OnGridRemoved += MapManagerOnGridRemoved;
SubscribeLocalEvent<EntMapIdChangedMessage>(EntMapIdChanged);
SubscribeLocalEvent<MoveEvent>(EntMoved);
SubscribeLocalEvent<EntParentChangedMessage>(EntParentChanged);
SubscribeLocalEvent<PointLightRadiusChangedMessage>(PointLightRadiusChanged);
SubscribeLocalEvent<RenderTreeRemoveSpriteMessage>(RemoveSprite);
SubscribeLocalEvent<RenderTreeRemoveLightMessage>(RemoveLight);
SubscribeLocalEvent<SpriteComponent, EntMapIdChangedMessage>(SpriteMapChanged);
SubscribeLocalEvent<SpriteComponent, MoveEvent>(SpriteMoved);
SubscribeLocalEvent<SpriteComponent, EntParentChangedMessage>(SpriteParentChanged);
SubscribeLocalEvent<SpriteComponent, RenderTreeRemoveSpriteEvent>(RemoveSprite);
SubscribeLocalEvent<PointLightComponent, EntMapIdChangedMessage>(LightMapChanged);
SubscribeLocalEvent<PointLightComponent, MoveEvent>(LightMoved);
SubscribeLocalEvent<PointLightComponent, EntParentChangedMessage>(LightParentChanged);
SubscribeLocalEvent<PointLightComponent, PointLightRadiusChangedEvent>(PointLightRadiusChanged);
SubscribeLocalEvent<PointLightComponent, RenderTreeRemoveLightEvent>(RemoveLight);
}
// For the RemoveX methods
// If the Transform is removed BEFORE the Sprite/Light,
// then the MapIdChanged code will handle and remove it (because MapId gets set to nullspace).
// Otherwise these will still have their past MapId and that's all we need..
#region SpriteHandlers
private void SpriteMapChanged(EntityUid uid, SpriteComponent component, EntMapIdChangedMessage args)
{
QueueSpriteUpdate(component);
}
private void SpriteMoved(EntityUid uid, SpriteComponent component, MoveEvent args)
{
QueueSpriteUpdate(component);
}
private void SpriteParentChanged(EntityUid uid, SpriteComponent component, EntParentChangedMessage args)
{
QueueSpriteUpdate(component);
}
private void RemoveSprite(EntityUid uid, SpriteComponent component, RenderTreeRemoveSpriteEvent args)
{
ClearSprite(component);
}
private void ClearSprite(SpriteComponent component)
{
if (_gridTrees.TryGetValue(component.IntersectingMapId, out var gridTrees))
{
foreach (var gridId in component.IntersectingGrids)
{
if (!gridTrees.TryGetValue(gridId, out var tree)) continue;
tree.SpriteTree.Remove(component);
}
}
component.IntersectingGrids.Clear();
}
private void QueueSpriteUpdate(SpriteComponent component)
{
if (component.TreeUpdateQueued) return;
component.TreeUpdateQueued = true;
_spriteQueue.Add(component);
foreach (var child in component.Owner.Transform.Children)
{
QueueSpriteUpdate(child.Owner);
}
}
private void QueueSpriteUpdate(IEntity entity)
{
if (!entity.TryGetComponent(out SpriteComponent? spriteComponent)) return;
QueueSpriteUpdate(spriteComponent);
foreach (var child in entity.Transform.Children)
{
QueueSpriteUpdate(child.Owner);
}
}
#endregion
#region LightHandlers
private void LightMapChanged(EntityUid uid, PointLightComponent component, EntMapIdChangedMessage args)
{
QueueLightUpdate(component);
}
private void LightMoved(EntityUid uid, PointLightComponent component, MoveEvent args)
{
QueueLightUpdate(component);
}
private void LightParentChanged(EntityUid uid, PointLightComponent component, EntParentChangedMessage args)
{
QueueLightUpdate(component);
}
private void PointLightRadiusChanged(EntityUid uid, PointLightComponent component, PointLightRadiusChangedEvent args)
{
QueueLightUpdate(component);
}
private void RemoveLight(EntityUid uid, PointLightComponent component, RenderTreeRemoveLightEvent args)
{
ClearLight(component);
}
private void ClearLight(PointLightComponent component)
{
if (_gridTrees.TryGetValue(component.IntersectingMapId, out var gridTrees))
{
foreach (var gridId in component.IntersectingGrids)
{
if (!gridTrees.TryGetValue(gridId, out var tree)) continue;
tree.LightTree.Remove(component);
}
}
component.IntersectingGrids.Clear();
}
private void QueueLightUpdate(PointLightComponent component)
{
if (component.TreeUpdateQueued) return;
component.TreeUpdateQueued = true;
_lightQueue.Add(component);
foreach (var child in component.Owner.Transform.Children)
{
QueueLightUpdate(child.Owner);
}
}
private void QueueLightUpdate(IEntity entity)
{
if (!entity.TryGetComponent(out PointLightComponent? lightComponent)) return;
QueueLightUpdate(lightComponent);
foreach (var child in entity.Transform.Children)
{
QueueLightUpdate(child.Owner);
}
}
#endregion
public override void Shutdown()
{
base.Shutdown();
@@ -62,136 +199,27 @@ namespace Robust.Client.GameObjects
_mapManager.MapDestroyed -= MapManagerOnMapDestroyed;
_mapManager.OnGridCreated -= MapManagerOnGridCreated;
_mapManager.OnGridRemoved -= MapManagerOnGridRemoved;
UnsubscribeLocalEvent<EntMapIdChangedMessage>();
UnsubscribeLocalEvent<MoveEvent>();
UnsubscribeLocalEvent<EntParentChangedMessage>();
UnsubscribeLocalEvent<PointLightRadiusChangedMessage>();
UnsubscribeLocalEvent<RenderTreeRemoveSpriteMessage>();
UnsubscribeLocalEvent<RenderTreeRemoveLightMessage>();
}
// For these next 2 methods (the Remove* ones):
// If the Transform is removed BEFORE the Sprite/Light,
// then the MapIdChanged code will handle and remove it (because MapId gets set to nullspace).
// Otherwise these will still have their past MapId and that's all we need..
private void RemoveLight(RenderTreeRemoveLightMessage ev)
{
foreach (var gridId in _mapManager.FindGridIdsIntersecting(ev.Map, MapTrees.LightAabbFunc(ev.Light), true))
{
_gridTrees[ev.Map][gridId].LightTree.Remove(ev.Light);
}
}
private void RemoveSprite(RenderTreeRemoveSpriteMessage ev)
{
foreach (var gridId in _mapManager.FindGridIdsIntersecting(ev.Map, MapTrees.SpriteAabbFunc(ev.Sprite), true))
{
_gridTrees[ev.Map][gridId].SpriteTree.Remove(ev.Sprite);
}
}
private void PointLightRadiusChanged(PointLightRadiusChangedMessage ev)
{
QueueUpdateLight(ev.PointLightComponent);
}
private void EntParentChanged(EntParentChangedMessage ev)
{
UpdateEntity(ev.Entity);
}
private void EntMoved(MoveEvent ev)
{
UpdateEntity(ev.Sender);
}
private void UpdateEntity(IEntity entity)
{
if (entity.TryGetComponent(out SpriteComponent? spriteComponent))
{
if (!spriteComponent.TreeUpdateQueued)
{
spriteComponent.TreeUpdateQueued = true;
_spriteQueue.Add(spriteComponent);
}
}
if (entity.TryGetComponent(out PointLightComponent? light))
{
QueueUpdateLight(light);
}
foreach (var child in entity.Transform.ChildEntityUids)
{
UpdateEntity(EntityManager.GetEntity(child));
}
}
private void QueueUpdateLight(PointLightComponent light)
{
if (!light.TreeUpdateQueued)
{
light.TreeUpdateQueued = true;
_lightQueue.Add(light);
}
}
private void EntMapIdChanged(EntMapIdChangedMessage ev)
{
// Nullspace is a valid map ID for stuff to have but we also aren't gonna bother indexing it.
// So that's why there's a GetValueOrDefault.
var oldMapTrees = _gridTrees.GetValueOrDefault(ev.OldMapId);
var newMapTrees = _gridTrees.GetValueOrDefault(ev.Entity.Transform.MapID);
// TODO: MMMM probably a better way to do this.
if (ev.Entity.TryGetComponent(out SpriteComponent? sprite))
{
if (oldMapTrees != null)
{
foreach (var (_, gridTree) in oldMapTrees)
{
gridTree.SpriteTree.Remove(sprite);
}
}
var bounds = MapTrees.SpriteAabbFunc(sprite);
foreach (var gridId in _mapManager.FindGridIdsIntersecting(ev.Entity.Transform.MapID, bounds, true))
{
var gridBounds = gridId == GridId.Invalid
? bounds : bounds.Translated(-_mapManager.GetGrid(gridId).WorldPosition);
newMapTrees?[gridId].SpriteTree.AddOrUpdate(sprite, gridBounds);
}
}
if (ev.Entity.TryGetComponent(out PointLightComponent? light))
{
if (oldMapTrees != null)
{
foreach (var (_, gridTree) in oldMapTrees)
{
gridTree.LightTree.Remove(light);
}
}
var bounds = MapTrees.LightAabbFunc(light);
foreach (var gridId in _mapManager.FindGridIdsIntersecting(ev.Entity.Transform.MapID, bounds, true))
{
var gridBounds = gridId == GridId.Invalid
? bounds : bounds.Translated(-_mapManager.GetGrid(gridId).WorldPosition);
newMapTrees?[gridId].LightTree.AddOrUpdate(light, gridBounds);
}
}
}
private void MapManagerOnMapDestroyed(object? sender, MapEventArgs e)
{
foreach (var (_, gridTree) in _gridTrees[e.Map])
{
foreach (var comp in gridTree.LightTree)
{
comp.IntersectingGrids.Clear();
}
foreach (var comp in gridTree.SpriteTree)
{
comp.IntersectingGrids.Clear();
}
// Just in case?
gridTree.LightTree.Clear();
gridTree.SpriteTree.Clear();
}
_gridTrees.Remove(e.Map);
}
@@ -215,47 +243,109 @@ namespace Robust.Client.GameObjects
private void MapManagerOnGridRemoved(MapId mapId, GridId gridId)
{
var gridTree = _gridTrees[mapId][gridId];
foreach (var sprite in gridTree.SpriteTree)
{
sprite.IntersectingGrids.Remove(gridId);
}
foreach (var light in gridTree.LightTree)
{
light.IntersectingGrids.Remove(gridId);
}
// Clear in case
gridTree.LightTree.Clear();
gridTree.SpriteTree.Clear();
_gridTrees[mapId].Remove(gridId);
}
public override void FrameUpdate(float frameTime)
{
foreach (var queuedUpdateSprite in _spriteQueue)
foreach (var sprite in _spriteQueue)
{
var map = queuedUpdateSprite.Owner.Transform.MapID;
if (map == MapId.Nullspace)
var mapId = sprite.Owner.Transform.MapID;
// If we're on a new map then clear the old one.
if (sprite.IntersectingMapId != mapId)
{
continue;
ClearSprite(sprite);
}
var mapTree = _gridTrees[map];
sprite.IntersectingMapId = mapId;
foreach (var gridId in _mapManager.FindGridIdsIntersecting(map,
MapTrees.SpriteAabbFunc(queuedUpdateSprite), true))
if (mapId == MapId.Nullspace) continue;
var mapTree = _gridTrees[mapId];
var aabb = MapTrees.SpriteAabbFunc(sprite);
var intersectingGrids = _mapManager.FindGridIdsIntersecting(mapId, aabb, true).ToList();
// Remove from old
foreach (var gridId in sprite.IntersectingGrids)
{
mapTree[gridId].SpriteTree.AddOrUpdate(queuedUpdateSprite);
if (intersectingGrids.Contains(gridId)) continue;
mapTree[gridId].SpriteTree.Remove(sprite);
}
queuedUpdateSprite.TreeUpdateQueued = false;
// Rebuild in the update below
sprite.IntersectingGrids.Clear();
// Update / add to new
foreach (var gridId in intersectingGrids)
{
var translated = aabb.Translated(gridId == GridId.Invalid
? Vector2.Zero
: -_mapManager.GetGrid(gridId).WorldPosition);
mapTree[gridId].SpriteTree.AddOrUpdate(sprite, translated);
sprite.IntersectingGrids.Add(gridId);
}
sprite.TreeUpdateQueued = false;
}
foreach (var queuedUpdateLight in _lightQueue)
foreach (var light in _lightQueue)
{
var map = queuedUpdateLight.Owner.Transform.MapID;
if (map == MapId.Nullspace)
var mapId = light.Owner.Transform.MapID;
// If we're on a new map then clear the old one.
if (light.IntersectingMapId != mapId)
{
continue;
ClearLight(light);
}
var mapTree = _gridTrees[map];
light.IntersectingMapId = mapId;
foreach (var gridId in _mapManager.FindGridIdsIntersecting(map,
MapTrees.LightAabbFunc(queuedUpdateLight), true))
if (mapId == MapId.Nullspace) continue;
var mapTree = _gridTrees[mapId];
var aabb = MapTrees.LightAabbFunc(light);
var intersectingGrids = _mapManager.FindGridIdsIntersecting(mapId, aabb, true).ToList();
// Remove from old
foreach (var gridId in intersectingGrids)
{
mapTree[gridId].LightTree.AddOrUpdate(queuedUpdateLight);
if (intersectingGrids.Contains(gridId)) continue;
mapTree[gridId].LightTree.Remove(light);
}
queuedUpdateLight.TreeUpdateQueued = false;
// Rebuild in the update below
light.IntersectingGrids.Clear();
// Update / add to new
foreach (var gridId in intersectingGrids)
{
var translated = aabb.Translated(gridId == GridId.Invalid
? Vector2.Zero
: -_mapManager.GetGrid(gridId).WorldPosition);
mapTree[gridId].LightTree.AddOrUpdate(light, translated);
light.IntersectingGrids.Add(gridId);
}
light.TreeUpdateQueued = false;
}
_spriteQueue.Clear();
@@ -290,9 +380,9 @@ namespace Robust.Client.GameObjects
}
}
internal struct RenderTreeRemoveSpriteMessage
internal class RenderTreeRemoveSpriteEvent : EntityEventArgs
{
public RenderTreeRemoveSpriteMessage(SpriteComponent sprite, MapId map)
public RenderTreeRemoveSpriteEvent(SpriteComponent sprite, MapId map)
{
Sprite = sprite;
Map = map;
@@ -302,9 +392,9 @@ namespace Robust.Client.GameObjects
public MapId Map { get; }
}
internal struct RenderTreeRemoveLightMessage
internal class RenderTreeRemoveLightEvent : EntityEventArgs
{
public RenderTreeRemoveLightMessage(PointLightComponent light, MapId map)
public RenderTreeRemoveLightEvent(PointLightComponent light, MapId map)
{
Light = light;
Map = map;

View File

@@ -16,11 +16,17 @@ namespace Robust.Client.GameObjects
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
private RenderingTreeSystem _treeSystem = default!;
public override void Initialize()
{
base.Initialize();
_treeSystem = Get<RenderingTreeSystem>();
}
/// <inheritdoc />
public override void FrameUpdate(float frameTime)
{
var renderTreeSystem = EntitySystemManager.GetEntitySystem<RenderingTreeSystem>();
// So we could calculate the correct size of the entities based on the contents of their sprite...
// Or we can just assume that no entity is larger than 10x10 and get a stupid easy check.
var pvsBounds = _eyeManager.GetWorldViewport().Enlarged(5);
@@ -33,18 +39,9 @@ namespace Robust.Client.GameObjects
foreach (var gridId in _mapManager.FindGridIdsIntersecting(currentMap, pvsBounds, true))
{
Box2 gridBounds;
var gridBounds = gridId == GridId.Invalid ? pvsBounds : pvsBounds.Translated(-_mapManager.GetGrid(gridId).WorldPosition);
if (gridId == GridId.Invalid)
{
gridBounds = pvsBounds;
}
else
{
gridBounds = pvsBounds.Translated(-_mapManager.GetGrid(gridId).WorldPosition);
}
var mapTree = renderTreeSystem.GetSpriteTreeForMap(currentMap, gridId);
var mapTree = _treeSystem.GetSpriteTreeForMap(currentMap, gridId);
mapTree.QueryAabb(ref frameTime, (ref float state, in SpriteComponent value) =>
{

View File

@@ -0,0 +1,37 @@
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Robust.Client.GameObjects
{
[UsedImplicitly]
public sealed class UserInterfaceSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<BoundUIWrapMessage>(MessageReceived);
SubscribeLocalEvent<ClientUserInterfaceComponent, ComponentShutdown>(OnUserInterfaceShutdown);
}
private void OnUserInterfaceShutdown(EntityUid uid, ClientUserInterfaceComponent component, ComponentShutdown args)
{
foreach (var bui in component.Interfaces)
{
bui.Dispose();
}
}
private void MessageReceived(BoundUIWrapMessage ev)
{
var cmp = ComponentManager.GetComponent<ClientUserInterfaceComponent>(ev.Entity);
cmp.MessageReceived(ev);
}
internal void Send(BoundUIWrapMessage msg)
{
RaiseNetworkEvent(msg);
}
}
}

View File

@@ -1,12 +1,15 @@
using System;
using Robust.Shared.GameObjects;
namespace Robust.Client.GameObjects
{
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public class PlayerAttachedMsg : ComponentMessage
{
}
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public class PlayerDetachedMsg : ComponentMessage
{

View File

@@ -146,13 +146,12 @@ namespace Robust.Client.GameStates
private void DrawWorld(in OverlayDrawArgs args)
{
bool pvsEnabled = _configurationManager.GetCVar<bool>("net.pvs");
if(!pvsEnabled)
return;
float pvsSize = _configurationManager.GetCVar<float>("net.maxupdaterange");
float pvsRange = _configurationManager.GetCVar<float>("net.maxupdaterange");
var pvsCenter = _eyeManager.CurrentEye.Position;
Box2 pvsBox = Box2.CenteredAround(pvsCenter.Position, new Vector2(pvsSize, pvsSize));
Box2 pvsBox = Box2.CenteredAround(pvsCenter.Position, new Vector2(pvsRange * 2, pvsRange * 2));
var worldHandle = args.WorldHandle;

View File

@@ -183,6 +183,32 @@ namespace Robust.Client.Graphics.Clyde
if (handles.filterHandle != 0) EFX.DeleteFilter(handles.filterHandle);
}
public AudioStream LoadAudioRaw(short[] samples, int channels, int sampleRate)
{
var buffer = AL.GenBuffer();
unsafe
{
fixed (short* ptr = samples)
{
AL.BufferData(
buffer,
channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16,
(IntPtr) ptr,
samples.Length * 2,
sampleRate);
}
}
_checkAlError();
var handle = new ClydeHandle(_audioSampleBuffers.Count);
_audioSampleBuffers.Add(new LoadedAudioSample(buffer));
// ReSharper disable once PossibleLossOfFraction
var length = TimeSpan.FromSeconds(samples.Length / channels / (double) sampleRate);
return new AudioStream(handle, length, channels);
}
public void SetMasterVolume(float newVolume)
{
AL.Listener(ALListenerf.Gain, _baseGain * newVolume);
@@ -439,6 +465,21 @@ namespace Robust.Client.Graphics.Clyde
_checkAlError();
}
public void SetVolumeDirect(float decibels)
{
_checkDisposed();
var priorOcclusion = 1f;
if (!IsEfxSupported)
{
AL.GetSource(SourceHandle, ALSourcef.Gain, out var priorGain);
priorOcclusion = priorGain / _gain;
}
_gain = decibels;
AL.Source(SourceHandle, ALSourcef.Gain, _gain * priorOcclusion);
_checkAlError();
}
public void SetOcclusion(float blocks)
{
_checkDisposed();
@@ -747,6 +788,21 @@ namespace Robust.Client.Graphics.Clyde
_checkAlError();
}
public void SetVolumeDirect(float masterVolumeDecay)
{
_checkDisposed();
var priorOcclusion = 1f;
if (!IsEfxSupported)
{
AL.GetSource(SourceHandle!.Value, ALSourcef.Gain, out var priorGain);
priorOcclusion = priorGain / _gain;
}
_gain = masterVolumeDecay;
AL.Source(SourceHandle!.Value, ALSourcef.Gain, _gain * priorOcclusion);
_checkAlError();
}
public void SetPitch(float pitch)
{
_checkDisposed();

View File

@@ -59,7 +59,6 @@ namespace Robust.Client.Graphics.Clyde
private bool _enableSoftShadows = true;
private bool _checkGLErrors;
private bool _initialized;
private Thread? _gameThread;
@@ -105,7 +104,6 @@ namespace Robust.Client.Graphics.Clyde
return false;
_initializeAudio();
_initialized = true;
return true;
}

View File

@@ -48,14 +48,14 @@ namespace Robust.Client.Graphics.Clyde
public IClydeDebugInfo DebugInfo { get; } = new DummyDebugInfo();
public IClydeDebugStats DebugStats { get; } = new DummyDebugStats();
public event Action<TextEventArgs>? TextEntered;
public event Action<MouseMoveEventArgs>? MouseMove;
public event Action<MouseEnterLeaveEventArgs>? MouseEnterLeave;
public event Action<KeyEventArgs>? KeyUp;
public event Action<KeyEventArgs>? KeyDown;
public event Action<MouseWheelEventArgs>? MouseWheel;
public event Action<WindowClosedEventArgs>? CloseWindow;
public event Action<WindowDestroyedEventArgs>? DestroyWindow;
public event Action<TextEventArgs>? TextEntered { add { } remove { } }
public event Action<MouseMoveEventArgs>? MouseMove { add { } remove { } }
public event Action<MouseEnterLeaveEventArgs>? MouseEnterLeave { add { } remove { } }
public event Action<KeyEventArgs>? KeyUp { add { } remove { } }
public event Action<KeyEventArgs>? KeyDown { add { } remove { } }
public event Action<MouseWheelEventArgs>? MouseWheel { add { } remove { } }
public event Action<WindowClosedEventArgs>? CloseWindow { add { } remove { } }
public event Action<WindowDestroyedEventArgs>? DestroyWindow { add { } remove { } }
public Texture GetStockTexture(ClydeStockTexture stockTexture)
{
@@ -248,6 +248,11 @@ namespace Robust.Client.Graphics.Clyde
return new(default, default, 1, name);
}
public AudioStream LoadAudioRaw(short[] samples, int channels, int sampleRate)
{
throw new NotImplementedException();
}
public IClydeAudioSource CreateAudioSource(AudioStream stream)
{
return DummyAudioSource.Instance;
@@ -337,6 +342,11 @@ namespace Robust.Client.Graphics.Clyde
{
// Nada.
}
public void SetVolumeDirect(float masterVolumeDecay)
{
// Nada.
}
}
private sealed class DummyBufferedAudioSource : DummyAudioSource, IClydeBufferedAudioSource
@@ -594,7 +604,7 @@ namespace Robust.Client.Graphics.Clyde
public bool IsVisible { get; set; } = true;
public Vector2 ContentScale => Vector2.One;
public bool DisposeOnClose { get; set; }
public event Action<WindowClosedEventArgs>? Closed;
public event Action<WindowClosedEventArgs>? Closed { add { } remove { } }
public void MaximizeOnMonitor(IClydeMonitor monitor)
{

View File

@@ -71,7 +71,7 @@ namespace Robust.Client.Graphics.Clyde
var impl = (CursorImpl) cursor;
DebugTools.Assert(impl.Owner == this);
if (impl.Id == null)
if (impl.Id == default)
{
throw new ObjectDisposedException(nameof(cursor));
}

View File

@@ -8,6 +8,7 @@ namespace Robust.Client.Graphics
// AUDIO SYSTEM DOWN BELOW.
AudioStream LoadAudioOggVorbis(Stream stream, string? name = null);
AudioStream LoadAudioWav(Stream stream, string? name = null);
AudioStream LoadAudioRaw(short[] samples, int channels, int sampleRate);
void SetMasterVolume(float newVolume);

View File

@@ -21,5 +21,6 @@ namespace Robust.Client.Graphics
void SetOcclusion(float blocks);
void SetPlaybackPosition(float seconds);
void SetVelocity(Vector2 velocity);
void SetVolumeDirect(float masterVolumeDecay);
}
}

View File

@@ -4,7 +4,7 @@ using Robust.Shared.Maths;
namespace Robust.Client.Graphics
{
internal interface IRenderHandle
public interface IRenderHandle
{
DrawingHandleScreen DrawingHandleScreen { get; }
DrawingHandleWorld DrawingHandleWorld { get; }

View File

@@ -334,6 +334,7 @@ namespace Robust.Client.Input
{
// christ this crap *is* re-entrant thanks to PlacementManager and
// I honestly have no idea what the best solution here is.
// note from the future: context switches won't cause re-entrancy anymore because InputContextContainer defers context switches
DebugTools.Assert(!_currentlyFindingViewport, "Re-entrant key events??");
try
@@ -341,6 +342,8 @@ namespace Robust.Client.Input
// This is terrible but anyways.
// This flag keeps track of "did a viewport fire the key up for us" so we know we don't do it again.
_currentlyFindingViewport = true;
// And this stops context switches from causing crashes
Contexts.DeferringEnabled = true;
binding.State = state;
@@ -361,12 +364,14 @@ namespace Robust.Client.Input
finally
{
_currentlyFindingViewport = false;
Contexts.DeferringEnabled = false;
}
}
public void ViewportKeyEvent(Control? viewport, BoundKeyEventArgs eventArgs)
{
_currentlyFindingViewport = false;
Contexts.DeferringEnabled = false;
var cmd = GetInputCommand(eventArgs.Function);
// TODO: Allow input commands to still get forwarded to server if necessary.

View File

@@ -52,7 +52,7 @@ namespace Robust.Client.Physics
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<IslandSolveMessage>();
IoCManager.Resolve<IOverlayManager>().RemoveOverlay(typeof(PhysicsIslandOverlay));
}

View File

@@ -2,13 +2,14 @@ using System;
using System.Collections.Generic;
using Robust.Shared.GameStates;
using Robust.Shared.Network;
using Robust.Shared.Players;
namespace Robust.Client.Player
{
public interface IPlayerManager : Shared.Players.ISharedPlayerManager
{
new IEnumerable<IPlayerSession> Sessions { get; }
IReadOnlyDictionary<NetUserId, IPlayerSession> SessionsDict { get; }
new IEnumerable<ICommonSession> Sessions { get; }
IReadOnlyDictionary<NetUserId, ICommonSession> SessionsDict { get; }
LocalPlayer? LocalPlayer { get; }

View File

@@ -1,11 +0,0 @@
using System;
using Robust.Shared.Players;
namespace Robust.Client.Player
{
/// <summary>
/// Client side session of a player.
/// </summary>
[Obsolete("Use the base " + nameof(ICommonSession))]
public interface IPlayerSession : ICommonSession { }
}

View File

@@ -4,6 +4,7 @@ using Robust.Shared.Configuration;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.Network;
using Robust.Shared.Players;
using Robust.Shared.ViewVariables;
namespace Robust.Client.Player
@@ -36,7 +37,7 @@ namespace Robust.Client.Player
/// Session of the local client.
/// </summary>
[ViewVariables]
public IPlayerSession Session => InternalSession;
public ICommonSession Session => InternalSession;
internal PlayerSession InternalSession { get; set; } = default!;

View File

@@ -28,7 +28,7 @@ namespace Robust.Client.Player
/// <summary>
/// Active sessions of connected clients to the server.
/// </summary>
private readonly Dictionary<NetUserId, IPlayerSession> _sessions = new();
private readonly Dictionary<NetUserId, ICommonSession> _sessions = new();
/// <inheritdoc />
public IEnumerable<ICommonSession> NetworkedSessions
@@ -69,10 +69,10 @@ namespace Robust.Client.Player
/// <inheritdoc />
[ViewVariables]
IEnumerable<IPlayerSession> IPlayerManager.Sessions => _sessions.Values;
IEnumerable<ICommonSession> IPlayerManager.Sessions => _sessions.Values;
/// <inheritdoc />
public IReadOnlyDictionary<NetUserId, IPlayerSession> SessionsDict => _sessions;
public IReadOnlyDictionary<NetUserId, ICommonSession> SessionsDict => _sessions;
/// <inheritdoc />
public event EventHandler? PlayerListUpdated;

View File

@@ -5,7 +5,7 @@ using Robust.Shared.Players;
namespace Robust.Client.Player
{
internal sealed class PlayerSession : IPlayerSession
internal sealed class PlayerSession : ICommonSession
{
internal SessionStatus Status { get; set; } = SessionStatus.Connecting;

View File

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

View File

@@ -41,7 +41,7 @@ namespace Robust.Client.UserInterface.Controls
return (32, 32) * Scale;
}
internal override void DrawInternal(IRenderHandle renderHandle)
public override void DrawInternal(IRenderHandle renderHandle)
{
if (Sprite == null || Sprite.Deleted)
{

View File

@@ -20,7 +20,7 @@ namespace Robust.Client.UserInterface.Controls
public bool HideRoot { get; set; }
public Item? Root => _root;
public Item? TreeRoot => _root;
public Item? Selected => _selectedIndex == null ? null : _itemList[_selectedIndex.Value];

View File

@@ -288,7 +288,7 @@ namespace Robust.Client.UserInterface.CustomControls
}
catch (Exception e)
{
sawmill.Warning("Failed to load debug console history due to exception!\n{e}");
sawmill.Warning($"Failed to load debug console history due to exception!\n{e}");
return null;
}
finally

View File

@@ -96,7 +96,7 @@ namespace Robust.Client.UserInterface.CustomControls
var (spaceX, spaceY) = Parent!.Size;
if (Position.Y > spaceY)
{
LayoutContainer.SetPosition(this, (Position.X, spaceY - HEADER_SIZE_Y));
LayoutContainer.SetPosition(this, (Position.X, spaceY + HEADER_SIZE_Y));
}
if (Position.X > spaceX)
@@ -104,6 +104,16 @@ namespace Robust.Client.UserInterface.CustomControls
// 50 is arbitrary here. As long as it's bumped back into view.
LayoutContainer.SetPosition(this, (spaceX - 50, Position.Y));
}
if (Position.Y < 0)
{
LayoutContainer.SetPosition(this, (Position.X, 0));
}
if (Position.X < 0)
{
LayoutContainer.SetPosition(this, (0, Position.Y));
}
}
protected override DragMode GetDragModeFor(Vector2 relativeMousePos)

View File

@@ -25,8 +25,6 @@ namespace Robust.Client.UserInterface
{
[Dependency] private readonly IInputManager _inputManager = default!;
[Dependency] private readonly IClydeInternal _clyde = default!;
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
[Dependency] private readonly IResourceManager _resourceManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IEyeManager _eyeManager = default!;

View File

@@ -306,7 +306,6 @@ namespace Robust.Server
// Call Init in game assemblies.
_modLoader.BroadcastRunLevel(ModRunLevel.Init);
_entityManager.Initialize();
IoCManager.Resolve<IEntityLookup>().Initialize();
IoCManager.Resolve<ISerializationManager>().Initialize();
@@ -319,6 +318,7 @@ namespace Robust.Server
IoCManager.Resolve<IServerConsoleHost>().Initialize();
_entityManager.Startup();
IoCManager.Resolve<IEntityLookup>().Startup();
_stateManager.Initialize();
_scriptHost.Initialize();

View File

@@ -57,9 +57,8 @@ namespace Robust.Server.Console.Commands
else
{
var mapEnt = mapMgr.GetMapEntity(mapId);
transform.AttachParent(mapEnt);
transform.WorldPosition = position;
transform.AttachParent(mapEnt);
}
shell.WriteLine($"Teleported {player} to {mapId}:{posX},{posY}.");

View File

@@ -5,21 +5,21 @@ using Robust.Shared.ViewVariables;
namespace Robust.Server.GameObjects
{
public class BasicActorComponent : Component, IActorComponent
public class ActorComponent : Component
{
public override string Name => "BasicActor";
public override string Name => "Actor";
[ViewVariables] public IPlayerSession playerSession { get; internal set; } = default!;
[ViewVariables] public IPlayerSession PlayerSession { get; internal set; } = default!;
/// <inheritdoc />
protected override void Shutdown()
{
base.Shutdown();
// Warning: careful here, Detach removes this component, make sure this is after the base shutdown
// to prevent infinite recursion
// ReSharper disable once ConstantConditionalAccessQualifier
playerSession?.DetachFromEntity();
PlayerSession?.DetachFromEntity();
}
}
@@ -27,6 +27,7 @@ namespace Robust.Server.GameObjects
/// Raised on an entity whenever a player attaches to this entity.
/// </summary>
[Serializable]
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public class PlayerAttachedMsg : ComponentMessage
{
public IPlayerSession NewPlayer { get; }
@@ -41,6 +42,7 @@ namespace Robust.Server.GameObjects
/// Raised on an entity whenever a player detaches from this entity.
/// </summary>
[Serializable]
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public class PlayerDetachedMsg : ComponentMessage
{
public IPlayerSession OldPlayer { get; }

View File

@@ -1,10 +0,0 @@
using Robust.Server.Player;
using Robust.Shared.GameObjects;
namespace Robust.Server.GameObjects
{
public interface IActorComponent : IComponent
{
IPlayerSession playerSession { get; }
}
}

View File

@@ -7,6 +7,7 @@ using Robust.Shared.Players;
namespace Robust.Server.GameObjects
{
[ComponentReference(typeof(SharedAppearanceComponent))]
public sealed class AppearanceComponent : SharedAppearanceComponent
{
[ViewVariables]

View File

@@ -8,6 +8,7 @@ using Robust.Shared.ViewVariables;
namespace Robust.Server.GameObjects
{
[ComponentReference(typeof(SharedEyeComponent))]
public class EyeComponent : SharedEyeComponent
{
[DataField("drawFov")]

View File

@@ -14,6 +14,8 @@ using Robust.Shared.ViewVariables;
namespace Robust.Server.GameObjects
{
[ComponentReference(typeof(SharedSpriteComponent))]
[ComponentReference(typeof(ISpriteRenderableComponent))]
public class SpriteComponent : SharedSpriteComponent, ISpriteRenderableComponent, ISerializationHooks
{
const string LayerSerializationCache = "spritelayersrv";

View File

@@ -7,8 +7,6 @@ using Robust.Server.Player;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.Network;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
@@ -20,6 +18,7 @@ namespace Robust.Server.GameObjects
/// </summary>
/// <seealso cref="BoundUserInterface"/>
[PublicAPI]
[ComponentReference(typeof(SharedUserInterfaceComponent))]
public sealed class ServerUserInterfaceComponent : SharedUserInterfaceComponent, ISerializationHooks
{
private readonly Dictionary<object, BoundUserInterface> _interfaces =
@@ -48,7 +47,8 @@ namespace Robust.Server.GameObjects
return _interfaces[uiKey];
}
public bool TryGetBoundUserInterface(object uiKey, [NotNullWhen(true)] out BoundUserInterface? boundUserInterface)
public bool TryGetBoundUserInterface(object uiKey,
[NotNullWhen(true)] out BoundUserInterface? boundUserInterface)
{
return _interfaces.TryGetValue(uiKey, out boundUserInterface);
}
@@ -67,32 +67,20 @@ namespace Robust.Server.GameObjects
internal void SendToSession(IPlayerSession session, BoundUserInterfaceMessage message, object uiKey)
{
SendNetworkMessage(new BoundInterfaceMessageWrapMessage(message, uiKey), session.ConnectedClient);
EntitySystem.Get<UserInterfaceSystem>()
.SendTo(session, new BoundUIWrapMessage(Owner.Uid, message, uiKey));
}
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel,
ICommonSession? session = null)
internal void ReceiveMessage(IPlayerSession session, BoundUIWrapMessage msg)
{
base.HandleNetworkMessage(message, netChannel, session);
switch (message)
if (!_interfaces.TryGetValue(msg.UiKey, out var @interface))
{
case BoundInterfaceMessageWrapMessage wrapped:
if (session == null)
{
throw new ArgumentNullException(nameof(session));
}
if (!_interfaces.TryGetValue(wrapped.UiKey, out var @interface))
{
Logger.DebugS("go.comp.ui", "Got BoundInterfaceMessageWrapMessage for unknown UI key: {0}",
wrapped.UiKey);
return;
}
@interface.ReceiveMessage(wrapped.Message, (IPlayerSession)session);
break;
Logger.DebugS("go.comp.ui", "Got BoundInterfaceMessageWrapMessage for unknown UI key: {0}",
msg.UiKey);
return;
}
@interface.ReceiveMessage(msg.Message, session);
}
}
@@ -153,6 +141,7 @@ namespace Robust.Server.GameObjects
{
_playerStateOverrides[session] = state;
}
_stateDirty = true;
}
@@ -178,7 +167,6 @@ namespace Robust.Server.GameObjects
}
/// <summary>
/// Opens this interface for a specific client.
/// </summary>

View File

@@ -30,6 +30,8 @@ namespace Robust.Server.GameObjects
/// <inheritdoc />
public override void Shutdown()
{
base.Shutdown();
_playerManager.PlayerStatusChanged -= OnPlayerStatusChanged;
}

View File

@@ -219,9 +219,7 @@ namespace Robust.Server.GameObjects
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<MoveEvent>();
UnsubscribeLocalEvent<EntityInitializedMessage>();
UnsubscribeLocalEvent<EntityDeletedMessage>();
_mapManager.OnGridCreated -= HandleGridCreated;
_mapManager.OnGridRemoved -= HandleGridRemoval;
_mapManager.TileChanged -= HandleTileChanged;
@@ -320,7 +318,12 @@ namespace Robust.Server.GameObjects
/// <param name="moveEvent"></param>
private void HandleEntityMove(MoveEvent moveEvent)
{
if (moveEvent.Sender.Deleted || moveEvent.NewPosition.GetGridId(EntityManager) == GridId.Invalid || !moveEvent.NewPosition.IsValid(EntityManager))
// TODO: When Acruid does TileEntities we may actually be able to delete this system if tile lookups become fast enough
var gridId = moveEvent.NewPosition.GetGridId(EntityManager);
if (moveEvent.Sender.Deleted ||
gridId == GridId.Invalid ||
!moveEvent.NewPosition.IsValid(EntityManager))
{
HandleEntityRemove(moveEvent.Sender);
return;
@@ -332,7 +335,7 @@ namespace Robust.Server.GameObjects
}
// Memory leak protection
var gridBounds = _mapManager.GetGrid(moveEvent.Sender.Transform.GridID).WorldBounds;
var gridBounds = _mapManager.GetGrid(gridId).WorldBounds;
if (!gridBounds.Contains(moveEvent.Sender.Transform.WorldPosition))
{
HandleEntityRemove(moveEvent.Sender);

View File

@@ -22,6 +22,31 @@ namespace Robust.Server.GameObjects
/// <inheritdoc />
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<BoundUIWrapMessage>(OnMessageReceived);
SubscribeLocalEvent<ServerUserInterfaceComponent, ComponentShutdown>(OnUserInterfaceShutdown);
}
private void OnUserInterfaceShutdown(EntityUid uid, ServerUserInterfaceComponent component, ComponentShutdown args)
{
foreach (var bui in component.Interfaces)
{
DeactivateInterface(bui);
}
}
internal void SendTo(IPlayerSession session, BoundUIWrapMessage msg)
{
RaiseNetworkEvent(msg, session.ConnectedClient);
}
private void OnMessageReceived(BoundUIWrapMessage msg, EntitySessionEventArgs args)
{
if (!ComponentManager.TryGetComponent<ServerUserInterfaceComponent>(msg.Entity, out var uiComp))
return;
uiComp.ReceiveMessage((IPlayerSession) args.SenderSession, msg);
}
/// <inheritdoc />

View File

@@ -1,68 +1,37 @@
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics;
namespace Robust.Server.GameObjects
{
public class ServerComponentFactory : ComponentFactory
{
public ServerComponentFactory()
{
// Required for the engine to work
Register<MetaDataComponent>();
RegisterReference<MetaDataComponent, IMetaDataComponent>();
// Required for the engine to work
Register<TransformComponent>();
RegisterReference<TransformComponent, ITransformComponent>();
Register<MapComponent>();
RegisterReference<MapComponent, IMapComponent>();
Register<MapGridComponent>();
RegisterReference<MapGridComponent, IMapGridComponent>();
Register<EyeComponent>();
RegisterReference<EyeComponent, SharedEyeComponent>();
Register<BasicActorComponent>();
RegisterReference<BasicActorComponent, IActorComponent>();
Register<PhysicsComponent>();
RegisterReference<PhysicsComponent, IPhysBody>();
Register<CollisionWakeComponent>();
Register<ContainerManagerComponent>();
RegisterReference<ContainerManagerComponent, IContainerManager>();
Register<OccluderComponent>();
RegisterIgnore("Input");
Register<SpriteComponent>();
RegisterReference<SpriteComponent, SharedSpriteComponent>();
RegisterReference<SpriteComponent, ISpriteRenderableComponent>();
Register<AppearanceComponent>();
RegisterReference<AppearanceComponent, SharedAppearanceComponent>();
Register<SnapGridComponent>();
Register<ServerUserInterfaceComponent>();
RegisterReference<ServerUserInterfaceComponent, SharedUserInterfaceComponent>();
Register<TimerComponent>();
RegisterIgnore("AnimationPlayer");
#if DEBUG
Register<DebugExceptionOnAddComponent>();
Register<DebugExceptionInitializeComponent>();
Register<DebugExceptionStartupComponent>();
#endif
RegisterClass<MetaDataComponent>();
RegisterClass<TransformComponent>();
RegisterClass<MapComponent>();
RegisterClass<MapGridComponent>();
RegisterClass<EyeComponent>();
RegisterClass<ActorComponent>();
RegisterClass<PhysicsComponent>();
RegisterClass<CollisionWakeComponent>();
RegisterClass<ContainerManagerComponent>();
RegisterClass<OccluderComponent>();
RegisterClass<SpriteComponent>();
RegisterClass<AppearanceComponent>();
RegisterClass<SnapGridComponent>();
RegisterClass<ServerUserInterfaceComponent>();
RegisterClass<TimerComponent>();
RegisterClass<MapSaveIdComponent>();
Register<MapSaveIdComponent>();
#if DEBUG
RegisterClass<DebugExceptionOnAddComponent>();
RegisterClass<DebugExceptionInitializeComponent>();
RegisterClass<DebugExceptionStartupComponent>();
#endif
}
}
}

View File

@@ -137,6 +137,7 @@ namespace Robust.Server.GameObjects
}
/// <inheritdoc />
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public void SendComponentNetworkMessage(INetChannel? channel, IEntity entity, IComponent component,
ComponentMessage message)
{

View File

@@ -132,11 +132,11 @@ namespace Robust.Server.GameStates
if (session.Status != SessionStatus.InGame || session.AttachedEntityUid is null)
return viewers;
var query = _compMan.EntityQuery<BasicActorComponent>();
var query = _compMan.EntityQuery<ActorComponent>();
foreach (var actorComp in query)
{
if (actorComp.playerSession == session)
if (actorComp.PlayerSession == session)
viewers.Add(actorComp.Owner.Uid);
}

View File

@@ -212,7 +212,7 @@ namespace Robust.Server.Placement
foreach (IEntity entity in IoCManager.Resolve<IEntityLookup>().GetEntitiesIntersecting(start.GetMapId(_entityManager),
new Box2(start.Position, start.Position + rectSize)))
{
if (entity.Deleted || entity.HasComponent<IMapGridComponent>() || entity.HasComponent<IActorComponent>())
if (entity.Deleted || entity.HasComponent<IMapGridComponent>() || entity.HasComponent<ActorComponent>())
continue;
entity.Delete();
}
@@ -223,10 +223,10 @@ namespace Robust.Server.Placement
/// </summary>
public void SendPlacementBegin(IEntity mob, int range, string objectType, string alignOption)
{
if (!mob.TryGetComponent<IActorComponent>(out var actor))
if (!mob.TryGetComponent<ActorComponent>(out var actor))
return;
var playerConnection = actor.playerSession.ConnectedClient;
var playerConnection = actor.PlayerSession.ConnectedClient;
if (playerConnection == null)
return;
@@ -244,10 +244,10 @@ namespace Robust.Server.Placement
/// </summary>
public void SendPlacementBeginTile(IEntity mob, int range, string tileType, string alignOption)
{
if (!mob.TryGetComponent<IActorComponent>(out var actor))
if (!mob.TryGetComponent<ActorComponent>(out var actor))
return;
var playerConnection = actor.playerSession.ConnectedClient;
var playerConnection = actor.PlayerSession.ConnectedClient;
if (playerConnection == null)
return;
@@ -265,10 +265,10 @@ namespace Robust.Server.Placement
/// </summary>
public void SendPlacementCancel(IEntity mob)
{
if (!mob.TryGetComponent<IActorComponent>(out var actor))
if (!mob.TryGetComponent<ActorComponent>(out var actor))
return;
var playerConnection = actor.playerSession.ConnectedClient;
var playerConnection = actor.PlayerSession.ConnectedClient;
if (playerConnection == null)
return;

View File

@@ -10,10 +10,10 @@ namespace Robust.Server.Player
if (entity == null)
return null;
if (!entity.TryGetComponent(out IActorComponent? actorComponent))
if (!entity.TryGetComponent(out ActorComponent? actorComponent))
return null;
return actorComponent.playerSession;
return actorComponent.PlayerSession;
}
}
}

View File

@@ -118,8 +118,8 @@ namespace Robust.Server.Player
return;
}
var actorComponent = a.AddComponent<BasicActorComponent>();
actorComponent.playerSession = this;
var actorComponent = a.AddComponent<ActorComponent>();
actorComponent.PlayerSession = this;
AttachedEntity = a;
a.SendMessage(actorComponent, new PlayerAttachedMsg(this));
a.EntityManager.EventBus.RaiseEvent(EventSource.Local, new PlayerAttachSystemMessage(a, this));
@@ -137,11 +137,11 @@ namespace Robust.Server.Player
throw new InvalidOperationException("Tried to detach player, but my entity does not exist!");
}
if (AttachedEntity.TryGetComponent<BasicActorComponent>(out var actor))
if (AttachedEntity.TryGetComponent<ActorComponent>(out var actor))
{
AttachedEntity.SendMessage(actor, new PlayerDetachedMsg(this));
AttachedEntity.EntityManager.EventBus.RaiseEvent(EventSource.Local, new PlayerDetachedSystemMessage(AttachedEntity));
AttachedEntity.RemoveComponent<BasicActorComponent>();
AttachedEntity.RemoveComponent<ActorComponent>();
AttachedEntity = null;
UpdatePlayerState();
}

View File

@@ -46,7 +46,7 @@ namespace Robust.Server
IoCManager.Register<IMapManagerInternal, ServerMapManager>();
IoCManager.Register<IServerMapManager, ServerMapManager>();
IoCManager.Register<IEntityManager, ServerEntityManager>();
IoCManager.Register<IEntityLookup, SharedEntityLookup>();
IoCManager.Register<IEntityLookup, EntityLookup>();
IoCManager.Register<IEntityNetworkManager, ServerEntityManager>();
IoCManager.Register<IServerEntityNetworkManager, ServerEntityManager>();
IoCManager.Register<IMapLoader, MapLoader>();

View File

@@ -1,3 +1,4 @@
using System;
using Robust.Shared.GameObjects;
namespace Robust.Shared.Containers
@@ -5,6 +6,7 @@ namespace Robust.Shared.Containers
/// <summary>
/// The contents of this container have been changed.
/// </summary>
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public class ContainerContentsModifiedMessage : ComponentMessage
{
/// <summary>
@@ -35,4 +37,4 @@ namespace Robust.Shared.Containers
Removed = removed;
}
}
}
}

View File

@@ -16,8 +16,7 @@ namespace Robust.Shared.Containers
/// <summary>
/// Holds data about a set of entity containers on this entity.
/// </summary>
// [RegisterComponent]
// [ComponentReference(typeof(IContainerManager))]
[ComponentReference(typeof(IContainerManager))]
public class ContainerManagerComponent : Component, IContainerManager
{
[Dependency] private readonly IRobustSerializer _serializer = default!;

View File

@@ -210,9 +210,11 @@ namespace Robust.Shared.GameObjects
}
/// <inheritdoc />
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public virtual void HandleMessage(ComponentMessage message, IComponent? component) { }
/// <inheritdoc />
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public virtual void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null) { }
/// <param name="player"></param>

View File

@@ -7,6 +7,7 @@ namespace Robust.Shared.GameObjects
/// A message containing info to send through the component message system.
/// </summary>
[Serializable, NetSerializable]
[Obsolete("Component messages are deprecated. Use directed local events instead.")]
public abstract class ComponentMessage
{
/// <summary>

View File

@@ -1,7 +1,9 @@
using JetBrains.Annotations;
using System;
using JetBrains.Annotations;
namespace Robust.Shared.GameObjects
{
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public class RelayMovementEntityMessage : ComponentMessage
{
[PublicAPI]
@@ -16,6 +18,7 @@ namespace Robust.Shared.GameObjects
/// <summary>
/// The entity transform parent has been changed.
/// </summary>
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public class ParentChangedMessage : ComponentMessage
{
/// <summary>

View File

@@ -98,7 +98,6 @@ namespace Robust.Shared.GameObjects
if (_bodyType == value)
return;
var oldAnchored = _bodyType == BodyType.Static;
var oldType = _bodyType;
_bodyType = value;
@@ -121,14 +120,7 @@ namespace Robust.Shared.GameObjects
RegenerateContacts();
var anchored = value == BodyType.Static;
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new PhysicsBodyTypeChangedEvent(_bodyType, oldType), false);
if (oldAnchored != anchored)
{
SendMessage(new AnchoredChangedMessage(Anchored));
}
}
}
@@ -900,35 +892,6 @@ namespace Robust.Shared.GameObjects
}
}
/// <summary>
/// Whether or not the entity is anchored in place.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[Obsolete("Use BodyType.Static instead")]
public bool Anchored
{
get => BodyType == BodyType.Static;
set
{
var anchored = BodyType == BodyType.Static;
if (anchored == value)
return;
if (value)
{
_bodyType = BodyType.Static;
}
else
{
_bodyType = BodyType.Dynamic;
}
SendMessage(new AnchoredChangedMessage(Anchored));
Dirty();
}
}
[ViewVariables(VVAccess.ReadWrite)]
public bool Predict
{
@@ -1331,6 +1294,7 @@ namespace Robust.Shared.GameObjects
if (preventCollideMessage.Cancelled) return false;
#pragma warning disable 618
foreach (var comp in Owner.GetAllComponents<ICollideSpecial>())
{
if (comp.PreventCollide(other)) return false;
@@ -1340,21 +1304,12 @@ namespace Robust.Shared.GameObjects
{
if (comp.PreventCollide(this)) return false;
}
#pragma warning restore 618
return true;
}
}
public class AnchoredChangedMessage : ComponentMessage
{
public readonly bool Anchored;
public AnchoredChangedMessage(bool anchored)
{
Anchored = anchored;
}
}
/// <summary>
/// Directed event raised when an entity's physics BodyType changes.
/// </summary>
@@ -1370,11 +1325,6 @@ namespace Robust.Shared.GameObjects
/// </summary>
public BodyType Old { get; }
/// <summary>
/// Whether the body is "anchored".
/// </summary>
public bool Anchored => New == BodyType.Static;
public PhysicsBodyTypeChangedEvent(BodyType newType, BodyType oldType)
{
New = newType;

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
using Robust.Shared.Animations;
using Robust.Shared.Map;
@@ -93,9 +94,6 @@ namespace Robust.Shared.GameObjects
/// </summary>
bool IsMapTransform { get; }
/// <summary>
///
/// </summary>
Vector2? LerpDestination { get; }
/// <summary>

View File

@@ -1,6 +1,5 @@
using System;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
@@ -18,6 +17,7 @@ namespace Robust.Shared.GameObjects
}
/// <inheritdoc cref="IMapComponent"/>
[ComponentReference(typeof(IMapComponent))]
public class MapComponent : Component, IMapComponent
{
[ViewVariables(VVAccess.ReadOnly)]

View File

@@ -21,6 +21,7 @@ namespace Robust.Shared.GameObjects
}
/// <inheritdoc cref="IMapGridComponent"/>
[ComponentReference(typeof(IMapGridComponent))]
internal class MapGridComponent : Component, IMapGridComponent
{
[Dependency] private readonly IMapManager _mapManager = default!;
@@ -51,6 +52,17 @@ namespace Robust.Shared.GameObjects
_gridIndex = GridId.Invalid;
}
public override void Initialize()
{
base.Initialize();
var mapId = Owner.Transform.MapID;
if (_mapManager.HasMapEntity(mapId))
{
Owner.Transform.AttachParent(_mapManager.GetMapEntity(mapId));
}
}
/// <param name="player"></param>
/// <inheritdoc />
public override ComponentState GetComponentState(ICommonSession player)

View File

@@ -65,6 +65,7 @@ namespace Robust.Shared.GameObjects
}
/// <inheritdoc cref="IMetaDataComponent"/>
[ComponentReference(typeof(IMetaDataComponent))]
internal class MetaDataComponent : Component, IMetaDataComponent
{
[Dependency] private readonly IPrototypeManager _prototypes = default!;

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Robust.Shared.Animations;
using Robust.Shared.Containers;
@@ -14,6 +15,7 @@ using Robust.Shared.ViewVariables;
namespace Robust.Shared.GameObjects
{
[ComponentReference(typeof(ITransformComponent))]
internal class TransformComponent : Component, ITransformComponent, IComponentDebug
{
[DataField("parent")]
@@ -65,25 +67,21 @@ namespace Robust.Shared.GameObjects
[ViewVariables]
public GridId GridID
{
get
get => _gridId;
private set
{
// root node, grid id is undefined
if (Owner.HasComponent<IMapComponent>())
return GridId.Invalid;
// second level node, terminates recursion up the branch of the tree
if (Owner.TryGetComponent(out IMapGridComponent? gridComp))
return gridComp.GridIndex;
// branch or leaf node
if (_parent.IsValid())
return Parent!.GridID;
// Not on a grid
return GridId.Invalid;
if (_gridId.Equals(value)) return;
_gridId = value;
foreach (var transformComponent in Children)
{
var child = (TransformComponent) transformComponent;
child.GridID = value;
}
}
}
private GridId _gridId = GridId.Invalid;
/// <inheritdoc />
[ViewVariables(VVAccess.ReadWrite)]
public bool NoLocalRotation
@@ -263,6 +261,7 @@ namespace Robust.Shared.GameObjects
set
{
var oldPosition = Coordinates;
_localPosition = value.Position;
if (value.EntityId != _parent)
{
@@ -270,7 +269,6 @@ namespace Robust.Shared.GameObjects
AttachParent(newEntity);
}
_localPosition = value.Position;
Dirty();
if (!DeferUpdates)
@@ -424,6 +422,28 @@ namespace Robust.Shared.GameObjects
// so duplicate additions (which will happen) don't matter.
((TransformComponent) Parent!)._children.Add(Owner.Uid);
}
GridID = GetGridIndex();
}
private GridId GetGridIndex()
{
if (Owner.HasComponent<IMapComponent>())
{
return GridId.Invalid;
}
if (Owner.TryGetComponent(out IMapGridComponent? gridComponent))
{
return gridComponent.GridIndex;
}
if (_parent.IsValid())
{
return Parent!.GridID;
}
return _mapManager.TryFindGridAt(MapID, WorldPosition, out var mapgrid) ? mapgrid.Index : GridId.Invalid;
}
/// <inheritdoc />
@@ -571,14 +591,14 @@ namespace Robust.Shared.GameObjects
// offset position from world to parent
SetPosition(newParent.InvWorldMatrix.Transform(WorldPosition));
_parent = newParentEnt.Uid;
ChangeMapId(newConcrete.MapID);
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, entMessage);
Owner.SendMessage(this, compMessage);
RebuildMatrices();
Dirty();
GridID = GetGridIndex();
}
internal void ChangeMapId(MapId newMapId)

View File

@@ -35,25 +35,6 @@ namespace Robust.Shared.GameObjects
UiKey = _uiKeyRaw;
}
}
[NetSerializable, Serializable]
protected sealed class BoundInterfaceMessageWrapMessage : ComponentMessage
{
public readonly BoundUserInterfaceMessage Message;
public readonly object UiKey;
public BoundInterfaceMessageWrapMessage(BoundUserInterfaceMessage message, object uiKey)
{
Directed = true;
Message = message;
UiKey = uiKey;
}
public override string ToString()
{
return $"{nameof(BoundInterfaceMessageWrapMessage)}: {Message}";
}
}
}
[NetSerializable, Serializable]
@@ -87,4 +68,24 @@ namespace Robust.Shared.GameObjects
internal sealed class CloseBoundInterfaceMessage : BoundUserInterfaceMessage
{
}
[Serializable, NetSerializable]
internal sealed class BoundUIWrapMessage : EntityEventArgs
{
public readonly EntityUid Entity;
public readonly BoundUserInterfaceMessage Message;
public readonly object UiKey;
public BoundUIWrapMessage(EntityUid entity, BoundUserInterfaceMessage message, object uiKey)
{
Message = message;
UiKey = uiKey;
Entity = entity;
}
public override string ToString()
{
return $"{nameof(BoundUIWrapMessage)}: {Message}";
}
}
}

View File

@@ -286,6 +286,12 @@ namespace Robust.Shared.GameObjects
return TryGetComponent(type, out var component) ? component : null;
}
/// <inheritdoc />
public void QueueDelete()
{
EntityManager.QueueDeleteEntity(this);
}
/// <inheritdoc />
public void Delete()
{

View File

@@ -44,6 +44,8 @@ namespace Robust.Shared.GameObjects
/// <inheritdoc />
public virtual IEntityNetworkManager? EntityNetManager => null;
protected readonly HashSet<EntityUid> QueuedDeletions = new();
/// <summary>
/// All entities currently stored in the manager.
/// </summary>
@@ -112,6 +114,16 @@ namespace Robust.Shared.GameObjects
_eventBus.ProcessEventQueue();
}
using (histogram?.WithLabels("QueuedDeletion").NewTimer())
{
foreach (var uid in QueuedDeletions)
{
DeleteEntity(uid);
}
QueuedDeletions.Clear();
}
using (histogram?.WithLabels("ComponentCull").NewTimer())
{
_componentManager.CullRemovedComponents();
@@ -212,6 +224,7 @@ namespace Robust.Shared.GameObjects
return false;
}
[Obsolete("IEntityQuery is obsolete")]
public IEnumerable<IEntity> GetEntities(IEntityQuery query)
{
return query.Match(this);
@@ -287,6 +300,16 @@ namespace Robust.Shared.GameObjects
EventBus.RaiseEvent(EventSource.Local, new EntityDeletedMessage(entity));
}
public void QueueDeleteEntity(IEntity entity)
{
QueueDeleteEntity(entity.Uid);
}
public void QueueDeleteEntity(EntityUid uid)
{
QueuedDeletions.Add(uid);
}
public void DeleteEntity(EntityUid uid)
{
if (TryGetEntity(uid, out var entity))
@@ -359,7 +382,7 @@ namespace Robust.Shared.GameObjects
// we want this called before adding components
EntityAdded?.Invoke(this, entity.Uid);
// We do this after the event, so if the event throws we have not committed
// We do this after the event, so if the event throws we have not committed
Entities[entity.Uid] = entity;
AllEntities.Add(entity);
@@ -457,6 +480,7 @@ namespace Robust.Shared.GameObjects
var session = netMsg.Session;
compMsg.Remote = true;
#pragma warning disable 618
var uid = netMsg.EntityUid;
if (compMsg.Directed)
{
@@ -470,6 +494,7 @@ namespace Robust.Shared.GameObjects
component.HandleNetworkMessage(compMsg, compChannel, session);
}
}
#pragma warning restore 618
}
/// <summary>

View File

@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
namespace Robust.Shared.GameObjects
{
public abstract partial class EntitySystem
{
private List<SubBase>? _subscriptions;
protected void SubscribeNetworkEvent<T>(EntityEventHandler<T> handler)
where T : notnull
{
EntityManager.EventBus.SubscribeEvent(EventSource.Network, this, handler);
_subscriptions ??= new();
_subscriptions.Add(new SubBroadcast<T>(EventSource.Network));
}
protected void SubscribeNetworkEvent<T>(EntitySessionEventHandler<T> handler)
where T : notnull
{
EntityManager.EventBus.SubscribeSessionEvent(EventSource.Network, this, handler);
_subscriptions ??= new();
_subscriptions.Add(new SubBroadcast<EntitySessionMessage<T>>(EventSource.Network));
}
protected void SubscribeLocalEvent<T>(EntityEventHandler<T> handler)
where T : notnull
{
EntityManager.EventBus.SubscribeEvent(EventSource.Local, this, handler);
_subscriptions ??= new();
_subscriptions.Add(new SubBroadcast<T>(EventSource.Local));
}
protected void SubscribeLocalEvent<T>(EntitySessionEventHandler<T> handler)
where T : notnull
{
EntityManager.EventBus.SubscribeSessionEvent(EventSource.Local, this, handler);
_subscriptions ??= new();
_subscriptions.Add(new SubBroadcast<EntitySessionMessage<T>>(EventSource.Local));
}
[Obsolete("Unsubscribing of entity system events is now automatic")]
protected void UnsubscribeNetworkEvent<T>()
where T : notnull
{
EntityManager.EventBus.UnsubscribeEvent<T>(EventSource.Network, this);
}
[Obsolete("Unsubscribing of entity system events is now automatic")]
protected void UnsubscribeLocalEvent<T>()
where T : notnull
{
EntityManager.EventBus.UnsubscribeEvent<T>(EventSource.Local, this);
}
protected void SubscribeLocalEvent<TComp, TEvent>(ComponentEventHandler<TComp, TEvent> handler)
where TComp : IComponent
where TEvent : EntityEventArgs
{
EntityManager.EventBus.SubscribeLocalEvent(handler);
_subscriptions ??= new();
_subscriptions.Add(new SubLocal<TComp, TEvent>());
}
[Obsolete("Unsubscribing of entity system events is now automatic")]
protected void UnsubscribeLocalEvent<TComp, TEvent>(ComponentEventHandler<TComp, TEvent> handler)
where TComp : IComponent
where TEvent : EntityEventArgs
{
EntityManager.EventBus.UnsubscribeLocalEvent<TComp, TEvent>();
}
[Obsolete("Unsubscribing of entity system events is now automatic")]
protected void UnsubscribeLocalEvent<TComp, TEvent>()
where TComp : IComponent
where TEvent : EntityEventArgs
{
EntityManager.EventBus.UnsubscribeLocalEvent<TComp, TEvent>();
}
private void ShutdownSubscriptions()
{
if (_subscriptions == null)
return;
foreach (var sub in _subscriptions)
{
sub.Unsubscribe(this, EntityManager.EventBus);
}
_subscriptions = null;
}
private abstract class SubBase
{
public abstract void Unsubscribe(EntitySystem sys, IEventBus bus);
}
private sealed class SubBroadcast<T> : SubBase where T : notnull
{
private readonly EventSource _source;
public SubBroadcast(EventSource source)
{
_source = source;
}
public override void Unsubscribe(EntitySystem sys, IEventBus bus)
{
bus.UnsubscribeEvent<T>(_source, sys);
}
}
private sealed class SubLocal<TComp, TBase> : SubBase where TComp : IComponent where TBase : EntityEventArgs
{
public override void Unsubscribe(EntitySystem sys, IEventBus bus)
{
bus.UnsubscribeLocalEvent<TComp, TBase>();
}
}
}
}

View File

@@ -18,7 +18,7 @@ namespace Robust.Shared.GameObjects
/// This class is instantiated by the <c>EntitySystemManager</c>, and any IoC Dependencies will be resolved.
/// </remarks>
[Reflect(false), PublicAPI]
public abstract class EntitySystem : IEntitySystem
public abstract partial class EntitySystem : IEntitySystem
{
[Dependency] protected readonly IEntityManager EntityManager = default!;
[Dependency] protected readonly IComponentManager ComponentManager = default!;
@@ -40,47 +40,14 @@ namespace Robust.Shared.GameObjects
public virtual void FrameUpdate(float frameTime) { }
/// <inheritdoc />
public virtual void Shutdown() { }
public virtual void Shutdown()
{
ShutdownSubscriptions();
}
#region Event Proxy
protected void SubscribeNetworkEvent<T>(EntityEventHandler<T> handler)
where T : notnull
{
EntityManager.EventBus.SubscribeEvent(EventSource.Network, this, handler);
}
protected void SubscribeNetworkEvent<T>(EntitySessionEventHandler<T> handler)
where T : notnull
{
EntityManager.EventBus.SubscribeSessionEvent(EventSource.Network, this, handler);
}
protected void SubscribeLocalEvent<T>(EntityEventHandler<T> handler)
where T : notnull
{
EntityManager.EventBus.SubscribeEvent(EventSource.Local, this, handler);
}
protected void SubscribeLocalEvent<T>(EntitySessionEventHandler<T> handler)
where T : notnull
{
EntityManager.EventBus.SubscribeSessionEvent(EventSource.Local, this, handler);
}
protected void UnsubscribeNetworkEvent<T>()
where T : notnull
{
EntityManager.EventBus.UnsubscribeEvent<T>(EventSource.Network, this);
}
protected void UnsubscribeLocalEvent<T>()
where T : notnull
{
EntityManager.EventBus.UnsubscribeEvent<T>(EventSource.Local, this);
}
protected void RaiseLocalEvent<T>(T message) where T : notnull
{
EntityManager.EventBus.RaiseEvent(EventSource.Local, message);
@@ -120,28 +87,6 @@ namespace Robust.Shared.GameObjects
return EntityManager.EventBus.AwaitEvent<T>(EventSource.Network, cancellationToken);
}
protected void SubscribeLocalEvent<TComp, TEvent>(ComponentEventHandler<TComp, TEvent> handler)
where TComp : IComponent
where TEvent : EntityEventArgs
{
EntityManager.EventBus.SubscribeLocalEvent(handler);
}
[Obsolete("Use the overload without the handler argument.")]
protected void UnsubscribeLocalEvent<TComp, TEvent>(ComponentEventHandler<TComp, TEvent> handler)
where TComp : IComponent
where TEvent : EntityEventArgs
{
EntityManager.EventBus.UnsubscribeLocalEvent<TComp, TEvent>();
}
protected void UnsubscribeLocalEvent<TComp, TEvent>()
where TComp : IComponent
where TEvent : EntityEventArgs
{
EntityManager.EventBus.UnsubscribeLocalEvent<TComp, TEvent>();
}
protected void RaiseLocalEvent<TEvent>(EntityUid uid, TEvent args, bool broadcast = true)
where TEvent : EntityEventArgs
{

View File

@@ -2,7 +2,7 @@ using Robust.Shared.Map;
namespace Robust.Shared.GameObjects
{
public readonly struct EntMapIdChangedMessage
public class EntMapIdChangedMessage : EntityEventArgs
{
public EntMapIdChangedMessage(IEntity entity, MapId oldMapId)
{

View File

@@ -1,4 +1,5 @@
using Robust.Shared.Network;
using System;
using Robust.Shared.Network;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
@@ -105,6 +106,7 @@ namespace Robust.Shared.GameObjects
/// </summary>
/// <param name="message">Incoming event message.</param>
/// <param name="component">The local component that sent the message.</param>
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
void HandleMessage(ComponentMessage message, IComponent? component);
/// <summary>
@@ -113,6 +115,7 @@ namespace Robust.Shared.GameObjects
/// <param name="message">Incoming event message.</param>
/// <param name="netChannel">The channel of the remote client that sent the message.</param>
/// <param name="session">The session data for the player who sent this message. Null if this is a client.</param>
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null);
/// <summary>

View File

@@ -161,6 +161,11 @@ namespace Robust.Shared.GameObjects
/// <returns>The component, if it was found. Null otherwise.</returns>
IComponent? GetComponentOrNull(Type type);
/// <summary>
/// Queues this entity for deletion at the end of the tick.
/// </summary>
void QueueDelete();
/// <summary>
/// Deletes this entity.
/// </summary>
@@ -185,6 +190,7 @@ namespace Robust.Shared.GameObjects
/// </summary>
/// <param name="owner">Object that sent the event.</param>
/// <param name="message">Message to send.</param>
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
void SendMessage(IComponent? owner, ComponentMessage message);
/// <summary>
@@ -192,6 +198,7 @@ namespace Robust.Shared.GameObjects
/// </summary>
/// <param name="owner"></param>
/// <param name="message">Message to send.</param>
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
void SendNetworkMessage(IComponent owner, ComponentMessage message, INetChannel? channel = null);
/// <summary>

View File

@@ -79,10 +79,15 @@ namespace Robust.Shared.GameObjects
/// </summary>
/// <param name="query">The query to test.</param>
/// <returns>An enumerable over all matching entities.</returns>
[Obsolete("IEntityQuery is obsolete")]
IEnumerable<IEntity> GetEntities(IEntityQuery query);
IEnumerable<IEntity> GetEntities();
public void QueueDeleteEntity(IEntity entity);
public void QueueDeleteEntity(EntityUid uid);
/// <summary>
/// Shuts-down and removes given <see cref="IEntity"/>. This is also broadcast to all clients.
/// </summary>

View File

@@ -34,6 +34,7 @@ namespace Robust.Shared.GameObjects
/// <param name="entity">Entity sending the message (also entity to send to).</param>
/// <param name="component">Component that sent the message.</param>
/// <param name="message">Message to send.</param>
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
void SendComponentNetworkMessage(INetChannel? channel, IEntity entity, IComponent component,
ComponentMessage message);

View File

@@ -30,7 +30,9 @@ namespace Robust.Shared.GameObjects
/// <summary>
/// The message payload.
/// </summary>
#pragma warning disable 618
public readonly ComponentMessage Message;
#pragma warning restore 618
/// <summary>
/// If the message is from the client, the client's session.

View File

@@ -12,14 +12,6 @@ namespace Robust.Shared.GameObjects
SubscribeLocalEvent<CollisionWakeComponent, CollisionWakeStateMessage>(HandleCollisionWakeState);
}
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<PhysicsWakeMessage>();
UnsubscribeLocalEvent<PhysicsSleepMessage>();
UnsubscribeLocalEvent<CollisionWakeComponent, CollisionWakeStateMessage>();
}
private void HandleWake(PhysicsWakeMessage message)
{
if (!message.Body.Owner.TryGetComponent<CollisionWakeComponent>(out var comp) || !comp.Enabled) return;

View File

@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
@@ -12,7 +14,7 @@ namespace Robust.Shared.GameObjects
{
// Not an EntitySystem given EntityManager has a dependency on it which means it's just easier to IoC it for tests.
void Initialize();
void Startup();
void Shutdown();
@@ -61,7 +63,8 @@ namespace Robust.Shared.GameObjects
Box2 GetWorldAabbFromEntity(in IEntity ent);
}
public class SharedEntityLookup : IEntityLookup, IEntityEventSubscriber
[UsedImplicitly]
public class EntityLookup : IEntityLookup, IEntityEventSubscriber
{
private readonly IEntityManager _entityManager;
private readonly IMapManager _mapManager;
@@ -69,25 +72,32 @@ namespace Robust.Shared.GameObjects
private readonly Dictionary<MapId, DynamicTree<IEntity>> _entityTreesPerMap = new();
// Using stacks so we always use latest data (given we only run it once per entity).
private Stack<MoveEvent> _moveQueue = new();
private Stack<RotateEvent> _rotateQueue = new();
private Queue<EntMapIdChangedMessage> _mapChangeQueue = new();
private readonly Stack<MoveEvent> _moveQueue = new();
private readonly Stack<RotateEvent> _rotateQueue = new();
private readonly Queue<EntMapIdChangedMessage> _mapChangeQueue = new();
/// <summary>
/// Move and rotate events generate the same update so no point duplicating work in the same tick.
/// </summary>
private HashSet<EntityUid> _handledThisTick = new();
private readonly HashSet<EntityUid> _handledThisTick = new();
// TODO: Should combine all of the methods that check for IPhysBody and just use the one GetWorldAabbFromEntity method
public SharedEntityLookup(IEntityManager entityManager, IMapManager mapManager)
public bool Started { get; private set; } = false;
public EntityLookup(IEntityManager entityManager, IMapManager mapManager)
{
_entityManager = entityManager;
_mapManager = mapManager;
}
public void Initialize()
public void Startup()
{
if (Started)
{
throw new InvalidOperationException("Startup() called multiple times.");
}
var eventBus = _entityManager.EventBus;
eventBus.SubscribeEvent<MoveEvent>(EventSource.Local, this, ev => _moveQueue.Push(ev));
eventBus.SubscribeEvent<RotateEvent>(EventSource.Local, this, ev => _rotateQueue.Push(ev));
@@ -96,15 +106,27 @@ namespace Robust.Shared.GameObjects
_entityManager.EntityStarted += HandleEntityStarted;
_mapManager.MapCreated += HandleMapCreated;
_mapManager.MapDestroyed += HandleMapDestroyed;
Started = true;
}
public void Shutdown()
{
// If we haven't even started up, there's nothing to clean up then.
if (!Started)
return;
_moveQueue.Clear();
_rotateQueue.Clear();
_handledThisTick.Clear();
_mapChangeQueue.Clear();
_entityTreesPerMap.Clear();
_entityManager.EventBus.UnsubscribeEvents(this);
_entityManager.EntityDeleted -= HandleEntityDeleted;
_entityManager.EntityStarted -= HandleEntityStarted;
_mapManager.MapCreated -= HandleMapCreated;
_mapManager.MapDestroyed -= HandleMapDestroyed;
Started = false;
}
private void HandleEntityDeleted(object? sender, EntityUid uid)
@@ -193,14 +215,14 @@ namespace Robust.Shared.GameObjects
/// <inheritdoc />
public IEnumerable<IEntity> GetEntitiesIntersecting(MapId mapId, Box2 position, bool approximate = false)
{
if (mapId == MapId.Nullspace)
if (!_entityTreesPerMap.TryGetValue(mapId, out var mapTree))
{
return Enumerable.Empty<IEntity>();
}
var list = new List<IEntity>();
_entityTreesPerMap[mapId].QueryAabb(ref list, (ref List<IEntity> list, in IEntity ent) =>
mapTree.QueryAabb(ref list, (ref List<IEntity> list, in IEntity ent) =>
{
if (!ent.Deleted)
{

View File

@@ -53,6 +53,7 @@ namespace Robust.Shared.GameObjects
public override void Shutdown()
{
base.Shutdown();
_mapManager.MapCreated -= OnMapCreated;
_mapManager.MapDestroyed -= OnMapDestroyed;
_mapManager.OnGridCreated -= OnGridCreated;

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using Robust.Shared.Containers;
using Robust.Shared.IoC;
using Robust.Shared.Map;
@@ -12,55 +11,63 @@ namespace Robust.Shared.GameObjects
{
[Dependency] private readonly IMapManager _mapManager = default!;
private Queue<MoveEvent> _queuedMoveEvents = new();
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MoveEvent>(QueueMoveEvent);
SubscribeLocalEvent<MoveEvent>(HandleMove);
}
public override void Shutdown()
private void HandleMove(MoveEvent moveEvent)
{
base.Shutdown();
UnsubscribeLocalEvent<MoveEvent>();
}
var entity = moveEvent.Sender;
public override void Update(float frameTime)
{
base.Update(frameTime);
while (_queuedMoveEvents.Count > 0)
if (entity.Deleted ||
entity.HasComponent<IMapComponent>() ||
entity.HasComponent<IMapGridComponent>() ||
entity.IsInContainer())
{
var moveEvent = _queuedMoveEvents.Dequeue();
var entity = moveEvent.Sender;
return;
}
if (entity.Deleted || !entity.HasComponent<PhysicsComponent>() || entity.IsInContainer()) continue;
var transform = entity.Transform;
var transform = entity.Transform;
// Change parent if necessary
// Given islands will probably have a bunch of static bodies in them then we'll verify velocities first as it's way cheaper
// This shoouullddnnn'''tt de-parent anything in a container because none of that should have physics applied to it.
if (_mapManager.TryFindGridAt(transform.MapID, moveEvent.NewPosition.ToMapPos(EntityManager), out var grid) &&
grid.GridEntityId.IsValid() &&
grid.GridEntityId != entity.Uid)
// Change parent if necessary
if (_mapManager.TryFindGridAt(transform.MapID, moveEvent.NewPosition.ToMapPos(EntityManager), out var grid) &&
grid.GridEntityId.IsValid() &&
grid.GridEntityId != entity.Uid)
{
// Some minor duplication here with AttachParent but only happens when going on/off grid so not a big deal ATM.
if (grid.Index != transform.GridID)
{
// Also this may deparent if 2 entities are parented but not using containers so fix that
if (grid.Index != transform.GridID)
{
transform.AttachParent(EntityManager.GetEntity(grid.GridEntityId));
}
transform.AttachParent(EntityManager.GetEntity(grid.GridEntityId));
RaiseLocalEvent(entity.Uid, new ChangedGridMessage(entity, transform.GridID, grid.Index));
}
else
}
else
{
var oldGridId = transform.GridID;
// Attach them to map / they are on an invalid grid
if (oldGridId != GridId.Invalid)
{
transform.AttachParent(_mapManager.GetMapEntity(transform.MapID));
RaiseLocalEvent(entity.Uid, new ChangedGridMessage(entity, oldGridId, GridId.Invalid));
}
}
}
}
private void QueueMoveEvent(MoveEvent moveEvent)
public sealed class ChangedGridMessage : EntityEventArgs
{
public IEntity Entity;
public GridId OldGrid;
public GridId NewGrid;
public ChangedGridMessage(IEntity entity, GridId oldGrid, GridId newGrid)
{
_queuedMoveEvents.Enqueue(moveEvent);
Entity = entity;
OldGrid = oldGrid;
NewGrid = newGrid;
}
}
}

View File

@@ -168,14 +168,6 @@ namespace Robust.Shared.GameObjects
_mapManager.MapCreated -= HandleMapCreated;
_mapManager.MapDestroyed -= HandleMapDestroyed;
UnsubscribeLocalEvent<PhysicsUpdateMessage>();
UnsubscribeLocalEvent<PhysicsWakeMessage>();
UnsubscribeLocalEvent<PhysicsSleepMessage>();
UnsubscribeLocalEvent<EntMapIdChangedMessage>();
UnsubscribeLocalEvent<EntInsertedIntoContainerMessage>();
UnsubscribeLocalEvent<EntRemovedFromContainerMessage>();
}
private void HandleMapCreated(object? sender, MapEventArgs eventArgs)

View File

@@ -21,16 +21,6 @@ namespace Robust.Shared.GameObjects
SubscribeLocalEvent<SnapGridComponent, MoveEvent>(HandleMoveEvent);
}
/// <inheritdoc />
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<SnapGridComponent, ComponentStartup>();
UnsubscribeLocalEvent<SnapGridComponent, ComponentShutdown>();
UnsubscribeLocalEvent<SnapGridComponent, MoveEvent>();
}
private void HandleComponentStartup(EntityUid uid, SnapGridComponent component, ComponentStartup args)
{
var transform = ComponentManager.GetComponent<ITransformComponent>(uid);

View File

@@ -14,6 +14,11 @@ namespace Robust.Shared.Input
/// </summary>
IInputCmdContext ActiveContext { get; }
/// <summary>
/// Puts context switches 'on hold'. When set to false, the last deferred context switch is executed, if any.
/// </summary>
bool DeferringEnabled { get; set; }
/// <summary>
/// This event is raised when ever the Active Context is changed.
/// </summary>
@@ -65,6 +70,7 @@ namespace Robust.Shared.Input
/// <summary>
/// Sets the context with the given unique name as the Active context.
/// This *may* be deferred if during input handling, and if multiple context switches are deferred, only the last 'counts'.
/// </summary>
/// <param name="uniqueName">Unique name of the context to set as active.</param>
void SetActiveContext(string uniqueName);
@@ -82,17 +88,42 @@ namespace Robust.Shared.Input
public event EventHandler<ContextChangedEventArgs>? ContextChanged;
private readonly Dictionary<string, InputCmdContext> _contexts = new();
// Random scribble here:
// InputManager r/n feeds the first active context using DefaultContextName
// This is why SetActiveContext needs to be careful to *not* defer the switch if there's no context,
// or else the client instantly crashes because there's no context on startup
private InputCmdContext _activeContext = default!;
/// <summary>
/// This is used to hold a pending context switch, because someone decided that:
/// + Reentrant input events were illegal
/// and
/// + Context switches ought to generate input events
/// This prevents the inevitable errors this caused from input events that switch contexts,
/// by deferring the context switches until we're definitely out of input event code.
/// </summary>
private InputCmdContext? _deferredContextSwitch = null;
/// <inheritdoc />
public IInputCmdContext ActiveContext
public IInputCmdContext ActiveContext => _activeContext;
private bool _deferringEnabled = false;
/// <inheritdoc />
public bool DeferringEnabled
{
get => _activeContext;
private set
{
var args = new ContextChangedEventArgs(_activeContext, value);
_activeContext = (InputCmdContext) value;
ContextChanged?.Invoke(this, args);
get => _deferringEnabled;
set {
// Must be first because _setActiveContextImmediately triggers input events.
_deferringEnabled = value;
if (!value)
{
if (_deferredContextSwitch != null)
{
var icc = _deferredContextSwitch;
_deferredContextSwitch = null;
_setActiveContextImmediately(icc);
}
}
}
}
@@ -179,7 +210,21 @@ namespace Robust.Shared.Input
/// <inheritdoc />
public void SetActiveContext(string uniqueName)
{
ActiveContext = _contexts[uniqueName];
if (!DeferringEnabled)
{
_setActiveContextImmediately(_contexts[uniqueName]);
}
else
{
_deferredContextSwitch = _contexts[uniqueName];
}
}
private void _setActiveContextImmediately(InputCmdContext icc)
{
var args = new ContextChangedEventArgs(_activeContext, icc);
_activeContext = icc;
ContextChanged?.Invoke(this, args);
}
}

View File

@@ -23,7 +23,9 @@ namespace Robust.Shared.Network.Messages
public EntityMessageType Type { get; set; }
public EntityEventArgs SystemMessage { get; set; }
#pragma warning disable 618
public ComponentMessage ComponentMessage { get; set; }
#pragma warning restore 618
public EntityUid EntityUid { get; set; }
public uint NetId { get; set; }
@@ -55,7 +57,9 @@ namespace Robust.Shared.Network.Messages
var serializer = IoCManager.Resolve<IRobustSerializer>();
int length = buffer.ReadVariableInt32();
using var stream = buffer.ReadAlignedMemory(length);
#pragma warning disable 618
ComponentMessage = serializer.Deserialize<ComponentMessage>(stream);
#pragma warning restore 618
}
break;
}

View File

@@ -218,13 +218,7 @@ namespace Robust.Shared.Physics.Broadphase
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<CollisionChangeMessage>();
UnsubscribeLocalEvent<MoveEvent>();
UnsubscribeLocalEvent<RotateEvent>();
UnsubscribeLocalEvent<EntMapIdChangedMessage>();
UnsubscribeLocalEvent<EntInsertedIntoContainerMessage>();
UnsubscribeLocalEvent<EntRemovedFromContainerMessage>();
UnsubscribeLocalEvent<FixtureUpdateMessage>();
_mapManager.OnGridCreated -= HandleGridCreated;
_mapManager.OnGridRemoved -= HandleGridRemoval;
_mapManager.MapCreated -= HandleMapCreated;
@@ -723,6 +717,7 @@ namespace Robust.Shared.Physics.Broadphase
if (preventCollideMessage.Cancelled) return true;
#pragma warning disable 618
foreach (var modifier in state.modifiers)
{
preventCollision |= modifier.PreventCollide(other.Fixture.Body);
@@ -731,6 +726,7 @@ namespace Robust.Shared.Physics.Broadphase
{
preventCollision |= modifier.PreventCollide(body);
}
#pragma warning restore 618
if (preventCollision)
return true;

View File

@@ -384,6 +384,7 @@ namespace Robust.Shared.Physics.Dynamics
_entityManager.EventBus.RaiseLocalEvent(bodyA.Owner.Uid, new StartCollideEvent(contact.FixtureA, contact.FixtureB, contact.Manifold));
_entityManager.EventBus.RaiseLocalEvent(bodyB.Owner.Uid, new StartCollideEvent(contact.FixtureB, contact.FixtureA, contact.Manifold));
#pragma warning disable 618
foreach (var comp in bodyA.Owner.GetAllComponents<IStartCollide>().ToArray())
{
if (bodyB.Deleted) break;
@@ -395,6 +396,7 @@ namespace Robust.Shared.Physics.Dynamics
if (bodyA.Deleted) break;
comp.CollideWith(contact.FixtureB!, contact.FixtureA!, contact.Manifold);
}
#pragma warning restore 618
}
foreach (var contact in _endCollisions)
@@ -405,6 +407,7 @@ namespace Robust.Shared.Physics.Dynamics
_entityManager.EventBus.RaiseLocalEvent(bodyA.Owner.Uid, new EndCollideEvent(contact.FixtureA, contact.FixtureB, contact.Manifold));
_entityManager.EventBus.RaiseLocalEvent(bodyB.Owner.Uid, new EndCollideEvent(contact.FixtureB, contact.FixtureA, contact.Manifold));
#pragma warning disable 618
foreach (var comp in bodyA.Owner.GetAllComponents<IEndCollide>().ToArray())
{
if (bodyB.Deleted) break;
@@ -416,6 +419,7 @@ namespace Robust.Shared.Physics.Dynamics
if (bodyA.Deleted) break;
comp.CollideWith(contact.FixtureB!, contact.FixtureA!, contact.Manifold);
}
#pragma warning restore 618
}
_startCollisions.Clear();

View File

@@ -1,10 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
@@ -62,21 +57,5 @@ namespace Robust.Shared.Physics
if (manifold.IsEmpty()) return 0.0f;
return manifold.Height > manifold.Width ? manifold.Width : manifold.Height;
}
[Obsolete("Use fixture masks and layers instead")]
public static bool CollidesOnMask(IPhysBody a, IPhysBody b)
{
if (a == b)
return false;
if (!a.CanCollide || !b.CanCollide)
return false;
if ((a.CollisionMask & b.CollisionLayer) == 0x0 &&
(b.CollisionMask & a.CollisionLayer) == 0x0)
return false;
return true;
}
}
}

View File

@@ -206,7 +206,6 @@ namespace Robust.Shared.Prototypes
private bool _initialized;
private bool _hasEverBeenReloaded;
private bool _hasEverResynced;
#region IPrototypeManager members
@@ -353,8 +352,8 @@ namespace Robust.Shared.Prototypes
foreach (var prototype in pushed[typeof(EntityPrototype)])
{
foreach (var entity in _entityManager.GetEntities(
new PredicateEntityQuery(e => e.Prototype != null && e.Prototype.ID == prototype)))
foreach (var entity in _entityManager.GetEntities()
.Where(e => e.Prototype != null && e.Prototype.ID == prototype))
{
((EntityPrototype) entityPrototypes[prototype]).UpdateEntity((Entity) entity);
}

View File

@@ -105,7 +105,7 @@ namespace Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Pro
bool skipHook,
ISerializationContext? context)
{
return new();
return new(source);
}
}
}

View File

@@ -44,7 +44,7 @@ namespace Robust.Shared.Utility
}
/// <exception cref="EndOfStreamException">
/// Thrown if not exactly <paramref name="amount"/> bytes could be read.
/// Thrown if not exactly <paramref name="buffer.Length"/> bytes could be read.
/// </exception>
public static void ReadExact(this Stream stream, Span<byte> buffer)
{

View File

@@ -73,7 +73,7 @@ namespace Robust.UnitTesting
entMan.Startup();
}
IoCManager.Resolve<IEntityLookup>().Initialize();
IoCManager.Resolve<IEntityLookup>().Startup();
var mapMan = IoCManager.Resolve<IMapManager>();
mapMan.Initialize();
mapMan.Startup();
@@ -88,8 +88,7 @@ namespace Robust.UnitTesting
var compFactory = IoCManager.Resolve<IComponentFactory>();
if (!compFactory.AllRegisteredTypes.Contains(typeof(MetaDataComponent)))
{
compFactory.Register<MetaDataComponent>();
compFactory.RegisterReference<MetaDataComponent, IMetaDataComponent>();
compFactory.RegisterClass<MetaDataComponent>();
}
if(entMan.EventBus == null)

View File

@@ -16,7 +16,7 @@ namespace Robust.UnitTesting.Server.GameObjects.Components
{
var sim = RobustServerSimulation
.NewSimulation()
.RegisterComponents(factory => { factory.RegisterClass<ContainerManagerComponent>(); factory.RegisterReference<ContainerManagerComponent, IContainerManager>(); })
.RegisterComponents(factory => { factory.RegisterClass<ContainerManagerComponent>(); })
.RegisterPrototypes(protoMan => protoMan.LoadString(PROTOTYPES))
.InitializeInstance();

View File

@@ -38,10 +38,10 @@ namespace Robust.UnitTesting.Server.GameObjects
{
_componentFactory = IoCManager.Resolve<IComponentFactory>();
_componentFactory.Register<ThrowsInAddComponent>();
_componentFactory.Register<ThrowsInInitializeComponent>();
_componentFactory.Register<ThrowsInStartupComponent>();
_componentFactory.RegisterClass<ThrowsInAddComponent>();
_componentFactory.RegisterClass<ThrowsInInitializeComponent>();
_componentFactory.RegisterClass<ThrowsInStartupComponent>();
EntityManager = IoCManager.Resolve<IServerEntityManager>();
MapManager = IoCManager.Resolve<IMapManager>();

View File

@@ -83,7 +83,7 @@ entities:
public void Setup()
{
var compFactory = IoCManager.Resolve<IComponentFactory>();
compFactory.Register<MapDeserializeTestComponent>();
compFactory.RegisterClass<MapDeserializeTestComponent>();
IoCManager.Resolve<ISerializationManager>().Initialize();
var resourceManager = IoCManager.Resolve<IResourceManagerInternal>();

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