[colobot] 17/145: goto() path 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 d38ddcbc4199fe624f9b6689127363ee7bb5693d
Author: krzys-h <krzys_h at interia.pl>
Date:   Mon Mar 28 20:25:07 2016 +0200

    goto() path debugger
---
 src/common/event.h             |  7 ++++---
 src/graphics/engine/engine.cpp | 30 ++++++++++++++++++++++++++++++
 src/graphics/engine/engine.h   |  6 ++++++
 src/object/task/taskgoto.cpp   | 33 ++++++++++++++++++++++++++++++++-
 src/ui/debug_menu.cpp          | 14 ++++++++++++++
 5 files changed, 86 insertions(+), 4 deletions(-)

diff --git a/src/common/event.h b/src/common/event.h
index c5fe1f5..d3f22b0 100644
--- a/src/common/event.h
+++ b/src/common/event.h
@@ -385,9 +385,10 @@ enum EventType
     EVENT_DBG_TELEPORT      = 852,
     EVENT_DBG_LIGHTNING     = 853,
     EVENT_DBG_RESOURCES     = 854,
-    EVENT_DBG_CRASHSPHERES  = 855,
-    EVENT_DBG_LIGHTS        = 856,
-    EVENT_DBG_LIGHTS_DUMP   = 857,
+    EVENT_DBG_GOTO          = 855,
+    EVENT_DBG_CRASHSPHERES  = 856,
+    EVENT_DBG_LIGHTS        = 857,
+    EVENT_DBG_LIGHTS_DUMP   = 858,
 
     EVENT_SPAWN_CANCEL      = 860,
     EVENT_SPAWN_ME          = 861,
diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp
index e3e3431..7d00e87 100644
--- a/src/graphics/engine/engine.cpp
+++ b/src/graphics/engine/engine.cpp
@@ -3378,6 +3378,21 @@ void CEngine::Draw3DScene()
     if (m_debugCrashSpheres)
         DrawCrashSpheres();
 
+    if (m_debugGoto)
+    {
+        Math::Matrix worldMatrix;
+        worldMatrix.LoadIdentity();
+        m_device->SetTransform(TRANSFORM_WORLD, worldMatrix);
+
+        SetState(ENG_RSTATE_OPAQUE_COLOR);
+
+        for (const auto& line : m_displayGoto)
+        {
+            m_device->DrawPrimitive(PRIMITIVE_LINE_STRIP, line.data(), line.size());
+        }
+    }
+    m_displayGoto.clear();
+
     m_app->StartPerformanceCounter(PCNT_RENDER_PARTICLE);
     m_particle->DrawParticle(SH_WORLD); // draws the particles of the 3D world
     m_app->StopPerformanceCounter(PCNT_RENDER_PARTICLE);
@@ -5129,4 +5144,19 @@ bool CEngine::GetDebugResources()
     return m_debugResources;
 }
 
+void CEngine::SetDebugGoto(bool debugGoto)
+{
+    m_debugGoto = debugGoto;
+}
+
+bool CEngine::GetDebugGoto()
+{
+    return m_debugGoto;
+}
+
+void CEngine::AddDebugGotoLine(std::vector<Gfx::VertexCol> line)
+{
+    m_displayGoto.push_back(line);
+}
+
 } // namespace Gfx
diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h
index f95bdf3..04757fc 100644
--- a/src/graphics/engine/engine.h
+++ b/src/graphics/engine/engine.h
@@ -1191,6 +1191,10 @@ public:
     void            SetDebugResources(bool debugResources);
     bool            GetDebugResources();
 
+    void            SetDebugGoto(bool debugGoto);
+    bool            GetDebugGoto();
+    void            AddDebugGotoLine(std::vector<Gfx::VertexCol> line);
+
 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 **/
@@ -1482,12 +1486,14 @@ protected:
     bool            m_debugDumpLights;
     bool            m_debugCrashSpheres = false;
     bool            m_debugResources = false;
