Skip to content

Commit ffeb34b

Browse files
committed
improve dead body ability performance
1 parent 76a01a5 commit ffeb34b

File tree

10 files changed

+21
-15
lines changed

10 files changed

+21
-15
lines changed

LaunchpadReloaded/Buttons/Crewmate/FreezeButton.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using MiraAPI.Utilities.Assets;
1010
using Rewired;
1111
using UnityEngine;
12-
using Helpers = MiraAPI.Utilities.Helpers;
12+
using Helpers = LaunchpadReloaded.Utilities.Helpers;
1313

1414
namespace LaunchpadReloaded.Buttons.Crewmate;
1515

@@ -33,7 +33,7 @@ public override bool Enabled(RoleBehaviour? role)
3333

3434
public override DeadBody? GetTarget()
3535
{
36-
return PlayerControl.LocalPlayer.GetNearestObjectOfType<DeadBody>(Distance, Helpers.CreateFilter(Constants.NotShipMask), "DeadBody", IsTargetValid);
36+
return PlayerControl.LocalPlayer.GetNearestObjectOfType<DeadBody>(Distance, Helpers.BodyFilter2D, "DeadBody", IsTargetValid);
3737
}
3838

3939
public override bool IsTargetValid(DeadBody? target)

LaunchpadReloaded/Buttons/Crewmate/InvestigateButton.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using MiraAPI.Utilities.Assets;
88
using Rewired;
99
using UnityEngine;
10-
using Helpers = MiraAPI.Utilities.Helpers;
10+
using Helpers = LaunchpadReloaded.Utilities.Helpers;
1111

1212
namespace LaunchpadReloaded.Buttons.Crewmate;
1313

@@ -31,7 +31,7 @@ public override bool Enabled(RoleBehaviour? role)
3131

3232
public override DeadBody? GetTarget()
3333
{
34-
return PlayerControl.LocalPlayer.GetNearestObjectOfType<DeadBody>(Distance, Helpers.CreateFilter(Constants.NotShipMask), "DeadBody", IsTargetValid);
34+
return PlayerControl.LocalPlayer.GetNearestObjectOfType<DeadBody>(Distance, Helpers.BodyFilter2D, "DeadBody", IsTargetValid);
3535
}
3636

3737
public override bool IsTargetValid(DeadBody? target)

LaunchpadReloaded/Buttons/Crewmate/ReviveButton.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
using MiraAPI.Utilities.Assets;
1212
using Rewired;
1313
using UnityEngine;
14-
using Helpers = MiraAPI.Utilities.Helpers;
14+
using Helpers = LaunchpadReloaded.Utilities.Helpers;
1515

1616
namespace LaunchpadReloaded.Buttons.Crewmate;
1717

@@ -50,7 +50,7 @@ public override void SetOutline(bool active)
5050

5151
public override DeadBody? GetTarget()
5252
{
53-
return PlayerControl.LocalPlayer.GetNearestObjectOfType<DeadBody>(Distance, Helpers.CreateFilter(Constants.NotShipMask), "DeadBody", IsTargetValid);
53+
return PlayerControl.LocalPlayer.GetNearestObjectOfType<DeadBody>(Distance, Helpers.BodyFilter2D, "DeadBody", IsTargetValid);
5454
}
5555

5656
public override bool IsTargetValid(DeadBody? target)

LaunchpadReloaded/Buttons/Crewmate/SealButton.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using MiraAPI.Utilities.Assets;
1010
using Rewired;
1111
using UnityEngine;
12-
using Helpers = MiraAPI.Utilities.Helpers;
12+
using Helpers = LaunchpadReloaded.Utilities.Helpers;
1313

1414
namespace LaunchpadReloaded.Buttons.Crewmate;
1515

@@ -33,7 +33,7 @@ public override bool Enabled(RoleBehaviour? role)
3333

3434
public override Vent? GetTarget()
3535
{
36-
return PlayerControl.LocalPlayer.GetNearestObjectOfType<Vent>(Distance, Helpers.CreateFilter(Constants.NotShipMask));
36+
return PlayerControl.LocalPlayer.GetNearestObjectOfType<Vent>(Distance, Helpers.BodyFilter2D);
3737
}
3838

3939
public override bool IsTargetValid(Vent? target)

LaunchpadReloaded/Buttons/DragButton.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
using MiraAPI.Utilities.Assets;
1313
using Rewired;
1414
using UnityEngine;
15-
using Helpers = MiraAPI.Utilities.Helpers;
15+
using Helpers = LaunchpadReloaded.Utilities.Helpers;
1616

1717
namespace LaunchpadReloaded.Buttons;
1818

@@ -36,7 +36,7 @@ public override bool Enabled(RoleBehaviour? role)
3636

