mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-01 03:32:38 +00:00
sync flames
This commit is contained in:
parent
1ee72ef973
commit
adf1945b75
@ -95,14 +95,14 @@ public class AnimationSync : PlayerSyncObject
|
||||
|
||||
private void InitAccelerationSync()
|
||||
{
|
||||
Player.JetpackAcceleration = GetComponent<ThrusterSync>();
|
||||
Player.JetpackAcceleration = GetComponent<JetpackAccelerationSync>();
|
||||
var thrusterModel = hasAuthority ? Locator.GetPlayerBody().GetComponent<ThrusterModel>() : null;
|
||||
Player.JetpackAcceleration.Init(thrusterModel);
|
||||
}
|
||||
|
||||
private void InitCrouchSync()
|
||||
{
|
||||
_crouchSync = GetComponent<CrouchSync>();
|
||||
_crouchSync = this.GetRequiredComponent<CrouchSync>();
|
||||
_crouchSync.Init(_playerController, VisibleAnimator);
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ using QSB.Utility.VariableSync;
|
||||
|
||||
namespace QSB.Animation.Player.Thrusters;
|
||||
|
||||
public class ThrusterSync : NetworkBehaviour
|
||||
public class JetpackAccelerationSync : NetworkBehaviour
|
||||
{
|
||||
public Vector3VariableSyncer AccelerationVariableSyncer;
|
||||
|
@ -33,7 +33,7 @@ internal abstract class RotatingElementsVariableSyncer<TWorldObject> : BaseVaria
|
||||
|
||||
protected abstract Transform[] RotatingElements { get; }
|
||||
|
||||
protected override bool HasChanged()
|
||||
public override bool HasChanged()
|
||||
{
|
||||
var rotatingElements = RotatingElements;
|
||||
Value ??= new Quaternion[rotatingElements.Length];
|
||||
|
@ -8,7 +8,7 @@ public partial class PlayerInfo
|
||||
{
|
||||
public bool Visible => IsLocalPlayer || _ditheringAnimator == null || _ditheringAnimator.FullyVisible;
|
||||
public AnimationSync AnimationSync { get; }
|
||||
public ThrusterSync JetpackAcceleration { get; set; }
|
||||
public JetpackAccelerationSync JetpackAcceleration { get; set; }
|
||||
internal QSBDitheringAnimator _ditheringAnimator;
|
||||
public DreamWorldSpawnAnimator DreamWorldSpawnAnimator { get; set; }
|
||||
}
|
||||
|
@ -20,11 +20,13 @@ using QSB.Patches;
|
||||
using QSB.Player;
|
||||
using QSB.Player.Messages;
|
||||
using QSB.Player.TransformSync;
|
||||
using QSB.ShipSync;
|
||||
using QSB.ShipSync.TransformSync;
|
||||
using QSB.Syncs.Occasional;
|
||||
using QSB.TimeSync;
|
||||
using QSB.Tools.ProbeTool.TransformSync;
|
||||
using QSB.Utility;
|
||||
using QSB.Utility.VariableSync;
|
||||
using QSB.WorldSync;
|
||||
using System;
|
||||
using System.Linq;
|
||||
@ -103,6 +105,9 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
|
||||
playerPrefab.GetRequiredComponent<NetworkIdentity>().SetValue("m_AssetId", 1.ToGuid().ToString("N"));
|
||||
|
||||
ShipPrefab = MakeNewNetworkObject(2, "NetworkShip", typeof(ShipTransformSync));
|
||||
var shipVector3Sync = ShipPrefab.AddComponent<Vector3VariableSyncer>();
|
||||
var shipThrustSync = ShipPrefab.AddComponent<ShipThrusterVariableSyncer>();
|
||||
shipThrustSync.AccelerationSyncer = shipVector3Sync;
|
||||
spawnPrefabs.Add(ShipPrefab);
|
||||
|
||||
_probePrefab = MakeNewNetworkObject(3, "NetworkProbe", typeof(PlayerProbeSync));
|
||||
|
@ -1,18 +1,25 @@
|
||||
using HarmonyLib;
|
||||
using QSB.Patches;
|
||||
using QSB.Player;
|
||||
using QSB.ShipSync.TransformSync;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.ShipSync.Patches;
|
||||
|
||||
internal class FlameWashPatches : QSBPatch
|
||||
[HarmonyPatch(typeof(ThrusterFlameController))]
|
||||
internal class ShipFlamePatches : QSBPatch
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(ThrusterFlameController), nameof(ThrusterFlameController.GetThrustFraction))]
|
||||
public static bool FlameThrustFraction(ThrusterFlameController __instance, ref float __result)
|
||||
[HarmonyPatch(nameof(ThrusterFlameController.GetThrustFraction))]
|
||||
public static bool GetThrustFraction(ThrusterFlameController __instance, ref float __result)
|
||||
{
|
||||
if (!ShipThrusterManager.ShipFlameControllers.Contains(__instance))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!__instance._thrusterModel.IsThrusterBankEnabled(OWUtilities.GetShipThrusterBank(__instance._thruster)))
|
||||
{
|
||||
__result = 0f;
|
||||
@ -25,10 +32,9 @@ internal class FlameWashPatches : QSBPatch
|
||||
}
|
||||
else
|
||||
{
|
||||
__instance.OnStartTranslationalThrust();
|
||||
__result = Vector3.Dot(ShipManager.Instance.ShipThrusterSync.AccelerationVariableSyncer.Value, __instance._thrusterFilter);
|
||||
__result = Vector3.Dot(ShipTransformSync.LocalInstance.ThrusterVariableSyncer.AccelerationSyncer.Value, __instance._thrusterFilter);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -28,7 +28,6 @@ internal class ShipManager : WorldObjectManager
|
||||
public ShipCockpitController CockpitController;
|
||||
public ShipElectricalComponent ShipElectricalComponent;
|
||||
public ShipCockpitUI ShipCockpitUI;
|
||||
public ThrusterSync ShipThrusterSync;
|
||||
private GameObject _shipCustomAttach;
|
||||
public uint CurrentFlyer
|
||||
{
|
||||
|
48
QSB/ShipSync/ShipThrusterVariableSyncer.cs
Normal file
48
QSB/ShipSync/ShipThrusterVariableSyncer.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using Mirror;
|
||||
using QSB.Player;
|
||||
using QSB.Utility.VariableSync;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.ShipSync;
|
||||
|
||||
public class ShipThrusterVariableSyncer : NetworkBehaviour
|
||||
{
|
||||
public Vector3VariableSyncer AccelerationSyncer;
|
||||
|
||||
private ShipThrusterModel _thrusterModel;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
_thrusterModel = Locator.GetShipBody().GetComponent<ShipThrusterModel>();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (QSBPlayerManager.LocalPlayer.FlyingShip)
|
||||
{
|
||||
GetFromShip();
|
||||
return;
|
||||
}
|
||||
|
||||
if (AccelerationSyncer.HasChanged())
|
||||
{
|
||||
if (AccelerationSyncer.Value == Vector3.zero)
|
||||
{
|
||||
foreach (var item in ShipThrusterManager.ShipFlameControllers)
|
||||
{
|
||||
item.OnStopTranslationalThrust();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var item in ShipThrusterManager.ShipFlameControllers)
|
||||
{
|
||||
item.OnStartTranslationalThrust();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GetFromShip() => AccelerationSyncer.Value = _thrusterModel.GetLocalAcceleration();
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ public class ShipTransformSync : SectoredRigidbodySync
|
||||
{
|
||||
public static ShipTransformSync LocalInstance { get; private set; }
|
||||
|
||||
public ShipThrusterVariableSyncer ThrusterVariableSyncer { get; private set; }
|
||||
|
||||
private float _lastSetPositionTime;
|
||||
private const float ForcePositionAfterTime = 1;
|
||||
|
||||
@ -32,8 +34,8 @@ public class ShipTransformSync : SectoredRigidbodySync
|
||||
{
|
||||
base.Init();
|
||||
|
||||
ShipManager.Instance.ShipThrusterSync = gameObject.GetAddComponent<ThrusterSync>();
|
||||
ShipManager.Instance.ShipThrusterSync.Init(Locator.GetShipBody().GetComponent<ShipThrusterModel>());
|
||||
ThrusterVariableSyncer = this.GetRequiredComponent<ShipThrusterVariableSyncer>();
|
||||
ThrusterVariableSyncer.Init();
|
||||
|
||||
ShipThrusterManager.CreateShipVFX();
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class QSBNetworkTransform : QSBNetworkBehaviour
|
||||
private Vector3 _prevPosition;
|
||||
private Quaternion _prevRotation;
|
||||
|
||||
protected override bool HasChanged() =>
|
||||
public override bool HasChanged() =>
|
||||
Vector3.Distance(transform.position, _prevPosition) > PositionChangeThreshold ||
|
||||
Quaternion.Angle(transform.rotation, _prevRotation) > RotationChangeThreshold;
|
||||
|
||||
|
@ -16,7 +16,7 @@ public class QSBNetworkTransformChild : QSBNetworkBehaviour
|
||||
private Vector3 _prevPosition;
|
||||
private Quaternion _prevRotation;
|
||||
|
||||
protected override bool HasChanged() =>
|
||||
public override bool HasChanged() =>
|
||||
Vector3.Distance(Target.localPosition, _prevPosition) > PositionChangeThreshold ||
|
||||
Quaternion.Angle(Target.localRotation, _prevRotation) > RotationChangeThreshold;
|
||||
|
||||
|
@ -36,7 +36,7 @@ public abstract class SectoredRigidbodySync : BaseSectoredSync
|
||||
ReferenceRigidbody = ReferenceTransform ? ReferenceTransform.GetAttachedOWRigidbody() : null;
|
||||
}
|
||||
|
||||
protected override bool HasChanged() =>
|
||||
public override bool HasChanged() =>
|
||||
base.HasChanged() ||
|
||||
Vector3.Distance(Velocity, _prevVelocity) > VelocityChangeThreshold ||
|
||||
Vector3.Distance(AngularVelocity, _prevAngularVelocity) > AngularVelocityChangeThreshold;
|
||||
|
@ -198,7 +198,7 @@ public abstract class SyncBase : QSBNetworkTransform
|
||||
/// <summary>
|
||||
/// call the base method FIRST
|
||||
/// </summary>
|
||||
protected override bool HasChanged()
|
||||
public override bool HasChanged()
|
||||
{
|
||||
GetFromAttached();
|
||||
if (UseInterpolation)
|
||||
|
@ -36,7 +36,7 @@ public abstract class UnsectoredRigidbodySync : BaseUnsectoredSync
|
||||
ReferenceRigidbody = ReferenceTransform ? ReferenceTransform.GetAttachedOWRigidbody() : null;
|
||||
}
|
||||
|
||||
protected override bool HasChanged() =>
|
||||
public override bool HasChanged() =>
|
||||
base.HasChanged() ||
|
||||
Vector3.Distance(Velocity, _prevVelocity) > VelocityChangeThreshold ||
|
||||
Vector3.Distance(AngularVelocity, _prevAngularVelocity) > AngularVelocityChangeThreshold;
|
||||
|
@ -23,7 +23,7 @@ public abstract class QSBNetworkBehaviour : NetworkBehaviour
|
||||
/// <summary>
|
||||
/// checked before serializing
|
||||
/// </summary>
|
||||
protected abstract bool HasChanged();
|
||||
public abstract bool HasChanged();
|
||||
|
||||
protected abstract void Serialize(NetworkWriter writer);
|
||||
|
||||
|
@ -12,7 +12,7 @@ public abstract class BaseVariableSyncer<T> : QSBNetworkBehaviour
|
||||
[NonSerialized]
|
||||
public T Value;
|
||||
|
||||
protected override bool HasChanged() => !EqualityComparer<T>.Default.Equals(PrevValue, Value);
|
||||
public override bool HasChanged() => !EqualityComparer<T>.Default.Equals(PrevValue, Value);
|
||||
protected override void UpdatePrevData() => PrevValue = Value;
|
||||
protected override void Serialize(NetworkWriter writer) => writer.Write(Value);
|
||||
protected override void Deserialize(NetworkReader reader) => Value = reader.Read<T>();
|
||||
|
Loading…
Reference in New Issue
Block a user