From 55287814e7ec69617ada1c053fe0edd2c8243fb5 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Tue, 3 May 2022 21:57:52 -0700 Subject: [PATCH] dont do the goofy caching stuff since its not worth the compute --- QSB/SectorSync/WorldObjects/QSBSector.cs | 13 +++++-------- QSB/WorldSync/QSBWorldSync.cs | 24 +++--------------------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/QSB/SectorSync/WorldObjects/QSBSector.cs b/QSB/SectorSync/WorldObjects/QSBSector.cs index 24d2d7f0..28d91286 100644 --- a/QSB/SectorSync/WorldObjects/QSBSector.cs +++ b/QSB/SectorSync/WorldObjects/QSBSector.cs @@ -2,7 +2,6 @@ using QSB.Utility; using QSB.WorldSync; using System; -using System.Linq; using UnityEngine; namespace QSB.SectorSync.WorldObjects; @@ -26,6 +25,8 @@ public class QSBSector : WorldObject public override void SendInitialState(uint to) { } + private static EyeShuttleController _cachedShuttleController; + public bool ShouldSyncTo(DynamicOccupant occupantType) { if (occupantType == DynamicOccupant.Ship && Type == Sector.Name.Ship) @@ -62,14 +63,10 @@ public class QSBSector : WorldObject } else if (QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse) { - var shuttleController = QSBWorldSync.GetUnityObject(); - if (shuttleController == null) - { - DebugLog.ToConsole($"Warning - Expected to find a EyeShuttleController for {AttachedObject.name}!", MessageType.Warning); - return false; - } + if (!_cachedShuttleController) + _cachedShuttleController = QSBWorldSync.GetUnityObject(); - if (!shuttleController._isPlayerInside) + if (!_cachedShuttleController._isPlayerInside) { return false; } diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index b2a08155..04976328 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -178,7 +178,6 @@ public static class QSBWorldSync private static readonly List WorldObjects = new(); private static readonly Dictionary UnityObjectsToWorldObjects = new(); - private static readonly Dictionary CachedUnityObjects = new(); static QSBWorldSync() { @@ -229,7 +228,6 @@ public static class QSBWorldSync DialogueConditions.Clear(); PersistentConditions.Clear(); ShipLogFacts.Clear(); - CachedUnityObjects.Clear(); } public static IEnumerable GetWorldObjects() => WorldObjects; @@ -275,28 +273,12 @@ public static class QSBWorldSync } /// - /// not deterministic across platforms + /// not deterministic across platforms. + /// iterates thru all objects and throws error if there isn't exactly 1. /// public static TUnityObject GetUnityObject() where TUnityObject : MonoBehaviour - { - if (CachedUnityObjects.ContainsKey(typeof(TUnityObject))) - { - return CachedUnityObjects[typeof(TUnityObject)] as TUnityObject; - } - - var unityObjects = GetUnityObjects(); - - if (unityObjects.Count() != 1) - { - DebugLog.ToConsole($"Warning - Tried to cache a unity object that there are multiple of. ({typeof(TUnityObject).Name})" + - "\r\nCaching the first one - this probably is going to end badly!", MessageType.Warning); - } - - var unityObject = unityObjects.First(); - CachedUnityObjects.Add(typeof(TUnityObject), unityObject); - return unityObject; - } + => GetUnityObjects().Single(); /// /// not deterministic across platforms