Implementation of reversed track.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/reverse_mode@10799 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
a993cebca0
commit
d81cc54fa8
@ -131,3 +131,14 @@ void Quad::transform(const btTransform &t, Quad *result) const
|
|||||||
std::min(result->m_p[2].getY(),
|
std::min(result->m_p[2].getY(),
|
||||||
result->m_p[3].getY()) );
|
result->m_p[3].getY()) );
|
||||||
} // transform
|
} // transform
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
/** Reverse the quad */
|
||||||
|
void Quad::reverse() {
|
||||||
|
Vec3 tmp = m_p[0];
|
||||||
|
m_p[0] = m_p[2];
|
||||||
|
m_p[2] = tmp;
|
||||||
|
tmp = m_p[1];
|
||||||
|
m_p[1] = m_p[3];
|
||||||
|
m_p[3] = tmp;
|
||||||
|
}
|
||||||
|
@ -75,5 +75,8 @@ public:
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** True if this quad should be ignored by the AI. */
|
/** True if this quad should be ignored by the AI. */
|
||||||
bool letAIIgnore() const { return m_ai_ignore; }
|
bool letAIIgnore() const { return m_ai_ignore; }
|
||||||
|
|
||||||
|
/** Reverse the quad */
|
||||||
|
void reverse();
|
||||||
}; // class Quad
|
}; // class Quad
|
||||||
#endif
|
#endif
|
||||||
|
@ -44,13 +44,16 @@ QuadGraph *QuadGraph::m_quad_graph = NULL;
|
|||||||
*/
|
*/
|
||||||
QuadGraph::QuadGraph(const std::string &quad_file_name,
|
QuadGraph::QuadGraph(const std::string &quad_file_name,
|
||||||
const std::string graph_file_name,
|
const std::string graph_file_name,
|
||||||
const bool reverse)
|
const bool reverse) : m_reverse(reverse)
|
||||||
{
|
{
|
||||||
m_node = NULL;
|
m_node = NULL;
|
||||||
m_mesh = NULL;
|
m_mesh = NULL;
|
||||||
m_mesh_buffer = NULL;
|
m_mesh_buffer = NULL;
|
||||||
m_lap_length = 0;
|
m_lap_length = 0;
|
||||||
m_all_quads = new QuadSet(quad_file_name);
|
m_all_quads = new QuadSet(quad_file_name);
|
||||||
|
if(m_reverse) {
|
||||||
|
m_all_quads->reverse_all_quads();
|
||||||
|
}
|
||||||
m_quad_filename = quad_file_name;
|
m_quad_filename = quad_file_name;
|
||||||
GraphNode::m_all_quads = m_all_quads;
|
GraphNode::m_all_quads = m_all_quads;
|
||||||
GraphNode::m_all_nodes = this;
|
GraphNode::m_all_nodes = this;
|
||||||
@ -70,6 +73,14 @@ QuadGraph::~QuadGraph()
|
|||||||
} // ~QuadGraph
|
} // ~QuadGraph
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void QuadGraph::addSuccessor(unsigned int from, unsigned int to) {
|
||||||
|
if(m_reverse)
|
||||||
|
m_all_nodes[to]->addSuccessor(from);
|
||||||
|
else
|
||||||
|
m_all_nodes[from]->addSuccessor(to);
|
||||||
|
}
|
||||||
|
|
||||||
/** Loads a quad graph from a file.
|
/** Loads a quad graph from a file.
|
||||||
* \param filename Name of the file to load.
|
* \param filename Name of the file to load.
|
||||||
*/
|
*/
|
||||||
@ -138,7 +149,8 @@ void QuadGraph::load(const std::string &filename)
|
|||||||
for(unsigned int i=from; i<=to; i++)
|
for(unsigned int i=from; i<=to; i++)
|
||||||
{
|
{
|
||||||
assert(i!=to ? i+1 : from <m_all_nodes.size());
|
assert(i!=to ? i+1 : from <m_all_nodes.size());
|
||||||
m_all_nodes[i]->addSuccessor(i!=to ? i+1 : from);
|
addSuccessor(i,(i!=to ? i+1 : from));
|
||||||
|
//~ m_all_nodes[i]->addSuccessor(i!=to ? i+1 : from);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(xml_node->getName()=="edge-line")
|
else if(xml_node->getName()=="edge-line")
|
||||||
@ -149,7 +161,8 @@ void QuadGraph::load(const std::string &filename)
|
|||||||
xml_node->get("to", &to);
|
xml_node->get("to", &to);
|
||||||
for(unsigned int i=from; i<to; i++)
|
for(unsigned int i=from; i<to; i++)
|
||||||
{
|
{
|
||||||
m_all_nodes[i]->addSuccessor(i+1);
|
addSuccessor(i,i+1);
|
||||||
|
//~ m_all_nodes[i]->addSuccessor(i+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(xml_node->getName()=="edge")
|
else if(xml_node->getName()=="edge")
|
||||||
@ -159,7 +172,8 @@ void QuadGraph::load(const std::string &filename)
|
|||||||
xml_node->get("from", &from);
|
xml_node->get("from", &from);
|
||||||
xml_node->get("to", &to);
|
xml_node->get("to", &to);
|
||||||
assert(to<m_all_nodes.size());
|
assert(to<m_all_nodes.size());
|
||||||
m_all_nodes[from]->addSuccessor(to);
|
addSuccessor(from,to);
|
||||||
|
//~ m_all_nodes[from]->addSuccessor(to);
|
||||||
} // edge
|
} // edge
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -281,7 +295,8 @@ void QuadGraph::setDefaultSuccessors()
|
|||||||
{
|
{
|
||||||
for(unsigned int i=0; i<m_all_nodes.size(); i++) {
|
for(unsigned int i=0; i<m_all_nodes.size(); i++) {
|
||||||
if(m_all_nodes[i]->getNumberOfSuccessors()==0) {
|
if(m_all_nodes[i]->getNumberOfSuccessors()==0) {
|
||||||
m_all_nodes[i]->addSuccessor(i+1>=m_all_nodes.size() ? 0 : i+1);
|
addSuccessor(i,i+1>=m_all_nodes.size() ? 0 : i+1);
|
||||||
|
//~ m_all_nodes[i]->addSuccessor(i+1>=m_all_nodes.size() ? 0 : i+1);
|
||||||
} // if size==0
|
} // if size==0
|
||||||
} // for i<m_allNodes.size()
|
} // for i<m_allNodes.size()
|
||||||
} // setDefaultSuccessors
|
} // setDefaultSuccessors
|
||||||
|
@ -77,9 +77,13 @@ private:
|
|||||||
/** Stores the filename - just used for error messages. */
|
/** Stores the filename - just used for error messages. */
|
||||||
std::string m_quad_filename;
|
std::string m_quad_filename;
|
||||||
|
|
||||||
|
/** Wether the graph should be reverted or not */
|
||||||
|
bool m_reverse;
|
||||||
|
|
||||||
void setDefaultSuccessors();
|
void setDefaultSuccessors();
|
||||||
void setChecklineRequirements(GraphNode* node, int latest_checkline);
|
void setChecklineRequirements(GraphNode* node, int latest_checkline);
|
||||||
|
|
||||||
|
void addSuccessor(unsigned int from, unsigned int to);
|
||||||
void load (const std::string &filename);
|
void load (const std::string &filename);
|
||||||
void createMesh(bool show_invisible=true,
|
void createMesh(bool show_invisible=true,
|
||||||
const video::SColor *track_color=NULL,
|
const video::SColor *track_color=NULL,
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "tracks/quad_set.hpp"
|
#include "tracks/quad_set.hpp"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "io/xml_node.hpp"
|
#include "io/xml_node.hpp"
|
||||||
@ -44,6 +45,12 @@ QuadSet::~QuadSet()
|
|||||||
} // ~QuadSet
|
} // ~QuadSet
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
void reverse_quad(Quad* q) {
|
||||||
|
q->reverse();
|
||||||
|
}
|
||||||
|
void QuadSet::reverse_all_quads() {
|
||||||
|
for_each(m_all_quads.begin(),m_all_quads.end(),reverse_quad);
|
||||||
|
}
|
||||||
/** This function interprets a point specification as an attribute in the
|
/** This function interprets a point specification as an attribute in the
|
||||||
xml quadset file. It understands two different specifications:
|
xml quadset file. It understands two different specifications:
|
||||||
p1="n:p" : get point p from square n (n, p integers)
|
p1="n:p" : get point p from square n (n, p integers)
|
||||||
|
@ -47,6 +47,7 @@ public:
|
|||||||
|
|
||||||
QuadSet (const std::string& filename);
|
QuadSet (const std::string& filename);
|
||||||
~QuadSet ();
|
~QuadSet ();
|
||||||
|
void reverse_all_quads();
|
||||||
int getCurrentQuad(const Vec3& p, int oldQuad) const;
|
int getCurrentQuad(const Vec3& p, int oldQuad) const;
|
||||||
const Quad& getQuad(int n) const {return *(m_all_quads[n]); }
|
const Quad& getQuad(int n) const {return *(m_all_quads[n]); }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user