From 9126fa16d7c5bbe395997e9e784af7113c0b6010 Mon Sep 17 00:00:00 2001 From: MattFiler Date: Tue, 6 Feb 2024 19:35:41 +0000 Subject: [PATCH] being super paranoid about memory --- CathodeLib/Scripts/CATHODE/Commands.cs | 5 ++++ .../CommandsPAK/Components/Composite.cs | 8 ++++++ .../CATHODE/CommandsPAK/Components/Entity.cs | 12 +++++++++ .../CommandsPAK/Components/Parameter.cs | 5 ++++ .../CommandsPAK/Helpers/EntityUtils.cs | 10 +++---- .../CommandsPAK/Helpers/ShortGuidUtils.cs | 1 + CathodeLib/Scripts/CATHODE/Models.cs | 27 +++++++++++++++++++ CathodeLib/Scripts/CATHODE/Shaders.cs | 18 +++++++++++++ CathodeLib/Scripts/CATHODE/Textures.cs | 17 ++++++++++++ 9 files changed, 98 insertions(+), 5 deletions(-) diff --git a/CathodeLib/Scripts/CATHODE/Commands.cs b/CathodeLib/Scripts/CATHODE/Commands.cs index 45762f7..b91e9fc 100644 --- a/CathodeLib/Scripts/CATHODE/Commands.cs +++ b/CathodeLib/Scripts/CATHODE/Commands.cs @@ -25,6 +25,11 @@ public class Commands : CathodeFile public static new Implementation Implementation = Implementation.CREATE | Implementation.LOAD | Implementation.SAVE; public Commands(string path) : base(path) { } + ~Commands() + { + Entries.Clear(); + } + // This is always: // - Root Instance (the map's entry composite, usually containing entities that call mission/environment composites) // - Global Instance (the main data handler for keeping track of mission number, etc - kinda like a big singleton) diff --git a/CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Composite.cs b/CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Composite.cs index 7552571..02760c3 100644 --- a/CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Composite.cs +++ b/CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Composite.cs @@ -19,6 +19,14 @@ public Composite(string name) this.name = name; } + ~Composite() + { + variables.Clear(); + functions.Clear(); + aliases.Clear(); + proxies.Clear(); + } + public ShortGuid shortGUID; //The id when this composite is used as an entity in another composite public string name = ""; //The string name of the composite diff --git a/CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Entity.cs b/CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Entity.cs index 5045415..de2579b 100644 --- a/CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Entity.cs +++ b/CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Entity.cs @@ -14,6 +14,7 @@ using System.Numerics; using System.IO; using CathodeLib; +using CathodeLib.Properties; #endif namespace CATHODE.Scripting.Internal @@ -42,6 +43,12 @@ public Entity(ShortGuid shortGUID, EntityVariant variant) public List childLinks = new List(); public List parameters = new List(); + ~Entity() + { + childLinks.Clear(); + parameters.Clear(); + } + /* Implements IComparable for searching */ public int CompareTo(Entity other) { @@ -224,6 +231,11 @@ public class FunctionEntity : Entity public FunctionEntity() : base(EntityVariant.FUNCTION) { } public FunctionEntity(ShortGuid shortGUID) : base(shortGUID, EntityVariant.FUNCTION) { } + ~FunctionEntity() + { + resources.Clear(); + } + public FunctionEntity(string function, bool autoGenerateParameters = false) : base(EntityVariant.FUNCTION) { this.function = ShortGuidUtils.Generate(function); diff --git a/CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Parameter.cs b/CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Parameter.cs index 2d42ef9..e53e99f 100644 --- a/CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Parameter.cs +++ b/CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Parameter.cs @@ -25,5 +25,10 @@ public Parameter(ShortGuid id, ParameterData data, ParameterVariant var = Parame public ShortGuid name; public ParameterData content = null; public ParameterVariant variant = ParameterVariant.PARAMETER; + + ~Parameter() + { + content = null; + } } } diff --git a/CathodeLib/Scripts/CATHODE/CommandsPAK/Helpers/EntityUtils.cs b/CathodeLib/Scripts/CATHODE/CommandsPAK/Helpers/EntityUtils.cs index 3d976a3..af4121b 100644 --- a/CathodeLib/Scripts/CATHODE/CommandsPAK/Helpers/EntityUtils.cs +++ b/CathodeLib/Scripts/CATHODE/CommandsPAK/Helpers/EntityUtils.cs @@ -20,6 +20,7 @@ public static class EntityUtils private static EntityNameTable _vanilla; private static EntityNameTable _custom; + public static Commands LinkedCommands => _commands; private static Commands _commands; /* Load all standard entity/composite names from our offline DB */ @@ -45,11 +46,10 @@ public static void LinkCommands(Commands commands) } _commands = commands; - if (_commands != null) - { - _commands.OnLoadSuccess += LoadCustomNames; - _commands.OnSaveSuccess += SaveCustomNames; - } + if (_commands == null) return; + + _commands.OnLoadSuccess += LoadCustomNames; + _commands.OnSaveSuccess += SaveCustomNames; LoadCustomNames(_commands.Filepath); } diff --git a/CathodeLib/Scripts/CATHODE/CommandsPAK/Helpers/ShortGuidUtils.cs b/CathodeLib/Scripts/CATHODE/CommandsPAK/Helpers/ShortGuidUtils.cs index 3c864dd..0155b1a 100644 --- a/CathodeLib/Scripts/CATHODE/CommandsPAK/Helpers/ShortGuidUtils.cs +++ b/CathodeLib/Scripts/CATHODE/CommandsPAK/Helpers/ShortGuidUtils.cs @@ -16,6 +16,7 @@ public static class ShortGuidUtils private static GuidNameTable _vanilla = null; private static GuidNameTable _custom = null; + public static Commands LinkedCommands => _commands; private static Commands _commands; /* Pull in strings we know are cached as ShortGuid in Cathode */ diff --git a/CathodeLib/Scripts/CATHODE/Models.cs b/CathodeLib/Scripts/CATHODE/Models.cs index a118946..7ef77db 100644 --- a/CathodeLib/Scripts/CATHODE/Models.cs +++ b/CathodeLib/Scripts/CATHODE/Models.cs @@ -21,6 +21,12 @@ public Models(string path) : base(path) { } private List _writeList = new List(); private string _filepathBIN; + ~Models() + { + Entries.Clear(); + _writeList.Clear(); + } + #region FILE_IO /* Load the file */ override protected bool LoadInternal() @@ -623,6 +629,11 @@ public class CS2 public string Name; public List Components = new List(); + ~CS2() + { + Components.Clear(); + } + public class Component { public List LODs = new List(); @@ -632,6 +643,11 @@ public class Component public int UnkLv426Pt1 = 0; public int UnkLv426Pt2 = 0; + ~Component() + { + LODs.Clear(); + } + public class LOD { public LOD(string name) @@ -642,6 +658,11 @@ public LOD(string name) public string Name; public List Submeshes = new List(); + ~LOD() + { + Submeshes.Clear(); + } + public class Submesh { public Vector3 AABBMin = new Vector3(-1,-1,-1); // <---- When importing a new model, setting these all to zero seem to make it invisible?? @@ -675,6 +696,12 @@ public class Submesh public List boneIndices = new List(); public byte[] content = new byte[0]; + + ~Submesh() + { + boneIndices.Clear(); + content = null; + } } public override string ToString() diff --git a/CathodeLib/Scripts/CATHODE/Shaders.cs b/CathodeLib/Scripts/CATHODE/Shaders.cs index 5137044..0e44ea2 100644 --- a/CathodeLib/Scripts/CATHODE/Shaders.cs +++ b/CathodeLib/Scripts/CATHODE/Shaders.cs @@ -21,6 +21,11 @@ public Shaders(string path) : base(path) { } private string _filepathBIN; private string _filepathIDX; + ~Shaders() + { + Entries.Clear(); + } + #region FILE_IO override protected bool LoadInternal() { @@ -534,6 +539,19 @@ public class Shader public byte[] GeometryShader; public byte[] ComputeShader; + ~Shader() + { + Unknown2.Clear(); + Unknown3.Clear(); + + VertexShader = null; + PixelShader = null; + HullShader = null; + DomainShader = null; + GeometryShader = null; + ComputeShader = null; + } + public class UnknownPair { public int unk1; diff --git a/CathodeLib/Scripts/CATHODE/Textures.cs b/CathodeLib/Scripts/CATHODE/Textures.cs index 0ba24cb..3d05bda 100644 --- a/CathodeLib/Scripts/CATHODE/Textures.cs +++ b/CathodeLib/Scripts/CATHODE/Textures.cs @@ -17,6 +17,12 @@ public Textures(string path) : base(path) { } public List _writeList = new List(); private string _filepathBIN; + ~Textures() + { + Entries.Clear(); + _writeList.Clear(); + } + #region FILE_IO override protected bool LoadInternal() { @@ -267,6 +273,12 @@ public class TEX4 public Part tex_LowRes = new Part(); public Part tex_HighRes = new Part(); + ~TEX4() + { + tex_LowRes = null; + tex_HighRes = null; + } + public class Part { public Int16 Width = 0; @@ -282,6 +294,11 @@ public class Part public UInt16 unk2 = 0; public UInt32 unk3 = 0; public UInt32 unk4 = 0; + + ~Part() + { + Content = null; + } } }