Browse Source

Optimize DeadItem() (#7213)

Optimize DeadItem() - Look up `player.position.tile` only once.
pull/7215/head
Eric Robinson 2 years ago committed by GitHub
parent
commit
5ae0e5eb17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      Source/player.cpp

6
Source/player.cpp

@ -307,7 +307,9 @@ void DeadItem(Player &player, Item &&itm, Displacement direction)
if (itm.isEmpty())
return;
Point target = player.position.tile + direction;
const Point playerTile = player.position.tile;
const Point target = playerTile + direction;
if (direction != Displacement { 0, 0 } && ItemSpaceOk(target)) {
RespawnDeadItem(std::move(itm), target);
return;
@ -316,7 +318,7 @@ void DeadItem(Player &player, Item &&itm, Displacement direction)
for (int k = 1; k < 50; k++) {
for (int j = -k; j <= k; j++) {
for (int i = -k; i <= k; i++) {
Point next = player.position.tile + Displacement { i, j };
Point next = playerTile + Displacement { i, j };
if (ItemSpaceOk(next)) {
RespawnDeadItem(std::move(itm), next);
return;

Loading…
Cancel
Save