Skip to content

Commit 550686a

Browse files
committed
Added output cache (massive performance boost)
Now each check is only executed once instead of once once for each def xml in each mod. Also avoids the issue where the second call will make that call execute twice, the third 3 times (1+2+3=6 times) etc. Those two combined meant a million executions of each check with around 250 mods This also fixes the issue where log entries could be written many times
1 parent 658e722 commit 550686a

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

About/About.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<name>ModCheck[B18]</name>
44
<author>Nightinggale</author>
55
<url>https://ludeon.com/forums/index.php?topic=36534.0</url>
6-
<targetVersion>0.18.2</targetVersion>
6+
<targetVersion>0.18.3</targetVersion>
77
<description>Adds the ability to create errors if required mods aren't loaded or incompatible mods are loaded as well as adding patch conditions related to other mods.
88

99
For players:

Assemblies/ModCheck.dll

0 Bytes
Binary file not shown.

Source/ModCheck.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public abstract class ModCheckBase : PatchOperation
2020

2121
protected List<string> altModNames = new List<string>();
2222

23+
private bool internalHasCache = false;
24+
private bool internalSuccess = false;
2325

2426

2527
protected bool isModLoaded(string name)
@@ -106,6 +108,14 @@ protected virtual void handleError(ArgumentException ex)
106108

107109
protected override bool ApplyWorker(XmlDocument xml)
108110
{
111+
// use cached output if it exist
112+
// the reason is that the calculations should be done once, not once for each def xml file
113+
if (internalHasCache)
114+
{
115+
return internalSuccess;
116+
}
117+
internalHasCache = true;
118+
109119
try
110120
{
111121
if (modName.NullOrEmpty()) throw new ArgumentException("MissingModName");
@@ -114,13 +124,14 @@ protected override bool ApplyWorker(XmlDocument xml)
114124
// include the modname in the alt names. That way all names will be used if alt names are looped
115125
altModNames.Add(modName);
116126

117-
bool testPassed = isTestPassed();
118-
writeLogEntry(testPassed);
119-
return testPassed;
127+
bool internalSuccess = isTestPassed();
128+
writeLogEntry(internalSuccess);
129+
return internalSuccess;
120130
}
121131
catch (ArgumentException ex)
122132
{
123133
handleError(ex);
134+
internalSuccess = false;
124135
return false;
125136
}
126137
}

changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog for ModCheck
22
Updating ModCheck will not break existing xml files.
33

4+
v1.3
5+
- Fix: checks are now only executed once (massive performance boost)
6+
- Fix: writing to the log will now always only write one line and never repeat the same many times
7+
48
v1.2
59
- Added custom message support (like logging: My mod detected modX and will patch itself accordingly)
610
- Added ability to detect another mod by more than one name (like name v1.3 and name v1.4)

0 commit comments

Comments
 (0)