More clean up
This commit is contained in:
parent
e4da6d4a99
commit
08b2e27ed9
@ -40,7 +40,6 @@ BattleGraph::BattleGraph(const std::string &navmesh_file_name)
|
||||
NavMesh::create(navmesh_file_name);
|
||||
m_navmesh_file = navmesh_file_name;
|
||||
buildGraph(NavMesh::get());
|
||||
setType();
|
||||
computeFloydWarshall();
|
||||
} // BattleGraph
|
||||
|
||||
|
@ -63,6 +63,23 @@ private:
|
||||
BattleGraph(const std::string &navmesh_file_name);
|
||||
~BattleGraph(void);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void set3DVerticesOfGraph(int i, video::S3DVertex *v,
|
||||
const video::SColor &color) const
|
||||
{ NavMesh::get()->setVertices(i, v, color); }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void getGraphBoundingBox(Vec3 *min, Vec3 *max) const
|
||||
{ NavMesh::get()->getBoundingBox(min, max); }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual const bool isNodeInvisible(int n) const
|
||||
{ return false; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual const bool isNodeInvalid(int n) const
|
||||
{ return (NavMesh::get()->getNavPoly(n).getVerticesIndex()).size()!=4; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual const bool hasLapLine() const
|
||||
{ return false; }
|
||||
|
||||
public:
|
||||
static const int UNKNOWN_POLY;
|
||||
|
||||
@ -92,12 +109,12 @@ public:
|
||||
/** Returns the number of nodes in the BattleGraph (equal to the number of
|
||||
* polygons in the NavMesh */
|
||||
virtual const unsigned int getNumNodes() const
|
||||
{ return m_distance_matrix.size(); }
|
||||
{ return m_distance_matrix.size(); }
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
/** Returns the NavPoly corresponding to the i-th node of the BattleGraph */
|
||||
const NavPoly& getPolyOfNode(int i) const
|
||||
{ return NavMesh::get()->getNavPoly(i); }
|
||||
{ return NavMesh::get()->getNavPoly(i); }
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
/** Returns the next polygon on the shortest path from i to j.
|
||||
@ -106,15 +123,9 @@ public:
|
||||
const int & getNextShortestPathPoly(int i, int j) const;
|
||||
|
||||
const std::vector < std::pair<const Item*, int> >& getItemList()
|
||||
{ return m_items_on_graph; }
|
||||
{ return m_items_on_graph; }
|
||||
|
||||
void findItemsOnGraphNodes();
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the type of this graph. */
|
||||
virtual void setType() { m_graph_type = GraphType::GT_BATTLE; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual const std::vector<GraphNode*> getAllNodes() const
|
||||
{return std::vector<GraphNode*>();}
|
||||
}; //BattleGraph
|
||||
|
||||
#endif
|
||||
|
@ -22,21 +22,17 @@
|
||||
#include <ICameraSceneNode.h>
|
||||
#include <IMeshSceneNode.h>
|
||||
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/glwrap.hpp"
|
||||
#include "graphics/shaders.hpp"
|
||||
#include "graphics/rtts.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "tracks/quad_set.hpp"
|
||||
#include "tracks/navmesh.hpp"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
GraphStructure::GraphStructure()
|
||||
{
|
||||
m_graph_type = GT_RACE;
|
||||
m_min_coord = 0;
|
||||
m_scaling = 0;
|
||||
m_node = NULL;
|
||||
@ -101,8 +97,7 @@ void GraphStructure::createDebugMesh()
|
||||
/** Creates the actual mesh that is used by createDebugMesh() or makeMiniMap() */
|
||||
void GraphStructure::createMesh(bool show_invisible,
|
||||
bool enable_transparency,
|
||||
const video::SColor *track_color,
|
||||
const video::SColor *lap_color)
|
||||
const video::SColor *track_color)
|
||||
{
|
||||
// The debug track will not be lighted or culled.
|
||||
video::SMaterial m;
|
||||
@ -115,21 +110,15 @@ void GraphStructure::createMesh(bool show_invisible,
|
||||
m_mesh = irr_driver->createQuadMesh(&m);
|
||||
m_mesh_buffer = m_mesh->getMeshBuffer(0);
|
||||
assert(m_mesh_buffer->getVertexType()==video::EVT_STANDARD);
|
||||
const std::vector<GraphNode*> all_nodes = getAllNodes();
|
||||
|
||||
unsigned int n;
|
||||
if (m_graph_type == GT_RACE)
|
||||
unsigned int n = 0;
|
||||
// Count the number of quads to display (some quads might be invisible
|
||||
|
||||
for (unsigned int i = 0; i < getNumNodes(); i++)
|
||||
{
|
||||
// Count the number of quads to display (some quads might be invisible
|
||||
n = 0;
|
||||
for (unsigned int i = 0; i < getNumNodes(); i++)
|
||||
{
|
||||
if (show_invisible || !all_nodes[i]->getQuad().isInvisible())
|
||||
n++;
|
||||
}
|
||||
if (show_invisible || !isNodeInvisible(i))
|
||||
n++;
|
||||
}
|
||||
else
|
||||
n = getNumNodes();
|
||||
|
||||
// Four vertices for each of the n-1 remaining quads
|
||||
video::S3DVertex *new_v = new video::S3DVertex[4*n];
|
||||
@ -146,16 +135,12 @@ void GraphStructure::createMesh(bool show_invisible,
|
||||
for (unsigned int count = 0; count < getNumNodes(); count++)
|
||||
{
|
||||
// Ignore invisible quads
|
||||
if (m_graph_type == GT_RACE)
|
||||
if (!show_invisible && isNodeInvisible(count))
|
||||
continue;
|
||||
else if (isNodeInvalid(count))
|
||||
{
|
||||
if (!show_invisible && all_nodes[count]->getQuad().isInvisible())
|
||||
continue;
|
||||
}
|
||||
else if ((NavMesh::get()->getNavPoly(count).getVerticesIndex()).size() !=4 &&
|
||||
m_graph_type == GT_BATTLE)
|
||||
{
|
||||
// There should not be a poly which isn't made of 4 vertices
|
||||
Log::warn("Battle Graph", "There is an invalid poly!");
|
||||
// There should not be a node which isn't made of 4 vertices
|
||||
Log::warn("Graph Structure", "There is an invalid node!");
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -167,10 +152,7 @@ void GraphStructure::createMesh(bool show_invisible,
|
||||
}
|
||||
|
||||
// Transfer the 4 points of the current quad to the list of vertices
|
||||
if (m_graph_type == GT_RACE)
|
||||
all_nodes[count]->getQuad().getVertices(new_v+4*i, c);
|
||||
else
|
||||
NavMesh::get()->setVertices(count, new_v+4*i, c);
|
||||
set3DVerticesOfGraph(count, new_v+4*i, c);
|
||||
|
||||
// Set up the indices for the triangles
|
||||
// (note, afaik with opengl we could use quads directly, but the code
|
||||
@ -186,17 +168,17 @@ void GraphStructure::createMesh(bool show_invisible,
|
||||
|
||||
m_mesh_buffer->append(new_v, n*4, ind, n*6);
|
||||
|
||||
if (lap_color && m_graph_type == GT_RACE)
|
||||
if (hasLapLine())
|
||||
{
|
||||
video::S3DVertex lap_v[4];
|
||||
irr::u16 lap_ind[6];
|
||||
video::SColor c(128, 255, 0, 0);
|
||||
all_nodes[0]->getQuad().getVertices(lap_v, *lap_color);
|
||||
video::SColor lap_color(128, 255, 0, 0);
|
||||
set3DVerticesOfGraph(0, lap_v, lap_color);
|
||||
|
||||
// Now scale the length (distance between vertix 0 and 3
|
||||
// and between 1 and 2) to be 'length':
|
||||
Vec3 bb_min, bb_max;
|
||||
QuadSet::get()->getBoundingBox(&bb_min, &bb_max);
|
||||
getGraphBoundingBox(&bb_min, &bb_max);
|
||||
// Length of the lap line about 3% of the 'height'
|
||||
// of the track.
|
||||
const float length = (bb_max.getZ()-bb_min.getZ())*0.03f;
|
||||
@ -278,21 +260,9 @@ void GraphStructure::makeMiniMap(const core::dimension2du &dimension,
|
||||
|
||||
irr_driver->getSceneManager()->setAmbientLight(video::SColor(255, 255, 255, 255));
|
||||
|
||||
if (m_graph_type == GT_RACE)
|
||||
{
|
||||
video::SColor red(128, 255, 0, 0);
|
||||
createMesh(/*show_invisible part of the track*/ false,
|
||||
/*enable_transparency*/ false,
|
||||
/*track_color*/ &fill_color,
|
||||
/*lap line color*/ &red);
|
||||
}
|
||||
else
|
||||
{
|
||||
createMesh(/*show_invisible part of the track*/ false,
|
||||
/*enable_transparency*/ false,
|
||||
/*track_color*/ &fill_color,
|
||||
/*lap line color*/ NULL);
|
||||
}
|
||||
createMesh(/*show_invisible part of the track*/ false,
|
||||
/*enable_transparency*/ false,
|
||||
/*track_color*/ &fill_color);
|
||||
|
||||
m_node = irr_driver->addMesh(m_mesh, "mini_map");
|
||||
#ifdef DEBUG
|
||||
@ -306,10 +276,7 @@ void GraphStructure::makeMiniMap(const core::dimension2du &dimension,
|
||||
// ---------------
|
||||
scene::ICameraSceneNode *camera = irr_driver->addCameraSceneNode();
|
||||
Vec3 bb_min, bb_max;
|
||||
if (m_graph_type == GT_RACE)
|
||||
QuadSet::get()->getBoundingBox(&bb_min, &bb_max);
|
||||
else
|
||||
NavMesh::get()->getBoundingBox(&bb_min, &bb_max);
|
||||
getGraphBoundingBox(&bb_min, &bb_max);
|
||||
Vec3 center = (bb_max+bb_min)*0.5f;
|
||||
|
||||
float dx = bb_max.getX()-bb_min.getX();
|
||||
@ -384,8 +351,8 @@ void GraphStructure::makeMiniMap(const core::dimension2du &dimension,
|
||||
|
||||
if (texture == NULL && frame_buffer == NULL)
|
||||
{
|
||||
Log::error("BattleGraph", "[makeMiniMap] WARNING: RTT does not appear to work,"
|
||||
"mini-map will not be available.");
|
||||
Log::error("Graph Structure", "[makeMiniMap] WARNING: RTT does not"
|
||||
"appear to work, mini-map will not be available.");
|
||||
}
|
||||
|
||||
*oldRttMinimap = texture;
|
||||
|
@ -23,14 +23,13 @@
|
||||
|
||||
#include <dimension2d.h>
|
||||
#include <SColor.h>
|
||||
#include "tracks/graph_node.hpp"
|
||||
#include "utils/vec3.hpp"
|
||||
#include "utils/no_copy.hpp"
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace scene { class ISceneNode; class IMesh; class IMeshBuffer; }
|
||||
namespace video { class ITexture; }
|
||||
namespace video { class ITexture; struct S3DVertex; }
|
||||
}
|
||||
using namespace irr;
|
||||
|
||||
@ -38,25 +37,17 @@ class FrameBuffer;
|
||||
class RTT;
|
||||
|
||||
/**
|
||||
* \brief Virtual base class for a graph structure.
|
||||
* \brief Virtual base class for a graph structure.
|
||||
* This is mainly used for drawing minimap in game.
|
||||
*
|
||||
* A graph structure has a certain type:
|
||||
* GT_RACE : Graph used by a lap race.
|
||||
* GT_BATTLE: Graph used by a battle arena.
|
||||
*
|
||||
* \ingroup tracks
|
||||
* \ingroup tracks
|
||||
*/
|
||||
class GraphStructure : public NoCopy
|
||||
{
|
||||
public:
|
||||
enum GraphType {GT_RACE, GT_BATTLE};
|
||||
|
||||
protected:
|
||||
/** The type of this graph. */
|
||||
GraphType m_graph_type;
|
||||
|
||||
void cleanupDebugMesh();
|
||||
void destroyRTT();
|
||||
void cleanupDebugMesh();
|
||||
void destroyRTT();
|
||||
|
||||
private:
|
||||
RTT* m_new_rtt;
|
||||
@ -76,10 +67,16 @@ private:
|
||||
/** Scaling for mini map. */
|
||||
float m_scaling;
|
||||
|
||||
void createMesh(bool show_invisible=true,
|
||||
bool enable_transparency=false,
|
||||
const video::SColor *track_color=NULL,
|
||||
const video::SColor *lap_color=NULL);
|
||||
void createMesh(bool show_invisible=true,
|
||||
bool enable_transparency=false,
|
||||
const video::SColor *track_color=NULL);
|
||||
|
||||
virtual void set3DVerticesOfGraph(int i, video::S3DVertex *v,
|
||||
const video::SColor &color) const = 0;
|
||||
virtual void getGraphBoundingBox(Vec3 *min, Vec3 *max) const = 0;
|
||||
virtual const bool isNodeInvisible(int n) const = 0;
|
||||
virtual const bool isNodeInvalid(int n) const = 0;
|
||||
virtual const bool hasLapLine() const = 0;
|
||||
|
||||
public:
|
||||
GraphStructure();
|
||||
@ -91,9 +88,7 @@ public:
|
||||
video::ITexture** oldRttMinimap,
|
||||
FrameBuffer** newRttMinimap);
|
||||
void mapPoint2MiniMap(const Vec3 &xyz, Vec3 *out) const;
|
||||
virtual const unsigned int getNumNodes() const = 0;
|
||||
virtual const std::vector<GraphNode*> getAllNodes() const = 0;
|
||||
virtual void setType() = 0;
|
||||
virtual const unsigned int getNumNodes() const = 0;
|
||||
}; // GraphStructure
|
||||
|
||||
#endif
|
||||
|
@ -57,7 +57,6 @@ QuadGraph::QuadGraph(const std::string &quad_file_name,
|
||||
m_quad_filename = quad_file_name;
|
||||
m_quad_graph = this;
|
||||
load(graph_file_name);
|
||||
setType();
|
||||
} // QuadGraph
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -73,6 +73,24 @@ private:
|
||||
const std::string &graph_file_name,
|
||||
const bool reverse);
|
||||
~QuadGraph ();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void set3DVerticesOfGraph(int i, video::S3DVertex *v,
|
||||
const video::SColor &color) const
|
||||
{ m_all_nodes[i]->getQuad().getVertices(v, color); }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void getGraphBoundingBox(Vec3 *min, Vec3 *max) const
|
||||
{ QuadSet::get()->getBoundingBox(min, max); }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual const bool isNodeInvisible(int n) const
|
||||
{ return m_all_nodes[n]->getQuad().isInvisible(); }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual const bool isNodeInvalid(int n) const
|
||||
{ return false; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual const bool hasLapLine() const
|
||||
{ return true; }
|
||||
|
||||
public:
|
||||
static const int UNKNOWN_SECTOR;
|
||||
|
||||
@ -160,12 +178,6 @@ public:
|
||||
float getLapLength() const {return m_lap_length; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool isReverse() const {return m_reverse; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the type of this graph. */
|
||||
virtual void setType() { m_graph_type = GraphType::GT_RACE; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual const std::vector<GraphNode*> getAllNodes() const
|
||||
{ return m_all_nodes; }
|
||||
}; // QuadGraph
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user