Browse Source

♻️ Leverage conversion constructor for 'Direction' to 'Displacement'

This makes code more consistent overall as we use the same pattern for dealing with Sizes.
pull/2812/head
Juliano Leal Goncalves 5 years ago committed by Anders Jenbo
parent
commit
32e22a16b3
  1. 2
      Source/controls/plrctrls.cpp
  2. 2
      Source/engine/point.hpp
  3. 2
      Source/monster.cpp
  4. 2
      Source/player.cpp
  5. 14
      Source/scrollrt.cpp

2
Source/controls/plrctrls.cpp

@ -1405,7 +1405,7 @@ void UpdateSpellTarget()
int range = myPlayer._pRSpell == SPL_TELEPORT ? 4 : 1;
cursPosition = myPlayer.position.future + Displacement::fromDirection(myPlayer._pdir) * range;
cursPosition = myPlayer.position.future + Displacement(myPlayer._pdir) * range;
}
/**

2
Source/engine/point.hpp

@ -35,7 +35,7 @@ struct Point {
constexpr Point &operator+=(Direction direction)
{
return (*this) += Displacement::fromDirection(direction);
return (*this) += Displacement(direction);
}
constexpr Point &operator-=(const Displacement &displacement)

2
Source/monster.cpp

@ -339,7 +339,7 @@ void PlaceGroup(int mtype, int num, UniqueMonsterPack uniqueMonsterPack, int lea
}
int j = 0;
for (int try2 = 0; j < num && try2 < 100; xp += Displacement::fromDirection(static_cast<Direction>(GenerateRnd(8))).deltaX, yp += Displacement::fromDirection(static_cast<Direction>(GenerateRnd(8))).deltaX) { /// BUGFIX: `yp += Point.y`
for (int try2 = 0; j < num && try2 < 100; xp += Displacement(static_cast<Direction>(GenerateRnd(8))).deltaX, yp += Displacement(static_cast<Direction>(GenerateRnd(8))).deltaX) { /// BUGFIX: `yp += Point.y`
if (!CanPlaceMonster(xp, yp)
|| (dTransVal[xp][yp] != dTransVal[x1][y1])
|| (uniqueMonsterPack == UniqueMonsterPack::Leashed && (abs(xp - x1) >= 4 || abs(yp - y1) >= 4))) {

2
Source/player.cpp

@ -3090,7 +3090,7 @@ StartPlayerKill(int pnum, int earflag)
Direction pdd = player._pdir;
for (auto &item : player.InvBody) {
pdd = left[pdd];
DeadItem(player, &item, Displacement::fromDirection(pdd));
DeadItem(player, &item, Displacement(pdd));
}
CalcPlrInv(player, false);

14
Source/scrollrt.cpp

@ -947,7 +947,7 @@ void DrawFloor(const Surface &out, Point tilePosition, Point targetBufferPositio
targetBufferPosition.x += TILE_WIDTH;
}
// Return to start of row
tilePosition += Displacement::fromDirection(DIR_W) * columns;
tilePosition += Displacement(DIR_W) * columns;
targetBufferPosition.x -= columns * TILE_WIDTH;
// Jump to next row
@ -1003,7 +1003,7 @@ void DrawTileContent(const Surface &out, Point tilePosition, Point targetBufferP
targetBufferPosition.x += TILE_WIDTH;
}
// Return to start of row
tilePosition += Displacement::fromDirection(DIR_W) * columns;
tilePosition += Displacement(DIR_W) * columns;
targetBufferPosition.x -= columns * TILE_WIDTH;
// Jump to next row
@ -1109,12 +1109,12 @@ void DrawGame(const Surface &fullOut, Point position)
if (CanPanelsCoverView()) {
if (zoomflag) {
if (chrflag || QuestLogIsOpen) {
position += Displacement::fromDirection(DIR_E) * 2;
position += Displacement(DIR_E) * 2;
columns -= 4;
sx += SPANEL_WIDTH - TILE_WIDTH / 2;
}
if (invflag || sbookflag) {
position += Displacement::fromDirection(DIR_E) * 2;
position += Displacement(DIR_E) * 2;
columns -= 4;
sx += -TILE_WIDTH / 2;
}
@ -1530,8 +1530,8 @@ void CalcViewportGeometry()
int lrow = tileRows - RowsCoveredByPanel();
// Center player tile on screen
tileShift += Displacement::fromDirection(DIR_W) * (tileColums / 2);
tileShift += Displacement::fromDirection(DIR_N) * (lrow / 2);
tileShift += Displacement(DIR_W) * (tileColums / 2);
tileShift += Displacement(DIR_N) * (lrow / 2);
tileRows *= 2;
@ -1545,7 +1545,7 @@ void CalcViewportGeometry()
}
} else if ((tileColums & 1) != 0 && (lrow & 1) != 0) {
// Offset tile to vertically align the player when both rows and colums are odd
tileShift += Displacement::fromDirection(DIR_N);
tileShift += Displacement(DIR_N);
tileRows++;
tileOffset.deltaY -= TILE_HEIGHT / 2;
}

Loading…
Cancel
Save