Player: stop making a List<AABB> every frame.

This commit is contained in:
Colin McMillen 2020-03-18 14:52:28 -04:00
parent de01b04873
commit 2aef0e26f5

View File

@ -37,6 +37,8 @@ namespace SemiColinGames {
// For passing into Line.Rasterize() during movement updates. // For passing into Line.Rasterize() during movement updates.
private List<Point> movePoints = new List<Point>(100); private List<Point> movePoints = new List<Point>(100);
// Possible hitboxes for player <-> obstacles.
private List<AABB> candidates = new List<AABB>(10);
public Player(Vector2 position, int facing) { public Player(Vector2 position, int facing) {
this.position = position; this.position = position;
@ -68,8 +70,7 @@ namespace SemiColinGames {
residual = new Vector2(movement.X - (int) movement.X, movement.Y - (int) movement.Y); residual = new Vector2(movement.X - (int) movement.X, movement.Y - (int) movement.Y);
// Broad test: remove all collision targets nowhere near the player. // Broad test: remove all collision targets nowhere near the player.
// TODO: don't allocate a list here. candidates.Clear();
var candidates = new List<AABB>();
// Expand the box in the direction of movement. The center is the midpoint of the line // 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 // 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 // the magnitude of the movement in each direction. We add 1 to each dimension just to be