From 2f2037bcc997949e4f4f79d56a32b2acd1026452 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 25 Feb 2022 11:34:13 -0800 Subject: [PATCH] SyncBase: move IsValid to QSBNetworkBehaviour, use that to guard Serialize/Deserialize --- QSB/Syncs/SyncBase.cs | 40 ++++++------------------------ QSB/Utility/QSBNetworkBehaviour.cs | 17 +++++++++++-- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/QSB/Syncs/SyncBase.cs b/QSB/Syncs/SyncBase.cs index f5db46c4..78195b15 100644 --- a/QSB/Syncs/SyncBase.cs +++ b/QSB/Syncs/SyncBase.cs @@ -65,20 +65,14 @@ public abstract class SyncBase : QSBNetworkTransform return true; } - /// - /// can be true with null reference transform.
- /// can be true with inactive attached object. - ///
- public bool IsValid { get; private set; } - - protected virtual bool CheckValid() + protected override bool CheckValid() { if (!IsInitialized) { return false; } - if (!QSBWorldSync.AllObjectsReady) + if (!base.CheckValid()) { return false; } @@ -126,8 +120,6 @@ public abstract class SyncBase : QSBNetworkTransform protected Quaternion SmoothRotation { get; private set; } protected abstract Transform InitAttachedTransform(); - protected abstract void GetFromAttached(); - protected abstract void ApplyToAttached(); public override void OnStartClient() { @@ -183,7 +175,6 @@ public abstract class SyncBase : QSBNetworkTransform { Uninit(); IsInitialized = false; - IsValid = false; }); if (IsInitialized) { @@ -230,27 +221,12 @@ public abstract class SyncBase : QSBNetworkTransform SafeUninit(); } - IsValid = CheckValid(); - if (!IsValid) - { - return; - } + // if (UseInterpolation) + // { + // Interpolate(); + // } - if (UseInterpolation) - { - Interpolate(); - } - - if (hasAuthority) - { - GetFromAttached(); - base.Update(); - } - else if (!OnlyApplyOnDeserialize || _shouldApply) - { - _shouldApply = false; - ApplyToAttached(); - } + base.Update(); } private void Interpolate() @@ -326,4 +302,4 @@ public abstract class SyncBase : QSBNetworkTransform DebugGUI.DrawLabel(AttachedTransform.transform, ToString()); } -} +} \ No newline at end of file diff --git a/QSB/Utility/QSBNetworkBehaviour.cs b/QSB/Utility/QSBNetworkBehaviour.cs index 8ca5df4a..6b14ddd8 100644 --- a/QSB/Utility/QSBNetworkBehaviour.cs +++ b/QSB/Utility/QSBNetworkBehaviour.cs @@ -17,9 +17,22 @@ public abstract class QSBNetworkBehaviour : NetworkBehaviour protected abstract void Serialize(NetworkWriter writer); protected abstract void Deserialize(NetworkReader reader); + public bool IsValid { get; private set; } + + protected virtual bool CheckValid() + { + return QSBWorldSync.AllObjectsReady; + } + protected virtual void Update() { - if (!hasAuthority || !QSBWorldSync.AllObjectsReady) + IsValid = CheckValid(); + if (!IsValid) + { + return; + } + + if (!hasAuthority) { return; } @@ -85,7 +98,7 @@ public abstract class QSBNetworkBehaviour : NetworkBehaviour private void OnData(ArraySegment data) { - if (hasAuthority || !QSBWorldSync.AllObjectsReady) + if (hasAuthority || !IsValid) { return; }