+    bool            m_debugGoto = false;
 
     std::string     m_timerText;
 
     std::unordered_map<std::string, int> m_staticMeshBaseObjects;
 
     std::vector<Math::Sphere> m_displayCrashSpheres;
+    std::vector<std::vector<VertexCol>> m_displayGoto;
 
     //! Pause the animation updates
     bool            m_pause = false;
diff --git a/src/object/task/taskgoto.cpp b/src/object/task/taskgoto.cpp
index d7e36cd..7a6c754 100644
--- a/src/object/task/taskgoto.cpp
+++ b/src/object/task/taskgoto.cpp
@@ -77,9 +77,38 @@ bool CTaskGoto::EventProcess(const Event &event)
     float           a, g, dist, linSpeed, cirSpeed, h, hh, factor, dir;
     Error           ret;
 
-    if ( m_engine->GetPause() )  return true;
     if ( event.type != EVENT_FRAME )  return true;
 
+    if (m_engine->GetDebugGoto())
+    {
+        auto AdjustPoint = [&](Math::Vector p) -> Math::Vector
+        {
+            m_terrain->AdjustToFloor(p);
+            p.y += 2.0f;
+            return p;
+        };
+
+        std::vector<Gfx::VertexCol> debugLine;
+        if (m_bmTotal > 0)
+        {
+            Gfx::Color color = Gfx::Color(0.0f, 1.0f, 0.0f);
+            for (int i = 0; i < m_bmTotal; i++)
+            {
+                if (i > m_bmIndex-1)
+                    color = Gfx::Color(1.0f, 0.0f, 0.0f);
+                debugLine.push_back(Gfx::VertexCol(AdjustPoint(m_bmPoints[i]), color));
+            }
+            m_engine->AddDebugGotoLine(debugLine);
+            debugLine.clear();
+        }
+        Gfx::Color color = Gfx::Color(0.0f, 0.0f, 1.0f);
+        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_engine->GetPause() )  return true;
+
     // Momentarily stationary object (ant on the back)?
     CBaseAlien* alien = dynamic_cast<CBaseAlien*>(m_object);
     if ( alien != nullptr && alien->GetFixed() )
@@ -1616,6 +1645,8 @@ Error CTaskGoto::BeamExplore(const Math::Vector &prevPos, const Math::Vector &cu
     iLar = 0;
     if ( i >= MAXPOINTS )  return ERR_GOTO_ITER;  // too many recursions
 
+    m_bmTotal = i;
+
     if ( m_bmIter[i] == -1 )
     {
         m_bmIter[i] = 0;
diff --git a/src/ui/debug_menu.cpp b/src/ui/debug_menu.cpp
index 7d8ae15..88e62c1 100644
--- a/src/ui/debug_menu.cpp
+++ b/src/ui/debug_menu.cpp
@@ -97,6 +97,9 @@ void CDebugMenu::CreateInterface()
     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_GOTO);
+    pc->SetName("Render goto() path");
+    pos.y -= 0.048f;
     pc = pw->CreateCheck(pos, ddim, -1, EVENT_DBG_CRASHSPHERES);
     pc->SetName("Render crash spheres");
     pos.y -= 0.048f;
@@ -213,6 +216,12 @@ void CDebugMenu::UpdateInterface()
         pc->SetState(STATE_CHECK, m_engine->GetDebugResources());
     }
 
+    pc = static_cast<CCheck*>(pw->SearchControl(EVENT_DBG_GOTO));
+    if (pc != nullptr)
+    {
+        pc->SetState(STATE_CHECK, m_engine->GetDebugGoto());
+    }
+
     pc = static_cast<CCheck*>(pw->SearchControl(EVENT_DBG_CRASHSPHERES));
     if (pc != nullptr)
     {
@@ -280,6 +289,11 @@ bool CDebugMenu::EventProcess(const Event &event)
             UpdateInterface();
             break;
 
+        case EVENT_DBG_GOTO:
+            m_engine->SetDebugGoto(!m_engine->GetDebugGoto());
+            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