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_Parser.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-2021 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
26
27#pragma once
28
29#include "Console.h"
31#include "RigDef_File.h"
33
34#include <memory>
35#include <string>
36#include <regex>
37
38namespace RigDef
39{
40
56class Parser
57{
58
59public:
60
61 static const int LINE_BUFFER_LENGTH = 2000;
62 static const int LINE_MAX_ARGS = 100;
63
64 struct Token
65 {
66 const char* start;
67 int length;
68 };
69
70 Parser();
71
72 void Prepare();
73 void Finalize();
74 void ProcessOgreStream(Ogre::DataStream* stream, Ogre::String resource_group);
75 void ProcessRawLine(const char* line);
76
81
83
84 // Common for truckfiles and addonparts:
85 static void ProcessForsetLine(RigDef::Flexbody& def, const std::string& line, int line_number = -1);
86 static Keyword IdentifyKeyword(const std::string& line);
87 static SpecialProp IdentifySpecialProp(const std::string& str);
88
89private:
90
91// --------------------------------------------------------------------------
92// Directive parsers
93// --------------------------------------------------------------------------
94
113
114// --------------------------------------------------------------------------
115// Section parsers
116// --------------------------------------------------------------------------
117
118 void ParseAirbrakes();
119 void ParseAnimator();
120 void ParseAntiLockBrakes();
121 void ParseAssetpacks();
122 void ParseAuthor();
123 void ParseAxles();
124 void ParseBeams();
125 void ParseBrakes();
126 void ParseCab();
127 void ParseCameras();
128 void ParseCameraRails();
129 void ParseCinecam();
130 void ParseCollisionBox();
132 void ParseContacter();
133 void ParseCruiseControl();
135 void ParseDescription();
136 void ParseEngine();
137 void ParseEngoption();
138 void ParseEngturbo();
139 void ParseExhaust();
140 void ParseExtCamera();
142 void ParseFileinfo();
143 void ParseFixes();
144 void ParseFlaresUnified();
145 void ParseFlares3();
147 void ParseFlexbody();
148 void ParseFlexBodyWheel();
149 void ParseFusedrag();
150 void ParseGlobals();
151 void ParseGuid();
152 void ParseGuiSettings();
153 void ParseHelp();
154 void ParseHook();
155 void ParseHydros();
156 void ParseInterAxles();
157 void ParseLockgroups();
160 void ParseMeshWheel();
161 void ParseMeshWheel2();
162 void ParseMinimass();
163 void ParseNodesUnified();
164 void ParseParticles();
165 void ParsePistonprops();
166 void ParseProps();
167 void ParseRailGroups();
168 void ParseRopables();
169 void ParseRopes();
171 void ParseScrewprops();
172 void ParseScripts();
175 void ParseShock();
176 void ParseShock2();
177 void ParseShock3();
178 void ParseSlidenodes();
179 void ParseSoundsources();
180 void ParseSoundsources2();
181 void ParseSpeedLimiter();
183 void ParseTexcoords();
184 void ParseTies();
185 void ParseTorqueCurve();
187 void ParseTransferCase();
188 void ParseTriggers();
189 void ParseTurbojets();
191 void ParseVideoCamera();
192 void ParseWheelDetachers();
193 void ParseWheel();
194 void ParseWheel2();
195 void ParseWing();
196
197// --------------------------------------------------------------------------
198// Utilities
199// --------------------------------------------------------------------------
200
201 void ProcessCurrentLine();
203 bool CheckNumArguments(int num_required_args);
206 void FlushPendingDocComment(size_t vectorlen, RigDef::Keyword keyword);
207
208 std::string GetArgStr (int index);
209 int GetArgInt (int index);
210 unsigned GetArgUint (int index);
211 long GetArgLong (int index);
212 float GetArgFloat (int index);
213 char GetArgChar (int index);
214 bool GetArgBool (int index);
217 Node::Ref GetArgNodeRef (int index);
218 Node::Ref GetArgRigidityNode (int index);
219 Node::Ref GetArgNullableNode (int index);
224 std::string GetArgManagedTex (int index);
226 BitMask_t GetArgCabOptions (int index);
228 BitMask_t GetArgBeamOptions (int index);
229 BitMask_t GetArgHydroOptions (int index);
230 BitMask_t GetArgShockOptions (int index);
233 BitMask_t GetArgNodeOptions (int index);
234 int GetArgDashboardInputDataType(int index);
235 EngineType GetArgEngineType (int index);
238
239 float ParseArgFloat (const char* str);
240 int ParseArgInt (const char* str);
241 unsigned ParseArgUint (const char* str);
242 unsigned ParseArgUint (const std::string& s);
243 float ParseArgFloat (const std::string& s);
244
246 void LogMessage(RoR::Console::MessageType type, std::string const& msg);
247
248 static void _TrimTrailingComments(std::string const & line_in, std::string & line_out);
249
250 Node::Ref _ParseNodeRef(std::string const & node_id_str);
251 void _ParseDifferentialTypes(DifferentialTypeVec& diff_types, std::string const& options_str);
252 void _ParseBaseMeshWheel(BaseMeshWheel& mesh_wheel);
253
254 void ParseOptionalInertia(Inertia& inertia, int index);
255
256// --------------------------------------------------------------------------
257
258 // RoR defaults
259
260 std::shared_ptr<Inertia> m_ror_default_inertia;
261 std::shared_ptr<NodeDefaults> m_ror_node_defaults;
262
263 // Data from user directives
264 // Each affected section-struct has a shared_ptr to it's respective defaults
265 std::shared_ptr<Inertia> m_user_default_inertia;
266 std::shared_ptr<BeamDefaults> m_user_beam_defaults;
267 std::shared_ptr<NodeDefaults> m_user_node_defaults;
268 std::shared_ptr<DefaultMinimass> m_set_default_minimass;
271
272 // Parser state
273 std::shared_ptr<Document::Module> m_root_module;
274 std::shared_ptr<Document::Module> m_current_module;
275
276 unsigned int m_current_line_number = 0;
279 int m_num_args = 0;
283 std::shared_ptr<Submesh> m_current_submesh;
284 std::shared_ptr<CameraRail> m_current_camera_rail;
286
288
289 Ogre::String m_filename; // Logging
290 Ogre::String m_resource_group;
291
293};
294
295} // namespace RigDef
uint32_t BitMask_t
Definition BitFlags.h:7
Data structures representing 'truck' file format, see https://docs.rigsofrods.org/vehicle-creation/fi...
Legacy parser resolved references on-the-fly and the condition to check named nodes was "are there an...
Definition RigDef_Node.h:78
Checks the rig-def file syntax and pulls data to File object.
char m_current_line[LINE_BUFFER_LENGTH]
int ParseArgInt(const char *str)
bool GetArgBool(int index)
BitMask_t GetArgBeamOptions(int index)
RigDef::DocumentPtr m_definition
std::shared_ptr< DefaultMinimass > m_set_default_minimass
void ParseTractionControl()
Ogre::String m_resource_group
SequentialImporter * GetSequentialImporter()
void ParseDirectiveSetDefaultMinimass()
std::shared_ptr< NodeDefaults > m_ror_node_defaults
void ParseMaterialFlareBindings()
BitMask_t GetArgShock3Options(int index)
static const int LINE_MAX_ARGS
WingControlSurface GetArgWingSurface(int index)
std::shared_ptr< Inertia > m_ror_default_inertia
RoR::VideoCamRole GetArgVideoCamRole(int index)
Node::Ref GetArgRigidityNode(int index)
RoR::WheelBraking GetArgBraking(int index)
Node::Ref _ParseNodeRef(std::string const &node_id_str)
void ParseCustomDashboardInputs()
void ParseDirectiveSetInertiaDefaults()
BitMask_t GetArgShockOptions(int index)
Token m_args[LINE_MAX_ARGS]
Tokens of current line.
std::shared_ptr< Document::Module > m_root_module
std::shared_ptr< Submesh > m_current_submesh
Parser state.
void ParseDirectiveForvert()
void ParseDirectivePropCameraMode()
Node::Ref GetArgNodeRef(int index)
MinimassOption GetArgMinimassOption(int index)
void BeginBlock(RigDef::Keyword keyword)
static const int LINE_BUFFER_LENGTH
void ParseDirectiveSetManagedMaterialsOptions()
RoR::FlareType GetArgFlareType(int index)
bool m_any_named_node_defined
Parser state.
static void ProcessForsetLine(RigDef::Flexbody &def, const std::string &line, int line_number=-1)
std::string GetArgStr(int index)
int GetArgInt(int index)
int GetArgDashboardInputDataType(int index)
Keyword m_log_keyword
void ParseDirectiveSetBeamDefaultsScale()
unsigned int m_current_line_number
unsigned GetArgUint(int index)
void ParseDirectiveDefaultSkin()
RoR::WheelSide GetArgWheelSide(int index)
ManagedMaterialType GetArgManagedMatType(int index)
void ParseDirectiveSubmesh()
ManagedMaterialsOptions m_current_managed_material_options
void ParseDirectiveBackmesh()
EngineType GetArgEngineType(int index)
BitMask_t GetArgNodeOptions(int index)
static SpecialProp IdentifySpecialProp(const std::string &str)
long GetArgLong(int index)
bool CheckNumArguments(int num_required_args)
void ParseSetSkeletonSettings()
void _ParseBaseMeshWheel(BaseMeshWheel &mesh_wheel)
void ProcessGlobalDirective(Keyword keyword)
Directives that should only appear in root module.
std::string GetArgManagedTex(int index)
float ParseArgFloat(const char *str)
std::shared_ptr< Document::Module > m_current_module
void LogMessage(RoR::Console::MessageType type, std::string const &msg)
Adds a message to console.
void ProcessCurrentLine()
std::shared_ptr< CameraRail > m_current_camera_rail
Parser state.
std::shared_ptr< BeamDefaults > m_user_beam_defaults
void ParseDirectiveAddAnimation()
void ParseFileFormatVersion()
void ParseDirectiveSectionConfig()
Ogre::String m_filename
RoR::WheelPropulsion GetArgPropulsion(int index)
SequentialImporter m_sequential_importer
BitMask_t GetArgCabOptions(int index)
Keyword m_current_block
static Keyword IdentifyKeyword(const std::string &line)
std::shared_ptr< NodeDefaults > m_user_node_defaults
RigDef::DocumentPtr GetFile()
int m_num_args
Number of tokens on current line.
void ParseFlaregroupsNoImport()
std::shared_ptr< Inertia > m_user_default_inertia
void ParseDirectiveFlexbodyCameraMode()
static void _TrimTrailingComments(std::string const &line_in, std::string &line_out)
void ParseDirectiveSetBeamDefaults()
void ParseOptionalInertia(Inertia &inertia, int index)
void ParseSubmeshGroundModel()
RoR::ExtCameraMode GetArgExtCameraMode(int index)
void ProcessRawLine(const char *line)
char GetArgChar(int index)
BitMask_t GetArgTriggerOptions(int index)
void ParseSetCollisionRange()
DocComment m_pending_doc_comment
To be linked with the following element.
unsigned ParseArgUint(const char *str)
BitMask_t GetArgHydroOptions(int index)
BitMask_t GetArgShock2Options(int index)
void ProcessChangeModuleLine(Keyword keyword)
void ParseTurbopropsUnified()
float GetArgFloat(int index)
void ProcessOgreStream(Ogre::DataStream *stream, Ogre::String resource_group)
void ParseDirectiveForset()
void FlushPendingDocComment(size_t vectorlen, RigDef::Keyword keyword)
void ParseDirectiveSetNodeDefaults()
void ParseDirectiveDetacherGroup()
void _ParseDifferentialTypes(DifferentialTypeVec &diff_types, std::string const &options_str)
Node::Ref GetArgNullableNode(int index)
ManagedMaterialType
Definition RigDef_File.h:79
WingControlSurface
std::vector< DifferentialType > DifferentialTypeVec
std::shared_ptr< Document > DocumentPtr
WheelSide
Used by rig-def/addonpart/tuneup formats to specify wheel rim mesh orientation.
VideoCamRole
ExtCameraMode
WheelPropulsion
WheelBraking
< Represents a comment (line starting with ';' or '//') that can be anywhere in the file.