Keep track of all predecessor of a node, not only the first one.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11382 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
e0c8652d89
commit
cebae627c8
@ -1546,8 +1546,10 @@ void Kart::crashed(const Material *m)
|
||||
int sector = lw->getSectorForKart(this);
|
||||
if(sector!=QuadGraph::UNKNOWN_SECTOR)
|
||||
{
|
||||
// Use the first predecessor node, which is the most
|
||||
// natural one (i.e. the one on the main driveline).
|
||||
const GraphNode &gn = QuadGraph::get()->getNode(
|
||||
QuadGraph::get()->getNode(sector).getPredecessor());
|
||||
QuadGraph::get()->getNode(sector).getPredecessor(0));
|
||||
Vec3 impulse = gn.getCenter() - getXYZ();
|
||||
impulse.setY(0);
|
||||
if(impulse.getX() || impulse.getZ())
|
||||
|
@ -38,7 +38,6 @@ GraphNode::GraphNode(unsigned int quad_index, unsigned int node_index)
|
||||
}
|
||||
m_quad_index = quad_index;
|
||||
m_node_index = node_index;
|
||||
m_predecessor = -1;
|
||||
m_distance_from_start = -1.0f;
|
||||
|
||||
const Quad &quad = QuadSet::get()->getQuad(m_quad_index);
|
||||
@ -74,16 +73,17 @@ GraphNode::GraphNode(unsigned int quad_index, unsigned int node_index)
|
||||
*/
|
||||
void GraphNode::addSuccessor(unsigned int to)
|
||||
{
|
||||
m_successor_node.push_back(to);
|
||||
m_successor_nodes.push_back(to);
|
||||
// m_quad_index is the quad index
|
||||
const Quad &this_quad = QuadSet::get()->getQuad(m_quad_index);
|
||||
// to is the graph node
|
||||
GraphNode &gn = QuadGraph::get()->getNode(to);
|
||||
const Quad &next_quad = QuadGraph::get()->getQuadOfNode(to);
|
||||
|
||||
// Keep the first predecessor, which is usually the most 'natural' one.
|
||||
if(gn.m_predecessor==-1)
|
||||
gn.m_predecessor = m_node_index;
|
||||
// Note that the first predecessor is (because of the way the quad graph
|
||||
// is exported) the most 'natural' one, i.e. the one on the main
|
||||
// driveline.
|
||||
gn.m_predecessor_nodes.push_back(m_node_index);
|
||||
|
||||
Vec3 d = m_lower_center - QuadGraph::get()->getNode(to).m_lower_center;
|
||||
m_distance_to_next.push_back(d.length());
|
||||
@ -100,7 +100,7 @@ void GraphNode::addSuccessor(unsigned int to)
|
||||
*/
|
||||
void GraphNode::setupPathsToNode()
|
||||
{
|
||||
if(m_successor_node.size()<2) return;
|
||||
if(m_successor_nodes.size()<2) return;
|
||||
|
||||
const unsigned int num_nodes = QuadGraph::get()->getNumNodes();
|
||||
m_path_to_node.resize(num_nodes);
|
||||
|
@ -53,12 +53,10 @@ private:
|
||||
unsigned int m_node_index;
|
||||
|
||||
/** The list of successor graph nodes. */
|
||||
std::vector<int> m_successor_node;
|
||||
std::vector<int> m_successor_nodes;
|
||||
|
||||
/** The first predecessor. This is used in moving karts after a rescue.
|
||||
* For this a node on the main driveline will be used (i.e. the first
|
||||
* reported node which has this node as a successor). */
|
||||
int m_predecessor;
|
||||
/** The list of predecessors of a node. */
|
||||
std::vector<int> m_predecessor_nodes;
|
||||
|
||||
/** The distance to each of the successors. */
|
||||
std::vector<float> m_distance_to_next;
|
||||
@ -133,13 +131,22 @@ public:
|
||||
void setDirectionData(unsigned int successor, DirectionType dir,
|
||||
unsigned int last_node_index);
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the i-th successor node. */
|
||||
unsigned int getSuccessor(unsigned int i) const
|
||||
{ return m_successor_node[i]; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the number of successors. */
|
||||
unsigned int getNumberOfSuccessors() const
|
||||
{ return (unsigned int)m_successor_node.size(); }
|
||||
{ return (unsigned int)m_successor_nodes.size(); }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the i-th successor node. */
|
||||
unsigned int getSuccessor(unsigned int i) const
|
||||
{ return m_successor_nodes[i]; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the number of predecessors. */
|
||||
unsigned int getNumberOfPredecessors() const
|
||||
{ return (unsigned int)m_predecessor_nodes.size(); }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns a predecessor for this node. Note that the first predecessor
|
||||
* is the most 'natural' one, i.e. the one on the main driveline.
|
||||
*/
|
||||
int getPredecessor(unsigned int i) const {return m_predecessor_nodes[i]; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the quad_index in the quad_set of this node. */
|
||||
int getIndex() const { return m_quad_index; }
|
||||
@ -193,12 +200,9 @@ public:
|
||||
* \param index Index of the successor. */
|
||||
bool ignoreSuccessorForAI(unsigned int i) const
|
||||
{
|
||||
return QuadSet::get()->getQuad(m_successor_node[i]).letAIIgnore();
|
||||
return QuadSet::get()->getQuad(m_successor_nodes[i]).letAIIgnore();
|
||||
};
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns a predecessor for this node. */
|
||||
int getPredecessor() const {return m_predecessor; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns which successor node to use in order to be able to reach the
|
||||
* given node n.
|
||||
* \param n Index of the graph node to reach.
|
||||
|
@ -324,8 +324,9 @@ void QuadGraph::setDefaultStartPositions(AlignedArray<btTransform>
|
||||
float upwards_distance) const
|
||||
{
|
||||
// We start just before the start node (which will trigger lap
|
||||
// counting when reached).
|
||||
int current_node = m_all_nodes[getStartNode()]->getPredecessor();
|
||||
// counting when reached). The first predecessor is the one on
|
||||
// the main driveline.
|
||||
int current_node = m_all_nodes[getStartNode()]->getPredecessor(0);
|
||||
|
||||
float distance_from_start = 0.1f+forwards_distance;
|
||||
|
||||
@ -340,7 +341,8 @@ void QuadGraph::setDefaultStartPositions(AlignedArray<btTransform>
|
||||
if (current_node == -1)
|
||||
{
|
||||
(*start_transforms)[i].setOrigin(Vec3(0,0,0));
|
||||
(*start_transforms)[i].setRotation(btQuaternion(btVector3(0, 1, 0), 0));
|
||||
(*start_transforms)[i].setRotation(btQuaternion(btVector3(0, 1, 0),
|
||||
0));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -348,7 +350,8 @@ void QuadGraph::setDefaultStartPositions(AlignedArray<btTransform>
|
||||
while(distance_from_start > getNode(current_node).getNodeLength())
|
||||
{
|
||||
distance_from_start -= getNode(current_node).getNodeLength();
|
||||
current_node = getNode(current_node).getPredecessor();
|
||||
// Only follow the main driveline, i.e. first predecessor
|
||||
current_node = getNode(current_node).getPredecessor(0);
|
||||
}
|
||||
const GraphNode &gn = getNode(current_node);
|
||||
Vec3 center_line = gn.getLowerCenter() - gn.getUpperCenter();
|
||||
|
@ -408,7 +408,7 @@ void Track::loadQuadGraph(unsigned int mode_id, const bool reverse)
|
||||
#ifdef DEBUG
|
||||
for(unsigned int i=0; i<QuadGraph::get()->getNumNodes(); i++)
|
||||
{
|
||||
assert(QuadGraph::get()->getNode(i).getPredecessor()!=-1);
|
||||
assert(QuadGraph::get()->getNode(i).getPredecessor(0)!=-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -105,11 +105,13 @@ void TrackSector::rescue()
|
||||
|
||||
// Using the predecessor has the additional advantage (besides punishing
|
||||
// the player a bit more) that it makes it less likely to fall in a
|
||||
// rescue loop since the kart moves back on each attempt.
|
||||
// rescue loop since the kart moves back on each attempt. At this stage
|
||||
// STK does not keep track of where the kart is coming from, so always
|
||||
// use the first predecessor, which is the one on the main driveline.
|
||||
m_current_graph_node = QuadGraph::get()->getNode(m_current_graph_node)
|
||||
.getPredecessor();
|
||||
.getPredecessor(0);
|
||||
m_last_valid_graph_node = QuadGraph::get()->getNode(m_current_graph_node)
|
||||
.getPredecessor();
|
||||
.getPredecessor(0);
|
||||
} // rescue
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user