Browse Source

Merge pull request #2711 from qndel/show_coords

pull/2737/head
qndel 5 years ago committed by GitHub
parent
commit
8436e1f641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 46
      Source/debug.cpp
  2. 5
      Source/debug.h
  3. 48
      Source/scrollrt.cpp

46
Source/debug.cpp

@ -27,6 +27,10 @@ namespace devilution {
std::optional<CelSprite> pSquareCel;
bool DebugGodMode = false;
bool DebugVision = false;
bool DebugCoords = false;
bool DebugCursorCoords = false;
bool DebugGrid = false;
std::unordered_map<int, Point> DebugCoordsMap;
namespace {
@ -406,11 +410,38 @@ std::string DebugCmdTalkToTowner(const std::string_view parameter)
return "NPC not found.";
}
std::string DebugCmdShowCoords(const std::string_view parameter)
{
DebugCoords = !DebugCoords;
if (DebugCoords)
return "I love math.";
return "I hate math.";
}
std::string DebugCmdShowGrid(const std::string_view parameter)
{
DebugGrid = !DebugGrid;
if (DebugGrid)
return "A basket full of rectangles and mushrooms.";
return "Back to boring.";
}
std::string DebugCmdShowCursorCoords(const std::string_view parameter)
{
DebugCursorCoords = !DebugCursorCoords;
if (DebugCursorCoords)
return "I am the master of coords and cursors!";
return "Cursor will never forget that.";
}
std::vector<DebugCmdItem> DebugCmdList = {
{ "help", "Prints help overview or help for a specific command.", "({command})", &DebugCmdHelp },
{ "give gold", "Fills the inventory with gold.", "", &DebugCmdGiveGoldCheat },
{ "give xp", "Levels the player up (min 1 level or {levels}).", "({levels})", &DebugCmdLevelUp },
{ "set spells", "Set spell level to {level} for all spells.", "{level}", &DebugCmdSetSpellsLevel },
{ "setspells", "Set spell level to {level} for all spells.", "{level}", &DebugCmdSetSpellsLevel },
{ "take gold", "Removes all gold from inventory.", "", &DebugCmdTakeGoldCheat },
{ "give quest", "Enable a given quest.", "({id})", &DebugCmdQuest },
{ "give map", "Reveal the map.", "", &DebugCmdMap },
@ -418,15 +449,18 @@ std::vector<DebugCmdItem> DebugCmdList = {
{ "map", "Load a quest level {level}.", "{level}", &DebugCmdLoadMap },
{ "visit", "Visit a towner.", "{towner}", &DebugCmdVisitTowner },
{ "restart", "Resets specified {level}.", "{level}", &DebugCmdResetLevel },
{ "god", "Togggles godmode.", "", &DebugCmdGodMode },
{ "r_drawvision", "Togggles vision debug rendering.", "", &DebugCmdVision },
{ "god", "Toggles godmode.", "", &DebugCmdGodMode },
{ "r_drawvision", "Toggles vision debug rendering.", "", &DebugCmdVision },
{ "r_fullbright", "Toggles whether light shading is in effect.", "", &DebugCmdLighting },
{ "refill", "Refills health and mana.", "", &DebugCmdRefillHealthMana },
{ "dropunique", "Attempts to generate unique item {name}.", "{name}", &DebugCmdGenerateUniqueItem },
{ "dropitem", "Attempts to generate item {name}.", "{name}", &DebugCmdGenerateItem },
{ "fill", "Refills health and mana.", "", &DebugCmdRefillHealthMana },
{ "dropu", "Attempts to generate unique item {name}.", "{name}", &DebugCmdGenerateUniqueItem },
{ "drop", "Attempts to generate item {name}.", "{name}", &DebugCmdGenerateItem },
{ "talkto", "Interacts with a NPC whose name contains {name}.", "{name}", &DebugCmdTalkToTowner },
{ "exit", "Exits the game.", "", &DebugCmdExit },
{ "arrow", "Changes arrow effect (normal, fire, lightning, explosion).", "{effect}", &DebugCmdArrow },
{ "coords", "Toggles showing tile coords.", "", &DebugCmdShowCoords },
{ "cursorcoords", "Toggles showing cursor coords.", "", &DebugCmdShowCursorCoords },
{ "grid", "Toggles showing grid.", "", &DebugCmdShowGrid },
};
} // namespace

5
Source/debug.h

@ -6,6 +6,7 @@
#pragma once
#include <string_view>
#include <unordered_map>
#include "engine.h"
#include "engine/cel_sprite.hpp"
@ -17,6 +18,10 @@ namespace devilution {
extern std::optional<CelSprite> pSquareCel;
extern bool DebugGodMode;
extern bool DebugVision;
extern bool DebugCoords;
extern bool DebugCursorCoords;
extern bool DebugGrid;
extern std::unordered_map<int, Point> DebugCoordsMap;
void FreeDebugGFX();
void LoadDebugGFX();

48
Source/scrollrt.cpp

@ -827,6 +827,7 @@ void DrawDungeon(const Surface &out, int sx, int sy, int dx, int dy)
if (DebugVision && (bFlag & BFLAG_LIT) != 0) {
CelClippedDrawTo(out, { dx, dy }, *pSquareCel, 1);
}
DebugCoordsMap[sx + sy * MAXDUNX] = { dx, dy };
#endif
if (MissilePreFlag) {
@ -1189,10 +1190,57 @@ void DrawGame(const Surface &fullOut, int x, int y)
*/
void DrawView(const Surface &out, int startX, int startY)
{
#ifdef _DEBUG
DebugCoordsMap.clear();
#endif
DrawGame(out, startX, startY);
if (AutomapActive) {
DrawAutomap(out.subregionY(0, gnViewportHeight));
}
#ifdef _DEBUG
if (DebugCoords || DebugGrid || DebugCursorCoords) {
for (auto m : DebugCoordsMap) {
Point dunCoords = { m.first % MAXDUNX, m.first / MAXDUNX };
Point pixelCoords = m.second;
Displacement ver = { 0, -TILE_HEIGHT / 2 };
Displacement hor = { TILE_WIDTH / 2, 0 };
if (!zoomflag) {
pixelCoords *= 2;
hor *= 2;
ver *= 2;
}
Point center = pixelCoords + hor + ver;
if (DebugCoords || (DebugCursorCoords && dunCoords == Point { cursmx, cursmy })) {
char coordstr[10];
sprintf(coordstr, "%d:%d", dunCoords.x, dunCoords.y);
int textWidth = GetLineWidth(coordstr);
int textHeight = 12;
Point position = center + Displacement { -textWidth / 2, textHeight / 2 };
DrawString(out, coordstr, { position, { textWidth, textHeight } }, UiFlags::ColorRed);
}
if (DebugGrid) {
auto DrawLine = [&out](Point from, Point to, uint8_t col) {
int dx = to.x - from.x;
int dy = to.y - from.y;
int steps = abs(dx) > abs(dy) ? abs(dx) : abs(dy);
float ix = dx / (float)steps;
float iy = dy / (float)steps;
float sx = from.x;
float sy = from.y;
for (int i = 0; i <= steps; i++, sx += ix, sy += iy)
out.SetPixel({ (int)sx, (int)sy }, col);
};
uint8_t col = PAL16_BEIGE;
DrawLine(center - hor, center - ver, col);
DrawLine(center + hor, center - ver, col);
DrawLine(center - hor, center + ver, col);
DrawLine(center + hor, center + ver, col);
}
}
}
#endif
DrawMonsterHealthBar(out);
DrawItemNameLabels(out);

Loading…
Cancel
Save