Skip to content

Commit

Permalink
Only send MsgNewAppearance to InGame players (#2184)
Browse files Browse the repository at this point in the history
  • Loading branch information
wixoaGit authored Jan 24, 2025
1 parent 83ee0f1 commit 2b2cd64
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 51 deletions.
10 changes: 0 additions & 10 deletions OpenDreamClient/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public override void PostInit() {
IoCManager.Resolve<IDreamSoundEngine>().Initialize();

_netManager.RegisterNetMessage<MsgAllAppearances>(RxAllAppearances);
_netManager.RegisterNetMessage<MsgNewAppearance>(RxNewAppearance);

if (_configurationManager.GetCVar(CVars.DisplayCompat))
_dreamInterface.OpenAlert(
Expand Down Expand Up @@ -113,15 +112,6 @@ private void RxAllAppearances(MsgAllAppearances message) {
clientAppearanceSystem.SetAllAppearances(message.AllAppearances);
}

private void RxNewAppearance(MsgNewAppearance message) {
if (!_entitySystemManager.TryGetEntitySystem<ClientAppearanceSystem>(out var clientAppearanceSystem)) {
Logger.GetSawmill("opendream").Error("Received MsgNewAppearance before initializing entity systems");
return;
}

clientAppearanceSystem.OnNewAppearance(message);
}

// As of RobustToolbox v0.90.0.0 there's a TileEdgeOverlay that breaks our rendering
// because we don't have an ITileDefinition for each tile.
// This removes that overlay immediately after MapSystem adds it.
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamClient/Interface/DummyDreamInterfaceManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using OpenDreamClient.Interface.Controls;
using OpenDreamClient.Interface.Descriptors;
using OpenDreamShared.Dream;
using OpenDreamShared.Network.Messages;
using Robust.Shared.Network;
Expand All @@ -20,6 +19,7 @@ public sealed class DummyDreamInterfaceManager : IDreamInterfaceManager {
public ControlMap? DefaultMap => null;
public ViewRange View => new(5);
public bool ShowPopupMenus => true;

[Dependency] private readonly IClientNetManager _netManager = default!;

public void Initialize() {
Expand Down
4 changes: 2 additions & 2 deletions OpenDreamClient/Rendering/ClientAppearanceSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using OpenDreamClient.Resources;
using OpenDreamClient.Resources.ResourceTypes;
using Robust.Shared.Timing;
using OpenDreamShared.Network.Messages;

namespace OpenDreamClient.Rendering;

Expand All @@ -25,6 +24,7 @@ internal sealed class ClientAppearanceSystem : SharedAppearanceSystem {
[Dependency] private readonly DMISpriteSystem _spriteSystem = default!;

public override void Initialize() {
SubscribeNetworkEvent<NewAppearanceEvent>(OnNewAppearance);
SubscribeNetworkEvent<RemoveAppearanceEvent>(e => _appearances.Remove(e.AppearanceId));
SubscribeNetworkEvent<AnimationEvent>(OnAnimation);
SubscribeLocalEvent<DMISpriteComponent, WorldAABBEvent>(OnWorldAABB);
Expand Down Expand Up @@ -75,7 +75,7 @@ public DreamIcon GetTurfIcon(uint turfId) {
return icon;
}

public void OnNewAppearance(MsgNewAppearance e) {
public void OnNewAppearance(NewAppearanceEvent e) {
uint appearanceId = e.Appearance.MustGetId();
_appearances[appearanceId] = e.Appearance;

Expand Down
1 change: 0 additions & 1 deletion OpenDreamRuntime/DreamManager.Connections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ private void InitializeConnectionManager() {
_netManager.RegisterNetMessage<MsgSound>();
_netManager.RegisterNetMessage<MsgUpdateClientInfo>();
_netManager.RegisterNetMessage<MsgAllAppearances>();
_netManager.RegisterNetMessage<MsgNewAppearance>();

var topicPort = _config.GetCVar(OpenDreamCVars.TopicPort);
var worldTopicAddress = new IPEndPoint(IPAddress.Loopback, topicPort);
Expand Down
14 changes: 6 additions & 8 deletions OpenDreamRuntime/Rendering/ServerAppearanceSystem.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using OpenDreamShared.Dream;
using Robust.Server.Player;
using Robust.Shared.Enums;
using SharedAppearanceSystem = OpenDreamShared.Rendering.SharedAppearanceSystem;
using System.Diagnostics.CodeAnalysis;
using OpenDreamShared.Network.Messages;
using Robust.Shared.Player;
using Robust.Shared.Network;
using System.Diagnostics;
using SharedAppearanceSystem = OpenDreamShared.Rendering.SharedAppearanceSystem;

namespace OpenDreamRuntime.Rendering;

public sealed class ServerAppearanceSystem : SharedAppearanceSystem {
public readonly ImmutableAppearance DefaultAppearance;
public ImmutableAppearance DefaultAppearance = default!;

/// <summary>
/// Each appearance gets a unique ID when marked as registered. Here we store these as a key -> weakref in a weaktable, which does not count
Expand All @@ -28,10 +27,9 @@ public sealed class ServerAppearanceSystem : SharedAppearanceSystem {
private readonly Dictionary<uint, ProxyWeakRef> _idToAppearance = new();
private uint _counter;

[Dependency] private readonly IServerNetManager _networkManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

public ServerAppearanceSystem() {
public override void Initialize() {
DefaultAppearance = new ImmutableAppearance(MutableAppearance.Default, this);
DefaultAppearance.MarkRegistered(_counter++); //first appearance registered gets id 0, this is the blank default appearance
ProxyWeakRef proxyWeakRef = new(DefaultAppearance);
Expand All @@ -40,9 +38,7 @@ public ServerAppearanceSystem() {
//leaving this in as a sanity check for mutable and immutable appearance hashcodes covering all the same vars
//if this debug assert fails, you've probably changed appearance var and not updated its counterpart
Debug.Assert(DefaultAppearance.GetHashCode() == MutableAppearance.Default.GetHashCode());
}

public override void Initialize() {
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
}

Expand Down Expand Up @@ -75,7 +71,8 @@ private void RegisterAppearance(ImmutableAppearance immutableAppearance) {
ProxyWeakRef proxyWeakRef = new(immutableAppearance);
_appearanceLookup.Add(proxyWeakRef);
_idToAppearance.Add(immutableAppearance.MustGetId(), proxyWeakRef);
_networkManager.ServerSendToAll(new MsgNewAppearance(immutableAppearance));

RaiseNetworkEvent(new NewAppearanceEvent(immutableAppearance));
}

public ImmutableAppearance AddAppearance(MutableAppearance appearance, bool registerAppearance = true) {
Expand All @@ -98,6 +95,7 @@ public ImmutableAppearance AddAppearance(ImmutableAppearance appearance, bool re
}

//this should only be called by the ImmutableAppearance's finalizer
[Access(typeof(ImmutableAppearance))]
public override void RemoveAppearance(ImmutableAppearance appearance) {
lock (_lock) {
ProxyWeakRef proxyWeakRef = new(appearance);
Expand Down
8 changes: 4 additions & 4 deletions OpenDreamShared/Dream/ImmutableAppearance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ namespace OpenDreamShared.Dream;
*/

// TODO: Wow this is huge! Probably look into splitting this by most used/least used to reduce the size of these
[Serializable]
[Serializable, NetSerializable]
public sealed class ImmutableAppearance : IEquatable<ImmutableAppearance> {
private uint? _registeredId;
private bool _needsFinalizer;
private int? _storedHashCode;
private readonly SharedAppearanceSystem? _appearanceSystem;

[ViewVariables] public readonly string Name = MutableAppearance.Default.Name;
[ViewVariables] public readonly string? Desc = MutableAppearance.Default.Desc;
Expand Down Expand Up @@ -71,6 +68,9 @@ public sealed class ImmutableAppearance : IEquatable<ImmutableAppearance> {
// PixelOffset2 behaves the same as PixelOffset in top-down mode, so this is used
public Vector2i TotalPixelOffset => PixelOffset + PixelOffset2;

[NonSerialized] private readonly SharedAppearanceSystem? _appearanceSystem;
[NonSerialized] private bool _needsFinalizer;
[NonSerialized] private int? _storedHashCode;
[NonSerialized] private List<uint>? _overlayIDs;
[NonSerialized] private List<uint>? _underlayIDs;

Expand Down
22 changes: 0 additions & 22 deletions OpenDreamShared/Network/Messages/MsgNewAppearance.cs

This file was deleted.

5 changes: 2 additions & 3 deletions OpenDreamShared/Rendering/SharedAppearanceSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ public abstract class SharedAppearanceSystem : EntitySystem {
public abstract void RemoveAppearance(ImmutableAppearance appearance);

[Serializable, NetSerializable]
public sealed class NewAppearanceEvent(uint appearanceId, MutableAppearance appearance) : EntityEventArgs {
public uint AppearanceId { get; } = appearanceId;
public MutableAppearance Appearance { get; } = appearance;
public sealed class NewAppearanceEvent(ImmutableAppearance appearance) : EntityEventArgs {
public ImmutableAppearance Appearance { get; } = appearance;
}

[Serializable, NetSerializable]
Expand Down

0 comments on commit 2b2cd64

Please sign in to comment.