SuperTuxKart
graph.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2016 SuperTuxKart Team
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_GRAPH_HPP
20 #define HEADER_GRAPH_HPP
21 
22 #include "utils/no_copy.hpp"
23 #include "utils/vec3.hpp"
24 
25 #include <dimension2d.h>
26 
27 #include <memory>
28 #include <string>
29 #include <vector>
30 
31 namespace irr
32 {
33  namespace scene { class ISceneNode; class IMesh; class IMeshBuffer; }
34  namespace video { class ITexture; struct S3DVertex; class SColor; }
35 }
36 
37 using namespace irr;
38 
39 class Quad;
40 class RenderTarget;
41 
52 class Graph : public NoCopy
53 {
54 protected:
55  static Graph* m_graph;
56 
57  std::vector<Quad*> m_all_nodes;
58 
59  // ------------------------------------------------------------------------
62  void createQuad(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2,
63  const Vec3 &p3, unsigned int node_index,
64  bool invisible, bool ai_ignore, bool is_arena,
65  bool ignore);
66  // ------------------------------------------------------------------------
68  void loadBoundingBoxNodes();
69 
70 private:
73  Vec3 m_bb_max;
74 
76  int m_bb_nodes[4];
77 
79  scene::ISceneNode *m_node;
80 
82  scene::IMesh *m_mesh;
83 
85  scene::IMeshBuffer *m_mesh_buffer;
86 
88  float m_scaling;
89 
91  std::unique_ptr<RenderTarget> m_render_target;
92 
93  // ------------------------------------------------------------------------
94  void createMesh(bool show_invisible=true,
95  bool enable_transparency=false,
96  const video::SColor *track_color=NULL,
97  bool invert_x_z = false);
98  // ------------------------------------------------------------------------
99  void createMeshSP(bool show_invisible=true,
100  bool enable_transparency=false,
101  const video::SColor *track_color=NULL,
102  bool invert_x_z = false);
103  // ------------------------------------------------------------------------
104  void cleanupDebugMesh();
105  // ------------------------------------------------------------------------
106  virtual bool hasLapLine() const = 0;
107  // ------------------------------------------------------------------------
108  virtual void differentNodeColor(int n, video::SColor* c) const = 0;
109 
110 public:
111  static const int UNKNOWN_SECTOR;
112  // For 2d Quad
113  static const float MIN_HEIGHT_TESTING;
114  static const float MAX_HEIGHT_TESTING;
115  // ------------------------------------------------------------------------
119  static Graph* get() { return m_graph; }
120  // ------------------------------------------------------------------------
122  static void setGraph(Graph* graph)
123  {
124  assert(m_graph == NULL);
125  m_graph = graph;
126  } // setGraph
127  // ------------------------------------------------------------------------
131  static void destroy()
132  {
133  if (m_graph)
134  {
135  delete m_graph;
136  m_graph = NULL;
137  }
138  } // destroy
139  // ------------------------------------------------------------------------
140  Graph();
141  // ------------------------------------------------------------------------
142  virtual ~Graph();
143  // ------------------------------------------------------------------------
144  void createDebugMesh();
145  // ------------------------------------------------------------------------
146  RenderTarget* makeMiniMap(const core::dimension2du &dimension,
147  const std::string &name,
148  const video::SColor &fill_color,
149  bool invert_x_z);
150  // ------------------------------------------------------------------------
151  void mapPoint2MiniMap(const Vec3 &xyz, Vec3 *out) const;
152  // ------------------------------------------------------------------------
153  Quad* getQuad(unsigned int i) const
154  {
155  assert(i < m_all_nodes.size());
156  return m_all_nodes[i];
157  }
158  // ------------------------------------------------------------------------
159  unsigned int getNumNodes() const { return (unsigned int)m_all_nodes.size(); }
160  // ------------------------------------------------------------------------
161  void findRoadSector(const Vec3& XYZ, int *sector,
162  std::vector<int> *all_sectors = NULL,
163  bool ignore_vertical = false) const;
164  // ------------------------------------------------------------------------
165  int findOutOfRoadSector(const Vec3& xyz,
166  const int curr_sector = UNKNOWN_SECTOR,
167  std::vector<int> *all_sectors = NULL,
168  bool ignore_vertical = false) const;
169  // ------------------------------------------------------------------------
170  const Vec3& getBBMin() const { return m_bb_min; }
171  // ------------------------------------------------------------------------
172  const Vec3& getBBMax() const { return m_bb_max; }
173  // ------------------------------------------------------------------------
174  const int* getBBNodes() const { return m_bb_nodes; }
175 
176 }; // Graph
177 
178 #endif
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:34
scene::ISceneNode * m_node
The node of the graph mesh.
Definition: graph.hpp:79
This class stores a graph of quads.
Definition: graph.hpp:52
float m_scaling
Scaling for mini map.
Definition: graph.hpp:88
Vec3 m_bb_min
The 2d bounding box, used for hashing.
Definition: graph.hpp:72
static Graph * get()
Returns the one instance of this object.
Definition: graph.hpp:119
Definition: quad.hpp:37
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:25
static void setGraph(Graph *graph)
Set the graph (either drive or arena graph for now).
Definition: graph.hpp:122
scene::IMeshBuffer * m_mesh_buffer
The actual mesh buffer storing the graph.
Definition: graph.hpp:85
Definition: render_target.hpp:28
static void destroy()
Cleans up the graph.
Definition: graph.hpp:131
std::unique_ptr< RenderTarget > m_render_target
The render target used for drawing the minimap.
Definition: graph.hpp:91
scene::IMesh * m_mesh
The mesh of the graph mesh.
Definition: graph.hpp:82