Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wixoaGit committed Jan 24, 2025
1 parent 56a847d commit e1e3c24
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
11 changes: 4 additions & 7 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 @@ -99,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

0 comments on commit e1e3c24

Please sign in to comment.