mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-26 09:35:26 +00:00
Merge pull request #312 from misternebula/sync-redux
Rewrite sync stuff (and ship position sync)
This commit is contained in:
commit
3e5b0f13ad
@ -12,7 +12,7 @@ namespace QSB.Animation.NPC
|
||||
QSBWorldSync.Init<QSBCharacterAnimController, CharacterAnimController>();
|
||||
QSBWorldSync.Init<QSBTravelerController, TravelerController>();
|
||||
|
||||
//TODO : this is the wrong place to put this... move it to Conversations?
|
||||
//MOVE : this is the wrong place to put this... move it to Conversations?
|
||||
QSBWorldSync.OldDialogueTrees.Clear();
|
||||
QSBWorldSync.OldDialogueTrees = Resources.FindObjectsOfTypeAll<CharacterDialogueTree>().ToList();
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ namespace QSB.Animation.NPC.Patches
|
||||
|
||||
var playerId = ConversationManager.Instance.GetPlayerTalkingToTree(____dialogueTree);
|
||||
var player = QSBPlayerManager.GetPlayer(playerId);
|
||||
var qsbObj = QSBWorldSync.GetWorldFromUnity<QSBCharacterAnimController, CharacterAnimController>(__instance); // TODO : maybe cache this somewhere... or assess how slow this is
|
||||
var qsbObj = QSBWorldSync.GetWorldFromUnity<QSBCharacterAnimController, CharacterAnimController>(__instance); // OPTIMIZE : maybe cache this somewhere... or assess how slow this is
|
||||
|
||||
PlayerInfo playerToUse = null;
|
||||
if (____inConversation)
|
||||
@ -63,7 +63,7 @@ namespace QSB.Animation.NPC.Patches
|
||||
: player;
|
||||
}
|
||||
}
|
||||
else if (!___lookOnlyWhenTalking && qsbObj.GetPlayersInHeadZone().Count != 0) // TODO : maybe this would be more fun if characters looked between players at random times? :P
|
||||
else if (!___lookOnlyWhenTalking && qsbObj.GetPlayersInHeadZone().Count != 0) // IDEA : maybe this would be more fun if characters looked between players at random times? :P
|
||||
{
|
||||
playerToUse = QSBPlayerManager.GetClosestPlayerToWorldPoint(qsbObj.GetPlayersInHeadZone(), __instance.transform.position);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace QSB.ClientServerStateSync
|
||||
public event ChangeStateEvent OnChangeState;
|
||||
public delegate void ChangeStateEvent(ClientState newState);
|
||||
|
||||
private void Awake()
|
||||
private void Awake()
|
||||
=> Instance = this;
|
||||
|
||||
private void Start()
|
||||
@ -28,6 +28,7 @@ namespace QSB.ClientServerStateSync
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DebugLog.DebugWrite($"CHANGE CLIENT STATE FROM {QSBPlayerManager.LocalPlayer.State} to {newState}");
|
||||
QSBPlayerManager.LocalPlayer.State = newState;
|
||||
OnChangeState?.Invoke(newState);
|
||||
@ -78,7 +79,7 @@ namespace QSB.ClientServerStateSync
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void OnDeath()
|
||||
{
|
||||
var currentScene = QSBSceneManager.CurrentScene;
|
||||
|
@ -34,6 +34,7 @@ namespace QSB.ClientServerStateSync.Events
|
||||
DebugLog.DebugWrite($"Error - ID is uint.MaxValue!", OWML.Common.MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var player = QSBPlayerManager.GetPlayer(message.AboutId);
|
||||
player.State = message.EnumValue;
|
||||
}
|
||||
|
@ -21,10 +21,10 @@ namespace QSB.ClientServerStateSync.Events
|
||||
EnumValue = state
|
||||
};
|
||||
|
||||
public override void OnReceiveLocal(bool server, EnumMessage<ServerState> message)
|
||||
public override void OnReceiveLocal(bool server, EnumMessage<ServerState> message)
|
||||
=> OnReceiveRemote(server, message);
|
||||
|
||||
public override void OnReceiveRemote(bool server, EnumMessage<ServerState> message)
|
||||
public override void OnReceiveRemote(bool server, EnumMessage<ServerState> message)
|
||||
=> ServerStateManager.Instance.ChangeServerState(message.EnumValue);
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace QSB.ClientServerStateSync
|
||||
|
||||
private ServerState _currentState;
|
||||
|
||||
private void Awake()
|
||||
private void Awake()
|
||||
=> Instance = this;
|
||||
|
||||
private void Start()
|
||||
@ -25,6 +25,7 @@ namespace QSB.ClientServerStateSync
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
|
||||
GlobalMessenger.AddListener("TriggerSupernova", OnTriggerSupernova);
|
||||
|
||||
@ -37,12 +38,13 @@ namespace QSB.ClientServerStateSync
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DebugLog.DebugWrite($"CHANGE SERVER STATE FROM {_currentState} to {newState}");
|
||||
_currentState = newState;
|
||||
OnChangeState?.Invoke(newState);
|
||||
}
|
||||
|
||||
public ServerState GetServerState()
|
||||
public ServerState GetServerState()
|
||||
=> _currentState;
|
||||
|
||||
private void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool inUniverse)
|
||||
@ -68,6 +70,7 @@ namespace QSB.ClientServerStateSync
|
||||
{
|
||||
QSBEventManager.FireEvent(EventNames.QSBServerState, ServerState.InSolarSystem);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case OWScene.EyeOfTheUniverse:
|
||||
|
@ -23,7 +23,7 @@ namespace QSB.ConversationSync
|
||||
Instance = this;
|
||||
|
||||
_boxPrefab = QSBCore.ConversationAssetBundle.LoadAsset<GameObject>("assets/dialoguebubble.prefab");
|
||||
// TODO : make dynamic so it can be different sizes!
|
||||
// BUG : make dynamic so it can be different sizes!
|
||||
// the dynamic font seems to be super lo-res at this size...?
|
||||
var font = (Font)Resources.Load(@"fonts\english - latin\spacemono-bold");
|
||||
if (font == null)
|
||||
|
@ -20,7 +20,7 @@ namespace QSB.DeathSync.Events
|
||||
EnumValue = type
|
||||
};
|
||||
|
||||
public override void OnReceiveLocal(bool server, EnumMessage<EndLoopReason> message)
|
||||
public override void OnReceiveLocal(bool server, EnumMessage<EndLoopReason> message)
|
||||
=> OnReceiveRemote(server, message);
|
||||
|
||||
public override void OnReceiveRemote(bool server, EnumMessage<EndLoopReason> message)
|
||||
@ -34,6 +34,7 @@ namespace QSB.DeathSync.Events
|
||||
{
|
||||
QSBEventManager.FireEvent(EventNames.QSBServerState, ServerState.WaitingForDeath);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ namespace QSB.DeathSync
|
||||
private Vector3 _deathPositionRelative;
|
||||
|
||||
public Transform DeathClosestAstroObject { get; private set; }
|
||||
public Vector3 DeathPositionWorld
|
||||
public Vector3 DeathPositionWorld
|
||||
=> DeathClosestAstroObject == null
|
||||
? Vector3.zero
|
||||
: DeathClosestAstroObject.TransformPoint(_deathPositionRelative);
|
||||
|
@ -84,9 +84,17 @@ namespace QSB.OrbSync.Events
|
||||
return;
|
||||
}
|
||||
|
||||
if (orbIdentity.ClientAuthorityOwner != null && orbIdentity.ClientAuthorityOwner != fromPlayer)
|
||||
var currentOwner = orbIdentity.ClientAuthorityOwner;
|
||||
var newOwner = fromPlayer;
|
||||
|
||||
if (currentOwner == newOwner)
|
||||
{
|
||||
orbIdentity.RemoveClientAuthority(orbIdentity.ClientAuthorityOwner);
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentOwner != null && currentOwner != fromPlayer)
|
||||
{
|
||||
orbIdentity.RemoveClientAuthority(currentOwner);
|
||||
}
|
||||
|
||||
orbIdentity.AssignClientAuthority(fromPlayer);
|
||||
|
@ -26,7 +26,10 @@ namespace QSB.OrbSync
|
||||
{
|
||||
NomaiOrbTransformSync.OrbTransformSyncs.ForEach(x => QNetworkServer.Destroy(x.gameObject));
|
||||
NomaiOrbTransformSync.OrbTransformSyncs.Clear();
|
||||
QSBWorldSync.OldOrbList.ForEach(x => QNetworkServer.Spawn(Instantiate(QSBNetworkManager.Instance.OrbPrefab)));
|
||||
foreach (var orb in QSBWorldSync.OldOrbList)
|
||||
{
|
||||
Instantiate(QSBNetworkManager.Instance.OrbPrefab).SpawnWithServerAuthority();
|
||||
}
|
||||
}
|
||||
|
||||
DebugLog.DebugWrite($"Finished orb build with {QSBWorldSync.OldOrbList.Count} orbs.", MessageType.Success);
|
||||
|
@ -1,4 +1,4 @@
|
||||
using QSB.Syncs.TransformSync;
|
||||
using QSB.Syncs.Unsectored.Transforms;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System.Collections.Generic;
|
||||
@ -6,7 +6,7 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.OrbSync.TransformSync
|
||||
{
|
||||
internal class NomaiOrbTransformSync : UnparentedBaseTransformSync
|
||||
internal class NomaiOrbTransformSync : UnsectoredTransformSync
|
||||
{
|
||||
public static List<NomaiOrbTransformSync> OrbTransformSyncs = new List<NomaiOrbTransformSync>();
|
||||
|
||||
@ -17,7 +17,7 @@ namespace QSB.OrbSync.TransformSync
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
OrbTransformSyncs.Remove(this);
|
||||
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
|
||||
base.OnDestroy();
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
@ -59,6 +59,7 @@ namespace QSB.OrbSync.TransformSync
|
||||
protected override Component InitLocalTransform() => GetTransform();
|
||||
protected override Component InitRemoteTransform() => GetTransform();
|
||||
|
||||
protected override float DistanceLeeway => 1f;
|
||||
public override bool IsReady => QSBCore.WorldObjectsReady;
|
||||
public override bool UseInterpolation => false;
|
||||
}
|
||||
|
@ -35,15 +35,15 @@ namespace QSB.Patches
|
||||
_patchedMethods.Add(method);
|
||||
}
|
||||
|
||||
public void Prefix(string patchName)
|
||||
=> DoPrefixPostfix(true, patchName);
|
||||
public void Prefix(string patchName, params Type[] args)
|
||||
=> DoPrefixPostfix(true, patchName, args);
|
||||
|
||||
public void Postfix(string patchName)
|
||||
=> DoPrefixPostfix(false, patchName);
|
||||
public void Postfix(string patchName, params Type[] args)
|
||||
=> DoPrefixPostfix(false, patchName, args);
|
||||
|
||||
private void DoPrefixPostfix(bool isPrefix, string patchName)
|
||||
private void DoPrefixPostfix(bool isPrefix, string patchName, params Type[] args)
|
||||
{
|
||||
var method = GetMethodInfo(patchName);
|
||||
var method = GetMethodInfo(patchName, args);
|
||||
|
||||
if (method != null)
|
||||
{
|
||||
@ -62,7 +62,7 @@ namespace QSB.Patches
|
||||
//DebugLog.DebugWrite($"{(isPrefix ? "[Prefix]" : "[Postfix]")} {patchName}", method == null ? MessageType.Error : MessageType.Success);
|
||||
}
|
||||
|
||||
private MethodInfo GetMethodInfo(string patchName)
|
||||
private MethodInfo GetMethodInfo(string patchName, params Type[] args)
|
||||
{
|
||||
var splitName = patchName.Split('_');
|
||||
var typeName = splitName[0];
|
||||
@ -75,14 +75,42 @@ namespace QSB.Patches
|
||||
return null;
|
||||
}
|
||||
|
||||
var method = type.GetAnyMethod(methodName);
|
||||
if (method == null)
|
||||
var allMethodsOfName = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy).Where(x => x.Name == methodName);
|
||||
|
||||
if (allMethodsOfName.Count() == 0)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - Couldn't find method for patch name {patchName}!", MessageType.Error);
|
||||
DebugLog.ToConsole($"Error - Could not find method {methodName} in type {typeName}.", MessageType.Error);
|
||||
return null;
|
||||
}
|
||||
|
||||
return method;
|
||||
if (allMethodsOfName.Count() == 1)
|
||||
{
|
||||
return allMethodsOfName.First();
|
||||
}
|
||||
|
||||
DebugLog.DebugWrite($"More than one method found with name {methodName} in type {typeName}");
|
||||
|
||||
foreach (var method in allMethodsOfName)
|
||||
{
|
||||
DebugLog.DebugWrite($"checking {method.Name}");
|
||||
var paramList = method.GetParameters().Select(x => x.ParameterType);
|
||||
if (Enumerable.SequenceEqual(args, paramList))
|
||||
{
|
||||
DebugLog.DebugWrite($"match!");
|
||||
return method;
|
||||
}
|
||||
}
|
||||
|
||||
DebugLog.DebugWrite($"nothing found");
|
||||
|
||||
DebugLog.ToConsole($"Error - Could not find method {methodName} in type {typeName} with parameter list of {string.Join(", ", args.Select(x => x.FullName).ToArray())}", MessageType.Error);
|
||||
foreach (var method in allMethodsOfName)
|
||||
{
|
||||
var paramList = method.GetParameters().Select(x => x.ParameterType);
|
||||
DebugLog.ToConsole($"- Found {method.Name}, but with params {string.Join(", ", paramList.Select(x => x.FullName).ToArray())}", MessageType.Error);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Type GetFirstTypeByName(string typeName)
|
||||
|
@ -30,6 +30,7 @@ namespace QSB.Player.Events
|
||||
DebugLog.ToConsole($"Error - Client {message.PlayerName} connecting with wrong QSB version. (Client:{message.QSBVersion}, Server:{QSBCore.QSBVersion})", MessageType.Error);
|
||||
QSBEventManager.FireEvent(EventNames.QSBPlayerKick, message.AboutId, KickReason.QSBVersionNotMatching);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -40,6 +41,7 @@ namespace QSB.Player.Events
|
||||
DebugLog.ToConsole($"Error - Client {message.PlayerName} connecting with wrong game version. (Client:{message.GameVersion}, Server:{QSBCore.GameVersion})", MessageType.Error);
|
||||
QSBEventManager.FireEvent(EventNames.QSBPlayerKick, message.AboutId, KickReason.GameVersionNotMatching);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ namespace QSB.Player
|
||||
// Tools
|
||||
public GameObject ProbeBody { get; set; }
|
||||
public QSBProbe Probe { get; set; }
|
||||
public QSBFlashlight FlashLight
|
||||
public QSBFlashlight FlashLight
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -66,8 +66,8 @@ namespace QSB.Player
|
||||
public JetpackAccelerationSync JetpackAcceleration { get; set; }
|
||||
|
||||
// Misc
|
||||
public bool IsInMoon; // TODO : move into PlayerStates?
|
||||
public bool IsInShrine; // TODO : move into PlayerStates?
|
||||
public bool IsInMoon; // MOVE : move into PlayerStates?
|
||||
public bool IsInShrine; // MOVE : move into PlayerStates?
|
||||
public IQSBQuantumObject EntangledObject;
|
||||
public bool IsDead { get; set; }
|
||||
public ClientState State { get; set; }
|
||||
@ -87,7 +87,7 @@ namespace QSB.Player
|
||||
}
|
||||
}
|
||||
|
||||
public Flashlight LocalFlashlight
|
||||
public Flashlight LocalFlashlight
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -129,7 +129,6 @@ namespace QSB.Player
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public PlayerInfo(uint id)
|
||||
{
|
||||
PlayerId = id;
|
||||
|
@ -91,6 +91,7 @@ namespace QSB.Player
|
||||
{
|
||||
player.UpdateStateObjects();
|
||||
}
|
||||
|
||||
player.State = message.ClientState;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ using QSB.Events;
|
||||
using QSB.Instruments;
|
||||
using QSB.RoastingSync;
|
||||
using QSB.SectorSync;
|
||||
using QSB.Syncs.TransformSync;
|
||||
using QSB.Syncs.Sectored.Transforms;
|
||||
using QSB.Tools;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
@ -86,7 +86,7 @@ namespace QSB.Player.TransformSync
|
||||
|
||||
protected override Component InitLocalTransform()
|
||||
{
|
||||
QSBCore.UnityEvents.RunWhen(() => WorldObjectManager.AllReady, () => SectorSync.Init(Locator.GetPlayerSectorDetector(), this));
|
||||
QSBCore.UnityEvents.RunWhen(() => WorldObjectManager.AllReady, () => SectorSync.Init(Locator.GetPlayerSectorDetector(), TargetType.Player));
|
||||
|
||||
// player body
|
||||
var player = Locator.GetPlayerTransform();
|
||||
@ -275,7 +275,5 @@ namespace QSB.Player.TransformSync
|
||||
public static PlayerTransformSync LocalInstance { get; private set; }
|
||||
|
||||
public override bool UseInterpolation => true;
|
||||
|
||||
public override TargetType Type => TargetType.Player;
|
||||
}
|
||||
}
|
@ -719,7 +719,7 @@ namespace QSB.PoolSync
|
||||
hologramCopy.GetChild(0).Find("player_mesh_noSuit:Traveller_HEA_Player/player_mesh_noSuit:Player_Head").gameObject.layer = 0;
|
||||
hologramCopy.GetChild(0).Find("Traveller_Mesh_v01:Traveller_Geo/Traveller_Mesh_v01:PlayerSuit_Helmet").gameObject.layer = 0;
|
||||
|
||||
// TODO : Look at this again... probably need to sync head rotation to something else
|
||||
// BUG : Look at this again... probably need to sync head rotation to something else
|
||||
//var ikSync = hologramCopy.GetChild(0).gameObject.AddComponent<PlayerHeadRotationSync>();
|
||||
//ikSync.Init(player.CameraBody.transform);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
using OWML.Common;
|
||||
using OWML.Utils;
|
||||
using QSB.SectorSync;
|
||||
using QSB.Syncs.TransformSync;
|
||||
using QSB.Syncs.Sectored.Transforms;
|
||||
using QSB.Tools;
|
||||
using QSB.Tools.ProbeLauncherTool;
|
||||
using QSB.Utility;
|
||||
@ -14,7 +14,6 @@ namespace QSB.ProbeSync.TransformSync
|
||||
{
|
||||
protected override float DistanceLeeway => 10f;
|
||||
public override bool UseInterpolation => true;
|
||||
public override TargetType Type => TargetType.Probe;
|
||||
public override bool IgnoreDisabledAttachedObject => true;
|
||||
|
||||
public static PlayerProbeSync LocalInstance { get; private set; }
|
||||
@ -23,7 +22,7 @@ namespace QSB.ProbeSync.TransformSync
|
||||
|
||||
protected override Component InitLocalTransform()
|
||||
{
|
||||
QSBCore.UnityEvents.RunWhen(() => WorldObjectManager.AllReady, () => SectorSync.Init(Locator.GetProbe().GetSectorDetector(), this));
|
||||
QSBCore.UnityEvents.RunWhen(() => WorldObjectManager.AllReady, () => SectorSync.Init(Locator.GetProbe().GetSectorDetector(), TargetType.Probe));
|
||||
|
||||
var body = Locator.GetProbe().transform;
|
||||
Player.ProbeBody = body.gameObject;
|
||||
@ -53,8 +52,8 @@ namespace QSB.ProbeSync.TransformSync
|
||||
return default;
|
||||
}
|
||||
|
||||
var body = probe.gameObject.activeSelf
|
||||
? probe.InstantiateInactive()
|
||||
var body = probe.gameObject.activeSelf
|
||||
? probe.InstantiateInactive()
|
||||
: Instantiate(probe);
|
||||
|
||||
body.name = "RemoteProbeTransform";
|
||||
|
@ -278,10 +278,13 @@
|
||||
<Compile Include="ShipSync\Events\RepairTickMessage.cs" />
|
||||
<Compile Include="ShipSync\WorldObjects\QSBShipComponent.cs" />
|
||||
<Compile Include="ShipSync\WorldObjects\QSBShipHull.cs" />
|
||||
<Compile Include="Syncs\ISectoredSync.cs" />
|
||||
<Compile Include="Syncs\RigidbodySync\BaseRigidbodySync.cs" />
|
||||
<Compile Include="Syncs\RigidbodySync\SectoredRigidbodySync.cs" />
|
||||
<Compile Include="Syncs\Sectored\BaseSectoredSync.cs" />
|
||||
<Compile Include="Syncs\Sectored\Rigidbodies\SectoredRigidbodySync.cs" />
|
||||
<Compile Include="Syncs\Sectored\Transforms\SectoredTransformSync.cs" />
|
||||
<Compile Include="Syncs\SyncBase.cs" />
|
||||
<Compile Include="Syncs\Unsectored\BaseUnsectoredSync.cs" />
|
||||
<Compile Include="Syncs\Unsectored\Rigidbodies\UnsectoredRigidbodySync.cs" />
|
||||
<Compile Include="Syncs\Unsectored\Transforms\UnsectoredTransformSync.cs" />
|
||||
<Compile Include="TimeSync\FastForwardReason.cs" />
|
||||
<Compile Include="TimeSync\Patches\TimePatches.cs" />
|
||||
<Compile Include="TimeSync\PauseReason.cs" />
|
||||
@ -309,10 +312,7 @@
|
||||
<Compile Include="StatueSync\Events\StartStatueMessage.cs" />
|
||||
<Compile Include="StatueSync\Patches\StatuePatches.cs" />
|
||||
<Compile Include="StatueSync\StatueManager.cs" />
|
||||
<Compile Include="Syncs\TransformSync\BaseTransformSync.cs" />
|
||||
<Compile Include="Syncs\IntermediaryTransform.cs" />
|
||||
<Compile Include="Syncs\TransformSync\SectoredTransformSync.cs" />
|
||||
<Compile Include="Syncs\TransformSync\UnparentedBaseTransformSync.cs" />
|
||||
<Compile Include="TranslationSync\Events\SetAsTranslatedEvent.cs" />
|
||||
<Compile Include="TranslationSync\Events\SetAsTranslatedMessage.cs" />
|
||||
<Compile Include="TranslationSync\NomaiTextType.cs" />
|
||||
|
@ -178,4 +178,5 @@ namespace QSB
|
||||
* Teleskärm
|
||||
* Daft Punk
|
||||
* Natalie Holt
|
||||
* WMD
|
||||
*/
|
@ -344,7 +344,7 @@ namespace QSB.QuantumSync.Patches
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO : make this *really* check for all players - check other probes and other jetpacks!
|
||||
// BUG : make this *really* check for all players - check other probes and other jetpacks!
|
||||
__result = ____gate.GetOpenFraction() == 0f
|
||||
&& !____isProbeInside
|
||||
&& Locator.GetThrusterLightTracker().GetLightRange() <= 0f;
|
||||
|
@ -83,14 +83,14 @@ namespace QSB.QuantumSync.Patches
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO : Implement checking for other probes!
|
||||
// BUG : Implement checking for other probes!
|
||||
if (Locator.GetProbe() != null && Locator.GetProbe().IsLaunched() && Locator.GetProbe().CheckIlluminationAtPoint(point, ____illuminationRadius))
|
||||
{
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO : Implement checking for other player's thrusters!
|
||||
// BUG : Implement checking for other player's thrusters!
|
||||
if (Locator.GetThrusterLightTracker().CheckIlluminationAtPoint(point, ____illuminationRadius))
|
||||
{
|
||||
__result = true;
|
||||
|
@ -1,6 +1,6 @@
|
||||
using OWML.Common;
|
||||
using QSB.SectorSync.WorldObjects;
|
||||
using QSB.Syncs;
|
||||
using QSB.Syncs.Sectored;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System.Collections.Generic;
|
||||
@ -18,8 +18,7 @@ namespace QSB.SectorSync
|
||||
private void OnEnable() => RepeatingManager.Repeatings.Add(this);
|
||||
private void OnDisable() => RepeatingManager.Repeatings.Remove(this);
|
||||
|
||||
public List<SyncBase> SectoredTransformSyncs = new List<SyncBase>();
|
||||
public List<SyncBase> SectoredRigidbodySyncs = new List<SyncBase>();
|
||||
public List<BaseSectoredSync> SectoredSyncs = new List<BaseSectoredSync>();
|
||||
|
||||
public void Invoke()
|
||||
{
|
||||
@ -28,7 +27,7 @@ namespace QSB.SectorSync
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var sync in SectoredTransformSyncs)
|
||||
foreach (var sync in SectoredSyncs)
|
||||
{
|
||||
if (sync.AttachedObject == null)
|
||||
{
|
||||
@ -39,22 +38,7 @@ namespace QSB.SectorSync
|
||||
&& sync.AttachedObject.gameObject.activeInHierarchy
|
||||
&& sync.IsReady)
|
||||
{
|
||||
CheckTransformSyncSector(sync as ISectoredSync<Transform>);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var sync in SectoredRigidbodySyncs)
|
||||
{
|
||||
if (sync.AttachedObject == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sync.HasAuthority
|
||||
&& sync.AttachedObject.gameObject.activeInHierarchy
|
||||
&& sync.IsReady)
|
||||
{
|
||||
CheckTransformSyncSector(sync as ISectoredSync<OWRigidbody>);
|
||||
CheckTransformSyncSector(sync);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -89,10 +73,9 @@ namespace QSB.SectorSync
|
||||
IsReady = QSBWorldSync.GetWorldObjects<QSBSector>().Any();
|
||||
}
|
||||
|
||||
private void CheckTransformSyncSector<T>(ISectoredSync<T> transformSync)
|
||||
where T : Component
|
||||
private void CheckTransformSyncSector(BaseSectoredSync transformSync)
|
||||
{
|
||||
var attachedObject = (transformSync as SyncBase).AttachedObject;
|
||||
var attachedObject = transformSync.AttachedObject;
|
||||
var closestSector = transformSync.SectorSync.GetClosestSector(attachedObject.transform);
|
||||
if (closestSector == default(QSBSector))
|
||||
{
|
||||
|
@ -1,7 +1,6 @@
|
||||
using OWML.Common;
|
||||
using OWML.Utils;
|
||||
using QSB.SectorSync.WorldObjects;
|
||||
using QSB.Syncs;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System;
|
||||
@ -27,10 +26,11 @@ namespace QSB.SectorSync
|
||||
_sectorDetector.OnEnterSector -= AddSector;
|
||||
_sectorDetector.OnExitSector -= RemoveSector;
|
||||
}
|
||||
|
||||
IsReady = false;
|
||||
}
|
||||
|
||||
public void Init<T>(SectorDetector detector, ISectoredSync<T> sectoredSync)
|
||||
public void Init(SectorDetector detector, TargetType type)
|
||||
{
|
||||
DebugLog.DebugWrite($"INIT SECTOR SYNC detector:{detector.name}");
|
||||
if (_sectorDetector != null)
|
||||
@ -57,7 +57,7 @@ namespace QSB.SectorSync
|
||||
|
||||
PopulateSectorList();
|
||||
|
||||
_targetType = sectoredSync.Type;
|
||||
_targetType = type;
|
||||
IsReady = true;
|
||||
}
|
||||
|
||||
|
@ -78,6 +78,7 @@ namespace QSB.ShipSync
|
||||
DebugLog.ToConsole($"Warning - ShipTransformSync's LocalInstance is not null, but it's gameobject is null!", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
QNetworkServer.Destroy(ShipTransformSync.LocalInstance.gameObject);
|
||||
}
|
||||
|
||||
@ -85,7 +86,8 @@ namespace QSB.ShipSync
|
||||
{
|
||||
DebugLog.ToConsole($"Error - Tried to spawn ship, but LocalPlayer's TransformSync is null!", MessageType.Error);
|
||||
}
|
||||
QNetworkServer.SpawnWithClientAuthority(Instantiate(QSBNetworkManager.Instance.ShipPrefab), QSBPlayerManager.LocalPlayer.TransformSync.gameObject);
|
||||
|
||||
Instantiate(QSBNetworkManager.Instance.ShipPrefab).SpawnWithServerAuthority();
|
||||
}
|
||||
|
||||
QSBWorldSync.Init<QSBShipComponent, ShipComponent>();
|
||||
@ -106,6 +108,9 @@ namespace QSB.ShipSync
|
||||
UpdateElectricalComponent();
|
||||
}
|
||||
|
||||
public bool IsPlayerInShip(PlayerInfo player)
|
||||
=> _playersInShip.Contains(player);
|
||||
|
||||
private void UpdateElectricalComponent()
|
||||
{
|
||||
var electricalSystem = ShipElectricalComponent.GetValue<ElectricalSystem>("_electricalSystem");
|
||||
|
@ -1,9 +1,7 @@
|
||||
using QSB.Player;
|
||||
using QSB.SectorSync;
|
||||
using QSB.Syncs.RigidbodySync;
|
||||
using QSB.Syncs.Sectored.Rigidbodies;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.ShipSync.TransformSync
|
||||
{
|
||||
@ -11,6 +9,9 @@ namespace QSB.ShipSync.TransformSync
|
||||
{
|
||||
public static ShipTransformSync LocalInstance { get; private set; }
|
||||
|
||||
private const int ForcePositionAfterUpdates = 50;
|
||||
private int _updateCount;
|
||||
|
||||
public override bool IsReady
|
||||
=> Locator.GetShipBody() != null;
|
||||
|
||||
@ -20,34 +21,51 @@ namespace QSB.ShipSync.TransformSync
|
||||
LocalInstance = this;
|
||||
}
|
||||
|
||||
protected override Component InitLocalTransform() => throw new System.NotImplementedException();
|
||||
protected override Component InitRemoteTransform() => throw new System.NotImplementedException();
|
||||
|
||||
protected override OWRigidbody GetRigidbody()
|
||||
{
|
||||
QSBCore.UnityEvents.RunWhen(() => WorldObjectManager.AllReady, () => SectorSync.Init(Locator.GetShipDetector().GetComponent<SectorDetector>(), this));
|
||||
QSBCore.UnityEvents.RunWhen(() => WorldObjectManager.AllReady, () => SectorSync.Init(Locator.GetShipDetector().GetComponent<SectorDetector>(), TargetType.Ship));
|
||||
return Locator.GetShipBody();
|
||||
}
|
||||
|
||||
private void ForcePosition()
|
||||
{
|
||||
var targetPos = _intermediaryTransform.GetTargetPosition_Unparented();
|
||||
var targetRot = _intermediaryTransform.GetTargetRotation_Unparented();
|
||||
|
||||
(AttachedObject as OWRigidbody).SetPosition(targetPos);
|
||||
(AttachedObject as OWRigidbody).SetRotation(targetRot);
|
||||
}
|
||||
|
||||
protected override bool UpdateTransform()
|
||||
{
|
||||
if (HasAuthority && ShipManager.Instance.CurrentFlyer != QSBPlayerManager.LocalPlayerId && ShipManager.Instance.CurrentFlyer != uint.MaxValue)
|
||||
if (HasAuthority)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - Has authority, but is not current flyer!", OWML.Common.MessageType.Warning);
|
||||
return false;
|
||||
_intermediaryTransform.EncodePosition(AttachedObject.transform.position);
|
||||
_intermediaryTransform.EncodeRotation(AttachedObject.transform.rotation);
|
||||
_relativeVelocity = GetRelativeVelocity();
|
||||
_relativeAngularVelocity = (AttachedObject as OWRigidbody).GetRelativeAngularVelocity(ReferenceTransform.GetAttachedOWRigidbody());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!HasAuthority && ShipManager.Instance.CurrentFlyer == QSBPlayerManager.LocalPlayerId)
|
||||
_updateCount++;
|
||||
|
||||
if (_updateCount >= ForcePositionAfterUpdates)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Doesn't have authority, but is current flyer!", OWML.Common.MessageType.Warning);
|
||||
return false;
|
||||
_updateCount = 0;
|
||||
ForcePosition();
|
||||
}
|
||||
|
||||
return base.UpdateTransform();
|
||||
var targetPos = _intermediaryTransform.GetTargetPosition_Unparented();
|
||||
|
||||
var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().GetPointVelocity(targetPos) + _relativeVelocity;
|
||||
var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().GetAngularVelocity() + _relativeAngularVelocity;
|
||||
|
||||
SetVelocity(AttachedObject as OWRigidbody, targetVelocity);
|
||||
(AttachedObject as OWRigidbody).SetAngularVelocity(targetAngularVelocity);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override TargetType Type => TargetType.Ship;
|
||||
|
||||
public override bool UseInterpolation => true;
|
||||
protected override float DistanceLeeway => 20f;
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ namespace QSB.StatueSync.Events
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QSBEventManager.FireEvent(EventNames.QSBServerState, ServerState.InStatueCutscene);
|
||||
}
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
using QSB.SectorSync;
|
||||
using QSB.SectorSync.WorldObjects;
|
||||
|
||||
namespace QSB.Syncs
|
||||
{
|
||||
public interface ISectoredSync<T>
|
||||
{
|
||||
SectorSync.SectorSync SectorSync { get; }
|
||||
QSBSector ReferenceSector { get; }
|
||||
TargetType Type { get; }
|
||||
|
||||
void SetReferenceSector(QSBSector sector);
|
||||
}
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
using QSB.SectorSync;
|
||||
using QSB.SectorSync.WorldObjects;
|
||||
using QSB.WorldSync;
|
||||
using QuantumUNET.Transport;
|
||||
|
||||
namespace QSB.Syncs.RigidbodySync
|
||||
{
|
||||
public abstract class SectoredRigidbodySync : BaseRigidbodySync, ISectoredSync<OWRigidbody>
|
||||
{
|
||||
public QSBSector ReferenceSector { get; set; }
|
||||
public SectorSync.SectorSync SectorSync { get; private set; }
|
||||
public abstract TargetType Type { get; }
|
||||
|
||||
public override bool IgnoreDisabledAttachedObject => false;
|
||||
public override bool IgnoreNullReferenceTransform => true;
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
SectorSync = gameObject.AddComponent<SectorSync.SectorSync>();
|
||||
QSBSectorManager.Instance.SectoredRigidbodySyncs.Add(this);
|
||||
base.Start();
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
QSBSectorManager.Instance.SectoredRigidbodySyncs.Remove(this);
|
||||
if (SectorSync != null)
|
||||
{
|
||||
Destroy(SectorSync);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
if (!QSBSectorManager.Instance.IsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!HasAuthority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var closestSector = SectorSync.GetClosestSector(AttachedObject.transform);
|
||||
if (closestSector != null)
|
||||
{
|
||||
SetReferenceTransform(closestSector.Transform);
|
||||
}
|
||||
}
|
||||
|
||||
public override void SerializeTransform(QNetworkWriter writer, bool initialState)
|
||||
{
|
||||
if (_intermediaryTransform == null)
|
||||
{
|
||||
_intermediaryTransform = new IntermediaryTransform(transform);
|
||||
}
|
||||
|
||||
if (ReferenceSector != null)
|
||||
{
|
||||
writer.Write(ReferenceSector.ObjectId);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(-1);
|
||||
}
|
||||
|
||||
base.SerializeTransform(writer, initialState);
|
||||
}
|
||||
|
||||
public override void DeserializeTransform(QNetworkReader reader, bool initialState)
|
||||
{
|
||||
if (!QSBCore.WorldObjectsReady)
|
||||
{
|
||||
reader.ReadInt32();
|
||||
reader.ReadVector3();
|
||||
DeserializeRotation(reader);
|
||||
return;
|
||||
}
|
||||
|
||||
var sectorId = reader.ReadInt32();
|
||||
var sector = sectorId == -1
|
||||
? null
|
||||
: QSBWorldSync.GetWorldFromId<QSBSector>(sectorId);
|
||||
|
||||
if (sector != ReferenceSector)
|
||||
{
|
||||
SetReferenceSector(sector);
|
||||
}
|
||||
|
||||
base.DeserializeTransform(reader, initialState);
|
||||
}
|
||||
|
||||
protected override bool UpdateTransform()
|
||||
{
|
||||
if ((ReferenceTransform == null || ReferenceSector == null || _intermediaryTransform.GetReferenceTransform() == null) && QSBSectorManager.Instance.IsReady && HasAuthority)
|
||||
{
|
||||
var closestSector = SectorSync.GetClosestSector(AttachedObject.transform);
|
||||
if (closestSector != null)
|
||||
{
|
||||
SetReferenceTransform(closestSector.Transform);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return base.UpdateTransform();
|
||||
}
|
||||
|
||||
public void SetReferenceSector(QSBSector sector)
|
||||
{
|
||||
ReferenceSector = sector;
|
||||
SetReferenceTransform(sector?.Transform);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,32 +4,30 @@ using QSB.SectorSync.WorldObjects;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Syncs.TransformSync
|
||||
namespace QSB.Syncs.Sectored
|
||||
{
|
||||
public abstract class SectoredTransformSync : BaseTransformSync, ISectoredSync<Transform>
|
||||
public abstract class BaseSectoredSync : SyncBase
|
||||
{
|
||||
public override bool IgnoreDisabledAttachedObject => false;
|
||||
public override bool IgnoreNullReferenceTransform => true;
|
||||
|
||||
public QSBSector ReferenceSector { get; set; }
|
||||
public SectorSync.SectorSync SectorSync { get; private set; }
|
||||
public abstract TargetType Type { get; }
|
||||
|
||||
public override bool IgnoreNullReferenceTransform => true;
|
||||
public override bool IgnoreDisabledAttachedObject => false;
|
||||
|
||||
private int _sectorIdWaitingSlot = int.MinValue;
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
SectorSync = gameObject.AddComponent<SectorSync.SectorSync>();
|
||||
QSBSectorManager.Instance.SectoredTransformSyncs.Add(this);
|
||||
QSBSectorManager.Instance.SectoredSyncs.Add(this);
|
||||
base.Start();
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
QSBSectorManager.Instance.SectoredTransformSyncs.Remove(this);
|
||||
QSBSectorManager.Instance.SectoredSyncs.Remove(this);
|
||||
if (SectorSync != null)
|
||||
{
|
||||
Destroy(SectorSync);
|
||||
@ -54,7 +52,6 @@ namespace QSB.Syncs.TransformSync
|
||||
|
||||
private void InitSector()
|
||||
{
|
||||
DebugLog.DebugWrite($"InitSector of {_logName}");
|
||||
var closestSector = SectorSync.GetClosestSector(AttachedObject.transform);
|
||||
if (closestSector != null)
|
||||
{
|
||||
@ -116,8 +113,7 @@ namespace QSB.Syncs.TransformSync
|
||||
{
|
||||
writer.Write(-1);
|
||||
}
|
||||
|
||||
if (ReferenceSector != null)
|
||||
else if (ReferenceSector != null)
|
||||
{
|
||||
writer.Write(ReferenceSector.ObjectId);
|
||||
}
|
||||
@ -127,10 +123,9 @@ namespace QSB.Syncs.TransformSync
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - ReferenceSector of {PlayerId}.{GetType().Name} is null.", OWML.Common.MessageType.Warning);
|
||||
}
|
||||
|
||||
writer.Write(-1);
|
||||
}
|
||||
|
||||
base.SerializeTransform(writer, initialState);
|
||||
}
|
||||
|
||||
public override void DeserializeTransform(QNetworkReader reader, bool initialState)
|
||||
@ -144,8 +139,7 @@ namespace QSB.Syncs.TransformSync
|
||||
DebugLog.DebugWrite($"{_logName} set waiting sector id:{sectorId}");
|
||||
_sectorIdWaitingSlot = sectorId;
|
||||
}
|
||||
reader.ReadVector3();
|
||||
DeserializeRotation(reader);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -159,14 +153,11 @@ namespace QSB.Syncs.TransformSync
|
||||
if (sector == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - {PlayerId}.{GetType().Name} got sector of ID -1.", OWML.Common.MessageType.Error);
|
||||
base.DeserializeTransform(reader, initialState);
|
||||
return;
|
||||
}
|
||||
|
||||
SetReferenceSector(sector);
|
||||
}
|
||||
|
||||
base.DeserializeTransform(reader, initialState);
|
||||
}
|
||||
|
||||
protected override bool UpdateTransform()
|
||||
@ -182,12 +173,14 @@ namespace QSB.Syncs.TransformSync
|
||||
$"Transform:{ReferenceTransform == null}, Sector:{ReferenceSector == null}, Intermediary:{_intermediaryTransform.GetReferenceTransform() == null}",
|
||||
OWML.Common.MessageType.Warning);
|
||||
}
|
||||
return base.UpdateTransform();
|
||||
|
||||
DebugLog.DebugWrite($"[BaseSectoredSync] {_logName} : Sector Manager not ready.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!HasAuthority)
|
||||
{
|
||||
return base.UpdateTransform();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (referenceNull)
|
||||
@ -203,12 +196,13 @@ namespace QSB.Syncs.TransformSync
|
||||
{
|
||||
DebugLog.ToConsole($"Error - No closest sector found to {PlayerId}.{GetType().Name}!", OWML.Common.MessageType.Error);
|
||||
}
|
||||
|
||||
return base.UpdateTransform();
|
||||
|
||||
DebugLog.DebugWrite($"[BaseSectoredSync] {_logName} : No sector found.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return base.UpdateTransform();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetReferenceSector(QSBSector sector)
|
@ -1,63 +1,46 @@
|
||||
using OWML.Common;
|
||||
using OWML.Utils;
|
||||
using QSB.Player.TransformSync;
|
||||
using QSB.Utility;
|
||||
using QuantumUNET.Transport;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Syncs.RigidbodySync
|
||||
namespace QSB.Syncs.Sectored.Rigidbodies
|
||||
{
|
||||
public abstract class BaseRigidbodySync : SyncBase
|
||||
public abstract class SectoredRigidbodySync : BaseSectoredSync
|
||||
{
|
||||
public override bool ShouldReparentAttachedObject => false;
|
||||
|
||||
public const float PositionMovedThreshold = 0.05f;
|
||||
public const float AngleRotatedThreshold = 0.05f;
|
||||
public const float VelocityChangeThreshold = 0.05f;
|
||||
public const float AngVelocityChangeThreshold = 0.05f;
|
||||
|
||||
protected Vector3 _relativeVelocity;
|
||||
protected Vector3 _relativeAngularVelocity;
|
||||
protected Vector3 _prevVelocity;
|
||||
protected Vector3 _prevAngularVelocity;
|
||||
|
||||
/// <summary>
|
||||
/// The previous position of the VISIBLE object, as if parented to the reference.
|
||||
/// </summary>
|
||||
protected Vector3 _localPrevPosition;
|
||||
|
||||
/// <summary>
|
||||
/// The previous rotation of the VISIBLE object, as if parented to the reference.
|
||||
/// </summary>
|
||||
protected Quaternion _localPrevRotation;
|
||||
|
||||
protected Vector3 _localPrevVelocity;
|
||||
protected Vector3 _localPrevAngularVelocity;
|
||||
|
||||
protected abstract OWRigidbody GetRigidbody();
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
var lowestBound = Resources.FindObjectsOfTypeAll<PlayerTransformSync>()
|
||||
.Where(x => x.NetId.Value <= NetId.Value).OrderBy(x => x.NetId.Value).Last();
|
||||
NetIdentity.SetRootIdentity(lowestBound.NetIdentity);
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
_intermediaryTransform = new IntermediaryTransform(transform);
|
||||
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
|
||||
}
|
||||
|
||||
protected virtual void OnDestroy() => QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
|
||||
|
||||
private void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool isInUniverse)
|
||||
=> _isInitialized = false;
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
if (!QSBSceneManager.IsInUniverse)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - {_logName} is being init-ed when not in the universe!", MessageType.Error);
|
||||
}
|
||||
|
||||
AttachedObject = GetRigidbody();
|
||||
_isInitialized = true;
|
||||
}
|
||||
protected override Component SetAttachedObject()
|
||||
=> GetRigidbody();
|
||||
|
||||
public override void SerializeTransform(QNetworkWriter writer, bool initialState)
|
||||
{
|
||||
if (_intermediaryTransform == null)
|
||||
{
|
||||
_intermediaryTransform = new IntermediaryTransform(transform);
|
||||
}
|
||||
|
||||
/* We need to send :
|
||||
* - Position
|
||||
* - Rotation
|
||||
* - Velocity
|
||||
* - Angular velocity
|
||||
* We can't store the last two on the IntermediaryTransform, so they come from fields.
|
||||
*/
|
||||
base.SerializeTransform(writer, initialState);
|
||||
|
||||
var worldPos = _intermediaryTransform.GetPosition();
|
||||
var worldRot = _intermediaryTransform.GetRotation();
|
||||
@ -77,6 +60,8 @@ namespace QSB.Syncs.RigidbodySync
|
||||
|
||||
public override void DeserializeTransform(QNetworkReader reader, bool initialState)
|
||||
{
|
||||
base.DeserializeTransform(reader, initialState);
|
||||
|
||||
if (!QSBCore.WorldObjectsReady)
|
||||
{
|
||||
reader.ReadVector3();
|
||||
@ -114,6 +99,11 @@ namespace QSB.Syncs.RigidbodySync
|
||||
|
||||
protected override bool UpdateTransform()
|
||||
{
|
||||
if (!base.UpdateTransform())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (HasAuthority)
|
||||
{
|
||||
_intermediaryTransform.EncodePosition(AttachedObject.transform.position);
|
||||
@ -131,28 +121,101 @@ namespace QSB.Syncs.RigidbodySync
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector3 positionToSet = targetPos;
|
||||
Quaternion rotationToSet = targetRot;
|
||||
|
||||
if (UseInterpolation)
|
||||
{
|
||||
(AttachedObject as OWRigidbody).SetPosition(SmartSmoothDamp(AttachedObject.transform.position, targetPos));
|
||||
(AttachedObject as OWRigidbody).SetRotation(QuaternionHelper.SmoothDamp(AttachedObject.transform.rotation, targetRot, ref _rotationSmoothVelocity, SmoothTime));
|
||||
positionToSet = SmartSmoothDamp(AttachedObject.transform.position, targetPos);
|
||||
rotationToSet = QuaternionHelper.SmoothDamp(AttachedObject.transform.rotation, targetRot, ref _rotationSmoothVelocity, SmoothTime);
|
||||
}
|
||||
else
|
||||
|
||||
var hasMoved = CustomHasMoved(
|
||||
_intermediaryTransform.GetTargetPosition_ParentedToReference(),
|
||||
_localPrevPosition,
|
||||
_intermediaryTransform.GetTargetRotation_ParentedToReference(),
|
||||
_localPrevRotation,
|
||||
_relativeVelocity,
|
||||
_localPrevVelocity,
|
||||
_relativeAngularVelocity,
|
||||
_localPrevAngularVelocity);
|
||||
|
||||
_localPrevPosition = _intermediaryTransform.GetTargetPosition_ParentedToReference();
|
||||
_localPrevRotation = _intermediaryTransform.GetTargetRotation_ParentedToReference();
|
||||
_localPrevVelocity = _relativeVelocity;
|
||||
_localPrevAngularVelocity = _relativeAngularVelocity;
|
||||
|
||||
if (!hasMoved)
|
||||
{
|
||||
(AttachedObject as OWRigidbody).SetPosition(targetPos);
|
||||
(AttachedObject as OWRigidbody).SetRotation(targetRot);
|
||||
return true;
|
||||
}
|
||||
|
||||
var currentVelocity = GetRelativeVelocity();
|
||||
var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().GetPointVelocity(targetPos) + _relativeVelocity;
|
||||
var adjustedTarget = targetVelocity + Locator.GetCenterOfTheUniverse().GetStaticFrameWorldVelocity();
|
||||
//(AttachedObject as OWRigidbody).SetPosition(positionToSet);
|
||||
//(AttachedObject as OWRigidbody).SetRotation(rotationToSet);
|
||||
|
||||
SetVelocity((AttachedObject as OWRigidbody), targetVelocity);
|
||||
(AttachedObject as OWRigidbody).SetAngularVelocity(ReferenceTransform.GetAttachedOWRigidbody().GetAngularVelocity() + _relativeAngularVelocity);
|
||||
(AttachedObject as OWRigidbody).MoveToPosition(positionToSet);
|
||||
(AttachedObject as OWRigidbody).MoveToRotation(rotationToSet);
|
||||
|
||||
var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().GetPointVelocity(targetPos) + _relativeVelocity;
|
||||
var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().GetAngularVelocity() + _relativeAngularVelocity;
|
||||
|
||||
SetVelocity(AttachedObject as OWRigidbody, targetVelocity);
|
||||
(AttachedObject as OWRigidbody).SetAngularVelocity(targetAngularVelocity);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void SetVelocity(OWRigidbody rigidbody, Vector3 relativeVelocity)
|
||||
public override bool HasMoved()
|
||||
=> CustomHasMoved(
|
||||
_intermediaryTransform.GetPosition(),
|
||||
_prevPosition,
|
||||
_intermediaryTransform.GetRotation(),
|
||||
_prevRotation,
|
||||
_relativeVelocity,
|
||||
_prevVelocity,
|
||||
_relativeAngularVelocity,
|
||||
_prevAngularVelocity);
|
||||
|
||||
// OPTIMIZE : optimize by using sqrMagnitude
|
||||
private bool CustomHasMoved(
|
||||
Vector3 newPosition,
|
||||
Vector3 prevPosition,
|
||||
Quaternion newRotation,
|
||||
Quaternion prevRotation,
|
||||
Vector3 newVelocity,
|
||||
Vector3 prevVelocity,
|
||||
Vector3 newAngVelocity,
|
||||
Vector3 prevAngVelocity)
|
||||
{
|
||||
var displacementMagnitude = (newPosition - prevPosition).magnitude;
|
||||
|
||||
if (displacementMagnitude > PositionMovedThreshold)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Quaternion.Angle(newRotation, prevRotation) > AngleRotatedThreshold)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var velocityChangeMagnitude = (newVelocity - prevVelocity).magnitude;
|
||||
var angularVelocityChangeMagnitude = (newAngVelocity - prevAngVelocity).magnitude;
|
||||
if (velocityChangeMagnitude > VelocityChangeThreshold)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (angularVelocityChangeMagnitude > AngVelocityChangeThreshold)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO : why? isn't owrigidbody.setvelocity the same...? :P
|
||||
protected void SetVelocity(OWRigidbody rigidbody, Vector3 relativeVelocity)
|
||||
{
|
||||
var isRunningKinematic = rigidbody.RunningKinematicSimulation();
|
||||
var currentVelocity = rigidbody.GetValue<Vector3>("_currentVelocity");
|
||||
@ -172,53 +235,6 @@ namespace QSB.Syncs.RigidbodySync
|
||||
rigidbody.SetValue("_currentVelocity", relativeVelocity);
|
||||
}
|
||||
|
||||
public void SetReferenceTransform(Transform transform)
|
||||
{
|
||||
if (ReferenceTransform == transform)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ReferenceTransform = transform;
|
||||
_intermediaryTransform.SetReferenceTransform(transform);
|
||||
|
||||
if (HasAuthority)
|
||||
{
|
||||
_intermediaryTransform.EncodePosition(AttachedObject.transform.position);
|
||||
_intermediaryTransform.EncodeRotation(AttachedObject.transform.rotation);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO : optimize by using sqrMagnitude
|
||||
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 = (_relativeVelocity - _prevVelocity).magnitude;
|
||||
var angularVelocityChangeMagnitude = (_relativeAngularVelocity - _prevAngularVelocity).magnitude;
|
||||
if (velocityChangeMagnitude > 1E-03f)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (angularVelocityChangeMagnitude > 1E-03f)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public float GetVelocityChangeMagnitude()
|
||||
=> (_relativeVelocity - _prevVelocity).magnitude;
|
||||
|
||||
@ -247,4 +263,4 @@ namespace QSB.Syncs.RigidbodySync
|
||||
return (AttachedObject as OWRigidbody).GetVelocity() - pointVelocity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
96
QSB/Syncs/Sectored/Transforms/SectoredTransformSync.cs
Normal file
96
QSB/Syncs/Sectored/Transforms/SectoredTransformSync.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using OWML.Common;
|
||||
using QSB.Utility;
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Syncs.Sectored.Transforms
|
||||
{
|
||||
public abstract class SectoredTransformSync : BaseSectoredSync
|
||||
{
|
||||
public override bool ShouldReparentAttachedObject => true;
|
||||
|
||||
protected abstract Component InitLocalTransform();
|
||||
protected abstract Component InitRemoteTransform();
|
||||
|
||||
protected override Component SetAttachedObject()
|
||||
=> HasAuthority ? InitLocalTransform() : InitRemoteTransform();
|
||||
|
||||
public override void SerializeTransform(QNetworkWriter writer, bool initialState)
|
||||
{
|
||||
base.SerializeTransform(writer, initialState);
|
||||
|
||||
var worldPos = _intermediaryTransform.GetPosition();
|
||||
var worldRot = _intermediaryTransform.GetRotation();
|
||||
writer.Write(worldPos);
|
||||
SerializeRotation(writer, worldRot);
|
||||
_prevPosition = worldPos;
|
||||
_prevRotation = worldRot;
|
||||
}
|
||||
|
||||
public override void DeserializeTransform(QNetworkReader reader, bool initialState)
|
||||
{
|
||||
base.DeserializeTransform(reader, initialState);
|
||||
|
||||
if (!QSBCore.WorldObjectsReady)
|
||||
{
|
||||
reader.ReadVector3();
|
||||
DeserializeRotation(reader);
|
||||
return;
|
||||
}
|
||||
|
||||
var pos = reader.ReadVector3();
|
||||
var rot = DeserializeRotation(reader);
|
||||
|
||||
if (HasAuthority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_intermediaryTransform == null)
|
||||
{
|
||||
_intermediaryTransform = new IntermediaryTransform(transform);
|
||||
}
|
||||
|
||||
_intermediaryTransform.SetPosition(pos);
|
||||
_intermediaryTransform.SetRotation(rot);
|
||||
|
||||
if (_intermediaryTransform.GetPosition() == Vector3.zero)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - {_logName} at (0,0,0)! - Given position was {pos}", MessageType.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool UpdateTransform()
|
||||
{
|
||||
if (!base.UpdateTransform())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (HasAuthority)
|
||||
{
|
||||
_intermediaryTransform.EncodePosition(AttachedObject.transform.position);
|
||||
_intermediaryTransform.EncodeRotation(AttachedObject.transform.rotation);
|
||||
return true;
|
||||
}
|
||||
|
||||
var targetPos = _intermediaryTransform.GetTargetPosition_ParentedToReference();
|
||||
var targetRot = _intermediaryTransform.GetTargetRotation_ParentedToReference();
|
||||
if (targetPos != Vector3.zero && _intermediaryTransform.GetTargetPosition_Unparented() != Vector3.zero)
|
||||
{
|
||||
if (UseInterpolation)
|
||||
{
|
||||
AttachedObject.transform.localPosition = SmartSmoothDamp(AttachedObject.transform.localPosition, targetPos);
|
||||
AttachedObject.transform.localRotation = QuaternionHelper.SmoothDamp(AttachedObject.transform.localRotation, targetRot, ref _rotationSmoothVelocity, SmoothTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
AttachedObject.transform.localPosition = targetPos;
|
||||
AttachedObject.transform.localRotation = targetRot;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,45 @@
|
||||
using OWML.Common;
|
||||
using QSB.Player;
|
||||
using QSB.Player.TransformSync;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using QuantumUNET.Components;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Syncs
|
||||
{
|
||||
/*
|
||||
* Rewrite number : 9
|
||||
* God has cursed me for my hubris, and my work is never finished.
|
||||
*/
|
||||
|
||||
public abstract class SyncBase : QNetworkTransform
|
||||
{
|
||||
private static readonly Dictionary<PlayerInfo, Dictionary<Type, SyncBase>> _storedTransformSyncs = new Dictionary<PlayerInfo, Dictionary<Type, SyncBase>>();
|
||||
|
||||
public static T GetPlayers<T>(PlayerInfo player)
|
||||
where T : SyncBase
|
||||
{
|
||||
var dictOfOwnedSyncs = _storedTransformSyncs[player];
|
||||
var wantedSync = dictOfOwnedSyncs[typeof(T)];
|
||||
if (wantedSync == default)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - _storedTransformSyncs does not contain type:{typeof(T)} under player {player.PlayerId}. Attempting to find manually...", MessageType.Error);
|
||||
var allSyncs = Resources.FindObjectsOfTypeAll<T>();
|
||||
wantedSync = allSyncs.First(x => x.Player == player);
|
||||
if (wantedSync == default)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - Could not find type:{typeof(T)} for player {player.PlayerId} manually!", MessageType.Error);
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
return (T)wantedSync;
|
||||
}
|
||||
|
||||
public uint AttachedNetId
|
||||
{
|
||||
get
|
||||
@ -50,6 +81,7 @@ namespace QSB.Syncs
|
||||
public abstract bool UseInterpolation { get; }
|
||||
public abstract bool IgnoreDisabledAttachedObject { get; }
|
||||
public abstract bool IgnoreNullReferenceTransform { get; }
|
||||
public abstract bool ShouldReparentAttachedObject { get; }
|
||||
|
||||
public Component AttachedObject { get; set; }
|
||||
public Transform ReferenceTransform { get; set; }
|
||||
@ -63,22 +95,78 @@ namespace QSB.Syncs
|
||||
protected IntermediaryTransform _intermediaryTransform;
|
||||
protected bool _isInitialized;
|
||||
|
||||
protected abstract Component InitLocalTransform();
|
||||
protected abstract Component InitRemoteTransform();
|
||||
protected abstract Component SetAttachedObject();
|
||||
protected abstract bool UpdateTransform();
|
||||
protected abstract void Init();
|
||||
|
||||
protected Vector3 SmartSmoothDamp(Vector3 currentPosition, Vector3 targetPosition)
|
||||
public virtual void Start()
|
||||
{
|
||||
var distance = Vector3.Distance(currentPosition, targetPosition);
|
||||
if (distance > _previousDistance + DistanceLeeway)
|
||||
var lowestBound = Resources.FindObjectsOfTypeAll<PlayerTransformSync>()
|
||||
.Where(x => x.NetId.Value <= NetId.Value).OrderBy(x => x.NetId.Value).Last();
|
||||
NetIdentity.SetRootIdentity(lowestBound.NetIdentity);
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
_intermediaryTransform = new IntermediaryTransform(transform);
|
||||
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
|
||||
|
||||
if (Player == null)
|
||||
{
|
||||
_previousDistance = distance;
|
||||
return targetPosition;
|
||||
DebugLog.ToConsole($"Error - Player in start of {_logName} was null!", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_previousDistance = distance;
|
||||
return Vector3.SmoothDamp(currentPosition, targetPosition, ref _positionSmoothVelocity, SmoothTime);
|
||||
if (!_storedTransformSyncs.ContainsKey(Player))
|
||||
{
|
||||
_storedTransformSyncs.Add(Player, new Dictionary<Type, SyncBase>());
|
||||
}
|
||||
|
||||
var playerDict = _storedTransformSyncs[Player];
|
||||
playerDict[GetType()] = this;
|
||||
}
|
||||
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
if (ShouldReparentAttachedObject)
|
||||
{
|
||||
if (!HasAuthority && AttachedObject != null)
|
||||
{
|
||||
Destroy(AttachedObject.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
|
||||
|
||||
if (!QSBPlayerManager.PlayerExists(PlayerId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var playerDict = _storedTransformSyncs[Player];
|
||||
playerDict.Remove(GetType());
|
||||
}
|
||||
|
||||
protected virtual void Init()
|
||||
{
|
||||
if (!QSBSceneManager.IsInUniverse)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - {_logName} is being init-ed when not in the universe!", MessageType.Error);
|
||||
}
|
||||
|
||||
// TODO : maybe make it's own option
|
||||
if (ShouldReparentAttachedObject)
|
||||
{
|
||||
if (!HasAuthority && AttachedObject != null)
|
||||
{
|
||||
Destroy(AttachedObject.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
AttachedObject = SetAttachedObject();
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
protected virtual void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool isInUniverse)
|
||||
{
|
||||
_isInitialized = false;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
@ -161,6 +249,69 @@ namespace QSB.Syncs
|
||||
base.Update();
|
||||
}
|
||||
|
||||
protected Vector3 SmartSmoothDamp(Vector3 currentPosition, Vector3 targetPosition)
|
||||
{
|
||||
var distance = Vector3.Distance(currentPosition, targetPosition);
|
||||
if (distance > _previousDistance + DistanceLeeway)
|
||||
{
|
||||
/*
|
||||
DebugLog.DebugWrite($"{_logName} moved too far!" +
|
||||
$"\r\n CurrentPosition:{currentPosition}," +
|
||||
$"\r\n TargetPosition:{targetPosition}");
|
||||
*/
|
||||
_previousDistance = distance;
|
||||
return targetPosition;
|
||||
}
|
||||
|
||||
_previousDistance = distance;
|
||||
return Vector3.SmoothDamp(currentPosition, targetPosition, ref _positionSmoothVelocity, SmoothTime);
|
||||
}
|
||||
|
||||
public void SetReferenceTransform(Transform transform)
|
||||
{
|
||||
if (ReferenceTransform == transform)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ReferenceTransform = transform;
|
||||
_intermediaryTransform.SetReferenceTransform(transform);
|
||||
|
||||
if (ShouldReparentAttachedObject)
|
||||
{
|
||||
if (AttachedObject == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - AttachedObject was null for {_logName} when trying to set reference transform to {transform?.name}. Waiting until not null...", MessageType.Warning);
|
||||
QSBCore.UnityEvents.RunWhen(
|
||||
() => AttachedObject != null,
|
||||
() => ReparentAttachedObject(transform));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!HasAuthority)
|
||||
{
|
||||
ReparentAttachedObject(transform);
|
||||
}
|
||||
}
|
||||
|
||||
if (HasAuthority)
|
||||
{
|
||||
_intermediaryTransform.EncodePosition(AttachedObject.transform.position);
|
||||
_intermediaryTransform.EncodeRotation(AttachedObject.transform.rotation);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReparentAttachedObject(Transform newParent)
|
||||
{
|
||||
if (AttachedObject.transform.parent != null && AttachedObject.transform.parent.GetComponent<Sector>() == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Trying to reparent AttachedObject {AttachedObject.name} which wasnt attached to sector!", MessageType.Warning);
|
||||
}
|
||||
|
||||
AttachedObject.transform.SetParent(newParent, true);
|
||||
AttachedObject.transform.localScale = Vector3.one;
|
||||
}
|
||||
|
||||
protected virtual void OnRenderObject()
|
||||
{
|
||||
if (!QSBCore.WorldObjectsReady
|
||||
|
@ -1,264 +0,0 @@
|
||||
using OWML.Common;
|
||||
using QSB.Player;
|
||||
using QSB.Player.TransformSync;
|
||||
using QSB.Utility;
|
||||
using QuantumUNET;
|
||||
using QuantumUNET.Transport;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Syncs.TransformSync
|
||||
{
|
||||
/*
|
||||
* Rewrite number : 7
|
||||
* God has cursed me for my hubris, and my work is never finished.
|
||||
*/
|
||||
|
||||
public abstract class BaseTransformSync : SyncBase
|
||||
{
|
||||
private static readonly Dictionary<PlayerInfo, Dictionary<Type, BaseTransformSync>> _storedTransformSyncs = new Dictionary<PlayerInfo, Dictionary<Type, BaseTransformSync>>();
|
||||
|
||||
public static T GetPlayers<T>(PlayerInfo player)
|
||||
where T : BaseTransformSync
|
||||
{
|
||||
var dictOfOwnedSyncs = _storedTransformSyncs[player];
|
||||
var wantedSync = dictOfOwnedSyncs[typeof(T)];
|
||||
if (wantedSync == default)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - _storedTransformSyncs does not contain type:{typeof(T)} under player {player.PlayerId}. Attempting to find manually...", MessageType.Error);
|
||||
var allSyncs = Resources.FindObjectsOfTypeAll<T>();
|
||||
wantedSync = allSyncs.First(x => x.Player == player);
|
||||
if (wantedSync == default)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - Could not find type:{typeof(T)} for player {player.PlayerId} manually!", MessageType.Error);
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
return (T)wantedSync;
|
||||
}
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
var lowestBound = Resources.FindObjectsOfTypeAll<PlayerTransformSync>()
|
||||
.Where(x => x.NetId.Value <= NetId.Value).OrderBy(x => x.NetId.Value).Last();
|
||||
NetIdentity.SetRootIdentity(lowestBound.NetIdentity);
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
_intermediaryTransform = new IntermediaryTransform(transform);
|
||||
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
|
||||
|
||||
if (Player == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - Player in start of {_logName} was null!", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_storedTransformSyncs.ContainsKey(Player))
|
||||
{
|
||||
_storedTransformSyncs.Add(Player, new Dictionary<Type, BaseTransformSync>());
|
||||
}
|
||||
|
||||
var playerDict = _storedTransformSyncs[Player];
|
||||
playerDict[GetType()] = this;
|
||||
}
|
||||
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
if (!HasAuthority && AttachedObject != null)
|
||||
{
|
||||
Destroy(AttachedObject.gameObject);
|
||||
}
|
||||
|
||||
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
|
||||
|
||||
if (!QSBPlayerManager.PlayerExists(PlayerId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var playerDict = _storedTransformSyncs[Player];
|
||||
playerDict.Remove(GetType());
|
||||
}
|
||||
|
||||
protected virtual void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool isInUniverse)
|
||||
=> _isInitialized = false;
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
if (!QSBSceneManager.IsInUniverse)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - {_logName} is being init-ed when not in the universe!", MessageType.Error);
|
||||
}
|
||||
|
||||
if (!HasAuthority && AttachedObject != null)
|
||||
{
|
||||
Destroy(AttachedObject.gameObject);
|
||||
}
|
||||
|
||||
AttachedObject = HasAuthority ? InitLocalTransform() : InitRemoteTransform();
|
||||
_isInitialized = true;
|
||||
|
||||
if (QSBCore.DebugMode)
|
||||
{
|
||||
DebugBoxManager.CreateBox(AttachedObject.transform, 0, _logName);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnSerialize(QNetworkWriter writer, bool initialState)
|
||||
{
|
||||
if (!initialState)
|
||||
{
|
||||
if (SyncVarDirtyBits == 0U)
|
||||
{
|
||||
writer.WritePackedUInt32(0U);
|
||||
return false;
|
||||
}
|
||||
|
||||
writer.WritePackedUInt32(1U);
|
||||
}
|
||||
|
||||
SerializeTransform(writer, initialState);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void OnDeserialize(QNetworkReader reader, bool initialState)
|
||||
{
|
||||
if (!IsServer || !QNetworkServer.localClientActive)
|
||||
{
|
||||
if (!initialState)
|
||||
{
|
||||
if (reader.ReadPackedUInt32() == 0U)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DeserializeTransform(reader, initialState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void SerializeTransform(QNetworkWriter writer, bool initialState)
|
||||
{
|
||||
if (_intermediaryTransform == null)
|
||||
{
|
||||
_intermediaryTransform = new IntermediaryTransform(transform);
|
||||
}
|
||||
|
||||
var worldPos = _intermediaryTransform.GetPosition();
|
||||
var worldRot = _intermediaryTransform.GetRotation();
|
||||
writer.Write(worldPos);
|
||||
SerializeRotation(writer, worldRot);
|
||||
_prevPosition = worldPos;
|
||||
_prevRotation = worldRot;
|
||||
}
|
||||
|
||||
public override void DeserializeTransform(QNetworkReader reader, bool initialState)
|
||||
{
|
||||
if (!QSBCore.WorldObjectsReady)
|
||||
{
|
||||
reader.ReadVector3();
|
||||
DeserializeRotation(reader);
|
||||
return;
|
||||
}
|
||||
|
||||
var pos = reader.ReadVector3();
|
||||
var rot = DeserializeRotation(reader);
|
||||
|
||||
if (HasAuthority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_intermediaryTransform == null)
|
||||
{
|
||||
_intermediaryTransform = new IntermediaryTransform(transform);
|
||||
}
|
||||
|
||||
_intermediaryTransform.SetPosition(pos);
|
||||
_intermediaryTransform.SetRotation(rot);
|
||||
|
||||
if (_intermediaryTransform.GetPosition() == Vector3.zero)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - {_logName} at (0,0,0)! - Given position was {pos}", MessageType.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool UpdateTransform()
|
||||
{
|
||||
if (HasAuthority)
|
||||
{
|
||||
_intermediaryTransform.EncodePosition(AttachedObject.transform.position);
|
||||
_intermediaryTransform.EncodeRotation(AttachedObject.transform.rotation);
|
||||
return true;
|
||||
}
|
||||
|
||||
var targetPos = _intermediaryTransform.GetTargetPosition_ParentedToReference();
|
||||
var targetRot = _intermediaryTransform.GetTargetRotation_ParentedToReference();
|
||||
if (targetPos != Vector3.zero && _intermediaryTransform.GetTargetPosition_Unparented() != Vector3.zero)
|
||||
{
|
||||
if (UseInterpolation)
|
||||
{
|
||||
AttachedObject.transform.localPosition = SmartSmoothDamp(AttachedObject.transform.localPosition, targetPos);
|
||||
AttachedObject.transform.localRotation = QuaternionHelper.SmoothDamp(AttachedObject.transform.localRotation, targetRot, ref _rotationSmoothVelocity, SmoothTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
AttachedObject.transform.localPosition = targetPos;
|
||||
AttachedObject.transform.localRotation = targetRot;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HasMoved()
|
||||
{
|
||||
var displacementMagnitude = (_intermediaryTransform.GetPosition() - _prevPosition).magnitude;
|
||||
return displacementMagnitude > 1E-03f
|
||||
|| Quaternion.Angle(_intermediaryTransform.GetRotation(), _prevRotation) > 1E-03f;
|
||||
}
|
||||
|
||||
public void SetReferenceTransform(Transform transform)
|
||||
{
|
||||
if (ReferenceTransform == transform)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ReferenceTransform = transform;
|
||||
_intermediaryTransform.SetReferenceTransform(transform);
|
||||
if (AttachedObject == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - AttachedObject was null for {_logName} when trying to set reference transform to {transform?.name}. Waiting until not null...", MessageType.Warning);
|
||||
QSBCore.UnityEvents.RunWhen(
|
||||
() => AttachedObject != null,
|
||||
() => ReparentAttachedObject(transform));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!HasAuthority)
|
||||
{
|
||||
ReparentAttachedObject(transform);
|
||||
}
|
||||
|
||||
if (HasAuthority)
|
||||
{
|
||||
_intermediaryTransform.EncodePosition(AttachedObject.transform.position);
|
||||
_intermediaryTransform.EncodeRotation(AttachedObject.transform.rotation);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReparentAttachedObject(Transform newParent)
|
||||
{
|
||||
if (AttachedObject.transform.parent != null && AttachedObject.transform.parent.GetComponent<Sector>() == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Trying to reparent AttachedObject {AttachedObject.name} which wasnt attached to sector!", MessageType.Warning);
|
||||
}
|
||||
|
||||
AttachedObject.transform.SetParent(newParent, true);
|
||||
AttachedObject.transform.localScale = Vector3.one;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,144 +0,0 @@
|
||||
using OWML.Common;
|
||||
using QSB.Player.TransformSync;
|
||||
using QSB.Utility;
|
||||
using QuantumUNET.Transport;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Syncs.TransformSync
|
||||
{
|
||||
public abstract class UnparentedBaseTransformSync : SyncBase
|
||||
{
|
||||
public override bool IgnoreDisabledAttachedObject => false;
|
||||
public override bool IgnoreNullReferenceTransform => false;
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
var lowestBound = Resources.FindObjectsOfTypeAll<PlayerTransformSync>()
|
||||
.Where(x => x.NetId.Value <= NetId.Value).OrderBy(x => x.NetId.Value).Last();
|
||||
NetIdentity.SetRootIdentity(lowestBound.NetIdentity);
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
_intermediaryTransform = new IntermediaryTransform(transform);
|
||||
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
|
||||
}
|
||||
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
DebugLog.DebugWrite($"OnDestroy {_logName}");
|
||||
if (!HasAuthority && AttachedObject != null)
|
||||
{
|
||||
Destroy(AttachedObject.gameObject);
|
||||
}
|
||||
|
||||
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
|
||||
}
|
||||
|
||||
protected void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool isInUniverse) =>
|
||||
_isInitialized = false;
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
AttachedObject = HasAuthority ? InitLocalTransform() : InitRemoteTransform();
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
public override void SerializeTransform(QNetworkWriter writer, bool initialState)
|
||||
{
|
||||
if (_intermediaryTransform == null)
|
||||
{
|
||||
_intermediaryTransform = new IntermediaryTransform(transform);
|
||||
}
|
||||
|
||||
var worldPos = _intermediaryTransform.GetPosition();
|
||||
var worldRot = _intermediaryTransform.GetRotation();
|
||||
writer.Write(worldPos);
|
||||
SerializeRotation(writer, worldRot);
|
||||
_prevPosition = worldPos;
|
||||
_prevRotation = worldRot;
|
||||
}
|
||||
|
||||
public override void DeserializeTransform(QNetworkReader reader, bool initialState)
|
||||
{
|
||||
if (!QSBCore.WorldObjectsReady)
|
||||
{
|
||||
reader.ReadVector3();
|
||||
DeserializeRotation(reader);
|
||||
return;
|
||||
}
|
||||
|
||||
var pos = reader.ReadVector3();
|
||||
var rot = DeserializeRotation(reader);
|
||||
|
||||
if (HasAuthority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_intermediaryTransform == null)
|
||||
{
|
||||
_intermediaryTransform = new IntermediaryTransform(transform);
|
||||
}
|
||||
|
||||
_intermediaryTransform.SetPosition(pos);
|
||||
_intermediaryTransform.SetRotation(rot);
|
||||
|
||||
if (_intermediaryTransform.GetPosition() == Vector3.zero)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - {PlayerId}.{GetType().Name} at (0,0,0)! - Given position was {pos}", MessageType.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool UpdateTransform()
|
||||
{
|
||||
if (HasAuthority)
|
||||
{
|
||||
_intermediaryTransform.EncodePosition(AttachedObject.transform.position);
|
||||
_intermediaryTransform.EncodeRotation(AttachedObject.transform.rotation);
|
||||
return true;
|
||||
}
|
||||
|
||||
var targetPos = _intermediaryTransform.GetTargetPosition_Unparented();
|
||||
var targetRot = _intermediaryTransform.GetTargetRotation_Unparented();
|
||||
if (targetPos != Vector3.zero && _intermediaryTransform.GetTargetPosition_ParentedToReference() != Vector3.zero)
|
||||
{
|
||||
if (UseInterpolation)
|
||||
{
|
||||
AttachedObject.transform.position = SmartSmoothDamp(AttachedObject.transform.position, targetPos);
|
||||
AttachedObject.transform.rotation = QuaternionHelper.SmoothDamp(AttachedObject.transform.rotation, targetRot, ref _rotationSmoothVelocity, SmoothTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
AttachedObject.transform.position = targetPos;
|
||||
AttachedObject.transform.rotation = targetRot;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HasMoved()
|
||||
{
|
||||
var displacementMagnitude = (_intermediaryTransform.GetPosition() - _prevPosition).magnitude;
|
||||
return displacementMagnitude > 1E-03f
|
||||
|| Quaternion.Angle(_intermediaryTransform.GetRotation(), _prevRotation) > 1E-03f;
|
||||
}
|
||||
|
||||
public void SetReferenceTransform(Transform transform)
|
||||
{
|
||||
if (ReferenceTransform == transform)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ReferenceTransform = transform;
|
||||
_intermediaryTransform.SetReferenceTransform(transform);
|
||||
|
||||
if (HasAuthority)
|
||||
{
|
||||
_intermediaryTransform.EncodePosition(AttachedObject.transform.position);
|
||||
_intermediaryTransform.EncodeRotation(AttachedObject.transform.rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
19
QSB/Syncs/Unsectored/BaseUnsectoredSync.cs
Normal file
19
QSB/Syncs/Unsectored/BaseUnsectoredSync.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using QuantumUNET.Transport;
|
||||
|
||||
namespace QSB.Syncs.Unsectored
|
||||
{
|
||||
public abstract class BaseUnsectoredSync : SyncBase
|
||||
{
|
||||
public override bool IgnoreDisabledAttachedObject => false;
|
||||
public override bool IgnoreNullReferenceTransform => false;
|
||||
public override bool ShouldReparentAttachedObject => false;
|
||||
|
||||
public override void SerializeTransform(QNetworkWriter writer, bool initialState)
|
||||
{
|
||||
if (_intermediaryTransform == null)
|
||||
{
|
||||
_intermediaryTransform = new IntermediaryTransform(transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs
Normal file
13
QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Syncs.Unsectored.Rigidbodies
|
||||
{
|
||||
public abstract class UnsectoredRigidbodySync : BaseUnsectoredSync
|
||||
{
|
||||
protected abstract OWRigidbody GetRigidbody();
|
||||
|
||||
protected override Component SetAttachedObject()
|
||||
=> throw new NotImplementedException();
|
||||
}
|
||||
}
|
91
QSB/Syncs/Unsectored/Transforms/UnsectoredTransformSync.cs
Normal file
91
QSB/Syncs/Unsectored/Transforms/UnsectoredTransformSync.cs
Normal file
@ -0,0 +1,91 @@
|
||||
using OWML.Common;
|
||||
using QSB.Utility;
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Syncs.Unsectored.Transforms
|
||||
{
|
||||
public abstract class UnsectoredTransformSync : BaseUnsectoredSync
|
||||
{
|
||||
protected abstract Component InitLocalTransform();
|
||||
protected abstract Component InitRemoteTransform();
|
||||
|
||||
protected override Component SetAttachedObject()
|
||||
=> HasAuthority ? InitLocalTransform() : InitRemoteTransform();
|
||||
|
||||
public override void SerializeTransform(QNetworkWriter writer, bool initialState)
|
||||
{
|
||||
base.SerializeTransform(writer, initialState);
|
||||
|
||||
var worldPos = _intermediaryTransform.GetPosition();
|
||||
var worldRot = _intermediaryTransform.GetRotation();
|
||||
writer.Write(worldPos);
|
||||
SerializeRotation(writer, worldRot);
|
||||
_prevPosition = worldPos;
|
||||
_prevRotation = worldRot;
|
||||
}
|
||||
|
||||
public override void DeserializeTransform(QNetworkReader reader, bool initialState)
|
||||
{
|
||||
if (!QSBCore.WorldObjectsReady)
|
||||
{
|
||||
reader.ReadVector3();
|
||||
DeserializeRotation(reader);
|
||||
return;
|
||||
}
|
||||
|
||||
var pos = reader.ReadVector3();
|
||||
var rot = DeserializeRotation(reader);
|
||||
|
||||
if (HasAuthority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_intermediaryTransform == null)
|
||||
{
|
||||
_intermediaryTransform = new IntermediaryTransform(transform);
|
||||
}
|
||||
|
||||
_intermediaryTransform.SetPosition(pos);
|
||||
_intermediaryTransform.SetRotation(rot);
|
||||
|
||||
if (_intermediaryTransform.GetPosition() == Vector3.zero)
|
||||
{
|
||||
//DebugLog.ToConsole($"Warning - {_logName} at (0,0,0)! - Given position was {pos}", MessageType.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool UpdateTransform()
|
||||
{
|
||||
if (HasAuthority)
|
||||
{
|
||||
_intermediaryTransform.EncodePosition(AttachedObject.transform.position);
|
||||
_intermediaryTransform.EncodeRotation(AttachedObject.transform.rotation);
|
||||
return true;
|
||||
}
|
||||
|
||||
var targetPos = _intermediaryTransform.GetTargetPosition_Unparented();
|
||||
var targetRot = _intermediaryTransform.GetTargetRotation_Unparented();
|
||||
if (targetPos != Vector3.zero && _intermediaryTransform.GetTargetPosition_Unparented() != Vector3.zero)
|
||||
{
|
||||
if (UseInterpolation)
|
||||
{
|
||||
AttachedObject.transform.position = SmartSmoothDamp(AttachedObject.transform.position, targetPos);
|
||||
AttachedObject.transform.rotation = QuaternionHelper.SmoothDamp(AttachedObject.transform.rotation, targetRot, ref _rotationSmoothVelocity, SmoothTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
AttachedObject.transform.position = targetPos;
|
||||
AttachedObject.transform.rotation = targetRot;
|
||||
}
|
||||
}
|
||||
else if (targetPos == Vector3.zero)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - TargetPos for {_logName} was (0,0,0).", MessageType.Warning);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -91,6 +91,7 @@ namespace QSB.TimeSync
|
||||
+ "Fast-forwarding to match server time...";
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TimeSyncType.Pausing:
|
||||
@ -112,6 +113,7 @@ namespace QSB.TimeSync
|
||||
text = "Waiting for end of loop...";
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -236,7 +236,6 @@ namespace QSB.TimeSync
|
||||
private void UpdateServer()
|
||||
{
|
||||
_serverTime = Time.timeSinceLevelLoad;
|
||||
|
||||
|
||||
var serverState = ServerStateManager.Instance.GetServerState();
|
||||
var clientState = QSBPlayerManager.LocalPlayer.State;
|
||||
|
@ -37,7 +37,7 @@ namespace QSB.Tools
|
||||
{
|
||||
Props_HEA_Lightbulb_mat = GameObject.Find("lantern_lamp").GetComponent<MeshRenderer>().materials[0];
|
||||
|
||||
// TODO : uhhhhh fuckin' uhhhhhhhh (find a material)
|
||||
// BUG : uhhhhh fuckin' uhhhhhhhh (find a material)
|
||||
Props_HEA_Lightbulb_OFF_mat = null;
|
||||
}
|
||||
|
||||
|
@ -30,11 +30,13 @@ namespace QSB.Tools.ProbeLauncherTool.Events
|
||||
_nonPlayerLauncherEquipped = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_nonPlayerLauncherEquipped)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Trying to equip player launcher whilst non player launcher is still equipped?", OWML.Common.MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
SendEvent(CreateMessage(true));
|
||||
}
|
||||
|
||||
@ -45,11 +47,13 @@ namespace QSB.Tools.ProbeLauncherTool.Events
|
||||
_nonPlayerLauncherEquipped = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_nonPlayerLauncherEquipped)
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Trying to de-equip player launcher whilst non player launcher is still equipped?", OWML.Common.MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
SendEvent(CreateMessage(false));
|
||||
}
|
||||
|
||||
|
@ -9,10 +9,10 @@ namespace QSB.Tools.ProbeLauncherTool.Events
|
||||
{
|
||||
public override EventType Type => EventType.RetrieveProbe;
|
||||
|
||||
public override void SetupListener()
|
||||
public override void SetupListener()
|
||||
=> GlobalMessenger<QSBProbeLauncher, bool>.AddListener(EventNames.QSBRetrieveProbe, Handler);
|
||||
|
||||
public override void CloseListener()
|
||||
public override void CloseListener()
|
||||
=> GlobalMessenger<QSBProbeLauncher, bool>.RemoveListener(EventNames.QSBRetrieveProbe, Handler);
|
||||
|
||||
private void Handler(QSBProbeLauncher launcher, bool playEffects) => SendEvent(CreateMessage(launcher, playEffects));
|
||||
|
@ -70,6 +70,7 @@ namespace QSB.Tools.ProbeLauncherTool.Patches
|
||||
return false;
|
||||
}
|
||||
|
||||
// BUG : This plays the sound to everyone
|
||||
// TODO : ehhhh idk about this. maybe copy each sound source so we have a 2d version (for local) and a 3d version (for remote)?
|
||||
// this would probably be a whole qsb version on it's own
|
||||
|
||||
|
@ -24,7 +24,7 @@ namespace QSB.Tools.ProbeLauncherTool
|
||||
|
||||
// TODO : make this do underwater stuff correctly
|
||||
Effects.PlayLaunchClip(false);
|
||||
// TODO : this plays particles on everyone's launcher...
|
||||
// BUG : this plays particles on everyone's launcher...
|
||||
Effects.PlayLaunchParticles(false);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
using QSB.ClientServerStateSync;
|
||||
using QSB.Player;
|
||||
using QSB.ProbeSync.TransformSync;
|
||||
using QSB.Syncs.TransformSync;
|
||||
using QSB.Syncs;
|
||||
using QSB.TimeSync;
|
||||
using UnityEngine;
|
||||
|
||||
@ -41,8 +41,6 @@ namespace QSB.Utility
|
||||
offset += _debugLineSpacing;
|
||||
GUI.Label(new Rect(220, offset, 200f, 20f), $"Timescale : {OWTime.GetTimeScale()}", guiStyle);
|
||||
offset += _debugLineSpacing;
|
||||
GUI.Label(new Rect(220, offset, 200f, 20f), $"Mouse input : {OWInput.GetValue(InputLibrary.look, false, InputMode.All)}", guiStyle);
|
||||
offset += _debugLineSpacing;
|
||||
}
|
||||
|
||||
var offset2 = 10f;
|
||||
@ -62,12 +60,11 @@ namespace QSB.Utility
|
||||
var networkTransform = player.TransformSync;
|
||||
var sector = networkTransform.ReferenceSector;
|
||||
|
||||
|
||||
GUI.Label(new Rect(420, offset2, 400f, 20f), $" - L.Pos : {networkTransform.transform.localPosition}", guiStyle);
|
||||
offset2 += _debugLineSpacing;
|
||||
GUI.Label(new Rect(420, offset2, 400f, 20f), $" - Sector : {(sector == null ? "NULL" : sector.Name)}", guiStyle);
|
||||
offset2 += _debugLineSpacing;
|
||||
var probeSync = BaseTransformSync.GetPlayers<PlayerProbeSync>(player);
|
||||
var probeSync = SyncBase.GetPlayers<PlayerProbeSync>(player);
|
||||
if (probeSync != default)
|
||||
{
|
||||
var probeSector = probeSync.ReferenceSector;
|
||||
|
@ -1,5 +1,6 @@
|
||||
using OWML.Common;
|
||||
using OWML.Utils;
|
||||
using QSB.Player;
|
||||
using QSB.Player.TransformSync;
|
||||
using QuantumUNET;
|
||||
using System;
|
||||
@ -72,6 +73,17 @@ namespace QSB.Utility
|
||||
return controller.NetId.Value;
|
||||
}
|
||||
|
||||
public static void SpawnWithServerAuthority(this GameObject go)
|
||||
{
|
||||
if (!QSBCore.IsHost)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - Tried to spawn {go.name} using SpawnWithServerAuthority when not the host!", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
QNetworkServer.SpawnWithClientAuthority(go, QSBPlayerManager.LocalPlayer.TransformSync.gameObject);
|
||||
}
|
||||
|
||||
// C#
|
||||
public static void SafeInvoke(this MulticastDelegate multicast, params object[] args)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user