Browse Source

♻️Split up DrawAutomapTile

pull/2539/head
Anders Jenbo 5 years ago
parent
commit
26756b82dc
  1. 197
      Source/automap.cpp

197
Source/automap.cpp

@ -103,6 +103,101 @@ void DrawMapHorizontalDoor(const Surface &out, Point center)
DrawDiamond(out, center, MapColorsBright); DrawDiamond(out, center, MapColorsBright);
} }
void DrawDirt(const Surface &out, Point center)
{
out.SetPixel(center, MapColorsDim);
out.SetPixel({ center.x - AmLine8, center.y - AmLine4 }, MapColorsDim);
out.SetPixel({ center.x - AmLine8, center.y + AmLine4 }, MapColorsDim);
out.SetPixel({ center.x + AmLine8, center.y - AmLine4 }, MapColorsDim);
out.SetPixel({ center.x + AmLine8, center.y + AmLine4 }, MapColorsDim);
out.SetPixel({ center.x - AmLine16, center.y }, MapColorsDim);
out.SetPixel({ center.x + AmLine16, center.y }, MapColorsDim);
out.SetPixel({ center.x, center.y - AmLine8 }, MapColorsDim);
out.SetPixel({ center.x, center.y + AmLine8 }, MapColorsDim);
out.SetPixel({ center.x + AmLine8 - AmLine32, center.y + AmLine4 }, MapColorsDim);
out.SetPixel({ center.x - AmLine8 + AmLine32, center.y + AmLine4 }, MapColorsDim);
out.SetPixel({ center.x - AmLine16, center.y + AmLine8 }, MapColorsDim);
out.SetPixel({ center.x + AmLine16, center.y + AmLine8 }, MapColorsDim);
out.SetPixel({ center.x - AmLine8, center.y + AmLine16 - AmLine4 }, MapColorsDim);
out.SetPixel({ center.x + AmLine8, center.y + AmLine16 - AmLine4 }, MapColorsDim);
out.SetPixel({ center.x, center.y + AmLine16 }, MapColorsDim);
}
void DrawStairs(const Surface &out, Point center)
{
constexpr int NumStairSteps = 4;
const Displacement offset = { -AmLine8, AmLine4 };
Point p = { center.x - AmLine8, center.y - AmLine8 - AmLine4 };
for (int i = 0; i < NumStairSteps; ++i) {
DrawMapLineSE(out, p, AmLine16, MapColorsBright);
p += offset;
}
}
/**
* Left-facing obstacle
*/
void DrawHorizontal(const Surface &out, Point center, AutomapTile tile)
{
if ((tile.flags & (AutomapFlagHorizontalDoor | AutomapFlagHorizontalGrate | AutomapFlagHorizontalArch)) == 0) {
DrawMapLineSE(out, { center.x, center.y - AmLine16 }, AmLine16, MapColorsDim);
return;
}
if ((tile.flags & AutomapFlagHorizontalDoor) != 0) {
DrawMapHorizontalDoor(out, { center.x + AmLine16, center.y - AmLine8 });
}
if ((tile.flags & AutomapFlagHorizontalGrate) != 0) {
DrawMapLineSE(out, { center.x + AmLine16, center.y - AmLine8 }, AmLine8, MapColorsDim);
DrawDiamond(out, { center.x, center.y - AmLine8 }, MapColorsDim);
} else if ((tile.flags & AutomapFlagHorizontalArch) != 0) {
DrawDiamond(out, { center.x, center.y - AmLine8 }, MapColorsDim);
}
}
/**
* Right-facing obstacle
*/
void DrawVertical(const Surface &out, Point center, AutomapTile tile)
{
if ((tile.flags & (AutomapFlagVerticalDoor | AutomapFlagVerticalGrate | AutomapFlagVerticalArch)) == 0) {
DrawMapLineNE(out, { center.x - AmLine32, center.y }, AmLine16, MapColorsDim);
return;
}
if ((tile.flags & AutomapFlagVerticalDoor) != 0) { // two wall segments with a door in the middle
DrawMapVerticalDoor(out, { center.x - AmLine16, center.y - AmLine8 });
}
if ((tile.flags & AutomapFlagVerticalGrate) != 0) { // right-facing half-wall
DrawMapLineNE(out, { center.x - AmLine32, center.y }, AmLine8, MapColorsDim);
DrawDiamond(out, { center.x, center.y - AmLine8 }, MapColorsDim);
} else if ((tile.flags & AutomapFlagVerticalArch) != 0) { // window or passable column
DrawDiamond(out, { center.x, center.y - AmLine8 }, MapColorsDim);
}
}
/**
* For caves the horizontal/vertical flags are swapped
*/
void DrawCaveHorizontal(const Surface &out, Point center, AutomapTile tile)
{
if ((tile.flags & AutomapFlagVerticalDoor) != 0) {
DrawMapHorizontalDoor(out, { center.x - AmLine16, center.y + AmLine8 });
} else {
DrawMapLineSE(out, { center.x - AmLine32, center.y }, AmLine16, MapColorsDim);
}
}
/**
* For caves the horizontal/vertical flags are swapped
*/
void DrawCaveVertical(const Surface &out, Point center, AutomapTile tile)
{
if ((tile.flags & AutomapFlagHorizontalDoor) != 0) {
DrawMapVerticalDoor(out, { center.x + AmLine16, center.y + AmLine8 });
} else {
DrawMapLineNE(out, { center.x, center.y + AmLine16 }, AmLine16, MapColorsDim);
}
}
/** /**
* @brief Renders the given automap shape at the specified screen coordinates. * @brief Renders the given automap shape at the specified screen coordinates.
*/ */
@ -112,125 +207,51 @@ void DrawAutomapTile(const Surface &out, Point center, AutomapTile tile)
return; return;
if ((tile.flags & AutomapFlagDirt) != 0) { if ((tile.flags & AutomapFlagDirt) != 0) {
out.SetPixel(center, MapColorsDim); DrawDirt(out, center);
out.SetPixel({ center.x - AmLine8, center.y - AmLine4 }, MapColorsDim);
out.SetPixel({ center.x - AmLine8, center.y + AmLine4 }, MapColorsDim);
out.SetPixel({ center.x + AmLine8, center.y - AmLine4 }, MapColorsDim);
out.SetPixel({ center.x + AmLine8, center.y + AmLine4 }, MapColorsDim);
out.SetPixel({ center.x - AmLine16, center.y }, MapColorsDim);
out.SetPixel({ center.x + AmLine16, center.y }, MapColorsDim);
out.SetPixel({ center.x, center.y - AmLine8 }, MapColorsDim);
out.SetPixel({ center.x, center.y + AmLine8 }, MapColorsDim);
out.SetPixel({ center.x + AmLine8 - AmLine32, center.y + AmLine4 }, MapColorsDim);
out.SetPixel({ center.x - AmLine8 + AmLine32, center.y + AmLine4 }, MapColorsDim);
out.SetPixel({ center.x - AmLine16, center.y + AmLine8 }, MapColorsDim);
out.SetPixel({ center.x + AmLine16, center.y + AmLine8 }, MapColorsDim);
out.SetPixel({ center.x - AmLine8, center.y + AmLine16 - AmLine4 }, MapColorsDim);
out.SetPixel({ center.x + AmLine8, center.y + AmLine16 - AmLine4 }, MapColorsDim);
out.SetPixel({ center.x, center.y + AmLine16 }, MapColorsDim);
} }
if ((tile.flags & AutomapFlagStairs) != 0) { if ((tile.flags & AutomapFlagStairs) != 0) {
constexpr int NumStairSteps = 4; DrawStairs(out, center);
const Displacement offset = { -AmLine8, AmLine4 };
Point p = { center.x - AmLine8, center.y - AmLine8 - AmLine4 };
for (int i = 0; i < NumStairSteps; ++i) {
DrawMapLineSE(out, p, AmLine16, MapColorsBright);
p += offset;
}
} }
bool drawVertical = false;
bool drawHorizontal = false;
bool drawCaveHorizontal = false;
bool drawCaveVertical = false;
switch (tile.type) { switch (tile.type) {
case AutomapTypes::Diamond: // stand-alone column or other unpassable object case AutomapTypes::Diamond: // stand-alone column or other unpassable object
DrawDiamond(out, { center.x, center.y - AmLine8 }, MapColorsDim); DrawDiamond(out, { center.x, center.y - AmLine8 }, MapColorsDim);
break; break;
case AutomapTypes::Vertical: case AutomapTypes::Vertical:
case AutomapTypes::FenceVertical: case AutomapTypes::FenceVertical:
drawVertical = true; DrawVertical(out, center, tile);
break; break;
case AutomapTypes::Horizontal: case AutomapTypes::Horizontal:
case AutomapTypes::FenceHorizontal: case AutomapTypes::FenceHorizontal:
drawHorizontal = true; DrawHorizontal(out, center, tile);
break; break;
case AutomapTypes::Cross: case AutomapTypes::Cross:
drawVertical = true; DrawVertical(out, center, tile);
drawHorizontal = true; DrawHorizontal(out, center, tile);
break; break;
case AutomapTypes::CaveHorizontalCross: case AutomapTypes::CaveHorizontalCross:
drawVertical = true; DrawVertical(out, center, tile);
drawCaveHorizontal = true; DrawCaveHorizontal(out, center, tile);
break; break;
case AutomapTypes::CaveVerticalCross: case AutomapTypes::CaveVerticalCross:
drawHorizontal = true; DrawHorizontal(out, center, tile);
drawCaveVertical = true; DrawCaveVertical(out, center, tile);
break; break;
case AutomapTypes::CaveHorizontal: case AutomapTypes::CaveHorizontal:
drawCaveHorizontal = true; DrawCaveHorizontal(out, center, tile);
break; break;
case AutomapTypes::CaveVertical: case AutomapTypes::CaveVertical:
drawCaveVertical = true; DrawCaveVertical(out, center, tile);
break; break;
case AutomapTypes::CaveCross: case AutomapTypes::CaveCross:
drawCaveHorizontal = true; DrawCaveHorizontal(out, center, tile);
drawCaveVertical = true; DrawCaveVertical(out, center, tile);
break; break;
case AutomapTypes::Corner: case AutomapTypes::Corner:
case AutomapTypes::None: case AutomapTypes::None:
break; break;
} }
if (drawVertical) { // right-facing obstacle
if ((tile.flags & AutomapFlagVerticalDoor) != 0) { // two wall segments with a door in the middle
DrawMapVerticalDoor(out, { center.x - AmLine16, center.y - AmLine8 });
}
if ((tile.flags & AutomapFlagVerticalGrate) != 0) { // right-facing half-wall
DrawMapLineNE(out, { center.x - AmLine32, center.y }, AmLine8, MapColorsDim);
tile.flags |= AutomapFlagVerticalArch;
}
if ((tile.flags & AutomapFlagVerticalArch) != 0) { // window or passable column
DrawDiamond(out, { center.x, center.y - AmLine8 }, MapColorsDim);
}
if ((tile.flags & (AutomapFlagVerticalDoor | AutomapFlagVerticalGrate | AutomapFlagVerticalArch)) == 0) {
DrawMapLineNE(out, { center.x - AmLine32, center.y }, AmLine16, MapColorsDim);
}
}
if (drawHorizontal) { // left-facing obstacle
if ((tile.flags & AutomapFlagHorizontalDoor) != 0) {
DrawMapHorizontalDoor(out, { center.x + AmLine16, center.y - AmLine8 });
}
if ((tile.flags & AutomapFlagHorizontalGrate) != 0) {
DrawMapLineSE(out, { center.x + AmLine16, center.y - AmLine8 }, AmLine8, MapColorsDim);
tile.flags |= AutomapFlagHorizontalArch;
}
if ((tile.flags & AutomapFlagHorizontalArch) != 0) {
DrawDiamond(out, { center.x, center.y - AmLine8 }, MapColorsDim);
}
if ((tile.flags & (AutomapFlagHorizontalDoor | AutomapFlagHorizontalGrate | AutomapFlagHorizontalArch)) == 0) {
DrawMapLineSE(out, { center.x, center.y - AmLine16 }, AmLine16, MapColorsDim);
}
}
// For caves the horizontal/vertical flags are swapped
if (drawCaveHorizontal) {
if ((tile.flags & AutomapFlagVerticalDoor) != 0) {
DrawMapHorizontalDoor(out, { center.x - AmLine16, center.y + AmLine8 });
} else {
DrawMapLineSE(out, { center.x - AmLine32, center.y }, AmLine16, MapColorsDim);
}
}
if (drawCaveVertical) {
if ((tile.flags & AutomapFlagHorizontalDoor) != 0) {
DrawMapVerticalDoor(out, { center.x + AmLine16, center.y + AmLine8 });
} else {
DrawMapLineNE(out, { center.x, center.y + AmLine16 }, AmLine16, MapColorsDim);
}
}
} }
void SearchAutomapItem(const Surface &out, const Displacement &myPlayerOffset) void SearchAutomapItem(const Surface &out, const Displacement &myPlayerOffset)

Loading…
Cancel
Save