Browse Source

♻️ Move automap_render to engine/, rename 2->Steep

Also adds header file documentation.
pull/1868/head
Gleb Mazovetskiy 5 years ago committed by Anders Jenbo
parent
commit
6474dea0a9
  1. 2
      CMakeLists.txt
  2. 18
      Source/automap.cpp
  3. 20
      Source/engine/render/automap_render.cpp
  4. 19
      Source/engine/render/automap_render.hpp

2
CMakeLists.txt

@ -272,7 +272,6 @@ add_library(PKWare STATIC
set(devilutionx_SRCS
Source/appfat.cpp
Source/automap.cpp
Source/automap_render.cpp
Source/capture.cpp
Source/codec.cpp
Source/control.cpp
@ -352,6 +351,7 @@ set(devilutionx_SRCS
Source/controls/touch.cpp
Source/controls/keymapper.cpp
Source/engine/animationinfo.cpp
Source/engine/render/automap_render.cpp
Source/qol/autopickup.cpp
Source/qol/common.cpp
Source/qol/monhealthbar.cpp

18
Source/automap.cpp

@ -7,8 +7,8 @@
#include <algorithm>
#include "automap_render.hpp"
#include "control.h"
#include "engine/render/automap_render.hpp"
#include "inv.h"
#include "miniwin/miniwin.h"
#include "monster.h"
@ -284,14 +284,14 @@ void DrawAutomapPlr(const CelOutputBuffer &out, int playerId)
case DIR_N: {
const Point point { base.x, base.y - AmLine16 };
DrawVerticalLine(out, point, AmLine16, playerColor);
DrawMapLineNE2(out, { point.x - AmLine4, point.y + 2 * AmLine4 }, AmLine4, playerColor);
DrawMapLineNW2(out, { point.x + AmLine4, point.y + 2 * AmLine4 }, AmLine4, playerColor);
DrawMapLineSteepNE(out, { point.x - AmLine4, point.y + 2 * AmLine4 }, AmLine4, playerColor);
DrawMapLineSteepNW(out, { point.x + AmLine4, point.y + 2 * AmLine4 }, AmLine4, playerColor);
} break;
case DIR_NE: {
const Point point { base.x + AmLine16, base.y - AmLine8 };
DrawHorizontalLine(out, {point.x - AmLine8, point.y}, AmLine8, playerColor);
DrawMapLineNE(out, { point.x - 2 * AmLine8, point.y + AmLine8 }, AmLine8, playerColor);
DrawMapLineSW2(out, point, AmLine4, playerColor);
DrawMapLineSteepSW(out, point, AmLine4, playerColor);
} break;
case DIR_E: {
const Point point { base.x + AmLine16, base.y };
@ -303,18 +303,18 @@ void DrawAutomapPlr(const CelOutputBuffer &out, int playerId)
const Point point { base.x + AmLine16, base.y + AmLine8 };
DrawMapLineSE(out, { point.x - 2 * AmLine8, point.y - AmLine8 }, AmLine8, playerColor);
DrawHorizontalLine(out, { point.x - (AmLine8 + 1), point.y }, AmLine8 + 1, playerColor);
DrawMapLineNW2(out, point, AmLine4, playerColor);
DrawMapLineSteepNW(out, point, AmLine4, playerColor);
} break;
case DIR_S:
case DIR_OMNI: {
const Point point { base.x, base.y + AmLine16 };
DrawVerticalLine(out, { point.x, point.y - AmLine16 }, AmLine16, playerColor);
DrawMapLineSW2(out, { point.x + AmLine4, point.y - 2 * AmLine4}, AmLine4, playerColor);
DrawMapLineSE2(out, { point.x - AmLine4, point.y - 2 * AmLine4}, AmLine4, playerColor);
DrawMapLineSteepSW(out, { point.x + AmLine4, point.y - 2 * AmLine4}, AmLine4, playerColor);
DrawMapLineSteepSE(out, { point.x - AmLine4, point.y - 2 * AmLine4}, AmLine4, playerColor);
} break;
case DIR_SW: {
const Point point { base.x - AmLine16, base.y + AmLine8 };
DrawMapLineNE2(out, point, AmLine4, playerColor);
DrawMapLineSteepNE(out, point, AmLine4, playerColor);
DrawMapLineSW(out, { point.x + 2 * AmLine8, point.y - AmLine8 }, AmLine8, playerColor);
DrawHorizontalLine(out, point, AmLine8 + 1, playerColor);
} break;
@ -328,7 +328,7 @@ void DrawAutomapPlr(const CelOutputBuffer &out, int playerId)
const Point point { base.x - AmLine16, base.y - AmLine8 };
DrawMapLineNW(out, { point.x + 2 * AmLine8, point.y + AmLine8 }, AmLine8, playerColor);
DrawHorizontalLine(out, point, AmLine8 + 1, playerColor);
DrawMapLineSE2(out, point, AmLine4, playerColor);
DrawMapLineSteepSE(out, point, AmLine4, playerColor);
} break;
}
}

