Excessive calls of a method in Bannerlord's codebase ?

Users who are viewing this thread

xtr

Recruit
While working on a mod of mine, I noticed that DefaultPartyWageModel.GetTotalWage() method is called by the game too often. Whether the game is paused or unpaused, the method is called 10 times per second for the main party. And when I count the calls for all parties, they are like 50, 100 or 200 times per second (this is when the game is unpaused). Surely parties' configurations aren't changing that often to warrant so many recalculations? And this GetTotalWage() method is rather big. Can some experienced modder tell me if this is this how it is supposed to work? This is my Harmony patch that I made to count the calls:

[HarmonyPatch(typeof(DefaultPartyWageModel), "GetTotalWage")]
public static class Patch_GetTotalWage {
private static Stopwatch stopwatch = new Stopwatch();
private static int counter = 0;

// This is the prefix method that will be called before the original method
public static void Prefix(MobileParty mobileParty, bool includeDescriptions = false) {
if (mobileParty == MobileParty.MainParty) {
if (!stopwatch.IsRunning) {
stopwatch.Start();
}

counter++;

if (stopwatch.ElapsedMilliseconds >= 1000) {
System.Diagnostics.Debug.WriteLine($"Method called {counter} times in the last second.");
counter = 0;
stopwatch.Restart();
}
}
}
}
 
Last edited:
While working on a mod of mine, I noticed that DefaultPartyWageModel.GetTotalWage() method is called by the game too often. Whether the game is paused or unpaused, the method is called 10 times per second for the main party. And when I count the calls for all parties, they are like 50, 100 or 200 times per second (this is when the game is unpaused). Surely parties' configurations aren't changing that often to warrant so many recalculations? And this GetTotalWage() method is rather big. Can some experienced modder tell me if this is this how it is supposed to work? This is my Harmony patch that I made to count the calls:

[HarmonyPatch(typeof(DefaultPartyWageModel), "GetTotalWage")]
public static class Patch_GetTotalWage {
private static Stopwatch stopwatch = new Stopwatch();
private static int counter = 0;

// This is the prefix method that will be called before the original method
public static void Prefix(MobileParty mobileParty, bool includeDescriptions = false) {
if (mobileParty == MobileParty.MainParty) {
if (!stopwatch.IsRunning) {
stopwatch.Start();
}

counter++;

if (stopwatch.ElapsedMilliseconds >= 1000) {
System.Diagnostics.Debug.WriteLine($"Method called {counter} times in the last second.");
counter = 0;
stopwatch.Restart();
}
}
}
}
You’ll need to ask on the BL-coding channel of the Mount & Blade Modding discord, few coders respond on the forums.
 
Back
Top Bottom