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
This commit is contained in:
hikerstk 2010-04-19 12:37:45 +00:00
parent e36f0fdd8f
commit 468507af8b
11 changed files with 61 additions and 16 deletions

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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,

View File

@ -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()

View File

@ -49,7 +49,8 @@ private:
* or to the right of the line. */
std::vector<bool> 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);

View File

@ -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<node.getNumNodes
} // CheckManager

View File

@ -31,8 +31,9 @@
* resetting e.g. new lap counters.
* \param node XML node containing the parameters for this checkline.
*/
CheckSphere::CheckSphere(CheckManager *check_manager, const XMLNode &node)
: CheckStructure(check_manager, node)
CheckSphere::CheckSphere(CheckManager *check_manager, const XMLNode &node,
unsigned int index)
: CheckStructure(check_manager, node, index)
{
m_radius2 = 1;

View File

@ -47,7 +47,8 @@ private:
* This saves some computations. */
std::vector<float> 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);

View File

@ -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;

View File

@ -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