From 46ed79ad42373950b468278981ec0d24845c5921 Mon Sep 17 00:00:00 2001 From: qndel Date: Sat, 6 Nov 2021 18:53:53 +0100 Subject: [PATCH] add megatiles to tiledata (#3211) --- Source/debug.cpp | 38 ++++++++++++++++++++++++++++++++++++++ Source/debug.h | 1 + Source/scrollrt.cpp | 45 ++++++++++++++++++++++++++++++--------------- 3 files changed, 69 insertions(+), 15 deletions(-) diff --git a/Source/debug.cpp b/Source/debug.cpp index 33535034a..3517f8284 100644 --- a/Source/debug.cpp +++ b/Source/debug.cpp @@ -52,14 +52,23 @@ enum class DebugGridTextItem : uint16_t { dObject, dItem, dSpecial, + coords, cursorcoords, objectindex, + + //take dPiece as index nBlockTable, nSolidTable, nTransTable, nMissileTable, nTrapTable, + + // megatiles + AutomapView, + dungeon, + pdungeon, + dflags, }; DebugGridTextItem SelectedDebugGridTextItem; @@ -611,6 +620,10 @@ std::string DebugCmdShowTileData(const string_view parameter) "nTransTable", "nMissileTable", "nTrapTable", + "AutomapView", + "dungeon", + "pdungeon", + "dflags", }; if (parameter == "clear") { @@ -813,9 +826,22 @@ bool IsDebugGridTextNeeded() return SelectedDebugGridTextItem != DebugGridTextItem::None; } +bool IsDebugGridInMegatiles() +{ + switch (SelectedDebugGridTextItem) { + case DebugGridTextItem::AutomapView: + case DebugGridTextItem::dungeon: + case DebugGridTextItem::pdungeon: + case DebugGridTextItem::dflags: + return true; + } + return false; +} + bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer) { int info = 0; + Point megaCoords = { (dungeonCoords.x - 16) / 2, (dungeonCoords.y - 16) / 2 }; switch (SelectedDebugGridTextItem) { case DebugGridTextItem::coords: sprintf(debugGridTextBuffer, "%d:%d", dungeonCoords.x, dungeonCoords.y); @@ -882,6 +908,18 @@ bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer) case DebugGridTextItem::nTrapTable: info = nTrapTable[dPiece[dungeonCoords.x][dungeonCoords.y]]; break; + case DebugGridTextItem::AutomapView: + info = AutomapView[megaCoords.x][megaCoords.y]; + break; + case DebugGridTextItem::dungeon: + info = dungeon[megaCoords.x][megaCoords.y]; + break; + case DebugGridTextItem::pdungeon: + info = pdungeon[megaCoords.x][megaCoords.y]; + break; + case DebugGridTextItem::dflags: + info = dflags[megaCoords.x][megaCoords.y]; + break; case DebugGridTextItem::None: return false; } diff --git a/Source/debug.h b/Source/debug.h index c398a0771..daf047625 100644 --- a/Source/debug.h +++ b/Source/debug.h @@ -31,6 +31,7 @@ void NextDebugMonster(); void SetDebugLevelSeedInfos(uint32_t mid1Seed, uint32_t mid2Seed, uint32_t mid3Seed, uint32_t endSeed); bool CheckDebugTextCommand(const string_view text); bool IsDebugGridTextNeeded(); +bool IsDebugGridInMegatiles(); bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer); } // namespace devilution diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 9be1dbe5a..52082112f 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -1203,9 +1203,15 @@ void DrawView(const Surface &out, Point startPosition) // force redrawing or debug stuff stays on panel on 640x480 resolution force_redraw = 255; char debugGridTextBuffer[10]; + bool megaTiles = IsDebugGridInMegatiles(); + for (auto m : DebugCoordsMap) { Point dunCoords = { m.first % MAXDUNX, m.first / MAXDUNX }; + if (megaTiles && (dunCoords.x % 2 == 1 || dunCoords.y % 2 == 1)) + continue; Point pixelCoords = m.second; + if (megaTiles) + pixelCoords += Displacement { 0, TILE_HEIGHT / 2 }; if (!zoomflag) pixelCoords *= 2; if (debugGridTextNeeded && GetDebugGridText(dunCoords, debugGridTextBuffer)) { @@ -1215,17 +1221,23 @@ void DrawView(const Surface &out, Point startPosition) 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) { - 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); + auto DrawDebugSquare = [&out](Point center, Displacement hor, Displacement ver, uint8_t col) { + 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); + }; + DrawLine(center - hor, center + ver, col); + DrawLine(center + hor, center + ver, col); + DrawLine(center - hor, center - ver, col); + DrawLine(center + hor, center - ver, col); }; Displacement hor = { TILE_WIDTH / 2, 0 }; @@ -1236,11 +1248,14 @@ void DrawView(const Surface &out, Point startPosition) } Point center = pixelCoords + hor - ver; + if (megaTiles) { + hor *= 2; + ver *= 2; + } + 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); + + DrawDebugSquare(center, hor, ver, col); } } }