Finished support for lap counting using checklines.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3710 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
0f47c60042
commit
e8c70f73af
@ -33,7 +33,7 @@ CheckManager::CheckManager(const XMLNode &node)
|
||||
const std::string &type = check_node->getName();
|
||||
if(type=="checkline")
|
||||
{
|
||||
m_all_checks.push_back(new Checkline(*check_node));
|
||||
m_all_checks.push_back(new Checkline(this, *check_node));
|
||||
}
|
||||
} // for i<node.getNumNodes
|
||||
} // CheckManager
|
||||
@ -57,3 +57,14 @@ void CheckManager::update(float dt)
|
||||
for(i=m_all_checks.begin(); i!=m_all_checks.end(); i++)
|
||||
(*i)->update(dt);
|
||||
} // update
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Called when a reset-new-lap check is triggered. It re-activates all new
|
||||
* lap checks.
|
||||
*/
|
||||
void CheckManager::activateNewLapChecks(int kart_index)
|
||||
{
|
||||
std::vector<CheckStructure*>::iterator i;
|
||||
for(i=m_all_checks.begin(); i!=m_all_checks.end(); i++)
|
||||
(*i)->activateNewLapCheck(kart_index);
|
||||
} // resetNewLaps
|
||||
|
@ -35,6 +35,7 @@ public:
|
||||
CheckManager(const XMLNode &node);
|
||||
void update(float dt);
|
||||
void reset(const Track &track);
|
||||
void activateNewLapChecks(int kart_index);
|
||||
}; // CheckManager
|
||||
|
||||
#endif
|
||||
|
@ -20,11 +20,14 @@
|
||||
#include "karts/kart.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
#include "tracks/check_manager.hpp"
|
||||
#include "tracks/check_structure.hpp"
|
||||
|
||||
|
||||
CheckStructure::CheckStructure(const XMLNode &node)
|
||||
CheckStructure::CheckStructure(CheckManager *check_manager,
|
||||
const XMLNode &node)
|
||||
{
|
||||
m_check_manager = check_manager;
|
||||
std::string type;
|
||||
node.get("type", &type);
|
||||
if(type=="new-lap")
|
||||
@ -71,8 +74,10 @@ void CheckStructure::update(float dt)
|
||||
{
|
||||
trigger(i);
|
||||
}
|
||||
m_previous_position[i] = xyz;
|
||||
} // for i<getNumKarts
|
||||
} // update
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Is called when this check structure is triggered. This then can cause
|
||||
* a lap to be counted, animation to be started etc.
|
||||
@ -84,7 +89,19 @@ void CheckStructure::trigger(unsigned int kart_index)
|
||||
case CT_NEW_LAP : RaceManager::getWorld()->newLap(kart_index);
|
||||
m_is_active[kart_index] = false;
|
||||
break;
|
||||
case CT_RESET_NEW_LAP : break;
|
||||
case CT_RESET_NEW_LAP :
|
||||
m_check_manager->activateNewLapChecks(kart_index);
|
||||
break;
|
||||
default: break;
|
||||
} // switch m_check_type
|
||||
} // trigger
|
||||
} // trigger
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** If this check structure is a new-lap check, activate it again.
|
||||
* \param kart_index Index of the kart for which the lap check is activated.
|
||||
*/
|
||||
void CheckStructure::activateNewLapCheck(int kart_index)
|
||||
{
|
||||
if(m_check_type==CT_NEW_LAP)
|
||||
m_is_active[kart_index] = true;
|
||||
} // resetNewLap
|
@ -26,6 +26,7 @@
|
||||
|
||||
class XMLNode;
|
||||
class Track;
|
||||
class CheckManager;
|
||||
|
||||
/** Virtual base class for a check structure. A check structure has a certain
|
||||
* type:
|
||||
@ -62,10 +63,14 @@ protected:
|
||||
/** Stores if this check structure is active (for a given kart). USed e.g.
|
||||
* in lap counting. */
|
||||
std::vector<bool> m_is_active;
|
||||
private:
|
||||
/** Stores a pointer to the check manager. */
|
||||
CheckManager *m_check_manager;
|
||||
|
||||
/** The type of this checkline. */
|
||||
CheckType m_check_type;
|
||||
public:
|
||||
CheckStructure(const XMLNode &node);
|
||||
CheckStructure(CheckManager *check_manager, const XMLNode &node);
|
||||
virtual ~CheckStructure() {};
|
||||
virtual void update(float dt);
|
||||
/** True if going from old_pos to new_pos crosses this checkline. This function
|
||||
@ -78,6 +83,7 @@ public:
|
||||
virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int indx)=0;
|
||||
virtual void trigger(unsigned int kart_index);
|
||||
virtual void reset(const Track &track);
|
||||
virtual void activateNewLapCheck(int kart_index);
|
||||
}; // CheckStructure
|
||||
|
||||
#endif
|
||||
|
@ -24,7 +24,13 @@
|
||||
#include "io/xml_node.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
|
||||
Checkline::Checkline(const XMLNode &node) : CheckStructure(node)
|
||||
/** Constructor for a checkline.
|
||||
* \param check_manager Pointer to the check manager, which is needed when
|
||||
* 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)
|
||||
{
|
||||
m_previous_sign.resize(race_manager->getNumKarts());
|
||||
core::vector2df p1, p2;
|
||||
@ -77,4 +83,4 @@ bool Checkline::isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int indx)
|
||||
result = false;
|
||||
m_previous_sign[indx] = sign;
|
||||
return result;
|
||||
} // update
|
||||
} // isTriggered
|
||||
|
@ -26,6 +26,7 @@ using namespace irr;
|
||||
#include "tracks/check_structure.hpp"
|
||||
|
||||
class XMLNode;
|
||||
class CheckManager;
|
||||
|
||||
/** Implements a simple checkline. It's a finite line with 2 endpoints in 2d
|
||||
* and a minimum height (i.e. the minimum Y coordinate of the two points).
|
||||
@ -48,7 +49,7 @@ private:
|
||||
* or to the right of the line. */
|
||||
std::vector<bool> m_previous_sign;
|
||||
public:
|
||||
Checkline(const XMLNode &node);
|
||||
Checkline(CheckManager *check_manager, const XMLNode &node);
|
||||
virtual ~Checkline() {};
|
||||
virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int indx);
|
||||
virtual void reset(const Track &track);
|
||||
|
Loading…
Reference in New Issue
Block a user