manual sample markers for streaming

This commit is contained in:
JohnCorby 2025-02-13 22:34:47 -08:00
parent ed011f1732
commit a51e87f002

View File

@ -2,6 +2,7 @@ using NewHorizons.Utility;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.Profiling;
namespace NewHorizons.Handlers namespace NewHorizons.Handlers
{ {
@ -51,8 +52,9 @@ namespace NewHorizons.Handlers
/// </summary> /// </summary>
public static void SetUpStreaming(GameObject obj, Sector sector) public static void SetUpStreaming(GameObject obj, Sector sector)
{ {
// TODO: used OFTEN by detail builder. 20ms adds up to seconds. speed up! // TODO: used OFTEN by detail builder. 20-40ms adds up to seconds. speed up!
Profiler.BeginSample("get bundles");
// find the asset bundles to load // find the asset bundles to load
// tries the cache first, then builds // tries the cache first, then builds
if (!_objectCache.TryGetValue(obj, out var assetBundles)) if (!_objectCache.TryGetValue(obj, out var assetBundles))
@ -96,7 +98,9 @@ namespace NewHorizons.Handlers
assetBundles = assetBundlesList.ToArray(); assetBundles = assetBundlesList.ToArray();
_objectCache[obj] = assetBundles; _objectCache[obj] = assetBundles;
} }
Profiler.EndSample();
Profiler.BeginSample("get sectors");
foreach (var assetBundle in assetBundles) foreach (var assetBundle in assetBundles)
{ {
// Track the sector even if its null. null means stay loaded forever // Track the sector even if its null. null means stay loaded forever
@ -107,7 +111,9 @@ namespace NewHorizons.Handlers
} }
sectors.SafeAdd(sector); sectors.SafeAdd(sector);
} }
Profiler.EndSample();
Profiler.BeginSample("load assets");
if (sector) if (sector)
{ {
sector.OnOccupantEnterSector += _ => sector.OnOccupantEnterSector += _ =>
@ -130,6 +136,7 @@ namespace NewHorizons.Handlers
foreach (var assetBundle in assetBundles) foreach (var assetBundle in assetBundles)
StreamingManager.LoadStreamingAssets(assetBundle); StreamingManager.LoadStreamingAssets(assetBundle);
} }
Profiler.EndSample();
} }
public static bool IsBundleInUse(string assetBundle) public static bool IsBundleInUse(string assetBundle)