fix sectors in a TERRIBLE TERRIBLE WAY

This commit is contained in:
Mister_Nebula 2021-03-11 20:02:23 +00:00
parent 10597859e5
commit ff94ecab3b
8 changed files with 59 additions and 12 deletions

View File

@ -50,11 +50,6 @@ namespace QSB.Player.Events
MessageType.Error);
return;
}
foreach (var item in QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>()
.Where(x => x != null && x.IsReady && x.ReferenceSector != null && x.PlayerId == LocalPlayerId))
{
QSBEventManager.FireEvent(EventNames.QSBSectorChange, item.NetId.Value, item.ReferenceSector);
}
}
}
}

View File

@ -204,6 +204,7 @@
<Compile Include="QuantumSync\QuantumManager.cs" />
<Compile Include="QuantumSync\Patches\QuantumVisibilityPatches.cs" />
<Compile Include="QuantumSync\Patches\ServerQuantumPatches.cs" />
<Compile Include="SectorSync\FakeSector.cs" />
<Compile Include="StatueSync\Events\StartStatueEvent.cs" />
<Compile Include="StatueSync\Events\StartStatueMessage.cs" />
<Compile Include="StatueSync\Patches\StatuePatches.cs" />

View File

@ -150,13 +150,11 @@ namespace QSB
}
var offset3 = 10f;
GUI.Label(new Rect(420, offset3, 200f, 20f), $"Current sectors :");
GUI.Label(new Rect(420, offset3, 200f, 20f), $"Current closest sector :");
offset3 += _debugLineSpacing;
var sector = PlayerTransformSync.LocalInstance.SectorSync.GetClosestSector(Locator.GetPlayerTransform());
GUI.Label(new Rect(420, offset3, 400f, 20f), $"- {sector.AttachedObject.name} : {sector.IsFakeSector}");
offset3 += _debugLineSpacing;
foreach (var obj in PlayerTransformSync.LocalInstance?.SectorSync.SectorList)
{
GUI.Label(new Rect(420, offset3, 400f, 20f), $"- {obj.AttachedObject.name} : {Vector3.Distance(obj.Position, Locator.GetPlayerTransform().position)}");
offset3 += _debugLineSpacing;
}
var offset2 = 10f;
GUI.Label(new Rect(620, offset2, 200f, 20f), $"Owned Objects :");

View File

@ -174,7 +174,6 @@ namespace QSB
QSBEventManager.Init();
gameObject.AddComponent<QSBSectorManager>();
gameObject.AddComponent<RespawnOnDeath>();
if (QSBSceneManager.IsInUniverse)

View File

@ -0,0 +1,7 @@
namespace QSB.SectorSync
{
public class FakeSector : Sector
{
public Sector AttachedSector;
}
}

View File

@ -4,6 +4,7 @@ using QSB.Player;
using QSB.SectorSync.WorldObjects;
using QSB.Utility;
using QSB.WorldSync;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
@ -13,6 +14,7 @@ namespace QSB.SectorSync
{
public static QSBSectorManager Instance { get; private set; }
public bool IsReady { get; private set; }
public List<QSBSector> FakeSectors = new List<QSBSector>();
private void OnEnable() => RepeatingManager.Repeatings.Add(this);
private void OnDisable() => RepeatingManager.Repeatings.Remove(this);
@ -25,6 +27,12 @@ namespace QSB.SectorSync
public void Awake()
{
if (Instance != null)
{
DebugLog.ToConsole("Error - Cannot have multiple QSBSectorManagers!", MessageType.Error);
Destroy(this);
return;
}
Instance = this;
QSBSceneManager.OnUniverseSceneLoaded += (OWScene scene) => RebuildSectors();
DebugLog.DebugWrite("Sector Manager ready.", MessageType.Success);
@ -33,9 +41,25 @@ namespace QSB.SectorSync
public void OnDestroy()
=> QSBSceneManager.OnUniverseSceneLoaded -= (OWScene scene) => RebuildSectors();
public void RebuildSectors()
{
DebugLog.DebugWrite("Rebuilding sectors...", MessageType.Warning);
if (QSBSceneManager.CurrentScene == OWScene.SolarSystem)
{
var timeLoopRing = GameObject.Find("TimeLoopRing_Body");
if (timeLoopRing != null)
{
if (timeLoopRing.GetComponent<FakeSector>() == null)
{
timeLoopRing.AddComponent<FakeSector>().AttachedSector = GameObject.Find("Sector_TimeLoopInterior").GetComponent<Sector>();
}
}
else
{
DebugLog.ToConsole($"Error - TimeLoopRing_Body not found!", MessageType.Error);
}
}
QSBWorldSync.Init<QSBSector, Sector>();
IsReady = QSBWorldSync.GetWorldObjects<QSBSector>().Any();
}

View File

@ -86,6 +86,16 @@ namespace QSB.SectorSync
var ordered = activeNotNullNotBlacklisted
.OrderBy(sector => Vector3.Distance(sector.Position, trans.position))
.ThenBy(sector => GetRadius(sector));
if (
QSBSectorManager.Instance.FakeSectors.Any(
x => OWMath.ApproxEquals(Vector3.Distance(x.Position, trans.position), Vector3.Distance(ordered.FirstOrDefault().Position, trans.position), 0.01f)
&& activeNotNullNotBlacklisted.Any(
y => y.AttachedObject == (x.AttachedObject as FakeSector).AttachedSector)))
{
return QSBSectorManager.Instance.FakeSectors.First(x => OWMath.ApproxEquals(Vector3.Distance(x.Position, trans.position), Vector3.Distance(ordered.FirstOrDefault().Position, trans.position), 0.01f));
}
return ordered.FirstOrDefault();
}

View File

@ -8,11 +8,24 @@ namespace QSB.SectorSync.WorldObjects
public Sector.Name Type => AttachedObject.GetName();
public Transform Transform => AttachedObject.transform;
public Vector3 Position => Transform.position;
public bool IsFakeSector => AttachedObject.GetType() == typeof(FakeSector);
public override void Init(Sector sector, int id)
{
ObjectId = id;
AttachedObject = sector;
if (IsFakeSector)
{
QSBSectorManager.Instance.FakeSectors.Add(this);
}
}
public override void OnRemoval()
{
if (IsFakeSector)
{
QSBSectorManager.Instance.FakeSectors.Remove(this);
}
}
}
}