3737
public override DeadBody? GetTarget()
3838
{
39-
return PlayerControl.LocalPlayer.GetNearestObjectOfType<DeadBody>(Distance, Helpers.CreateFilter(Constants.NotShipMask), "DeadBody", IsTargetValid);
39+
return PlayerControl.LocalPlayer.GetNearestObjectOfType<DeadBody>(Distance, Helpers.BodyFilter2D, "DeadBody", IsTargetValid);
4040
}
4141

4242
public override bool IsTargetValid(DeadBody? target)

LaunchpadReloaded/Buttons/Impostor/DissectButton.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using MiraAPI.Utilities.Assets;
1010
using Rewired;
1111
using UnityEngine;
12-
using Helpers = MiraAPI.Utilities.Helpers;
12+
using Helpers = LaunchpadReloaded.Utilities.Helpers;
1313

1414
namespace LaunchpadReloaded.Buttons.Impostor;
1515

@@ -32,7 +32,7 @@ public override bool Enabled(RoleBehaviour? role)
3232

3333
public override DeadBody? GetTarget()
3434
{
35-
return PlayerControl.LocalPlayer.GetNearestObjectOfType<DeadBody>(Distance, Helpers.CreateFilter(Constants.NotShipMask), "DeadBody", IsTargetValid);
35+
return PlayerControl.LocalPlayer.GetNearestObjectOfType<DeadBody>(Distance, Helpers.BodyFilter2D, "DeadBody", IsTargetValid);
3636
}
3737

3838
public override bool IsTargetValid(DeadBody? target)

LaunchpadReloaded/Buttons/Impostor/HideButton.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
using MiraAPI.Utilities.Assets;
1212
using Rewired;
1313
using UnityEngine;
14-
using Helpers = MiraAPI.Utilities.Helpers;
14+
using Helpers = LaunchpadReloaded.Utilities.Helpers;
1515

1616
namespace LaunchpadReloaded.Buttons.Impostor;
1717

@@ -32,7 +32,7 @@ public class HideButton : BaseLaunchpadButton<DeadBody>
3232

3333
public override DeadBody? GetTarget()
3434
{
35-
return PlayerControl.LocalPlayer.GetNearestObjectOfType<DeadBody>(Distance, Helpers.CreateFilter(Constants.NotShipMask), "DeadBody", IsTargetValid);
35+
return PlayerControl.LocalPlayer.GetNearestObjectOfType<DeadBody>(Distance, Helpers.BodyFilter2D, "DeadBody", IsTargetValid);
3636
}
3737

3838
public override bool IsTargetValid(DeadBody? target)

LaunchpadReloaded/Buttons/Neutral/CollectButton.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using MiraAPI.Utilities.Assets;
1010
using Rewired;
1111
using UnityEngine;
12+
using Helpers = LaunchpadReloaded.Utilities.Helpers;
1213

1314
namespace LaunchpadReloaded.Buttons.Neutral;
1415

@@ -31,7 +32,7 @@ public override bool Enabled(RoleBehaviour? role)
3132

3233
public override DeadBody? GetTarget()
3334
{
34-
return PlayerControl.LocalPlayer.GetNearestObjectOfType<DeadBody>(Distance, MiraAPI.Utilities.Helpers.CreateFilter(Constants.NotShipMask), "DeadBody", IsTargetValid);
35+
return PlayerControl.LocalPlayer.GetNearestObjectOfType<DeadBody>(Distance, Helpers.BodyFilter2D, "DeadBody", IsTargetValid);
3536
}
3637

3738
public override bool IsTargetValid(DeadBody? target)

LaunchpadReloaded/Patches/Generic/GameManagerPatch.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using HarmonyLib;
22
using LaunchpadReloaded.Components;
3+
using Reactor.Utilities;
34

45
namespace LaunchpadReloaded.Patches.Generic;
56

@@ -11,6 +12,7 @@ public static void Postfix(GameManager __instance)
1112
foreach (var deadBody in __instance.deadBodyPrefab)
1213
{
1314
deadBody.gameObject.AddComponent<DeadBodyCacheComponent>();
15+
Logger<LaunchpadReloadedPlugin>.Info("Added DeadBodyCacheComponent to dead body prefab");
1416
}
1517
}
1618
}

LaunchpadReloaded/Utilities/Helpers.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ namespace LaunchpadReloaded.Utilities;
1010
public static class Helpers
1111
{
1212
public static readonly Random Random = new();
13+
14+
private static ContactFilter2D? _bodyFilter2D;
15+
public static ContactFilter2D BodyFilter2D => _bodyFilter2D ??= MiraAPI.Utilities.Helpers.CreateFilter(Constants.NotShipMask);
1316

1417
public static bool ShouldCancelClick()
1518
{

0 commit comments

Comments
 (0)