[colobot] 18/145: goto() bitmap debugger
Didier Raboud
odyx at moszumanska.debian.org
Mon Jul 11 12:56:13 UTC 2016
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch debian/master
in repository colobot.
commit e24d77bde87b20b8a4d02e8c0871d8c6748d3bc2
Author: krzys-h <krzys_h at interia.pl>
Date: Mon Mar 28 21:42:25 2016 +0200
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 7d00e87..5b2fc6e 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<Gfx::VertexCol> line)
m_displayGoto.push_back(line);
}
+void CEngine::SetDebugGotoBitmap(std::unique_ptr<CImage> 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 04757fc..a64b8c3 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<Gfx::VertexCol> line);
+ void SetDebugGotoBitmap(std::unique_ptr<CImage> debugImage);
protected:
//! Resets some states and flushes textures after device was changed (e.g. resoulution changed)
@@ -1494,6 +1495,7 @@ protected:
std::vector<Math::Sphere> m_displayCrashSpheres;
std::vector<std::vector<VertexCol>> m_displayGoto;
+ std::unique_ptr<CImage> 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 7a6c754..de37d1a 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<CImage> debugImage = MakeUnique<CImage>(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<int>(3200.0f/BM_DIM_STEP);
m_bmArray = MakeUniqueArray<unsigned char>(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<<x%8);
+ m_bmChanged = true;
}
// Removes a point in the bitmap.
@@ -2085,6 +2117,7 @@ void CTaskGoto::BitmapClearDot(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<<x%8);
+ m_bmChanged = true;
}
// Tests a point in the bitmap.
diff --git a/src/object/task/taskgoto.h b/src/object/task/taskgoto.h
index 463aaf7..908cf8f 100644
--- a/src/object/task/taskgoto.h
+++ b/src/object/task/taskgoto.h
@@ -137,6 +137,7 @@ protected:
float m_wormLastTime = 0.0f;
float m_lastDistance = 0.0f;
+ bool m_bmChanged = true;
int m_bmSize = 0; // width or height of the table
int m_bmOffset = 0; // m_bmSize/2
int m_bmLine = 0; // increment line m_bmSize/8
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list