From 9678d002d3f4662381c433e4f0900aa0ec85f2ea Mon Sep 17 00:00:00 2001 From: obligaron Date: Wed, 15 Sep 2021 00:28:53 +0200 Subject: [PATCH] Reduce exported functions in debug.h --- Source/debug.cpp | 77 ++++++++++++++++++++++++++++++++++++--------- Source/debug.h | 23 ++------------ Source/scrollrt.cpp | 21 +++---------- 3 files changed, 69 insertions(+), 52 deletions(-) diff --git a/Source/debug.cpp b/Source/debug.cpp index 11a149c47..6888c1619 100644 --- a/Source/debug.cpp +++ b/Source/debug.cpp @@ -32,14 +32,32 @@ std::optional pSquareCel; bool DebugToggle = false; bool DebugGodMode = false; bool DebugVision = false; -bool DebugCoords = false; -bool DebugCursorCoords = false; bool DebugGrid = false; std::unordered_map DebugCoordsMap; -DebugInfoFlags DebugInfoFlag; namespace { +enum class DebugInfoFlags : uint16_t { + // clang-format off + empty = 0, + dPiece = 1 << 0, + dTransVal = 1 << 1, + dLight = 1 << 2, + dPreLight = 1 << 3, + dFlags = 1 << 4, + dPlayer = 1 << 5, + dMonster = 1 << 6, + dCorpse = 1 << 7, + dObject = 1 << 8, + dItem = 1 << 9, + dSpecial = 1 << 10, + // clang-format on +}; + +bool DebugCoords = false; +bool DebugCursorCoords = false; +DebugInfoFlags DebugInfoFlag; + int DebugPlayerId; int DebugQuestId; int DebugMonsterId; @@ -747,31 +765,60 @@ bool CheckDebugTextCommand(const string_view text) return true; } -int DebugGetTileData(Point dungeonCoords) +bool IsDebugGridTextNeeded() +{ + return DebugCoords || DebugGrid || DebugCursorCoords || DebugInfoFlag != DebugInfoFlags::empty; +} + +bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer) { + if (DebugCoords) { + sprintf(debugGridTextBuffer, "%d:%d", dungeonCoords.x, dungeonCoords.y); + return true; + } + if (DebugCursorCoords) { + if (dungeonCoords != cursPosition) + return false; + sprintf(debugGridTextBuffer, "%d:%d", dungeonCoords.x, dungeonCoords.y); + return true; + } + int info = 0; switch (DebugInfoFlag) { case DebugInfoFlags::dPiece: - return dPiece[dungeonCoords.x][dungeonCoords.y]; + info = dPiece[dungeonCoords.x][dungeonCoords.y]; + break; case DebugInfoFlags::dTransVal: - return dTransVal[dungeonCoords.x][dungeonCoords.y]; + info = dTransVal[dungeonCoords.x][dungeonCoords.y]; + break; case DebugInfoFlags::dLight: - return dLight[dungeonCoords.x][dungeonCoords.y]; + info = dLight[dungeonCoords.x][dungeonCoords.y]; + break; case DebugInfoFlags::dPreLight: - return dPreLight[dungeonCoords.x][dungeonCoords.y]; + info = dPreLight[dungeonCoords.x][dungeonCoords.y]; + break; case DebugInfoFlags::dFlags: - return dFlags[dungeonCoords.x][dungeonCoords.y]; + info = dFlags[dungeonCoords.x][dungeonCoords.y]; + break; case DebugInfoFlags::dPlayer: - return dPlayer[dungeonCoords.x][dungeonCoords.y]; + info = dPlayer[dungeonCoords.x][dungeonCoords.y]; + break; case DebugInfoFlags::dMonster: - return dMonster[dungeonCoords.x][dungeonCoords.y]; + info = dMonster[dungeonCoords.x][dungeonCoords.y]; + break; case DebugInfoFlags::dCorpse: - return dCorpse[dungeonCoords.x][dungeonCoords.y]; + info = dCorpse[dungeonCoords.x][dungeonCoords.y]; + break; case DebugInfoFlags::dItem: - return dItem[dungeonCoords.x][dungeonCoords.y]; + info = dItem[dungeonCoords.x][dungeonCoords.y]; + break; case DebugInfoFlags::dSpecial: - return dSpecial[dungeonCoords.x][dungeonCoords.y]; + info = dSpecial[dungeonCoords.x][dungeonCoords.y]; + break; } - return 0; + if (info == 0) + return false; + sprintf(debugGridTextBuffer, "%d", info); + return true; } } // namespace devilution diff --git a/Source/debug.h b/Source/debug.h index cddd3ffbb..73a8d3b0b 100644 --- a/Source/debug.h +++ b/Source/debug.h @@ -15,32 +15,12 @@ namespace devilution { -enum class DebugInfoFlags : uint16_t { - // clang-format off - empty = 0, - dPiece = 1 << 0, - dTransVal = 1 << 1, - dLight = 1 << 2, - dPreLight = 1 << 3, - dFlags = 1 << 4, - dPlayer = 1 << 5, - dMonster = 1 << 6, - dCorpse = 1 << 7, - dObject = 1 << 8, - dItem = 1 << 9, - dSpecial = 1 << 10, - // clang-format on -}; - extern std::optional pSquareCel; extern bool DebugToggle; extern bool DebugGodMode; extern bool DebugVision; -extern bool DebugCoords; -extern bool DebugCursorCoords; extern bool DebugGrid; extern std::unordered_map DebugCoordsMap; -extern DebugInfoFlags DebugInfoFlag; void FreeDebugGFX(); void LoadDebugGFX(); @@ -50,6 +30,7 @@ void GetDebugMonster(); void NextDebugMonster(); void SetDebugLevelSeedInfos(uint32_t mid1Seed, uint32_t mid2Seed, uint32_t mid3Seed, uint32_t endSeed); bool CheckDebugTextCommand(const string_view text); -int DebugGetTileData(Point dungeonCoords); +bool IsDebugGridTextNeeded(); +bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer); } // namespace devilution diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index cafcd0744..27bbfbc20 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -1201,32 +1201,21 @@ void DrawView(const Surface &out, Point startPosition) DrawAutomap(out.subregionY(0, gnViewportHeight)); } #ifdef _DEBUG - bool debugInfo = DebugInfoFlag != DebugInfoFlags::empty; - if (DebugCoords || DebugGrid || DebugCursorCoords || debugInfo) { + bool debugGridTextNeeded = IsDebugGridTextNeeded(); + if (debugGridTextNeeded || DebugGrid) { // force redrawing or debug stuff stays on panel on 640x480 resolution force_redraw = 255; + char debugGridTextBuffer[10]; for (auto m : DebugCoordsMap) { Point dunCoords = { m.first % MAXDUNX, m.first / MAXDUNX }; Point pixelCoords = m.second; if (!zoomflag) pixelCoords *= 2; - if (DebugCoords || (DebugCursorCoords && dunCoords == cursPosition) || debugInfo) { - char buffer[10]; - bool drawText = true; - if (!debugInfo) - sprintf(buffer, "%d:%d", dunCoords.x, dunCoords.y); - else { - int value = DebugGetTileData(dunCoords); - sprintf(buffer, "%d", value); - if (value == 0) - drawText = false; - } - + if (debugGridTextNeeded && GetDebugGridText(dunCoords, debugGridTextBuffer)) { Size tileSize = { TILE_WIDTH, TILE_HEIGHT }; if (!zoomflag) tileSize *= 2; - if (drawText) - DrawString(out, buffer, { pixelCoords - Displacement { 0, tileSize.height }, tileSize }, UiFlags::ColorRed | UiFlags::AlignCenter | UiFlags::VerticalCenter); + DrawString(out, debugGridTextBuffer, { pixelCoords - Displacement { 0, tileSize.height }, tileSize }, UiFlags::ColorRed | UiFlags::AlignCenter | UiFlags::VerticalCenter); } if (DebugGrid) { auto DrawLine = [&out](Point from, Point to, uint8_t col) {