Pioneer
Node.h
Go to the documentation of this file.
1 // Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3 
4 #ifndef _NODE_H
5 #define _NODE_H
6 /*
7  * Generic node for the model scenegraph
8  */
9 #include "RefCounted.h"
10 #include "graphics/Material.h"
11 #include "libs.h"
12 
13 namespace Graphics {
14  class Renderer;
15 }
16 
17 namespace Serializer {
18  class Reader;
19  class Writer;
20 } // namespace Serializer
21 
22 namespace SceneGraph {
23 
24  class BaseLoader;
25  class NodeVisitor;
26  class NodeCopyCache;
27  class Model;
28 
29  //Node traversal mask - for other
30  //purposes, use NodeFlags
31  enum NodeMask {
32  NODE_SOLID = 0x1,
34  MASK_IGNORE = 0x4
35  };
36 
37  //misc flags to identify features
38  enum NodeFlags {
39  NODE_TAG = 0x1,
40  NODE_DECAL = 0x2
41  };
42 
43  //Small structure used internally to pass rendering data
44  struct RenderData {
45  float linthrust[3]; // 1.0 to -1.0
46  float angthrust[3]; // 1.0 to -1.0
48 
49  float boundingRadius; //updated by model and passed to submodels
50  unsigned int nodemask;
51 
53  linthrust(),
54  angthrust(),
55  boundingRadius(0.f),
56  nodemask(NODE_SOLID) //draw solids
57  {
58  }
59  };
60 
61  //Collection of stuff nodes need for serialization -
62  //makes maintaining function signatures easier
63  struct NodeDatabase {
66  // Graphics::Renderer *renderer;
68  std::vector<std::pair<std::string, RefCountedPtr<Graphics::Material>>> *materials;
70  };
71 
72  class Node : public RefCounted {
73  public:
75  Node(Graphics::Renderer *r, unsigned int nodemask);
76  Node(const Node &, NodeCopyCache *);
77  virtual Node *Clone(NodeCopyCache *) = 0; //implement clone to return shallow or deep copy
78  virtual const char *GetTypeName() const { return "Node"; }
79  virtual void Save(NodeDatabase &);
80 
81  virtual void Accept(NodeVisitor &v);
82  virtual void Traverse(NodeVisitor &v);
83  virtual void Render(const matrix4x4f &trans, const RenderData *rd) {}
84  virtual void Render(const std::vector<matrix4x4f> &trans, const RenderData *rd) {}
85  void DrawAxes();
86  void SetName(const std::string &name) { m_name = name; }
87  const std::string &GetName() const { return m_name; }
88 
89  virtual Node *FindNode(const std::string &);
90 
91  unsigned int GetNodeMask() const { return m_nodeMask; }
92  void SetNodeMask(unsigned int m) { m_nodeMask = m; }
93 
94  unsigned int GetNodeFlags() const { return m_nodeFlags; }
95  void SetNodeFlags(unsigned int m) { m_nodeFlags = m; }
96 
98 
99  protected:
100  //can only to be deleted using DecRefCount
101  virtual ~Node();
102  std::string m_name;
103  unsigned int m_nodeMask;
104  unsigned int m_nodeFlags;
106  };
107 
108 } // namespace SceneGraph
109 
110 #endif
Definition: Renderer.h:44
Definition: RefCounted.h:11
Definition: BaseLoader.h:18
Definition: Model.h:88
Definition: NodeCopyCache.h:14
Definition: NodeVisitor.h:26
Definition: Node.h:72
virtual void Save(NodeDatabase &)
Definition: Node.cpp:63
virtual void Accept(NodeVisitor &v)
Definition: Node.cpp:40
unsigned int GetNodeFlags() const
Definition: Node.h:94
virtual const char * GetTypeName() const
Definition: Node.h:78
unsigned int GetNodeMask() const
Definition: Node.h:91
Graphics::Renderer * m_renderer
Definition: Node.h:105
unsigned int m_nodeMask
Definition: Node.h:103
std::string m_name
Definition: Node.h:102
virtual Node * FindNode(const std::string &)
Definition: Node.cpp:49
unsigned int m_nodeFlags
Definition: Node.h:104
Node(Graphics::Renderer *r)
Definition: Node.cpp:12
virtual ~Node()
Definition: Node.cpp:36
virtual Node * Clone(NodeCopyCache *)=0
virtual void Render(const matrix4x4f &trans, const RenderData *rd)
Definition: Node.h:83
void SetNodeMask(unsigned int m)
Definition: Node.h:92
void SetNodeFlags(unsigned int m)
Definition: Node.h:95
Graphics::Renderer * GetRenderer() const
Definition: Node.h:97
void SetName(const std::string &name)
Definition: Node.h:86
virtual void Traverse(NodeVisitor &v)
Definition: Node.cpp:45
void DrawAxes()
Definition: Node.cpp:57
virtual void Render(const std::vector< matrix4x4f > &trans, const RenderData *rd)
Definition: Node.h:84
const std::string & GetName() const
Definition: Node.h:87
Definition: Serializer.h:110
Definition: Serializer.h:35
Definition: Background.h:14
Definition: CityOnPlanet.h:31
NodeMask
Definition: Node.h:31
@ NODE_TRANSPARENT
Definition: Node.h:33
@ NODE_SOLID
Definition: Node.h:32
@ MASK_IGNORE
Definition: Node.h:34
NodeFlags
Definition: Node.h:38
@ NODE_DECAL
Definition: Node.h:40
@ NODE_TAG
Definition: Node.h:39
Definition: GeomTree.h:9
Definition: Color.h:66
Definition: Node.h:63
Serializer::Reader * rd
Definition: Node.h:65
std::vector< std::pair< std::string, RefCountedPtr< Graphics::Material > > > * materials
Definition: Node.h:68
Serializer::Writer * wr
Definition: Node.h:64
Model * model
Definition: Node.h:67
BaseLoader * loader
Definition: Node.h:69
Definition: Node.h:44
RenderData()
Definition: Node.h:52
unsigned int nodemask
Definition: Node.h:50
Color customColor
Definition: Node.h:47
float boundingRadius
Definition: Node.h:49
float linthrust[3]
Definition: Node.h:45
float angthrust[3]
Definition: Node.h:46