[colobot] 16/145: Resources debug mode
Didier Raboud
odyx at moszumanska.debian.org
Mon Jul 11 12:56:12 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 e4f9360e63fcd7ee66dc942a927b0ac799d1d3e2
Author: krzys-h <krzys_h at interia.pl>
Date: Mon Mar 28 17:57:41 2016 +0200
Resources debug mode
---
src/common/event.h | 7 ++++---
src/graphics/engine/engine.cpp | 37 ++++++++++++++++++++++++++++++++++++-
src/graphics/engine/engine.h | 4 ++++
src/graphics/engine/terrain.cpp | 36 +++++++++++++++++++++---------------
src/graphics/engine/terrain.h | 2 ++
src/ui/debug_menu.cpp | 15 +++++++++++++++
6 files changed, 82 insertions(+), 19 deletions(-)
diff --git a/src/common/event.h b/src/common/event.h
index d1b851c..c5fe1f5 100644
--- a/src/common/event.h
+++ b/src/common/event.h
@@ -384,9 +384,10 @@ enum EventType
EVENT_DBG_SPAWN_OBJ = 851,
EVENT_DBG_TELEPORT = 852,
EVENT_DBG_LIGHTNING = 853,
- EVENT_DBG_CRASHSPHERES = 854,
- EVENT_DBG_LIGHTS = 855,
- EVENT_DBG_LIGHTS_DUMP = 856,
+ EVENT_DBG_RESOURCES = 854,
+ EVENT_DBG_CRASHSPHERES = 855,
+ EVENT_DBG_LIGHTS = 856,
+ EVENT_DBG_LIGHTS_DUMP = 857,
EVENT_SPAWN_CANCEL = 860,
EVENT_SPAWN_ME = 861,
diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp
index 4ab66f3..e3e3431 100644
--- a/src/graphics/engine/engine.cpp
+++ b/src/graphics/engine/engine.cpp
@@ -3971,7 +3971,7 @@ void CEngine::UpdateGroundSpotTextures()
set = true;
}
- if (clear || set)
+ if (clear || set || m_debugResources)
{
CImage shadowImg(Math::IntPoint(256, 256));
shadowImg.Fill(Gfx::IntColor(255, 255, 255, 255));
@@ -4131,6 +4131,29 @@ void CEngine::UpdateGroundSpotTextures()
}
}
+ if (m_debugResources)
+ {
+ for (float x = min.x; x < max.x; x += 1.0f)
+ {
+ for (float y = min.y; y < max.y; y += 1.0f)
+ {
+ Math::Vector pos(
+ x / 4.0f / 254.0f * 3200.0f - 1600.0f,
+ 0.0f,
+ y / 4.0f / 254.0f * 3200.0f - 1600.0f
+ );
+ TerrainRes res = m_terrain->GetResource(pos);
+ Math::IntPoint p(x-min.x, y-min.y);
+ if (res == TR_NULL)
+ {
+ shadowImg.SetPixel(p, Gfx::Color(0.5f, 0.5f, 0.5f));
+ continue;
+ }
+ shadowImg.SetPixelInt(p, ResourceToColor(res));
+ }
+ }
+ }
+
std::stringstream str;
str << "textures/shadow" << std::setfill('0') << std::setw(2) << s << ".png";
std::string texName = str.str();
@@ -5094,4 +5117,16 @@ void CEngine::DebugDumpLights()
m_debugDumpLights = true;
}
+void CEngine::SetDebugResources(bool debugResources)
+{
+ m_debugResources = debugResources;
+ m_firstGroundSpot = true; // Force a refresh of ground spot textures
+ UpdateGroundSpotTextures();
+}
+
+bool CEngine::GetDebugResources()
+{
+ return m_debugResources;
+}
+
} // namespace Gfx
diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h
index ba1b171..f95bdf3 100644
--- a/src/graphics/engine/engine.h
+++ b/src/graphics/engine/engine.h
@@ -1188,6 +1188,9 @@ public:
bool GetDebugLights();
void DebugDumpLights();
+ void SetDebugResources(bool debugResources);
+ bool GetDebugResources();
+
protected:
//! Resets some states and flushes textures after device was changed (e.g. resoulution changed)
/** Instead of calling this directly, send EVENT_RESOLUTION_CHANGED event **/
@@ -1478,6 +1481,7 @@ protected:
bool m_debugLights;
bool m_debugDumpLights;
bool m_debugCrashSpheres = false;
+ bool m_debugResources = false;
std::string m_timerText;
diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp
index 8475a8a..7ff2417 100644
--- a/src/graphics/engine/terrain.cpp
+++ b/src/graphics/engine/terrain.cpp
@@ -192,6 +192,22 @@ void CTerrain::AddMaterial(int id, const std::string& texName, const Math::Point
}
+// values from original bitmap palette
+const std::map<TerrainRes, Gfx::IntColor> RESOURCE_PALETTE = {
+ {TR_STONE, Gfx::IntColor(255, 0, 0)},
+ {TR_URANIUM, Gfx::IntColor(255, 255, 0)},
+ {TR_POWER, Gfx::IntColor( 0, 255, 0)},
+ {TR_KEY_A, Gfx::IntColor( 0, 204, 0)},
+ {TR_KEY_B, Gfx::IntColor( 51, 204, 0)},
+ {TR_KEY_C, Gfx::IntColor(102, 204, 0)},
+ {TR_KEY_D, Gfx::IntColor(153, 204, 0)}
+};
+
+Gfx::IntColor ResourceToColor(TerrainRes res)
+{
+ return RESOURCE_PALETTE.at(res);
+}
+
/**
* The image must be 24 bits/pixel and grayscale and dx x dy in size
* with dx = dy = (mosaic*brick)+1 */
@@ -224,21 +240,11 @@ bool CTerrain::LoadResources(const std::string& fileName)
Gfx::IntColor pixel = img.GetPixelInt(Math::IntPoint(x, size - y - 1));
TerrainRes res = TR_NULL;
- // values from original bitmap palette
- if (pixel.r == 255 && pixel.g == 0 && pixel.b == 0)
- res = TR_STONE;
- else if (pixel.r == 255 && pixel.g == 255 && pixel.b == 0)
- res = TR_URANIUM;
- else if (pixel.r == 0 && pixel.g == 255 && pixel.b == 0)
- res = TR_POWER;
- else if (pixel.r == 0 && pixel.g == 204 && pixel.b == 0)
- res = TR_KEY_A;
- else if (pixel.r == 51 && pixel.g == 204 && pixel.b == 0)
- res = TR_KEY_B;
- else if (pixel.r == 102 && pixel.g == 204 && pixel.b == 0)
- res = TR_KEY_C;
- else if (pixel.r == 153 && pixel.g == 204 && pixel.b == 0)
- res = TR_KEY_D;
+ for (const auto& it : RESOURCE_PALETTE)
+ {
+ if (pixel.r == it.second.r && pixel.g == it.second.g && pixel.b == it.second.b)
+ res = it.first;
+ }
m_resources[x+size*y] = static_cast<unsigned char>(res);
}
diff --git a/src/graphics/engine/terrain.h b/src/graphics/engine/terrain.h
index 7f66f72..9a86b58 100644
--- a/src/graphics/engine/terrain.h
+++ b/src/graphics/engine/terrain.h
@@ -69,6 +69,8 @@ enum TerrainRes
TR_KEY_D = 7
//@}
};
+//! Converts TerrainRes to color
+Gfx::IntColor ResourceToColor(TerrainRes res);
/**
* \class CTerrain
diff --git a/src/ui/debug_menu.cpp b/src/ui/debug_menu.cpp
index 2c98371..7d8ae15 100644
--- a/src/ui/debug_menu.cpp
+++ b/src/ui/debug_menu.cpp
@@ -94,6 +94,9 @@ void CDebugMenu::CreateInterface()
pc->SetName("Display stats");
pos.y -= 0.048f;
pos.y -= 0.048f;
+ pc = pw->CreateCheck(pos, ddim, -1, EVENT_DBG_RESOURCES);
+ pc->SetName("Underground resources");
+ pos.y -= 0.048f;
pc = pw->CreateCheck(pos, ddim, -1, EVENT_DBG_CRASHSPHERES);
pc->SetName("Render crash spheres");
pos.y -= 0.048f;
@@ -124,6 +127,7 @@ void CDebugMenu::CreateSpawnInterface()
pos.y = oy+sy*9.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_SPAWN_CANCEL);
pb->SetName("Cancel");
+ pos.y -= ddim.y;
pos.y -= dim.y;
pw->CreateButton(pos, dim, 128+8, EVENT_SPAWN_ME);
@@ -203,6 +207,12 @@ void CDebugMenu::UpdateInterface()
pc->SetState(STATE_CHECK, m_engine->GetShowStats());
}
+ pc = static_cast<CCheck*>(pw->SearchControl(EVENT_DBG_RESOURCES));
+ if (pc != nullptr)
+ {
+ pc->SetState(STATE_CHECK, m_engine->GetDebugResources());
+ }
+
pc = static_cast<CCheck*>(pw->SearchControl(EVENT_DBG_CRASHSPHERES));
if (pc != nullptr)
{
@@ -265,6 +275,11 @@ bool CDebugMenu::EventProcess(const Event &event)
UpdateInterface();
break;
+ case EVENT_DBG_RESOURCES:
+ m_engine->SetDebugResources(!m_engine->GetDebugResources());
+ UpdateInterface();
+ break;
+
case EVENT_DBG_CRASHSPHERES:
m_main->SetDebugCrashSpheres(!m_main->GetDebugCrashSpheres());
UpdateInterface();
--
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