Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
RigDef_SequentialImporter.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
29#include "RigDef_File.h"
30
31#include <memory>
32#include <vector>
33
34namespace RigDef
35{
36
37/*
38 @brief Legacy rig-file importer.
39
40 RoR's physics work on this principle:
41 1. There is a node array, pre-allocated to some 5000 items.
42 2. As .truck file is parsed, defined nodes are reserved in this array and accessible through their
43 index. Alternatively, nodes can be defined "named"; in that case, a <name->node index> translation
44 is performed and node can be addressed by both.
45 3. Nodes are also generated by some sections (cinecam, wheels...). These can also be adressed by index.
46
47 Traditionally, the order of nodes in nodes-array was determined by order of definitions in .truck file.
48 This approach had downsides:
49 1. Nodes could be adressed before they were defined
50 This could be detected, but for compatibility reasons, parser emitted a warning only.
51 2. Non-existent nodes could be adressed.
52 Due to pre-allocated nature of node-array, this passed unnoticed.
53 It could be explicitly detected, but parsers weren't equipped to do so in every case.
54 3. Very hard to determine index of some nodes.
55 Creating rig was traditionally a manual process, and not every section supported named nodes (i.e. axles)
56 Knowing index of node was necessary, but with named/generated nodes, it was hard to tell.
57 3. Unfeasible for visual editor with mouse controls.
58 This approach would, by nature, re-order definitions and make direct index-adressing impossible.
59
60 To ease code maintenance, enable bullet-proof checking and prepare grounds for visual rig editor,
61 a new approach was applied: Truckfile would be loaded to RigDef::Document structure in it's entirety,
62 and then parsed in pre-determined order.
63 Order (section name[number of nodes generated per line]):
64 1. nodes[1]
65 2. nodes2[1]
66 3. cinecam[1]
67 4. wheels[num_rays*2]
68 5. wheels2[num_rays*4]
69 6. meshwheels[num_rays*2]
70 7. meshwheels2[num_rays*2]
71 8. flexbodywheels[num_rays*4]
72
73 Naturally, older truckfiles which rely on user-determined order of definitions needed to be converted
74 with index-references updated to match new node-array positions. This class does exactly that.
75
76*/
78{
79public:
104
105 struct Message // TODO: remove, use console API directly
106 {
116 };
117
118 void Init(bool enabled);
119
120 void Disable()
121 {
122 m_enabled = false;
123 m_all_nodes.clear();
124 }
125
126 inline bool IsEnabled() const { return m_enabled; }
127
128 bool AddNumberedNode(unsigned int number);
129
130 bool AddNamedNode(std::string const & name);
131
133
134 void GenerateNodesForWheel(Keyword generated_from, int num_rays, bool has_rigidity_node);
135
138
139 std::string GetNodeStatistics();
140 std::string IterateAndPrintAllNodes();
141
142private:
143
144 void ProcessModule(std::shared_ptr<RigDef::Document::Module> module);
145
146 Node::Ref ResolveNode(Node::Ref const & noderef_in);
147 Node::Ref ResolveNodeByIndex(unsigned int index, unsigned int def_line_number);
149 void ResolveNodeRanges(std::vector<Node::Range>& ranges);
150 void ResolveFlexbodyForset(std::vector<Node::Range>& ranges, std::vector<Node::Ref>& out_nodes);
151
152 void AddMessage(Message::Type msg_type, std::string text);
153
154 std::vector<NodeMapEntry> m_all_nodes;
155 std::map<std::string, NodeMapEntry> m_named_nodes;
165
166 // Logging
170 std::shared_ptr<Document::Module> m_current_module;
171};
172
173} // namespace RigDef
Data structures representing 'truck' file format, see https://docs.rigsofrods.org/vehicle-creation/fi...
Abstract node ID (numbered or named) Node name is always available.
Definition RigDef_Node.h:45
Legacy parser resolved references on-the-fly and the condition to check named nodes was "are there an...
Definition RigDef_Node.h:78
std::map< std::string, NodeMapEntry > m_named_nodes
bool AddNamedNode(std::string const &name)
void AddGeneratedNode(Keyword generated_from, NodeMapEntry::OriginDetail detail=NodeMapEntry::DETAIL_UNDEFINED)
void Process(RigDef::DocumentPtr def)
Traverse whole rig definition and resolve all node references.
void ResolveNodeRanges(std::vector< Node::Range > &ranges)
void ResolveFlexbodyForset(std::vector< Node::Range > &ranges, std::vector< Node::Ref > &out_nodes)
unsigned GetNodeArrayOffset(Keyword keyword)
void GenerateNodesForWheel(Keyword generated_from, int num_rays, bool has_rigidity_node)
Node::Ref ResolveNode(Node::Ref const &noderef_in)
std::vector< NodeMapEntry > m_all_nodes
void AddMessage(Message::Type msg_type, std::string text)
void ProcessModule(std::shared_ptr< RigDef::Document::Module > module)
Node::Ref ResolveNodeByIndex(unsigned int index, unsigned int def_line_number)
std::shared_ptr< Document::Module > m_current_module
bool AddNumberedNode(unsigned int number)
std::shared_ptr< Document > DocumentPtr
NodeMapEntry(Keyword keyword, Node::Id id, unsigned node_sub_index, OriginDetail detail=NodeMapEntry::DETAIL_UNDEFINED)
unsigned node_sub_index
RigDef::Keyword origin_keyword
Node::Id node_id
OriginDetail
@ DETAIL_WHEEL_RIM_B
@ DETAIL_WHEEL_TYRE_A
@ DETAIL_WHEEL_TYRE_B
@ DETAIL_WHEEL_RIM_A
@ DETAIL_UNDEFINED
OriginDetail origin_detail