Skip to content

Commit

Permalink
being super paranoid about memory
Browse files Browse the repository at this point in the history
  • Loading branch information
MattFiler committed Feb 6, 2024
1 parent 901fae4 commit 9126fa1
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CathodeLib/Scripts/CATHODE/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Numerics;
using System.IO;
using CathodeLib;
using CathodeLib.Properties;
#endif

namespace CATHODE.Scripting.Internal
Expand Down Expand Up @@ -42,6 +43,12 @@ public Entity(ShortGuid shortGUID, EntityVariant variant)
public List<EntityConnector> childLinks = new List<EntityConnector>();
public List<Parameter> parameters = new List<Parameter>();

~Entity()
{
childLinks.Clear();
parameters.Clear();
}

/* Implements IComparable for searching */
public int CompareTo(Entity other)
{
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
10 changes: 5 additions & 5 deletions CathodeLib/Scripts/CATHODE/CommandsPAK/Helpers/EntityUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
27 changes: 27 additions & 0 deletions CathodeLib/Scripts/CATHODE/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public Models(string path) : base(path) { }
private List<CS2.Component.LOD.Submesh> _writeList = new List<CS2.Component.LOD.Submesh>();
private string _filepathBIN;

~Models()
{
Entries.Clear();
_writeList.Clear();
}

#region FILE_IO
/* Load the file */
override protected bool LoadInternal()
Expand Down Expand Up @@ -623,6 +629,11 @@ public class CS2
public string Name;
public List<Component> Components = new List<Component>();

~CS2()
{
Components.Clear();
}

public class Component
{
public List<LOD> LODs = new List<LOD>();
Expand All @@ -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)
Expand All @@ -642,6 +658,11 @@ public LOD(string name)
public string Name;
public List<Submesh> Submeshes = new List<Submesh>();

~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??
Expand Down Expand Up @@ -675,6 +696,12 @@ public class Submesh
public List<int> boneIndices = new List<int>();

public byte[] content = new byte[0];

~Submesh()
{
boneIndices.Clear();
content = null;
}
}

public override string ToString()
Expand Down
18 changes: 18 additions & 0 deletions CathodeLib/Scripts/CATHODE/Shaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions CathodeLib/Scripts/CATHODE/Textures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public Textures(string path) : base(path) { }
public List<TEX4> _writeList = new List<TEX4>();
private string _filepathBIN;

~Textures()
{
Entries.Clear();
_writeList.Clear();
}

#region FILE_IO
override protected bool LoadInternal()
{
Expand Down Expand Up @@ -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;
Expand All @@ -282,6 +294,11 @@ public class Part
public UInt16 unk2 = 0;
public UInt32 unk3 = 0;
public UInt32 unk4 = 0;

~Part()
{
Content = null;
}
}
}

Expand Down

0 comments on commit 9126fa1

Please sign in to comment.