mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-03-30 13:20:13 +00:00
i dont even know anymore
This commit is contained in:
parent
47968d71e8
commit
d79a716d4e
@ -15,18 +15,16 @@ namespace QSB.Animation.Player
|
||||
|
||||
private PlayerCharacterController _playerController;
|
||||
private Animator _bodyAnim;
|
||||
private VariableReference<float> _crouchValueReference;
|
||||
|
||||
public FloatVariableSyncer CrouchVariableSyncer;
|
||||
public float CrouchValue;
|
||||
public float CrouchValue = 0f;
|
||||
|
||||
public void Init(PlayerCharacterController playerController, Animator bodyAnim)
|
||||
{
|
||||
_playerController = playerController;
|
||||
_bodyAnim = bodyAnim;
|
||||
|
||||
_crouchValueReference = new VariableReference<float>(() => CrouchValue, val => CrouchValue = val);
|
||||
CrouchVariableSyncer.FloatToSync = _crouchValueReference;
|
||||
CrouchVariableSyncer.Init(() => CrouchValue, val => CrouchValue = val);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
@ -48,7 +46,7 @@ namespace QSB.Animation.Player
|
||||
}
|
||||
|
||||
var jumpChargeFraction = _playerController.GetJumpCrouchFraction();
|
||||
_crouchValueReference.Value = jumpChargeFraction;
|
||||
CrouchVariableSyncer.ValueToSync.Value = jumpChargeFraction;
|
||||
}
|
||||
|
||||
private void SyncRemoteCrouch()
|
||||
|
@ -8,11 +8,9 @@ namespace QSB.Animation.Player.Thrusters
|
||||
{
|
||||
public Vector3VariableSyncer AccelerationVariableSyncer;
|
||||
public BoolVariableSyncer ThrustingVariableSyncer;
|
||||
public Vector3 LocalAcceleration => _accelerationValueReference.Value;
|
||||
public bool IsThrusting => _thrustingValueReference.Value;
|
||||
public Vector3 LocalAcceleration => AccelerationVariableSyncer.ValueToSync.Value;
|
||||
public bool IsThrusting => ThrustingVariableSyncer.ValueToSync.Value;
|
||||
|
||||
private VariableReference<Vector3> _accelerationValueReference;
|
||||
private VariableReference<bool> _thrustingValueReference;
|
||||
private Vector3 _localAcceleration;
|
||||
private bool _isThrusting;
|
||||
private ThrusterModel _thrusterModel;
|
||||
@ -21,11 +19,8 @@ namespace QSB.Animation.Player.Thrusters
|
||||
{
|
||||
_thrusterModel = model;
|
||||
|
||||
_accelerationValueReference = new VariableReference<Vector3>(() => _localAcceleration, val => _localAcceleration = val);
|
||||
AccelerationVariableSyncer.FloatToSync = _accelerationValueReference;
|
||||
|
||||
_thrustingValueReference = new VariableReference<bool>(() => _isThrusting, val => _isThrusting = val);
|
||||
ThrustingVariableSyncer.FloatToSync = _thrustingValueReference;
|
||||
AccelerationVariableSyncer.Init(() => _localAcceleration, val => _localAcceleration = val);
|
||||
ThrustingVariableSyncer.Init(() => _isThrusting, val => _isThrusting = val);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
@ -40,8 +35,8 @@ namespace QSB.Animation.Player.Thrusters
|
||||
{
|
||||
if (_thrusterModel != null)
|
||||
{
|
||||
_accelerationValueReference.Value = _thrusterModel.GetLocalAcceleration();
|
||||
_thrustingValueReference.Value = _thrusterModel.IsTranslationalThrusterFiring();
|
||||
AccelerationVariableSyncer.ValueToSync.Value = _thrusterModel.GetLocalAcceleration();
|
||||
ThrustingVariableSyncer.ValueToSync.Value = _thrusterModel.IsTranslationalThrusterFiring();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,12 +11,13 @@ namespace QSB.Utility.VariableSync
|
||||
{
|
||||
private float _lastClientSendTime;
|
||||
private QNetworkWriter _writer;
|
||||
private int _index;
|
||||
protected bool _ready;
|
||||
|
||||
public abstract bool HasChanged();
|
||||
public abstract void WriteData(QNetworkWriter writer);
|
||||
public abstract void ReadData(QNetworkReader writer);
|
||||
|
||||
public void Awake()
|
||||
public virtual void Awake()
|
||||
{
|
||||
QNetworkServer.instance.m_SimpleServerSimple.RegisterHandlerSafe((short)QSB.Events.EventType.VariableSync, HandleVariable);
|
||||
|
||||
@ -26,6 +27,9 @@ namespace QSB.Utility.VariableSync
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Start()
|
||||
=> _index = GetComponents<BaseVariableSyncer>().ToList().IndexOf(this);
|
||||
|
||||
public override bool OnSerialize(QNetworkWriter writer, bool initialState)
|
||||
{
|
||||
if (!initialState)
|
||||
@ -58,12 +62,12 @@ namespace QSB.Utility.VariableSync
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (!IsServer || SyncVarDirtyBits != 0U || !QNetworkServer.active)
|
||||
if (!IsServer || SyncVarDirtyBits != 0U || !QNetworkServer.active || !_ready)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetNetworkSendInterval() != 0f && HasChanged())
|
||||
if (GetNetworkSendInterval() != 0f)
|
||||
{
|
||||
SetDirtyBit(1U);
|
||||
}
|
||||
@ -71,7 +75,7 @@ namespace QSB.Utility.VariableSync
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
if (!HasAuthority || !LocalPlayerAuthority || QNetworkServer.active)
|
||||
if (!HasAuthority || !LocalPlayerAuthority || QNetworkServer.active || !_ready)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -86,12 +90,12 @@ namespace QSB.Utility.VariableSync
|
||||
[Client]
|
||||
private void SendVariable()
|
||||
{
|
||||
if (HasChanged() && QClientScene.readyConnection != null)
|
||||
// TODO - this sends a message, even when the value hasnt changed! this is really bad!
|
||||
if (QClientScene.readyConnection != null)
|
||||
{
|
||||
_writer.StartMessage((short)QSB.Events.EventType.VariableSync);
|
||||
_writer.Write(NetId);
|
||||
// OPTIMIZE - cache this
|
||||
_writer.Write(GetComponents<BaseVariableSyncer>().ToList().IndexOf(this));
|
||||
_writer.Write(_index);
|
||||
WriteData(_writer);
|
||||
_writer.FinishMessage();
|
||||
QClientScene.readyConnection.SendWriter(_writer, GetNetworkChannel());
|
||||
|
@ -1,39 +1,26 @@
|
||||
using QuantumUNET.Transport;
|
||||
using System;
|
||||
|
||||
namespace QSB.Utility.VariableSync
|
||||
{
|
||||
public class BoolVariableSyncer : BaseVariableSyncer
|
||||
{
|
||||
public VariableReference<bool> FloatToSync;
|
||||
public VariableReference<bool> ValueToSync { get; private set; } = new();
|
||||
|
||||
public void Init(Func<bool> getter, Action<bool> setter)
|
||||
{
|
||||
ValueToSync.Getter = getter;
|
||||
ValueToSync.Setter = setter;
|
||||
_ready = true;
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
=> _ready = false;
|
||||
|
||||
public override void WriteData(QNetworkWriter writer)
|
||||
{
|
||||
if (FloatToSync == null)
|
||||
{
|
||||
writer.Write(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(FloatToSync.Value);
|
||||
}
|
||||
}
|
||||
=> writer.Write(ValueToSync.Value);
|
||||
|
||||
public override void ReadData(QNetworkReader writer)
|
||||
{
|
||||
if (FloatToSync == null)
|
||||
{
|
||||
writer.ReadBoolean();
|
||||
}
|
||||
else
|
||||
{
|
||||
FloatToSync.Value = writer.ReadBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasChanged()
|
||||
{
|
||||
// TODO - do this!!
|
||||
return true;
|
||||
}
|
||||
=> ValueToSync.Value = writer.ReadBoolean();
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +1,26 @@
|
||||
using QuantumUNET.Transport;
|
||||
using System;
|
||||
|
||||
namespace QSB.Utility.VariableSync
|
||||
{
|
||||
public class FloatVariableSyncer : BaseVariableSyncer
|
||||
{
|
||||
public VariableReference<float> FloatToSync;
|
||||
public VariableReference<float> ValueToSync { get; private set; } = new();
|
||||
|
||||
public void Init(Func<float> getter, Action<float> setter)
|
||||
{
|
||||
ValueToSync.Getter = getter;
|
||||
ValueToSync.Setter = setter;
|
||||
_ready = true;
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
=> _ready = false;
|
||||
|
||||
public override void WriteData(QNetworkWriter writer)
|
||||
{
|
||||
if (FloatToSync == null)
|
||||
{
|
||||
writer.Write(0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(FloatToSync.Value);
|
||||
}
|
||||
}
|
||||
=> writer.Write(ValueToSync.Value);
|
||||
|
||||
public override void ReadData(QNetworkReader writer)
|
||||
{
|
||||
if (FloatToSync == null)
|
||||
{
|
||||
writer.ReadSingle();
|
||||
}
|
||||
else
|
||||
{
|
||||
FloatToSync.Value = writer.ReadSingle();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasChanged()
|
||||
{
|
||||
// TODO - do this!!
|
||||
return true;
|
||||
}
|
||||
=> ValueToSync.Value = writer.ReadSingle();
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,45 @@
|
||||
using System;
|
||||
using QSB.Player;
|
||||
using System;
|
||||
|
||||
namespace QSB.Utility.VariableSync
|
||||
{
|
||||
public class VariableReference<T>
|
||||
{
|
||||
private Func<T> _getter;
|
||||
private Action<T> _setter;
|
||||
|
||||
public VariableReference(Func<T> getter, Action<T> setter)
|
||||
{
|
||||
_getter = getter;
|
||||
_setter = setter;
|
||||
}
|
||||
public Func<T> Getter;
|
||||
public Action<T> Setter;
|
||||
|
||||
public T Value
|
||||
{
|
||||
get => _getter();
|
||||
set => _setter(value);
|
||||
get
|
||||
{
|
||||
if (Getter != null)
|
||||
{
|
||||
return Getter();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (QSBPlayerManager.LocalPlayer.IsReady)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Getter is null!", OWML.Common.MessageType.Warning);
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (Setter != null)
|
||||
{
|
||||
Setter(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (QSBPlayerManager.LocalPlayer.IsReady)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Setter is null!", OWML.Common.MessageType.Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,27 @@
|
||||
using QuantumUNET.Transport;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Utility.VariableSync
|
||||
{
|
||||
public class Vector3VariableSyncer : BaseVariableSyncer
|
||||
{
|
||||
public VariableReference<Vector3> FloatToSync;
|
||||
public VariableReference<Vector3> ValueToSync { get; private set; } = new();
|
||||
|
||||
public void Init(Func<Vector3> getter, Action<Vector3> setter)
|
||||
{
|
||||
ValueToSync.Getter = getter;
|
||||
ValueToSync.Setter = setter;
|
||||
_ready = true;
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
=> _ready = false;
|
||||
|
||||
public override void WriteData(QNetworkWriter writer)
|
||||
{
|
||||
if (FloatToSync == null)
|
||||
{
|
||||
writer.Write(Vector3.zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(FloatToSync.Value);
|
||||
}
|
||||
}
|
||||
=> writer.Write(ValueToSync.Value);
|
||||
|
||||
public override void ReadData(QNetworkReader writer)
|
||||
{
|
||||
if (FloatToSync == null)
|
||||
{
|
||||
writer.ReadVector3();
|
||||
}
|
||||
else
|
||||
{
|
||||
FloatToSync.Value = writer.ReadVector3();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasChanged()
|
||||
{
|
||||
// TODO - do this!!
|
||||
return true;
|
||||
}
|
||||
=> ValueToSync.Value = writer.ReadVector3();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user