Merge branch 'dev' into clear-logs

This commit is contained in:
Mister_Nebula 2021-12-12 10:42:19 +00:00
commit 8612bbd810
66 changed files with 107 additions and 352 deletions

View File

@ -14,6 +14,7 @@ namespace QSB.Anglerfish.TransformSync
public override bool IsPlayerObject => false; public override bool IsPlayerObject => false;
private QSBAngler _qsbAngler; private QSBAngler _qsbAngler;
public static readonly List<AnglerfishController> Anglers = new();
private static readonly List<AnglerTransformSync> _instances = new(); private static readonly List<AnglerTransformSync> _instances = new();
protected override OWRigidbody GetRigidbody() protected override OWRigidbody GetRigidbody()
@ -35,7 +36,7 @@ namespace QSB.Anglerfish.TransformSync
protected override void Init() protected override void Init()
{ {
_qsbAngler = QSBWorldSync.GetWorldFromId<QSBAngler>(_instances.IndexOf(this)); _qsbAngler = QSBWorldSync.GetWorldFromUnity<QSBAngler>(Anglers[_instances.IndexOf(this)]);
_qsbAngler.TransformSync = this; _qsbAngler.TransformSync = this;
base.Init(); base.Init();

View File

@ -14,11 +14,9 @@ namespace QSB.Anglerfish.WorldObjects
private Vector3 _lastTargetPosition; private Vector3 _lastTargetPosition;
public override void Init(AnglerfishController attachedObject, int id) public override void Init()
{ {
ObjectId = id; AnglerTransformSync.Anglers.Add(AttachedObject);
AttachedObject = attachedObject;
if (QSBCore.IsHost) if (QSBCore.IsHost)
{ {
QNetworkServer.Spawn(Object.Instantiate(QSBNetworkManager.Instance.AnglerPrefab)); QNetworkServer.Spawn(Object.Instantiate(QSBNetworkManager.Instance.AnglerPrefab));
@ -41,6 +39,7 @@ namespace QSB.Anglerfish.WorldObjects
public override void OnRemoval() public override void OnRemoval()
{ {
AnglerTransformSync.Anglers.Remove(AttachedObject);
if (QSBCore.IsHost) if (QSBCore.IsHost)
{ {
TransformSync.NetIdentity.UnregisterAuthQueue(); TransformSync.NetIdentity.UnregisterAuthQueue();

View File

@ -153,7 +153,7 @@ namespace QSB.Animation.NPC.Patches
return true; return true;
} }
var id = QSBWorldSync.GetIdFromTypeSubset(ownerOfThis); var id = ownerOfThis.ObjectId;
QSBEventManager.FireEvent(EventNames.QSBNpcAnimEvent, AnimationEvent.StartConversation, id); QSBEventManager.FireEvent(EventNames.QSBNpcAnimEvent, AnimationEvent.StartConversation, id);
return true; return true;
} }
@ -169,7 +169,7 @@ namespace QSB.Animation.NPC.Patches
return true; return true;
} }
var id = QSBWorldSync.GetIdFromTypeSubset(ownerOfThis); var id = ownerOfThis.ObjectId;
QSBEventManager.FireEvent(EventNames.QSBNpcAnimEvent, AnimationEvent.EndConversation, id); QSBEventManager.FireEvent(EventNames.QSBNpcAnimEvent, AnimationEvent.EndConversation, id);
return true; return true;
} }

View File

@ -1,6 +1,8 @@
namespace QSB.Animation.NPC.WorldObjects using QSB.WorldSync;
namespace QSB.Animation.NPC.WorldObjects
{ {
public interface INpcAnimController public interface INpcAnimController : IWorldObject
{ {
CharacterDialogueTree GetDialogueTree(); CharacterDialogueTree GetDialogueTree();
void StartConversation(); void StartConversation();

View File

@ -7,12 +7,6 @@ namespace QSB.Animation.NPC.WorldObjects
internal abstract class NpcAnimController<T> : WorldObject<T>, INpcAnimController internal abstract class NpcAnimController<T> : WorldObject<T>, INpcAnimController
where T : MonoBehaviour where T : MonoBehaviour
{ {
public override void Init(T controller, int id)
{
ObjectId = id;
AttachedObject = controller;
}
public abstract CharacterDialogueTree GetDialogueTree(); public abstract CharacterDialogueTree GetDialogueTree();
public virtual void StartConversation() public virtual void StartConversation()

View File

@ -8,12 +8,6 @@ namespace QSB.Animation.NPC.WorldObjects
{ {
private readonly List<PlayerInfo> _playersInHeadZone = new(); private readonly List<PlayerInfo> _playersInHeadZone = new();
public override void Init(SolanumAnimController controller, int id)
{
ObjectId = id;
AttachedObject = controller;
}
public List<PlayerInfo> GetPlayersInHeadZone() public List<PlayerInfo> GetPlayersInHeadZone()
=> _playersInHeadZone; => _playersInHeadZone;

View File

@ -5,12 +5,6 @@ namespace QSB.CampfireSync.WorldObjects
{ {
public class QSBCampfire : WorldObject<Campfire> public class QSBCampfire : WorldObject<Campfire>
{ {
public override void Init(Campfire campfire, int id)
{
ObjectId = id;
AttachedObject = campfire;
}
public void StartRoasting() public void StartRoasting()
=> AttachedObject => AttachedObject
.GetType() .GetType()

View File

@ -4,10 +4,5 @@ namespace QSB.EchoesOfTheEye.AirlockSync.WorldObjects
{ {
internal class QSBGhostAirlock : WorldObject<GhostAirlock> internal class QSBGhostAirlock : WorldObject<GhostAirlock>
{ {
public override void Init(GhostAirlock airlock, int id)
{
ObjectId = id;
AttachedObject = airlock;
}
} }
} }

View File

@ -4,10 +4,5 @@ namespace QSB.EchoesOfTheEye.LightSensorSync.WorldObjects
{ {
internal class QSBSingleLightSensor : WorldObject<SingleLightSensor> internal class QSBSingleLightSensor : WorldObject<SingleLightSensor>
{ {
public override void Init(SingleLightSensor sensor, int id)
{
ObjectId = id;
AttachedObject = sensor;
}
} }
} }

View File

@ -13,15 +13,15 @@ namespace QSB.ElevatorSync.WorldObjects
private OWAudioSource _owAudioSourceLP; private OWAudioSource _owAudioSourceLP;
private OWTriggerVolume _elevatorTrigger; private OWTriggerVolume _elevatorTrigger;
public override void Init(Elevator elevator, int id) public override void Init()
{ {
AttachedObject = elevator; StartDelayedReady();
ObjectId = id;
QSBCore.UnityEvents.RunWhen(() => AttachedObject._interactVolume != null, InitValues); QSBCore.UnityEvents.RunWhen(() => AttachedObject._interactVolume != null, InitValues);
} }
private void InitValues() private void InitValues()
{ {
FinishDelayedReady();
_startLocalPos = AttachedObject._startLocalPos; _startLocalPos = AttachedObject._startLocalPos;
_endLocalPos = AttachedObject._endLocalPos; _endLocalPos = AttachedObject._endLocalPos;
_interactVolume = AttachedObject._interactVolume; _interactVolume = AttachedObject._interactVolume;

View File

@ -6,10 +6,8 @@ namespace QSB.GeyserSync.WorldObjects
{ {
public class QSBGeyser : WorldObject<GeyserController> public class QSBGeyser : WorldObject<GeyserController>
{ {
public override void Init(GeyserController geyserController, int id) public override void Init()
{ {
ObjectId = id;
AttachedObject = geyserController;
AttachedObject.OnGeyserActivateEvent += () => HandleEvent(true); AttachedObject.OnGeyserActivateEvent += () => HandleEvent(true);
AttachedObject.OnGeyserDeactivateEvent += () => HandleEvent(false); AttachedObject.OnGeyserDeactivateEvent += () => HandleEvent(false);
} }

View File

@ -42,7 +42,7 @@ namespace QSB.ItemSync.Events
case SocketEventType.StartUnsocket: case SocketEventType.StartUnsocket:
if (!socketWorldObject.IsSocketOccupied()) if (!socketWorldObject.IsSocketOccupied())
{ {
DebugLog.ToConsole($"Warning - Trying to start unsocket on socket that is unoccupied! Socket:{(socketWorldObject as IWorldObject).Name}"); DebugLog.ToConsole($"Warning - Trying to start unsocket on socket that is unoccupied! Socket:{socketWorldObject.Name}");
return; return;
} }

View File

@ -20,8 +20,8 @@ namespace QSB.ItemSync.Patches
[HarmonyPatch(typeof(ItemTool), nameof(ItemTool.MoveItemToCarrySocket))] [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.MoveItemToCarrySocket))]
public static bool ItemTool_MoveItemToCarrySocket(OWItem item) public static bool ItemTool_MoveItemToCarrySocket(OWItem item)
{ {
var qsbObj = (IQSBOWItem)QSBWorldSync.GetWorldFromUnity(item); var qsbObj = QSBWorldSync.GetWorldFromUnity<IQSBOWItem>(item);
var itemId = QSBWorldSync.GetIdFromTypeSubset(qsbObj); var itemId = qsbObj.ObjectId;
QSBPlayerManager.LocalPlayer.HeldItem = qsbObj; QSBPlayerManager.LocalPlayer.HeldItem = qsbObj;
QSBEventManager.FireEvent(EventNames.QSBMoveToCarry, itemId); QSBEventManager.FireEvent(EventNames.QSBMoveToCarry, itemId);
return true; return true;
@ -31,9 +31,9 @@ namespace QSB.ItemSync.Patches
[HarmonyPatch(typeof(ItemTool), nameof(ItemTool.SocketItem))] [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.SocketItem))]
public static bool ItemTool_SocketItem(OWItem ____heldItem, OWItemSocket socket) public static bool ItemTool_SocketItem(OWItem ____heldItem, OWItemSocket socket)
{ {
var qsbObj = (IQSBOWItem)QSBWorldSync.GetWorldFromUnity(____heldItem); var qsbObj = QSBWorldSync.GetWorldFromUnity<IQSBOWItem>(____heldItem);
var socketId = QSBWorldSync.GetIdFromTypeSubset((IQSBOWItemSocket)QSBWorldSync.GetWorldFromUnity(socket)); var socketId = QSBWorldSync.GetWorldFromUnity<IQSBOWItemSocket>(socket).ObjectId;
var itemId = QSBWorldSync.GetIdFromTypeSubset(qsbObj); var itemId = qsbObj.ObjectId;
QSBPlayerManager.LocalPlayer.HeldItem = null; QSBPlayerManager.LocalPlayer.HeldItem = null;
QSBEventManager.FireEvent(EventNames.QSBSocketItem, socketId, itemId, SocketEventType.Socket); QSBEventManager.FireEvent(EventNames.QSBSocketItem, socketId, itemId, SocketEventType.Socket);
return true; return true;
@ -43,9 +43,9 @@ namespace QSB.ItemSync.Patches
[HarmonyPatch(typeof(ItemTool), nameof(ItemTool.StartUnsocketItem))] [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.StartUnsocketItem))]
public static bool ItemTool_StartUnsocketItem(OWItemSocket socket) public static bool ItemTool_StartUnsocketItem(OWItemSocket socket)
{ {
var item = (IQSBOWItem)QSBWorldSync.GetWorldFromUnity(socket.GetSocketedItem()); var item = QSBWorldSync.GetWorldFromUnity<IQSBOWItem>(socket.GetSocketedItem());
QSBPlayerManager.LocalPlayer.HeldItem = item; QSBPlayerManager.LocalPlayer.HeldItem = item;
var socketId = QSBWorldSync.GetIdFromTypeSubset((IQSBOWItemSocket)QSBWorldSync.GetWorldFromUnity(socket)); var socketId = QSBWorldSync.GetWorldFromUnity<IQSBOWItemSocket>(socket).ObjectId;
QSBEventManager.FireEvent(EventNames.QSBSocketItem, socketId, 0, SocketEventType.StartUnsocket); QSBEventManager.FireEvent(EventNames.QSBSocketItem, socketId, 0, SocketEventType.StartUnsocket);
return true; return true;
} }
@ -54,7 +54,7 @@ namespace QSB.ItemSync.Patches
[HarmonyPatch(typeof(ItemTool), nameof(ItemTool.CompleteUnsocketItem))] [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.CompleteUnsocketItem))]
public static bool ItemTool_CompleteUnsocketItem(OWItem ____heldItem) public static bool ItemTool_CompleteUnsocketItem(OWItem ____heldItem)
{ {
var itemId = QSBWorldSync.GetIdFromTypeSubset((IQSBOWItem)QSBWorldSync.GetWorldFromUnity(____heldItem)); var itemId = QSBWorldSync.GetWorldFromUnity<IQSBOWItem>(____heldItem).ObjectId;
QSBEventManager.FireEvent(EventNames.QSBSocketItem, 0, itemId, SocketEventType.CompleteUnsocket); QSBEventManager.FireEvent(EventNames.QSBSocketItem, 0, itemId, SocketEventType.CompleteUnsocket);
return true; return true;
} }
@ -90,7 +90,7 @@ namespace QSB.ItemSync.Patches
var parent = (customDropTarget == null) var parent = (customDropTarget == null)
? targetRigidbody.transform ? targetRigidbody.transform
: customDropTarget.GetItemDropTargetTransform(hit.collider.gameObject); : customDropTarget.GetItemDropTargetTransform(hit.collider.gameObject);
var objectId = QSBWorldSync.GetIdFromTypeSubset((IQSBOWItem)QSBWorldSync.GetWorldFromUnity(____heldItem)); var objectId = QSBWorldSync.GetWorldFromUnity<IQSBOWItem>(____heldItem).ObjectId;
____heldItem.DropItem(hit.point, hit.normal, parent, sector, customDropTarget); ____heldItem.DropItem(hit.point, hit.normal, parent, sector, customDropTarget);
____heldItem = null; ____heldItem = null;
QSBPlayerManager.LocalPlayer.HeldItem = null; QSBPlayerManager.LocalPlayer.HeldItem = null;

View File

@ -3,7 +3,7 @@ using UnityEngine;
namespace QSB.ItemSync.WorldObjects.Items namespace QSB.ItemSync.WorldObjects.Items
{ {
public interface IQSBOWItem : IWorldObjectTypeSubset public interface IQSBOWItem : IWorldObject
{ {
ItemType GetItemType(); ItemType GetItemType();
void SetColliderActivation(bool active); void SetColliderActivation(bool active);

View File

@ -2,11 +2,5 @@
{ {
internal class QSBNomaiConversationStone : QSBOWItem<NomaiConversationStone> internal class QSBNomaiConversationStone : QSBOWItem<NomaiConversationStone>
{ {
public override void Init(NomaiConversationStone attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
base.Init(attachedObject, id);
}
} }
} }

View File

@ -17,9 +17,9 @@ namespace QSB.ItemSync.WorldObjects.Items
public QSBSector InitialSector { get; private set; } public QSBSector InitialSector { get; private set; }
public uint HoldingPlayer { get; private set; } public uint HoldingPlayer { get; private set; }
public override void Init(T attachedObject, int id) public override void Init()
{ {
if (attachedObject == null) if (AttachedObject == null)
{ {
DebugLog.ToConsole($"Error - AttachedObject is null! Type:{GetType().Name}", OWML.Common.MessageType.Error); DebugLog.ToConsole($"Error - AttachedObject is null! Type:{GetType().Name}", OWML.Common.MessageType.Error);
return; return;
@ -30,10 +30,10 @@ namespace QSB.ItemSync.WorldObjects.Items
{ {
FinishDelayedReady(); FinishDelayedReady();
InitialParent = attachedObject.transform.parent; InitialParent = AttachedObject.transform.parent;
InitialPosition = attachedObject.transform.localPosition; InitialPosition = AttachedObject.transform.localPosition;
InitialRotation = attachedObject.transform.localRotation; InitialRotation = AttachedObject.transform.localRotation;
var initialSector = attachedObject.GetSector(); var initialSector = AttachedObject.GetSector();
if (initialSector != null) if (initialSector != null)
{ {
InitialSector = QSBWorldSync.GetWorldFromUnity<QSBSector>(initialSector); InitialSector = QSBWorldSync.GetWorldFromUnity<QSBSector>(initialSector);
@ -41,12 +41,12 @@ namespace QSB.ItemSync.WorldObjects.Items
if (InitialParent == null) if (InitialParent == null)
{ {
DebugLog.ToConsole($"Warning - InitialParent of {attachedObject.name} is null!", OWML.Common.MessageType.Warning); DebugLog.ToConsole($"Warning - InitialParent of {AttachedObject.name} is null!", OWML.Common.MessageType.Warning);
} }
if (InitialParent?.GetComponent<OWItemSocket>() != null) if (InitialParent?.GetComponent<OWItemSocket>() != null)
{ {
var qsbObj = (IQSBOWItemSocket)QSBWorldSync.GetWorldFromUnity(InitialParent.GetComponent<OWItemSocket>()); var qsbObj = QSBWorldSync.GetWorldFromUnity<IQSBOWItemSocket>(InitialParent.GetComponent<OWItemSocket>());
InitialSocket = qsbObj; InitialSocket = qsbObj;
} }
}); });

View File

@ -2,13 +2,6 @@
{ {
internal class QSBScrollItem : QSBOWItem<ScrollItem> internal class QSBScrollItem : QSBOWItem<ScrollItem>
{ {
public override void Init(ScrollItem attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
base.Init(attachedObject, id);
}
public override void PlaySocketAnimation() public override void PlaySocketAnimation()
=> AttachedObject.PlaySocketAnimation(); => AttachedObject.PlaySocketAnimation();

View File

@ -2,13 +2,6 @@
{ {
internal class QSBSharedStone : QSBOWItem<SharedStone> internal class QSBSharedStone : QSBOWItem<SharedStone>
{ {
public override void Init(SharedStone attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
base.Init(attachedObject, id);
}
public override void PlaySocketAnimation() public override void PlaySocketAnimation()
=> AttachedObject.PlaySocketAnimation(); => AttachedObject.PlaySocketAnimation();

View File

@ -2,13 +2,6 @@
{ {
internal class QSBSimpleLanternItem : QSBOWItem<SimpleLanternItem> internal class QSBSimpleLanternItem : QSBOWItem<SimpleLanternItem>
{ {
public override void Init(SimpleLanternItem attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
base.Init(attachedObject, id);
}
public override void PlaySocketAnimation() public override void PlaySocketAnimation()
=> AttachedObject.PlaySocketAnimation(); => AttachedObject.PlaySocketAnimation();

View File

@ -2,13 +2,6 @@
{ {
internal class QSBSlideReelItem : QSBOWItem<SlideReelItem> internal class QSBSlideReelItem : QSBOWItem<SlideReelItem>
{ {
public override void Init(SlideReelItem attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
base.Init(attachedObject, id);
}
public override void PlaySocketAnimation() public override void PlaySocketAnimation()
=> AttachedObject.PlaySocketAnimation(); => AttachedObject.PlaySocketAnimation();

View File

@ -2,13 +2,6 @@
{ {
internal class QSBWarpCoreItem : QSBOWItem<WarpCoreItem> internal class QSBWarpCoreItem : QSBOWItem<WarpCoreItem>
{ {
public override void Init(WarpCoreItem attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
base.Init(attachedObject, id);
}
public bool IsVesselCoreType() public bool IsVesselCoreType()
=> AttachedObject.IsVesselCoreType(); => AttachedObject.IsVesselCoreType();
} }

View File

@ -3,7 +3,7 @@ using QSB.WorldSync;
namespace QSB.ItemSync.WorldObjects.Sockets namespace QSB.ItemSync.WorldObjects.Sockets
{ {
public interface IQSBOWItemSocket : IWorldObjectTypeSubset public interface IQSBOWItemSocket : IWorldObject
{ {
bool AcceptsItem(IQSBOWItem item); bool AcceptsItem(IQSBOWItem item);
bool IsSocketOccupied(); bool IsSocketOccupied();

View File

@ -2,11 +2,5 @@
{ {
internal class QSBNomaiConversationStoneSocket : QSBOWItemSocket<NomaiConversationStoneSocket> internal class QSBNomaiConversationStoneSocket : QSBOWItemSocket<NomaiConversationStoneSocket>
{ {
public override void Init(NomaiConversationStoneSocket attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
base.Init(attachedObject, id);
}
} }
} }

View File

@ -6,8 +6,6 @@ namespace QSB.ItemSync.WorldObjects.Sockets
internal class QSBOWItemDoubleSocket<T> : WorldObject<T>, IQSBOWItemSocket internal class QSBOWItemDoubleSocket<T> : WorldObject<T>, IQSBOWItemSocket
where T : OWItemSocket where T : OWItemSocket
{ {
public override void Init(T attachedObject, int id) { }
public virtual bool AcceptsItem(IQSBOWItem item) public virtual bool AcceptsItem(IQSBOWItem item)
{ {
var itemType = item.GetItemType(); var itemType = item.GetItemType();
@ -19,9 +17,9 @@ namespace QSB.ItemSync.WorldObjects.Sockets
=> AttachedObject.IsSocketOccupied(); => AttachedObject.IsSocketOccupied();
public virtual bool PlaceIntoSocket(IQSBOWItem item) public virtual bool PlaceIntoSocket(IQSBOWItem item)
=> AttachedObject.PlaceIntoSocket((OWItem)(item as IWorldObject).ReturnObject()); => AttachedObject.PlaceIntoSocket((OWItem)item.ReturnObject());
public virtual IQSBOWItem RemoveFromSocket() public virtual IQSBOWItem RemoveFromSocket()
=> (IQSBOWItem)QSBWorldSync.GetWorldFromUnity(AttachedObject.RemoveFromSocket()); => QSBWorldSync.GetWorldFromUnity<IQSBOWItem>(AttachedObject.RemoveFromSocket());
} }
} }

View File

@ -6,8 +6,6 @@ namespace QSB.ItemSync.WorldObjects.Sockets
internal class QSBOWItemSocket<T> : WorldObject<T>, IQSBOWItemSocket internal class QSBOWItemSocket<T> : WorldObject<T>, IQSBOWItemSocket
where T : OWItemSocket where T : OWItemSocket
{ {
public override void Init(T attachedObject, int id) { }
public virtual bool AcceptsItem(IQSBOWItem item) public virtual bool AcceptsItem(IQSBOWItem item)
{ {
var itemType = item.GetItemType(); var itemType = item.GetItemType();
@ -19,9 +17,9 @@ namespace QSB.ItemSync.WorldObjects.Sockets
=> AttachedObject.IsSocketOccupied(); => AttachedObject.IsSocketOccupied();
public virtual bool PlaceIntoSocket(IQSBOWItem item) public virtual bool PlaceIntoSocket(IQSBOWItem item)
=> AttachedObject.PlaceIntoSocket((OWItem)(item as IWorldObject).ReturnObject()); => AttachedObject.PlaceIntoSocket((OWItem)item.ReturnObject());
public virtual IQSBOWItem RemoveFromSocket() public virtual IQSBOWItem RemoveFromSocket()
=> (IQSBOWItem)QSBWorldSync.GetWorldFromUnity(AttachedObject.RemoveFromSocket()); => QSBWorldSync.GetWorldFromUnity<IQSBOWItem>(AttachedObject.RemoveFromSocket());
} }
} }

View File

@ -2,11 +2,5 @@
{ {
internal class QSBScrollSocket : QSBOWItemSocket<ScrollSocket> internal class QSBScrollSocket : QSBOWItemSocket<ScrollSocket>
{ {
public override void Init(ScrollSocket attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
base.Init(attachedObject, id);
}
} }
} }

View File

@ -2,11 +2,5 @@
{ {
internal class QSBSharedStoneSocket : QSBOWItemSocket<SharedStoneSocket> internal class QSBSharedStoneSocket : QSBOWItemSocket<SharedStoneSocket>
{ {
public override void Init(SharedStoneSocket attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
base.Init(attachedObject, id);
}
} }
} }

View File

@ -2,11 +2,5 @@
{ {
internal class QSBSlideProjectorSocket : QSBOWItemDoubleSocket<SlideProjectorSocket> internal class QSBSlideProjectorSocket : QSBOWItemDoubleSocket<SlideProjectorSocket>
{ {
public override void Init(SlideProjectorSocket attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
base.Init(attachedObject, id);
}
} }
} }

View File

@ -2,11 +2,5 @@
{ {
internal class QSBSlideReelSocket : QSBOWItemSocket<SlideReelSocket> internal class QSBSlideReelSocket : QSBOWItemSocket<SlideReelSocket>
{ {
public override void Init(SlideReelSocket attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
base.Init(attachedObject, id);
}
} }
} }

View File

@ -2,11 +2,5 @@
{ {
internal class QSBWarpCoreSocket : QSBOWItemSocket<WarpCoreSocket> internal class QSBWarpCoreSocket : QSBOWItemSocket<WarpCoreSocket>
{ {
public override void Init(WarpCoreSocket attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
base.Init(attachedObject, id);
}
} }
} }

View File

@ -16,6 +16,7 @@ namespace QSB.JellyfishSync.TransformSync
public override bool IsPlayerObject => false; public override bool IsPlayerObject => false;
private QSBJellyfish _qsbJellyfish; private QSBJellyfish _qsbJellyfish;
public static readonly List<JellyfishController> Jellyfish = new();
private static readonly List<JellyfishTransformSync> _instances = new(); private static readonly List<JellyfishTransformSync> _instances = new();
protected override OWRigidbody GetRigidbody() protected override OWRigidbody GetRigidbody()
@ -37,7 +38,7 @@ namespace QSB.JellyfishSync.TransformSync
protected override void Init() protected override void Init()
{ {
_qsbJellyfish = QSBWorldSync.GetWorldFromId<QSBJellyfish>(_instances.IndexOf(this)); _qsbJellyfish = QSBWorldSync.GetWorldFromUnity<QSBJellyfish>(Jellyfish[_instances.IndexOf(this)]);
_qsbJellyfish.TransformSync = this; _qsbJellyfish.TransformSync = this;
base.Init(); base.Init();

View File

@ -11,12 +11,11 @@ namespace QSB.JellyfishSync.WorldObjects
public JellyfishTransformSync TransformSync; public JellyfishTransformSync TransformSync;
private AlignWithTargetBody _alignWithTargetBody; private AlignWithTargetBody _alignWithTargetBody;
public override void Init(JellyfishController attachedObject, int id) public override void Init()
{ {
ObjectId = id;
AttachedObject = attachedObject;
_alignWithTargetBody = AttachedObject.GetRequiredComponent<AlignWithTargetBody>(); _alignWithTargetBody = AttachedObject.GetRequiredComponent<AlignWithTargetBody>();
JellyfishTransformSync.Jellyfish.Add(AttachedObject);
if (QSBCore.IsHost) if (QSBCore.IsHost)
{ {
QNetworkServer.Spawn(Object.Instantiate(QSBNetworkManager.Instance.JellyfishPrefab)); QNetworkServer.Spawn(Object.Instantiate(QSBNetworkManager.Instance.JellyfishPrefab));
@ -39,6 +38,7 @@ namespace QSB.JellyfishSync.WorldObjects
public override void OnRemoval() public override void OnRemoval()
{ {
JellyfishTransformSync.Jellyfish.Remove(AttachedObject);
if (QSBCore.IsHost) if (QSBCore.IsHost)
{ {
TransformSync.NetIdentity.UnregisterAuthQueue(); TransformSync.NetIdentity.UnregisterAuthQueue();

View File

@ -5,10 +5,8 @@ namespace QSB.MeteorSync.WorldObjects
{ {
public class QSBFragment : WorldObject<FragmentIntegrity> public class QSBFragment : WorldObject<FragmentIntegrity>
{ {
public override void Init(FragmentIntegrity attachedObject, int id) public override void Init()
{ {
ObjectId = id;
AttachedObject = attachedObject;
DetachableFragment = AttachedObject.GetComponent<DetachableFragment>(); DetachableFragment = AttachedObject.GetComponent<DetachableFragment>();
if (QSBCore.IsHost) if (QSBCore.IsHost)

View File

@ -5,12 +5,6 @@ namespace QSB.MeteorSync.WorldObjects
{ {
public class QSBMeteor : WorldObject<MeteorController> public class QSBMeteor : WorldObject<MeteorController>
{ {
public override void Init(MeteorController attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
}
public static bool IsSpecialImpact(GameObject go) => public static bool IsSpecialImpact(GameObject go) =>
go == Locator.GetPlayerCollider().gameObject || go == Locator.GetProbe()._anchor._collider.gameObject; go == Locator.GetPlayerCollider().gameObject || go == Locator.GetProbe()._anchor._collider.gameObject;

View File

@ -4,12 +4,6 @@ namespace QSB.MeteorSync.WorldObjects
{ {
public class QSBMeteorLauncher : WorldObject<MeteorLauncher> public class QSBMeteorLauncher : WorldObject<MeteorLauncher>
{ {
public override void Init(MeteorLauncher attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
}
public int MeteorId; public int MeteorId;
public float LaunchSpeed; public float LaunchSpeed;

View File

@ -11,10 +11,8 @@ namespace QSB.OrbSync.WorldObjects
private bool _initialized; private bool _initialized;
public override void Init(NomaiInterfaceSlot slot, int id) public override void Init()
{ {
ObjectId = id;
AttachedObject = slot;
_initialized = true; _initialized = true;
} }

View File

@ -108,11 +108,8 @@ namespace QSB.Player.Events
=> QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.VesselComputer, vesselComputer.ObjectId, id)); => QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.VesselComputer, vesselComputer.ObjectId, id));
} }
var list = QSBWorldSync.GetWorldObjects<IQSBQuantumObject>().ToList(); QSBWorldSync.GetWorldObjects<IQSBQuantumObject>().ForEach(x
for (var i = 0; i < list.Count; i++) => QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, x.ObjectId, x.ControllingPlayer));
{
QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, i, list[i].ControllingPlayer);
}
QSBWorldSync.GetWorldObjects<QSBCampfire>().ForEach(campfire QSBWorldSync.GetWorldObjects<QSBCampfire>().ForEach(campfire
=> QSBEventManager.FireEvent(EventNames.QSBCampfireState, campfire.ObjectId, campfire.GetState())); => QSBEventManager.FireEvent(EventNames.QSBCampfireState, campfire.ObjectId, campfire.GetState()));

View File

@ -27,7 +27,7 @@ namespace QSB.Player
if (_previousCollidingQuantumObject != collidingQuantumObject) if (_previousCollidingQuantumObject != collidingQuantumObject)
{ {
var objectIndex = (collidingQuantumObject != null) var objectIndex = (collidingQuantumObject != null)
? QSBWorldSync.GetIdFromTypeSubset((IQSBQuantumObject)QSBWorldSync.GetWorldFromUnity(collidingQuantumObject)) ? QSBWorldSync.GetWorldFromUnity<IQSBQuantumObject>(collidingQuantumObject).ObjectId
: -1; : -1;
QSBEventManager.FireEvent( QSBEventManager.FireEvent(

View File

@ -51,22 +51,21 @@ namespace QSB.Player
} }
var player = PlayerList.FirstOrDefault(x => x.PlayerId == id); var player = PlayerList.FirstOrDefault(x => x.PlayerId == id);
if (player != null) if (player == null)
{ {
return player; DebugLog.ToConsole($"Error - Player with id {id} does not exist! Stacktrace : {Environment.StackTrace}", MessageType.Error);
}
if (!QSBCore.IsInMultiplayer)
{
DebugLog.ToConsole($"Error - Tried to create player id:{id} when not in multiplayer! Stacktrace : {Environment.StackTrace}", MessageType.Error);
return default; return default;
} }
return player;
}
public static void AddPlayer(uint id)
{
DebugLog.DebugWrite($"Create Player : id<{id}>", MessageType.Info); DebugLog.DebugWrite($"Create Player : id<{id}>", MessageType.Info);
player = new PlayerInfo(id); var player = new PlayerInfo(id);
PlayerList.Add(player); PlayerList.Add(player);
OnAddPlayer?.Invoke(id); OnAddPlayer?.Invoke(id);
return player;
} }
public static void RemovePlayer(uint id) public static void RemovePlayer(uint id)

View File

@ -50,6 +50,7 @@ namespace QSB.Player.TransformSync
public override void Start() public override void Start()
{ {
base.Start(); base.Start();
QSBPlayerManager.AddPlayer(PlayerId);
Player.TransformSync = this; Player.TransformSync = this;
} }

View File

@ -277,8 +277,7 @@ namespace QSB
private void RemoveWorldObjects() private void RemoveWorldObjects()
{ {
QSBWorldSync.RemoveWorldObjects<IWorldObjectTypeSubset>(); QSBWorldSync.RemoveWorldObjects();
QSBWorldSync.RemoveWorldObjects<IWorldObject>();
foreach (var platform in QSBWorldSync.GetUnityObjects<CustomNomaiRemoteCameraPlatform>()) foreach (var platform in QSBWorldSync.GetUnityObjects<CustomNomaiRemoteCameraPlatform>())
{ {
Destroy(platform); Destroy(platform);

View File

@ -83,7 +83,7 @@ namespace QSB.QuantumSync
{ {
if (quantumObject.IsEnabled) if (quantumObject.IsEnabled)
{ {
Popcron.Gizmos.Line((quantumObject as IWorldObject).ReturnObject().transform.position, Popcron.Gizmos.Line(quantumObject.ReturnObject().transform.position,
QSBPlayerManager.LocalPlayer.Body.transform.position, QSBPlayerManager.LocalPlayer.Body.transform.position,
Color.magenta * 0.25f); Color.magenta * 0.25f);
} }
@ -91,7 +91,7 @@ namespace QSB.QuantumSync
continue; continue;
} }
Popcron.Gizmos.Line((quantumObject as IWorldObject).ReturnObject().transform.position, Popcron.Gizmos.Line(quantumObject.ReturnObject().transform.position,
QSBPlayerManager.GetPlayer(quantumObject.ControllingPlayer).Body.transform.position, QSBPlayerManager.GetPlayer(quantumObject.ControllingPlayer).Body.transform.position,
Color.magenta); Color.magenta);
} }
@ -151,7 +151,7 @@ namespace QSB.QuantumSync
return Enumerable.Empty<PlayerInfo>(); return Enumerable.Empty<PlayerInfo>();
} }
var worldObj = (IQSBQuantumObject)QSBWorldSync.GetWorldFromUnity(obj); var worldObj = QSBWorldSync.GetWorldFromUnity<IQSBQuantumObject>(obj);
return QSBPlayerManager.PlayerList.Where(x => x.EntangledObject == worldObj); return QSBPlayerManager.PlayerList.Where(x => x.EntangledObject == worldObj);
} }
} }

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace QSB.QuantumSync namespace QSB.QuantumSync
{ {
public interface IQSBQuantumObject : IWorldObjectTypeSubset public interface IQSBQuantumObject : IWorldObject
{ {
uint ControllingPlayer { get; set; } uint ControllingPlayer { get; set; }
bool IsEnabled { get; set; } bool IsEnabled { get; set; }

View File

@ -4,12 +4,10 @@ namespace QSB.QuantumSync.WorldObjects
{ {
internal class QSBEyeProxyQuantumMoon : QSBQuantumObject<EyeProxyQuantumMoon> internal class QSBEyeProxyQuantumMoon : QSBQuantumObject<EyeProxyQuantumMoon>
{ {
public override void Init(EyeProxyQuantumMoon moonObject, int id) public override void Init()
{ {
ObjectId = id;
AttachedObject = moonObject;
ControllingPlayer = QSBPlayerManager.LocalPlayerId; ControllingPlayer = QSBPlayerManager.LocalPlayerId;
base.Init(moonObject, id); base.Init();
} }
} }
} }

View File

@ -21,17 +21,14 @@ namespace QSB.QuantumSync.WorldObjects
} }
} }
public override void Init(MultiStateQuantumObject attachedObject, int id) public override void Init()
{ {
ObjectId = id;
AttachedObject = attachedObject;
if (QSBCore.ShowQuantumDebugBoxes) if (QSBCore.ShowQuantumDebugBoxes)
{ {
DebugBoxText = DebugBoxManager.CreateBox(AttachedObject.transform, 0, $"Multistate\r\nid:{id}\r\nstate:{CurrentState}").GetComponent<Text>(); DebugBoxText = DebugBoxManager.CreateBox(AttachedObject.transform, 0, $"Multistate\r\nid:{ObjectId}\r\nstate:{CurrentState}").GetComponent<Text>();
} }
base.Init(attachedObject, id); base.Init();
StartDelayedReady(); StartDelayedReady();
QSBCore.UnityEvents.RunWhen(() => WorldObjectManager.AllObjectsAdded, () => QSBCore.UnityEvents.RunWhen(() => WorldObjectManager.AllObjectsAdded, () =>

View File

@ -5,14 +5,12 @@ namespace QSB.QuantumSync.WorldObjects
{ {
internal class QSBQuantumMoon : QSBQuantumObject<QuantumMoon> internal class QSBQuantumMoon : QSBQuantumObject<QuantumMoon>
{ {
public override void Init(QuantumMoon moonObject, int id) public override void Init()
{ {
ObjectId = id;
AttachedObject = moonObject;
ControllingPlayer = QSBCore.IsHost ControllingPlayer = QSBCore.IsHost
? QSBPlayerManager.LocalPlayerId ? QSBPlayerManager.LocalPlayerId
: QSBPlayerManager.PlayerList.OrderBy(x => x.PlayerId).First().PlayerId; : QSBPlayerManager.PlayerList.OrderBy(x => x.PlayerId).First().PlayerId;
base.Init(moonObject, id); base.Init();
} }
} }
} }

View File

@ -24,7 +24,7 @@ namespace QSB.QuantumSync.WorldObjects
} }
} }
public override void Init(T attachedObject, int id) public override void Init()
{ {
var debugBundle = QSBCore.DebugAssetBundle; var debugBundle = QSBCore.DebugAssetBundle;
var sphere = debugBundle.LoadAsset<GameObject>("Assets/Prefabs/Sphere.prefab"); var sphere = debugBundle.LoadAsset<GameObject>("Assets/Prefabs/Sphere.prefab");
@ -82,11 +82,13 @@ namespace QSB.QuantumSync.WorldObjects
} }
} }
StartDelayedReady();
QSBCore.UnityEvents.FireInNUpdates(LateInit, 5); QSBCore.UnityEvents.FireInNUpdates(LateInit, 5);
} }
private void LateInit() private void LateInit()
{ {
FinishDelayedReady();
foreach (var shape in GetAttachedShapes()) foreach (var shape in GetAttachedShapes())
{ {
shape.OnShapeActivated += OnEnable; shape.OnShapeActivated += OnEnable;
@ -171,7 +173,7 @@ namespace QSB.QuantumSync.WorldObjects
return; return;
} }
var id = QSBWorldSync.GetIdFromTypeSubset<IQSBQuantumObject>(this); var id = ObjectId;
// no one is controlling this object right now, request authority // no one is controlling this object right now, request authority
QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, id, QSBPlayerManager.LocalPlayerId); QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, id, QSBPlayerManager.LocalPlayerId);
} }
@ -200,7 +202,7 @@ namespace QSB.QuantumSync.WorldObjects
return; return;
} }
var id = QSBWorldSync.GetIdFromTypeSubset<IQSBQuantumObject>(this); var id = ObjectId;
// send event to other players that we're releasing authority // send event to other players that we're releasing authority
QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, id, 0u); QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, id, 0u);
} }

View File

@ -5,13 +5,6 @@ namespace QSB.QuantumSync.WorldObjects
{ {
internal class QSBQuantumShuffleObject : QSBQuantumObject<QuantumShuffleObject> internal class QSBQuantumShuffleObject : QSBQuantumObject<QuantumShuffleObject>
{ {
public override void Init(QuantumShuffleObject shuffleObject, int id)
{
ObjectId = id;
AttachedObject = shuffleObject;
base.Init(shuffleObject, id);
}
public void ShuffleObjects(int[] indexArray) public void ShuffleObjects(int[] indexArray)
{ {
var shuffledObjects = AttachedObject.GetValue<Transform[]>("_shuffledObjects"); var shuffledObjects = AttachedObject.GetValue<Transform[]>("_shuffledObjects");

View File

@ -5,10 +5,8 @@ namespace QSB.QuantumSync.WorldObjects
{ {
internal class QSBQuantumSocket : WorldObject<QuantumSocket> internal class QSBQuantumSocket : WorldObject<QuantumSocket>
{ {
public override void Init(QuantumSocket quantumSocket, int id) public override void Init()
{ {
ObjectId = id;
AttachedObject = quantumSocket;
AttachedObject.GetType().SetValue("_randomYRotation", false); AttachedObject.GetType().SetValue("_randomYRotation", false);
} }
} }

View File

@ -6,12 +6,6 @@ namespace QSB.QuantumSync.WorldObjects
{ {
public bool IsMeantToBeEnabled; public bool IsMeantToBeEnabled;
public override void Init(QuantumState state, int id)
{
ObjectId = id;
AttachedObject = state;
}
public void SetVisible(bool visible) public void SetVisible(bool visible)
{ {
IsMeantToBeEnabled = visible; IsMeantToBeEnabled = visible;

View File

@ -13,11 +13,9 @@ namespace QSB.QuantumSync.WorldObjects
{ {
public Text DebugBoxText; public Text DebugBoxText;
public override void Init(SocketedQuantumObject quantumObject, int id) public override void Init()
{ {
ObjectId = id; base.Init();
AttachedObject = quantumObject;
base.Init(quantumObject, id);
if (QSBCore.ShowQuantumDebugBoxes) if (QSBCore.ShowQuantumDebugBoxes)
{ {
DebugBoxText = DebugBoxManager.CreateBox(AttachedObject.transform, 0, $"Socketed\r\nid:{ObjectId}").GetComponent<Text>(); DebugBoxText = DebugBoxManager.CreateBox(AttachedObject.transform, 0, $"Socketed\r\nid:{ObjectId}").GetComponent<Text>();

View File

@ -27,10 +27,8 @@ namespace QSB.SectorSync.WorldObjects
public Vector3 Position => Transform.position; public Vector3 Position => Transform.position;
public bool IsFakeSector => AttachedObject.GetType() == typeof(FakeSector); public bool IsFakeSector => AttachedObject.GetType() == typeof(FakeSector);
public override void Init(Sector sector, int id) public override void Init()
{ {
ObjectId = id;
AttachedObject = sector;
if (IsFakeSector) if (IsFakeSector)
{ {
QSBSectorManager.Instance.FakeSectors.Add(this); QSBSectorManager.Instance.FakeSectors.Add(this);

View File

@ -6,12 +6,6 @@ namespace QSB.ShipSync.WorldObjects
{ {
internal class QSBShipComponent : WorldObject<ShipComponent> internal class QSBShipComponent : WorldObject<ShipComponent>
{ {
public override void Init(ShipComponent component, int id)
{
ObjectId = id;
AttachedObject = component;
}
public void SetDamaged() public void SetDamaged()
{ {
DebugLog.DebugWrite($"[S COMPONENT] {AttachedObject} Set damaged."); DebugLog.DebugWrite($"[S COMPONENT] {AttachedObject} Set damaged.");

View File

@ -6,12 +6,6 @@ namespace QSB.ShipSync.WorldObjects
{ {
internal class QSBShipHull : WorldObject<ShipHull> internal class QSBShipHull : WorldObject<ShipHull>
{ {
public override void Init(ShipHull hull, int id)
{
ObjectId = id;
AttachedObject = hull;
}
public void SetDamaged() public void SetDamaged()
{ {
DebugLog.DebugWrite($"[HULL] {AttachedObject} Set damaged."); DebugLog.DebugWrite($"[HULL] {AttachedObject} Set damaged.");

View File

@ -12,10 +12,8 @@ namespace QSB.Tools.ProbeLauncherTool.WorldObjects
private ProbeLauncherEffects _effects; private ProbeLauncherEffects _effects;
private SingularityWarpEffect _probeRetrievalEffect; private SingularityWarpEffect _probeRetrievalEffect;
public override void Init(ProbeLauncher launcher, int id) public override void Init()
{ {
ObjectId = id;
AttachedObject = launcher;
_probeRetrievalLength = AttachedObject.GetValue<float>("_probeRetrievalLength"); _probeRetrievalLength = AttachedObject.GetValue<float>("_probeRetrievalLength");
_preLaunchProbeProxy = AttachedObject.GetValue<GameObject>("_preLaunchProbeProxy"); _preLaunchProbeProxy = AttachedObject.GetValue<GameObject>("_preLaunchProbeProxy");
_effects = AttachedObject.GetValue<ProbeLauncherEffects>("_effects"); _effects = AttachedObject.GetValue<ProbeLauncherEffects>("_effects");

View File

@ -6,12 +6,6 @@ namespace QSB.Tools.TranslatorTool.TranslationSync.WorldObjects
{ {
internal class QSBComputer : WorldObject<NomaiComputer> internal class QSBComputer : WorldObject<NomaiComputer>
{ {
public override void Init(NomaiComputer computer, int id)
{
ObjectId = id;
AttachedObject = computer;
}
public void HandleSetAsTranslated(int id) public void HandleSetAsTranslated(int id)
{ {
if (AttachedObject.IsTranslated(id)) if (AttachedObject.IsTranslated(id))

View File

@ -7,12 +7,6 @@ namespace QSB.Tools.TranslatorTool.TranslationSync.WorldObjects
{ {
internal class QSBVesselComputer : WorldObject<NomaiVesselComputer> internal class QSBVesselComputer : WorldObject<NomaiVesselComputer>
{ {
public override void Init(NomaiVesselComputer computer, int id)
{
ObjectId = id;
AttachedObject = computer;
}
public void HandleSetAsTranslated(int id) public void HandleSetAsTranslated(int id)
{ {
if (AttachedObject.IsTranslated(id)) if (AttachedObject.IsTranslated(id))

View File

@ -6,12 +6,6 @@ namespace QSB.Tools.TranslatorTool.TranslationSync.WorldObjects
{ {
internal class QSBWallText : WorldObject<NomaiWallText> internal class QSBWallText : WorldObject<NomaiWallText>
{ {
public override void Init(NomaiWallText wallText, int id)
{
ObjectId = id;
AttachedObject = wallText;
}
public void HandleSetAsTranslated(int id) public void HandleSetAsTranslated(int id)
{ {
if (AttachedObject.IsTranslated(id)) if (AttachedObject.IsTranslated(id))

View File

@ -4,12 +4,6 @@ namespace QSB.TornadoSync.WorldObjects
{ {
public class QSBTornado : WorldObject<TornadoController> public class QSBTornado : WorldObject<TornadoController>
{ {
public override void Init(TornadoController attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
}
public bool FormState public bool FormState
{ {
get => AttachedObject._tornadoRoot.activeSelf // forming or formed or collapsing get => AttachedObject._tornadoRoot.activeSelf // forming or formed or collapsing

View File

@ -1,4 +0,0 @@
namespace QSB.WorldSync
{
public interface IWorldObjectTypeSubset { }
}

View File

@ -20,47 +20,25 @@ namespace QSB.WorldSync
private static readonly Dictionary<MonoBehaviour, IWorldObject> WorldObjectsToUnityObjects = new(); private static readonly Dictionary<MonoBehaviour, IWorldObject> WorldObjectsToUnityObjects = new();
public static IEnumerable<TWorldObject> GetWorldObjects<TWorldObject>() public static IEnumerable<TWorldObject> GetWorldObjects<TWorldObject>()
where TWorldObject : IWorldObject
=> WorldObjects.OfType<TWorldObject>(); => WorldObjects.OfType<TWorldObject>();
public static TWorldObject GetWorldFromId<TWorldObject>(int id) public static TWorldObject GetWorldFromId<TWorldObject>(int id)
where TWorldObject : IWorldObject
{ {
var worldObjects = GetWorldObjects<TWorldObject>().ToList(); if (id < 0 || id >= WorldObjects.Count)
if (id < 0 || id >= worldObjects.Count)
{ {
DebugLog.ToConsole($"Warning - Tried to find {typeof(TWorldObject).Name} id {id}. Count is {worldObjects.Count}.", MessageType.Warning); DebugLog.ToConsole($"Warning - Tried to find {typeof(TWorldObject).Name} id {id}. Count is {WorldObjects.Count}.", MessageType.Warning);
return default; return default;
} }
return worldObjects[id]; if (WorldObjects[id] is not TWorldObject worldObject)
}
public static IWorldObject GetWorldFromUnity(MonoBehaviour unityObject)
{
if (unityObject == null)
{ {
DebugLog.ToConsole($"Error - Trying to run GetWorldFromUnity with a null unity object! TUnityObject:NULL, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Error); DebugLog.ToConsole($"Error - {typeof(TWorldObject).Name} id {id} is actually {WorldObjects[id].GetType().Name}.", MessageType.Error);
return default; return default;
} }
if (!QSBCore.IsInMultiplayer) return worldObject;
{
DebugLog.ToConsole($"Warning - Trying to run GetWorldFromUnity while not in multiplayer! TUnityObject:{unityObject.GetType().Name}, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Warning);
return default;
}
if (!WorldObjectsToUnityObjects.TryGetValue(unityObject, out var returnObject))
{
DebugLog.ToConsole($"Error - WorldObjectsToUnityObjects does not contain \"{unityObject.name}\"! TUnityObject:{unityObject.GetType().Name}, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Error);
return default;
}
if (returnObject == null)
{
DebugLog.ToConsole($"Error - World object for unity object {unityObject.name} is null! TUnityObject:{unityObject.GetType().Name}, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Error);
return default;
}
return returnObject;
} }
public static TWorldObject GetWorldFromUnity<TWorldObject>(MonoBehaviour unityObject) public static TWorldObject GetWorldFromUnity<TWorldObject>(MonoBehaviour unityObject)
@ -97,32 +75,18 @@ namespace QSB.WorldSync
where TWorldObject : IWorldObject where TWorldObject : IWorldObject
=> GetWorldFromUnity<TWorldObject>(unityObject).ObjectId; => GetWorldFromUnity<TWorldObject>(unityObject).ObjectId;
public static int GetIdFromTypeSubset<TTypeSubset>(TTypeSubset typeSubset) public static void RemoveWorldObjects()
{
var index = GetWorldObjects<TTypeSubset>().ToList().IndexOf(typeSubset);
if (index == -1)
{
DebugLog.ToConsole($"Warning - {((IWorldObject)typeSubset).Name} doesn't exist in list of {typeof(TTypeSubset).Name} !", MessageType.Warning);
}
return index;
}
public static void RemoveWorldObjects<TWorldObject>()
{ {
if (WorldObjects.Count == 0) if (WorldObjects.Count == 0)
{ {
DebugLog.ToConsole($"Warning - Trying to remove WorldObjects of type {typeof(TWorldObject).Name}, but there are no WorldObjects!", MessageType.Warning); DebugLog.ToConsole($"Warning - Trying to remove WorldObjects, but there are no WorldObjects!", MessageType.Warning);
return; return;
} }
var itemsToRemove = WorldObjects.Where(x => x is TWorldObject); foreach (var item in WorldObjects)
foreach (var item in itemsToRemove)
{ {
try try
{ {
WorldObjectsToUnityObjects.Remove(item.ReturnObject());
item.OnRemoval(); item.OnRemoval();
} }
catch (Exception e) catch (Exception e)
@ -131,7 +95,8 @@ namespace QSB.WorldSync
} }
} }
WorldObjects.RemoveAll(x => x is TWorldObject); WorldObjects.Clear();
WorldObjectsToUnityObjects.Clear();
} }
public static IEnumerable<TUnityObject> GetUnityObjects<TUnityObject>() public static IEnumerable<TUnityObject> GetUnityObjects<TUnityObject>()
@ -140,34 +105,24 @@ namespace QSB.WorldSync
.Where(x => x.gameObject.scene.name != null); .Where(x => x.gameObject.scene.name != null);
public static void Init<TWorldObject, TUnityObject>() public static void Init<TWorldObject, TUnityObject>()
where TWorldObject : WorldObject<TUnityObject> where TWorldObject : WorldObject<TUnityObject>, new()
where TUnityObject : MonoBehaviour where TUnityObject : MonoBehaviour
{ {
RemoveWorldObjects<TWorldObject>();
var list = GetUnityObjects<TUnityObject>().ToList(); var list = GetUnityObjects<TUnityObject>().ToList();
//DebugLog.DebugWrite($"{typeof(TWorldObject).Name} init : {list.Count} instances.", MessageType.Info); //DebugLog.DebugWrite($"{typeof(TWorldObject).Name} init : {list.Count} instances.", MessageType.Info);
for (var id = 0; id < list.Count; id++) for (var id = 0; id < list.Count; id++)
{ {
var obj = CreateWorldObject<TWorldObject>(); var obj = new TWorldObject
obj.Init(list[id], id); {
AttachedObject = list[id],
ObjectId = WorldObjects.Count
};
obj.Init();
WorldObjects.Add(obj);
WorldObjectsToUnityObjects.Add(list[id], obj); WorldObjectsToUnityObjects.Add(list[id], obj);
} }
} }
private static TWorldObject CreateWorldObject<TWorldObject>()
where TWorldObject : IWorldObject
{
var worldObject = (TWorldObject)Activator.CreateInstance(typeof(TWorldObject));
WorldObjects.Add(worldObject);
if (worldObject == null)
{
// if this happens, god help you
DebugLog.ToConsole($"Error - CreateWorldObject is returning a null value! This is very bad!", MessageType.Error);
}
return worldObject;
}
public static void HandleSlotStateChange(NomaiInterfaceSlot slot, NomaiInterfaceOrb affectingOrb, bool state) public static void HandleSlotStateChange(NomaiInterfaceSlot slot, NomaiInterfaceOrb affectingOrb, bool state)
{ {
var slotList = GetWorldObjects<QSBOrbSlot>().ToList(); var slotList = GetWorldObjects<QSBOrbSlot>().ToList();

View File

@ -6,12 +6,12 @@ namespace QSB.WorldSync
public abstract class WorldObject<T> : IWorldObject public abstract class WorldObject<T> : IWorldObject
where T : MonoBehaviour where T : MonoBehaviour
{ {
public int ObjectId { get; protected set; } public int ObjectId { get; set; }
public T AttachedObject { get; protected set; } public T AttachedObject { get; set; }
public string Name => AttachedObject == null ? "<NullObject!>" : AttachedObject.name; public string Name => AttachedObject == null ? "<NullObject!>" : AttachedObject.name;
public string LogName => $"{QSBPlayerManager.LocalPlayerId}.{ObjectId}:{GetType().Name}"; public string LogName => $"{QSBPlayerManager.LocalPlayerId}.{ObjectId}:{GetType().Name}";
public abstract void Init(T attachedObject, int id); public virtual void Init() { }
public virtual void OnRemoval() { } public virtual void OnRemoval() { }
public MonoBehaviour ReturnObject() => AttachedObject; public MonoBehaviour ReturnObject() => AttachedObject;

View File

@ -66,6 +66,7 @@ namespace QSB.WorldSync
private static void DoRebuild(OWScene scene) private static void DoRebuild(OWScene scene)
{ {
QSBWorldSync.RemoveWorldObjects();
_numManagersReadying = 0; _numManagersReadying = 0;
_numObjectsReadying = 0; _numObjectsReadying = 0;
AllObjectsAdded = false; AllObjectsAdded = false;
@ -79,7 +80,7 @@ namespace QSB.WorldSync
} }
catch (Exception ex) catch (Exception ex)
{ {
DebugLog.ToConsole($"Exception - Exception when trying to rebuild WorldObjects of manager {manager.GetType().Name} : {ex.Message} Stacktrace :\r\n{ex.StackTrace}", OWML.Common.MessageType.Error); DebugLog.ToConsole($"Exception - Exception when trying to rebuild WorldObjects of manager {manager.GetType().Name} : {ex.Message} Stacktrace :\r\n{ex.StackTrace}", MessageType.Error);
} }
} }

View File

@ -5,12 +5,6 @@ namespace QSB.ZeroGCaveSync.WorldObjects
{ {
internal class QSBSatelliteNode : WorldObject<SatelliteNode> internal class QSBSatelliteNode : WorldObject<SatelliteNode>
{ {
public override void Init(SatelliteNode component, int id)
{
ObjectId = id;
AttachedObject = component;
}
public void SetRepaired() public void SetRepaired()
{ {
DebugLog.DebugWrite($"[SATELLITE NODE] {AttachedObject} Set repaired."); DebugLog.DebugWrite($"[SATELLITE NODE] {AttachedObject} Set repaired.");

View File

@ -1,5 +1,4 @@
using QuantumUNET.Transport; using QuantumUNET.Transport;
using System;
namespace QuantumUNET.Messages namespace QuantumUNET.Messages
{ {
@ -12,7 +11,7 @@ namespace QuantumUNET.Messages
public TMsg ReadMessage<TMsg>() where TMsg : QMessageBase, new() public TMsg ReadMessage<TMsg>() where TMsg : QMessageBase, new()
{ {
var result = Activator.CreateInstance<TMsg>(); var result = new TMsg();
result.Deserialize(Reader); result.Deserialize(Reader);
return result; return result;
} }

View File

@ -458,7 +458,7 @@ namespace QuantumUNET.Transport
public TMsg ReadMessage<TMsg>() where TMsg : QMessageBase, new() public TMsg ReadMessage<TMsg>() where TMsg : QMessageBase, new()
{ {
var result = Activator.CreateInstance<TMsg>(); var result = new TMsg();
result.Deserialize(this); result.Deserialize(this);
return result; return result;
} }