Rigs of Rods 2023.09
Soft-body Physics Simulation
Loading...
Searching...
No Matches
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
31
32#include <memory>
33#include <OgreVector3.h>
34#include <string>
35
36namespace RigDef
37{
38
39struct 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
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
Bit operations.
#define BITMASK(OFFSET)
Definition BitFlags.h:10
uint32_t BitMask_t
Definition BitFlags.h:7
Abstract node ID (numbered or named) Node name is always available.
Definition RigDef_Node.h:45
void SetNum(unsigned int id_num)
std::string m_id_str
Definition RigDef_Node.h:71
void setStr(std::string const &id_str)
BITMASK_PROPERTY_GET(m_flags, 2, IS_TYPE_NUMBERED, IsTypeNumbered)
BITMASK_PROPERTY_GET(m_flags, 1, IS_VALID, IsValid)
unsigned int m_id_num
Definition RigDef_Node.h:70
BITMASK_PROPERTY_GET(m_flags, 3, IS_TYPE_NAMED, IsTypeNamed)
unsigned int Num() const
Definition RigDef_Node.h:62
std::string ToString() const
unsigned int m_flags
Definition RigDef_Node.h:72
std::string const & Str() const
Definition RigDef_Node.h:61
Legacy parser resolved references on-the-fly and the condition to check named nodes was "are there an...
Definition RigDef_Node.h:78
bool operator==(Ref const &rhs) const
Definition RigDef_Node.h:98
BITMASK_PROPERTY_GET(m_flags, 2, IMPORT_STATE_MUST_CHECK_NAMED_FIRST, GetImportState_MustCheckNamedFirst)
bool IsValidAnyState() const
unsigned int Num() const
Definition RigDef_Node.h:95
unsigned int m_flags
bool Compare(Ref const &rhs) const
Definition RigDef_Node.h:97
BITMASK_PROPERTY_GET(m_flags, 1, IMPORT_STATE_IS_VALID, GetImportState_IsValid)
unsigned int m_line_number
std::string m_id
std::string ToString() const
BITMASK_PROPERTY_GET(m_flags, 3, IMPORT_STATE_IS_RESOLVED_NAMED, GetImportState_IsResolvedNamed)
unsigned int m_id_as_number
BITMASK_PROPERTY_GET(m_flags, 6, REGULAR_STATE_IS_NAMED, GetRegularState_IsNamed)
bool operator!=(Ref const &rhs) const
Definition RigDef_Node.h:99
BITMASK_PROPERTY_GET(m_flags, 4, IMPORT_STATE_IS_RESOLVED_NUMBERED, GetImportState_IsResolvedNumbered)
unsigned GetLineNumber() const
std::string const & Str() const
Definition RigDef_Node.h:94
BITMASK_PROPERTY_GET(m_flags, 5, REGULAR_STATE_IS_VALID, GetRegularState_IsValid)
BITMASK_PROPERTY_GET(m_flags, 7, REGULAR_STATE_IS_NUMBERED, GetRegularState_IsNumbered)
Range(Node::Ref const &single)
void SetSingle(Node::Ref const &ref)
Range(Node::Ref const &start, Node::Ref const &end)
bool IsRange() const
std::shared_ptr< BeamDefaults > beam_defaults
static const BitMask_t OPTION_c_NO_GROUND_CONTACT
static const BitMask_t OPTION_p_NO_PARTICLES
std::shared_ptr< DefaultMinimass > default_minimass
bool _has_load_weight_override
static const BitMask_t OPTION_f_NO_SPARKS
static const BitMask_t OPTION_b_EXTRA_BUOYANCY
BitMask_t options
static const BitMask_t OPTION_L_LOG
static const BitMask_t OPTION_x_EXHAUST_POINT
static const BitMask_t OPTION_e_TERRAIN_EDIT_POINT
std::shared_ptr< NodeDefaults > node_defaults
float load_weight_override
static const BitMask_t OPTION_h_HOOK_POINT
Ogre::Vector3 position
static const BitMask_t OPTION_m_NO_MOUSE_GRAB
static const BitMask_t OPTION_l_LOAD_WEIGHT
static const BitMask_t OPTION_y_EXHAUST_DIRECTION