From 2aef0e26f50e0a14588e7fd8ce53a3783b3142b6 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Wed, 18 Mar 2020 14:52:28 -0400 Subject: [PATCH] Player: stop making a List every frame. --- Shared/Player.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Shared/Player.cs b/Shared/Player.cs index d0c21bb..6a045cd 100644 --- a/Shared/Player.cs +++ b/Shared/Player.cs @@ -37,6 +37,8 @@ namespace SemiColinGames { // For passing into Line.Rasterize() during movement updates. private List movePoints = new List(100); + // Possible hitboxes for player <-> obstacles. + private List candidates = new List(10); public Player(Vector2 position, int facing) { this.position = position; @@ -68,8 +70,7 @@ namespace SemiColinGames { residual = new Vector2(movement.X - (int) movement.X, movement.Y - (int) movement.Y); // Broad test: remove all collision targets nowhere near the player. - // TODO: don't allocate a list here. - var candidates = new List(); + candidates.Clear(); // Expand the box in the direction of movement. The center is the midpoint of the line // between the player's current position and their desired movement. The width increases by // the magnitude of the movement in each direction. We add 1 to each dimension just to be