From 468507af8b68a8fbbfe98264bf18532269a597a1 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Mon, 19 Apr 2010 12:37:45 +0000 Subject: [PATCH] Added debugging features for check structures (use --check-debug), which prints when a checkline is triggered or activated. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5211 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/config/user_config.hpp | 9 ++++++--- src/main.cpp | 4 ++++ src/tracks/ambient_light_sphere.cpp | 5 +++-- src/tracks/ambient_light_sphere.hpp | 2 +- src/tracks/check_line.cpp | 5 +++-- src/tracks/check_line.hpp | 3 ++- src/tracks/check_manager.cpp | 7 +++++-- src/tracks/check_sphere.cpp | 5 +++-- src/tracks/check_sphere.hpp | 3 ++- src/tracks/check_structure.cpp | 25 ++++++++++++++++++++++++- src/tracks/check_structure.hpp | 9 ++++++++- 11 files changed, 61 insertions(+), 16 deletions(-) diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index 32a0433fd..d446fc7ab 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -231,13 +231,16 @@ namespace UserConfigParams "Type of the renderer.") ); // ---- Debug - not saved to config file - // If gamepad debugging is enabled. + /** If gamepad debugging is enabled. */ PARAM_PREFIX bool m_gamepad_debug PARAM_DEFAULT( false ); - // If track debugging is enabled + /** If track debugging is enabled. */ PARAM_PREFIX int m_track_debug PARAM_DEFAULT( false ); - // If the kart sizes should be printed at startup + /** True if check structures should be debugged. */ + PARAM_PREFIX bool m_check_debug PARAM_DEFAULT( false ); + + /** If the kart sizes should be printed at startup. */ PARAM_PREFIX bool m_print_kart_sizes PARAM_DEFAULT( false ); /** Verbosity level for debug messages. Note that error and important warnings diff --git a/src/main.cpp b/src/main.cpp index 98f0d9558..a17860e60 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -249,6 +249,10 @@ int handleCmdLine(int argc, char **argv) { UserConfigParams::m_print_kart_sizes=true; } + else if(!strcmp(argv[i], "--check-debug")) + { + UserConfigParams::m_check_debug=true; + } else if(sscanf(argv[i], "--server=%d",&n)==1) { network_manager->setMode(NetworkManager::NW_SERVER); diff --git a/src/tracks/ambient_light_sphere.cpp b/src/tracks/ambient_light_sphere.cpp index d3a0a3edf..2ee89533a 100644 --- a/src/tracks/ambient_light_sphere.cpp +++ b/src/tracks/ambient_light_sphere.cpp @@ -34,8 +34,9 @@ * \param node XML node containing the parameters for this checkline. */ AmbientLightSphere::AmbientLightSphere(CheckManager *check_manager, - const XMLNode &node) - : CheckSphere(check_manager, node) + const XMLNode &node, + unsigned int index) + : CheckSphere(check_manager, node, index) { m_ambient_color = video::SColor(255, 0, 255, 0); // green m_inner_radius2 = 1; diff --git a/src/tracks/ambient_light_sphere.hpp b/src/tracks/ambient_light_sphere.hpp index 6b72858c5..487c172e4 100644 --- a/src/tracks/ambient_light_sphere.hpp +++ b/src/tracks/ambient_light_sphere.hpp @@ -47,7 +47,7 @@ private: video::SColor m_ambient_color; public: AmbientLightSphere(CheckManager *check_manager, - const XMLNode &node); + const XMLNode &node, unsigned int index); virtual ~AmbientLightSphere() {}; virtual void update(float dt); virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, diff --git a/src/tracks/check_line.cpp b/src/tracks/check_line.cpp index b3c8eba65..e997255ff 100644 --- a/src/tracks/check_line.cpp +++ b/src/tracks/check_line.cpp @@ -30,8 +30,9 @@ * resetting e.g. new lap counters. * \param node XML node containing the parameters for this checkline. */ -CheckLine::CheckLine(CheckManager *check_manager, const XMLNode &node) - : CheckStructure(check_manager, node) +CheckLine::CheckLine(CheckManager *check_manager, const XMLNode &node, + unsigned int index) + : CheckStructure(check_manager, node, index) { // Note that when this is called the karts have not been allocated // in world, so we can't call world->getNumKarts() diff --git a/src/tracks/check_line.hpp b/src/tracks/check_line.hpp index 41d9aa429..bcd78b415 100644 --- a/src/tracks/check_line.hpp +++ b/src/tracks/check_line.hpp @@ -49,7 +49,8 @@ private: * or to the right of the line. */ std::vector m_previous_sign; public: - CheckLine(CheckManager *check_manager, const XMLNode &node); + CheckLine(CheckManager *check_manager, const XMLNode &node, + unsigned int index); virtual ~CheckLine() {}; virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int indx); virtual void reset(const Track &track); diff --git a/src/tracks/check_manager.cpp b/src/tracks/check_manager.cpp index 89122d114..77c8d55f6 100644 --- a/src/tracks/check_manager.cpp +++ b/src/tracks/check_manager.cpp @@ -35,7 +35,7 @@ CheckManager::CheckManager(const XMLNode &node, Track *track) const std::string &type = check_node->getName(); if(type=="check-line") { - CheckLine *cl = new CheckLine(this, *check_node); + CheckLine *cl = new CheckLine(this, *check_node, i); m_all_checks.push_back(cl); if(cl->getType()==CheckStructure::CT_NEW_LAP) { @@ -44,9 +44,12 @@ CheckManager::CheckManager(const XMLNode &node, Track *track) } // checkline else if(type=="check-sphere") { - AmbientLightSphere *cs = new AmbientLightSphere(this, *check_node); + AmbientLightSphere *cs = new AmbientLightSphere(this, *check_node, + i); m_all_checks.push_back(cs); } // checksphere + else + printf("Unknown check structure '%s' - ignored.\n", type.c_str()); } // for i m_distance2; public: - CheckSphere(CheckManager *check_manager, const XMLNode &node); + CheckSphere(CheckManager *check_manager, const XMLNode &node, + unsigned int index); virtual ~CheckSphere() {}; virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int kart_id); diff --git a/src/tracks/check_structure.cpp b/src/tracks/check_structure.cpp index ca6d7f1de..747a706ec 100644 --- a/src/tracks/check_structure.cpp +++ b/src/tracks/check_structure.cpp @@ -25,8 +25,9 @@ CheckStructure::CheckStructure(CheckManager *check_manager, - const XMLNode &node) + const XMLNode &node, unsigned int index) { + m_index = index; m_check_manager = check_manager; std::string kind; node.get("kind", &kind); @@ -86,6 +87,9 @@ void CheckStructure::update(float dt) // Only check active checklines. if(m_is_active[i] && isTriggered(m_previous_position[i], xyz, i)) { + if(UserConfigParams::m_check_debug) + printf("CHECK: Check structure %d triggered for kart %s.\n", + m_index, world->getKart(i)->getIdent().c_str()); trigger(i); } m_previous_position[i] = xyz; @@ -102,17 +106,36 @@ void CheckStructure::trigger(unsigned int kart_index) { case CT_NEW_LAP : World::getWorld()->newLap(kart_index); m_is_active[kart_index] = false; + if(UserConfigParams::m_check_debug) + { + printf("CHECK: %s new lap %d triggered, now deactivated.\n", + World::getWorld()->getKart(kart_index)->getIdent().c_str(), + m_index); + } break; case CT_ACTIVATE: { CheckStructure *cs= m_check_manager->getCheckStructure(m_activate_check_index); cs->m_is_active[kart_index] = true; + if(UserConfigParams::m_check_debug) + { + printf("CHECK: %s %d triggered, activating %d.\n", + World::getWorld()->getKart(kart_index)->getIdent().c_str(), + m_index, m_activate_check_index); + } break; } case CT_TOGGLE: { CheckStructure *cs= m_check_manager->getCheckStructure(m_activate_check_index); cs->m_is_active[kart_index] = !cs->m_is_active[kart_index]; + if(UserConfigParams::m_check_debug) + { + printf("CHECK: %s %d triggered, setting %d to %d.\n", + World::getWorld()->getKart(kart_index)->getIdent().c_str(), + m_index, m_activate_check_index, + cs->m_is_active); + } break; } default: break; diff --git a/src/tracks/check_structure.hpp b/src/tracks/check_structure.hpp index 201ce88b7..1ac7eccb1 100644 --- a/src/tracks/check_structure.hpp +++ b/src/tracks/check_structure.hpp @@ -73,6 +73,11 @@ private: /** The type of this checkline. */ CheckType m_check_type; + + /** Stores the index of this check structure. This is only used for + * debugging (use --check-debug option). */ + unsigned int m_index; + /** True if this check structure should be activated at a reset. */ bool m_active_at_reset; @@ -80,7 +85,8 @@ private: * the index of the corresponding check structure that is triggered. */ int m_activate_check_index; public: - CheckStructure(CheckManager *check_manager, const XMLNode &node); + CheckStructure(CheckManager *check_manager, const XMLNode &node, + unsigned int index); virtual ~CheckStructure() {}; virtual void update(float dt); /** True if going from old_pos to new_pos crosses this checkline. This function @@ -94,6 +100,7 @@ public: virtual void trigger(unsigned int kart_index); virtual void reset(const Track &track); virtual Vec3 getCenterPoint() const=0; + /** Returns the type of this check structure. */ CheckType getType() const { return m_check_type; } }; // CheckStructure