summaryrefslogtreecommitdiffstats
path: root/src/graphics/engine
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2013-06-17 18:06:39 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2013-06-17 18:17:21 +0200
commit366d3a551ef3541f6eeb226f80a16b8de8fdd2e9 (patch)
tree191548d0cdf98740db0f6fa0eeb9e700d11450cf /src/graphics/engine
parent868b5927064aba1ca72bd403446f9ff84c99c29b (diff)
downloadcolobot-366d3a551ef3541f6eeb226f80a16b8de8fdd2e9.tar.gz
colobot-366d3a551ef3541f6eeb226f80a16b8de8fdd2e9.tar.bz2
colobot-366d3a551ef3541f6eeb226f80a16b8de8fdd2e9.zip
Added debug aids for lighting
* displaying positions of current lights (F11) * dumping info to console (F10) * added assert() in suspicious place in CPyro
Diffstat (limited to 'src/graphics/engine')
-rw-r--r--src/graphics/engine/engine.cpp27
-rw-r--r--src/graphics/engine/engine.h3
-rw-r--r--src/graphics/engine/lightman.cpp64
-rw-r--r--src/graphics/engine/lightman.h6
-rw-r--r--src/graphics/engine/pyro.cpp1
5 files changed, 98 insertions, 3 deletions
diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp
index 3423864..669ea42 100644
--- a/src/graphics/engine/engine.cpp
+++ b/src/graphics/engine/engine.cpp
@@ -128,6 +128,9 @@ CEngine::CEngine(CApplication *app)
m_interfaceMode = false;
+ m_debugLights = false;
+ m_debugDumpLights = false;
+
m_mice[ENG_MOUSE_NORM] = EngineMouse( 0, 1, 32, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::Point( 1.0f, 1.0f));
m_mice[ENG_MOUSE_WAIT] = EngineMouse( 2, 3, 33, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::Point( 8.0f, 12.0f));
m_mice[ENG_MOUSE_HAND] = EngineMouse( 4, 5, 34, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::Point( 7.0f, 2.0f));
@@ -325,7 +328,22 @@ bool CEngine::ProcessEvent(const Event &event)
if (event.type == EVENT_KEY_DOWN)
{
if (event.key.key == KEY(F12))
+ {
m_showStats = !m_showStats;
+ return false;
+ }
+
+ if (event.key.key == KEY(F11))
+ {
+ m_debugLights = !m_debugLights;
+ return false;
+ }
+
+ if (event.key.key == KEY(F10))
+ {
+ m_debugDumpLights = true;
+ return false;
+ }
}
// By default, pass on all events
@@ -3293,6 +3311,15 @@ void CEngine::Draw3DScene()
m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN);
+ if (m_debugLights)
+ m_device->DebugLights();
+
+ if (m_debugDumpLights)
+ {
+ m_debugDumpLights = false;
+ m_lightMan->DebugDumpLights();
+ }
+
if (m_waterMode)
{
m_app->StartPerformanceCounter(PCNT_RENDER_WATER);
diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h
index 207ae27..5ecde8f 100644
--- a/src/graphics/engine/engine.h
+++ b/src/graphics/engine/engine.h
@@ -1437,6 +1437,9 @@ protected:
//! True when drawing 2D UI
bool m_interfaceMode;
+
+ bool m_debugLights;
+ bool m_debugDumpLights;
};
diff --git a/src/graphics/engine/lightman.cpp b/src/graphics/engine/lightman.cpp
index cbb8509..3e512d8 100644
--- a/src/graphics/engine/lightman.cpp
+++ b/src/graphics/engine/lightman.cpp
@@ -71,6 +71,7 @@ void LightProgression::SetTarget(float value)
DynamicLight::DynamicLight()
{
+ rank = 0;
used = enabled = false;
priority = LIGHT_PRI_LOW;
includeType = excludeType = ENG_OBJTYPE_NULL;
@@ -98,6 +99,61 @@ void CLightManager::SetDevice(CDevice* device)
m_lightMap = std::vector<int>(m_device->GetMaxLightCount(), -1);
}
+void CLightManager::DebugDumpLights()
+{
+ CLogger* l = GetLogger();
+
+ l->Debug("Dynamic lights:\n");
+
+ for (int i = 0; i < static_cast<int>( m_dynLights.size() ); ++i)
+ {
+ const DynamicLight& dynLight = m_dynLights[i];
+ if (!dynLight.used)
+ continue;
+
+ int deviceLight = -1;
+ for (int j = 0; j < m_lightMap.size(); ++j)
+ {
+ if (m_lightMap[j] == i)
+ {
+ deviceLight = j;
+ break;
+ }
+ }
+
+ l->Debug(" light %d\n", i);
+ l->Debug(" enabled = %s\n", dynLight.enabled ? "true" : "false");
+ l->Debug(" priority = %d\n", dynLight.priority);
+ l->Debug(" device light = %d\n", deviceLight);
+ l->Debug(" light:\n");
+
+ const Light& light = dynLight.light;
+ std::string str;
+
+ l->Debug(" type = %d\n", light.type);
+ str = light.ambient.ToString();
+ l->Debug(" ambient = %s\n", str.c_str());
+ str = light.diffuse.ToString();
+ l->Debug(" diffuse = %s\n", str.c_str());
+ str = light.specular.ToString();
+ l->Debug(" specular = %s\n", str.c_str());
+ str = light.position.ToString();
+ l->Debug(" position = %s\n", str.c_str());
+ str = light.direction.ToString();
+ l->Debug(" direction = %s\n", str.c_str());
+ l->Debug(" attenuation0 = %s\n", light.attenuation0);
+ l->Debug(" attenuation1 = %s\n", light.attenuation1);
+ l->Debug(" attenuation2 = %s\n", light.attenuation2);
+ l->Debug(" spotAngle = %s\n", light.spotAngle);
+ l->Debug(" spotIntensity = %s\n", light.spotIntensity);
+
+ l->Debug(" intensity: %f\n", dynLight.intensity.current);
+ l->Debug(" color: %f %f %f\n", dynLight.colorRed.current, dynLight.colorGreen.current, dynLight.colorBlue.current);
+ l->Debug(" includeType: %d\n", dynLight.includeType);
+ l->Debug(" excludeType: %d\n", dynLight.excludeType);
+ }
+}
+
void CLightManager::FlushLights()
{
m_dynLights.clear();
@@ -117,6 +173,7 @@ int CLightManager::CreateLight(LightPriority priority)
m_dynLights.push_back(DynamicLight());
m_dynLights[index] = DynamicLight();
+ m_dynLights[index].rank = index;
m_dynLights[index].used = true;
m_dynLights[index].enabled = true;
m_dynLights[index].priority = priority;
@@ -411,7 +468,7 @@ void CLightManager::UpdateDeviceLights(EngineObjectType type)
if (enabled)
{
- m_lightMap[lightMapIndex] = i;
+ m_lightMap[lightMapIndex] = sortedLights[i].rank;
++lightMapIndex;
}
@@ -424,8 +481,9 @@ void CLightManager::UpdateDeviceLights(EngineObjectType type)
int rank = m_lightMap[i];
if (rank != -1)
{
- sortedLights[rank].light.ambient = Gfx::Color(0.2f, 0.2f, 0.2f);
- m_device->SetLight(i, sortedLights[rank].light);
+ Light light = m_dynLights[rank].light;
+ light.ambient = Gfx::Color(0.2f, 0.2f, 0.2f);
+ m_device->SetLight(i, light);
m_device->SetLightEnabled(i, true);
}
else
diff --git a/src/graphics/engine/lightman.h b/src/graphics/engine/lightman.h
index 171299c..d0ac338 100644
--- a/src/graphics/engine/lightman.h
+++ b/src/graphics/engine/lightman.h
@@ -84,6 +84,9 @@ enum LightPriority
*/
struct DynamicLight
{
+ //! Rank (index)
+ int rank;
+
//! Whether the light is used
bool used;
//! Whether the light is turned on
@@ -136,6 +139,9 @@ public:
//! Sets the device to be used
void SetDevice(CDevice* device);
+ //! Prints debug info
+ void DebugDumpLights();
+
//! Clears and disables all lights
void FlushLights();
//! Creates a new dynamic light and returns its index (lightRank)
diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp
index 93198ec..7c51829 100644
--- a/src/graphics/engine/pyro.cpp
+++ b/src/graphics/engine/pyro.cpp
@@ -2398,6 +2398,7 @@ void CPyro::LightOperFrame(float rTime)
{
if ( m_progress < m_lightOper[i].progress )
{
+ assert(i > 0); // TODO: if assert fails, fix the code
float progress = (m_progress-m_lightOper[i-1].progress) / (m_lightOper[i].progress-m_lightOper[i-1].progress);
float intensity = m_lightOper[i-1].intensity + (m_lightOper[i].intensity-m_lightOper[i-1].intensity)*progress;