Skip to content

Commit

Permalink
performance: Disable world and vob meshed during loading time. Simply…
Browse files Browse the repository at this point in the history
… enabling all at the end.
  • Loading branch information
JaXt0r committed Oct 4, 2024
1 parent 36d6f60 commit ed411a2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
6 changes: 4 additions & 2 deletions Assets/UnZENity-Core/Scripts/Creator/VobCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ private static void PostWorldLoaded()
GameContext.InteractionAdapter.SetTeleportationArea(_teleportGo);
}

public static async Task CreateAsync(GameConfiguration config, LoadingManager loading, List<IVirtualObject> vobs)
public static async Task CreateAsync(GameConfiguration config, LoadingManager loading, List<IVirtualObject> vobs, GameObject root)
{
Stopwatch stopwatch = new();

_vobsGo = root;

stopwatch.Start();
PreCreateVobs(vobs);
await CreateVobs(config, loading, vobs);
Expand Down Expand Up @@ -101,7 +104,6 @@ private static void PreCreateVobs(List<IVirtualObject> vobs)
_createdCount = 0;
_cullingVobObjects.Clear();

_vobsGo = new GameObject("VOBs");
_teleportGo = new GameObject("Teleport");
_nonTeleportGo = new GameObject("NonTeleport");
_teleportGo.SetParent(_vobsGo);
Expand Down
4 changes: 2 additions & 2 deletions Assets/UnZENity-Core/Scripts/Creator/WorldCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
(
Expand Down
14 changes: 12 additions & 2 deletions Assets/UnZENity-Core/Scripts/Manager/Scenes/WorldSceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,20 @@ 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.
// Build the world and vob meshes, populating the texture arrays.
// 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.
Expand All @@ -56,14 +62,18 @@ private async Task LoadWorldContentAsync()
// 4.
if (config.EnableWorldMesh)
{
await WorldCreator.CreateAsync(config, GameGlobals.Loading);
await WorldCreator.CreateAsync(config, GameGlobals.Loading, worldRoot);
}

GameGlobals.Sky.InitSky();
StationaryLight.InitStationaryLights();

// 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.
Expand Down

0 comments on commit ed411a2

Please sign in to comment.