Browse Source

♻️ Replace usages of 'ShiftGrid' against 'Point' values with direct offset/direction-based increments

pull/2804/head
Juliano Leal Goncalves 5 years ago committed by Anders Jenbo
parent
commit
84ede906a0
  1. 29
      Source/scrollrt.cpp

29
Source/scrollrt.cpp

@ -943,11 +943,11 @@ void DrawFloor(const Surface &out, Point tilePosition, Point targetBufferPositio
} else { } else {
world_draw_black_tile(out, targetBufferPosition.x, targetBufferPosition.y); world_draw_black_tile(out, targetBufferPosition.x, targetBufferPosition.y);
} }
ShiftGrid(&tilePosition.x, &tilePosition.y, 1, 0); tilePosition += DIR_E;
targetBufferPosition.x += TILE_WIDTH; targetBufferPosition.x += TILE_WIDTH;
} }
// Return to start of row // Return to start of row
ShiftGrid(&tilePosition.x, &tilePosition.y, -columns, 0); tilePosition += Displacement::fromDirection(DIR_W) * columns;
targetBufferPosition.x -= columns * TILE_WIDTH; targetBufferPosition.x -= columns * TILE_WIDTH;
// Jump to next row // Jump to next row
@ -999,11 +999,11 @@ void DrawTileContent(const Surface &out, Point tilePosition, Point targetBufferP
DrawDungeon(out, tilePosition, targetBufferPosition); DrawDungeon(out, tilePosition, targetBufferPosition);
} }
} }
ShiftGrid(&tilePosition.x, &tilePosition.y, 1, 0); tilePosition += DIR_E;
targetBufferPosition.x += TILE_WIDTH; targetBufferPosition.x += TILE_WIDTH;
} }
// Return to start of row // Return to start of row
ShiftGrid(&tilePosition.x, &tilePosition.y, -columns, 0); tilePosition += Displacement::fromDirection(DIR_W) * columns;
targetBufferPosition.x -= columns * TILE_WIDTH; targetBufferPosition.x -= columns * TILE_WIDTH;
// Jump to next row // Jump to next row
@ -1109,23 +1109,23 @@ void DrawGame(const Surface &fullOut, Point position)
if (CanPanelsCoverView()) { if (CanPanelsCoverView()) {
if (zoomflag) { if (zoomflag) {
if (chrflag || QuestLogIsOpen) { if (chrflag || QuestLogIsOpen) {
ShiftGrid(&position.x, &position.y, 2, 0); position += Displacement::fromDirection(DIR_E) * 2;
columns -= 4; columns -= 4;
sx += SPANEL_WIDTH - TILE_WIDTH / 2; sx += SPANEL_WIDTH - TILE_WIDTH / 2;
} }
if (invflag || sbookflag) { if (invflag || sbookflag) {
ShiftGrid(&position.x, &position.y, 2, 0); position += Displacement::fromDirection(DIR_E) * 2;
columns -= 4; columns -= 4;
sx += -TILE_WIDTH / 2; sx += -TILE_WIDTH / 2;
} }
} else { } else {
if (chrflag || QuestLogIsOpen) { if (chrflag || QuestLogIsOpen) {
ShiftGrid(&position.x, &position.y, 1, 0); position += DIR_E;
columns -= 2; columns -= 2;
sx += -TILE_WIDTH / 2 / 2; // SPANEL_WIDTH accounted for in Zoom() sx += -TILE_WIDTH / 2 / 2; // SPANEL_WIDTH accounted for in Zoom()
} }
if (invflag || sbookflag) { if (invflag || sbookflag) {
ShiftGrid(&position.x, &position.y, 1, 0); position += DIR_E;
columns -= 2; columns -= 2;
sx += -TILE_WIDTH / 2 / 2; sx += -TILE_WIDTH / 2 / 2;
} }
@ -1138,12 +1138,12 @@ void DrawGame(const Surface &fullOut, Point position)
switch (ScrollInfo._sdir) { switch (ScrollInfo._sdir) {
case SDIR_N: case SDIR_N:
sy -= TILE_HEIGHT; sy -= TILE_HEIGHT;
ShiftGrid(&position.x, &position.y, 0, -1); position += DIR_N;
rows += 2; rows += 2;
break; break;
case SDIR_NE: case SDIR_NE:
sy -= TILE_HEIGHT; sy -= TILE_HEIGHT;
ShiftGrid(&position.x, &position.y, 0, -1); position += DIR_N;
columns++; columns++;
rows += 2; rows += 2;
break; break;
@ -1159,13 +1159,13 @@ void DrawGame(const Surface &fullOut, Point position)
break; break;
case SDIR_SW: case SDIR_SW:
sx -= TILE_WIDTH; sx -= TILE_WIDTH;
ShiftGrid(&position.x, &position.y, -1, 0); position += DIR_W;
columns++; columns++;
rows++; rows++;
break; break;
case SDIR_W: case SDIR_W:
sx -= TILE_WIDTH; sx -= TILE_WIDTH;
ShiftGrid(&position.x, &position.y, -1, 0); position += DIR_W;
columns++; columns++;
break; break;
case SDIR_NW: case SDIR_NW:
@ -1530,7 +1530,8 @@ void CalcViewportGeometry()
int lrow = tileRows - RowsCoveredByPanel(); int lrow = tileRows - RowsCoveredByPanel();
// Center player tile on screen // Center player tile on screen
ShiftGrid(&tileShift.deltaX, &tileShift.deltaY, -tileColums / 2, -lrow / 2); tileShift += Displacement::fromDirection(DIR_W) * (tileColums / 2);
tileShift += Displacement::fromDirection(DIR_N) * (lrow / 2);
tileRows *= 2; tileRows *= 2;
@ -1544,7 +1545,7 @@ void CalcViewportGeometry()
} }
} else if ((tileColums & 1) != 0 && (lrow & 1) != 0) { } else if ((tileColums & 1) != 0 && (lrow & 1) != 0) {
// Offset tile to vertically align the player when both rows and colums are odd // Offset tile to vertically align the player when both rows and colums are odd
ShiftGrid(&tileShift.deltaX, &tileShift.deltaY, 0, -1); tileShift += Displacement::fromDirection(DIR_N);
tileRows++; tileRows++;
tileOffset.deltaY -= TILE_HEIGHT / 2; tileOffset.deltaY -= TILE_HEIGHT / 2;
} }

Loading…
Cancel
Save