dont do the goofy caching stuff since its not worth the compute

This commit is contained in:
JohnCorby 2022-05-03 21:57:52 -07:00
parent 8f38bedcfa
commit 55287814e7
2 changed files with 8 additions and 29 deletions

View File

@ -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<Sector>
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<Sector>
}
else if (QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse)
{
var shuttleController = QSBWorldSync.GetUnityObject<EyeShuttleController>();
if (shuttleController == null)
{
DebugLog.ToConsole($"Warning - Expected to find a EyeShuttleController for {AttachedObject.name}!", MessageType.Warning);
return false;
}
if (!_cachedShuttleController)
_cachedShuttleController = QSBWorldSync.GetUnityObject<EyeShuttleController>();
if (!shuttleController._isPlayerInside)
if (!_cachedShuttleController._isPlayerInside)
{
return false;
}

View File

@ -178,7 +178,6 @@ public static class QSBWorldSync
private static readonly List<IWorldObject> WorldObjects = new();
private static readonly Dictionary<MonoBehaviour, IWorldObject> UnityObjectsToWorldObjects = new();
private static readonly Dictionary<Type, MonoBehaviour> CachedUnityObjects = new();
static QSBWorldSync()
{
@ -229,7 +228,6 @@ public static class QSBWorldSync
DialogueConditions.Clear();
PersistentConditions.Clear();
ShipLogFacts.Clear();
CachedUnityObjects.Clear();
}
public static IEnumerable<IWorldObject> GetWorldObjects() => WorldObjects;
@ -275,28 +273,12 @@ public static class QSBWorldSync
}
/// <summary>
/// not deterministic across platforms
/// not deterministic across platforms.
/// iterates thru all objects and throws error if there isn't exactly 1.
/// </summary>
public static TUnityObject GetUnityObject<TUnityObject>()
where TUnityObject : MonoBehaviour
{
if (CachedUnityObjects.ContainsKey(typeof(TUnityObject)))
{
return CachedUnityObjects[typeof(TUnityObject)] as TUnityObject;
}
var unityObjects = GetUnityObjects<TUnityObject>();
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<TUnityObject>().Single();
/// <summary>
/// not deterministic across platforms