Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove prefab requests array and lock cache dictionary #525

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Remove requests array and lock cache dictionary
Freddy 5 bear or or or or or
  • Loading branch information
LeeTwentyThree committed Jan 2, 2024
commit 47d0dce9c7b18d7c26c1c1a83464c9645bcde846
40 changes: 20 additions & 20 deletions Nautilus/Assets/ModPrefabCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace Nautilus.Assets;
public static class ModPrefabCache
{
private static ModPrefabCacheInstance _cacheInstance;
internal static Dictionary<string, ModPrefabRequest> Requests { get; } = new Dictionary<string, ModPrefabRequest>();

/// <summary> Adds the given prefab to the cache. </summary>
/// <param name="prefab"> The prefab object that is disabled and cached. </param>
Expand Down Expand Up @@ -88,17 +87,6 @@ private void Awake()

public void EnterPrefabIntoCache(GameObject prefab)
{
// Proper prefabs can never exist in the scene, so parenting them is dangerous and pointless.
if(prefab.IsPrefab())
{
InternalLogger.Debug($"Game Object: {prefab} is a proper prefab. Skipping parenting for cache.");
}
else
{
prefab.transform.parent = _prefabRoot;
prefab.SetActive(true);
}

var prefabIdentifier = prefab.GetComponent<PrefabIdentifier>();

if(prefabIdentifier == null)
Expand All @@ -107,15 +95,27 @@ public void EnterPrefabIntoCache(GameObject prefab)
return;
}

// Proper prefabs can never exist in the scene, so parenting them is dangerous and pointless.
if(!Entries.ContainsKey(prefabIdentifier.classId))
{
Entries.Add(prefabIdentifier.classId, prefab);
InternalLogger.Debug($"ModPrefabCache: added prefab {prefab}");
}
else // this should never happen
lock (Entries)
{
InternalLogger.Warn($"ModPrefabCache: prefab {prefabIdentifier.classId} already existed in cache!");
if(!Entries.ContainsKey(prefabIdentifier.classId))
{
Entries.Add(prefabIdentifier.classId, prefab);
InternalLogger.Debug($"ModPrefabCache: added prefab {prefab}");
// Proper prefabs can never exist in the scene, so parenting them is dangerous and pointless.
if (prefab.IsPrefab())
{
InternalLogger.Debug($"Game Object: {prefab} is a proper prefab. Skipping parenting for cache.");
}
else
{
prefab.transform.parent = _prefabRoot;
prefab.SetActive(true);
}
}
else // this should never happen
{
InternalLogger.Warn($"ModPrefabCache: prefab {prefabIdentifier.classId} already existed in cache!");
}
}
}

Expand Down
1 change: 0 additions & 1 deletion Nautilus/Assets/ModPrefabRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ internal class ModPrefabRequest: IPrefabRequest
public ModPrefabRequest(PrefabInfo prefabInfo)
{
this.prefabInfo = prefabInfo;
ModPrefabCache.Requests[prefabInfo.ClassID] = this;
}

private void Init()
Expand Down
5 changes: 0 additions & 5 deletions Nautilus/Patchers/PrefabDatabasePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ private static IPrefabRequest GetModPrefabAsync(string classId)
return null;
}

if(ModPrefabCache.Requests.TryGetValue(prefabInfo.ClassID, out var request))
{
return request;
}

return new ModPrefabRequest(prefabInfo);
}

Expand Down