Skip to content

Commit 9eb3e72

Browse files
committed
Utilize a shared list of CustomNavigationPoint objects instead of one per bot
Te only per-bot data was whether the bot could fire, and only one bot should be on a point at a time anyways
1 parent ca7a8fa commit 9eb3e72

File tree

5 files changed

+47
-29
lines changed

5 files changed

+47
-29
lines changed

DrakiaXYZ-Waypoints.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
<Compile Include="Patches\BotVoxelesPersonalActivatePatch.cs" />
126126
<Compile Include="Patches\FindPathPatch.cs" />
127127
<Compile Include="Patches\GroupPointCachePatch.cs" />
128+
<Compile Include="Patches\GroupPointGetByIdPatch.cs" />
128129
<Compile Include="Patches\SwitchDoorBlockerPatch.cs" />
129130
<Compile Include="Patches\DebugPatch.cs" />
130131
<Compile Include="Patches\DoorLinkPatch.cs" />

Patches/BotVoxelesPersonalActivatePatch.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,15 @@ protected override MethodBase GetTargetMethod()
1818
}
1919

2020
[PatchPrefix]
21-
public static bool PatchPrefix(AICoversData data, BotOwner ___botOwner_0, ref AICoversData ____data, ref List<CustomNavigationPoint> ____allPoints, out Stopwatch __state)
21+
public static bool PatchPrefix(AICoversData data, ref AICoversData ____data, ref List<CustomNavigationPoint> ____allPoints)
2222
{
23-
__state = new Stopwatch();
24-
__state.Start();
25-
2623
var stopwatch = new Stopwatch();
2724
stopwatch.Start();
2825

2926
____data = data;
30-
int id = ___botOwner_0.Id;
31-
32-
foreach (var groupPoint in GroupPointCachePatch.CachedGroupPoints)
27+
foreach (var navPoint in GroupPointCachePatch.CachedNavPoints)
3328
{
34-
____allPoints.Add(groupPoint.CreateCustomNavigationPoint(id));
29+
____allPoints.Add(navPoint);
3530
}
3631

3732
stopwatch.Stop();

Patches/GroupPointCachePatch.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
namespace DrakiaXYZ.Waypoints.Patches
88
{
99
/**
10-
* `CoversData` is static, so isntead of iterating through the 3d array on every bot spawn,
10+
* `CoversData` is static, so instead of iterating through the 3d array on every bot spawn,
1111
* iterate through it once on map load and cache the results
1212
*/
1313
public class GroupPointCachePatch : ModulePatch
1414
{
15-
public static List<GroupPoint> CachedGroupPoints = new List<GroupPoint>();
15+
public static List<CustomNavigationPoint> CachedNavPoints = new List<CustomNavigationPoint>();
1616

1717
protected override MethodBase GetTargetMethod()
1818
{
@@ -23,7 +23,7 @@ protected override MethodBase GetTargetMethod()
2323
public static void PatchPostfix(GameWorld __instance)
2424
{
2525
// Clear before we add anything to it
26-
CachedGroupPoints.Clear();
26+
CachedNavPoints.Clear();
2727

2828
var botGame = Singleton<IBotGame>.Instance;
2929
var data = botGame.BotsController.CoversData;
@@ -39,16 +39,16 @@ public static void PatchPostfix(GameWorld __instance)
3939
{
4040
foreach (GroupPoint groupPoint in navGraphVoxelSimple.Points)
4141
{
42-
CachedGroupPoints.Add(groupPoint);
42+
CachedNavPoints.Add(groupPoint.CreateCustomNavigationPoint(0));
4343
}
4444
}
4545
}
4646
}
4747
}
4848

49-
foreach (GroupPoint groupPoint2 in data.AIManualPointsHolder.ManualPoints)
49+
foreach (GroupPoint groupPoint in data.AIManualPointsHolder.ManualPoints)
5050
{
51-
CachedGroupPoints.Add(groupPoint2);
51+
CachedNavPoints.Add(groupPoint.CreateCustomNavigationPoint(0));
5252
}
5353
}
5454
}

Patches/GroupPointGetByIdPatch.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Aki.Reflection.Patching;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
5+
namespace DrakiaXYZ.Waypoints.Patches
6+
{
7+
public class GroupPointGetByIdPatch : ModulePatch
8+
{
9+
protected override MethodBase GetTargetMethod()
10+
{
11+
return typeof(GroupPoint).GetMethod(nameof(GroupPoint.GetById));
12+
}
13+
14+
[PatchPrefix]
15+
public static bool PatchPrefix(Dictionary<int, CustomNavigationPoint> ____childs, ref CustomNavigationPoint __result)
16+
{
17+
__result = ____childs[0];
18+
19+
// Skip original
20+
return false;
21+
}
22+
}
23+
}

WaypointsPlugin.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ private void Awake()
4747
new FindPathPatch().Enable();
4848
new GroupPointCachePatch().Enable();
4949
new BotVoxelesPersonalActivatePatch().Enable();
50+
new GroupPointGetByIdPatch().Enable();
5051

5152
// Debug perf timing output
5253
//new PerfTimingPatch().Enable();
@@ -64,23 +65,21 @@ public class PerfTimingPatch
6465

6566
public void Enable()
6667
{
67-
Logger.LogInfo($"Patching in {Assembly.GetExecutingAssembly()}");
68-
6968
var harmony = new Harmony("xyz.drakia.waypoints");
7069

71-
var props = AccessTools.GetDeclaredProperties(typeof(BotOwner));
72-
foreach (var prop in props)
73-
{
74-
var method = prop.PropertyType.GetMethod("Activate");
75-
if (method != null && !method.IsAbstract)
76-
{
77-
Logger.LogInfo($"Adding timing to {prop.PropertyType.Name}::{method.Name}");
78-
var target = method;
79-
var prefix = new HarmonyMethod(typeof(PerfTimingPatch).GetMethod("PatchPrefix"));
80-
var postfix = new HarmonyMethod(typeof(PerfTimingPatch).GetMethod("PatchPostfix"));
81-
harmony.Patch(target, prefix, postfix);
82-
}
83-
}
70+
//var props = AccessTools.GetDeclaredProperties(typeof(BotOwner));
71+
//foreach (var prop in props)
72+
//{
73+
// var method = prop.PropertyType.GetMethod("Activate");
74+
// if (method != null && !method.IsAbstract)
75+
// {
76+
// Logger.LogInfo($"Adding timing to {prop.PropertyType.Name}::{method.Name}");
77+
// var target = method;
78+
// var prefix = new HarmonyMethod(typeof(PerfTimingPatch).GetMethod("PatchPrefix"));
79+
// var postfix = new HarmonyMethod(typeof(PerfTimingPatch).GetMethod("PatchPostfix"));
80+
// harmony.Patch(target, prefix, postfix);
81+
// }
82+
//}
8483

8584
// Time the overall activate method
8685
{

0 commit comments

Comments
 (0)