From e24d77bde87b20b8a4d02e8c0871d8c6748d3bc2 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 28 Mar 2016 21:42:25 +0200 Subject: [PATCH] goto() bitmap debugger --- src/graphics/engine/engine.cpp | 27 ++++++++++++++++++++++++++- src/graphics/engine/engine.h | 2 ++ src/object/task/taskgoto.cpp | 33 +++++++++++++++++++++++++++++++++ src/object/task/taskgoto.h | 1 + 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 7d00e874..5b2fc6e5 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -3986,7 +3986,7 @@ void CEngine::UpdateGroundSpotTextures() set = true; } - if (clear || set || m_debugResources) + if (clear || set || m_debugResources || m_displayGotoImage != nullptr) { CImage shadowImg(Math::IntPoint(256, 256)); shadowImg.Fill(Gfx::IntColor(255, 255, 255, 255)); @@ -4169,6 +4169,20 @@ void CEngine::UpdateGroundSpotTextures() } } + if (m_displayGotoImage != nullptr) + { + Math::IntPoint size = m_displayGotoImage->GetSize(); + for (float x = min.x; x < max.x; x += 1.0f) + { + for (float y = min.y; y < max.y; y += 1.0f) + { + int px = x / 4.0f / 254.0f * size.x; + int py = y / 4.0f / 254.0f * size.y; + shadowImg.SetPixelInt(Math::IntPoint(x-min.x, y-min.y), m_displayGotoImage->GetPixelInt(Math::IntPoint(px, py))); + } + } + } + std::stringstream str; str << "textures/shadow" << std::setfill('0') << std::setw(2) << s << ".png"; std::string texName = str.str(); @@ -5147,6 +5161,10 @@ bool CEngine::GetDebugResources() void CEngine::SetDebugGoto(bool debugGoto) { m_debugGoto = debugGoto; + if (!m_debugGoto) + { + m_displayGotoImage.reset(); + } } bool CEngine::GetDebugGoto() @@ -5159,4 +5177,11 @@ void CEngine::AddDebugGotoLine(std::vector line) m_displayGoto.push_back(line); } +void CEngine::SetDebugGotoBitmap(std::unique_ptr debugImage) +{ + m_displayGotoImage = std::move(debugImage); + m_firstGroundSpot = true; // Force ground spot texture reload + UpdateGroundSpotTextures(); +} + } // namespace Gfx diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 04757fc7..a64b8c3c 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -1194,6 +1194,7 @@ public: void SetDebugGoto(bool debugGoto); bool GetDebugGoto(); void AddDebugGotoLine(std::vector line); + void SetDebugGotoBitmap(std::unique_ptr debugImage); protected: //! Resets some states and flushes textures after device was changed (e.g. resoulution changed) @@ -1494,6 +1495,7 @@ protected: std::vector m_displayCrashSpheres; std::vector> m_displayGoto; + std::unique_ptr m_displayGotoImage; //! Pause the animation updates bool m_pause = false; diff --git a/src/object/task/taskgoto.cpp b/src/object/task/taskgoto.cpp index 7a6c754e..de37d1a1 100644 --- a/src/object/task/taskgoto.cpp +++ b/src/object/task/taskgoto.cpp @@ -22,6 +22,7 @@ #include "common/event.h" #include "common/global.h" +#include "common/image.h" #include "common/make_unique.h" #include "graphics/engine/terrain.h" @@ -65,6 +66,9 @@ CTaskGoto::CTaskGoto(COldObject* object) : CForegroundTask(object) CTaskGoto::~CTaskGoto() { BitmapClose(); + + if (m_engine->GetDebugGoto() && m_object->GetSelect()) + m_engine->SetDebugGotoBitmap(std::move(nullptr)); } @@ -105,6 +109,31 @@ bool CTaskGoto::EventProcess(const Event &event) debugLine.push_back(Gfx::VertexCol(m_object->GetPosition(), color)); debugLine.push_back(Gfx::VertexCol(AdjustPoint(m_bmTotal > 0 && m_bmIndex <= m_bmTotal && m_phase != TGP_BEAMSEARCH ? m_bmPoints[m_bmIndex] : m_goal), color)); m_engine->AddDebugGotoLine(debugLine); + + if (m_object->GetSelect() && m_bmChanged) + { + if (m_bmArray != nullptr) + { + std::unique_ptr debugImage = MakeUnique(Math::IntPoint(m_bmSize, m_bmSize)); + debugImage->Fill(Gfx::IntColor(255, 255, 255, 255)); + for (int x = 0; x < m_bmSize; x++) + { + for (int y = 0; y < m_bmSize; y++) + { + bool a = BitmapTestDot(0, x, y); + bool b = BitmapTestDot(1, x, y); + if (a || b) + { + Gfx::Color c = Gfx::Color(0.0f, 0.0f, 0.0f, 1.0f); + if (b) c = Gfx::Color(0.0f, 0.0f, 1.0f, 1.0f); + debugImage->SetPixel(Math::IntPoint(x, y), c); + } + } + } + m_engine->SetDebugGotoBitmap(std::move(debugImage)); + } + m_bmChanged = false; + } } if ( m_engine->GetPause() ) return true; @@ -2001,6 +2030,7 @@ bool CTaskGoto::BitmapOpen() m_bmSize = static_cast(3200.0f/BM_DIM_STEP); m_bmArray = MakeUniqueArray(m_bmSize*m_bmSize/8*2); + m_bmChanged = true; m_bmOffset = m_bmSize/2; m_bmLine = m_bmSize/8; @@ -2018,6 +2048,7 @@ bool CTaskGoto::BitmapOpen() bool CTaskGoto::BitmapClose() { m_bmArray.reset(); + m_bmChanged = true; return true; } @@ -2074,6 +2105,7 @@ void CTaskGoto::BitmapSetDot(int rank, int x, int y) y < 0 || y >= m_bmSize ) return; m_bmArray[rank*m_bmLine*m_bmSize + m_bmLine*y + x/8] |= (1<= m_bmSize ) return; m_bmArray[rank*m_bmLine*m_bmSize + m_bmLine*y + x/8] &= ~(1<