From ab39b7113fa23de637580ea3afc819bcdb07892c Mon Sep 17 00:00:00 2001 From: wixoaGit Date: Sun, 29 Dec 2024 17:24:31 -0500 Subject: [PATCH] Only register movables' appearances when in PVS range --- OpenDreamRuntime/AtomManager.cs | 4 ++-- OpenDreamRuntime/Objects/Types/DreamList.cs | 2 +- OpenDreamRuntime/Rendering/DMISpriteSystem.cs | 8 ++++++-- .../Rendering/ServerAppearanceSystem.cs | 20 +++++++++++-------- RobustToolbox | 2 +- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/OpenDreamRuntime/AtomManager.cs b/OpenDreamRuntime/AtomManager.cs index 1e137f47cf..4932b052e3 100644 --- a/OpenDreamRuntime/AtomManager.cs +++ b/OpenDreamRuntime/AtomManager.cs @@ -503,7 +503,7 @@ public ImmutableAppearance MustGetAppearance(DreamObject atom) { DreamObjectTurf turf => turf.Appearance, DreamObjectMovable movable => movable.SpriteComponent.Appearance!, DreamObjectArea area => area.Appearance, - DreamObjectImage image => image.IsMutableAppearance ? AppearanceSystem!.AddAppearance(image.MutableAppearance!, registerApearance: false) : image.SpriteComponent!.Appearance!, + DreamObjectImage image => image.IsMutableAppearance ? AppearanceSystem!.AddAppearance(image.MutableAppearance!, registerAppearance: false) : image.SpriteComponent!.Appearance!, _ => throw new Exception($"Cannot get appearance of {atom}") }; } @@ -517,7 +517,7 @@ public bool TryGetAppearance(DreamObject atom, [NotNullWhen(true)] out Immutable else if (atom is DreamObjectMovable movable && movable.SpriteComponent.Appearance is not null) appearance = movable.SpriteComponent.Appearance; else if (atom is DreamObjectImage image) - appearance = image.IsMutableAppearance ? AppearanceSystem!.AddAppearance(image.MutableAppearance!, registerApearance: false) : image.SpriteComponent?.Appearance; + appearance = image.IsMutableAppearance ? AppearanceSystem!.AddAppearance(image.MutableAppearance!, registerAppearance: false) : image.SpriteComponent?.Appearance; else if (atom is DreamObjectArea area) appearance = area.Appearance; else diff --git a/OpenDreamRuntime/Objects/Types/DreamList.cs b/OpenDreamRuntime/Objects/Types/DreamList.cs index 75672fcaa2..6b088cfdcf 100644 --- a/OpenDreamRuntime/Objects/Types/DreamList.cs +++ b/OpenDreamRuntime/Objects/Types/DreamList.cs @@ -727,7 +727,7 @@ public override void RemoveValue(DreamValue value) { return; _atomManager.UpdateAppearance(_owner, appearance => { - GetOverlaysList(appearance).Remove(_appearanceSystem.AddAppearance(overlayAppearance, registerApearance:false)); + GetOverlaysList(appearance).Remove(_appearanceSystem.AddAppearance(overlayAppearance, registerAppearance:false)); }); } diff --git a/OpenDreamRuntime/Rendering/DMISpriteSystem.cs b/OpenDreamRuntime/Rendering/DMISpriteSystem.cs index b5ef3ce611..5bafbabe4f 100644 --- a/OpenDreamRuntime/Rendering/DMISpriteSystem.cs +++ b/OpenDreamRuntime/Rendering/DMISpriteSystem.cs @@ -14,12 +14,16 @@ public override void Initialize() { } private void GetComponentState(EntityUid uid, DMISpriteComponent component, ref ComponentGetState args) { - args.State = new SharedDMISpriteComponent.DMISpriteComponentState(component.Appearance?.MustGetID(), component.ScreenLocation); + uint? appearanceId = (component.Appearance != null) + ? _appearance?.AddAppearance(component.Appearance).MustGetID() + : null; + + args.State = new SharedDMISpriteComponent.DMISpriteComponentState(appearanceId, component.ScreenLocation); } public void SetSpriteAppearance(Entity ent, MutableAppearance appearance, bool dirty = true) { DMISpriteComponent component = ent.Comp; - component.Appearance = _appearance?.AddAppearance(appearance); + component.Appearance = new ImmutableAppearance(appearance, _appearance); if(dirty) Dirty(ent, component); } diff --git a/OpenDreamRuntime/Rendering/ServerAppearanceSystem.cs b/OpenDreamRuntime/Rendering/ServerAppearanceSystem.cs index 8fe7871908..93a666a676 100644 --- a/OpenDreamRuntime/Rendering/ServerAppearanceSystem.cs +++ b/OpenDreamRuntime/Rendering/ServerAppearanceSystem.cs @@ -7,6 +7,7 @@ using Robust.Shared.Player; using Robust.Shared.Network; using System.Diagnostics; +using Robust.Shared.Console; namespace OpenDreamRuntime.Rendering; @@ -61,11 +62,10 @@ private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e) { if(proxyWeakRef.TryGetTarget(out var immutable)) sendData.Add(immutable.MustGetID(), immutable); } - Logger.GetSawmill("appearance").Debug($"Sending {sendData.Count} appearances to new player {e.Session.Name}"); + Logger.GetSawmill("appearance").Debug($"Sending {sendData.Count} appearances to new player {e.Session.Name}"); e.Session.Channel.SendMessage(new MsgAllAppearances(sendData)); } - } } @@ -77,17 +77,21 @@ private void RegisterAppearance(ImmutableAppearance immutableAppearance) { _networkManager.ServerSendToAll(new MsgNewAppearance(immutableAppearance)); } - public ImmutableAppearance AddAppearance(MutableAppearance appearance, bool registerApearance = true) { + public ImmutableAppearance AddAppearance(MutableAppearance appearance, bool registerAppearance = true) { ImmutableAppearance immutableAppearance = new(appearance, this); + AddAppearance(immutableAppearance, registerAppearance); + } + + public ImmutableAppearance AddAppearance(ImmutableAppearance appearance, bool registerAppearance = true) { lock (_lock) { - if(_appearanceLookup.TryGetValue(new(immutableAppearance), out var weakReference) && weakReference.TryGetTarget(out var originalImmutable)) { + if(_appearanceLookup.TryGetValue(new(appearance), out var weakReference) && weakReference.TryGetTarget(out var originalImmutable)) { return originalImmutable; - } else if (registerApearance) { - RegisterAppearance(immutableAppearance); - return immutableAppearance; + } else if (registerAppearance) { + RegisterAppearance(appearance); + return appearance; } else { - return immutableAppearance; + return appearance; } } } diff --git a/RobustToolbox b/RobustToolbox index 9c30fdf5fd..92b0e7f1a8 160000 --- a/RobustToolbox +++ b/RobustToolbox @@ -1 +1 @@ -Subproject commit 9c30fdf5fd7261ea424f80478c2746e2001326e8 +Subproject commit 92b0e7f1a853979a1361ed24d2fb5ffc11f43f66