Skip to content

Commit ec7cf1e

Browse files
committed
better memory handling within Level
1 parent 8724787 commit ec7cf1e

31 files changed

Lines changed: 310 additions & 13 deletions

CathodeLib/Scripts/CATHODE/AlphaLightLevel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public AlphaLightLevel(byte[] data, string path = "") : base(data, path) { }
2525
public Vector2 Resolution;
2626
public byte[] ImageData; // this is in A16B16G16R16F format
2727

28+
~AlphaLightLevel()
29+
{
30+
ImageData = null;
31+
}
32+
2833
#region FILE_IO
2934
override protected bool LoadInternal(MemoryStream stream)
3035
{

CathodeLib/Scripts/CATHODE/AnimationStrings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public AnimationStrings(string path) : base(path) { }
2121
public AnimationStrings(MemoryStream stream, string path = "") : base(stream, path) { }
2222
public AnimationStrings(byte[] data, string path = "") : base(data, path) { }
2323

24+
~AnimationStrings()
25+
{
26+
Entries.Clear();
27+
}
28+
2429
#region FILE_IO
2530
override protected bool LoadInternal(MemoryStream stream)
2631
{

CathodeLib/Scripts/CATHODE/BehaviorTreeDB.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public BehaviorTreeDB(string path) : base(path) { }
2525
public BehaviorTreeDB(MemoryStream stream, string path = "") : base(stream, path) { }
2626
public BehaviorTreeDB(byte[] data, string path = "") : base(data, path) { }
2727

28+
~BehaviorTreeDB()
29+
{
30+
Entries.Clear();
31+
}
32+
2833
#region FILE_IO
2934
override protected bool LoadInternal(MemoryStream stream)
3035
{

CathodeLib/Scripts/CATHODE/CharacterAccessorySets.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public CharacterAccessorySets(string path) : base(path) { }
2020
public CharacterAccessorySets(MemoryStream stream, string path = "") : base(stream, path) { }
2121
public CharacterAccessorySets(byte[] data, string path = "") : base(data, path) { }
2222

23+
~CharacterAccessorySets()
24+
{
25+
Entries.Clear();
26+
}
27+
2328
#region FILE_IO
2429
override protected bool LoadInternal(MemoryStream stream)
2530
{

CathodeLib/Scripts/CATHODE/CollisionMaps.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using CATHODE.Scripting;
1+
using CATHODE.Scripting;
22
using CathodeLib;
33
using CathodeLib.ObjectExtensions;
44
using System;
@@ -35,6 +35,19 @@ public CollisionMaps(string path, Materials materials, MaterialMappings material
3535
_loaded = Load();
3636
}
3737

38+
public void ClearReferences()
39+
{
40+
_materials = null;
41+
_materialMaps = null;
42+
}
43+
44+
~CollisionMaps()
45+
{
46+
ClearReferences();
47+
Entries.Clear();
48+
_writeList.Clear();
49+
}
50+
3851
#region FILE_IO
3952
override protected bool LoadInternal(MemoryStream stream)
4053
{

CathodeLib/Scripts/CATHODE/Collisions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public Collisions(byte[] data, string path = "") : base(data, path) { }
3434

3535
private List<WeightedCollision> _writeList = new List<WeightedCollision>();
3636

37+
~Collisions()
38+
{
39+
Entries.Clear();
40+
_writeList.Clear();
41+
}
42+
3743
#region FILE_IO
3844
override protected bool LoadInternal(MemoryStream stream)
3945
{

CathodeLib/Scripts/CATHODE/Commands.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,16 @@ public Commands(string path, EnvironmentAnimations envAnims, CollisionMaps colMa
4343
_loaded = Load();
4444
}
4545

46+
public void ClearReferences()
47+
{
48+
_envAnims = null;
49+
_colMaps = null;
50+
_reds = null;
51+
}
52+
4653
~Commands()
4754
{
55+
ClearReferences();
4856
Entries.Clear();
4957
}
5058

CathodeLib/Scripts/CATHODE/EnvironmentAnimations.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public class EnvironmentAnimations : CathodeFile
2525
public List<EnvironmentAnimation> Entries = new List<EnvironmentAnimation>();
2626
public static new Implementation Implementation = Implementation.LOAD | Implementation.CREATE | Implementation.SAVE;
2727

28+
private AnimationStrings _strings;
29+
private List<EnvironmentAnimation> _writeList = new List<EnvironmentAnimation>();
30+
2831
public EnvironmentAnimations(string path, AnimationStrings strings) : base(path)
2932
{
3033
_strings = strings;
@@ -44,9 +47,17 @@ public EnvironmentAnimations(byte[] data, AnimationStrings strings, string path
4447
}
4548
}
4649

47-
private List<EnvironmentAnimation> _writeList = new List<EnvironmentAnimation>();
50+
public void ClearReferences()
51+
{
52+
_strings = null;
53+
}
4854

49-
private AnimationStrings _strings;
55+
~EnvironmentAnimations()
56+
{
57+
ClearReferences();
58+
_writeList.Clear();
59+
Entries.Clear();
60+
}
5061

5162
#region FILE_IO
5263
override protected bool LoadInternal(MemoryStream stream)

CathodeLib/Scripts/CATHODE/EnvironmentMaps.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,28 @@ public class EnvironmentMaps : CathodeFile
1919
protected override bool HandlesLoadingManually => true;
2020
private Movers _movers;
2121

22+
/// <summary>
23+
/// This is the number of environment maps in the level. We should never reference an index higher than this.
24+
/// </summary>
25+
public int EnvironmentMapCount = 0;
26+
2227
public EnvironmentMaps(string path, Movers movers) : base(path)
2328
{
2429
_movers = movers;
2530

2631
_loaded = Load();
2732
}
2833

29-
/// <summary>
30-
/// This is the number of environment maps in the level. We should never reference an index higher than this.
31-
/// </summary>
32-
public int EnvironmentMapCount = 0;
34+
public void ClearReferences()
35+
{
36+
_movers = null;
37+
}
38+
39+
~EnvironmentMaps()
40+
{
41+
ClearReferences();
42+
Entries.Clear();
43+
}
3344

3445
#region FILE_IO
3546
override protected bool LoadInternal(MemoryStream stream)

CathodeLib/Scripts/CATHODE/GalaxyDefinition.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public GalaxyDefinition(string path) : base(path) { }
3232
public GalaxyDefinition(MemoryStream stream, string path = "") : base(stream, path) { }
3333
public GalaxyDefinition(byte[] data, string path = "") : base(data, path) { }
3434

35+
~GalaxyDefinition()
36+
{
37+
Entries.Clear();
38+
}
39+
3540
#region FILE_IO
3641
override protected bool LoadInternal(MemoryStream stream)
3742
{

0 commit comments

Comments
 (0)