Browse Source

Fix various Automap drawing issues (#6555)

pull/6600/head
Eric Robinson 3 years ago committed by GitHub
parent
commit
c754d95ecc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 808
      Source/automap.cpp
  2. 52
      Source/automap.h
  3. 56
      test/automap_test.cpp

808
Source/automap.cpp

File diff suppressed because it is too large Load Diff

52
Source/automap.h

@ -36,11 +36,55 @@ extern uint8_t AutomapView[DMAXX][DMAXY];
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;
inline int AmLine(int x) /** Defines the offsets used for Automap lines */
enum class AmWidthOffset : int8_t {
None,
EighthTileRight = TILE_WIDTH >> 4,
QuarterTileRight = TILE_WIDTH >> 3,
HalfTileRight = TILE_WIDTH >> 2,
ThreeQuartersTileRight = (TILE_WIDTH >> 1) - (TILE_WIDTH >> 3),
FullTileRight = TILE_WIDTH >> 1,
DoubleTileRight = TILE_WIDTH,
EighthTileLeft = -EighthTileRight,
QuarterTileLeft = -QuarterTileRight,
HalfTileLeft = -HalfTileRight,
ThreeQuartersTileLeft = -ThreeQuartersTileRight,
FullTileLeft = -FullTileRight,
DoubleTileLeft = -DoubleTileRight,
};
enum class AmHeightOffset : int8_t {
None,
EighthTileDown = TILE_HEIGHT >> 4,
QuarterTileDown = TILE_HEIGHT >> 3,
HalfTileDown = TILE_HEIGHT >> 2,
ThreeQuartersTileDown = (TILE_HEIGHT >> 1) - (TILE_HEIGHT >> 3),
FullTileDown = TILE_HEIGHT >> 1,
DoubleTileDown = TILE_HEIGHT,
EighthTileUp = -EighthTileDown,
QuarterTileUp = -QuarterTileDown,
HalfTileUp = -HalfTileDown,
ThreeQuartersTileUp = -ThreeQuartersTileDown,
FullTileUp = -FullTileDown,
DoubleTileUp = -DoubleTileDown,
};
enum class AmLineLength : uint8_t {
QuarterTile = 2,
HalfTile = 4,
FullTile = 8,
FullAndHalfTile = 12,
DoubleTile = 16,
};
inline Displacement AmOffset(AmWidthOffset x, AmHeightOffset y)
{
return { AutoMapScale * static_cast<int>(x) / 100, AutoMapScale * static_cast<int>(y) / 100 };
}
inline int AmLine(AmLineLength l)
{ {
assert(x >= 4 && x <= 64); return AutoMapScale * static_cast<int>(l) / 100;
assert((x & (x - 1)) == 0);
return AutoMapScale * x / 100;
} }
/** /**

56
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(AmLine(64), 32); EXPECT_EQ(AmLine(AmLineLength::DoubleTile), static_cast<int>(AmLineLength::FullTile));
EXPECT_EQ(AmLine(32), 16); EXPECT_EQ(AmLine(AmLineLength::FullAndHalfTile), 6);
EXPECT_EQ(AmLine(16), 8); EXPECT_EQ(AmLine(AmLineLength::FullTile), static_cast<int>(AmLineLength::HalfTile));
EXPECT_EQ(AmLine(8), 4); EXPECT_EQ(AmLine(AmLineLength::HalfTile), static_cast<int>(AmLineLength::QuarterTile));
EXPECT_EQ(AmLine(4), 2); EXPECT_EQ(AmLine(AmLineLength::QuarterTile), 1);
} }
TEST(Automap, StartAutomap) TEST(Automap, StartAutomap)
@ -65,24 +65,23 @@ TEST(Automap, AutomapZoomIn)
AutoMapScale = 50; AutoMapScale = 50;
AutomapZoomIn(); AutomapZoomIn();
EXPECT_EQ(AutoMapScale, 75); EXPECT_EQ(AutoMapScale, 75);
EXPECT_EQ(AmLine(64), 48); EXPECT_EQ(AmLine(AmLineLength::DoubleTile), static_cast<int>(AmLineLength::FullAndHalfTile));
EXPECT_EQ(AmLine(32), 24); EXPECT_EQ(AmLine(AmLineLength::FullTile), 6);
EXPECT_EQ(AmLine(16), 12); EXPECT_EQ(AmLine(AmLineLength::HalfTile), 3);
EXPECT_EQ(AmLine(8), 6); EXPECT_EQ(AmLine(AmLineLength::QuarterTile), 1);
EXPECT_EQ(AmLine(4), 3);
} }
TEST(Automap, AutomapZoomIn_Max) TEST(Automap, AutomapZoomIn_Max)
{ {
AutoMapScale = 175;
AutoMapScale = 175; AutoMapScale = 175;
AutomapZoomIn(); AutomapZoomIn();
AutomapZoomIn(); AutomapZoomIn();
EXPECT_EQ(AutoMapScale, 200); EXPECT_EQ(AutoMapScale, 200);
EXPECT_EQ(AmLine(64), 128); EXPECT_EQ(AmLine(AmLineLength::DoubleTile), 32);
EXPECT_EQ(AmLine(32), 64); EXPECT_EQ(AmLine(AmLineLength::FullTile), static_cast<int>(AmLineLength::DoubleTile));
EXPECT_EQ(AmLine(16), 32); EXPECT_EQ(AmLine(AmLineLength::HalfTile), static_cast<int>(AmLineLength::FullTile));
EXPECT_EQ(AmLine(8), 16); EXPECT_EQ(AmLine(AmLineLength::QuarterTile), static_cast<int>(AmLineLength::HalfTile));
EXPECT_EQ(AmLine(4), 8);
} }
TEST(Automap, AutomapZoomOut) TEST(Automap, AutomapZoomOut)
@ -90,11 +89,10 @@ TEST(Automap, AutomapZoomOut)
AutoMapScale = 200; AutoMapScale = 200;
AutomapZoomOut(); AutomapZoomOut();
EXPECT_EQ(AutoMapScale, 175); EXPECT_EQ(AutoMapScale, 175);
EXPECT_EQ(AmLine(64), 112); EXPECT_EQ(AmLine(AmLineLength::DoubleTile), 28);
EXPECT_EQ(AmLine(32), 56); EXPECT_EQ(AmLine(AmLineLength::FullTile), 14);
EXPECT_EQ(AmLine(16), 28); EXPECT_EQ(AmLine(AmLineLength::HalfTile), 7);
EXPECT_EQ(AmLine(8), 14); EXPECT_EQ(AmLine(AmLineLength::QuarterTile), 3);
EXPECT_EQ(AmLine(4), 7);
} }
TEST(Automap, AutomapZoomOut_Min) TEST(Automap, AutomapZoomOut_Min)
@ -103,11 +101,10 @@ TEST(Automap, AutomapZoomOut_Min)
AutomapZoomOut(); AutomapZoomOut();
AutomapZoomOut(); AutomapZoomOut();
EXPECT_EQ(AutoMapScale, 25); EXPECT_EQ(AutoMapScale, 25);
EXPECT_EQ(AmLine(64), 16); EXPECT_EQ(AmLine(AmLineLength::DoubleTile), static_cast<int>(AmLineLength::HalfTile));
EXPECT_EQ(AmLine(32), 8); EXPECT_EQ(AmLine(AmLineLength::FullTile), static_cast<int>(AmLineLength::QuarterTile));
EXPECT_EQ(AmLine(16), 4); EXPECT_EQ(AmLine(AmLineLength::HalfTile), 1);
EXPECT_EQ(AmLine(8), 2); EXPECT_EQ(AmLine(AmLineLength::QuarterTile), 0);
EXPECT_EQ(AmLine(4), 1);
} }
TEST(Automap, AutomapZoomReset) TEST(Automap, AutomapZoomReset)
@ -119,9 +116,8 @@ 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(AmLine(64), 32); EXPECT_EQ(AmLine(AmLineLength::DoubleTile), static_cast<int>(AmLineLength::FullTile));
EXPECT_EQ(AmLine(32), 16); EXPECT_EQ(AmLine(AmLineLength::FullTile), static_cast<int>(AmLineLength::HalfTile));
EXPECT_EQ(AmLine(16), 8); EXPECT_EQ(AmLine(AmLineLength::HalfTile), static_cast<int>(AmLineLength::QuarterTile));
EXPECT_EQ(AmLine(8), 4); EXPECT_EQ(AmLine(AmLineLength::QuarterTile), 1);
EXPECT_EQ(AmLine(4), 2);
} }

Loading…
Cancel
Save