Started adding code to assign a checkline to each quad (currently disabled). See #398

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9805 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2011-09-11 19:46:51 +00:00
parent 12d9888a2a
commit ee7b178dce
9 changed files with 110 additions and 2 deletions

View File

@@ -323,6 +323,7 @@ void LinearWorld::newLap(unsigned int kart_index)
//-----------------------------------------------------------------------------
int LinearWorld::getSectorForKart(const int kart_id) const
{
assert(kart_id < (int)m_kart_info.size());
return m_kart_info[kart_id].getSector()->getCurrentGraphNode();
} // getSectorForKart
@@ -333,6 +334,7 @@ int LinearWorld::getSectorForKart(const int kart_id) const
*/
float LinearWorld::getDistanceDownTrackForKart(const int kart_id) const
{
assert(kart_id < (int)m_kart_info.size());
return m_kart_info[kart_id].getSector()->getDistanceFromStart();
} // getDistanceDownTrackForKart
@@ -343,12 +345,14 @@ float LinearWorld::getDistanceDownTrackForKart(const int kart_id) const
*/
float LinearWorld::getDistanceToCenterForKart(const int kart_id) const
{
assert(kart_id < (int)m_kart_info.size());
return m_kart_info[kart_id].getSector()->getDistanceToCenter();
} // getDistanceToCenterForKart
//-----------------------------------------------------------------------------
int LinearWorld::getLapForKart(const int kart_id) const
{
assert(kart_id < (int)m_kart_info.size());
return m_kart_info[kart_id].m_race_lap;
} // getLapForKart
@@ -358,6 +362,7 @@ int LinearWorld::getLapForKart(const int kart_id) const
*/
float LinearWorld::getEstimatedFinishTime(const int kart_id) const
{
assert(kart_id < (int)m_kart_info.size());
assert(m_kart_info[kart_id].m_race_lap == race_manager->getNumLaps()-1);
return m_kart_info[kart_id].m_estimated_finish;
} // getEstimatedFinishTime
@@ -365,6 +370,7 @@ float LinearWorld::getEstimatedFinishTime(const int kart_id) const
//-----------------------------------------------------------------------------
float LinearWorld::getTimeAtLapForKart(const int kart_id) const
{
assert(kart_id < (int)m_kart_info.size());
return m_kart_info[kart_id].m_time_at_last_lap;
} // getTimeAtLapForKart

View File

@@ -40,6 +40,9 @@ public:
~CheckManager();
void update(float dt);
void reset(const Track &track);
int getCheckStructureCount() const { return m_all_checks.size(); }
/** Returns the nth. check structure. */
CheckStructure *getCheckStructure(unsigned int n)
{

View File

@@ -23,6 +23,7 @@
#include "modes/world.hpp"
#include "race/race_manager.hpp"
#include "tracks/check_lap.hpp"
#include "tracks/check_manager.hpp"
@@ -171,6 +172,20 @@ void CheckStructure::changeStatus(const std::vector<int> indices,
cs->changeDebugColor(cs->m_is_active[kart_index]);
}
} // for i<indices.size()
/*
printf("--------\n");
for (int n=0; n<m_check_manager->getCheckStructureCount(); n++)
{
CheckStructure *cs = m_check_manager->getCheckStructure(n);
if (dynamic_cast<CheckLap*>(cs) != NULL)
printf("Checkline %i (LAP) : %i\n", n, (int)cs->m_is_active[kart_index]);
else
printf("Checkline %i : %i\n", n, (int)cs->m_is_active[kart_index]);
}
*/
} //changeStatus
// ----------------------------------------------------------------------------

View File

@@ -218,3 +218,8 @@ float GraphNode::getDistance2FromPoint(const Vec3 &xyz)
} // getDistance2FromPoint
// ----------------------------------------------------------------------------
void GraphNode::setChecklineRequirements(const std::set<int>& r)
{
m_checkline_requirements.push_back(r);
}

View File

