1) Made check structures activating more general (not only new-lap lines
can be activated now, and each check structure that changes the activation state has one other check structure associated with it (instead of all previously where all activtation state changing structures would activate all (and only) new-lap structures. 2) Added support for activation toggle (instead of only switching on) 3) Renamed Checkline to CheckLine (and checline.?pp to check_line.?pp) to be consistent with other names. MAKE DISTCLEAN most likely necessary! git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@4028 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
850c6eea65
commit
7d4d50afe3
@ -279,8 +279,8 @@ supertuxkart_SOURCES = \
|
||||
tracks/check_sphere.hpp \
|
||||
tracks/check_structure.cpp \
|
||||
tracks/check_structure.hpp \
|
||||
tracks/checkline.cpp \
|
||||
tracks/checkline.hpp \
|
||||
tracks/check_line.cpp \
|
||||
tracks/check_line.hpp \
|
||||
tracks/graph_node.cpp\
|
||||
tracks/graph_node.hpp\
|
||||
tracks/quad.cpp \
|
||||
|
@ -616,6 +616,10 @@
|
||||
RelativePath="..\..\tracks\bezier_curve.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\tracks\check_line.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\tracks\check_manager.cpp"
|
||||
>
|
||||
@ -628,10 +632,6 @@
|
||||
RelativePath="..\..\tracks\check_structure.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\tracks\checkline.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\tracks\graph_node.cpp"
|
||||
>
|
||||
@ -1342,6 +1342,10 @@
|
||||
RelativePath="..\..\tracks\bezier_curve.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\tracks\check_line.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\tracks\check_manager.hpp"
|
||||
>
|
||||
@ -1354,10 +1358,6 @@
|
||||
RelativePath="..\..\tracks\check_structure.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\tracks\checkline.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\tracks\graph_node.hpp"
|
||||
>
|
||||
|
@ -1,4 +1,4 @@
|
||||
// $Id: checkline.cpp 1681 2008-04-09 13:52:48Z hikerstk $
|
||||
// $Id: check_line.cpp 1681 2008-04-09 13:52:48Z hikerstk $
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2009 Joerg Henrichs
|
||||
@ -17,7 +17,7 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "tracks/checkline.hpp"
|
||||
#include "tracks/check_line.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
* resetting e.g. new lap counters.
|
||||
* \param node XML node containing the parameters for this checkline.
|
||||
*/
|
||||
Checkline::Checkline(CheckManager *check_manager, const XMLNode &node)
|
||||
CheckLine::CheckLine(CheckManager *check_manager, const XMLNode &node)
|
||||
: CheckStructure(check_manager, node)
|
||||
{
|
||||
m_previous_sign.resize(race_manager->getNumKarts());
|
||||
@ -38,10 +38,10 @@ Checkline::Checkline(CheckManager *check_manager, const XMLNode &node)
|
||||
node.get("p2", &p2);
|
||||
node.get("min-height", &m_min_height);
|
||||
m_line.setLine(p1, p2);
|
||||
} // Checkline
|
||||
} // CheckLine
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Checkline::reset(const Track &track)
|
||||
void CheckLine::reset(const Track &track)
|
||||
{
|
||||
CheckStructure::reset(track);
|
||||
for(unsigned int i=0; i<m_previous_sign.size(); i++)
|
||||
@ -54,7 +54,7 @@ void Checkline::reset(const Track &track)
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns the center point of this checkline.
|
||||
*/
|
||||
Vec3 Checkline::getCenterPoint() const
|
||||
Vec3 CheckLine::getCenterPoint() const
|
||||
{
|
||||
core::vector2df c=m_line.getMiddle();
|
||||
Vec3 xyz(c.X, c.Y, m_min_height);
|
||||
@ -69,7 +69,7 @@ Vec3 Checkline::getCenterPoint() const
|
||||
* \param indx Index of the kart, can be used to store kart specific
|
||||
* additional data.
|
||||
*/
|
||||
bool Checkline::isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int indx)
|
||||
bool CheckLine::isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int indx)
|
||||
{
|
||||
core::vector2df p=new_pos.toIrrVector2d();
|
||||
bool sign = m_line.getPointOrientation(p)>=0;
|
@ -1,4 +1,4 @@
|
||||
// $Id: checkline.hpp 1681 2008-04-09 13:52:48Z hikerstk $
|
||||
// $Id: check_line.hpp 1681 2008-04-09 13:52:48Z hikerstk $
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2009 Joerg Henrichs
|
||||
@ -17,8 +17,8 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_CHECKLINE_HPP
|
||||
#define HEADER_CHECKLINE_HPP
|
||||
#ifndef HEADER_CHECK_LINE_HPP
|
||||
#define HEADER_CHECK_LINE_HPP
|
||||
|
||||
#include "irrlicht.h"
|
||||
using namespace irr;
|
||||
@ -35,7 +35,7 @@ class CheckManager;
|
||||
* easy checking of checklines, and should be sufficient for most check
|
||||
* structure.
|
||||
*/
|
||||
class Checkline : public CheckStructure
|
||||
class CheckLine : public CheckStructure
|
||||
{
|
||||
private:
|
||||
/** The line that is tested for being crossed. */
|
||||
@ -49,12 +49,12 @@ private:
|
||||
* or to the right of the line. */
|
||||
std::vector<bool> m_previous_sign;
|
||||
public:
|
||||
Checkline(CheckManager *check_manager, const XMLNode &node);
|
||||
virtual ~Checkline() {};
|
||||
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);
|
||||
virtual Vec3 getCenterPoint() const;
|
||||
}; // ChecklineManager
|
||||
}; // CheckLine
|
||||
|
||||
#endif
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "io/xml_node.hpp"
|
||||
#include "tracks/checkline.hpp"
|
||||
#include "tracks/check_line.hpp"
|
||||
#include "tracks/ambient_light_sphere.hpp"
|
||||
#include "tracks/check_structure.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
@ -33,9 +33,9 @@ CheckManager::CheckManager(const XMLNode &node, Track *track)
|
||||
{
|
||||
const XMLNode *check_node = node.getNode(i);
|
||||
const std::string &type = check_node->getName();
|
||||
if(type=="checkline")
|
||||
if(type=="check-line")
|
||||
{
|
||||
Checkline *cl = new Checkline(this, *check_node);
|
||||
CheckLine *cl = new CheckLine(this, *check_node);
|
||||
m_all_checks.push_back(cl);
|
||||
if(cl->getType()==CheckStructure::CT_NEW_LAP)
|
||||
{
|
||||
@ -70,13 +70,3 @@ void CheckManager::update(float dt)
|
||||
(*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,7 +35,9 @@ public:
|
||||
CheckManager(const XMLNode &node, Track *track);
|
||||
void update(float dt);
|
||||
void reset(const Track &track);
|
||||
void activateNewLapChecks(int kart_index);
|
||||
/** Returns the nth. check structure. */
|
||||
CheckStructure *getCheckStructure(unsigned int n)
|
||||
{ return m_all_checks[n]; }
|
||||
}; // CheckManager
|
||||
|
||||
#endif
|
||||
|
@ -27,19 +27,28 @@
|
||||
CheckStructure::CheckStructure(CheckManager *check_manager,
|
||||
const XMLNode &node)
|
||||
{
|
||||
m_check_manager = check_manager;
|
||||
m_check_manager = check_manager;
|
||||
std::string type;
|
||||
node.get("type", &type);
|
||||
if(type=="new-lap")
|
||||
m_check_type = CT_NEW_LAP;
|
||||
else if(type=="reset-new-lap")
|
||||
m_check_type = CT_RESET_NEW_LAP;
|
||||
else if(type=="activate")
|
||||
m_check_type = CT_ACTIVATE;
|
||||
else if(type=="toggle")
|
||||
m_check_type = CT_TOGGLE;
|
||||
else if(type=="ambient-light")
|
||||
m_check_type = CT_AMBIENT_SPHERE;
|
||||
else
|
||||
{
|
||||
printf("Unknown check structure '%s' - ignored.\n", type.c_str());
|
||||
}
|
||||
m_activate_check_index = -1;
|
||||
node.get("other-id", &m_activate_check_index);
|
||||
if( (m_check_type==CT_TOGGLE || m_check_type==CT_ACTIVATE) &&
|
||||
m_activate_check_index==-1)
|
||||
{
|
||||
printf("Unknown other-id in checkline.\n");
|
||||
}
|
||||
m_active_at_reset=true;
|
||||
node.get("active", &m_active_at_reset);
|
||||
} // CheckStructure
|
||||
@ -92,19 +101,18 @@ 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 :
|
||||
m_check_manager->activateNewLapChecks(kart_index);
|
||||
break;
|
||||
case CT_ACTIVATE: {
|
||||
CheckStructure *cs=
|
||||
m_check_manager->getCheckStructure(m_activate_check_index);
|
||||
cs->m_is_active[kart_index] = true;
|
||||
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];
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
} // switch m_check_type
|
||||
} // 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
|
||||
} // trigger
|
@ -46,21 +46,25 @@ class CheckManager;
|
||||
class CheckStructure
|
||||
{
|
||||
public:
|
||||
/** Different types of check structures: one which triggers couting a new
|
||||
* lap, and one which resets all lap counters. This is used to avoid
|
||||
* shortcuts: a new lap is only counted if a reset_new_lap check
|
||||
* structure was triggered in between. So by adding a single reset
|
||||
* structure at the rhoughly halfway mark of the track karts have to
|
||||
* drive there first before a new lap will be counted.
|
||||
/** Different types of check structures:
|
||||
* ACTIVATE: Activates another check structure (independent of
|
||||
* the state that check structure is in)
|
||||
* TOGGLE: Switches (or inverts) the state of another check structure.
|
||||
* NEW_LAP: On crossing a new lap is counted.
|
||||
* AMBIENT_SPHERE: Modifies the ambient color.
|
||||
* A combination of an activate and new_lap line are used to
|
||||
* avoid shortcuts: a new_lap line is deactivated after crossing it, and
|
||||
* you have to cross a corresponding activate structure to re-activate it,
|
||||
* enabling you to count the lap again.
|
||||
*/
|
||||
enum CheckType {CT_NEW_LAP, CT_RESET_NEW_LAP, CT_AMBIENT_SPHERE};
|
||||
enum CheckType {CT_NEW_LAP, CT_ACTIVATE, CT_TOGGLE, CT_AMBIENT_SPHERE};
|
||||
|
||||
protected:
|
||||
/** Stores the previous position of all karts. This is needed to detect
|
||||
* when e.g. a check point is reached the first time, or a checkline is
|
||||
* crossed. */
|
||||
std::vector<Vec3> m_previous_position;
|
||||
/** Stores if this check structure is active (for a given kart). USed e.g.
|
||||
/** Stores if this check structure is active (for a given kart). Used e.g.
|
||||
* in lap counting. */
|
||||
std::vector<bool> m_is_active;
|
||||
private:
|
||||
@ -71,6 +75,10 @@ private:
|
||||
CheckType m_check_type;
|
||||
/** True if this check structure should be activated at a reset. */
|
||||
bool m_active_at_reset;
|
||||
|
||||
/** If this is a CT_ACTIVATE or CT_SWITCH type, this will contain
|
||||
* the index of the corresponding check structure that is triggered. */
|
||||
int m_activate_check_index;
|
||||
public:
|
||||
CheckStructure(CheckManager *check_manager, const XMLNode &node);
|
||||
virtual ~CheckStructure() {};
|
||||
@ -85,7 +93,6 @@ 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);
|
||||
virtual Vec3 getCenterPoint() const=0;
|
||||
/** Returns the type of this check structure. */
|
||||
CheckType getType() const { return m_check_type; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user