Browse Source

Turn AmLine* into inline function

pull/5181/head
Vladimir Olteanu 4 years ago committed by Anders Jenbo
parent
commit
77353d2db9
  1. 215
      Source/automap.cpp
  2. 12
      Source/automap.h
  3. 60
      test/automap_test.cpp

215
Source/automap.cpp

@ -86,57 +86,57 @@ std::array<AutomapTile, 256> AutomapTypeTiles;
void DrawDiamond(const Surface &out, Point center, uint8_t color) void DrawDiamond(const Surface &out, Point center, uint8_t color)
{ {
const Point left { center.x - AmLine16, center.y }; const Point left { center.x - AmLine(16), center.y };
const Point top { center.x, center.y - AmLine8 }; const Point top { center.x, center.y - AmLine(8) };
const Point bottom { center.x, center.y + AmLine8 }; const Point bottom { center.x, center.y + AmLine(8) };
DrawMapLineNE(out, left, AmLine8, color); DrawMapLineNE(out, left, AmLine(8), color);
DrawMapLineSE(out, left, AmLine8, color); DrawMapLineSE(out, left, AmLine(8), color);
DrawMapLineSE(out, top, AmLine8, color); DrawMapLineSE(out, top, AmLine(8), color);
DrawMapLineNE(out, bottom, AmLine8, color); DrawMapLineNE(out, bottom, AmLine(8), color);
} }
void DrawMapVerticalDoor(const Surface &out, Point center, uint8_t colorBright, uint8_t colorDim) void DrawMapVerticalDoor(const Surface &out, Point center, uint8_t colorBright, uint8_t colorDim)
{ {
DrawMapLineNE(out, { center.x + AmLine8, center.y - AmLine4 }, AmLine4, colorDim); DrawMapLineNE(out, { center.x + AmLine(8), center.y - AmLine(4) }, AmLine(4), colorDim);
DrawMapLineNE(out, { center.x - AmLine16, center.y + AmLine8 }, AmLine4, colorDim); DrawMapLineNE(out, { center.x - AmLine(16), center.y + AmLine(8) }, AmLine(4), colorDim);
DrawDiamond(out, center, colorBright); DrawDiamond(out, center, colorBright);
} }
void DrawMapHorizontalDoor(const Surface &out, Point center, uint8_t colorBright, uint8_t colorDim) void DrawMapHorizontalDoor(const Surface &out, Point center, uint8_t colorBright, uint8_t colorDim)
{ {
DrawMapLineSE(out, { center.x - AmLine16, center.y - AmLine8 }, AmLine4, colorDim); DrawMapLineSE(out, { center.x - AmLine(16), center.y - AmLine(8) }, AmLine(4), colorDim);
DrawMapLineSE(out, { center.x + AmLine8, center.y + AmLine4 }, AmLine4, colorDim); DrawMapLineSE(out, { center.x + AmLine(8), center.y + AmLine(4) }, AmLine(4), colorDim);
DrawDiamond(out, center, colorBright); DrawDiamond(out, center, colorBright);
} }
void DrawDirt(const Surface &out, Point center, uint8_t color) void DrawDirt(const Surface &out, Point center, uint8_t color)
{ {
out.SetPixel(center, color); out.SetPixel(center, color);
out.SetPixel({ center.x - AmLine8, center.y - AmLine4 }, color); out.SetPixel({ center.x - AmLine(8), center.y - AmLine(4) }, color);
out.SetPixel({ center.x - AmLine8, center.y + AmLine4 }, color); out.SetPixel({ center.x - AmLine(8), center.y + AmLine(4) }, color);
out.SetPixel({ center.x + AmLine8, center.y - AmLine4 }, color); out.SetPixel({ center.x + AmLine(8), center.y - AmLine(4) }, color);
out.SetPixel({ center.x + AmLine8, center.y + AmLine4 }, color); out.SetPixel({ center.x + AmLine(8), center.y + AmLine(4) }, color);
out.SetPixel({ center.x - AmLine16, center.y }, color); out.SetPixel({ center.x - AmLine(16), center.y }, color);
out.SetPixel({ center.x + AmLine16, center.y }, color); out.SetPixel({ center.x + AmLine(16), center.y }, color);
out.SetPixel({ center.x, center.y - AmLine8 }, color); out.SetPixel({ center.x, center.y - AmLine(8) }, color);
out.SetPixel({ center.x, center.y + AmLine8 }, color); out.SetPixel({ center.x, center.y + AmLine(8) }, color);
out.SetPixel({ center.x + AmLine8 - AmLine32, center.y + AmLine4 }, color); out.SetPixel({ center.x + AmLine(8) - AmLine(32), center.y + AmLine(4) }, color);
out.SetPixel({ center.x - AmLine8 + AmLine32, center.y + AmLine4 }, color); out.SetPixel({ center.x - AmLine(8) + AmLine(32), center.y + AmLine(4) }, color);
out.SetPixel({ center.x - AmLine16, center.y + AmLine8 }, color); out.SetPixel({ center.x - AmLine(16), center.y + AmLine(8) }, color);
out.SetPixel({ center.x + AmLine16, center.y + AmLine8 }, color); out.SetPixel({ center.x + AmLine(16), center.y + AmLine(8) }, color);
out.SetPixel({ center.x - AmLine8, center.y + AmLine16 - AmLine4 }, color); out.SetPixel({ center.x - AmLine(8), center.y + AmLine(16) - AmLine(4) }, color);
out.SetPixel({ center.x + AmLine8, center.y + AmLine16 - AmLine4 }, color); out.SetPixel({ center.x + AmLine(8), center.y + AmLine(16) - AmLine(4) }, color);
out.SetPixel({ center.x, center.y + AmLine16 }, color); out.SetPixel({ center.x, center.y + AmLine(16) }, color);
} }
void DrawStairs(const Surface &out, Point center, uint8_t color) void DrawStairs(const Surface &out, Point center, uint8_t color)
{ {
constexpr int NumStairSteps = 4; constexpr int NumStairSteps = 4;
const Displacement offset = { -AmLine8, AmLine4 }; const Displacement offset = { -AmLine(8), AmLine(4) };
Point p = { center.x - AmLine8, center.y - AmLine8 - AmLine4 }; Point p = { center.x - AmLine(8), center.y - AmLine(8) - AmLine(4) };
for (int i = 0; i < NumStairSteps; ++i) { for (int i = 0; i < NumStairSteps; ++i) {
DrawMapLineSE(out, p, AmLine16, color); DrawMapLineSE(out, p, AmLine(16), color);
p += offset; p += offset;
} }
} }
@ -147,17 +147,17 @@ void DrawStairs(const Surface &out, Point center, uint8_t color)
void DrawHorizontal(const Surface &out, Point center, AutomapTile tile, uint8_t colorBright, uint8_t colorDim) void DrawHorizontal(const Surface &out, Point center, AutomapTile tile, uint8_t colorBright, uint8_t colorDim)
{ {
if (!tile.HasFlag(AutomapTile::Flags::HorizontalPassage)) { if (!tile.HasFlag(AutomapTile::Flags::HorizontalPassage)) {
DrawMapLineSE(out, { center.x, center.y - AmLine16 }, AmLine16, colorDim); DrawMapLineSE(out, { center.x, center.y - AmLine(16) }, AmLine(16), colorDim);
return; return;
} }
if (tile.HasFlag(AutomapTile::Flags::HorizontalDoor)) { if (tile.HasFlag(AutomapTile::Flags::HorizontalDoor)) {
DrawMapHorizontalDoor(out, { center.x + AmLine16, center.y - AmLine8 }, colorBright, colorDim); DrawMapHorizontalDoor(out, { center.x + AmLine(16), center.y - AmLine(8) }, colorBright, colorDim);
} }
if (tile.HasFlag(AutomapTile::Flags::HorizontalGrate)) { if (tile.HasFlag(AutomapTile::Flags::HorizontalGrate)) {
DrawMapLineSE(out, { center.x + AmLine16, center.y - AmLine8 }, AmLine8, colorDim); DrawMapLineSE(out, { center.x + AmLine(16), center.y - AmLine(8) }, AmLine(8), colorDim);
DrawDiamond(out, { center.x, center.y - AmLine8 }, colorDim); DrawDiamond(out, { center.x, center.y - AmLine(8) }, colorDim);
} else if (tile.HasFlag(AutomapTile::Flags::HorizontalArch)) { } else if (tile.HasFlag(AutomapTile::Flags::HorizontalArch)) {
DrawDiamond(out, { center.x, center.y - AmLine8 }, colorDim); DrawDiamond(out, { center.x, center.y - AmLine(8) }, colorDim);
} }
} }
@ -167,17 +167,17 @@ void DrawHorizontal(const Surface &out, Point center, AutomapTile tile, uint8_t
void DrawVertical(const Surface &out, Point center, AutomapTile tile, uint8_t colorBright, uint8_t colorDim) void DrawVertical(const Surface &out, Point center, AutomapTile tile, uint8_t colorBright, uint8_t colorDim)
{ {
if (!tile.HasFlag(AutomapTile::Flags::VerticalPassage)) { if (!tile.HasFlag(AutomapTile::Flags::VerticalPassage)) {
DrawMapLineNE(out, { center.x - AmLine32, center.y }, AmLine16, colorDim); DrawMapLineNE(out, { center.x - AmLine(32), center.y }, AmLine(16), colorDim);
return; return;
} }
if (tile.HasFlag(AutomapTile::Flags::VerticalDoor)) { // two wall segments with a door in the middle if (tile.HasFlag(AutomapTile::Flags::VerticalDoor)) { // two wall segments with a door in the middle
DrawMapVerticalDoor(out, { center.x - AmLine16, center.y - AmLine8 }, colorBright, colorDim); DrawMapVerticalDoor(out, { center.x - AmLine(16), center.y - AmLine(8) }, colorBright, colorDim);
} }
if (tile.HasFlag(AutomapTile::Flags::VerticalGrate)) { // right-facing half-wall if (tile.HasFlag(AutomapTile::Flags::VerticalGrate)) { // right-facing half-wall
DrawMapLineNE(out, { center.x - AmLine32, center.y }, AmLine8, colorDim); DrawMapLineNE(out, { center.x - AmLine(32), center.y }, AmLine(8), colorDim);
DrawDiamond(out, { center.x, center.y - AmLine8 }, colorDim); DrawDiamond(out, { center.x, center.y - AmLine(8) }, colorDim);
} else if (tile.HasFlag(AutomapTile::Flags::VerticalArch)) { // window or passable column } else if (tile.HasFlag(AutomapTile::Flags::VerticalArch)) { // window or passable column
DrawDiamond(out, { center.x, center.y - AmLine8 }, colorDim); DrawDiamond(out, { center.x, center.y - AmLine(8) }, colorDim);
} }
} }
@ -187,9 +187,9 @@ void DrawVertical(const Surface &out, Point center, AutomapTile tile, uint8_t co
void DrawCaveHorizontal(const Surface &out, Point center, AutomapTile tile, uint8_t colorBright, uint8_t colorDim) void DrawCaveHorizontal(const Surface &out, Point center, AutomapTile tile, uint8_t colorBright, uint8_t colorDim)
{ {
if (tile.HasFlag(AutomapTile::Flags::VerticalDoor)) { if (tile.HasFlag(AutomapTile::Flags::VerticalDoor)) {
DrawMapHorizontalDoor(out, { center.x - AmLine16, center.y + AmLine8 }, colorBright, colorDim); DrawMapHorizontalDoor(out, { center.x - AmLine(16), center.y + AmLine(8) }, colorBright, colorDim);
} else { } else {
DrawMapLineSE(out, { center.x - AmLine32, center.y }, AmLine16, colorDim); DrawMapLineSE(out, { center.x - AmLine(32), center.y }, AmLine(16), colorDim);
} }
} }
@ -199,9 +199,9 @@ void DrawCaveHorizontal(const Surface &out, Point center, AutomapTile tile, uint
void DrawCaveVertical(const Surface &out, Point center, AutomapTile tile, uint8_t colorBright, uint8_t colorDim) void DrawCaveVertical(const Surface &out, Point center, AutomapTile tile, uint8_t colorBright, uint8_t colorDim)
{ {
if (tile.HasFlag(AutomapTile::Flags::HorizontalDoor)) { if (tile.HasFlag(AutomapTile::Flags::HorizontalDoor)) {
DrawMapVerticalDoor(out, { center.x + AmLine16, center.y + AmLine8 }, colorBright, colorDim); DrawMapVerticalDoor(out, { center.x + AmLine(16), center.y + AmLine(8) }, colorBright, colorDim);
} else { } else {
DrawMapLineNE(out, { center.x, center.y + AmLine16 }, AmLine16, colorDim); DrawMapLineNE(out, { center.x, center.y + AmLine(16) }, AmLine(16), colorDim);
} }
} }
@ -305,7 +305,7 @@ void DrawAutomapTile(const Surface &out, Point center, Point map)
switch (tile.type) { switch (tile.type) {
case AutomapTile::Types::Diamond: // stand-alone column or other unpassable object case AutomapTile::Types::Diamond: // stand-alone column or other unpassable object
DrawDiamond(out, { center.x, center.y - AmLine8 }, colorDim); DrawDiamond(out, { center.x, center.y - AmLine(8) }, colorDim);
break; break;
case AutomapTile::Types::Vertical: case AutomapTile::Types::Vertical:
case AutomapTile::Types::FenceVertical: case AutomapTile::Types::FenceVertical:
@ -370,8 +370,8 @@ void SearchAutomapItem(const Surface &out, const Displacement &myPlayerOffset)
int py = j - 2 * AutomapOffset.deltaY - ViewPosition.y; int py = j - 2 * AutomapOffset.deltaY - ViewPosition.y;
Point screen = { Point screen = {
(myPlayerOffset.deltaX * AutoMapScale / 100 / 2) + (px - py) * AmLine16 + gnScreenWidth / 2, (myPlayerOffset.deltaX * AutoMapScale / 100 / 2) + (px - py) * AmLine(16) + gnScreenWidth / 2,
(myPlayerOffset.deltaY * AutoMapScale / 100 / 2) + (px + py) * AmLine8 + (gnScreenHeight - GetMainPanel().size.height) / 2 (myPlayerOffset.deltaY * AutoMapScale / 100 / 2) + (px + py) * AmLine(8) + (gnScreenHeight - GetMainPanel().size.height) / 2
}; };
if (CanPanelsCoverView()) { if (CanPanelsCoverView()) {
@ -380,7 +380,7 @@ void SearchAutomapItem(const Surface &out, const Displacement &myPlayerOffset)
if (IsLeftPanelOpen()) if (IsLeftPanelOpen())
screen.x += 160; screen.x += 160;
} }
screen.y -= AmLine8; screen.y -= AmLine(8);
DrawDiamond(out, screen, MapColorsItem); DrawDiamond(out, screen, MapColorsItem);
} }
} }
@ -407,8 +407,8 @@ void DrawAutomapPlr(const Surface &out, const Displacement &myPlayerOffset, int
playerOffset = GetOffsetForWalking(player.AnimInfo, player._pdir); playerOffset = GetOffsetForWalking(player.AnimInfo, player._pdir);
Point base = { Point base = {
((playerOffset.deltaX + myPlayerOffset.deltaX) * AutoMapScale / 100 / 2) + (px - py) * AmLine16 + gnScreenWidth / 2, ((playerOffset.deltaX + myPlayerOffset.deltaX) * AutoMapScale / 100 / 2) + (px - py) * AmLine(16) + gnScreenWidth / 2,
((playerOffset.deltaY + myPlayerOffset.deltaY) * AutoMapScale / 100 / 2) + (px + py) * AmLine8 + (gnScreenHeight - GetMainPanel().size.height) / 2 ((playerOffset.deltaY + myPlayerOffset.deltaY) * AutoMapScale / 100 / 2) + (px + py) * AmLine(8) + (gnScreenHeight - GetMainPanel().size.height) / 2
}; };
if (CanPanelsCoverView()) { if (CanPanelsCoverView()) {
@ -417,56 +417,56 @@ void DrawAutomapPlr(const Surface &out, const Displacement &myPlayerOffset, int
if (IsLeftPanelOpen()) if (IsLeftPanelOpen())
base.x += gnScreenWidth / 4; base.x += gnScreenWidth / 4;
} }
base.y -= AmLine16; base.y -= AmLine(16);
switch (player._pdir) { switch (player._pdir) {
case Direction::North: { case Direction::North: {
const Point point { base.x, base.y - AmLine16 }; const Point point { base.x, base.y - AmLine(16) };
DrawVerticalLine(out, point, AmLine16, playerColor); DrawVerticalLine(out, point, AmLine(16), playerColor);
DrawMapLineSteepNE(out, { point.x - AmLine4, point.y + 2 * AmLine4 }, AmLine4, playerColor); DrawMapLineSteepNE(out, { point.x - AmLine(4), point.y + 2 * AmLine(4) }, AmLine(4), playerColor);
DrawMapLineSteepNW(out, { point.x + AmLine4, point.y + 2 * AmLine4 }, AmLine4, playerColor); DrawMapLineSteepNW(out, { point.x + AmLine(4), point.y + 2 * AmLine(4) }, AmLine(4), playerColor);
} break; } break;
case Direction::NorthEast: { case Direction::NorthEast: {
const Point point { base.x + AmLine16, base.y - AmLine8 }; const Point point { base.x + AmLine(16), base.y - AmLine(8) };
DrawHorizontalLine(out, { point.x - AmLine8, point.y }, AmLine8, playerColor); DrawHorizontalLine(out, { point.x - AmLine(8), point.y }, AmLine(8), playerColor);
DrawMapLineNE(out, { point.x - 2 * AmLine8, point.y + AmLine8 }, AmLine8, playerColor); DrawMapLineNE(out, { point.x - 2 * AmLine(8), point.y + AmLine(8) }, AmLine(8), playerColor);
DrawMapLineSteepSW(out, point, AmLine4, playerColor); DrawMapLineSteepSW(out, point, AmLine(4), playerColor);
} break; } break;
case Direction::East: { case Direction::East: {
const Point point { base.x + AmLine16, base.y }; const Point point { base.x + AmLine(16), base.y };
DrawMapLineNW(out, point, AmLine4, playerColor); DrawMapLineNW(out, point, AmLine(4), playerColor);
DrawHorizontalLine(out, { point.x - AmLine16, point.y }, AmLine16, playerColor); DrawHorizontalLine(out, { point.x - AmLine(16), point.y }, AmLine(16), playerColor);
DrawMapLineSW(out, point, AmLine4, playerColor); DrawMapLineSW(out, point, AmLine(4), playerColor);
} break; } break;
case Direction::SouthEast: { case Direction::SouthEast: {
const Point point { base.x + AmLine16, base.y + AmLine8 }; const Point point { base.x + AmLine(16), base.y + AmLine(8) };
DrawMapLineSteepNW(out, point, AmLine4, playerColor); DrawMapLineSteepNW(out, point, AmLine(4), playerColor);
DrawMapLineSE(out, { point.x - 2 * AmLine8, point.y - AmLine8 }, AmLine8, playerColor); DrawMapLineSE(out, { point.x - 2 * AmLine(8), point.y - AmLine(8) }, AmLine(8), playerColor);
DrawHorizontalLine(out, { point.x - (AmLine8 + 1), point.y }, AmLine8 + 1, playerColor); DrawHorizontalLine(out, { point.x - (AmLine(8) + 1), point.y }, AmLine(8) + 1, playerColor);
} break; } break;
case Direction::South: { case Direction::South: {
const Point point { base.x, base.y + AmLine16 }; const Point point { base.x, base.y + AmLine(16) };
DrawVerticalLine(out, { point.x, point.y - AmLine16 }, AmLine16, playerColor); DrawVerticalLine(out, { point.x, point.y - AmLine(16) }, AmLine(16), playerColor);
DrawMapLineSteepSW(out, { point.x + AmLine4, point.y - 2 * AmLine4 }, AmLine4, playerColor); DrawMapLineSteepSW(out, { point.x + AmLine(4), point.y - 2 * AmLine(4) }, AmLine(4), playerColor);
DrawMapLineSteepSE(out, { point.x - AmLine4, point.y - 2 * AmLine4 }, AmLine4, playerColor); DrawMapLineSteepSE(out, { point.x - AmLine(4), point.y - 2 * AmLine(4) }, AmLine(4), playerColor);
} break; } break;
case Direction::SouthWest: { case Direction::SouthWest: {
const Point point { base.x - AmLine16, base.y + AmLine8 }; const Point point { base.x - AmLine(16), base.y + AmLine(8) };
DrawMapLineSteepNE(out, point, AmLine4, playerColor); DrawMapLineSteepNE(out, point, AmLine(4), playerColor);
DrawMapLineSW(out, { point.x + 2 * AmLine8, point.y - AmLine8 }, AmLine8, playerColor); DrawMapLineSW(out, { point.x + 2 * AmLine(8), point.y - AmLine(8) }, AmLine(8), playerColor);
DrawHorizontalLine(out, point, AmLine8 + 1, playerColor); DrawHorizontalLine(out, point, AmLine(8) + 1, playerColor);
} break; } break;
case Direction::West: { case Direction::West: {
const Point point { base.x - AmLine16, base.y }; const Point point { base.x - AmLine(16), base.y };
DrawMapLineNE(out, point, AmLine4, playerColor); DrawMapLineNE(out, point, AmLine(4), playerColor);
DrawHorizontalLine(out, point, AmLine16 + 1, playerColor); DrawHorizontalLine(out, point, AmLine(16) + 1, playerColor);
DrawMapLineSE(out, point, AmLine4, playerColor); DrawMapLineSE(out, point, AmLine(4), playerColor);
} break; } break;
case Direction::NorthWest: { case Direction::NorthWest: {
const Point point { base.x - AmLine16, base.y - AmLine8 }; const Point point { base.x - AmLine(16), base.y - AmLine(8) };
DrawMapLineNW(out, { point.x + 2 * AmLine8, point.y + AmLine8 }, AmLine8, playerColor); DrawMapLineNW(out, { point.x + 2 * AmLine(8), point.y + AmLine(8) }, AmLine(8), playerColor);
DrawHorizontalLine(out, point, AmLine8 + 1, playerColor); DrawHorizontalLine(out, point, AmLine(8) + 1, playerColor);
DrawMapLineSteepSE(out, point, AmLine4, playerColor); DrawMapLineSteepSE(out, point, AmLine(4), playerColor);
} break; } break;
} }
} }
@ -562,21 +562,11 @@ bool AutomapActive;
uint8_t AutomapView[DMAXX][DMAXY]; uint8_t AutomapView[DMAXX][DMAXY];
int AutoMapScale; int AutoMapScale;
Displacement AutomapOffset; Displacement AutomapOffset;
int AmLine64;
int AmLine32;
int AmLine16;
int AmLine8;
int AmLine4;
void InitAutomapOnce() void InitAutomapOnce()
{ {
AutomapActive = false; AutomapActive = false;
AutoMapScale = 50; AutoMapScale = 50;
AmLine64 = 32;
AmLine32 = 16;
AmLine16 = 8;
AmLine8 = 4;
AmLine4 = 2;
} }
void InitAutomap() void InitAutomap()
@ -630,11 +620,6 @@ void AutomapZoomIn()
return; return;
AutoMapScale += 5; AutoMapScale += 5;
AmLine64 = (AutoMapScale * 64) / 100;
AmLine32 = AmLine64 / 2;
AmLine16 = AmLine32 / 2;
AmLine8 = AmLine16 / 2;
AmLine4 = AmLine8 / 2;
} }
void AutomapZoomOut() void AutomapZoomOut()
@ -643,11 +628,6 @@ void AutomapZoomOut()
return; return;
AutoMapScale -= 5; AutoMapScale -= 5;
AmLine64 = (AutoMapScale * 64) / 100;
AmLine32 = AmLine64 / 2;
AmLine16 = AmLine32 / 2;
AmLine8 = AmLine16 / 2;
AmLine4 = AmLine8 / 2;
} }
void DrawAutomap(const Surface &out) void DrawAutomap(const Surface &out)
@ -689,19 +669,19 @@ void DrawAutomap(const Surface &out)
(gnScreenHeight - GetMainPanel().size.height) / 2 (gnScreenHeight - GetMainPanel().size.height) / 2
}; };
if ((cells & 1) != 0) { if ((cells & 1) != 0) {
screen.x -= AmLine64 * ((cells - 1) / 2); screen.x -= AmLine(64) * ((cells - 1) / 2);
screen.y -= AmLine32 * ((cells + 1) / 2); screen.y -= AmLine(32) * ((cells + 1) / 2);
} else { } else {
screen.x -= AmLine64 * (cells / 2) - AmLine32; screen.x -= AmLine(64) * (cells / 2) - AmLine(32);
screen.y -= AmLine32 * (cells / 2) + AmLine16; screen.y -= AmLine(32) * (cells / 2) + AmLine(16);
} }
if ((ViewPosition.x & 1) != 0) { if ((ViewPosition.x & 1) != 0) {
screen.x -= AmLine16; screen.x -= AmLine(16);
screen.y -= AmLine8; screen.y -= AmLine(8);
} }
if ((ViewPosition.y & 1) != 0) { if ((ViewPosition.y & 1) != 0) {
screen.x += AmLine16; screen.x += AmLine(16);
screen.y -= AmLine8; screen.y -= AmLine(8);
} }
screen.x += AutoMapScale * myPlayerOffset.deltaX / 100 / 2; screen.x += AutoMapScale * myPlayerOffset.deltaX / 100 / 2;
@ -722,17 +702,17 @@ void DrawAutomap(const Surface &out)
Point tile1 = screen; Point tile1 = screen;
for (int j = 0; j < cells; j++) { for (int j = 0; j < cells; j++) {
DrawAutomapTile(out, tile1, { map.x + j, map.y - j }); DrawAutomapTile(out, tile1, { map.x + j, map.y - j });
tile1.x += AmLine64; tile1.x += AmLine(64);
} }
map.y++; map.y++;
Point tile2 { screen.x - AmLine32, screen.y + AmLine16 }; Point tile2 { screen.x - AmLine(32), screen.y + AmLine(16) };
for (int j = 0; j <= cells; j++) { for (int j = 0; j <= cells; j++) {
DrawAutomapTile(out, tile2, { map.x + j, map.y - j }); DrawAutomapTile(out, tile2, { map.x + j, map.y - j });
tile2.x += AmLine64; tile2.x += AmLine(64);
} }
map.x++; map.x++;
screen.y += AmLine32; screen.y += AmLine(32);
} }
for (int playerId = 0; playerId < MAX_PLRS; playerId++) { for (int playerId = 0; playerId < MAX_PLRS; playerId++) {
@ -833,11 +813,6 @@ void SetAutomapView(Point position, MapExplorationType explorer)
void AutomapZoomReset() void AutomapZoomReset()
{ {
AutomapOffset = { 0, 0 }; AutomapOffset = { 0, 0 };
AmLine64 = (AutoMapScale * 64) / 100;
AmLine32 = AmLine64 / 2;
AmLine16 = AmLine32 / 2;
AmLine8 = AmLine16 / 2;
AmLine4 = AmLine8 / 2;
} }
} // namespace devilution } // namespace devilution

12
Source/automap.h

@ -35,11 +35,13 @@ extern uint8_t AutomapView[DMAXX][DMAXY];
/** Specifies the scale of the automap. */ /** Specifies the scale of the automap. */
extern DVL_API_FOR_TEST int AutoMapScale; extern DVL_API_FOR_TEST int AutoMapScale;
extern DVL_API_FOR_TEST Displacement AutomapOffset; extern DVL_API_FOR_TEST Displacement AutomapOffset;
extern DVL_API_FOR_TEST int AmLine64;
extern DVL_API_FOR_TEST int AmLine32; inline int AmLine(int x)
extern DVL_API_FOR_TEST int AmLine16; {
extern DVL_API_FOR_TEST int AmLine8; assert(x >= 4 && x <= 64);
extern DVL_API_FOR_TEST int AmLine4; assert((x & (x - 1)) == 0);
return AutoMapScale * x / 100;
}
/** /**
* @brief Initializes the automap. * @brief Initializes the automap.

60
test/automap_test.cpp

@ -9,11 +9,11 @@ TEST(Automap, InitAutomap)
InitAutomapOnce(); InitAutomapOnce();
EXPECT_EQ(AutomapActive, false); EXPECT_EQ(AutomapActive, false);
EXPECT_EQ(AutoMapScale, 50); EXPECT_EQ(AutoMapScale, 50);
EXPECT_EQ(AmLine64, 32); EXPECT_EQ(AmLine(64), 32);
EXPECT_EQ(AmLine32, 16); EXPECT_EQ(AmLine(32), 16);
EXPECT_EQ(AmLine16, 8); EXPECT_EQ(AmLine(16), 8);
EXPECT_EQ(AmLine8, 4); EXPECT_EQ(AmLine(8), 4);
EXPECT_EQ(AmLine4, 2); EXPECT_EQ(AmLine(4), 2);
} }
TEST(Automap, StartAutomap) TEST(Automap, StartAutomap)
@ -65,11 +65,11 @@ TEST(Automap, AutomapZoomIn)
AutoMapScale = 50; AutoMapScale = 50;
AutomapZoomIn(); AutomapZoomIn();
EXPECT_EQ(AutoMapScale, 55); EXPECT_EQ(AutoMapScale, 55);
EXPECT_EQ(AmLine64, 35); EXPECT_EQ(AmLine(64), 35);
EXPECT_EQ(AmLine32, 17); EXPECT_EQ(AmLine(32), 17);
EXPECT_EQ(AmLine16, 8); EXPECT_EQ(AmLine(16), 8);
EXPECT_EQ(AmLine8, 4); EXPECT_EQ(AmLine(8), 4);
EXPECT_EQ(AmLine4, 2); EXPECT_EQ(AmLine(4), 2);
} }
TEST(Automap, AutomapZoomIn_Max) TEST(Automap, AutomapZoomIn_Max)
@ -78,11 +78,11 @@ TEST(Automap, AutomapZoomIn_Max)
AutomapZoomIn(); AutomapZoomIn();
AutomapZoomIn(); AutomapZoomIn();
EXPECT_EQ(AutoMapScale, 200); EXPECT_EQ(AutoMapScale, 200);
EXPECT_EQ(AmLine64, 128); EXPECT_EQ(AmLine(64), 128);
EXPECT_EQ(AmLine32, 64); EXPECT_EQ(AmLine(32), 64);
EXPECT_EQ(AmLine16, 32); EXPECT_EQ(AmLine(16), 32);
EXPECT_EQ(AmLine8, 16); EXPECT_EQ(AmLine(8), 16);
EXPECT_EQ(AmLine4, 8); EXPECT_EQ(AmLine(4), 8);
} }
TEST(Automap, AutomapZoomOut) TEST(Automap, AutomapZoomOut)
@ -90,11 +90,11 @@ TEST(Automap, AutomapZoomOut)
AutoMapScale = 200; AutoMapScale = 200;
AutomapZoomOut(); AutomapZoomOut();
EXPECT_EQ(AutoMapScale, 195); EXPECT_EQ(AutoMapScale, 195);
EXPECT_EQ(AmLine64, 124); EXPECT_EQ(AmLine(64), 124);
EXPECT_EQ(AmLine32, 62); EXPECT_EQ(AmLine(32), 62);
EXPECT_EQ(AmLine16, 31); EXPECT_EQ(AmLine(16), 31);
EXPECT_EQ(AmLine8, 15); EXPECT_EQ(AmLine(8), 15);
EXPECT_EQ(AmLine4, 7); EXPECT_EQ(AmLine(4), 7);
} }
TEST(Automap, AutomapZoomOut_Min) TEST(Automap, AutomapZoomOut_Min)
@ -103,11 +103,11 @@ TEST(Automap, AutomapZoomOut_Min)
AutomapZoomOut(); AutomapZoomOut();
AutomapZoomOut(); AutomapZoomOut();
EXPECT_EQ(AutoMapScale, 50); EXPECT_EQ(AutoMapScale, 50);
EXPECT_EQ(AmLine64, 32); EXPECT_EQ(AmLine(64), 32);
EXPECT_EQ(AmLine32, 16); EXPECT_EQ(AmLine(32), 16);
EXPECT_EQ(AmLine16, 8); EXPECT_EQ(AmLine(16), 8);
EXPECT_EQ(AmLine8, 4); EXPECT_EQ(AmLine(8), 4);
EXPECT_EQ(AmLine4, 2); EXPECT_EQ(AmLine(4), 2);
} }
TEST(Automap, AutomapZoomReset) TEST(Automap, AutomapZoomReset)
@ -119,9 +119,9 @@ TEST(Automap, AutomapZoomReset)
EXPECT_EQ(AutomapOffset.deltaX, 0); EXPECT_EQ(AutomapOffset.deltaX, 0);
EXPECT_EQ(AutomapOffset.deltaY, 0); EXPECT_EQ(AutomapOffset.deltaY, 0);
EXPECT_EQ(AutoMapScale, 50); EXPECT_EQ(AutoMapScale, 50);
EXPECT_EQ(AmLine64, 32); EXPECT_EQ(AmLine(64), 32);
EXPECT_EQ(AmLine32, 16); EXPECT_EQ(AmLine(32), 16);
EXPECT_EQ(AmLine16, 8); EXPECT_EQ(AmLine(16), 8);
EXPECT_EQ(AmLine8, 4); EXPECT_EQ(AmLine(8), 4);
EXPECT_EQ(AmLine4, 2); EXPECT_EQ(AmLine(4), 2);
} }

Loading…
Cancel
Save