rotating elements: only do auth on first lit/last darkened

This commit is contained in:
JohnCorby 2022-03-14 08:50:01 -07:00
parent 4b679746e6
commit 133639353b
3 changed files with 21 additions and 11 deletions

View File

@ -73,9 +73,6 @@ public static class AuthorityManager
{ {
identity.AssignClientAuthority(newConn); identity.AssignClientAuthority(newConn);
} }
// DebugLog.DebugWrite($"{identity.NetId}:{identity.gameObject.name} - "
// + $"set authority to {id}");
} }
#endregion #endregion
@ -93,4 +90,4 @@ public static class AuthorityManager
} }
#endregion #endregion
} }

View File

@ -19,6 +19,7 @@ internal abstract class QSBRotatingElements<T, U> : LinkedWorldObject<T, U>
protected abstract IEnumerable<SingleLightSensor> LightSensors { get; } protected abstract IEnumerable<SingleLightSensor> LightSensors { get; }
private QSBLightSensor[] _qsbLightSensors; private QSBLightSensor[] _qsbLightSensors;
private int _litSensors;
public override async UniTask Init(CancellationToken ct) public override async UniTask Init(CancellationToken ct)
{ {
@ -45,8 +46,23 @@ internal abstract class QSBRotatingElements<T, U> : LinkedWorldObject<T, U>
} }
} }
private void OnDetectLocalLight() => NetworkBehaviour.netIdentity.UpdateAuthQueue(AuthQueueAction.Add); private void OnDetectLocalLight()
private void OnDetectLocalDarkness() => NetworkBehaviour.netIdentity.UpdateAuthQueue(AuthQueueAction.Remove); {
_litSensors++;
if (_litSensors == 1)
{
NetworkBehaviour.netIdentity.UpdateAuthQueue(AuthQueueAction.Add);
}
}
private void OnDetectLocalDarkness()
{
_litSensors--;
if (_litSensors == 0)
{
NetworkBehaviour.netIdentity.UpdateAuthQueue(AuthQueueAction.Remove);
}
}
protected override bool SpawnWithServerAuthority => false; protected override bool SpawnWithServerAuthority => false;
} }

View File

@ -36,11 +36,8 @@ internal abstract class RotatingElementsVariableSyncer<TWorldObject> : BaseVaria
protected override bool HasChanged() protected override bool HasChanged()
{ {
var rotatingElements = RotatingElements; var rotatingElements = RotatingElements;
if (Value == null) Value ??= new Quaternion[rotatingElements.Length];
{ PrevValue ??= new Quaternion[rotatingElements.Length];
Value = new Quaternion[rotatingElements.Length];
PrevValue = new Quaternion[rotatingElements.Length];
}
for (var i = 0; i < rotatingElements.Length; i++) for (var i = 0; i < rotatingElements.Length; i++)
{ {