mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-17 01:13:05 +00:00
transform sync: be consistent with position/rotation change threshold
This commit is contained in:
parent
2a7d4ad97f
commit
d53735f160
@ -95,8 +95,8 @@ namespace QSB.JellyfishSync.TransformSync
|
||||
var pos = ReferenceTransform.FromRelPos(transform.position);
|
||||
AttachedRigidbody.SetPosition(pos);
|
||||
AttachedRigidbody.SetRotation(ReferenceTransform.FromRelRot(transform.rotation));
|
||||
AttachedRigidbody.SetVelocity(ReferenceRigidbody.FromRelVel(_relativeVelocity, pos));
|
||||
AttachedRigidbody.SetAngularVelocity(ReferenceRigidbody.FromRelAngVel(_relativeAngularVelocity));
|
||||
AttachedRigidbody.SetVelocity(ReferenceRigidbody.FromRelVel(Velocity, pos));
|
||||
AttachedRigidbody.SetAngularVelocity(ReferenceRigidbody.FromRelAngVel(AngularVelocity));
|
||||
|
||||
_qsbJellyfish.SetIsRising(_isRising);
|
||||
}
|
||||
|
@ -48,8 +48,8 @@ namespace QSB.ShipSync.TransformSync
|
||||
AttachedRigidbody.SetRotation(targetRot);
|
||||
}
|
||||
|
||||
var targetVelocity = ReferenceRigidbody.FromRelVel(_relativeVelocity, targetPos);
|
||||
var targetAngularVelocity = ReferenceRigidbody.FromRelAngVel(_relativeAngularVelocity);
|
||||
var targetVelocity = ReferenceRigidbody.FromRelVel(Velocity, targetPos);
|
||||
var targetAngularVelocity = ReferenceRigidbody.FromRelAngVel(AngularVelocity);
|
||||
|
||||
SetVelocity(AttachedRigidbody, targetVelocity);
|
||||
AttachedRigidbody.SetAngularVelocity(targetAngularVelocity);
|
||||
|
@ -72,8 +72,8 @@ namespace QSB.Syncs.Occasional
|
||||
var pos = ReferenceTransform.FromRelPos(transform.position);
|
||||
AttachedRigidbody.SetPosition(pos);
|
||||
AttachedRigidbody.SetRotation(ReferenceTransform.FromRelRot(transform.rotation));
|
||||
AttachedRigidbody.SetVelocity(ReferenceRigidbody.FromRelVel(_relativeVelocity, pos));
|
||||
AttachedRigidbody.SetAngularVelocity(ReferenceRigidbody.FromRelAngVel(_relativeAngularVelocity));
|
||||
AttachedRigidbody.SetVelocity(ReferenceRigidbody.FromRelVel(Velocity, pos));
|
||||
AttachedRigidbody.SetAngularVelocity(ReferenceRigidbody.FromRelAngVel(AngularVelocity));
|
||||
|
||||
Move();
|
||||
}
|
||||
|
@ -8,8 +8,11 @@ namespace QSB.Syncs
|
||||
{
|
||||
protected override float SendInterval => 0.05f;
|
||||
|
||||
protected Vector3 _prevPosition;
|
||||
protected Quaternion _prevRotation;
|
||||
private const float PositionChangeThreshold = 0.05f;
|
||||
private const float RotationChangeThreshold = 0.05f;
|
||||
|
||||
private Vector3 _prevPosition;
|
||||
private Quaternion _prevRotation;
|
||||
|
||||
protected override void UpdatePrevData()
|
||||
{
|
||||
@ -18,8 +21,8 @@ namespace QSB.Syncs
|
||||
}
|
||||
|
||||
protected override bool HasChanged() =>
|
||||
Vector3.Distance(transform.position, _prevPosition) > 1E-05f ||
|
||||
Quaternion.Angle(transform.rotation, _prevRotation) > 1E-05f;
|
||||
Vector3.Distance(transform.position, _prevPosition) > PositionChangeThreshold ||
|
||||
Quaternion.Angle(transform.rotation, _prevRotation) > RotationChangeThreshold;
|
||||
|
||||
protected override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
|
@ -10,8 +10,11 @@ namespace QSB.Syncs
|
||||
|
||||
protected override float SendInterval => 0.05f;
|
||||
|
||||
protected Vector3 _prevPosition;
|
||||
protected Quaternion _prevRotation;
|
||||
private const float PositionChangeThreshold = 0.05f;
|
||||
private const float RotationChangeThreshold = 0.05f;
|
||||
|
||||
private Vector3 _prevPosition;
|
||||
private Quaternion _prevRotation;
|
||||
|
||||
protected override void UpdatePrevData()
|
||||
{
|
||||
@ -20,8 +23,8 @@ namespace QSB.Syncs
|
||||
}
|
||||
|
||||
protected override bool HasChanged() =>
|
||||
Vector3.Distance(Target.localPosition, _prevPosition) > 1E-05f ||
|
||||
Quaternion.Angle(Target.localRotation, _prevRotation) > 1E-05f;
|
||||
Vector3.Distance(Target.localPosition, _prevPosition) > PositionChangeThreshold ||
|
||||
Quaternion.Angle(Target.localRotation, _prevRotation) > RotationChangeThreshold;
|
||||
|
||||
protected override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
|
@ -6,13 +6,11 @@ namespace QSB.Syncs.Sectored.Rigidbodies
|
||||
{
|
||||
public abstract class SectoredRigidbodySync : BaseSectoredSync
|
||||
{
|
||||
private const float PositionMovedThreshold = 0.05f;
|
||||
private const float AngleRotatedThreshold = 0.05f;
|
||||
private const float VelocityChangeThreshold = 0.05f;
|
||||
private const float AngVelocityChangeThreshold = 0.05f;
|
||||
private const float AngularVelocityChangeThreshold = 0.05f;
|
||||
|
||||
protected Vector3 _relativeVelocity;
|
||||
protected Vector3 _relativeAngularVelocity;
|
||||
protected Vector3 Velocity;
|
||||
protected Vector3 AngularVelocity;
|
||||
private Vector3 _prevVelocity;
|
||||
private Vector3 _prevAngularVelocity;
|
||||
|
||||
@ -41,22 +39,22 @@ namespace QSB.Syncs.Sectored.Rigidbodies
|
||||
protected override void UpdatePrevData()
|
||||
{
|
||||
base.UpdatePrevData();
|
||||
_prevVelocity = _relativeVelocity;
|
||||
_prevAngularVelocity = _relativeAngularVelocity;
|
||||
_prevVelocity = Velocity;
|
||||
_prevAngularVelocity = AngularVelocity;
|
||||
}
|
||||
|
||||
protected override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(_relativeVelocity);
|
||||
writer.Write(_relativeAngularVelocity);
|
||||
writer.Write(Velocity);
|
||||
writer.Write(AngularVelocity);
|
||||
}
|
||||
|
||||
protected override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
_relativeVelocity = reader.ReadVector3();
|
||||
_relativeAngularVelocity = reader.ReadVector3();
|
||||
Velocity = reader.ReadVector3();
|
||||
AngularVelocity = reader.ReadVector3();
|
||||
}
|
||||
|
||||
protected override void GetFromAttached()
|
||||
@ -69,8 +67,8 @@ namespace QSB.Syncs.Sectored.Rigidbodies
|
||||
|
||||
transform.position = ReferenceTransform.ToRelPos(AttachedRigidbody.GetPosition());
|
||||
transform.rotation = ReferenceTransform.ToRelRot(AttachedRigidbody.GetRotation());
|
||||
_relativeVelocity = ReferenceRigidbody.ToRelVel(AttachedRigidbody.GetVelocity(), AttachedRigidbody.GetPosition());
|
||||
_relativeAngularVelocity = ReferenceRigidbody.ToRelAngVel(AttachedRigidbody.GetAngularVelocity());
|
||||
Velocity = ReferenceRigidbody.ToRelVel(AttachedRigidbody.GetVelocity(), AttachedRigidbody.GetPosition());
|
||||
AngularVelocity = ReferenceRigidbody.ToRelAngVel(AttachedRigidbody.GetAngularVelocity());
|
||||
}
|
||||
|
||||
protected override void ApplyToAttached()
|
||||
@ -96,36 +94,16 @@ namespace QSB.Syncs.Sectored.Rigidbodies
|
||||
AttachedRigidbody.MoveToPosition(positionToSet);
|
||||
AttachedRigidbody.MoveToRotation(rotationToSet);
|
||||
|
||||
var targetVelocity = ReferenceRigidbody.FromRelVel(_relativeVelocity, targetPos);
|
||||
var targetAngularVelocity = ReferenceRigidbody.FromRelAngVel(_relativeAngularVelocity);
|
||||
var targetVelocity = ReferenceRigidbody.FromRelVel(Velocity, targetPos);
|
||||
var targetAngularVelocity = ReferenceRigidbody.FromRelAngVel(AngularVelocity);
|
||||
|
||||
AttachedRigidbody.SetVelocity(targetVelocity);
|
||||
AttachedRigidbody.SetAngularVelocity(targetAngularVelocity);
|
||||
}
|
||||
|
||||
protected override bool HasChanged()
|
||||
{
|
||||
if (Vector3.Distance(transform.position, _prevPosition) > PositionMovedThreshold)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Quaternion.Angle(transform.rotation, _prevRotation) > AngleRotatedThreshold)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Vector3.Distance(_relativeVelocity, _prevVelocity) > VelocityChangeThreshold)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Vector3.Distance(_relativeAngularVelocity, _prevAngularVelocity) > AngVelocityChangeThreshold)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
protected override bool HasChanged() =>
|
||||
base.HasChanged() ||
|
||||
Vector3.Distance(Velocity, _prevVelocity) > VelocityChangeThreshold ||
|
||||
Vector3.Distance(AngularVelocity, _prevAngularVelocity) > AngularVelocityChangeThreshold;
|
||||
}
|
||||
}
|
||||
|
@ -6,17 +6,15 @@ namespace QSB.Syncs.Unsectored.Rigidbodies
|
||||
{
|
||||
public abstract class UnsectoredRigidbodySync : BaseUnsectoredSync
|
||||
{
|
||||
private const float PositionMovedThreshold = 0.05f;
|
||||
private const float AngleRotatedThreshold = 0.05f;
|
||||
private const float VelocityChangeThreshold = 0.05f;
|
||||
private const float AngVelocityChangeThreshold = 0.05f;
|
||||
private const float AngularVelocityChangeThreshold = 0.05f;
|
||||
|
||||
protected Vector3 _relativeVelocity;
|
||||
protected Vector3 _relativeAngularVelocity;
|
||||
protected Vector3 Velocity;
|
||||
protected Vector3 AngularVelocity;
|
||||
private Vector3 _prevVelocity;
|
||||
private Vector3 _prevAngularVelocity;
|
||||
|
||||
protected OWRigidbody AttachedRigidbody { get; private set; }
|
||||
public OWRigidbody AttachedRigidbody { get; private set; }
|
||||
public OWRigidbody ReferenceRigidbody { get; private set; }
|
||||
|
||||
protected abstract OWRigidbody InitAttachedRigidbody();
|
||||
@ -41,30 +39,30 @@ namespace QSB.Syncs.Unsectored.Rigidbodies
|
||||
protected override void UpdatePrevData()
|
||||
{
|
||||
base.UpdatePrevData();
|
||||
_prevVelocity = _relativeVelocity;
|
||||
_prevAngularVelocity = _relativeAngularVelocity;
|
||||
_prevVelocity = Velocity;
|
||||
_prevAngularVelocity = AngularVelocity;
|
||||
}
|
||||
|
||||
protected override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(_relativeVelocity);
|
||||
writer.Write(_relativeAngularVelocity);
|
||||
writer.Write(Velocity);
|
||||
writer.Write(AngularVelocity);
|
||||
}
|
||||
|
||||
protected override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
_relativeVelocity = reader.ReadVector3();
|
||||
_relativeAngularVelocity = reader.ReadVector3();
|
||||
Velocity = reader.ReadVector3();
|
||||
AngularVelocity = reader.ReadVector3();
|
||||
}
|
||||
|
||||
protected override void GetFromAttached()
|
||||
{
|
||||
transform.position = ReferenceTransform.ToRelPos(AttachedRigidbody.GetPosition());
|
||||
transform.rotation = ReferenceTransform.ToRelRot(AttachedRigidbody.GetRotation());
|
||||
_relativeVelocity = ReferenceRigidbody.ToRelVel(AttachedRigidbody.GetVelocity(), AttachedRigidbody.GetPosition());
|
||||
_relativeAngularVelocity = ReferenceRigidbody.ToRelAngVel(AttachedRigidbody.GetAngularVelocity());
|
||||
Velocity = ReferenceRigidbody.ToRelVel(AttachedRigidbody.GetVelocity(), AttachedRigidbody.GetPosition());
|
||||
AngularVelocity = ReferenceRigidbody.ToRelAngVel(AttachedRigidbody.GetAngularVelocity());
|
||||
}
|
||||
|
||||
protected override void ApplyToAttached()
|
||||
@ -84,36 +82,16 @@ namespace QSB.Syncs.Unsectored.Rigidbodies
|
||||
AttachedRigidbody.MoveToPosition(positionToSet);
|
||||
AttachedRigidbody.MoveToRotation(rotationToSet);
|
||||
|
||||
var targetVelocity = ReferenceRigidbody.FromRelVel(_relativeVelocity, targetPos);
|
||||
var targetAngularVelocity = ReferenceRigidbody.FromRelAngVel(_relativeAngularVelocity);
|
||||
var targetVelocity = ReferenceRigidbody.FromRelVel(Velocity, targetPos);
|
||||
var targetAngularVelocity = ReferenceRigidbody.FromRelAngVel(AngularVelocity);
|
||||
|
||||
AttachedRigidbody.SetVelocity(targetVelocity);
|
||||
AttachedRigidbody.SetAngularVelocity(targetAngularVelocity);
|
||||
}
|
||||
|
||||
protected override bool HasChanged()
|
||||
{
|
||||
if (Vector3.Distance(transform.position, _prevPosition) > PositionMovedThreshold)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Quaternion.Angle(transform.rotation, _prevRotation) > AngleRotatedThreshold)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Vector3.Distance(_relativeVelocity, _prevVelocity) > VelocityChangeThreshold)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Vector3.Distance(_relativeAngularVelocity, _prevAngularVelocity) > AngVelocityChangeThreshold)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
protected override bool HasChanged() =>
|
||||
base.HasChanged() ||
|
||||
Vector3.Distance(Velocity, _prevVelocity) > VelocityChangeThreshold ||
|
||||
Vector3.Distance(AngularVelocity, _prevAngularVelocity) > AngularVelocityChangeThreshold;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user