From cfaab257ed185e37797132d8cfe5e3b777769d60 Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Tue, 11 Oct 2022 12:45:03 +0300 Subject: [PATCH] Added debug overlay for ball sprite size cutoff points. --- SpaceCadetPinball/DebugOverlay.cpp | 28 ++++++++++++++++++++++++++++ SpaceCadetPinball/DebugOverlay.h | 1 + SpaceCadetPinball/TBall.cpp | 1 + SpaceCadetPinball/options.cpp | 2 ++ SpaceCadetPinball/options.h | 1 + SpaceCadetPinball/winmain.cpp | 2 ++ 6 files changed, 35 insertions(+) diff --git a/SpaceCadetPinball/DebugOverlay.cpp b/SpaceCadetPinball/DebugOverlay.cpp index a0c794d..a3d1ff3 100644 --- a/SpaceCadetPinball/DebugOverlay.cpp +++ b/SpaceCadetPinball/DebugOverlay.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "DebugOverlay.h" +#include "loader.h" #include "maths.h" #include "proj.h" #include "winmain.h" @@ -118,6 +119,10 @@ void DebugOverlay::DrawOverlay() if (options::Options.DebugOverlaySounds) DrawSoundPositions(); + // Draw ball depth cutoff steps that determine sprite size. + if (options::Options.DebugOverlayBallDepthGrid) + DrawBallDepthSteps(); + // Restore render target SDL_SetRenderTarget(winmain::Renderer, initialRenderTarget); SDL_SetRenderDrawColor(winmain::Renderer, @@ -243,6 +248,29 @@ void DebugOverlay::DrawSoundPositions() } } +void DebugOverlay::DrawBallDepthSteps() +{ + auto& edgeMan = *TTableLayer::edge_manager; + SDL_SetRenderDrawColor(winmain::Renderer, 200, 100, 0, 255); + + for (auto ball : pb::MainTable->BallList) + { + auto visualCount = loader::query_visual_states(ball->GroupIndex); + for (auto index = 0; index < visualCount; ++index) + { + auto depthPt = reinterpret_cast(loader::query_float_attribute(ball->GroupIndex, index, 501)); + auto pt = proj::xform_to_2d(*depthPt); + + // Snap X coordinate to edge box sides + auto x1 = proj::xform_to_2d(vector2{edgeMan.MinX, depthPt->Y}).X; + auto x2 = proj::xform_to_2d(vector2{edgeMan.MaxBoxX * edgeMan.AdvanceX + edgeMan.MinX, depthPt->Y}).X; + auto ff = proj::xform_to_2d(vector2{ edgeMan.MaxBoxX * edgeMan.AdvanceX + edgeMan.MinX, depthPt->Y }); + SDL_RenderDrawLine(winmain::Renderer, x1, pt.Y, x2, pt.Y); + } + break; + } +} + void DebugOverlay::DrawCicleType(circle_type& circle) { vector2 linePt{ circle.Center.X + sqrt(circle.RadiusSq), circle.Center.Y }; diff --git a/SpaceCadetPinball/DebugOverlay.h b/SpaceCadetPinball/DebugOverlay.h index ca1d523..3c95d52 100644 --- a/SpaceCadetPinball/DebugOverlay.h +++ b/SpaceCadetPinball/DebugOverlay.h @@ -21,4 +21,5 @@ private: static void DrawBallInfo(); static void DrawAllSprites(); static void DrawSoundPositions(); + static void DrawBallDepthSteps(); }; \ No newline at end of file diff --git a/SpaceCadetPinball/TBall.cpp b/SpaceCadetPinball/TBall.cpp index c6881b7..0f53a31 100644 --- a/SpaceCadetPinball/TBall.cpp +++ b/SpaceCadetPinball/TBall.cpp @@ -54,6 +54,7 @@ TBall::TBall(TPinballTable* table) : TPinballComponent(table, -1, false) RenderSprite = new render_sprite(VisualTypes::Ball, nullptr, nullptr, 0, 0, nullptr); PinballTable->CollisionCompOffset = Offset; Position.Z = Offset; + GroupIndex = groupIndex; } void TBall::Repaint() diff --git a/SpaceCadetPinball/options.cpp b/SpaceCadetPinball/options.cpp index 7a9b4e2..740dc3c 100644 --- a/SpaceCadetPinball/options.cpp +++ b/SpaceCadetPinball/options.cpp @@ -117,6 +117,7 @@ void options::InitPrimary() Options.DebugOverlaySounds = get_int("Debug Overlay Sounds", true); translations::SetCurrentLanguage(get_string("Language", translations::GetCurrentLanguage()->ShortName).c_str()); Options.FontFileName = get_string("FontFileName", ""); + Options.DebugOverlayBallDepthGrid = get_int("Debug Overlay Ball Depth Grid", true); } void options::InitSecondary() @@ -167,6 +168,7 @@ void options::uninit() set_int("Debug Overlay Sounds", Options.DebugOverlaySounds); set_string("Language", translations::GetCurrentLanguage()->ShortName); set_string("FontFileName", Options.FontFileName.c_str()); + set_int("Debug Overlay Ball Depth Grid", Options.DebugOverlayBallDepthGrid); } diff --git a/SpaceCadetPinball/options.h b/SpaceCadetPinball/options.h index 07235d4..4157959 100644 --- a/SpaceCadetPinball/options.h +++ b/SpaceCadetPinball/options.h @@ -92,6 +92,7 @@ struct optionsStruct bool DebugOverlayCollisionMask; bool DebugOverlaySprites; bool DebugOverlaySounds; + bool DebugOverlayBallDepthGrid; std::string FontFileName; }; diff --git a/SpaceCadetPinball/winmain.cpp b/SpaceCadetPinball/winmain.cpp index 0a1ab50..bd62040 100644 --- a/SpaceCadetPinball/winmain.cpp +++ b/SpaceCadetPinball/winmain.cpp @@ -657,6 +657,8 @@ void winmain::RenderUi() { if (ImGui::MenuItem("Box Grid", nullptr, Options.DebugOverlayGrid)) Options.DebugOverlayGrid ^= true; + if (ImGui::MenuItem("Ball Depth Grid", nullptr, Options.DebugOverlayBallDepthGrid)) + Options.DebugOverlayBallDepthGrid ^= true; if (ImGui::MenuItem("Sprite Positions", nullptr, Options.DebugOverlaySprites)) Options.DebugOverlaySprites ^= true; if (ImGui::MenuItem("All Edges", nullptr, Options.DebugOverlayAllEdges))