More clean up

This commit is contained in:
Benau 2015-12-19 16:23:18 +08:00
parent e4da6d4a99
commit 08b2e27ed9
6 changed files with 78 additions and 95 deletions

View File

@ -40,7 +40,6 @@ BattleGraph::BattleGraph(const std::string &navmesh_file_name)
NavMesh::create(navmesh_file_name); NavMesh::create(navmesh_file_name);
m_navmesh_file = navmesh_file_name; m_navmesh_file = navmesh_file_name;
buildGraph(NavMesh::get()); buildGraph(NavMesh::get());
setType();
computeFloydWarshall(); computeFloydWarshall();
} // BattleGraph } // BattleGraph

View File

@ -63,6 +63,23 @@ private:
BattleGraph(const std::string &navmesh_file_name); BattleGraph(const std::string &navmesh_file_name);
~BattleGraph(void); ~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: public:
static const int UNKNOWN_POLY; static const int UNKNOWN_POLY;
@ -109,12 +126,6 @@ public:
{ return m_items_on_graph; } { return m_items_on_graph; }
void findItemsOnGraphNodes(); 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 }; //BattleGraph
#endif #endif

View File

@ -22,21 +22,17 @@
#include <ICameraSceneNode.h> #include <ICameraSceneNode.h>
#include <IMeshSceneNode.h> #include <IMeshSceneNode.h>
#include "config/user_config.hpp"
#include "graphics/irr_driver.hpp" #include "graphics/irr_driver.hpp"
#include "graphics/glwrap.hpp" #include "graphics/glwrap.hpp"
#include "graphics/shaders.hpp" #include "graphics/shaders.hpp"
#include "graphics/rtts.hpp" #include "graphics/rtts.hpp"
#include "modes/world.hpp" #include "modes/world.hpp"
#include "tracks/quad_set.hpp"
#include "tracks/navmesh.hpp"
#include "utils/log.hpp" #include "utils/log.hpp"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
GraphStructure::GraphStructure() GraphStructure::GraphStructure()
{ {
m_graph_type = GT_RACE;
m_min_coord = 0; m_min_coord = 0;
m_scaling = 0; m_scaling = 0;
m_node = NULL; m_node = NULL;
@ -101,8 +97,7 @@ void GraphStructure::createDebugMesh()
/** Creates the actual mesh that is used by createDebugMesh() or makeMiniMap() */ /** Creates the actual mesh that is used by createDebugMesh() or makeMiniMap() */
void GraphStructure::createMesh(bool show_invisible, void GraphStructure::createMesh(bool show_invisible,
bool enable_transparency, bool enable_transparency,
const video::SColor *track_color, const video::SColor *track_color)
const video::SColor *lap_color)
{ {
// The debug track will not be lighted or culled. // The debug track will not be lighted or culled.
video::SMaterial m; video::SMaterial m;
@ -115,21 +110,15 @@ void GraphStructure::createMesh(bool show_invisible,
m_mesh = irr_driver->createQuadMesh(&m); m_mesh = irr_driver->createQuadMesh(&m);
m_mesh_buffer = m_mesh->getMeshBuffer(0); m_mesh_buffer = m_mesh->getMeshBuffer(0);
assert(m_mesh_buffer->getVertexType()==video::EVT_STANDARD); assert(m_mesh_buffer->getVertexType()==video::EVT_STANDARD);
const std::vector<GraphNode*> all_nodes = getAllNodes();
unsigned int n; unsigned int n = 0;
if (m_graph_type == GT_RACE)
{
// Count the number of quads to display (some quads might be invisible // Count the number of quads to display (some quads might be invisible
n = 0;
for (unsigned int i = 0; i < getNumNodes(); i++) for (unsigned int i = 0; i < getNumNodes(); i++)
{ {
if (show_invisible || !all_nodes[i]->getQuad().isInvisible()) if (show_invisible || !isNodeInvisible(i))
n++; n++;
} }
}
else
n = getNumNodes();
// Four vertices for each of the n-1 remaining quads // Four vertices for each of the n-1 remaining quads
video::S3DVertex *new_v = new video::S3DVertex[4*n]; 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++) for (unsigned int count = 0; count < getNumNodes(); count++)
{ {
// Ignore invisible quads // Ignore invisible quads
if (m_graph_type == GT_RACE) if (!show_invisible && isNodeInvisible(count))
{
if (!show_invisible && all_nodes[count]->getQuad().isInvisible())
continue; continue;
} else if (isNodeInvalid(count))
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 // There should not be a node which isn't made of 4 vertices
Log::warn("Battle Graph", "There is an invalid poly!"); Log::warn("Graph Structure", "There is an invalid node!");
continue; continue;
} }
@ -167,10 +152,7 @@ void GraphStructure::createMesh(bool show_invisible,
} }
// Transfer the 4 points of the current quad to the list of vertices // Transfer the 4 points of the current quad to the list of vertices
if (m_graph_type == GT_RACE) set3DVerticesOfGraph(count, new_v+4*i, c);
all_nodes[count]->getQuad().getVertices(new_v+4*i, c);
else
NavMesh::get()->setVertices(count, new_v+4*i, c);
// Set up the indices for the triangles // Set up the indices for the triangles
// (note, afaik with opengl we could use quads directly, but the code // (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); 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]; video::S3DVertex lap_v[4];
irr::u16 lap_ind[6]; irr::u16 lap_ind[6];
video::SColor c(128, 255, 0, 0); video::SColor lap_color(128, 255, 0, 0);
all_nodes[0]->getQuad().getVertices(lap_v, *lap_color); set3DVerticesOfGraph(0, lap_v, lap_color);
// Now scale the length (distance between vertix 0 and 3 // Now scale the length (distance between vertix 0 and 3
// and between 1 and 2) to be 'length': // and between 1 and 2) to be 'length':
Vec3 bb_min, bb_max; 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' // Length of the lap line about 3% of the 'height'
// of the track. // of the track.
const float length = (bb_max.getZ()-bb_min.getZ())*0.03f; 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)); 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, createMesh(/*show_invisible part of the track*/ false,
/*enable_transparency*/ false, /*enable_transparency*/ false,
/*track_color*/ &fill_color, /*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);
}
m_node = irr_driver->addMesh(m_mesh, "mini_map"); m_node = irr_driver->addMesh(m_mesh, "mini_map");
#ifdef DEBUG #ifdef DEBUG
@ -306,10 +276,7 @@ void GraphStructure::makeMiniMap(const core::dimension2du &dimension,
// --------------- // ---------------
scene::ICameraSceneNode *camera = irr_driver->addCameraSceneNode(); scene::ICameraSceneNode *camera = irr_driver->addCameraSceneNode();
Vec3 bb_min, bb_max; Vec3 bb_min, bb_max;
if (m_graph_type == GT_RACE) getGraphBoundingBox(&bb_min, &bb_max);
QuadSet::get()->getBoundingBox(&bb_min, &bb_max);
else
NavMesh::get()->getBoundingBox(&bb_min, &bb_max);
Vec3 center = (bb_max+bb_min)*0.5f; Vec3 center = (bb_max+bb_min)*0.5f;
float dx = bb_max.getX()-bb_min.getX(); 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) if (texture == NULL && frame_buffer == NULL)
{ {
Log::error("BattleGraph", "[makeMiniMap] WARNING: RTT does not appear to work," Log::error("Graph Structure", "[makeMiniMap] WARNING: RTT does not"
"mini-map will not be available."); "appear to work, mini-map will not be available.");
} }
*oldRttMinimap = texture; *oldRttMinimap = texture;

View File

@ -23,14 +23,13 @@
#include <dimension2d.h> #include <dimension2d.h>
#include <SColor.h> #include <SColor.h>
#include "tracks/graph_node.hpp"
#include "utils/vec3.hpp" #include "utils/vec3.hpp"
#include "utils/no_copy.hpp" #include "utils/no_copy.hpp"
namespace irr namespace irr
{ {
namespace scene { class ISceneNode; class IMesh; class IMeshBuffer; } namespace scene { class ISceneNode; class IMesh; class IMeshBuffer; }
namespace video { class ITexture; } namespace video { class ITexture; struct S3DVertex; }
} }
using namespace irr; using namespace irr;
@ -39,21 +38,13 @@ 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 class GraphStructure : public NoCopy
{ {
public:
enum GraphType {GT_RACE, GT_BATTLE};
protected: protected:
/** The type of this graph. */
GraphType m_graph_type;
void cleanupDebugMesh(); void cleanupDebugMesh();
void destroyRTT(); void destroyRTT();
@ -78,8 +69,14 @@ private:
void createMesh(bool show_invisible=true, void createMesh(bool show_invisible=true,
bool enable_transparency=false, bool enable_transparency=false,
const video::SColor *track_color=NULL, const video::SColor *track_color=NULL);
const video::SColor *lap_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: public:
GraphStructure(); GraphStructure();
@ -92,8 +89,6 @@ public:
FrameBuffer** newRttMinimap); FrameBuffer** newRttMinimap);
void mapPoint2MiniMap(const Vec3 &xyz, Vec3 *out) const; void mapPoint2MiniMap(const Vec3 &xyz, Vec3 *out) const;
virtual const unsigned int getNumNodes() const = 0; virtual const unsigned int getNumNodes() const = 0;
virtual const std::vector<GraphNode*> getAllNodes() const = 0;
virtual void setType() = 0;
}; // GraphStructure }; // GraphStructure
#endif #endif

View File

@ -57,7 +57,6 @@ QuadGraph::QuadGraph(const std::string &quad_file_name,
m_quad_filename = quad_file_name; m_quad_filename = quad_file_name;
m_quad_graph = this; m_quad_graph = this;
load(graph_file_name); load(graph_file_name);
setType();
} // QuadGraph } // QuadGraph
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -73,6 +73,24 @@ private:
const std::string &graph_file_name, const std::string &graph_file_name,
const bool reverse); const bool reverse);
~QuadGraph (); ~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: public:
static const int UNKNOWN_SECTOR; static const int UNKNOWN_SECTOR;
@ -160,12 +178,6 @@ public:
float getLapLength() const {return m_lap_length; } float getLapLength() const {return m_lap_length; }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
bool isReverse() const {return m_reverse; } 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 }; // QuadGraph
#endif #endif