SyncBase: move IsValid to QSBNetworkBehaviour, use that to guard Serialize/Deserialize

This commit is contained in:
JohnCorby 2022-02-25 11:34:13 -08:00
parent 396102a055
commit 2f2037bcc9
2 changed files with 23 additions and 34 deletions

View File

@ -65,20 +65,14 @@ public abstract class SyncBase : QSBNetworkTransform
return true;
}
/// <summary>
/// can be true with null reference transform. <br/>
/// can be true with inactive attached object.
/// </summary>
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());
}
}
}

View File

@ -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<byte> data)
{
if (hasAuthority || !QSBWorldSync.AllObjectsReady)
if (hasAuthority || !IsValid)
{
return;
}