Resources debug mode

dev-time-step
krzys-h 2016-03-28 17:57:41 +02:00
parent 4af02c86f8
commit e4f9360e63
6 changed files with 82 additions and 19 deletions

View File

@ -384,9 +384,10 @@ enum EventType
EVENT_DBG_SPAWN_OBJ = 851, EVENT_DBG_SPAWN_OBJ = 851,
EVENT_DBG_TELEPORT = 852, EVENT_DBG_TELEPORT = 852,
EVENT_DBG_LIGHTNING = 853, EVENT_DBG_LIGHTNING = 853,
EVENT_DBG_CRASHSPHERES = 854, EVENT_DBG_RESOURCES = 854,
EVENT_DBG_LIGHTS = 855, EVENT_DBG_CRASHSPHERES = 855,
EVENT_DBG_LIGHTS_DUMP = 856, EVENT_DBG_LIGHTS = 856,
EVENT_DBG_LIGHTS_DUMP = 857,
EVENT_SPAWN_CANCEL = 860, EVENT_SPAWN_CANCEL = 860,
EVENT_SPAWN_ME = 861, EVENT_SPAWN_ME = 861,

View File

@ -3971,7 +3971,7 @@ void CEngine::UpdateGroundSpotTextures()
set = true; set = true;
} }
if (clear || set) if (clear || set || m_debugResources)
{ {
CImage shadowImg(Math::IntPoint(256, 256)); CImage shadowImg(Math::IntPoint(256, 256));
shadowImg.Fill(Gfx::IntColor(255, 255, 255, 255)); 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; std::stringstream str;
str << "textures/shadow" << std::setfill('0') << std::setw(2) << s << ".png"; str << "textures/shadow" << std::setfill('0') << std::setw(2) << s << ".png";
std::string texName = str.str(); std::string texName = str.str();
@ -5094,4 +5117,16 @@ void CEngine::DebugDumpLights()
m_debugDumpLights = true; 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 } // namespace Gfx

View File

@ -1188,6 +1188,9 @@ public:
bool GetDebugLights(); bool GetDebugLights();
void DebugDumpLights(); void DebugDumpLights();
void SetDebugResources(bool debugResources);
bool GetDebugResources();
protected: protected:
//! Resets some states and flushes textures after device was changed (e.g. resoulution changed) //! Resets some states and flushes textures after device was changed (e.g. resoulution changed)
/** Instead of calling this directly, send EVENT_RESOLUTION_CHANGED event **/ /** Instead of calling this directly, send EVENT_RESOLUTION_CHANGED event **/
@ -1478,6 +1481,7 @@ protected:
bool m_debugLights; bool m_debugLights;
bool m_debugDumpLights; bool m_debugDumpLights;
bool m_debugCrashSpheres = false; bool m_debugCrashSpheres = false;
bool m_debugResources = false;
std::string m_timerText; std::string m_timerText;

View File

@ -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 * The image must be 24 bits/pixel and grayscale and dx x dy in size
* with dx = dy = (mosaic*brick)+1 */ * 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)); Gfx::IntColor pixel = img.GetPixelInt(Math::IntPoint(x, size - y - 1));
TerrainRes res = TR_NULL; TerrainRes res = TR_NULL;
// values from original bitmap palette for (const auto& it : RESOURCE_PALETTE)
if (pixel.r == 255 && pixel.g == 0 && pixel.b == 0) {
res = TR_STONE; if (pixel.r == it.second.r && pixel.g == it.second.g && pixel.b == it.second.b)
else if (pixel.r == 255 && pixel.g == 255 && pixel.b == 0) res = it.first;
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;
m_resources[x+size*y] = static_cast<unsigned char>(res); m_resources[x+size*y] = static_cast<unsigned char>(res);
} }

View File

@ -69,6 +69,8 @@ enum TerrainRes
TR_KEY_D = 7 TR_KEY_D = 7
//@} //@}
}; };
//! Converts TerrainRes to color
Gfx::IntColor ResourceToColor(TerrainRes res);
/** /**
* \class CTerrain * \class CTerrain

View File

@ -94,6 +94,9 @@ void CDebugMenu::CreateInterface()
pc->SetName("Display stats"); pc->SetName("Display stats");
pos.y -= 0.048f; pos.y -= 0.048f;
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 = pw->CreateCheck(pos, ddim, -1, EVENT_DBG_CRASHSPHERES);
pc->SetName("Render crash spheres"); pc->SetName("Render crash spheres");
pos.y -= 0.048f; pos.y -= 0.048f;
@ -124,6 +127,7 @@ void CDebugMenu::CreateSpawnInterface()
pos.y = oy+sy*9.0f; pos.y = oy+sy*9.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_SPAWN_CANCEL); pb = pw->CreateButton(pos, ddim, -1, EVENT_SPAWN_CANCEL);
pb->SetName("Cancel"); pb->SetName("Cancel");
pos.y -= ddim.y;
pos.y -= dim.y; pos.y -= dim.y;
pw->CreateButton(pos, dim, 128+8, EVENT_SPAWN_ME); pw->CreateButton(pos, dim, 128+8, EVENT_SPAWN_ME);
@ -203,6 +207,12 @@ void CDebugMenu::UpdateInterface()
pc->SetState(STATE_CHECK, m_engine->GetShowStats()); 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)); pc = static_cast<CCheck*>(pw->SearchControl(EVENT_DBG_CRASHSPHERES));
if (pc != nullptr) if (pc != nullptr)
{ {
@ -265,6 +275,11 @@ bool CDebugMenu::EventProcess(const Event &event)
UpdateInterface(); UpdateInterface();
break; break;
case EVENT_DBG_RESOURCES:
m_engine->SetDebugResources(!m_engine->GetDebugResources());
UpdateInterface();
break;
case EVENT_DBG_CRASHSPHERES: case EVENT_DBG_CRASHSPHERES:
m_main->SetDebugCrashSpheres(!m_main->GetDebugCrashSpheres()); m_main->SetDebugCrashSpheres(!m_main->GetDebugCrashSpheres());
UpdateInterface(); UpdateInterface();