From e11f2df92a6ef87a529cab5f77a6316d4f4dc710 Mon Sep 17 00:00:00 2001 From: Slender2000 <64808609+Slender2000@users.noreply.github.com> Date: Sun, 31 Jul 2022 12:37:03 +0100 Subject: [PATCH] texture caching --- LibLunacy/AssetLoader.cs | 4 ++-- LibLunacy/FileManager.cs | 9 +++++---- Lunacy/AssetManager.cs | 10 +++++----- Lunacy/Drawable.cs | 4 ++-- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/LibLunacy/AssetLoader.cs b/LibLunacy/AssetLoader.cs index b3c1161..552786b 100644 --- a/LibLunacy/AssetLoader.cs +++ b/LibLunacy/AssetLoader.cs @@ -1,9 +1,10 @@ namespace LibLunacy { + //Assets are managed here and whenever an asset needs to reference another, that is done here public class AssetLoader { public FileManager fm; - + public Dictionary mobys = new Dictionary(); public Dictionary ties = new Dictionary(); public Dictionary shaders = new Dictionary(); @@ -115,7 +116,6 @@ private void LoadShadersNew() MemoryStream shaderms = new MemoryStream(shaderdat); IGFile igshader = new IGFile(shaderms); CShader shader = new CShader(igshader, this); - //Console.WriteLine($"shader {i.ToString("X04")} albedo offset is {shader.name}"); shaders.Add(shaderPtrs[i].tuid, shader); } } diff --git a/LibLunacy/FileManager.cs b/LibLunacy/FileManager.cs index 67a064f..58afb58 100644 --- a/LibLunacy/FileManager.cs +++ b/LibLunacy/FileManager.cs @@ -1,13 +1,14 @@ namespace LibLunacy { + //Files are loaded here public class FileManager { public string folderPath = string.Empty; - public Dictionary igfiles = new Dictionary(); - public Dictionary rawfiles = new Dictionary(); + public Dictionary igfiles = new Dictionary(); //Actual IGFiles + public Dictionary rawfiles = new Dictionary(); //Raw data, includes files containing nothing but IGFiles - public bool isOld { get; private set; } + public bool isOld { get; private set; } //if true, old filesystem, else new filesystem public void LoadFolder(string folderPath) { @@ -31,7 +32,7 @@ public void LoadFolder(string folderPath) LoadFile("gameplay.dat", false); LoadFile("assetlookup.dat", false); - //Load raw files, a lot of these are actually a bunch of IGFiles, however the files themselves are not IGFiles + //Load raw files, a lot of these files contain a bunch of IGFiles, however the files themselves are not IGFiles LoadFile("mobys.dat", true); LoadFile("ties.dat", true); LoadFile("textures.dat", true); diff --git a/Lunacy/AssetManager.cs b/Lunacy/AssetManager.cs index b5a9810..2db29d6 100644 --- a/Lunacy/AssetManager.cs +++ b/Lunacy/AssetManager.cs @@ -12,11 +12,11 @@ public class AssetManager public void Initialize(AssetLoader al) { - //TODO: cache textures and materials - //foreach(KeyValuePair ctex in al.textures) - //{ - // textures.Add(ctex.Key, new Texture(ctex.Value)); - //} + //TODO: cache materials + foreach(KeyValuePair ctex in al.textures) + { + textures.Add(ctex.Key, new Texture(ctex.Value)); + } foreach(KeyValuePair moby in al.mobys) { mobys.Add(moby.Key, new DrawableListList(moby.Value)); diff --git a/Lunacy/Drawable.cs b/Lunacy/Drawable.cs index 4d44280..78be2e7 100644 --- a/Lunacy/Drawable.cs +++ b/Lunacy/Drawable.cs @@ -22,7 +22,7 @@ public Drawable(CMoby moby, CMoby.MobyMesh mesh) SetVertexPositions(vPositions); SetVertexTexCoords(vTexCoords); SetIndices(indices); - Texture? tex = (mesh.shader.albedo == null ? null : new Texture(mesh.shader.albedo)); + Texture? tex = (mesh.shader.albedo == null ? null : AssetManager.Singleton.textures[mesh.shader.albedo.id]); SetMaterial(new Material(MaterialManager.materials["stdv;ulitf"], tex)); } public Drawable(CTie tie, CTie.TieMesh mesh) @@ -34,7 +34,7 @@ public Drawable(CTie tie, CTie.TieMesh mesh) SetVertexPositions(vPositions); SetVertexTexCoords(vTexCoords); SetIndices(indices); - Texture? tex = (mesh.shader.albedo == null ? null : new Texture(mesh.shader.albedo)); + Texture? tex = (mesh.shader.albedo == null ? null : AssetManager.Singleton.textures[mesh.shader.albedo.id]); SetMaterial(new Material(MaterialManager.materials["stdv;ulitf"], tex)); } public Drawable(ref Zone.NewTFrag mesh)