From 49aa1da3a3a5cd9192e1cce841b6a8388db31393 Mon Sep 17 00:00:00 2001 From: Acruid Date: Mon, 29 Jun 2020 22:51:47 -0700 Subject: [PATCH] Enum.HasFlag was causing tons of boxing allocations, this adds a custom function that does not allocate. --- .../Movement/SharedPlayerInputMoverComponent.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Content.Shared/GameObjects/Components/Movement/SharedPlayerInputMoverComponent.cs b/Content.Shared/GameObjects/Components/Movement/SharedPlayerInputMoverComponent.cs index 74664e9fa2..c8d389e973 100644 --- a/Content.Shared/GameObjects/Components/Movement/SharedPlayerInputMoverComponent.cs +++ b/Content.Shared/GameObjects/Components/Movement/SharedPlayerInputMoverComponent.cs @@ -1,4 +1,4 @@ -using System; +using System; using Content.Shared.GameObjects.Components.Mobs; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Components; @@ -79,7 +79,7 @@ namespace Content.Shared.GameObjects.Components.Movement public float CurrentPushSpeed => 5; public float GrabRange => 0.2f; - public bool Sprinting => !_heldMoveButtons.HasFlag(MoveButtons.Walk); + public bool Sprinting => !HasFlag(_heldMoveButtons, MoveButtons.Walk); /// /// Calculated linear velocity direction of the entity. @@ -241,14 +241,14 @@ namespace Content.Shared.GameObjects.Components.Movement // if the camera is moved, this needs to be changed var x = 0; - x -= buttons.HasFlag(MoveButtons.Left) ? 1 : 0; - x += buttons.HasFlag(MoveButtons.Right) ? 1 : 0; + x -= HasFlag(buttons, MoveButtons.Left) ? 1 : 0; + x += HasFlag(buttons, MoveButtons.Right) ? 1 : 0; var y = 0; if (DiagonalMovementEnabled || x == 0) { - y -= buttons.HasFlag(MoveButtons.Down) ? 1 : 0; - y += buttons.HasFlag(MoveButtons.Up) ? 1 : 0; + y -= HasFlag(buttons, MoveButtons.Down) ? 1 : 0; + y += HasFlag(buttons, MoveButtons.Up) ? 1 : 0; } var vec = new Vector2(x, y); @@ -291,5 +291,10 @@ namespace Content.Shared.GameObjects.Components.Movement Right = 8, Walk = 16, } + + private static bool HasFlag(MoveButtons buttons, MoveButtons flag) + { + return (buttons & flag) == flag; + } } }