mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-19 12:40:56 +00:00
go back to unpatching DeterministicRigidbodyPatches
This commit is contained in:
parent
dddbc0e1c1
commit
c9bd31fc8d
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using HarmonyLib;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
@ -13,6 +14,9 @@ namespace QSB.Utility.Deterministic;
|
||||
/// </summary>
|
||||
public static class DeterministicManager
|
||||
{
|
||||
private static readonly Harmony _harmony = new(typeof(DeterministicManager).FullName);
|
||||
private static bool _patched;
|
||||
|
||||
public static readonly Dictionary<Transform, (int SiblingIndex, Transform Parent)> ParentCache = new();
|
||||
|
||||
public static void Init()
|
||||
@ -21,11 +25,30 @@ public static class DeterministicManager
|
||||
{
|
||||
DebugLog.DebugWrite("cleared deterministic parent cache");
|
||||
ParentCache.Clear();
|
||||
|
||||
if (!_patched)
|
||||
{
|
||||
_harmony.PatchAll(typeof(DeterministicRigidbodyPatches));
|
||||
_patched = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// unpatch DeterministicRigidbodyPatches so rigidbodies added/activated later dont get counted towards the cache.
|
||||
/// also breaks with e.g. QuantumInstrument since transform is added to the cache twice (once by body and once by instrument)
|
||||
/// </summary>
|
||||
public static void OnWorldObjectsAdded()
|
||||
{
|
||||
if (_patched)
|
||||
{
|
||||
_harmony.UnpatchSelf();
|
||||
_patched = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// world object managers call this as early as possible to capture parents before they change
|
||||
/// only world object managers call this, to do it as early as possible to capture parents before they change
|
||||
/// </summary>
|
||||
public static string DeterministicPath(this Component component)
|
||||
{
|
||||
@ -56,7 +79,7 @@ public static class DeterministicManager
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// world object managers call this as early as possible to capture parents before they change
|
||||
/// only world object managers call this, to do it as early as possible to capture parents before they change
|
||||
/// </summary>
|
||||
public static IEnumerable<T> SortDeterministic<T>(this IEnumerable<T> components) where T : Component
|
||||
=> components.OrderBy(DeterministicPath);
|
||||
|
@ -9,10 +9,8 @@ namespace QSB.Utility.Deterministic;
|
||||
/// used to capture the true path of a rigidbody before it changes parent
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(OWRigidbody))]
|
||||
public class DeterministicRigidbodyPatches : QSBPatch
|
||||
public static class DeterministicRigidbodyPatches
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnModStart;
|
||||
|
||||
/// <summary>
|
||||
/// changing the parent has to be deferred until Start to preserve the sibling index.
|
||||
/// for example, anglerfish bodies all share the same parent, so unparenting one clobbers the sibling index of all the others.
|
||||
|
@ -88,6 +88,8 @@ public static class QSBWorldSync
|
||||
AllObjectsAdded = true;
|
||||
DebugLog.DebugWrite("World Objects added.", MessageType.Success);
|
||||
|
||||
DeterministicManager.OnWorldObjectsAdded();
|
||||
|
||||
foreach (var item in _managerToBuiltObjects)
|
||||
{
|
||||
var worldObjects = item.Value;
|
||||
|
Loading…
x
Reference in New Issue
Block a user