[RelativeSync] Fixed buncha stuff, cleanup

This commit is contained in:
NotAKidoS 2024-05-29 13:41:11 -05:00
parent b97265ef37
commit b786ecd51c
11 changed files with 429 additions and 231 deletions

View file

@ -1,4 +1,6 @@
using ABI.CCK.Components;
using ABI_RC.Core.Player;
using ABI_RC.Core.Savior;
using ABI.CCK.Components;
using UnityEngine;
namespace NAK.RelativeSync.Components;
@ -14,8 +16,21 @@ public class RelativeSyncMarker : MonoBehaviour
private void Start()
{
string path = GetGameObjectPath(transform);
pathHash = path.GetHashCode();
RelativeSyncManager.RelativeSyncTransforms.Add(pathHash, this);
int hash = path.GetHashCode();
// check if it already exists (this **should** only matter in worlds)
if (RelativeSyncManager.RelativeSyncTransforms.ContainsKey(hash))
{
RelativeSyncMod.Logger.Warning($"Duplicate RelativeSyncMarker found at path {path}");
if (!FindAvailableHash(ref hash)) // super lazy fix idfc
{
RelativeSyncMod.Logger.Error($"Failed to find available hash for RelativeSyncMarker after 16 tries! {path}");
return;
}
}
pathHash = hash;
RelativeSyncManager.RelativeSyncTransforms.Add(hash, this);
ConfigureForPotentialMovementParent();
}
@ -39,12 +54,37 @@ public class RelativeSyncMarker : MonoBehaviour
private static string GetGameObjectPath(Transform transform)
{
// props already have a unique instance identifier at root
// worlds uhhhh, dont duplicate the same thing over and over thx
// avatars on remote/local client have diff path, we need to account for it -_-
string path = transform.name;
while (transform.parent != null)
{
transform = transform.parent;
// only true at root of local player object
if (transform.CompareTag("Player"))
{
path = MetaPort.Instance.ownerId + "/" + path;
break;
} // remote player object root is already player guid
path = transform.name + "/" + path;
}
return path;
}
private bool FindAvailableHash(ref int hash)
{
for (int i = 0; i < 16; i++)
{
hash += 1;
if (!RelativeSyncManager.RelativeSyncTransforms.ContainsKey(hash)) return true;
}
// failed to find a hash in 16 tries, dont care
return false;
}
}