mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-04 03:39:55 +00:00
more changes
This commit is contained in:
parent
5791c9fd0c
commit
178fe91f78
@ -1,4 +1,5 @@
|
||||
using QSB.Events;
|
||||
using QSB.SectorSync;
|
||||
using QSB.Syncs.TransformSync;
|
||||
using QSB.Tools;
|
||||
using QSB.Utility;
|
||||
@ -10,7 +11,7 @@ namespace QSB.Player.TransformSync
|
||||
{
|
||||
protected override Transform InitLocalTransform()
|
||||
{
|
||||
SectorSync.SetSectorDetector(Locator.GetPlayerSectorDetector());
|
||||
SectorSync.Init(Locator.GetPlayerSectorDetector(), this);
|
||||
var body = Locator.GetPlayerCamera().gameObject.transform;
|
||||
|
||||
Player.Camera = Locator.GetPlayerCamera();
|
||||
@ -49,5 +50,7 @@ namespace QSB.Player.TransformSync
|
||||
&& NetId.Value != 0U;
|
||||
|
||||
public override bool UseInterpolation => true;
|
||||
|
||||
public override TargetType Type => TargetType.PlayerCamera;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using QSB.Animation.Player;
|
||||
using QSB.Instruments;
|
||||
using QSB.SectorSync;
|
||||
using QSB.Syncs.TransformSync;
|
||||
using UnityEngine;
|
||||
|
||||
@ -7,9 +8,6 @@ namespace QSB.Player.TransformSync
|
||||
{
|
||||
public class PlayerTransformSync : SectoredTransformSync
|
||||
{
|
||||
public static PlayerTransformSync LocalInstance { get; private set; }
|
||||
public override bool UseInterpolation => true;
|
||||
|
||||
static PlayerTransformSync() => AnimControllerPatch.Init();
|
||||
|
||||
public override void OnStartLocalPlayer()
|
||||
@ -37,7 +35,7 @@ namespace QSB.Player.TransformSync
|
||||
|
||||
protected override Transform InitLocalTransform()
|
||||
{
|
||||
SectorSync.SetSectorDetector(Locator.GetPlayerSectorDetector());
|
||||
SectorSync.Init(Locator.GetPlayerSectorDetector(), this);
|
||||
var body = GetPlayerModel();
|
||||
|
||||
GetComponent<AnimationSync>().InitLocal(body);
|
||||
@ -70,5 +68,11 @@ namespace QSB.Player.TransformSync
|
||||
&& Player.PlayerStates.IsReady
|
||||
&& NetId.Value != uint.MaxValue
|
||||
&& NetId.Value != 0U;
|
||||
|
||||
public static PlayerTransformSync LocalInstance { get; private set; }
|
||||
|
||||
public override bool UseInterpolation => true;
|
||||
|
||||
public override TargetType Type => TargetType.Player;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using OWML.Common;
|
||||
using QSB.Player;
|
||||
using QSB.SectorSync;
|
||||
using QSB.Syncs.TransformSync;
|
||||
using QSB.Tools;
|
||||
using QSB.Utility;
|
||||
@ -11,9 +12,6 @@ namespace QSB.ProbeSync.TransformSync
|
||||
{
|
||||
public static PlayerProbeSync LocalInstance { get; private set; }
|
||||
|
||||
protected override float DistanceLeeway => 10f;
|
||||
public override bool UseInterpolation => true;
|
||||
|
||||
public override void OnStartAuthority()
|
||||
{
|
||||
DebugLog.DebugWrite($"OnStartAuthority probe");
|
||||
@ -25,7 +23,7 @@ namespace QSB.ProbeSync.TransformSync
|
||||
|
||||
protected override Transform InitLocalTransform()
|
||||
{
|
||||
SectorSync.SetSectorDetector(Locator.GetProbe().GetSectorDetector());
|
||||
SectorSync.Init(Locator.GetProbe().GetSectorDetector(), this);
|
||||
var body = GetProbe();
|
||||
|
||||
Player.ProbeBody = body.gameObject;
|
||||
@ -61,5 +59,11 @@ namespace QSB.ProbeSync.TransformSync
|
||||
&& Player.PlayerStates.IsReady
|
||||
&& NetId.Value != uint.MaxValue
|
||||
&& NetId.Value != 0U;
|
||||
|
||||
protected override float DistanceLeeway => 10f;
|
||||
|
||||
public override bool UseInterpolation => true;
|
||||
|
||||
public override TargetType Type => TargetType.Probe;
|
||||
}
|
||||
}
|
@ -238,6 +238,7 @@
|
||||
<Compile Include="QuantumSync\QuantumManager.cs" />
|
||||
<Compile Include="QuantumSync\Patches\QuantumVisibilityPatches.cs" />
|
||||
<Compile Include="QuantumSync\Patches\ServerQuantumPatches.cs" />
|
||||
<Compile Include="SectorSync\TargetType.cs" />
|
||||
<Compile Include="Syncs\ISectoredSync.cs" />
|
||||
<Compile Include="Syncs\ISync.cs" />
|
||||
<Compile Include="Syncs\RigidbodySync\UnparentedBaseRigidbodySync.cs" />
|
||||
|
@ -163,19 +163,25 @@ namespace QSB
|
||||
var probeText = probeSector == null ? "NULL" : probeSector.Name;
|
||||
GUI.Label(new Rect(420, offset3, 400f, 20f), $"Probe sector : {probeText}");
|
||||
offset3 += _debugLineSpacing;
|
||||
var shipTransform = Locator.GetShipTransform();
|
||||
var hatchController = shipTransform.GetComponentInChildren<HatchController>();
|
||||
var interactZone = hatchController.GetComponent<InteractZone>();
|
||||
GUI.Label(new Rect(420, offset3, 200f, 20f), $"Hatch angle : {2 * Vector3.Angle(Locator.GetPlayerCamera().transform.forward, interactZone.transform.forward)}");
|
||||
offset3 += _debugLineSpacing;
|
||||
|
||||
GUI.Label(new Rect(420, offset3, 200f, 20f), $"Current Flyer : {ShipManager.Instance.CurrentFlyer}");
|
||||
offset3 += _debugLineSpacing;
|
||||
var ship = ShipTransformSync.LocalInstance;
|
||||
GUI.Label(new Rect(420, offset3, 200f, 20f), $"In control of ship? : {ship.HasAuthority}");
|
||||
offset3 += _debugLineSpacing;
|
||||
GUI.Label(new Rect(420, offset3, 200f, 20f), $"Ship sector : {(ship.ReferenceSector == null ? "NULL" : ship.ReferenceSector.Name)}");
|
||||
offset3 += _debugLineSpacing;
|
||||
if (ship == null)
|
||||
{
|
||||
GUI.Label(new Rect(420, offset3, 200f, 20f), $"SHIP INSTANCE NULL");
|
||||
offset3 += _debugLineSpacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.Label(new Rect(420, offset3, 200f, 20f), $"In control of ship? : {ship.HasAuthority}");
|
||||
offset3 += _debugLineSpacing;
|
||||
GUI.Label(new Rect(420, offset3, 200f, 20f), $"Ship sector : {(ship.ReferenceSector == null ? "NULL" : ship.ReferenceSector.Name)}");
|
||||
offset3 += _debugLineSpacing;
|
||||
GUI.Label(new Rect(420, offset3, 200f, 20f), $"Ship relative velocity : {ship.AttachedObject.GetRelativeVelocity(ship.ReferenceTransform.GetAttachedOWRigidbody())}");
|
||||
offset3 += _debugLineSpacing;
|
||||
}
|
||||
|
||||
|
||||
|
||||
var offset2 = 10f;
|
||||
|
@ -1,5 +1,6 @@
|
||||
using OWML.Utils;
|
||||
using QSB.Player;
|
||||
using QSB.SectorSync;
|
||||
using QSB.Syncs.TransformSync;
|
||||
using QSB.Utility;
|
||||
using System.Linq;
|
||||
@ -9,8 +10,6 @@ namespace QSB.RoastingSync.TransformSync
|
||||
{
|
||||
internal class RoastingStickTransformSync : SectoredTransformSync
|
||||
{
|
||||
public override bool UseInterpolation => true;
|
||||
|
||||
private Transform _stickTip;
|
||||
private Transform _networkStickTip => gameObject.transform.GetChild(0);
|
||||
private const float SmoothTime = 0.1f;
|
||||
@ -87,5 +86,9 @@ namespace QSB.RoastingSync.TransformSync
|
||||
&& Player.PlayerStates.IsReady
|
||||
&& NetId.Value != uint.MaxValue
|
||||
&& NetId.Value != 0U;
|
||||
|
||||
public override bool UseInterpolation => true;
|
||||
|
||||
public override TargetType Type => TargetType.RoastingStick;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using OWML.Common;
|
||||
using OWML.Utils;
|
||||
using QSB.SectorSync.WorldObjects;
|
||||
using QSB.Syncs;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System.Collections.Generic;
|
||||
@ -15,6 +16,7 @@ namespace QSB.SectorSync
|
||||
|
||||
private OWRigidbody _attachedOWRigidbody;
|
||||
private SectorDetector _sectorDetector;
|
||||
private TargetType _targetType;
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
@ -25,7 +27,7 @@ namespace QSB.SectorSync
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSectorDetector(SectorDetector detector)
|
||||
public void Init<T>(SectorDetector detector, ISectoredSync<T> sectoredSync)
|
||||
{
|
||||
if (_sectorDetector != null)
|
||||
{
|
||||
@ -41,6 +43,8 @@ namespace QSB.SectorSync
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - OWRigidbody for {_sectorDetector.name} is null!", MessageType.Warning);
|
||||
}
|
||||
|
||||
_targetType = sectoredSync.Type;
|
||||
}
|
||||
|
||||
private void AddSector(Sector sector)
|
||||
@ -82,7 +86,7 @@ namespace QSB.SectorSync
|
||||
return null;
|
||||
}
|
||||
|
||||
var listToCheck = SectorList.Count(x => x.ShouldSyncTo()) == 0
|
||||
var listToCheck = SectorList.Count(x => x.ShouldSyncTo(_targetType)) == 0
|
||||
? QSBWorldSync.GetWorldObjects<QSBSector>()
|
||||
: SectorList;
|
||||
|
||||
@ -97,7 +101,7 @@ namespace QSB.SectorSync
|
||||
*/
|
||||
|
||||
var activeNotNullNotBlacklisted = listToCheck.Where(sector => sector.AttachedObject != null
|
||||
&& sector.ShouldSyncTo());
|
||||
&& sector.ShouldSyncTo(_targetType));
|
||||
if (activeNotNullNotBlacklisted.Count() == 0)
|
||||
{
|
||||
return default;
|
||||
@ -128,7 +132,7 @@ namespace QSB.SectorSync
|
||||
var radius = GetRadius(sector); // want to be small
|
||||
var velocity = GetRelativeVelocity(sector, rigidbody); // want to be small
|
||||
|
||||
return (distance * distance) + (radius * radius) + (velocity * velocity);
|
||||
return Mathf.Pow(distance, 2) + Mathf.Pow(radius, 2) + Mathf.Pow(velocity, 2);
|
||||
}
|
||||
|
||||
public static float GetRadius(QSBSector sector)
|
||||
|
13
QSB/SectorSync/TargetType.cs
Normal file
13
QSB/SectorSync/TargetType.cs
Normal file
@ -0,0 +1,13 @@
|
||||
namespace QSB.SectorSync
|
||||
{
|
||||
public enum TargetType
|
||||
{
|
||||
None = 0,
|
||||
Player = 1,
|
||||
Probe = 2,
|
||||
PlayerCamera = 3,
|
||||
RoastingStick = 4,
|
||||
Ship = 5,
|
||||
Other = 6
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ namespace QSB.SectorSync.WorldObjects
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShouldSyncTo()
|
||||
public bool ShouldSyncTo(TargetType targetType)
|
||||
{
|
||||
if (AttachedObject == null)
|
||||
{
|
||||
@ -45,7 +45,7 @@ namespace QSB.SectorSync.WorldObjects
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Type == Sector.Name.Ship)
|
||||
if (targetType == TargetType.Ship && Type == Sector.Name.Ship)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
using QSB.Player;
|
||||
using QSB.SectorSync;
|
||||
using QSB.Syncs.RigidbodySync;
|
||||
using QSB.Syncs.TransformSync;
|
||||
using QSB.Utility;
|
||||
@ -9,8 +11,6 @@ namespace QSB.ShipSync.TransformSync
|
||||
{
|
||||
public static ShipTransformSync LocalInstance { get; private set; }
|
||||
|
||||
public override bool UseInterpolation => true;
|
||||
|
||||
public override bool IsReady
|
||||
=> Locator.GetShipBody() != null;
|
||||
|
||||
@ -23,8 +23,29 @@ namespace QSB.ShipSync.TransformSync
|
||||
|
||||
protected override OWRigidbody GetRigidbody()
|
||||
{
|
||||
SectorSync.SetSectorDetector(Locator.GetShipDetector().GetComponent<SectorDetector>());
|
||||
SectorSync.Init(Locator.GetShipDetector().GetComponent<SectorDetector>(), this);
|
||||
return Locator.GetShipBody();
|
||||
}
|
||||
|
||||
protected override void UpdateTransform()
|
||||
{
|
||||
if (HasAuthority && ShipManager.Instance.CurrentFlyer != QSBPlayerManager.LocalPlayerId)
|
||||
{
|
||||
DebugLog.DebugWrite($"Warning - Local player has ship authority, but is not the current flyer!", OWML.Common.MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!HasAuthority && ShipManager.Instance.CurrentFlyer == QSBPlayerManager.LocalPlayerId)
|
||||
{
|
||||
DebugLog.DebugWrite($"Warning - Local player does not have ship authority, but is the current flyer!", OWML.Common.MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
base.UpdateTransform();
|
||||
}
|
||||
|
||||
public override TargetType Type => TargetType.Ship;
|
||||
|
||||
public override bool UseInterpolation => true;
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using QSB.SectorSync.WorldObjects;
|
||||
using QSB.SectorSync;
|
||||
using QSB.SectorSync.WorldObjects;
|
||||
|
||||
namespace QSB.Syncs
|
||||
{
|
||||
@ -6,6 +7,7 @@ namespace QSB.Syncs
|
||||
{
|
||||
SectorSync.SectorSync SectorSync { get; }
|
||||
QSBSector ReferenceSector { get; }
|
||||
TargetType Type { get; }
|
||||
|
||||
void SetReferenceSector(QSBSector sector);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ namespace QSB.Syncs.RigidbodySync
|
||||
public QSBSector ReferenceSector { get; set; }
|
||||
public SectorSync.SectorSync SectorSync { get; private set; }
|
||||
public static List<SectoredRigidbodySync> SectoredNetworkTransformList = new List<SectoredRigidbodySync>();
|
||||
public abstract TargetType Type { get; }
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
|
@ -1,12 +1,7 @@
|
||||
using OWML.Common;
|
||||
using QSB.Syncs.TransformSync;
|
||||
using QSB.Utility;
|
||||
using QuantumUNET.Components;
|
||||
using QuantumUNET.Transport;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Syncs.RigidbodySync
|
||||
@ -23,6 +18,8 @@ namespace QSB.Syncs.RigidbodySync
|
||||
protected IntermediaryTransform _intermediaryTransform;
|
||||
protected Vector3 _velocity;
|
||||
protected Vector3 _angularVelocity;
|
||||
protected Vector3 _prevVelocity;
|
||||
protected Vector3 _prevAngularVelocity;
|
||||
private string _logName => $"{NetId}:{GetType().Name}";
|
||||
|
||||
protected abstract OWRigidbody GetRigidbody();
|
||||
@ -90,6 +87,8 @@ namespace QSB.Syncs.RigidbodySync
|
||||
writer.Write(angularVelocity);
|
||||
_prevPosition = worldPos;
|
||||
_prevRotation = worldRot;
|
||||
_prevVelocity = velocity;
|
||||
_prevAngularVelocity = angularVelocity;
|
||||
}
|
||||
|
||||
public override void DeserializeTransform(QNetworkReader reader)
|
||||
@ -197,6 +196,33 @@ namespace QSB.Syncs.RigidbodySync
|
||||
_intermediaryTransform.SetReferenceTransform(transform);
|
||||
}
|
||||
|
||||
public override bool HasMoved()
|
||||
{
|
||||
var displacementMagnitude = (_intermediaryTransform.GetPosition() - _prevPosition).magnitude;
|
||||
|
||||
if (displacementMagnitude > 1E-03f)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (Quaternion.Angle(_intermediaryTransform.GetRotation(), _prevRotation) > 1E-03f)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var velocityChangeMagnitude = (_velocity - _prevVelocity).magnitude;
|
||||
var angularVelocityChangeMagnitude = (_angularVelocity - _prevAngularVelocity).magnitude;
|
||||
if (velocityChangeMagnitude > 1E-03f)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (angularVelocityChangeMagnitude > 1E-03f)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void OnRenderObject()
|
||||
{
|
||||
if (!QSBCore.WorldObjectsReady || !QSBCore.DebugMode || !QSBCore.ShowLinesInDebug || !IsReady)
|
||||
|
@ -12,6 +12,7 @@ namespace QSB.Syncs.TransformSync
|
||||
public QSBSector ReferenceSector { get; set; }
|
||||
public SectorSync.SectorSync SectorSync { get; private set; }
|
||||
public static List<SectoredTransformSync> SectoredNetworkTransformList = new List<SectoredTransformSync>();
|
||||
public abstract TargetType Type { get; }
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user