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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,10 +4,5 @@ namespace QSB.EchoesOfTheEye.AirlockSync.WorldObjects
{
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>
{
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 OWTriggerVolume _elevatorTrigger;
public override void Init(Elevator elevator, int id)
public override void Init()
{
AttachedObject = elevator;
ObjectId = id;
StartDelayedReady();
QSBCore.UnityEvents.RunWhen(() => AttachedObject._interactVolume != null, InitValues);
}
private void InitValues()
{
FinishDelayedReady();
_startLocalPos = AttachedObject._startLocalPos;
_endLocalPos = AttachedObject._endLocalPos;
_interactVolume = AttachedObject._interactVolume;

View File

@ -6,10 +6,8 @@ namespace QSB.GeyserSync.WorldObjects
{
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.OnGeyserDeactivateEvent += () => HandleEvent(false);
}

View File

@ -42,7 +42,7 @@ namespace QSB.ItemSync.Events
case SocketEventType.StartUnsocket:
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;
}

View File

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

View File

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

View File

@ -2,11 +2,5 @@
{
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 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);
return;
@ -30,10 +30,10 @@ namespace QSB.ItemSync.WorldObjects.Items
{
FinishDelayedReady();
InitialParent = attachedObject.transform.parent;
InitialPosition = attachedObject.transform.localPosition;
InitialRotation = attachedObject.transform.localRotation;
var initialSector = attachedObject.GetSector();
InitialParent = AttachedObject.transform.parent;
InitialPosition = AttachedObject.transform.localPosition;
InitialRotation = AttachedObject.transform.localRotation;
var initialSector = AttachedObject.GetSector();
if (initialSector != null)
{
InitialSector = QSBWorldSync.GetWorldFromUnity<QSBSector>(initialSector);
@ -41,12 +41,12 @@ namespace QSB.ItemSync.WorldObjects.Items
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)
{
var qsbObj = (IQSBOWItemSocket)QSBWorldSync.GetWorldFromUnity(InitialParent.GetComponent<OWItemSocket>());
var qsbObj = QSBWorldSync.GetWorldFromUnity<IQSBOWItemSocket>(InitialParent.GetComponent<OWItemSocket>());
InitialSocket = qsbObj;
}
});

View File

@ -2,13 +2,6 @@
{
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()
=> AttachedObject.PlaySocketAnimation();

View File

@ -2,13 +2,6 @@
{
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()
=> AttachedObject.PlaySocketAnimation();

View File

@ -2,13 +2,6 @@
{
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()
=> AttachedObject.PlaySocketAnimation();

View File

@ -2,13 +2,6 @@
{
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()
=> AttachedObject.PlaySocketAnimation();

View File

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

View File

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

View File

@ -2,11 +2,5 @@
{
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
where T : OWItemSocket
{
public override void Init(T attachedObject, int id) { }
public virtual bool AcceptsItem(IQSBOWItem item)
{
var itemType = item.GetItemType();
@ -19,9 +17,9 @@ namespace QSB.ItemSync.WorldObjects.Sockets
=> AttachedObject.IsSocketOccupied();
public virtual bool PlaceIntoSocket(IQSBOWItem item)
=> AttachedObject.PlaceIntoSocket((OWItem)(item as IWorldObject).ReturnObject());
=> AttachedObject.PlaceIntoSocket((OWItem)item.ReturnObject());
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
where T : OWItemSocket
{
public override void Init(T attachedObject, int id) { }
public virtual bool AcceptsItem(IQSBOWItem item)
{
var itemType = item.GetItemType();
@ -19,9 +17,9 @@ namespace QSB.ItemSync.WorldObjects.Sockets
=> AttachedObject.IsSocketOccupied();
public virtual bool PlaceIntoSocket(IQSBOWItem item)
=> AttachedObject.PlaceIntoSocket((OWItem)(item as IWorldObject).ReturnObject());
=> AttachedObject.PlaceIntoSocket((OWItem)item.ReturnObject());
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>
{
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>
{
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>
{
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>
{
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>
{
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;
private QSBJellyfish _qsbJellyfish;
public static readonly List<JellyfishController> Jellyfish = new();
private static readonly List<JellyfishTransformSync> _instances = new();
protected override OWRigidbody GetRigidbody()
@ -37,7 +38,7 @@ namespace QSB.JellyfishSync.TransformSync
protected override void Init()
{
_qsbJellyfish = QSBWorldSync.GetWorldFromId<QSBJellyfish>(_instances.IndexOf(this));
_qsbJellyfish = QSBWorldSync.GetWorldFromUnity<QSBJellyfish>(Jellyfish[_instances.IndexOf(this)]);
_qsbJellyfish.TransformSync = this;
base.Init();

View File

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

View File

@ -5,10 +5,8 @@ namespace QSB.MeteorSync.WorldObjects
{
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>();
if (QSBCore.IsHost)

View File

@ -5,12 +5,6 @@ namespace QSB.MeteorSync.WorldObjects
{
public class QSBMeteor : WorldObject<MeteorController>
{
public override void Init(MeteorController attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
}
public static bool IsSpecialImpact(GameObject go) =>
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 override void Init(MeteorLauncher attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
}
public int MeteorId;
public float LaunchSpeed;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,12 +4,10 @@ namespace QSB.QuantumSync.WorldObjects
{
internal class QSBEyeProxyQuantumMoon : QSBQuantumObject<EyeProxyQuantumMoon>
{
public override void Init(EyeProxyQuantumMoon moonObject, int id)
public override void Init()
{
ObjectId = id;
AttachedObject = moonObject;
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)
{
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();
QSBCore.UnityEvents.RunWhen(() => WorldObjectManager.AllObjectsAdded, () =>

View File

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

View File

@ -5,13 +5,6 @@ namespace QSB.QuantumSync.WorldObjects
{
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)
{
var shuffledObjects = AttachedObject.GetValue<Transform[]>("_shuffledObjects");

View File

@ -5,10 +5,8 @@ namespace QSB.QuantumSync.WorldObjects
{
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);
}
}

View File

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

View File

@ -13,11 +13,9 @@ namespace QSB.QuantumSync.WorldObjects
{
public Text DebugBoxText;
public override void Init(SocketedQuantumObject quantumObject, int id)
public override void Init()
{
ObjectId = id;
AttachedObject = quantumObject;
base.Init(quantumObject, id);
base.Init();
if (QSBCore.ShowQuantumDebugBoxes)
{
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 bool IsFakeSector => AttachedObject.GetType() == typeof(FakeSector);
public override void Init(Sector sector, int id)
public override void Init()
{
ObjectId = id;
AttachedObject = sector;
if (IsFakeSector)
{
QSBSectorManager.Instance.FakeSectors.Add(this);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,12 +4,6 @@ namespace QSB.TornadoSync.WorldObjects
{
public class QSBTornado : WorldObject<TornadoController>
{
public override void Init(TornadoController attachedObject, int id)
{
ObjectId = id;
AttachedObject = attachedObject;
}
public bool FormState
{
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();
public static IEnumerable<TWorldObject> GetWorldObjects<TWorldObject>()
where TWorldObject : IWorldObject
=> WorldObjects.OfType<TWorldObject>();
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 worldObjects[id];
}
public static IWorldObject GetWorldFromUnity(MonoBehaviour unityObject)
{
if (unityObject == null)
if (WorldObjects[id] is not TWorldObject worldObject)
{
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;
}
if (!QSBCore.IsInMultiplayer)
{
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;
return worldObject;
}
public static TWorldObject GetWorldFromUnity<TWorldObject>(MonoBehaviour unityObject)
@ -97,32 +75,18 @@ namespace QSB.WorldSync
where TWorldObject : IWorldObject
=> GetWorldFromUnity<TWorldObject>(unityObject).ObjectId;
public static int GetIdFromTypeSubset<TTypeSubset>(TTypeSubset typeSubset)
{
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>()
public static void RemoveWorldObjects()
{
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;
}
var itemsToRemove = WorldObjects.Where(x => x is TWorldObject);
foreach (var item in itemsToRemove)
foreach (var item in WorldObjects)
{
try
{
WorldObjectsToUnityObjects.Remove(item.ReturnObject());
item.OnRemoval();
}
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>()
@ -140,34 +105,24 @@ namespace QSB.WorldSync
.Where(x => x.gameObject.scene.name != null);
public static void Init<TWorldObject, TUnityObject>()
where TWorldObject : WorldObject<TUnityObject>
where TWorldObject : WorldObject<TUnityObject>, new()
where TUnityObject : MonoBehaviour
{
RemoveWorldObjects<TWorldObject>();
var list = GetUnityObjects<TUnityObject>().ToList();
//DebugLog.DebugWrite($"{typeof(TWorldObject).Name} init : {list.Count} instances.", MessageType.Info);
for (var id = 0; id < list.Count; id++)
{
var obj = CreateWorldObject<TWorldObject>();
obj.Init(list[id], id);
var obj = new TWorldObject
{
AttachedObject = list[id],
ObjectId = WorldObjects.Count
};
obj.Init();
WorldObjects.Add(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)
{
var slotList = GetWorldObjects<QSBOrbSlot>().ToList();

View File

@ -6,12 +6,12 @@ namespace QSB.WorldSync
public abstract class WorldObject<T> : IWorldObject
where T : MonoBehaviour
{
public int ObjectId { get; protected set; }
public T AttachedObject { get; protected set; }
public int ObjectId { get; set; }
public T AttachedObject { get; set; }
public string Name => AttachedObject == null ? "<NullObject!>" : AttachedObject.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 MonoBehaviour ReturnObject() => AttachedObject;

View File

@ -66,6 +66,7 @@ namespace QSB.WorldSync
private static void DoRebuild(OWScene scene)
{
QSBWorldSync.RemoveWorldObjects();
_numManagersReadying = 0;
_numObjectsReadying = 0;
AllObjectsAdded = false;
@ -79,7 +80,7 @@ namespace QSB.WorldSync
}
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>
{
public override void Init(SatelliteNode component, int id)
{
ObjectId = id;
AttachedObject = component;
}
public void SetRepaired()
{
DebugLog.DebugWrite($"[SATELLITE NODE] {AttachedObject} Set repaired.");

View File

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

View File

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