cache ReferenceTransform.GetAttachedOWRigidbody() into ReferenceRigidbody

This commit is contained in:
JohnCorby 2022-02-16 01:22:13 -08:00
parent 6fb47ffd35
commit e119920db9
6 changed files with 39 additions and 15 deletions

View File

@ -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(ReferenceTransform.GetAttachedOWRigidbody().FromRelVel(_relativeVelocity, pos));
AttachedRigidbody.SetAngularVelocity(ReferenceTransform.GetAttachedOWRigidbody().FromRelAngVel(_relativeAngularVelocity));
AttachedRigidbody.SetVelocity(ReferenceRigidbody.FromRelVel(_relativeVelocity, pos));
AttachedRigidbody.SetAngularVelocity(ReferenceRigidbody.FromRelAngVel(_relativeAngularVelocity));
_qsbJellyfish.SetIsRising(_isRising);
}

View File

@ -49,8 +49,8 @@ namespace QSB.ShipSync.TransformSync
AttachedRigidbody.SetRotation(targetRot);
}
var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelVel(_relativeVelocity, targetPos);
var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelAngVel(_relativeAngularVelocity);
var targetVelocity = ReferenceRigidbody.FromRelVel(_relativeVelocity, targetPos);
var targetAngularVelocity = ReferenceRigidbody.FromRelAngVel(_relativeAngularVelocity);
SetVelocity(AttachedRigidbody, targetVelocity);
AttachedRigidbody.SetAngularVelocity(targetAngularVelocity);

View File

@ -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(ReferenceTransform.GetAttachedOWRigidbody().FromRelVel(_relativeVelocity, pos));
AttachedRigidbody.SetAngularVelocity(ReferenceTransform.GetAttachedOWRigidbody().FromRelAngVel(_relativeAngularVelocity));
AttachedRigidbody.SetVelocity(ReferenceRigidbody.FromRelVel(_relativeVelocity, pos));
AttachedRigidbody.SetAngularVelocity(ReferenceRigidbody.FromRelAngVel(_relativeAngularVelocity));
Move();
}

View File

@ -17,6 +17,7 @@ namespace QSB.Syncs.Sectored.Rigidbodies
private Vector3 _prevAngularVelocity;
public OWRigidbody AttachedRigidbody { get; private set; }
public OWRigidbody ReferenceRigidbody { get; private set; }
protected abstract OWRigidbody InitAttachedRigidbody();
@ -26,6 +27,17 @@ namespace QSB.Syncs.Sectored.Rigidbodies
return AttachedRigidbody ? AttachedRigidbody.transform : null;
}
public override void SetReferenceTransform(Transform referenceTransform)
{
if (ReferenceTransform == referenceTransform)
{
return;
}
base.SetReferenceTransform(referenceTransform);
ReferenceRigidbody = ReferenceTransform ? ReferenceTransform.GetAttachedOWRigidbody() : null;
}
protected override void UpdatePrevData()
{
base.UpdatePrevData();
@ -57,8 +69,8 @@ namespace QSB.Syncs.Sectored.Rigidbodies
transform.position = ReferenceTransform.ToRelPos(AttachedRigidbody.GetPosition());
transform.rotation = ReferenceTransform.ToRelRot(AttachedRigidbody.GetRotation());
_relativeVelocity = ReferenceTransform.GetAttachedOWRigidbody().ToRelVel(AttachedRigidbody.GetVelocity(), AttachedRigidbody.GetPosition());
_relativeAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().ToRelAngVel(AttachedRigidbody.GetAngularVelocity());
_relativeVelocity = ReferenceRigidbody.ToRelVel(AttachedRigidbody.GetVelocity(), AttachedRigidbody.GetPosition());
_relativeAngularVelocity = ReferenceRigidbody.ToRelAngVel(AttachedRigidbody.GetAngularVelocity());
}
protected override void ApplyToAttached()
@ -84,8 +96,8 @@ namespace QSB.Syncs.Sectored.Rigidbodies
AttachedRigidbody.MoveToPosition(positionToSet);
AttachedRigidbody.MoveToRotation(rotationToSet);
var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelVel(_relativeVelocity, targetPos);
var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelAngVel(_relativeAngularVelocity);
var targetVelocity = ReferenceRigidbody.FromRelVel(_relativeVelocity, targetPos);
var targetAngularVelocity = ReferenceRigidbody.FromRelAngVel(_relativeAngularVelocity);
AttachedRigidbody.SetVelocity(targetVelocity);
AttachedRigidbody.SetAngularVelocity(targetAngularVelocity);

View File

@ -278,7 +278,7 @@ namespace QSB.Syncs
return Vector3.SmoothDamp(currentPosition, targetPosition, ref _positionSmoothVelocity, SmoothTime);
}
public void SetReferenceTransform(Transform referenceTransform)
public virtual void SetReferenceTransform(Transform referenceTransform)
{
if (ReferenceTransform == referenceTransform)
{

View File

@ -17,6 +17,7 @@ namespace QSB.Syncs.Unsectored.Rigidbodies
private Vector3 _prevAngularVelocity;
protected OWRigidbody AttachedRigidbody { get; private set; }
public OWRigidbody ReferenceRigidbody { get; private set; }
protected abstract OWRigidbody InitAttachedRigidbody();
@ -26,6 +27,17 @@ namespace QSB.Syncs.Unsectored.Rigidbodies
return AttachedRigidbody ? AttachedRigidbody.transform : null;
}
public override void SetReferenceTransform(Transform referenceTransform)
{
if (ReferenceTransform == referenceTransform)
{
return;
}
base.SetReferenceTransform(referenceTransform);
ReferenceRigidbody = ReferenceTransform ? ReferenceTransform.GetAttachedOWRigidbody() : null;
}
protected override void UpdatePrevData()
{
base.UpdatePrevData();
@ -51,8 +63,8 @@ namespace QSB.Syncs.Unsectored.Rigidbodies
{
transform.position = ReferenceTransform.ToRelPos(AttachedRigidbody.GetPosition());
transform.rotation = ReferenceTransform.ToRelRot(AttachedRigidbody.GetRotation());
_relativeVelocity = ReferenceTransform.GetAttachedOWRigidbody().ToRelVel(AttachedRigidbody.GetVelocity(), AttachedRigidbody.GetPosition());
_relativeAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().ToRelAngVel(AttachedRigidbody.GetAngularVelocity());
_relativeVelocity = ReferenceRigidbody.ToRelVel(AttachedRigidbody.GetVelocity(), AttachedRigidbody.GetPosition());
_relativeAngularVelocity = ReferenceRigidbody.ToRelAngVel(AttachedRigidbody.GetAngularVelocity());
}
protected override void ApplyToAttached()
@ -72,8 +84,8 @@ namespace QSB.Syncs.Unsectored.Rigidbodies
AttachedRigidbody.MoveToPosition(positionToSet);
AttachedRigidbody.MoveToRotation(rotationToSet);
var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelVel(_relativeVelocity, targetPos);
var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelAngVel(_relativeAngularVelocity);
var targetVelocity = ReferenceRigidbody.FromRelVel(_relativeVelocity, targetPos);
var targetAngularVelocity = ReferenceRigidbody.FromRelAngVel(_relativeAngularVelocity);
AttachedRigidbody.SetVelocity(targetVelocity);
AttachedRigidbody.SetAngularVelocity(targetAngularVelocity);