20
Source/automap_render.cpp → Source/engine/render/automap_render.cpp

@ -1,4 +1,4 @@
#include "automap_render.hpp"
#include "engine/render/automap_render.hpp"
namespace devilution {
namespace {
@ -27,7 +27,7 @@ void DrawMapLine(const CelOutputBuffer &out, Point from, int height, std::uint8_
}
template <DirectionX DirX, DirectionY DirY>
void DrawMapLine2(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex)
void DrawMapLineSteep(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex)
{
while (width-- > 0) {
SetPixel(out, from, colorIndex);
@ -61,24 +61,24 @@ void DrawMapLineSW(const CelOutputBuffer &out, Point from, int height, std::uint
DrawMapLine<DirectionX::WEST, DirectionY::SOUTH>(out, from, height, colorIndex);
}
void DrawMapLineNE2(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex)
void DrawMapLineSteepNE(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex)
{
DrawMapLine2<DirectionX::EAST, DirectionY::NORTH>(out, from, width, colorIndex);
DrawMapLineSteep<DirectionX::EAST, DirectionY::NORTH>(out, from, width, colorIndex);
}
void DrawMapLineSE2(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex)
void DrawMapLineSteepSE(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex)
{
DrawMapLine2<DirectionX::EAST, DirectionY::SOUTH>(out, from, width, colorIndex);
DrawMapLineSteep<DirectionX::EAST, DirectionY::SOUTH>(out, from, width, colorIndex);
}
void DrawMapLineNW2(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex)
void DrawMapLineSteepNW(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex)
{
DrawMapLine2<DirectionX::WEST, DirectionY::NORTH>(out, from, width, colorIndex);
DrawMapLineSteep<DirectionX::WEST, DirectionY::NORTH>(out, from, width, colorIndex);
}
void DrawMapLineSW2(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex)
void DrawMapLineSteepSW(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex)
{
DrawMapLine2<DirectionX::WEST, DirectionY::SOUTH>(out, from, width, colorIndex);
DrawMapLineSteep<DirectionX::WEST, DirectionY::SOUTH>(out, from, width, colorIndex);
}
} // namespace devilution

19
Source/automap_render.hpp → Source/engine/render/automap_render.hpp

@ -1,3 +1,14 @@
/** @file automap_render.hpp
* Defines 2 sets of rendering primitives for drawing automap lines.
*
* 1. DrawMapLine* - used for rendering most map lines - 2 pixels horizontally for each pixel vertically.
* 2. DrawMapLineSteep* - currently only used for rendering the player arrow - 2 pixels vertically for each pixel horizontally.
*
* These functions draw a single extra pixel at the end of the line -- they always draw an odd number of pixels.
* These functions clip to the output buffer -- they are safe to call with out-of-bounds coordinates.
*/
#pragma once
#include "engine.h"
namespace devilution {
@ -45,7 +56,7 @@ void DrawMapLineSW(const CelOutputBuffer &out, Point from, int height, std::uint
*
* The end point is at `{ from.x + width + 1, from.y - 2 * width }`.
*/
void DrawMapLineNE2(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex);
void DrawMapLineSteepNE(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex);
/**
* @brief Draw a line in the target buffer from the given point towards south east at an `atan(2)` angle.
@ -54,7 +65,7 @@ void DrawMapLineNE2(const CelOutputBuffer &out, Point from, int width, std::uint
*
* The end point is at `{ from.x + width + 1, from.y + 2 * width }`.
*/
void DrawMapLineSE2(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex);
void DrawMapLineSteepSE(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex);
/**
* @brief Draw a line in the target buffer from the given point towards north west at an `atan(1/2)` angle.
@ -63,7 +74,7 @@ void DrawMapLineSE2(const CelOutputBuffer &out, Point from, int width, std::uint
*
* The end point is at `{ from.x - (width + 1), from.y - 2 * width }`.
*/
void DrawMapLineNW2(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex);
void DrawMapLineSteepNW(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex);
/**
* @brief Draw a line in the target buffer from the given point towards south west at an `atan(1/2)` angle.
@ -72,6 +83,6 @@ void DrawMapLineNW2(const CelOutputBuffer &out, Point from, int width, std::uint
*
* The end point is at `{ from.x - (width + 1), from.y + 2 * width }`.
*/
void DrawMapLineSW2(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex);
void DrawMapLineSteepSW(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex);
} // namespace devilution
Loading…
Cancel
Save