rewrite worldobjectmanager

This commit is contained in:
Mister_Nebula 2021-07-17 09:52:46 +01:00
parent c63861e2f5
commit d09717c06f
2 changed files with 49 additions and 5 deletions

View File

@ -246,6 +246,8 @@ namespace QSB
{
Destroy(streaming);
}
WorldObjectManager.SetNotReady();
}
}
}

View File

@ -1,4 +1,7 @@
using System.Collections.Generic;
using QSB.Player;
using QSB.Utility;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace QSB.WorldSync
@ -21,17 +24,56 @@ namespace QSB.WorldSync
_managers.Remove(this);
}
public static void SetNotReady()
{
AllReady = false;
}
private void OnSceneLoaded(OWScene scene, bool inUniverse)
=> AllReady = false;
{
AllReady = false;
}
public static void Rebuild(OWScene scene)
{
foreach (var manager in _managers)
if (!QSBNetworkManager.Instance.IsReady)
{
manager.RebuildWorldObjects(scene);
DebugLog.ToConsole($"Warning - Tried to rebuild WorldObjects when Network Manager not ready!", OWML.Common.MessageType.Warning);
QSBCore.UnityEvents.RunWhen(() => QSBNetworkManager.Instance.IsReady, () => Rebuild(scene));
return;
}
AllReady = true;
if (QSBPlayerManager.LocalPlayerId == uint.MaxValue)
{
DebugLog.ToConsole($"Warning - Tried to rebuild WorldObjects when LocalPlayer is not ready!", OWML.Common.MessageType.Warning);
QSBCore.UnityEvents.RunWhen(() => QSBPlayerManager.LocalPlayerId != uint.MaxValue, () => Rebuild(scene));
return;
}
if (QSBPlayerManager.LocalPlayer.PlayerStates.IsReady)
{
DoRebuild(scene);
return;
}
QSBCore.UnityEvents.RunWhen(() => QSBPlayerManager.LocalPlayer.PlayerStates.IsReady, () => DoRebuild(scene));
}
private static void DoRebuild(OWScene scene)
{
foreach (var manager in _managers)
{
try
{
manager.RebuildWorldObjects(scene);
}
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);
}
}
QSBCore.UnityEvents.FireInNUpdates(() => AllReady = true, 1);
}
protected abstract void RebuildWorldObjects(OWScene scene);