From ed411a2b69597c917809512e6355245366d3cb70 Mon Sep 17 00:00:00 2001 From: JaXt0r <120568393+JaXt0r@users.noreply.github.com> Date: Fri, 4 Oct 2024 14:38:30 +0200 Subject: [PATCH] performance: Disable world and vob meshed during loading time. Simply enabling all at the end. --- Assets/UnZENity-Core/Scripts/Creator/VobCreator.cs | 6 ++++-- .../UnZENity-Core/Scripts/Creator/WorldCreator.cs | 4 ++-- .../Scripts/Manager/Scenes/WorldSceneManager.cs | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Assets/UnZENity-Core/Scripts/Creator/VobCreator.cs b/Assets/UnZENity-Core/Scripts/Creator/VobCreator.cs index a653efde..e15cd741 100644 --- a/Assets/UnZENity-Core/Scripts/Creator/VobCreator.cs +++ b/Assets/UnZENity-Core/Scripts/Creator/VobCreator.cs @@ -64,9 +64,12 @@ private static void PostWorldLoaded() GameContext.InteractionAdapter.SetTeleportationArea(_teleportGo); } - public static async Task CreateAsync(GameConfiguration config, LoadingManager loading, List vobs) + public static async Task CreateAsync(GameConfiguration config, LoadingManager loading, List vobs, GameObject root) { Stopwatch stopwatch = new(); + + _vobsGo = root; + stopwatch.Start(); PreCreateVobs(vobs); await CreateVobs(config, loading, vobs); @@ -101,7 +104,6 @@ private static void PreCreateVobs(List vobs) _createdCount = 0; _cullingVobObjects.Clear(); - _vobsGo = new GameObject("VOBs"); _teleportGo = new GameObject("Teleport"); _nonTeleportGo = new GameObject("NonTeleport"); _teleportGo.SetParent(_vobsGo); diff --git a/Assets/UnZENity-Core/Scripts/Creator/WorldCreator.cs b/Assets/UnZENity-Core/Scripts/Creator/WorldCreator.cs index 4d71da25..fe0ce1cb 100644 --- a/Assets/UnZENity-Core/Scripts/Creator/WorldCreator.cs +++ b/Assets/UnZENity-Core/Scripts/Creator/WorldCreator.cs @@ -26,9 +26,9 @@ static WorldCreator() GlobalEventDispatcher.WorldSceneLoaded.AddListener(WorldLoaded); } - public static async Task CreateAsync(GameConfiguration config, LoadingManager loading) + public static async Task CreateAsync(GameConfiguration config, LoadingManager loading, GameObject root) { - _worldGo = new GameObject("World"); + _worldGo = root; var lightingEnabled = config.EnableVOBs && ( diff --git a/Assets/UnZENity-Core/Scripts/Manager/Scenes/WorldSceneManager.cs b/Assets/UnZENity-Core/Scripts/Manager/Scenes/WorldSceneManager.cs index 55fe1c1b..1089a38f 100644 --- a/Assets/UnZENity-Core/Scripts/Manager/Scenes/WorldSceneManager.cs +++ b/Assets/UnZENity-Core/Scripts/Manager/Scenes/WorldSceneManager.cs @@ -33,6 +33,12 @@ private async Task LoadWorldContentAsync() var watch = Stopwatch.StartNew(); var config = GameGlobals.Config; + var worldRoot = new GameObject("World"); + var vobRoot = new GameObject("VOBs"); + // We need to disable all vob meshed during loading. Otherwise loading time will increase from 10 seconds to 10 minutes. ;-) + worldRoot.SetActive(false); + vobRoot.SetActive(false); + try { // 1. @@ -40,7 +46,7 @@ private async Task LoadWorldContentAsync() // We need to start creating Vobs as we need to calculate world slicing based on amount of lights at a certain space afterwards. if (config.EnableVOBs) { - await VobCreator.CreateAsync(config, GameGlobals.Loading, SaveGameManager.CurrentWorldData.Vobs); + await VobCreator.CreateAsync(config, GameGlobals.Loading, SaveGameManager.CurrentWorldData.Vobs, vobRoot); } // 2. @@ -56,7 +62,7 @@ private async Task LoadWorldContentAsync() // 4. if (config.EnableWorldMesh) { - await WorldCreator.CreateAsync(config, GameGlobals.Loading); + await WorldCreator.CreateAsync(config, GameGlobals.Loading, worldRoot); } GameGlobals.Sky.InitSky(); @@ -64,6 +70,10 @@ private async Task LoadWorldContentAsync() // World fully loaded ResourceLoader.ReleaseLoadedData(); + + worldRoot.SetActive(true); + vobRoot.SetActive(true); + TeleportPlayerToStart(); // There are many handlers which listen to this event. If any of these fails, we won't get notified without a try-catch.