ModelLoader uses context pathmanager

This commit is contained in:
Jarrod Doyle 2024-09-05 18:52:44 +01:00
parent 12a8b4f06d
commit 236cf3b317
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
2 changed files with 5 additions and 11 deletions

View File

@ -14,7 +14,7 @@ public partial class Context : Node
{ {
var extractPath = ProjectSettings.GlobalizePath($"user://extracted/tmp"); var extractPath = ProjectSettings.GlobalizePath($"user://extracted/tmp");
PathManager = new ResourcePathManager(extractPath); PathManager = new ResourcePathManager(extractPath);
ModelLoader = new ModelLoader(PathManager); ModelLoader = new ModelLoader();
Instance = this; Instance = this;
} }

View File

@ -7,14 +7,7 @@ namespace KeepersCompound.TMV;
public class ModelLoader public class ModelLoader
{ {
private readonly Dictionary<(string, string), MeshInstance3D> _cache; private readonly Dictionary<(string, string), MeshInstance3D> _cache = new();
private readonly ResourcePathManager _pathManager;
public ModelLoader(ResourcePathManager pathManager)
{
_pathManager = pathManager;
_cache = new Dictionary<(string, string), MeshInstance3D>();
}
public MeshInstance3D Load(string campaignName, string modelName, bool forceLoad = false) public MeshInstance3D Load(string campaignName, string modelName, bool forceLoad = false)
{ {
@ -33,13 +26,14 @@ public class ModelLoader
} }
// We don't care if this is null actually, we'll still cache that it's null lol // We don't care if this is null actually, we'll still cache that it's null lol
var model = Timing.TimeStage("Load Models", () => { return LoadModel(_pathManager, ref campaignName, modelName); }); var model = Timing.TimeStage("Load Models", () => { return LoadModel(ref campaignName, modelName); });
_cache[(campaignName, modelName)] = model; _cache[(campaignName, modelName)] = model;
return model?.Duplicate() as MeshInstance3D; return model?.Duplicate() as MeshInstance3D;
} }
public static MeshInstance3D LoadModel(ResourcePathManager pathManager, ref string campaignName, string modelName) public static MeshInstance3D LoadModel(ref string campaignName, string modelName)
{ {
var pathManager = Context.Instance.PathManager;
var (newCampaignName, modelPath) = pathManager.GetResourcePath(ResourceType.Object, campaignName, modelName); var (newCampaignName, modelPath) = pathManager.GetResourcePath(ResourceType.Object, campaignName, modelName);
campaignName = newCampaignName; campaignName = newCampaignName;
if (modelPath == null) if (modelPath == null)