1) Started adding support for quad graphs to have a more flexible way
of specifying the track to use (mainly for the AI). For beach/lighthouse files to specify the graphs have been added (note that if the graph is a simple look, no .graph file is necessary, since it will default to a simple loop), and a script to convert from the current driveline structure to quad graphs has been added, too. This information is currently read in, but not yet used! 2) Some memory leaks were fixed, the filemanager functions getXML* were renamed to createXML* to indicate that the return pointer needs to be freed. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3486 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
55b95609d1
commit
ffe39e467a
@ -222,6 +222,10 @@ supertuxkart_SOURCES = \
|
||||
robots/default_robot.hpp \
|
||||
robots/track_info.cpp \
|
||||
robots/track_info.hpp \
|
||||
tracks/quad_graph.hpp \
|
||||
tracks/quad_graph.cpp \
|
||||
tracks/quad_set.hpp \
|
||||
tracks/quad_set.cpp \
|
||||
tracks/terrain_info.cpp \
|
||||
tracks/terrain_info.hpp \
|
||||
tracks/track.cpp \
|
||||
|
@ -608,6 +608,14 @@
|
||||
<Filter
|
||||
Name="tracks"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\tracks\quad_graph.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\tracks\quad_set.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\tracks\terrain_info.cpp"
|
||||
>
|
||||
@ -1194,6 +1202,14 @@
|
||||
<Filter
|
||||
Name="tracks"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\tracks\quad_graph.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\tracks\quad_set.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\tracks\terrain_info.hpp"
|
||||
>
|
||||
|
@ -209,7 +209,7 @@ FileManager::~FileManager()
|
||||
} // ~FileManager
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
io::IXMLReader *FileManager::getXMLReader(const std::string &filename)
|
||||
io::IXMLReader *FileManager::createXMLReader(const std::string &filename)
|
||||
{
|
||||
return m_file_system->createXMLReader(filename.c_str());
|
||||
} // getXMLReader
|
||||
@ -217,9 +217,9 @@ io::IXMLReader *FileManager::getXMLReader(const std::string &filename)
|
||||
/** Reads in a XML file and converts it into a XMLNode tree.
|
||||
* \param filename Name of the XML file to read.
|
||||
*/
|
||||
XMLNode *FileManager::getXMLTree(const std::string &filename)
|
||||
XMLNode *FileManager::createXMLTree(const std::string &filename)
|
||||
{
|
||||
io::IXMLReader *xml_reader = getXMLReader(filename);
|
||||
io::IXMLReader *xml_reader = createXMLReader(filename);
|
||||
if(!xml_reader) return NULL;
|
||||
return new XMLNode(xml_reader);
|
||||
} // getXMLTree
|
||||
|
@ -56,8 +56,8 @@ public:
|
||||
~FileManager();
|
||||
void setDevice(IrrlichtDevice *device);
|
||||
void dropFileSystem();
|
||||
io::IXMLReader *getXMLReader(const std::string &filename);
|
||||
XMLNode *getXMLTree(const std::string &filename);
|
||||
io::IXMLReader *createXMLReader(const std::string &filename);
|
||||
XMLNode *createXMLTree(const std::string &filename);
|
||||
|
||||
std::string getHomeDir () const;
|
||||
std::string getTrackDir () const;
|
||||
|
@ -34,7 +34,7 @@ XMLNode::XMLNode(io::IXMLReader *xml)
|
||||
*/
|
||||
XMLNode::XMLNode(const std::string &filename)
|
||||
{
|
||||
io::IXMLReader *xml = file_manager->getXMLReader(filename);
|
||||
io::IXMLReader *xml = file_manager->createXMLReader(filename);
|
||||
bool is_first_element = true;
|
||||
while(xml->read())
|
||||
{
|
||||
@ -59,8 +59,14 @@ XMLNode::XMLNode(const std::string &filename)
|
||||
default: break;
|
||||
} // switch
|
||||
} // while
|
||||
xml->drop();
|
||||
} // XMLNode
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Destructor. */
|
||||
XMLNode::~XMLNode()
|
||||
{
|
||||
} // ~XMLNode
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Stores all attributes, and reads in all children.
|
||||
* \param xml The XML reader.
|
||||
|
@ -41,6 +41,7 @@ private:
|
||||
public:
|
||||
XMLNode(io::IXMLReader *xml);
|
||||
XMLNode(const std::string &filename);
|
||||
~XMLNode();
|
||||
const std::string &getName() const {return m_name; }
|
||||
const XMLNode *getNode(const std::string &name) const;
|
||||
const XMLNode *getNode(unsigned int i) const;
|
||||
|
@ -113,8 +113,12 @@ void MaterialManager::addSharedMaterial(const std::string& filename)
|
||||
//-----------------------------------------------------------------------------
|
||||
bool MaterialManager::pushTempMaterial(const std::string& filename)
|
||||
{
|
||||
XMLNode *root = file_manager->getXMLTree(filename);
|
||||
if(!root || root->getName()!="materials") return true;
|
||||
XMLNode *root = file_manager->createXMLTree(filename);
|
||||
if(!root || root->getName()!="materials")
|
||||
{
|
||||
if(root) delete root;
|
||||
return true;
|
||||
}
|
||||
for(unsigned int i=0; i<root->getNumNodes(); i++)
|
||||
{
|
||||
const XMLNode *node = root->getNode(i);
|
||||
@ -134,6 +138,7 @@ bool MaterialManager::pushTempMaterial(const std::string& filename)
|
||||
fprintf(stderr, e.what(), filename.c_str());
|
||||
}
|
||||
} // for i<xml->getNumNodes)(
|
||||
delete root;
|
||||
return true;
|
||||
} // pushTempMaterial
|
||||
|
||||
|
107
src/tracks/quad_graph.cpp
Executable file
107
src/tracks/quad_graph.cpp
Executable file
@ -0,0 +1,107 @@
|
||||
// $Id$
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2009 Joerg Henrichs
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, B
|
||||
|
||||
#include "tracks/quad_graph.hpp"
|
||||
|
||||
#include "io/file_manager.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
#include "tracks/quad_set.hpp"
|
||||
|
||||
/** Constructor, loads the graph information for a given set of quads
|
||||
* from a graph file.
|
||||
* \param filename Name of the file to load.
|
||||
* \param quad_set The set of quads to which the graph applies.
|
||||
*/
|
||||
QuadGraph::QuadGraph(const std::string &filename, QuadSet* quad_set)
|
||||
{
|
||||
// First create all nodes
|
||||
for(unsigned int i=0; i<quad_set->getSize(); i++) {
|
||||
m_all_nodes.push_back(new GraphNode);
|
||||
}
|
||||
load(filename);
|
||||
} // QuadGraph
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Destructor, removes all nodes of the graph. */
|
||||
QuadGraph::~QuadGraph()
|
||||
{
|
||||
for(unsigned int i=0; i<m_all_nodes.size(); i++) {
|
||||
delete m_all_nodes[i];
|
||||
}
|
||||
} // ~QuadGraph
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Loads a quad graph from a file.
|
||||
* \param filename Name of the file to load.
|
||||
*/
|
||||
void QuadGraph::load(const std::string &filename)
|
||||
{
|
||||
const XMLNode *xml = file_manager->createXMLTree(filename);
|
||||
|
||||
if(!xml)
|
||||
{
|
||||
// No graph file exist, assume a default loop X -> X+1
|
||||
setDefaultSuccessors();
|
||||
return;
|
||||
}
|
||||
for(unsigned int i=0; i<xml->getNumNodes(); i++)
|
||||
{
|
||||
const XMLNode *node = xml->getNode(i);
|
||||
if(node->getName()!="edge")
|
||||
{
|
||||
fprintf(stderr, "Incorrect specification in '%s': '%' ignored\n",
|
||||
filename.c_str(), node->getName().c_str());
|
||||
continue;
|
||||
}
|
||||
int from, to;
|
||||
node->get("from", &from);
|
||||
node->get("to", &to);
|
||||
assert(from>=0 && from <(int)m_all_nodes.size());
|
||||
m_all_nodes[from]->addSuccessor(to);
|
||||
} // from
|
||||
delete xml;
|
||||
|
||||
setDefaultSuccessors();
|
||||
} // load
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** This function sets a default successor for all graph nodes that currently
|
||||
* don't have a successor defined. The default successor of node X is X+1.
|
||||
*/
|
||||
void QuadGraph::setDefaultSuccessors()
|
||||
{
|
||||
for(unsigned int i=0; i<m_all_nodes.size(); i++) {
|
||||
if(m_all_nodes[i]->getNumberOfSuccessors()==0) {
|
||||
m_all_nodes[i]->addSuccessor( i+1>=m_all_nodes.size() ? 0 : i+1);
|
||||
} // if size==0
|
||||
} // for i<m_allNodes.size()
|
||||
} // setDefaultSuccessors
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Returns the list of successors or a node.
|
||||
* \param node_number The number of the node.
|
||||
* \param succ A vector of ints to which the successors are added.
|
||||
*/
|
||||
void QuadGraph::getSuccessors(int node_number, std::vector<int>& succ) const {
|
||||
const GraphNode *v=m_all_nodes[node_number];
|
||||
for(unsigned int i=0; i<v->getNumberOfSuccessors(); i++) {
|
||||
succ.push_back((*v)[i]);
|
||||
}
|
||||
} // getSuccessors
|
||||
|
57
src/tracks/quad_graph.hpp
Executable file
57
src/tracks/quad_graph.hpp
Executable file
@ -0,0 +1,57 @@
|
||||
// $Id$
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2009 Joerg Henrichs
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, B
|
||||
|
||||
#ifndef HEADER_QUAD_GRAPH_HPP
|
||||
#define HEADER_QUAD_GRAPH_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class QuadSet;
|
||||
|
||||
/** This class stores a graph of quads. */
|
||||
class QuadGraph {
|
||||
/** This class stores a node of the graph, i.e. a list of successor
|
||||
* edges. */
|
||||
class GraphNode
|
||||
{
|
||||
/** The list of successors. */
|
||||
std::vector<int> m_vertices;
|
||||
public:
|
||||
/** Adds a successor to a node. */
|
||||
void addSuccessor (int to) {m_vertices.push_back(to); }
|
||||
/** Returns the i-th successor. */
|
||||
unsigned int operator[] (int i) const {return m_vertices[i]; }
|
||||
/** Returns the number of successors. */
|
||||
unsigned int getNumberOfSuccessors() const
|
||||
{ return (unsigned int)m_vertices.size(); }
|
||||
};
|
||||
// ========================================================================
|
||||
protected:
|
||||
std::vector<GraphNode*> m_all_nodes;
|
||||
void setDefaultSuccessors();
|
||||
void load (const std::string &filename);
|
||||
|
||||
public:
|
||||
QuadGraph (const std::string &filename, QuadSet *quad_set);
|
||||
~QuadGraph ();
|
||||
void getSuccessors(int quadNumber, std::vector<int>& succ) const;
|
||||
}; // QuadGraph
|
||||
|
||||
#endif
|
124
src/tracks/quad_set.cpp
Executable file
124
src/tracks/quad_set.cpp
Executable file
@ -0,0 +1,124 @@
|
||||
// $Id$
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2009 Joerg Henrichs
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "quad_set.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "io/file_manager.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
/** Constructor, loads the quad set from a file.
|
||||
* \param filename filename to load.
|
||||
*/
|
||||
QuadSet::QuadSet(const std::string& filename) {
|
||||
load(filename);
|
||||
} // QuadSet
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** This function interprets a point specification as an attribute in the
|
||||
xml quadset file. It understands two different specifications:
|
||||
p1="n:p" : get point p from square n (n, p integers)
|
||||
p1="p1,p2,p3" : make a 3d point out of these 3 floating point values
|
||||
*/
|
||||
void QuadSet::getPoint(const XMLNode *xml, const std::string &attribute_name,
|
||||
Vec3* result) const
|
||||
{
|
||||
std::string s;
|
||||
xml->get(attribute_name, &s);
|
||||
int pos=s.find_first_of(":");
|
||||
if(pos>0) // n:p specification
|
||||
{
|
||||
std::vector<std::string> l = StringUtils::split(s, ':');
|
||||
int n=atoi(l[0].c_str());
|
||||
int p=atoi(l[1].c_str());
|
||||
*result=(*m_allQuads[n])[p];
|
||||
}
|
||||
else
|
||||
{
|
||||
xml->get(attribute_name, result);
|
||||
}
|
||||
|
||||
} // getPoint
|
||||
// -----------------------------------------------------------------------------
|
||||
void QuadSet::load(const std::string &filename) {
|
||||
m_xMin = m_zMin = 9999999.9f;
|
||||
m_xMax = m_zMax = -9999999.9f;
|
||||
|
||||
XMLNode *xml = file_manager->createXMLTree(filename);
|
||||
if(!xml || xml->getName()!="quads")
|
||||
{
|
||||
fprintf(stderr, "QuadSet '%s' not found.\n", filename.c_str());
|
||||
return;
|
||||
//FIXME exit(-1);
|
||||
}
|
||||
for(unsigned int i=0; i<xml->getNumNodes(); i++)
|
||||
{
|
||||
const XMLNode *xml_node = xml->getNode(i);
|
||||
if(xml_node->getName()!="quad")
|
||||
{
|
||||
printf("Unsupported node type '%s' found in '%s' - ignored.\n",
|
||||
xml_node->getName().c_str(), filename.c_str());
|
||||
continue;
|
||||
}
|
||||
Vec3 p0, p1, p2, p3;
|
||||
getPoint(xml_node, "p0", &p0);
|
||||
getPoint(xml_node, "p1", &p1);
|
||||
getPoint(xml_node, "p2", &p2);
|
||||
getPoint(xml_node, "p3", &p3);
|
||||
Quad* q=new Quad(p0,p1,p2,p3);
|
||||
m_allQuads.push_back(q);
|
||||
|
||||
}
|
||||
delete xml;
|
||||
} // load
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Returns wether a point is to the left or to the right of a line.
|
||||
While all arguments are 3d, only the x and y coordinates are actually used.
|
||||
*/
|
||||
float QuadSet::sideOfLine2D(const Vec3 &l1, const Vec3 &l2, const Vec3 &p) const
|
||||
{
|
||||
return (l2.getX()-l1.getX())*(p.getZ()-l1.getZ()) -
|
||||
(l2.getZ()-l1.getZ())*(p.getX()-l1.getX());
|
||||
} // sideOfLine
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
bool QuadSet::pointInQuad(const Quad& q, const btVector3& p) const {
|
||||
if(sideOfLine2D(q[0], q[2], p)<0) {
|
||||
return sideOfLine2D(q[0], q[1], p) > 0.0 &&
|
||||
sideOfLine2D(q[1], q[2], p) >= 0.0;
|
||||
} else {
|
||||
return sideOfLine2D(q[2], q[3], p) > 0.0 &&
|
||||
sideOfLine2D(q[3], q[0], p) >= 0.0;
|
||||
}
|
||||
} // pointInQuad
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Determines the quad on which the position pos is. This is a rather slow
|
||||
algorithm, used to get the initial quad position of a kart, but not for
|
||||
constantly updating it.
|
||||
*/
|
||||
int QuadSet::getQuad(const Vec3 &pos) const {
|
||||
for(unsigned int i=0; i<m_allQuads.size(); i++) {
|
||||
if(pointInQuad(*(m_allQuads[i]), pos)) return i;
|
||||
}
|
||||
return QUAD_NONE;
|
||||
} // getQuad
|
||||
// -----------------------------------------------------------------------------
|
84
src/tracks/quad_set.hpp
Executable file
84
src/tracks/quad_set.hpp
Executable file
@ -0,0 +1,84 @@
|
||||
// $Id$
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2009 Joerg Henrichs
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// 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_QUAD_SET_HPP
|
||||
#define HEADER_QUAD_SET_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "io/xml_node.hpp"
|
||||
#include "utils/vec3.hpp"
|
||||
|
||||
class QuadSet {
|
||||
private:
|
||||
/** Internal class to store a single quad. */
|
||||
class Quad {
|
||||
public:
|
||||
/** The four points of a quad. */
|
||||
Vec3 m_p[4];
|
||||
/** The center, which is used by the AI. This saves some
|
||||
computations at runtime. */
|
||||
Vec3 m_center;
|
||||
/** Constructor, takes 4 points. */
|
||||
Quad(btVector3 p0, btVector3 p1, btVector3 p2, btVector3 p3)
|
||||
{
|
||||
m_p[0]=p0; m_p[1]=p1; m_p[2]=p2; m_p[3]=p3;
|
||||
m_center = 0.25f*(p0+p1+p2+p3);
|
||||
m_center.setX((p0.getX()+p1.getX()+p2.getX()+p3.getX())/4.0f);
|
||||
m_center.setY((p0.getY()+p1.getY()+p2.getY()+p3.getY())/4.0f);
|
||||
m_center.setZ((p0.getZ()+p1.getZ()+p2.getZ()+p3.getZ())/4.0f);
|
||||
}
|
||||
/** Returns the i-th. point of a quad. */
|
||||
const btVector3& operator[](int i) const {return m_p[i]; }
|
||||
/** Returns the center of a quad. */
|
||||
const btVector3& getCenter () const {return m_center; }
|
||||
}; // class Quad
|
||||
// =======================================================================
|
||||
/** The 2d bounding box, used for hashing. */
|
||||
// FIXME: named with z being the forward axis
|
||||
float m_xMin, m_xMax, m_zMin, m_zMax;
|
||||
/** The list of all quads. */
|
||||
std::vector<Quad*> m_allQuads;
|
||||
void load (const std::string &filename);
|
||||
void getPoint(const XMLNode *xml, const std::string &attribute_name,
|
||||
Vec3 *result) const;
|
||||
float sideOfLine2D(const Vec3 &l1, const Vec3 &l2, const Vec3 &p) const;
|
||||
|
||||
public:
|
||||
static const int QUAD_NONE=-1;
|
||||
|
||||
QuadSet (const std::string& filename);
|
||||
int getQuad (const Vec3& p) const;
|
||||
int getCurrentQuad(const Vec3& p, int oldQuad) const;
|
||||
bool pointInQuad (const Quad& q, const btVector3& p) const;
|
||||
/** Returns true if the point p is in the n-th. quad. */
|
||||
bool pointInQuad (int n, const btVector3& p) const
|
||||
{return pointInQuad(*m_allQuads[n],p);}
|
||||
void getBoundingBox(float* xMin, float* xMax,
|
||||
float* zMin, float* zMax) const
|
||||
{ *xMin=m_xMin; *xMax=m_xMax;
|
||||
*zMin=m_zMin; *zMax=m_zMax;}
|
||||
/** Returns the number of quads. */
|
||||
unsigned int getSize() const {return (unsigned int)m_allQuads.size(); }
|
||||
/** Returns the center of quad n. */
|
||||
const btVector3& getCenterOfQuad(int n) const
|
||||
{return m_allQuads[n]->getCenter(); }
|
||||
}; // QuadSet
|
||||
#endif
|
@ -43,6 +43,8 @@
|
||||
#include "physics/physical_object.hpp"
|
||||
#include "physics/triangle_mesh.hpp"
|
||||
#include "race_manager.hpp"
|
||||
#include "tracks/quad_graph.hpp"
|
||||
#include "tracks/quad_set.hpp"
|
||||
#include "utils/ssg_help.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
@ -70,16 +72,21 @@ Track::Track( std::string filename_, float w, float h, bool stretch )
|
||||
m_non_collision_mesh = new TriangleMesh();
|
||||
m_all_nodes.clear();
|
||||
m_all_meshes.clear();
|
||||
m_has_final_camera = false;
|
||||
m_is_arena = false;
|
||||
m_has_final_camera = false;
|
||||
m_is_arena = false;
|
||||
m_quads = NULL;
|
||||
m_quad_graph = NULL;
|
||||
loadTrack(m_filename);
|
||||
loadDriveline();
|
||||
|
||||
} // Track
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Destructor, removes quad data structures etc. */
|
||||
Track::~Track()
|
||||
{
|
||||
if(m_quads) delete m_quads;
|
||||
if(m_quad_graph) delete m_quad_graph;
|
||||
} // ~Track
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -871,7 +878,7 @@ void Track::loadTrack(const std::string &filename)
|
||||
m_ambient_color = video::SColorf(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
m_specular_color = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
m_diffuse_color = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
XMLNode *root = file_manager->getXMLTree(m_filename);
|
||||
XMLNode *root = file_manager->createXMLTree(m_filename);
|
||||
|
||||
if(!root || root->getName()!="track")
|
||||
{
|
||||
@ -954,6 +961,8 @@ void Track::loadTrack(const std::string &filename)
|
||||
|
||||
// Set the correct paths
|
||||
m_screenshot = file_manager->getTrackFile(m_screenshot, getIdent());
|
||||
delete root;
|
||||
|
||||
} // loadTrack
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -993,6 +1002,9 @@ void Track::startMusic() const
|
||||
//-----------------------------------------------------------------------------
|
||||
void Track::loadDriveline()
|
||||
{
|
||||
m_quads = new QuadSet (file_manager->getTrackFile(m_ident+".quads"));
|
||||
m_quad_graph = new QuadGraph(file_manager->getTrackFile(m_ident+".graph"),
|
||||
m_quads);
|
||||
readDrivelineFromFile(m_left_driveline, ".drvl");
|
||||
|
||||
const unsigned int DRIVELINE_SIZE = (unsigned int)m_left_driveline.size();
|
||||
@ -1375,9 +1387,8 @@ void Track::loadTrackModel()
|
||||
}
|
||||
|
||||
// Start building the scene graph
|
||||
#ifdef HAVE_IRRLICHT
|
||||
std::string path = file_manager->getTrackFile(getIdent()+".scene");
|
||||
XMLNode *root = file_manager->getXMLTree(path);
|
||||
XMLNode *root = file_manager->createXMLTree(path);
|
||||
|
||||
// Make sure that we have a track (which is used for raycasts to
|
||||
// place other objects).
|
||||
@ -1449,6 +1460,7 @@ void Track::loadTrackModel()
|
||||
}
|
||||
|
||||
}
|
||||
delete root;
|
||||
|
||||
// Init all physical objects
|
||||
for(std::vector<PhysicalObject*>::const_iterator i=m_physical_objects.begin();
|
||||
@ -1457,7 +1469,7 @@ void Track::loadTrackModel()
|
||||
(*i)->init();
|
||||
}
|
||||
|
||||
#else
|
||||
#ifndef HAVE_IRRLICHT
|
||||
std::string path = file_manager->getTrackFile(getIdent()+".loc");
|
||||
|
||||
FILE *fd = fopen (path.c_str(), "r" );
|
||||
|
@ -42,6 +42,8 @@ class TriangleMesh;
|
||||
class MovingTexture;
|
||||
class XMLNode;
|
||||
class PhysicalObject;
|
||||
class QuadSet;
|
||||
class QuadGraph;
|
||||
|
||||
class Track
|
||||
{
|
||||
@ -68,6 +70,10 @@ private:
|
||||
int m_version;
|
||||
bool loadMainTrack(const XMLNode &node);
|
||||
void createWater(const XMLNode &node);
|
||||
/** The set of all quads for this track. */
|
||||
QuadSet *m_quads;
|
||||
/** The graph used to connect the quads. */
|
||||
QuadGraph *m_quad_graph;
|
||||
/** The type of sky to be used for the track. */
|
||||
enum {SKY_NONE, SKY_BOX,
|
||||
SKY_DOME} m_sky_type;
|
||||
|
Loading…
x
Reference in New Issue
Block a user