From 46f93ee5b91a9db4d176ce11d19b8a7540ed09a6 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 11 Mar 2022 00:55:49 -0800 Subject: [PATCH 1/3] RelativeTransformUtil: make vel and ang vel actually relative --- QSB/Utility/RelativeTransformUtil.cs | 33 ++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/QSB/Utility/RelativeTransformUtil.cs b/QSB/Utility/RelativeTransformUtil.cs index 7cd5a081..5a151cf7 100644 --- a/QSB/Utility/RelativeTransformUtil.cs +++ b/QSB/Utility/RelativeTransformUtil.cs @@ -4,12 +4,27 @@ namespace QSB.Utility; public static class RelativeTransformUtil { - public static Vector3 ToRelPos(this Transform reference, Vector3 pos) => reference.InverseTransformPoint(pos); - public static Vector3 FromRelPos(this Transform reference, Vector3 relPos) => reference.TransformPoint(relPos); - public static Quaternion ToRelRot(this Transform reference, Quaternion rot) => reference.InverseTransformRotation(rot); - public static Quaternion FromRelRot(this Transform reference, Quaternion relRot) => reference.TransformRotation(relRot); - public static Vector3 ToRelVel(this OWRigidbody reference, Vector3 vel, Vector3 pos) => vel - reference.GetPointVelocity(pos); - public static Vector3 FromRelVel(this OWRigidbody reference, Vector3 relVel, Vector3 pos) => relVel + reference.GetPointVelocity(pos); - public static Vector3 ToRelAngVel(this OWRigidbody reference, Vector3 angVel) => angVel - reference.GetAngularVelocity(); - public static Vector3 FromRelAngVel(this OWRigidbody reference, Vector3 relAngVel) => relAngVel + reference.GetAngularVelocity(); -} \ No newline at end of file + public static Vector3 ToRelPos(this Transform refTransform, Vector3 pos) => + refTransform.InverseTransformPoint(pos); + + public static Vector3 FromRelPos(this Transform refTransform, Vector3 relPos) => + refTransform.TransformPoint(relPos); + + public static Quaternion ToRelRot(this Transform refTransform, Quaternion rot) => + refTransform.InverseTransformRotation(rot); + + public static Quaternion FromRelRot(this Transform refTransform, Quaternion relRot) => + refTransform.TransformRotation(relRot); + + public static Vector3 ToRelVel(this OWRigidbody refBody, Vector3 vel, Vector3 pos) => + refBody.transform.InverseTransformDirection(vel - refBody.GetPointVelocity(pos)); + + public static Vector3 FromRelVel(this OWRigidbody refBody, Vector3 relVel, Vector3 pos) => + refBody.GetPointVelocity(pos) + refBody.transform.TransformDirection(relVel); + + public static Vector3 ToRelAngVel(this OWRigidbody refBody, Vector3 angVel) => + refBody.transform.InverseTransformDirection(angVel - refBody.GetAngularVelocity()); + + public static Vector3 FromRelAngVel(this OWRigidbody refBody, Vector3 relAngVel) => + refBody.GetAngularVelocity() + refBody.transform.TransformDirection(relAngVel); +} From ad2c84acb20dfc2666e5ed56e1fa0ba6f0c2984f Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 11 Mar 2022 00:58:14 -0800 Subject: [PATCH 2/3] Revert "use GetType() instead of GetType().Name in strings, since they return the same thing" This reverts commit c3e77d24 --- QSB/ItemSync/WorldObjects/Items/QSBItem.cs | 2 +- QSB/Patches/QSBPatchManager.cs | 4 ++-- QSB/Player/PlayerInfo.cs | 2 +- QSB/Syncs/SyncBase.cs | 2 +- QSB/WorldSync/QSBWorldSync.cs | 8 ++++---- QSB/WorldSync/WorldObject.cs | 2 +- QSB/WorldSync/WorldObjectManager.cs | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs index 77dc329d..3dcbde7c 100644 --- a/QSB/ItemSync/WorldObjects/Items/QSBItem.cs +++ b/QSB/ItemSync/WorldObjects/Items/QSBItem.cs @@ -22,7 +22,7 @@ internal class QSBItem : WorldObject, IQSBItem { if (AttachedObject == null) { - DebugLog.ToConsole($"Error - AttachedObject is null! Type:{GetType()}", OWML.Common.MessageType.Error); + DebugLog.ToConsole($"Error - AttachedObject is null! Type:{GetType().Name}", OWML.Common.MessageType.Error); return; } diff --git a/QSB/Patches/QSBPatchManager.cs b/QSB/Patches/QSBPatchManager.cs index 1c4a85fc..9ba90950 100644 --- a/QSB/Patches/QSBPatchManager.cs +++ b/QSB/Patches/QSBPatchManager.cs @@ -55,14 +55,14 @@ public static class QSBPatchManager //DebugLog.DebugWrite($"Patch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info); foreach (var patch in _patchList.Where(x => x.Type == type)) { - //DebugLog.DebugWrite($" - Patching in {patch}", MessageType.Info); + //DebugLog.DebugWrite($" - Patching in {patch.GetType().Name}", MessageType.Info); try { patch.DoPatches(TypeToInstance[type]); } catch (Exception ex) { - DebugLog.ToConsole($"Error while patching {patch} :\r\n{ex}", MessageType.Error); + DebugLog.ToConsole($"Error while patching {patch.GetType().Name} :\r\n{ex}", MessageType.Error); } } diff --git a/QSB/Player/PlayerInfo.cs b/QSB/Player/PlayerInfo.cs index c628b8da..6c4141da 100644 --- a/QSB/Player/PlayerInfo.cs +++ b/QSB/Player/PlayerInfo.cs @@ -300,5 +300,5 @@ public class PlayerInfo _ditheringAnimator.SetVisible(visible, seconds); } - public override string ToString() => $"{PlayerId}:{GetType()} ({Name})"; + public override string ToString() => $"{PlayerId}:{GetType().Name} ({Name})"; } \ No newline at end of file diff --git a/QSB/Syncs/SyncBase.cs b/QSB/Syncs/SyncBase.cs index 83efe0f8..e0190596 100644 --- a/QSB/Syncs/SyncBase.cs +++ b/QSB/Syncs/SyncBase.cs @@ -109,7 +109,7 @@ public abstract class SyncBase : QSBNetworkTransform public string Name => AttachedTransform ? AttachedTransform.name : ""; public override string ToString() => (IsPlayerObject ? $"{Player.PlayerId}." : string.Empty) - + $"{netId}:{GetType()} ({Name})"; + + $"{netId}:{GetType().Name} ({Name})"; protected virtual float DistanceChangeThreshold => 5f; private float _prevDistance; diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 4b953020..05353172 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -203,13 +203,13 @@ public static class QSBWorldSync { if (!WorldObjects.IsInRange(objectId)) { - DebugLog.ToConsole($"Warning - Tried to find {typeof(TWorldObject)} id {objectId}. Count is {WorldObjects.Count}.", MessageType.Warning); + DebugLog.ToConsole($"Warning - Tried to find {typeof(TWorldObject).Name} id {objectId}. Count is {WorldObjects.Count}.", MessageType.Warning); return default; } if (WorldObjects[objectId] is not TWorldObject worldObject) { - DebugLog.ToConsole($"Error - {typeof(TWorldObject)} id {objectId} is actually {WorldObjects[objectId].GetType()}.", MessageType.Error); + DebugLog.ToConsole($"Error - {typeof(TWorldObject).Name} id {objectId} is actually {WorldObjects[objectId].GetType().Name}.", MessageType.Error); return default; } @@ -221,13 +221,13 @@ public static class QSBWorldSync { if (!unityObject) { - DebugLog.ToConsole($"Error - Trying to run GetWorldFromUnity with a null unity object! TWorldObject:{typeof(TWorldObject)}, TUnityObject:NULL, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Error); + DebugLog.ToConsole($"Error - Trying to run GetWorldFromUnity with a null unity object! TWorldObject:{typeof(TWorldObject).Name}, TUnityObject:NULL, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Error); return default; } if (!UnityObjectsToWorldObjects.TryGetValue(unityObject, out var worldObject)) { - DebugLog.ToConsole($"Error - WorldObjectsToUnityObjects does not contain \"{unityObject.name}\"! TWorldObject:{typeof(TWorldObject)}, TUnityObject:{unityObject.GetType()}, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Error); + DebugLog.ToConsole($"Error - WorldObjectsToUnityObjects does not contain \"{unityObject.name}\"! TWorldObject:{typeof(TWorldObject).Name}, TUnityObject:{unityObject.GetType().Name}, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Error); return default; } diff --git a/QSB/WorldSync/WorldObject.cs b/QSB/WorldSync/WorldObject.cs index e587194d..a9a324a3 100644 --- a/QSB/WorldSync/WorldObject.cs +++ b/QSB/WorldSync/WorldObject.cs @@ -11,7 +11,7 @@ public abstract class WorldObject : IWorldObject MonoBehaviour IWorldObject.AttachedObject => AttachedObject; public T AttachedObject { get; init; } public string Name => AttachedObject ? AttachedObject.name : ""; - public override string ToString() => $"{ObjectId}:{GetType()} ({Name})"; + public override string ToString() => $"{ObjectId}:{GetType().Name} ({Name})"; public virtual async UniTask Init(CancellationToken ct) { } public virtual void OnRemoval() { } diff --git a/QSB/WorldSync/WorldObjectManager.cs b/QSB/WorldSync/WorldObjectManager.cs index e0ace223..d234fa02 100644 --- a/QSB/WorldSync/WorldObjectManager.cs +++ b/QSB/WorldSync/WorldObjectManager.cs @@ -20,5 +20,5 @@ public abstract class WorldObjectManager : MonoBehaviour, IAddComponentOnStart public virtual void UnbuildWorldObjects() { } - public override string ToString() => GetType().ToString(); + public override string ToString() => GetType().Name; } \ No newline at end of file From 99cf46a23f839f254e14db97288e220241315ab7 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 11 Mar 2022 01:06:34 -0800 Subject: [PATCH 3/3] RigidbodySync.GetFromAttached: store AttachedRigidbody.GetPosition() in local var --- QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs | 5 +++-- QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs b/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs index dc612ffb..e41f85c7 100644 --- a/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs +++ b/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs @@ -70,9 +70,10 @@ public abstract class SectoredRigidbodySync : BaseSectoredSync return; } - transform.position = ReferenceTransform.ToRelPos(AttachedRigidbody.GetPosition()); + var pos = AttachedRigidbody.GetPosition(); + transform.position = ReferenceTransform.ToRelPos(pos); transform.rotation = ReferenceTransform.ToRelRot(AttachedRigidbody.GetRotation()); - Velocity = ReferenceRigidbody.ToRelVel(AttachedRigidbody.GetVelocity(), AttachedRigidbody.GetPosition()); + Velocity = ReferenceRigidbody.ToRelVel(AttachedRigidbody.GetVelocity(), pos); AngularVelocity = ReferenceRigidbody.ToRelAngVel(AttachedRigidbody.GetAngularVelocity()); } diff --git a/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs b/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs index b0d3a6a5..99b5cc91 100644 --- a/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs +++ b/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs @@ -64,9 +64,10 @@ public abstract class UnsectoredRigidbodySync : BaseUnsectoredSync protected override void GetFromAttached() { - transform.position = ReferenceTransform.ToRelPos(AttachedRigidbody.GetPosition()); + var pos = AttachedRigidbody.GetPosition(); + transform.position = ReferenceTransform.ToRelPos(pos); transform.rotation = ReferenceTransform.ToRelRot(AttachedRigidbody.GetRotation()); - Velocity = ReferenceRigidbody.ToRelVel(AttachedRigidbody.GetVelocity(), AttachedRigidbody.GetPosition()); + Velocity = ReferenceRigidbody.ToRelVel(AttachedRigidbody.GetVelocity(), pos); AngularVelocity = ReferenceRigidbody.ToRelAngVel(AttachedRigidbody.GetAngularVelocity()); }