mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-26 18:35:34 +00:00
Merge pull request #205 from Raicuparta/netid-changes
Removing offset system + renaming
This commit is contained in:
commit
953f601597
@ -3,7 +3,7 @@ CRC: 2815158869
|
||||
Hashes:
|
||||
AssetFileHash:
|
||||
serializedVersion: 2
|
||||
Hash: b0dab33ce9502b8c920c956269fa585e
|
||||
Hash: 5677b7876f2afae05c0920067ef29e8a
|
||||
TypeTreeHash:
|
||||
serializedVersion: 2
|
||||
Hash: 4d6a73cb377370ba69c96eb5da1b5028
|
||||
|
Binary file not shown.
@ -1,9 +1,9 @@
|
||||
ManifestFileVersion: 0
|
||||
CRC: 561788810
|
||||
CRC: 3045401868
|
||||
Hashes:
|
||||
AssetFileHash:
|
||||
serializedVersion: 2
|
||||
Hash: 2ed408e0c9f6147e341c9606eb7228c3
|
||||
Hash: fbaaf26c59dbb62b2ffc0c3939c0880a
|
||||
TypeTreeHash:
|
||||
serializedVersion: 2
|
||||
Hash: 47ee499ae8022a6b96ca6a5fd541f154
|
||||
|
@ -9,8 +9,6 @@ namespace QSB.Animation
|
||||
{
|
||||
public class AnimationSync : PlayerSyncObject
|
||||
{
|
||||
protected override uint PlayerIdOffset => 0;
|
||||
|
||||
private Animator _anim;
|
||||
private Animator _bodyAnim;
|
||||
private NetworkAnimator _netAnim;
|
||||
|
@ -1,6 +1,5 @@
|
||||
using QSB.Events;
|
||||
using QSB.Messaging;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
|
||||
namespace QSB.ElevatorSync
|
||||
@ -29,7 +28,6 @@ namespace QSB.ElevatorSync
|
||||
|
||||
public override void OnReceiveRemote(ElevatorMessage message)
|
||||
{
|
||||
DebugLog.DebugWrite($"Get ElevatorMessage {message.Direction} for {message.ObjectId}");
|
||||
var elevator = WorldRegistry.GetObject<QSBElevator>(message.ObjectId);
|
||||
elevator?.RemoteCall(message.Direction);
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ namespace QSB.Events
|
||||
{
|
||||
var player = PlayerRegistry.GetPlayer(message.AboutId);
|
||||
player.Name = message.PlayerName;
|
||||
var text = $"{player.Name} joined!";
|
||||
DebugLog.ToAll(text, MessageType.Info);
|
||||
DebugLog.ToHud($"{player.Name} joined!");
|
||||
DebugLog.DebugWrite($"{player.Name} joined as id {player.PlayerId}", MessageType.Info);
|
||||
}
|
||||
|
||||
public override void OnReceiveLocal(PlayerJoinMessage message)
|
||||
|
@ -45,7 +45,6 @@ namespace QSB.Events
|
||||
foreach (var item in PlayerRegistry.GetSyncObjects<TransformSync.TransformSync>()
|
||||
.Where(x => x != null && x.IsReady && x.ReferenceSector != null && x.PlayerId == LocalPlayerId))
|
||||
{
|
||||
DebugLog.DebugWrite($"* Sending sector for netid {item.netId.Value}...");
|
||||
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, item.netId.Value, item.ReferenceSector);
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ namespace QSB.Events
|
||||
{
|
||||
var message = new PlayerStateMessage
|
||||
{
|
||||
AboutId = player.NetId,
|
||||
AboutId = player.PlayerId,
|
||||
PlayerName = player.Name,
|
||||
PlayerReady = player.IsReady,
|
||||
PlayerState = player.State
|
||||
|
@ -33,7 +33,6 @@ namespace QSB.Events
|
||||
foreach (var item in PlayerRegistry.GetSyncObjects<TransformSync.TransformSync>()
|
||||
.Where(x => x != null && x.IsReady && x.ReferenceSector != null))
|
||||
{
|
||||
DebugLog.DebugWrite($"* Sending sector for netid {item.netId.Value}...");
|
||||
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, item.netId.Value, item.ReferenceSector);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ using QSB.WorldSync;
|
||||
|
||||
namespace QSB.GeyserSync
|
||||
{
|
||||
public class GeyserEvent : QSBEvent<GeyserMessage>
|
||||
public class GeyserEvent : QSBEvent<BoolWorldObjectMessage>
|
||||
{
|
||||
public override EventType Type => EventType.Geyser;
|
||||
|
||||
@ -20,14 +20,14 @@ namespace QSB.GeyserSync
|
||||
|
||||
private void Handler(int id, bool state) => SendEvent(CreateMessage(id, state));
|
||||
|
||||
private GeyserMessage CreateMessage(int id, bool state) => new GeyserMessage
|
||||
private BoolWorldObjectMessage CreateMessage(int id, bool state) => new BoolWorldObjectMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
ObjectId = id,
|
||||
State = state
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(GeyserMessage message)
|
||||
public override void OnReceiveRemote(BoolWorldObjectMessage message)
|
||||
{
|
||||
var geyser = WorldRegistry.GetObject<QSBGeyser>(message.ObjectId);
|
||||
geyser?.SetState(message.State);
|
||||
|
@ -9,7 +9,7 @@ namespace QSB
|
||||
{
|
||||
public class PlayerInfo
|
||||
{
|
||||
public uint NetId { get; }
|
||||
public uint PlayerId { get; }
|
||||
public GameObject Camera { get; set; }
|
||||
public GameObject ProbeBody { get; set; }
|
||||
public QSBProbe Probe { get; set; }
|
||||
@ -24,7 +24,7 @@ namespace QSB
|
||||
|
||||
public PlayerInfo(uint id)
|
||||
{
|
||||
NetId = id;
|
||||
PlayerId = id;
|
||||
}
|
||||
|
||||
public void UpdateState(State state, bool value)
|
||||
@ -53,8 +53,8 @@ namespace QSB
|
||||
Translator?.ChangeEquipState(FlagsHelper.IsSet(State, State.Translator));
|
||||
ProbeLauncher?.ChangeEquipState(FlagsHelper.IsSet(State, State.ProbeLauncher));
|
||||
Signalscope?.ChangeEquipState(FlagsHelper.IsSet(State, State.Signalscope));
|
||||
QSB.Helper.Events.Unity.RunWhen(() => PlayerRegistry.GetSyncObject<AnimationSync>(NetId) != null,
|
||||
() => PlayerRegistry.GetSyncObject<AnimationSync>(NetId).SetSuitState(FlagsHelper.IsSet(State, State.Suit)));
|
||||
QSB.Helper.Events.Unity.RunWhen(() => PlayerRegistry.GetSyncObject<AnimationSync>(PlayerId) != null,
|
||||
() => PlayerRegistry.GetSyncObject<AnimationSync>(PlayerId).SetSuitState(FlagsHelper.IsSet(State, State.Suit)));
|
||||
}
|
||||
|
||||
public bool GetState(State state)
|
||||
|
@ -10,9 +10,7 @@ namespace QSB
|
||||
{
|
||||
public static class PlayerRegistry
|
||||
{
|
||||
public const int NetworkObjectCount = 4;
|
||||
|
||||
public static uint LocalPlayerId => PlayerTransformSync.LocalInstance.GetComponent<NetworkIdentity>()?.netId.Value ?? 0;
|
||||
public static uint LocalPlayerId => PlayerTransformSync.LocalInstance.GetComponent<NetworkIdentity>()?.netId.Value ?? uint.MaxValue;
|
||||
public static PlayerInfo LocalPlayer => GetPlayer(LocalPlayerId);
|
||||
public static List<PlayerInfo> PlayerList { get; } = new List<PlayerInfo>();
|
||||
|
||||
@ -20,12 +18,16 @@ namespace QSB
|
||||
|
||||
public static PlayerInfo GetPlayer(uint id)
|
||||
{
|
||||
var player = PlayerList.FirstOrDefault(x => x.NetId == id);
|
||||
if (id == uint.MaxValue || id == 0U)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
var player = PlayerList.FirstOrDefault(x => x.PlayerId == id);
|
||||
if (player != null)
|
||||
{
|
||||
return player;
|
||||
}
|
||||
DebugLog.DebugWrite($"Creating player with id {id}", MessageType.Info);
|
||||
DebugLog.DebugWrite($"Creating player id {id}", MessageType.Info);
|
||||
player = new PlayerInfo(id);
|
||||
PlayerList.Add(player);
|
||||
return player;
|
||||
@ -33,24 +35,21 @@ namespace QSB
|
||||
|
||||
public static void RemovePlayer(uint id)
|
||||
{
|
||||
DebugLog.DebugWrite($"Removing player with id {id}", MessageType.Info);
|
||||
DebugLog.DebugWrite($"Removing player {GetPlayer(id).Name} id {id}", MessageType.Info);
|
||||
PlayerList.Remove(GetPlayer(id));
|
||||
}
|
||||
|
||||
public static bool PlayerExists(uint id)
|
||||
{
|
||||
return PlayerList.Any(x => x.NetId == id);
|
||||
return id != uint.MaxValue && PlayerList.Any(x => x.PlayerId == id);
|
||||
}
|
||||
|
||||
public static void HandleFullStateMessage(PlayerStateMessage message)
|
||||
{
|
||||
DebugLog.DebugWrite($"Handle full state message for player {message.AboutId}");
|
||||
var player = GetPlayer(message.AboutId);
|
||||
player.Name = message.PlayerName;
|
||||
player.IsReady = message.PlayerReady;
|
||||
DebugLog.DebugWrite($"* Is ready? : {player.IsReady}");
|
||||
player.State = message.PlayerState;
|
||||
DebugLog.DebugWrite($"* Suit is on? : {FlagsHelper.IsSet(player.State, State.Suit)}");
|
||||
//DebugLog.DebugWrite($"Updating state of player {player.NetId} to : {Environment.NewLine}" +
|
||||
// $"{DebugLog.GenerateTable(Enum.GetNames(typeof(State)).ToList(), FlagsHelper.FlagsToListSet(player.State))}");
|
||||
if (LocalPlayer.IsReady)
|
||||
@ -66,18 +65,40 @@ namespace QSB
|
||||
|
||||
public static T GetSyncObject<T>(uint id) where T : PlayerSyncObject
|
||||
{
|
||||
return GetSyncObjects<T>().FirstOrDefault(x => x != null && x.NetId == id);
|
||||
return GetSyncObjects<T>().FirstOrDefault(x => x != null && x.AttachedNetId == id);
|
||||
}
|
||||
|
||||
public static bool IsBelongingToLocalPlayer(uint id)
|
||||
{
|
||||
return id == LocalPlayerId ||
|
||||
PlayerSyncObjects.Any(x => x != null && x.NetId == id && x.PlayerId == LocalPlayerId);
|
||||
PlayerSyncObjects.Any(x => x != null && x.AttachedNetId == id && x.isLocalPlayer);
|
||||
}
|
||||
|
||||
public static uint GetPlayerOfObject(this PlayerSyncObject syncObject)
|
||||
{
|
||||
var playerIds = PlayerList.Select(x => x.PlayerId).ToList();
|
||||
var lowerBound = playerIds.Where(x => x <= syncObject.AttachedNetId).ToList().Max();
|
||||
if (PlayerList.Count != PlayerSyncObjects.Count(x => x.GetType() == syncObject.GetType()) && lowerBound == playerIds.Max())
|
||||
{
|
||||
if (syncObject.PreviousPlayerId != uint.MaxValue)
|
||||
{
|
||||
return syncObject.PreviousPlayerId;
|
||||
}
|
||||
if (syncObject.GetType() == typeof(PlayerTransformSync) && syncObject.AttachedNetId != 0U)
|
||||
{
|
||||
return GetPlayer(syncObject.AttachedNetId).PlayerId;
|
||||
}
|
||||
syncObject.PreviousPlayerId = uint.MaxValue;
|
||||
return uint.MaxValue;
|
||||
}
|
||||
syncObject.PreviousPlayerId = lowerBound;
|
||||
return lowerBound;
|
||||
}
|
||||
|
||||
public static List<uint> GetPlayerNetIds(PlayerInfo player)
|
||||
{
|
||||
return Enumerable.Range((int)player.NetId, NetworkObjectCount).Select(x => (uint)x).ToList();
|
||||
var count = PlayerSyncObjects.DistinctBy(x => x.AttachedNetId).Count(x => x.Player.PlayerId == player.PlayerId);
|
||||
return Enumerable.Range((int)player.PlayerId, count).Select(x => (uint)x).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,9 @@ namespace QSB
|
||||
{
|
||||
public abstract class PlayerSyncObject : NetworkBehaviour
|
||||
{
|
||||
protected abstract uint PlayerIdOffset { get; }
|
||||
public uint NetId => GetComponent<NetworkIdentity>()?.netId.Value ?? 0;
|
||||
public bool IsLocal => hasAuthority;
|
||||
public uint PlayerId => NetId - PlayerIdOffset;
|
||||
public uint AttachedNetId => GetComponent<NetworkIdentity>()?.netId.Value ?? uint.MaxValue;
|
||||
public uint PlayerId => this.GetPlayerOfObject();
|
||||
public uint PreviousPlayerId { get; set; }
|
||||
public PlayerInfo Player => PlayerRegistry.GetPlayer(PlayerId);
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +151,6 @@
|
||||
<Compile Include="TimeSync\ServerTimeEvent.cs" />
|
||||
<Compile Include="GeyserSync\GeyserEvent.cs" />
|
||||
<Compile Include="GeyserSync\GeyserManager.cs" />
|
||||
<Compile Include="GeyserSync\GeyserMessage.cs" />
|
||||
<Compile Include="GeyserSync\QSBGeyser.cs" />
|
||||
<Compile Include="DeathSync\PlayerDeathMessage.cs" />
|
||||
<Compile Include="Messaging\PlayerLeaveMessage.cs" />
|
||||
@ -163,7 +162,10 @@
|
||||
<Compile Include="Messaging\ToggleMessage.cs" />
|
||||
<Compile Include="TransformSync\QSBSector.cs" />
|
||||
<Compile Include="TransformSync\QSBSectorManager.cs" />
|
||||
<Compile Include="TransformSync\TransformSync.cs" />
|
||||
<Compile Include="Utility\GOExtensions.cs" />
|
||||
<Compile Include="Utility\ListExtensions.cs" />
|
||||
<Compile Include="WorldSync\BoolWorldObjectMessage.cs" />
|
||||
<Compile Include="WorldSync\WorldObjectMessage.cs" />
|
||||
<Compile Include="Tools\QSBFlashlight.cs" />
|
||||
<Compile Include="Tools\QSBProbe.cs" />
|
||||
@ -192,7 +194,6 @@
|
||||
<Compile Include="Utility\QuaternionHelper.cs" />
|
||||
<Compile Include="TimeSync\PreserveTimeScale.cs" />
|
||||
<Compile Include="TransformSync\ShipTransformSync.cs" />
|
||||
<Compile Include="TransformSync\TransformSync.cs" />
|
||||
<Compile Include="TransformSync\SectorSync.cs" />
|
||||
<Compile Include="TimeSync\ServerTimeMessage.cs" />
|
||||
<Compile Include="TimeSync\WakeUpSync.cs" />
|
||||
|
@ -73,6 +73,7 @@ namespace QSB
|
||||
|
||||
public override void OnServerAddPlayer(NetworkConnection connection, short playerControllerId) // Called on the server when a client joins
|
||||
{
|
||||
DebugLog.DebugWrite("[S] Add player");
|
||||
base.OnServerAddPlayer(connection, playerControllerId);
|
||||
|
||||
// These have to be in a constant order (for now, until we get a better netId getting system...)
|
||||
@ -107,6 +108,10 @@ namespace QSB
|
||||
|
||||
QSB.Helper.Events.Unity.RunWhen(() => EventList.Ready,
|
||||
() => GlobalMessenger<string>.FireEvent(EventNames.QSBPlayerJoin, _lobby.PlayerName));
|
||||
|
||||
QSB.Helper.Events.Unity.RunWhen(() => EventList.Ready,
|
||||
() => GlobalMessenger.FireEvent(EventNames.QSBPlayerStatesRequest));
|
||||
|
||||
}
|
||||
|
||||
public override void OnStopClient() // Called on the client when closing connection
|
||||
@ -118,11 +123,11 @@ namespace QSB
|
||||
EventList.Reset();
|
||||
PlayerRegistry.PlayerList.ForEach(player => player.HudMarker?.Remove());
|
||||
|
||||
foreach (var player in PlayerRegistry.PlayerList.Where(x => x.NetId != PlayerRegistry.LocalPlayerId).ToList())
|
||||
foreach (var player in PlayerRegistry.PlayerList)
|
||||
{
|
||||
PlayerRegistry.GetPlayerNetIds(player).ForEach(CleanupNetworkBehaviour);
|
||||
PlayerRegistry.RemovePlayer(player.NetId);
|
||||
}
|
||||
PlayerRegistry.PlayerList.ForEach(x => PlayerRegistry.PlayerList.Remove(x));
|
||||
|
||||
_lobby.CanEditName = true;
|
||||
}
|
||||
@ -177,7 +182,7 @@ namespace QSB
|
||||
|
||||
public void CleanupNetworkBehaviour(uint netId)
|
||||
{
|
||||
DebugLog.DebugWrite($"Cleaning up object {netId}");
|
||||
DebugLog.DebugWrite($"Cleaning up netId {netId}");
|
||||
// Multiple networkbehaviours can use the same networkidentity (same netId), so get all of them
|
||||
var networkBehaviours = FindObjectsOfType<NetworkBehaviour>()
|
||||
.Where(x => x != null && x.netId.Value == netId);
|
||||
@ -188,12 +193,16 @@ namespace QSB
|
||||
if (transformSync != null)
|
||||
{
|
||||
PlayerRegistry.PlayerSyncObjects.Remove(transformSync);
|
||||
if (transformSync.SyncedTransform != null)
|
||||
if (transformSync.SyncedTransform != null && netId != PlayerRegistry.LocalPlayerId && !networkBehaviour.hasAuthority)
|
||||
{
|
||||
Destroy(transformSync.SyncedTransform.gameObject);
|
||||
}
|
||||
}
|
||||
Destroy(networkBehaviour.gameObject);
|
||||
|
||||
if (!networkBehaviour.hasAuthority)
|
||||
{
|
||||
Destroy(networkBehaviour.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,6 @@ namespace QSB.TransformSync
|
||||
{
|
||||
public static PlayerCameraSync LocalInstance { get; private set; }
|
||||
|
||||
protected override uint PlayerIdOffset => 2;
|
||||
|
||||
public override void OnStartLocalPlayer()
|
||||
{
|
||||
LocalInstance = this;
|
||||
@ -32,7 +30,7 @@ namespace QSB.TransformSync
|
||||
|
||||
protected override Transform InitRemoteTransform()
|
||||
{
|
||||
var body = new GameObject("PlayerCamera");
|
||||
var body = new GameObject("RemotePlayerCamera");
|
||||
|
||||
PlayerToolsManager.Init(body.transform);
|
||||
|
||||
@ -41,6 +39,10 @@ namespace QSB.TransformSync
|
||||
return body.transform;
|
||||
}
|
||||
|
||||
public override bool IsReady => Locator.GetPlayerTransform() != null && PlayerRegistry.PlayerExists(PlayerId);
|
||||
public override bool IsReady => Locator.GetPlayerTransform() != null
|
||||
&& Player != null
|
||||
&& PlayerRegistry.PlayerExists(Player.PlayerId)
|
||||
&& netId.Value != uint.MaxValue
|
||||
&& netId.Value != 0U;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using QSB.Tools;
|
||||
using OWML.Common;
|
||||
using QSB.Tools;
|
||||
using QSB.Utility;
|
||||
using UnityEngine;
|
||||
|
||||
@ -8,8 +9,6 @@ namespace QSB.TransformSync
|
||||
{
|
||||
public static PlayerProbeSync LocalInstance { get; private set; }
|
||||
|
||||
protected override uint PlayerIdOffset => 3;
|
||||
|
||||
private Transform _disabledSocket;
|
||||
|
||||
public override void OnStartLocalPlayer()
|
||||
@ -36,7 +35,14 @@ namespace QSB.TransformSync
|
||||
{
|
||||
var probe = GetProbe();
|
||||
|
||||
if (probe == null)
|
||||
{
|
||||
DebugLog.ToConsole("Error - Probe is null!", MessageType.Error);
|
||||
return default;
|
||||
}
|
||||
|
||||
var body = probe.InstantiateInactive();
|
||||
body.name = "RemoteProbeTransform";
|
||||
|
||||
Destroy(body.GetComponentInChildren<ProbeAnimatorController>());
|
||||
|
||||
@ -68,6 +74,11 @@ namespace QSB.TransformSync
|
||||
SyncedTransform.localPosition = ReferenceSector.Transform.InverseTransformPoint(_disabledSocket.position);
|
||||
}
|
||||
|
||||
public override bool IsReady => Locator.GetProbe() != null && PlayerRegistry.PlayerExists(PlayerId) && Player.IsReady;
|
||||
public override bool IsReady => Locator.GetProbe() != null
|
||||
&& Player != null
|
||||
&& PlayerRegistry.PlayerExists(Player.PlayerId)
|
||||
&& Player.IsReady
|
||||
&& netId.Value != uint.MaxValue
|
||||
&& netId.Value != 0U;
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,6 @@ namespace QSB.TransformSync
|
||||
{
|
||||
public static PlayerTransformSync LocalInstance { get; private set; }
|
||||
|
||||
protected override uint PlayerIdOffset => 0;
|
||||
|
||||
static PlayerTransformSync()
|
||||
{
|
||||
AnimControllerPatch.Init();
|
||||
@ -45,6 +43,11 @@ namespace QSB.TransformSync
|
||||
return body;
|
||||
}
|
||||
|
||||
public override bool IsReady => Locator.GetPlayerTransform() != null && PlayerRegistry.PlayerExists(PlayerId) && Player.IsReady;
|
||||
public override bool IsReady => Locator.GetPlayerTransform() != null
|
||||
&& Player != null
|
||||
&& PlayerRegistry.PlayerExists(Player.PlayerId)
|
||||
&& Player.IsReady
|
||||
&& netId.Value != uint.MaxValue
|
||||
&& netId.Value != 0U;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using QSB.Events;
|
||||
using QSB.Utility;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
@ -21,7 +20,7 @@ namespace QSB.TransformSync
|
||||
{
|
||||
return;
|
||||
}
|
||||
PlayerRegistry.GetSyncObjects<TransformSync>().Where(x => x.IsLocal).ToList().ForEach(CheckTransformSyncSector);
|
||||
PlayerRegistry.GetSyncObjects<TransformSync>().Where(x => x.hasAuthority).ToList().ForEach(CheckTransformSyncSector);
|
||||
_checkTimer = 0;
|
||||
}
|
||||
|
||||
@ -43,7 +42,6 @@ namespace QSB.TransformSync
|
||||
|
||||
private void SendSector(uint id, QSBSector sector)
|
||||
{
|
||||
DebugLog.DebugWrite($"Sending sector {sector.Name} for object {id}");
|
||||
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, id, sector);
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,6 @@ namespace QSB.TransformSync
|
||||
{
|
||||
public static ShipTransformSync LocalInstance { get; private set; }
|
||||
|
||||
protected override uint PlayerIdOffset => 1;
|
||||
|
||||
public override void OnStartLocalPlayer()
|
||||
{
|
||||
LocalInstance = this;
|
||||
@ -27,7 +25,7 @@ namespace QSB.TransformSync
|
||||
{
|
||||
var shipModel = GetShipModel();
|
||||
|
||||
var remoteTransform = new GameObject().transform;
|
||||
var remoteTransform = new GameObject("RemoteShipTransform").transform;
|
||||
|
||||
Instantiate(shipModel.Find("Module_Cockpit/Geo_Cockpit/Cockpit_Geometry/Cockpit_Exterior"), remoteTransform);
|
||||
Instantiate(shipModel.Find("Module_Cabin/Geo_Cabin/Cabin_Geometry/Cabin_Exterior"), remoteTransform);
|
||||
@ -51,6 +49,11 @@ namespace QSB.TransformSync
|
||||
return remoteTransform;
|
||||
}
|
||||
|
||||
public override bool IsReady => GetShipModel() != null && PlayerRegistry.PlayerExists(PlayerId) && Player.IsReady;
|
||||
public override bool IsReady => GetShipModel() != null
|
||||
&& Player != null
|
||||
&& PlayerRegistry.PlayerExists(Player.PlayerId)
|
||||
&& Player.IsReady
|
||||
&& netId.Value != uint.MaxValue
|
||||
&& netId.Value != 0U;
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ namespace QSB.TransformSync
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
DebugLog.DebugWrite($"Awake of {AttachedNetId} ({GetType().Name})");
|
||||
PlayerRegistry.PlayerSyncObjects.Add(this);
|
||||
DontDestroyOnLoad(gameObject);
|
||||
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
|
||||
@ -33,6 +34,7 @@ namespace QSB.TransformSync
|
||||
|
||||
protected void Init()
|
||||
{
|
||||
DebugLog.DebugWrite($"Init of {AttachedNetId} ({Player.PlayerId}.{GetType().Name})");
|
||||
ReferenceSector = QSBSectorManager.Instance.GetStartPlanetSector();
|
||||
SyncedTransform = hasAuthority ? InitLocalTransform() : InitRemoteTransform();
|
||||
if (!hasAuthority)
|
||||
@ -52,18 +54,23 @@ namespace QSB.TransformSync
|
||||
else if (_isInitialized && !IsReady)
|
||||
{
|
||||
_isInitialized = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (SyncedTransform == null || !_isInitialized)
|
||||
if (!_isInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get which sector should be used as a reference point
|
||||
if (SyncedTransform == null)
|
||||
{
|
||||
DebugLog.ToConsole($"SyncedTransform {AttachedNetId} ({Player.PlayerId}.{GetType().Name}) is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ReferenceSector == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - TransformSync with id {netId.Value} doesn't have a reference sector", MessageType.Error);
|
||||
DebugLog.ToConsole($"Error - {AttachedNetId} ({Player.PlayerId}.{GetType().Name}) doesn't have a reference sector", MessageType.Error);
|
||||
}
|
||||
|
||||
UpdateTransform();
|
||||
@ -71,18 +78,18 @@ namespace QSB.TransformSync
|
||||
|
||||
protected virtual void UpdateTransform()
|
||||
{
|
||||
if (hasAuthority) // If this script is attached to the client's own body on the client's side.
|
||||
if (hasAuthority) // If this script is attached to the client's own body on the client's side.
|
||||
{
|
||||
if (ReferenceSector.Sector == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Sector is null for referencesector for {GetType().Name}!", MessageType.Error);
|
||||
DebugLog.ToConsole($"Sector is null for referencesector for {AttachedNetId} ({Player.PlayerId}.{GetType().Name})!", MessageType.Error);
|
||||
}
|
||||
transform.position = ReferenceSector.Transform.InverseTransformPoint(SyncedTransform.position);
|
||||
transform.rotation = ReferenceSector.Transform.InverseTransformRotation(SyncedTransform.rotation);
|
||||
return;
|
||||
}
|
||||
|
||||
// If this script is attached to any other body, eg the representations of other players
|
||||
// If this script is attached to any other body, eg the representations of other players
|
||||
if (SyncedTransform.position == Vector3.zero)
|
||||
{
|
||||
Hide();
|
||||
@ -100,9 +107,12 @@ namespace QSB.TransformSync
|
||||
{
|
||||
_positionSmoothVelocity = Vector3.zero;
|
||||
ReferenceSector = sector;
|
||||
SyncedTransform.SetParent(sector.Transform, true);
|
||||
transform.position = sector.Transform.InverseTransformPoint(SyncedTransform.position);
|
||||
transform.rotation = sector.Transform.InverseTransformRotation(SyncedTransform.rotation);
|
||||
if (!hasAuthority)
|
||||
{
|
||||
SyncedTransform.SetParent(sector.Transform, true);
|
||||
transform.position = sector.Transform.InverseTransformPoint(SyncedTransform.position);
|
||||
transform.rotation = sector.Transform.InverseTransformRotation(SyncedTransform.rotation);
|
||||
}
|
||||
}
|
||||
|
||||
private void Show()
|
||||
@ -124,4 +134,4 @@ namespace QSB.TransformSync
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
20
QSB/Utility/ListExtensions.cs
Normal file
20
QSB/Utility/ListExtensions.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QSB.Utility
|
||||
{
|
||||
public static class ListExtensions
|
||||
{
|
||||
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
|
||||
{
|
||||
var seenKeys = new HashSet<TKey>();
|
||||
foreach (var element in source)
|
||||
{
|
||||
if (seenKeys.Add(keySelector(element)))
|
||||
{
|
||||
yield return element;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
using QSB.WorldSync;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.GeyserSync
|
||||
namespace QSB.WorldSync
|
||||
{
|
||||
public class GeyserMessage : WorldObjectMessage
|
||||
public class BoolWorldObjectMessage : WorldObjectMessage
|
||||
{
|
||||
public bool State { get; set; }
|
||||
|
@ -25,6 +25,5 @@ namespace QSB.WorldSync
|
||||
{
|
||||
return GetObjects<T>().FirstOrDefault(x => x.ObjectId == id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,6 @@
|
||||
"settings": {
|
||||
"defaultServerIP": "localhost",
|
||||
"port": 7777,
|
||||
"debugMode": false
|
||||
"debugMode": true
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
{
|
||||
"filename": "QSB.dll",
|
||||
"author": "Rai, Alek & Nebula",
|
||||
"author": "Raicuparta, AmazingAlek & misternebula",
|
||||
"name": "Quantum Space Buddies",
|
||||
"description": "Adds online multiplayer to the game.",
|
||||
"uniqueName": "Raicuparta.QuantumSpaceBuddies",
|
||||
"version": "0.5.1",
|
||||
"version": "0.6.0",
|
||||
"owmlVersion": "0.7.3"
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ MonoBehaviour:
|
||||
m_ScriptCRCCheck: 1
|
||||
m_MaxDelay: 0.01
|
||||
m_LogLevel: 2
|
||||
m_PlayerPrefab: {fileID: 1480237966074134, guid: 163f71f5a4ce8e543bbf5632a3585dc7,
|
||||
m_PlayerPrefab: {fileID: 1211347487444314, guid: 163f71f5a4ce8e543bbf5632a3585dc7,
|
||||
type: 2}
|
||||
m_AutoCreatePlayer: 1
|
||||
m_PlayerSpawnMethod: 0
|
||||
|
@ -20,7 +20,7 @@ GameObject:
|
||||
m_Component:
|
||||
- component: {fileID: 4562567225116386}
|
||||
- component: {fileID: 114951036537616502}
|
||||
- component: {fileID: 114833759961836714}
|
||||
- component: {fileID: 114287548021608114}
|
||||
m_Layer: 0
|
||||
m_Name: NetworkPlayer
|
||||
m_TagString: Untagged
|
||||
@ -41,7 +41,7 @@ Transform:
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &114833759961836714
|
||||
--- !u!114 &114287548021608114
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 1
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
|
Loading…
x
Reference in New Issue
Block a user