@@ -21,6 +21,7 @@
#define HEADER_GRAPH_NODE_HPP
#include <vector>
#include <set>
#include <vector2d.h>
#include <dimension2d.h>
@@ -98,6 +99,13 @@ class GraphNode
void markAllSuccessorsToUse(unsigned int n,
PathToNodeVector *m_path_to_node);
/**
* Sets of checklines you should have activated when you are driving on
* this node (there is a possibility of more than one set because of
* alternate ways)
*/
std::vector< std::set<int> > m_checkline_requirements;
public:
/** Keep a shared pointer so that some asserts and tests can be
* done without adding additional parameters. */
@@ -159,6 +167,9 @@ public:
/** Returns the center point of the upper edge of this graph node. */
const Vec3& getUpperCenter() const {return m_upper_center;}
// ------------------------------------------------------------------------
/** Returns the center point of this graph node. */
const Vec3 getCenter() const {return (m_upper_center + m_lower_center) / 2.0f;}
// ------------------------------------------------------------------------
/** Returns the length of the quad of this node. */
float getNodeLength() const
{return (m_lower_center-m_upper_center).length();}
@@ -185,6 +196,8 @@ public:
return m_path_to_node.size()>0 ? m_path_to_node[n] : 0;
}
// ------------------------------------------------------------------------
void setChecklineRequirements(const std::set<int>& r);
}; // GraphNode
#endif

View File

@@ -28,8 +28,12 @@
#include "graphics/irr_driver.hpp"
#include "io/file_manager.hpp"
#include "io/xml_node.hpp"
#include "modes/world.hpp"
#include "tracks/check_lap.hpp"
#include "tracks/check_line.hpp"
#include "tracks/check_manager.hpp"
#include "tracks/quad_set.hpp"
#include "tracks/track.hpp"
const int QuadGraph::UNKNOWN_SECTOR = -1;
QuadGraph *QuadGraph::m_quad_graph = NULL;
@@ -176,10 +180,58 @@ void QuadGraph::load(const std::string &filename)
break;
}
}
setDefaultSuccessors();
setDefaultSuccessors();
} // load
// ----------------------------------------------------------------------------
/**
* Finds which checklines must be visited before driving on this quad
* (useful for rescue)
*/
void QuadGraph::setChecklineRequirements(GraphNode* node, std::set<int> checklines)
{
Track* t = World::getWorld()->getTrack();
CheckManager* cm = t->getCheckManager();
assert(cm != NULL);
for (unsigned int n=0; n<node->getNumberOfSuccessors(); n++)
{
const int succ_id = node->getSuccessor(n);
// warp-around
if (succ_id == 0) break;
std::set<int> these_checklines = checklines;
GraphNode* succ = m_all_nodes[succ_id];
for (int i=0; i<cm->getCheckStructureCount(); i++)
{
CheckStructure* c = cm->getCheckStructure(i);
// skip lapline
if (dynamic_cast<CheckLap*>(c) != NULL) continue;
if (c->isTriggered(node->getCenter(), succ->getCenter(), 0 /* kart id */))
{
//printf("* Check %i is triggerred when going from %i to %i\n", i, node->getIndex(), succ_id);
these_checklines.insert(i);
}
}
/*
printf("Quad %i :\n", succ_id);
for (std::set<int>::iterator it = these_checklines.begin();it != these_checklines.end(); it++)
{
printf(" Depends on checkline %i\n", *it);
}
*/
succ->setChecklineRequirements(these_checklines);
setChecklineRequirements(succ, these_checklines);
}
}
// ----------------------------------------------------------------------------
/** This function defines the "path-to-nodes" for each graph node that has
* more than one successor. The path-to-nodes indicates which successor to

View File

@@ -22,6 +22,7 @@
#include <vector>
#include <string>
#include <set>
#include "tracks/graph_node.hpp"
#include "tracks/quad_set.hpp"
@@ -78,6 +79,8 @@ private:
std::string m_quad_filename;
void setDefaultSuccessors();
void setChecklineRequirements(GraphNode* node, std::set<int> checklines);
void load (const std::string &filename);
void createMesh(bool show_invisible=true,
const video::SColor *track_color=NULL,
@@ -171,6 +174,12 @@ public:
/** Returns the length of the main driveline. */
float getLapLength() const {return m_lap_length; }
// ----------------------------------------------------------------------
void setChecklineRequirements()
{
setChecklineRequirements(m_all_nodes[0], std::set<int>());
}
}; // QuadGraph
#endif

View File

@@ -1447,6 +1447,8 @@ void Track::loadTrackModel(World* parent, unsigned int mode_id)
irr_driver->getSceneManager()->getMeshCache()->getMeshCount(),
irr_driver->getVideoDriver()->getTextureCount());
//QuadGraph::get()->setChecklineRequirements();
} // loadTrackModel
//-----------------------------------------------------------------------------

View File

@@ -380,6 +380,9 @@ public:
// ------------------------------------------------------------------------
bool isFogEnabled() const { return m_use_fog; }
CheckManager* getCheckManager() { return m_check_manager; }
TrackObjectManager* getTrackObjectManager() { return m_track_object_manager; }
}; // class Track