RigsofRods
Soft-body Physics Simulation
RigDef_Node.h
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2013-2020 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
25 
26 #pragma once
27 
28 #include "BitFlags.h"
29 
30 #include "RigDef_Prerequisites.h"
31 
32 #include <memory>
33 #include <OgreVector3.h>
34 #include <string>
35 
36 namespace RigDef
37 {
38 
39 struct Node
40 {
44  class Id
45  {
46  public:
47  BITMASK_PROPERTY_GET (m_flags, 1, IS_VALID, IsValid);
48  BITMASK_PROPERTY_GET (m_flags, 2, IS_TYPE_NUMBERED, IsTypeNumbered);
49  BITMASK_PROPERTY_GET (m_flags, 3, IS_TYPE_NAMED, IsTypeNamed);
50 
51  // Constructors
52  Id();
53  Id(unsigned int id_num);
54  Id(std::string const & id_str);
55 
56  // Setters
57  void SetNum(unsigned int id_num);
58  void setStr(std::string const & id_str);
59 
60  // Getters
61  inline std::string const & Str() const { return m_id_str; }
62  inline unsigned int Num() const { return m_id_num; }
63 
64  // Util
65  void Invalidate();
66  std::string ToString() const;
67 
68  private:
69 
70  unsigned int m_id_num;
71  std::string m_id_str;
72  unsigned int m_flags;
73  };
74 
77  class Ref
78  {
79  public:
80  // Since fileformatversion is not known from the beginning of parsing, 2 states must be kept
81  // at the same time: IMPORT_STATE and REGULAR_STATE. The outer logic must make the right pick.
82  BITMASK_PROPERTY_GET (m_flags, 1, IMPORT_STATE_IS_VALID, GetImportState_IsValid);
83  BITMASK_PROPERTY_GET (m_flags, 2, IMPORT_STATE_MUST_CHECK_NAMED_FIRST, GetImportState_MustCheckNamedFirst);
84  BITMASK_PROPERTY_GET (m_flags, 3, IMPORT_STATE_IS_RESOLVED_NAMED, GetImportState_IsResolvedNamed);
85  BITMASK_PROPERTY_GET (m_flags, 4, IMPORT_STATE_IS_RESOLVED_NUMBERED, GetImportState_IsResolvedNumbered);
86 
87  BITMASK_PROPERTY_GET (m_flags, 5, REGULAR_STATE_IS_VALID, GetRegularState_IsValid);
88  BITMASK_PROPERTY_GET (m_flags, 6, REGULAR_STATE_IS_NAMED, GetRegularState_IsNamed);
89  BITMASK_PROPERTY_GET (m_flags, 7, REGULAR_STATE_IS_NUMBERED, GetRegularState_IsNumbered);
90 
91  Ref(std::string const & id_str, unsigned int id_num, unsigned flags, unsigned line_number_defined);
92  Ref();
93 
94  inline std::string const & Str() const { return m_id; }
95  inline unsigned int Num() const { return m_id_as_number; }
96 
97  inline bool Compare (Ref const & rhs) const { return m_id == rhs.m_id; }
98  inline bool operator==(Ref const & rhs) const { return Compare(rhs); }
99  inline bool operator!=(Ref const & rhs) const { return ! Compare(rhs); }
100 
101  inline bool IsValidAnyState() const { return GetImportState_IsValid() || GetRegularState_IsValid(); }
102  inline unsigned GetLineNumber() const { return m_line_number; }
103 
104  void Invalidate();
105  std::string ToString() const;
106 
107  private:
108  std::string m_id;
109  unsigned int m_id_as_number;
110  unsigned int m_flags;
111  unsigned int m_line_number;
112  };
113 
114  struct Range
115  {
116  Range(Node::Ref const & start, Node::Ref const & end):
117  start(start),
118  end(end)
119  {}
120 
121  Range(Node::Ref const & single):
122  start(single),
123  end(single)
124  {}
125 
126  inline bool IsRange() const { return start != end; }
127 
128  void SetSingle(Node::Ref const & ref)
129  {
130  start = ref;
131  end = ref;
132  }
133 
136  };
137 
138  Node():
139  position(Ogre::Vector3::ZERO),
140  options(0),
143  detacher_group(0) /* Global detacher group */
144  {}
145 
155  static const BitMask_t OPTION_L_LOG = BITMASK(10);
157 
159  Ogre::Vector3 position;
163  std::shared_ptr<NodeDefaults> node_defaults;
164  std::shared_ptr<DefaultMinimass> default_minimass; // override of global 'minimass'.
165  std::shared_ptr<BeamDefaults> beam_defaults; /* Needed for hook */
167 };
168 
169 } //namespace RigDef
RigDef::Node::Id::BITMASK_PROPERTY_GET
BITMASK_PROPERTY_GET(m_flags, 1, IS_VALID, IsValid)
RigDef::Node::OPTION_x_EXHAUST_POINT
static const BitMask_t OPTION_x_EXHAUST_POINT
Definition: RigDef_Node.h:148
RigDef::Node::Ref
Legacy parser resolved references on-the-fly and the condition to check named nodes was "are there an...
Definition: RigDef_Node.h:77
RigDef::Node::Range::Range
Range(Node::Ref const &single)
Definition: RigDef_Node.h:121
RigDef::Node::Node
Node()
Definition: RigDef_Node.h:138
RigDef::Node::beam_defaults
std::shared_ptr< BeamDefaults > beam_defaults
Definition: RigDef_Node.h:165
RigDef::Node::Ref::operator!=
bool operator!=(Ref const &rhs) const
Definition: RigDef_Node.h:99
RigDef::Node::Ref::Str
const std::string & Str() const
Definition: RigDef_Node.h:94
RigDef::Node::Ref::m_flags
unsigned int m_flags
Definition: RigDef_Node.h:110
RigDef::Node::Range::start
Node::Ref start
Definition: RigDef_Node.h:134
RigDef_Prerequisites.h
RigDef::Node::Ref::ToString
std::string ToString() const
Definition: RigDef_Node.cpp:103
RigDef::Node::Id::SetNum
void SetNum(unsigned int id_num)
Definition: RigDef_Node.cpp:55
RigDef::Node::Range::SetSingle
void SetSingle(Node::Ref const &ref)
Definition: RigDef_Node.h:128
RigDef::Node::Range::IsRange
bool IsRange() const
Definition: RigDef_Node.h:126
RigDef::Node::OPTION_p_NO_PARTICLES
static const BitMask_t OPTION_p_NO_PARTICLES
Definition: RigDef_Node.h:154
RigDef::Node::Ref::Invalidate
void Invalidate()
Definition: RigDef_Node.cpp:95
RigDef::Node::Ref::GetLineNumber
unsigned GetLineNumber() const
Definition: RigDef_Node.h:102
RigDef::Node::Ref::BITMASK_PROPERTY_GET
BITMASK_PROPERTY_GET(m_flags, 1, IMPORT_STATE_IS_VALID, GetImportState_IsValid)
RigDef::Node::Range
Definition: RigDef_Node.h:114
BITMASK
#define BITMASK(OFFSET)
Definition: BitFlags.h:10
RigDef::Node::Ref::IsValidAnyState
bool IsValidAnyState() const
Definition: RigDef_Node.h:101
RigDef::Node::Id::Id
Id()
Definition: RigDef_Node.cpp:34
RigDef::Node::OPTION_m_NO_MOUSE_GRAB
static const BitMask_t OPTION_m_NO_MOUSE_GRAB
Definition: RigDef_Node.h:146
RigDef::Node::position
Ogre::Vector3 position
Definition: RigDef_Node.h:159
RigDef::Node::OPTION_l_LOAD_WEIGHT
static const BitMask_t OPTION_l_LOAD_WEIGHT
Definition: RigDef_Node.h:156
RigDef::Node::_has_load_weight_override
bool _has_load_weight_override
Definition: RigDef_Node.h:162
BitFlags.h
Bit operations.
RigDef::Node::Id::m_id_str
std::string m_id_str
Definition: RigDef_Node.h:71
RigDef
Definition: RigDef_File.cpp:32
RigDef::Node::load_weight_override
float load_weight_override
Definition: RigDef_Node.h:161
RigDef::Node::Id::Str
const std::string & Str() const
Definition: RigDef_Node.h:61
RigDef::Node::Range::end
Node::Ref end
Definition: RigDef_Node.h:135
RigDef::Node::id
Id id
Definition: RigDef_Node.h:158
RigDef::Node::Id::Invalidate
void Invalidate()
Definition: RigDef_Node.cpp:72
RigDef::Node::OPTION_L_LOG
static const BitMask_t OPTION_L_LOG
Definition: RigDef_Node.h:155
RigDef::Node::detacher_group
int detacher_group
Definition: RigDef_Node.h:166
RigDef::Node::Ref::m_line_number
unsigned int m_line_number
Definition: RigDef_Node.h:111
RigDef::Node::Id::Num
unsigned int Num() const
Definition: RigDef_Node.h:62
RigDef::Node::Ref::operator==
bool operator==(Ref const &rhs) const
Definition: RigDef_Node.h:98
RigDef::Node::Ref::Ref
Ref()
Definition: RigDef_Node.cpp:88
RigDef::Node::OPTION_y_EXHAUST_DIRECTION
static const BitMask_t OPTION_y_EXHAUST_DIRECTION
Definition: RigDef_Node.h:149
RigDef::Node::OPTION_b_EXTRA_BUOYANCY
static const BitMask_t OPTION_b_EXTRA_BUOYANCY
Definition: RigDef_Node.h:153
RigDef::Node::OPTION_c_NO_GROUND_CONTACT
static const BitMask_t OPTION_c_NO_GROUND_CONTACT
Definition: RigDef_Node.h:150
RigDef::Node::Id
Abstract node ID (numbered or named) Node name is always available.
Definition: RigDef_Node.h:44
RigDef::Node::OPTION_h_HOOK_POINT
static const BitMask_t OPTION_h_HOOK_POINT
Definition: RigDef_Node.h:151
RigDef::Node::Id::m_flags
unsigned int m_flags
Definition: RigDef_Node.h:72
RigDef::Node::node_defaults
std::shared_ptr< NodeDefaults > node_defaults
Definition: RigDef_Node.h:163
RigDef::Node::options
BitMask_t options
Definition: RigDef_Node.h:160
RigDef::Node::Id::setStr
void setStr(std::string const &id_str)
Definition: RigDef_Node.cpp:63
RigDef::Node::Ref::m_id_as_number
unsigned int m_id_as_number
Definition: RigDef_Node.h:109
BitMask_t
uint32_t BitMask_t
Definition: BitFlags.h:7
RigDef::Node::Id::m_id_num
unsigned int m_id_num
Definition: RigDef_Node.h:70
Ogre
Definition: ExtinguishableFireAffector.cpp:35
RigDef::Node
Definition: RigDef_Node.h:39
RigDef::Node::OPTION_e_TERRAIN_EDIT_POINT
static const BitMask_t OPTION_e_TERRAIN_EDIT_POINT
Definition: RigDef_Node.h:152
RigDef::Node::Id::ToString
std::string ToString() const
Definition: RigDef_Node.cpp:129
RigDef::Node::Range::Range
Range(Node::Ref const &start, Node::Ref const &end)
Definition: RigDef_Node.h:116
RigDef::Node::Ref::m_id
std::string m_id
Definition: RigDef_Node.h:108
RigDef::Node::Ref::Num
unsigned int Num() const
Definition: RigDef_Node.h:95
RigDef::Node::default_minimass
std::shared_ptr< DefaultMinimass > default_minimass
Definition: RigDef_Node.h:164
RigDef::Node::OPTION_f_NO_SPARKS
static const BitMask_t OPTION_f_NO_SPARKS
Definition: RigDef_Node.h:147
RigDef::Node::Ref::Compare
bool Compare(Ref const &rhs) const
Definition: RigDef_Node.h:97