37 #include <OgreException.h>
38 #include <OgreString.h>
39 #include <OgreStringVector.h>
40 #include <OgreStringConverter.h>
51 return (c ==
' ') || (c ==
'\t');
56 return IsWhitespace(c) || (c ==
':') || (c ==
'|') || (c ==
',');
61 if (s1.size() != s2.size()) {
return false; }
62 for (
size_t i = 0; i < s1.size(); ++i)
64 if (tolower(s1[i]) != tolower(s2[i])) {
return false; }
72 m_ror_default_inertia = std::shared_ptr<Inertia>(
new Inertia);
73 m_ror_node_defaults = std::shared_ptr<NodeDefaults>(
new NodeDefaults);
76 void Parser::ProcessCurrentLine()
79 if ((m_current_line[0] ==
';') || (m_current_line[0] ==
'/'))
85 if (m_definition->name ==
"" && m_current_line !=
"")
87 m_definition->name = m_current_line;
92 if (m_current_block != Keyword::COMMENT &&
93 m_current_block != Keyword::DESCRIPTION)
95 this->TokenizeCurrentLine();
101 char c = tolower(m_current_line[0]);
102 if (c >=
'a' && c <=
'z')
104 keyword = Parser::IdentifyKeyword(m_current_line);
110 case Keyword::INVALID:
114 case Keyword::DISABLEDEFAULTSOUNDS:
115 case Keyword::ENABLE_ADVANCED_DEFORMATION:
116 case Keyword::FORWARDCOMMANDS:
117 case Keyword::HIDEINCHOOSER:
118 case Keyword::IMPORTCOMMANDS:
119 case Keyword::LOCKGROUP_DEFAULT_NOLOCK:
120 case Keyword::RESCUER:
121 case Keyword::ROLLON:
122 case Keyword::SLIDENODE_CONNECT_INSTANTLY:
123 this->ProcessGlobalDirective(
keyword);
125 case Keyword::END_SECTION:
126 this->ProcessChangeModuleLine(
keyword);
130 case Keyword::ADD_ANIMATION:
131 this->ParseDirectiveAddAnimation();
133 case Keyword::ANTILOCKBRAKES:
134 this->ParseAntiLockBrakes();
136 case Keyword::AUTHOR:
139 case Keyword::BACKMESH:
140 this->ParseDirectiveBackmesh();
142 case Keyword::CRUISECONTROL:
143 this->ParseCruiseControl();
145 case Keyword::DEFAULT_SKIN:
146 this->ParseDirectiveDefaultSkin();
148 case Keyword::DETACHER_GROUP:
149 this->ParseDirectiveDetacherGroup();
151 case Keyword::EXTCAMERA:
152 this->ParseExtCamera();
154 case Keyword::FILEFORMATVERSION:
155 this->ParseFileFormatVersion();
157 case Keyword::FILEINFO:
158 this->ParseFileinfo();
160 case Keyword::FLEXBODY_CAMERA_MODE:
161 this->ParseDirectiveFlexbodyCameraMode();
163 case Keyword::FORSET:
164 this->ParseDirectiveForset();
169 case Keyword::PROP_CAMERA_MODE:
170 this->ParseDirectivePropCameraMode();
172 case Keyword::SECTION:
173 this->ParseDirectiveSection();
175 case Keyword::SET_BEAM_DEFAULTS:
176 this->ParseDirectiveSetBeamDefaults();
178 case Keyword::SET_BEAM_DEFAULTS_SCALE:
179 this->ParseDirectiveSetBeamDefaultsScale();
181 case Keyword::SET_COLLISION_RANGE:
182 this->ParseSetCollisionRange();
184 case Keyword::SET_DEFAULT_MINIMASS:
185 this->ParseDirectiveSetDefaultMinimass();
187 case Keyword::SET_INERTIA_DEFAULTS:
188 this->ParseDirectiveSetInertiaDefaults();
190 case Keyword::SET_MANAGEDMATERIALS_OPTIONS:
191 this->ParseDirectiveSetManagedMaterialsOptions();
193 case Keyword::SET_NODE_DEFAULTS:
194 this->ParseDirectiveSetNodeDefaults();
196 case Keyword::SET_SKELETON_SETTINGS:
197 this->ParseSetSkeletonSettings();
199 case Keyword::SPEEDLIMITER:
200 this->ParseSpeedLimiter();
202 case Keyword::SUBMESH:
203 this->ParseDirectiveSubmesh();
205 case Keyword::SUBMESH_GROUNDMODEL:
206 this->ParseSubmeshGroundModel();
208 case Keyword::TRACTIONCONTROL:
209 this->ParseTractionControl();
213 case Keyword::END_COMMENT:
214 case Keyword::END_DESCRIPTION:
216 this->BeginBlock(Keyword::INVALID);
220 case Keyword::ENVMAP:
221 case Keyword::HOOKGROUP:
222 case Keyword::NODECOLLISION:
223 case Keyword::RIGIDIFIERS:
233 m_log_keyword = m_current_block;
234 switch (m_current_block)
236 case Keyword::AIRBRAKES: this->ParseAirbrakes();
return;
237 case Keyword::ANIMATORS: this->ParseAnimator();
return;
238 case Keyword::ASSETPACKS: this->ParseAssetpacks();
return;
239 case Keyword::AXLES: this->ParseAxles();
return;
240 case Keyword::BEAMS: this->ParseBeams();
return;
241 case Keyword::BRAKES: this->ParseBrakes();
return;
242 case Keyword::CAMERAS: this->ParseCameras();
return;
243 case Keyword::CAB: this->ParseCab();
return;
244 case Keyword::CAMERARAIL: this->ParseCameraRails();
return;
245 case Keyword::CINECAM: this->ParseCinecam();
return;
246 case Keyword::COMMANDS:
247 case Keyword::COMMANDS2: this->ParseCommandsUnified();
return;
248 case Keyword::COLLISIONBOXES: this->ParseCollisionBox();
return;
249 case Keyword::CONTACTERS: this->ParseContacter();
return;
250 case Keyword::DESCRIPTION: this->ParseDescription();
return;
251 case Keyword::ENGINE: this->ParseEngine();
return;
252 case Keyword::ENGOPTION: this->ParseEngoption();
return;
253 case Keyword::ENGTURBO: this->ParseEngturbo();
return;
254 case Keyword::EXHAUSTS: this->ParseExhaust();
return;
255 case Keyword::FIXES: this->ParseFixes();
return;
256 case Keyword::FLARES:
257 case Keyword::FLARES2: this->ParseFlaresUnified();
return;
258 case Keyword::FLARES3: this->ParseFlares3();
return;
259 case Keyword::FLEXBODIES: this->ParseFlexbody();
return;
260 case Keyword::FLEXBODYWHEELS: this->ParseFlexBodyWheel();
return;
261 case Keyword::FUSEDRAG: this->ParseFusedrag();
return;
262 case Keyword::GLOBALS: this->ParseGlobals();
return;
263 case Keyword::GUISETTINGS: this->ParseGuiSettings();
return;
264 case Keyword::HELP: this->ParseHelp();
return;
265 case Keyword::HOOKS: this->ParseHook();
return;
266 case Keyword::HYDROS: this->ParseHydros();
return;
267 case Keyword::INTERAXLES: this->ParseInterAxles();
return;
268 case Keyword::LOCKGROUPS: this->ParseLockgroups();
return;
269 case Keyword::MANAGEDMATERIALS: this->ParseManagedMaterials();
return;
270 case Keyword::MATERIALFLAREBINDINGS:this->ParseMaterialFlareBindings();
return;
271 case Keyword::MESHWHEELS: this->ParseMeshWheel();
return;
272 case Keyword::MESHWHEELS2: this->ParseMeshWheel2();
return;
273 case Keyword::MINIMASS: this->ParseMinimass();
return;
275 case Keyword::NODES2: this->ParseNodesUnified();
return;
276 case Keyword::PARTICLES: this->ParseParticles();
return;
277 case Keyword::PISTONPROPS: this->ParsePistonprops();
return;
278 case Keyword::PROPS: this->ParseProps();
return;
279 case Keyword::RAILGROUPS: this->ParseRailGroups();
return;
280 case Keyword::ROPABLES: this->ParseRopables();
return;
281 case Keyword::ROPES: this->ParseRopes();
return;
282 case Keyword::ROTATORS:
283 case Keyword::ROTATORS2: this->ParseRotatorsUnified();
return;
284 case Keyword::SCREWPROPS: this->ParseScrewprops();
return;
285 case Keyword::SCRIPTS: this->ParseScripts();
return;
286 case Keyword::SHOCKS: this->ParseShock();
return;
287 case Keyword::SHOCKS2: this->ParseShock2();
return;
288 case Keyword::SHOCKS3: this->ParseShock3();
return;
289 case Keyword::SLIDENODES: this->ParseSlidenodes();
return;
290 case Keyword::SOUNDSOURCES: this->ParseSoundsources();
return;
291 case Keyword::SOUNDSOURCES2: this->ParseSoundsources2();
return;
292 case Keyword::TEXCOORDS: this->ParseTexcoords();
return;
293 case Keyword::TIES: this->ParseTies();
return;
294 case Keyword::TORQUECURVE: this->ParseTorqueCurve();
return;
295 case Keyword::TRANSFERCASE: this->ParseTransferCase();
return;
296 case Keyword::TRIGGERS: this->ParseTriggers();
return;
297 case Keyword::TURBOJETS: this->ParseTurbojets();
return;
298 case Keyword::TURBOPROPS:
299 case Keyword::TURBOPROPS2: this->ParseTurbopropsUnified();
return;
300 case Keyword::VIDEOCAMERA: this->ParseVideoCamera();
return;
301 case Keyword::WHEELDETACHERS: this->ParseWheelDetachers();
return;
302 case Keyword::WHEELS: this->ParseWheel();
return;
303 case Keyword::WHEELS2: this->ParseWheel2();
return;
304 case Keyword::WINGS: this->ParseWing();
return;
309 bool Parser::CheckNumArguments(
int min_args)
311 if (min_args > m_num_args)
314 fmt::format(
"Not enough arguments (got {}, {} needed), skipping line", m_num_args, min_args));
324 void Parser::ParseWing()
326 if (!this->CheckNumArguments(16)) {
return; }
330 for (
int i = 0; i < 8; i++) { wing.
nodes[i] = this->GetArgNodeRef (i); }
331 for (
int i = 8; i < 16; i++) { wing.
tex_coords[i-8] = this->GetArgFloat (i); }
333 if (m_num_args > 16) { wing.
control_surface = this->GetArgWingSurface (16); }
334 if (m_num_args > 17) { wing.
chord_point = this->GetArgFloat (17); }
335 if (m_num_args > 18) { wing.
min_deflection = this->GetArgFloat (18); }
336 if (m_num_args > 19) { wing.
max_deflection = this->GetArgFloat (19); }
337 if (m_num_args > 20) { wing.
airfoil = this->GetArgStr (20); }
338 if (m_num_args > 21) { wing.
efficacy_coef = this->GetArgFloat (21); }
340 m_current_module->wings.push_back(wing);
343 void Parser::ParseSetCollisionRange()
345 if (! this->CheckNumArguments(2)) {
return; }
350 m_current_module->set_collision_range.push_back(cr);
353 void Parser::ParseWheel2()
355 if (!this->CheckNumArguments(17)) {
return; }
363 wheel_2.
width = this->GetArgFloat ( 2);
364 wheel_2.
num_rays = this->GetArgInt ( 3);
365 wheel_2.
nodes[0] = this->GetArgNodeRef ( 4);
366 wheel_2.
nodes[1] = this->GetArgNodeRef ( 5);
368 wheel_2.
braking = this->GetArgBraking ( 7);
369 wheel_2.
propulsion = this->GetArgPropulsion ( 8);
371 wheel_2.
mass = this->GetArgFloat (10);
379 if (m_sequential_importer.IsEnabled())
384 m_current_module->wheels2.push_back(wheel_2);
387 void Parser::ParseWheel()
389 if (! this->CheckNumArguments(14)) {
return; }
395 wheel.
radius = this->GetArgFloat ( 0);
396 wheel.
width = this->GetArgFloat ( 1);
397 wheel.
num_rays = this->GetArgInt ( 2);
398 wheel.
nodes[0] = this->GetArgNodeRef ( 3);
399 wheel.
nodes[1] = this->GetArgNodeRef ( 4);
401 wheel.
braking = this->GetArgBraking ( 6);
402 wheel.
propulsion = this->GetArgPropulsion ( 7);
404 wheel.
mass = this->GetArgFloat ( 9);
406 wheel.
damping = this->GetArgFloat (11);
410 if (m_sequential_importer.IsEnabled())
415 m_current_module->wheels.push_back(wheel);
418 void Parser::ParseWheelDetachers()
420 if (! this->CheckNumArguments(2)) {
return; }
424 wheeldetacher.
wheel_id = this->GetArgInt(0);
427 m_current_module->wheeldetachers.push_back(wheeldetacher);
430 void Parser::ParseTractionControl()
432 Ogre::StringVector tokens = Ogre::StringUtil::split(m_current_line + 15,
",");
433 m_num_args = (int)tokens.size();
434 if (! this->CheckNumArguments(2)) {
return; }
438 tc.
wheel_slip = this->ParseArgFloat(tokens[1].c_str());
439 if (tokens.size() > 2) { tc.
fade_speed = this->ParseArgFloat(tokens[2].c_str()); }
440 if (tokens.size() > 3) { tc.
pulse_per_sec = this->ParseArgFloat(tokens[3].c_str()); }
442 for (
unsigned int i=4; i<tokens.size(); i++)
444 Ogre::StringVector args2 = Ogre::StringUtil::split(tokens[i],
":");
445 Ogre::StringUtil::trim(args2[0]);
446 Ogre::StringUtil::toLowerCase(args2[0]);
448 if (args2[0] ==
"mode" && args2.size() == 2)
450 Ogre::StringVector attrs = Ogre::StringUtil::split(args2[1],
"&");
451 auto itor = attrs.begin();
452 auto endi = attrs.end();
453 for (; itor != endi; ++itor)
455 std::string attr = *itor;
456 Ogre::StringUtil::trim(attr);
457 Ogre::StringUtil::toLowerCase(attr);
459 else if (strncmp(attr.c_str(),
"notoggle", 8) == 0) { tc.
attr_no_toggle =
true; }
460 else if (strncmp(attr.c_str(),
"on", 2) == 0) { tc.
attr_is_on =
true; }
461 else if (strncmp(attr.c_str(),
"off", 3) == 0) { tc.
attr_is_on =
false; }
473 m_current_module->tractioncontrol.push_back(tc);
476 void Parser::ParseTransferCase()
478 if (! this->CheckNumArguments(2)) {
return; }
482 tc.
a1 = this->GetArgInt(0) - 1;
483 tc.
a2 = this->GetArgInt(1) - 1;
484 if (m_num_args > 2) { tc.
has_2wd = this->GetArgInt(2); }
485 if (m_num_args > 3) { tc.
has_2wd_lo = this->GetArgInt(3); }
486 for (
int i = 4; i < m_num_args; i++) { tc.
gear_ratios.push_back(this->GetArgFloat(i)); }
488 m_current_module->transfercase.push_back(tc);
491 void Parser::ParseSubmeshGroundModel()
493 if (!this->CheckNumArguments(2)) {
return; }
495 m_current_module->submesh_groundmodel.push_back(this->GetArgStr(1));
498 void Parser::ParseSpeedLimiter()
500 if (! this->CheckNumArguments(2)) {
return; }
506 m_current_module->speedlimiter.push_back(sl);
509 void Parser::ParseSetSkeletonSettings()
511 if (! this->CheckNumArguments(2)) {
return; }
513 if (m_current_module->set_skeleton_settings.size() == 0)
527 void Parser::ParseDirectiveSetNodeDefaults()
529 if (!this->CheckNumArguments(2)) {
return; }
531 float load_weight = this->GetArgFloat(1);
532 float friction = (m_num_args > 2) ? this->GetArgFloat(2) : -1;
533 float volume = (m_num_args > 3) ? this->GetArgFloat(3) : -1;
534 float surface = (m_num_args > 4) ? this->GetArgFloat(4) : -1;
536 m_user_node_defaults = std::shared_ptr<NodeDefaults>(
new NodeDefaults(*m_user_node_defaults) );
538 m_user_node_defaults->load_weight = (load_weight < 0) ? m_ror_node_defaults->load_weight : load_weight;
539 m_user_node_defaults->friction = (friction < 0) ? m_ror_node_defaults->friction : friction;
540 m_user_node_defaults->volume = (volume < 0) ? m_ror_node_defaults->volume : volume;
541 m_user_node_defaults->surface = (surface < 0) ? m_ror_node_defaults->surface : surface;
543 if (m_num_args > 5) m_user_node_defaults->options = this->GetArgNodeOptions(5);
546 void Parser::ParseDirectiveSetManagedMaterialsOptions()
548 if (! this->CheckNumArguments(2)) {
return; }
551 m_current_managed_material_options.double_sided = (this->GetArgChar(1) !=
'0');
554 void Parser::ParseDirectiveSetBeamDefaultsScale()
556 if (! this->CheckNumArguments(5)) {
return; }
565 m_user_beam_defaults = std::shared_ptr<BeamDefaults>(b);
568 void Parser::ParseDirectiveSetBeamDefaults()
570 if (! this->CheckNumArguments(2)) {
return; }
599 m_user_beam_defaults = std::shared_ptr<BeamDefaults>(
new BeamDefaults(d) );
603 void Parser::ParseDirectivePropCameraMode()
605 if (! this->CheckNumArguments(2)) {
return; }
607 if (m_current_module->props.size() > 0)
609 m_current_module->props[m_current_module->props.size() - 1].camera_settings.mode = this->GetArgInt(1);
617 void Parser::ParseDirectiveSubmesh()
619 this->BeginBlock(Keyword::INVALID);
620 m_current_submesh = std::shared_ptr<Submesh>(
new Submesh() );
623 void Parser::ParseDirectiveBackmesh()
625 if (m_current_submesh)
627 m_current_submesh->backmesh =
true;
639 case Keyword::DISABLEDEFAULTSOUNDS: m_definition->disable_default_sounds =
true;
return;
640 case Keyword::ENABLE_ADVANCED_DEFORMATION: m_definition->enable_advanced_deformation =
true;
return;
641 case Keyword::FORWARDCOMMANDS: m_definition->forward_commands =
true;
return;
642 case Keyword::IMPORTCOMMANDS: m_definition->import_commands =
true;
return;
643 case Keyword::HIDEINCHOOSER: m_definition->hide_in_chooser =
true;
return;
644 case Keyword::LOCKGROUP_DEFAULT_NOLOCK: m_definition->lockgroup_default_nolock =
true;
return;
645 case Keyword::RESCUER: m_definition->rescuer =
true;
return;
646 case Keyword::ROLLON: m_definition->rollon =
true;
return;
647 case Keyword::SLIDENODE_CONNECT_INSTANTLY: m_definition->slide_nodes_connect_instantly =
true;
return;
659 mesh_wheel.
rim_radius = this->GetArgFloat ( 1);
660 mesh_wheel.
width = this->GetArgFloat ( 2);
661 mesh_wheel.
num_rays = this->GetArgInt ( 3);
662 mesh_wheel.
nodes[0] = this->GetArgNodeRef ( 4);
663 mesh_wheel.
nodes[1] = this->GetArgNodeRef ( 5);
665 mesh_wheel.
braking = this->GetArgBraking ( 7);
666 mesh_wheel.
propulsion = this->GetArgPropulsion ( 8);
668 mesh_wheel.
mass = this->GetArgFloat (10);
669 mesh_wheel.
spring = this->GetArgFloat (11);
670 mesh_wheel.
damping = this->GetArgFloat (12);
671 mesh_wheel.
side = this->GetArgWheelSide (13);
672 mesh_wheel.
mesh_name = this->GetArgStr (14);
676 void Parser::ParseMeshWheel()
678 if (! this->CheckNumArguments(16)) {
return; }
681 this->_ParseBaseMeshWheel(mesh_wheel);
683 if (m_sequential_importer.IsEnabled())
688 m_current_module->meshwheels.push_back(mesh_wheel);
691 void Parser::ParseMeshWheel2()
693 if (! this->CheckNumArguments(16)) {
return; }
696 this->_ParseBaseMeshWheel(mesh_wheel);
698 if (m_sequential_importer.IsEnabled())
703 m_current_module->meshwheels2.push_back(mesh_wheel);
706 void Parser::ParseHook()
708 if (! this->CheckNumArguments(1)) {
return; }
711 hook.
node = this->GetArgNodeRef(0);
714 while (i < m_num_args)
716 std::string attr = this->GetArgStr(i);
717 Ogre::StringUtil::trim(attr);
718 const bool has_value = (i < (m_num_args - 1));
721 if (has_value && (attr ==
"hookrange") ) { hook.
option_hook_range = this->GetArgFloat(++i); }
722 else if (has_value && (attr ==
"speedcoef") ) { hook.
option_speed_coef = this->GetArgFloat(++i); }
723 else if (has_value && (attr ==
"maxforce") ) { hook.
option_max_force = this->GetArgFloat(++i); }
724 else if (has_value && (attr ==
"timer") ) { hook.
option_timer = this->GetArgFloat(++i); }
725 else if (has_value && (attr ==
"hookgroup" || attr ==
"hgroup") ) { hook.
option_hookgroup = this->GetArgInt (++i); }
726 else if (has_value && (attr ==
"lockgroup" || attr ==
"lgroup") ) { hook.
option_lockgroup = this->GetArgInt (++i); }
727 else if (has_value && (attr ==
"shortlimit" || attr ==
"short_limit")) { hook.
option_min_range_meters = this->GetArgFloat(++i); }
729 else if ((attr ==
"selflock") ||(attr ==
"self-lock") ||(attr ==
"self_lock") ) { hook.
flag_self_lock =
true; }
730 else if ((attr ==
"autolock") ||(attr ==
"auto-lock") ||(attr ==
"auto_lock") ) { hook.
flag_auto_lock =
true; }
731 else if ((attr ==
"nodisable")||(attr ==
"no-disable")||(attr ==
"no_disable")) { hook.
flag_no_disable =
true; }
732 else if ((attr ==
"norope") ||(attr ==
"no-rope") ||(attr ==
"no_rope") ) { hook.
flag_no_rope =
true; }
733 else if ((attr ==
"visible") ||(attr ==
"vis") ) { hook.
flag_visible =
true; }
741 m_current_module->hooks.push_back(hook);
744 void Parser::ParseHelp()
748 m_current_module->help.push_back(h);
751 void Parser::ParseGuiSettings()
753 if (! this->CheckNumArguments(2)) {
return; }
756 gs.
key = this->GetArgStr(0);
757 gs.
value = this->GetArgStr(1);
759 m_current_module->guisettings.push_back(gs);
762 void Parser::ParseGuid()
764 if (! this->CheckNumArguments(2)) {
return; }
767 g.
guid = this->GetArgStr(1);
769 m_current_module->guid.push_back(g);
772 void Parser::ParseGlobals()
774 if (! this->CheckNumArguments(2)) {
return; }
777 globals.
dry_mass = this->GetArgFloat(0);
780 if (m_num_args > 2) { globals.
material_name = this->GetArgStr(2); }
782 m_current_module->globals.push_back(globals);
785 void Parser::ParseFusedrag()
787 if (! this->CheckNumArguments(3)) {
return; }
791 fusedrag.
rear_node = this->GetArgNodeRef(1);
793 if (this->GetArgStr(2) ==
"autocalc")
799 if (m_num_args > 4) { fusedrag.
airfoil_name = this->GetArgStr (4); }
806 if (m_num_args > 3) { fusedrag.
airfoil_name = this->GetArgStr(3); }
809 m_current_module->fusedrag.push_back(fusedrag);
812 void Parser::ParseDirectiveFlexbodyCameraMode()
814 if (! this->CheckNumArguments(2)) {
return; }
816 if (m_current_module->flexbodies.size() > 0)
818 m_current_module->flexbodies[m_current_module->flexbodies.size() - 1].camera_settings.mode = this->GetArgInt(1);
826 void Parser::ParseCab()
828 if (! this->CheckNumArguments(3)) {
return; }
830 if (!m_current_submesh)
837 cab.
nodes[0] = this->GetArgNodeRef(0);
838 cab.
nodes[1] = this->GetArgNodeRef(1);
839 cab.
nodes[2] = this->GetArgNodeRef(2);
840 if (m_num_args > 3) cab.
options = this->GetArgCabOptions(3);
842 m_current_submesh->cab_triangles.push_back(cab);
845 void Parser::ParseTexcoords()
847 if (! this->CheckNumArguments(3)) {
return; }
849 if (!m_current_submesh)
856 texcoord.
node = this->GetArgNodeRef(0);
857 texcoord.
u = this->GetArgFloat (1);
858 texcoord.
v = this->GetArgFloat (2);
860 m_current_submesh->texcoords.push_back(texcoord);
863 void Parser::ParseFlexbody()
865 if (! this->CheckNumArguments(10)) {
return; }
871 flexbody.
offset.x = this->GetArgFloat (3);
872 flexbody.
offset.y = this->GetArgFloat (4);
873 flexbody.
offset.z = this->GetArgFloat (5);
874 flexbody.
rotation.x = this->GetArgFloat (6);
875 flexbody.
rotation.y = this->GetArgFloat (7);
876 flexbody.
rotation.z = this->GetArgFloat (8);
877 flexbody.
mesh_name = this->GetArgStr (9);
879 m_current_module->flexbodies.push_back(flexbody);
882 void Parser::ParseDirectiveForset()
884 if (m_current_module->flexbodies.size() == 0)
890 Parser::ProcessForsetLine(m_current_module->flexbodies.back(), m_current_line, m_current_line_number);
893 void Parser::ProcessForsetLine(
RigDef::Flexbody& def,
const std::string& _line,
int line_number )
903 std::string line = _line;
904 char* pos = &line[0] + 6;
905 while (*pos ==
' ' || *pos ==
':' || *pos ==
',') { pos++; }
912 while (*end !=
'-' && *end !=
',' && *end != 0) end++;
915 val1 = strtoul(pos, 0, 10);
920 while (*end !=
',' && *end != 0) end++;
923 val2 = strtoul(pos, 0, 10);
927 Node::Ref(std::to_string(val1), val1, Node::Ref::IMPORT_STATE_IS_VALID, line_number),
928 Node::Ref(std::to_string(val2), val2, Node::Ref::IMPORT_STATE_IS_VALID, line_number)));
940 void Parser::ParseFlaresUnified()
942 const bool is_flares2 = (m_current_block == Keyword::FLARES2);
943 if (! this->CheckNumArguments(is_flares2 ? 6 : 5)) {
return; }
950 flare2.
offset.x = this->GetArgFloat (pos++);
951 flare2.
offset.y = this->GetArgFloat (pos++);
953 if (m_current_block == Keyword::FLARES2)
955 flare2.
offset.z = this->GetArgFloat(pos++);
958 if (m_num_args > pos) { flare2.
type = this->GetArgFlareType(pos++); }
960 if (m_num_args > pos)
972 if (m_num_args > pos) { flare2.
size = this->GetArgFloat (pos++); }
973 if (m_num_args > pos) { flare2.
material_name = this->GetArgStr (pos++); }
975 m_current_module->flares2.push_back(flare2);
978 void Parser::ParseFlares3()
980 const bool is_flares2 = (m_current_block == Keyword::FLARES2);
981 if (! this->CheckNumArguments(is_flares2 ? 6 : 5)) {
return; }
989 flare3.
offset.x = this->GetArgFloat(3);
990 flare3.
offset.y = this->GetArgFloat(4);
991 flare3.
offset.z = this->GetArgFloat(5);
992 if (m_num_args > 6) { flare3.
type = this->GetArgFlareType(6); }
1005 if (m_num_args > 9) { flare3.
size = this->GetArgFloat (9); }
1006 if (m_num_args > 10) { flare3.
material_name = this->GetArgStr (10); }
1008 m_current_module->flares3.push_back(flare3);
1011 void Parser::ParseFixes()
1013 m_current_module->fixes.push_back(this->GetArgNodeRef(0));
1016 void Parser::ParseExtCamera()
1018 if (! this->CheckNumArguments(2)) {
return; }
1021 extcam.
mode = this->GetArgExtCameraMode(1);
1022 if (m_num_args > 2) { extcam.
node = this->GetArgNodeRef(2); }
1024 m_current_module->extcamera.push_back(extcam);
1027 void Parser::ParseExhaust()
1029 if (! this->CheckNumArguments(2)) {
return; }
1036 if (m_num_args > 3) { exhaust.
particle_name = this->GetArgStr(3); }
1038 m_current_module->exhausts.push_back(exhaust);
1041 void Parser::ParseFileFormatVersion()
1043 if (! this->CheckNumArguments(2)) {
return; }
1046 ffv.
version = this->GetArgInt(1);
1048 m_current_module->fileformatversion.push_back(ffv);
1049 m_current_block = Keyword::INVALID;
1052 void Parser::ParseDirectiveDefaultSkin()
1054 if (!this->CheckNumArguments(2)) {
return; }
1060 m_current_module->default_skin.push_back(data);
1063 void Parser::ParseDirectiveDetacherGroup()
1065 if (! this->CheckNumArguments(2)) {
return; }
1067 if (this->GetArgStr(1) ==
"end")
1069 m_current_detacher_group = 0;
1073 m_current_detacher_group = this->GetArgInt(1);
1077 void Parser::ParseCruiseControl()
1079 if (! this->CheckNumArguments(3)) {
return; }
1082 cruise_control.
min_speed = this->GetArgFloat(1);
1083 cruise_control.
autobrake = this->GetArgInt(2);
1085 m_current_module->cruisecontrol.push_back(cruise_control);
1088 void Parser::ParseDescription()
1090 m_current_module->description.push_back(m_current_line);
1093 void Parser::ParseDirectiveAddAnimation()
1095 Ogre::StringVector tokens = Ogre::StringUtil::split(m_current_line + 14,
",");
1096 m_num_args = (int)tokens.size();
1097 if (! this->CheckNumArguments(4)) {
return; }
1099 if (m_current_module->props.size() == 0)
1106 animation.
ratio = this->ParseArgFloat(tokens[0].c_str());
1107 animation.
lower_limit = this->ParseArgFloat(tokens[1].c_str());
1108 animation.
upper_limit = this->ParseArgFloat(tokens[2].c_str());
1110 for (
auto itor = tokens.begin() + 3; itor != tokens.end(); ++itor)
1112 Ogre::StringVector entry = Ogre::StringUtil::split(*itor,
":");
1113 Ogre::StringUtil::trim(entry[0]);
1114 if (entry.size() > 1) Ogre::StringUtil::trim(entry[1]);
1116 const int WARN_LEN = 500;
1117 char warn_msg[WARN_LEN] =
"";
1119 if (entry.size() == 1)
1121 if (entry[0] ==
"autoanimate") { animation.
mode |= Animation::MODE_AUTO_ANIMATE; }
1122 else if (entry[0] ==
"noflip") { animation.
mode |= Animation::MODE_NO_FLIP; }
1123 else if (entry[0] ==
"bounce") { animation.
mode |= Animation::MODE_BOUNCE; }
1124 else if (entry[0] ==
"eventlock") { animation.
mode |= Animation::MODE_EVENT_LOCK; }
1126 else { snprintf(warn_msg, WARN_LEN,
"Invalid keyword: %s", entry[0].c_str()); }
1128 else if (entry.size() == 2 && (entry[0] ==
"mode" || entry[0] ==
"event" || entry[0] ==
"source" || entry[0] ==
"link"))
1130 Ogre::StringVector values = Ogre::StringUtil::split(entry[1],
"|");
1131 if (entry[0] ==
"mode")
1133 for (
auto itor = values.begin(); itor != values.end(); ++itor)
1135 std::string value = *itor;
1136 Ogre::StringUtil::trim(value);
1138 if (value ==
"x-rotation") { animation.
mode |= Animation::MODE_ROTATION_X; }
1139 else if (value ==
"y-rotation") { animation.
mode |= Animation::MODE_ROTATION_Y; }
1140 else if (value ==
"z-rotation") { animation.
mode |= Animation::MODE_ROTATION_Z; }
1141 else if (value ==
"x-offset" ) { animation.
mode |= Animation::MODE_OFFSET_X; }
1142 else if (value ==
"y-offset" ) { animation.
mode |= Animation::MODE_OFFSET_Y; }
1143 else if (value ==
"z-offset" ) { animation.
mode |= Animation::MODE_OFFSET_Z; }
1145 else { snprintf(warn_msg, WARN_LEN,
"Invalid 'mode': %s, ignoring...", entry[1].c_str()); }
1148 else if (entry[0] ==
"event")
1151 Ogre::StringUtil::trim(animation.
event_name);
1152 Ogre::StringUtil::toUpperCase(animation.
event_name);
1154 else if (entry[0] ==
"link")
1159 else if (entry[0] ==
"source")
1161 for (
auto itor = values.begin(); itor != values.end(); ++itor)
1163 std::string value = *itor;
1164 Ogre::StringUtil::trim(value);
1166 if (value ==
"airspeed") { animation.
source |= Animation::SOURCE_AIRSPEED; }
1167 else if (value ==
"vvi") { animation.
source |= Animation::SOURCE_VERTICAL_VELOCITY; }
1168 else if (value ==
"altimeter100k") { animation.
source |= Animation::SOURCE_ALTIMETER_100K; }
1169 else if (value ==
"altimeter10k") { animation.
source |= Animation::SOURCE_ALTIMETER_10K; }
1170 else if (value ==
"altimeter1k") { animation.
source |= Animation::SOURCE_ALTIMETER_1K; }
1171 else if (value ==
"aoa") { animation.
source |= Animation::SOURCE_ANGLE_OF_ATTACK; }
1172 else if (value ==
"flap") { animation.
source |= Animation::SOURCE_FLAP; }
1173 else if (value ==
"airbrake") { animation.
source |= Animation::SOURCE_AIR_BRAKE; }
1174 else if (value ==
"roll") { animation.
source |= Animation::SOURCE_ROLL; }
1175 else if (value ==
"pitch") { animation.
source |= Animation::SOURCE_PITCH; }
1176 else if (value ==
"brakes") { animation.
source |= Animation::SOURCE_BRAKES; }
1177 else if (value ==
"accel") { animation.
source |= Animation::SOURCE_ACCEL; }
1178 else if (value ==
"clutch") { animation.
source |= Animation::SOURCE_CLUTCH; }
1179 else if (value ==
"speedo") { animation.
source |= Animation::SOURCE_SPEEDO; }
1180 else if (value ==
"tacho") { animation.
source |= Animation::SOURCE_TACHO; }
1181 else if (value ==
"turbo") { animation.
source |= Animation::SOURCE_TURBO; }
1182 else if (value ==
"parking") { animation.
source |= Animation::SOURCE_PARKING; }
1183 else if (value ==
"shifterman1") { animation.
source |= Animation::SOURCE_SHIFT_LEFT_RIGHT; }
1184 else if (value ==
"shifterman2") { animation.
source |= Animation::SOURCE_SHIFT_BACK_FORTH; }
1185 else if (value ==
"sequential") { animation.
source |= Animation::SOURCE_SEQUENTIAL_SHIFT; }
1186 else if (value ==
"shifterlin") { animation.
source |= Animation::SOURCE_SHIFTERLIN; }
1187 else if (value ==
"autoshifterlin"){ animation.
source |= Animation::SOURCE_AUTOSHIFTERLIN; }
1188 else if (value ==
"torque") { animation.
source |= Animation::SOURCE_TORQUE; }
1189 else if (value ==
"heading") { animation.
source |= Animation::SOURCE_HEADING; }
1190 else if (value ==
"difflock") { animation.
source |= Animation::SOURCE_DIFFLOCK; }
1191 else if (value ==
"rudderboat") { animation.
source |= Animation::SOURCE_BOAT_RUDDER; }
1192 else if (value ==
"throttleboat") { animation.
source |= Animation::SOURCE_BOAT_THROTTLE; }
1193 else if (value ==
"steeringwheel") { animation.
source |= Animation::SOURCE_STEERING_WHEEL; }
1194 else if (value ==
"aileron") { animation.
source |= Animation::SOURCE_AILERON; }
1195 else if (value ==
"elevator") { animation.
source |= Animation::SOURCE_ELEVATOR; }
1196 else if (value ==
"rudderair") { animation.
source |= Animation::SOURCE_AIR_RUDDER; }
1197 else if (value ==
"permanent") { animation.
source |= Animation::SOURCE_PERMANENT; }
1198 else if (value ==
"event") { animation.
source |= Animation::SOURCE_EVENT; }
1199 else if (value ==
"dashboard") { animation.
source |= Animation::SOURCE_DASHBOARD; }
1200 else if (value ==
"signalstalk") { animation.
source |= Animation::SOURCE_SIGNALSTALK; }
1201 else if (value ==
"gearreverse") { animation.
source |= Animation::SOURCE_GEAR_REVERSE; }
1202 else if (value ==
"gearneutral") { animation.
source |= Animation::SOURCE_GEAR_NEUTRAL; }
1208 if (entry[1].compare(0, 8,
"throttle") == 0)
1210 motor_source.
source = Animation::MotorSource::SOURCE_AERO_THROTTLE;
1211 motor_source.
motor = this->ParseArgUint(entry[1].substr(8));
1213 else if (entry[1].compare(0, 3,
"rpm") == 0)
1215 motor_source.
source = Animation::MotorSource::SOURCE_AERO_RPM;
1216 motor_source.
motor = this->ParseArgUint(entry[1].substr(3));
1218 else if (entry[1].compare(0, 8,
"aerotorq") == 0)
1220 motor_source.
source = Animation::MotorSource::SOURCE_AERO_TORQUE;
1221 motor_source.
motor = this->ParseArgUint(entry[1].substr(8));
1223 else if (entry[1].compare(0, 7,
"aeropit") == 0)
1225 motor_source.
source = Animation::MotorSource::SOURCE_AERO_PITCH;
1226 motor_source.
motor = this->ParseArgUint(entry[1].substr(7));
1228 else if (entry[1].compare(0, 10,
"aerostatus") == 0)
1230 motor_source.
source = Animation::MotorSource::SOURCE_AERO_STATUS;
1231 motor_source.
motor = this->ParseArgUint(entry[1].substr(10));
1234 else if (entry[1].compare(0, 4,
"gear") == 0)
1236 motor_source.
source = Animation::MotorSource::SOURCE_GEAR_FORWARD;
1237 motor_source.
motor = this->ParseArgUint(entry[1].substr(4));
1241 snprintf(warn_msg, WARN_LEN,
"Invalid 'source': %s, ignoring...", entry[1].c_str());
1250 snprintf(warn_msg, WARN_LEN,
"Invalid keyword: %s, ignoring...", entry[0].c_str());
1255 snprintf(warn_msg, WARN_LEN,
"Invalid item: %s, ignoring...", entry[0].c_str());
1258 if (warn_msg[0] !=
'\0')
1261 fmt::format(
"Ignoring invalid token '{}' ({})", itor->c_str(), warn_msg));
1265 m_current_module->props.back().animations.push_back(animation);
1268 void Parser::ParseAntiLockBrakes()
1271 Ogre::StringVector tokens = Ogre::StringUtil::split(m_current_line + 15,
",");
1272 m_num_args = (int)tokens.size();
1273 if (! this->CheckNumArguments(2)) {
return; }
1276 alb.
min_speed = this->ParseArgInt (tokens[1].c_str());
1278 if (tokens.size() > 3) { alb.
pulse_per_sec = this->ParseArgFloat(tokens[2].c_str()); }
1280 for (
unsigned int i=3; i<tokens.size(); i++)
1282 Ogre::StringVector args2 = Ogre::StringUtil::split(tokens[i],
":");
1283 Ogre::StringUtil::trim(args2[0]);
1284 Ogre::StringUtil::toLowerCase(args2[0]);
1285 if (args2[0] ==
"mode" && args2.size() == 2)
1287 Ogre::StringVector attrs = Ogre::StringUtil::split(args2[1],
"&");
1288 auto itor = attrs.begin();
1289 auto endi = attrs.end();
1290 for (; itor != endi; ++itor)
1292 std::string attr = *itor;
1293 Ogre::StringUtil::trim(attr);
1294 Ogre::StringUtil::toLowerCase(attr);
1296 else if (strncmp(attr.c_str(),
"notoggle", 8) == 0) { alb.
attr_no_toggle =
true; }
1297 else if (strncmp(attr.c_str(),
"on", 2) == 0) { alb.
attr_is_on =
true; }
1298 else if (strncmp(attr.c_str(),
"off", 3) == 0) { alb.
attr_is_on =
false; }
1310 m_current_module->antilockbrakes.push_back(alb);
1313 void Parser::ParseEngoption()
1315 if (! this->CheckNumArguments(1)) {
return; }
1318 engoption.
inertia = this->GetArgFloat(0);
1320 if (m_num_args > 1) { engoption.
type = this->GetArgEngineType(1); }
1321 if (m_num_args > 2) { engoption.
clutch_force = this->GetArgFloat(2); }
1322 if (m_num_args > 3) { engoption.
shift_time = this->GetArgFloat(3); }
1323 if (m_num_args > 4) { engoption.
clutch_time = this->GetArgFloat(4); }
1324 if (m_num_args > 5) { engoption.
post_shift_time = this->GetArgFloat(5); }
1325 if (m_num_args > 6) { engoption.
stall_rpm = this->GetArgFloat(6); }
1326 if (m_num_args > 7) { engoption.
idle_rpm = this->GetArgFloat(7); }
1329 if (m_num_args > 10){ engoption.
braking_torque = this->GetArgFloat(10);}
1331 m_current_module->engoption.push_back(engoption);
1334 void Parser::ParseEngturbo()
1336 if (! this->CheckNumArguments(4)) {
return; }
1339 engturbo.
version = this->GetArgInt ( 0);
1341 engturbo.
nturbos = this->GetArgInt ( 2);
1342 engturbo.
param1 = this->GetArgFloat( 3);
1344 if (m_num_args > 4) { engturbo.
param2 = this->GetArgFloat( 4); }
1345 if (m_num_args > 5) { engturbo.
param3 = this->GetArgFloat( 5); }
1346 if (m_num_args > 6) { engturbo.
param4 = this->GetArgFloat( 6); }
1347 if (m_num_args > 7) { engturbo.
param5 = this->GetArgFloat( 7); }
1348 if (m_num_args > 8) { engturbo.
param6 = this->GetArgFloat( 8); }
1349 if (m_num_args > 9) { engturbo.
param7 = this->GetArgFloat( 9); }
1350 if (m_num_args > 10) { engturbo.
param8 = this->GetArgFloat(10); }
1351 if (m_num_args > 11) { engturbo.
param9 = this->GetArgFloat(11); }
1352 if (m_num_args > 12) { engturbo.
param10 = this->GetArgFloat(12); }
1353 if (m_num_args > 13) { engturbo.
param11 = this->GetArgFloat(13); }
1361 m_current_module->engturbo.push_back(engturbo);
1364 void Parser::ParseEngine()
1366 if (! this->CheckNumArguments(6)) {
return; }
1371 engine.
torque = this->GetArgFloat(2);
1377 for (
int i = 6; i < m_num_args; i++)
1379 float ratio = this->GetArgFloat(i);
1393 m_current_module->engine.push_back(engine);
1396 void Parser::ParseContacter()
1398 if (! this->CheckNumArguments(1)) {
return; }
1400 m_current_module->contacters.push_back(this->GetArgNodeRef(0));
1403 void Parser::ParseCommandsUnified()
1405 const bool is_commands2 = (m_current_block == Keyword::COMMANDS2);
1406 const int max_args = (is_commands2 ? 8 : 7);
1407 if (! this->CheckNumArguments(max_args)) {
return; }
1415 command2.
nodes[0] = this->GetArgNodeRef(pos++);
1416 command2.
nodes[1] = this->GetArgNodeRef(pos++);
1431 command2.
extend_key = this->GetArgInt (pos++);
1433 if (m_num_args <= max_args)
1435 m_current_module->commands2.push_back(command2);
1440 std::string options_str = this->GetArgStr(pos++);
1442 for (
auto itor = options_str.begin(); itor != options_str.end(); ++itor)
1444 const char c = *itor;
1445 if ((winner == 0) && (c ==
'o' || c ==
'p' || c ==
'c')) { winner = c; }
1480 if (
ignored != 0 && winner ==
'c')
1483 "Command cannot be one-pressed and self centering at the same time, ignoring flag '%c'");
1485 else if (
ignored != 0 && (winner ==
'o' || winner ==
'p'))
1488 "Command already has a one-pressed c.mode, ignoring flag '%c'");
1491 if (m_num_args > pos) { command2.
description = this->GetArgStr (pos++);}
1493 if (m_num_args > pos) { ParseOptionalInertia(command2.
inertia, pos); pos += 4; }
1495 if (m_num_args > pos) { command2.
affect_engine = this->GetArgFloat(pos++);}
1496 if (m_num_args > pos) { command2.
needs_engine = this->GetArgBool (pos++);}
1497 if (m_num_args > pos) { command2.
plays_sound = this->GetArgBool (pos++);}
1499 m_current_module->commands2.push_back(command2);
1502 void Parser::ParseCollisionBox()
1506 Ogre::StringVector tokens = Ogre::StringUtil::split(m_current_line,
",");
1507 Ogre::StringVector::iterator iter = tokens.begin();
1508 for ( ; iter != tokens.end(); iter++)
1510 collisionbox.
nodes.push_back( this->_ParseNodeRef(*iter) );
1513 m_current_module->collisionboxes.push_back(collisionbox);
1516 void Parser::ParseCinecam()
1518 if (! this->CheckNumArguments(11)) {
return; }
1525 cinecam.
position.x = this->GetArgFloat ( 0);
1526 cinecam.
position.y = this->GetArgFloat ( 1);
1527 cinecam.
position.z = this->GetArgFloat ( 2);
1528 cinecam.
nodes[0] = this->GetArgNodeRef( 3);
1529 cinecam.
nodes[1] = this->GetArgNodeRef( 4);
1530 cinecam.
nodes[2] = this->GetArgNodeRef( 5);
1531 cinecam.
nodes[3] = this->GetArgNodeRef( 6);
1532 cinecam.
nodes[4] = this->GetArgNodeRef( 7);
1533 cinecam.
nodes[5] = this->GetArgNodeRef( 8);
1534 cinecam.
nodes[6] = this->GetArgNodeRef( 9);
1535 cinecam.
nodes[7] = this->GetArgNodeRef(10);
1538 if (m_num_args > 11) { cinecam.
spring = this->GetArgFloat(11); }
1539 if (m_num_args > 12) { cinecam.
damping = this->GetArgFloat(12); }
1541 if (m_num_args > 13)
1543 float value = this->GetArgFloat(13);
1548 if (m_sequential_importer.IsEnabled())
1550 m_sequential_importer.AddGeneratedNode(Keyword::CINECAM);
1553 m_current_module->cinecam.push_back(cinecam);
1556 void Parser::ParseCameraRails()
1558 m_current_camera_rail->nodes.push_back( this->GetArgNodeRef(0) );
1561 void Parser::ParseBrakes()
1563 if (!this->CheckNumArguments(1)) {
return; }
1571 m_current_module->brakes.push_back(brakes);
1574 void Parser::ParseAxles()
1578 Ogre::StringVector tokens = Ogre::StringUtil::split(m_current_line,
",");
1579 Ogre::StringVector::iterator iter = tokens.begin();
1580 for ( ; iter != tokens.end(); iter++)
1582 std::smatch results;
1583 if (! std::regex_search(*iter, results, Regexes::SECTION_AXLES_PROPERTY))
1590 if (results[1].matched)
1592 unsigned int wheel_index =
PARSEINT(results[2]) - 1;
1593 axle.
wheels[wheel_index][0] = _ParseNodeRef(results[3]);
1594 axle.
wheels[wheel_index][1] = _ParseNodeRef(results[4]);
1596 else if (results[5].matched)
1598 this->_ParseDifferentialTypes(axle.
options, results[6].str());
1602 m_current_module->axles.push_back(axle);
1605 void Parser::ParseInterAxles()
1607 auto args = Ogre::StringUtil::split(m_current_line,
",");
1608 if (args.size() < 2) {
return; }
1612 interaxle.
a1 = this->ParseArgInt(args[0].c_str()) - 1;
1613 interaxle.
a2 = this->ParseArgInt(args[1].c_str()) - 1;
1615 std::smatch results;
1616 if (! std::regex_search(args[2], results, Regexes::SECTION_AXLES_PROPERTY))
1623 if (results[5].matched)
1625 this->_ParseDifferentialTypes(interaxle.
options, results[6].str());
1628 m_current_module->interaxles.push_back(interaxle);
1631 void Parser::ParseAirbrakes()
1633 if (! this->CheckNumArguments(14)) {
return; }
1640 airbrake.
offset.x = this->GetArgFloat ( 4);
1641 airbrake.
offset.y = this->GetArgFloat ( 5);
1642 airbrake.
offset.z = this->GetArgFloat ( 6);
1643 airbrake.
width = this->GetArgFloat ( 7);
1644 airbrake.
height = this->GetArgFloat ( 8);
1651 m_current_module->airbrakes.push_back(airbrake);
1654 void Parser::ParseAssetpacks()
1656 if (! this->CheckNumArguments(1)) {
return; }
1660 assetpack.
filename = this->GetArgStr(0);
1662 m_current_module->assetpacks.push_back(assetpack);
1665 void Parser::ParseVideoCamera()
1667 if (! this->CheckNumArguments(19)) {
return; }
1672 videocamera.
left_node = this->GetArgNodeRef ( 1);
1673 videocamera.
bottom_node = this->GetArgNodeRef ( 2);
1676 videocamera.
offset.x = this->GetArgFloat ( 5);
1677 videocamera.
offset.y = this->GetArgFloat ( 6);
1678 videocamera.
offset.z = this->GetArgFloat ( 7);
1679 videocamera.
rotation.x = this->GetArgFloat ( 8);
1680 videocamera.
rotation.y = this->GetArgFloat ( 9);
1681 videocamera.
rotation.z = this->GetArgFloat (10);
1691 if (m_num_args > 19) { videocamera.
camera_name = this->GetArgStr(19); }
1693 m_current_module->videocameras.push_back(videocamera);
1696 void Parser::ParseCameras()
1698 if (! this->CheckNumArguments(3)) {
return; }
1702 camera.
back_node = this->GetArgNodeRef(1);
1703 camera.
left_node = this->GetArgNodeRef(2);
1705 m_current_module->cameras.push_back(camera);
1708 void Parser::ParseTurbopropsUnified()
1710 bool is_turboprop_2 = m_current_block == Keyword::TURBOPROPS2;
1712 if (! this->CheckNumArguments(is_turboprop_2 ? 9 : 8)) {
return; }
1717 turboprop.
axis_node = this->GetArgNodeRef(1);
1727 turboprop.
couple_node = this->GetArgNullableNode(6);
1733 turboprop.
airfoil = this->GetArgStr (7 + offset);
1735 m_current_module->turboprops2.push_back(turboprop);
1738 void Parser::ParseTurbojets()
1740 if (! this->CheckNumArguments(9)) {
return; }
1743 turbojet.
front_node = this->GetArgNodeRef(0);
1744 turbojet.
back_node = this->GetArgNodeRef(1);
1745 turbojet.
side_node = this->GetArgNodeRef(2);
1753 m_current_module->turbojets.push_back(turbojet);
1756 void Parser::ParseTriggers()
1758 if (! this->CheckNumArguments(6)) {
return; }
1763 trigger.
nodes[0] = this->GetArgNodeRef(0);
1764 trigger.
nodes[1] = this->GetArgNodeRef(1);
1769 if (m_num_args > 6) trigger.
options = this->GetArgTriggerOptions(6);
1770 if (m_num_args > 7) trigger.
boundary_timer = this->GetArgFloat(7);
1772 m_current_module->triggers.push_back(trigger);
1775 void Parser::ParseTorqueCurve()
1777 if (m_current_module->torquecurve.size() == 0)
1779 m_current_module->torquecurve.push_back(
TorqueCurve());
1782 Ogre::StringVector args = Ogre::StringUtil::split(m_current_line,
",");
1784 if (args.size() == 1u)
1786 m_current_module->torquecurve[0].predefined_func_name = args[0];
1788 else if (args.size() == 2u)
1791 sample.
power = this->ParseArgFloat(args[0].c_str());
1793 m_current_module->torquecurve[0].samples.push_back(sample);
1802 void Parser::ParseTies()
1804 if (! this->CheckNumArguments(5)) {
return; }
1818 for (
char c: this->GetArgStr(5))
1822 case (
char)TieOption::n_DUMMY:
1823 case (
char)TieOption::v_DUMMY:
1826 case (
char)TieOption::i_INVISIBLE:
1827 tie.
options |= Tie::OPTION_i_INVISIBLE;
1830 case (
char)TieOption::s_NO_SELF_LOCK:
1831 tie.
options |= Tie::OPTION_s_DISABLE_SELF_LOCK;
1842 if (m_num_args > 6) { tie.
max_stress = this->GetArgFloat (6); }
1843 if (m_num_args > 7) { tie.
group = this->GetArgInt (7); }
1845 m_current_module->ties.push_back(tie);
1848 void Parser::ParseSoundsources()
1850 if (! this->CheckNumArguments(2)) {
return; }
1853 soundsource.
node = this->GetArgNodeRef(0);
1856 m_current_module->soundsources.push_back(soundsource);
1859 void Parser::ParseSoundsources2()
1861 if (! this->CheckNumArguments(3)) {
return; }
1864 soundsource2.
node = this->GetArgNodeRef(0);
1865 soundsource2.
mode = this->GetArgInt(1);
1868 if (soundsource2.
mode < -2)
1871 fmt::format(
"invalid mode {}, falling back to default -2", soundsource2.
mode));
1872 soundsource2.
mode = -2;
1875 m_current_module->soundsources2.push_back(soundsource2);
1878 void Parser::ParseSlidenodes()
1880 Ogre::StringVector args = Ogre::StringUtil::split(m_current_line,
", ");
1881 m_num_args = (int)args.size();
1882 if (! this->CheckNumArguments(2)) {
return; }
1885 slidenode.
slide_node = this->_ParseNodeRef(args[0]);
1887 bool in_rail_node_list =
true;
1889 for (
auto itor = args.begin() + 1; itor != args.end(); ++itor)
1891 char c = toupper(itor->at(0));
1895 slidenode.
spring_rate = this->ParseArgFloat(itor->substr(1));
1897 in_rail_node_list =
false;
1900 slidenode.
break_force = this->ParseArgFloat(itor->substr(1));
1902 in_rail_node_list =
false;
1905 slidenode.
tolerance = this->ParseArgFloat(itor->substr(1));
1907 in_rail_node_list =
false;
1912 in_rail_node_list =
false;
1915 slidenode.
railgroup_id = this->ParseArgFloat(itor->substr(1));
1917 in_rail_node_list =
false;
1922 in_rail_node_list =
false;
1925 switch (itor->at(1))
1941 fmt::format(
"Ignoring invalid option '{}'", itor->at(1)));
1944 in_rail_node_list =
false;
1947 if (in_rail_node_list)
1953 m_current_module->slidenodes.push_back(slidenode);
1956 void Parser::ParseShock3()
1958 if (! this->CheckNumArguments(15)) {
return; }
1964 shock_3.
nodes[0] = this->GetArgNodeRef( 0);
1965 shock_3.
nodes[1] = this->GetArgNodeRef( 1);
1966 shock_3.
spring_in = this->GetArgFloat ( 2);
1967 shock_3.
damp_in = this->GetArgFloat ( 3);
1972 shock_3.
damp_out = this->GetArgFloat ( 8);
1980 if (m_num_args > 15) shock_3.
options = this->GetArgShock3Options(15);
1982 m_current_module->shocks3.push_back(shock_3);
1985 void Parser::ParseShock2()
1987 if (! this->CheckNumArguments(13)) {
return; }
1993 shock_2.
nodes[0] = this->GetArgNodeRef( 0);
1994 shock_2.
nodes[1] = this->GetArgNodeRef( 1);
1995 shock_2.
spring_in = this->GetArgFloat ( 2);
1996 shock_2.
damp_in = this->GetArgFloat ( 3);
2000 shock_2.
damp_out = this->GetArgFloat ( 7);
2007 if (m_num_args > 13) shock_2.
options = this->GetArgShock2Options(13);
2009 m_current_module->shocks2.push_back(shock_2);
2012 void Parser::ParseShock()
2014 if (! this->CheckNumArguments(7)) {
return; }
2020 shock.
nodes[0] = this->GetArgNodeRef(0);
2021 shock.
nodes[1] = this->GetArgNodeRef(1);
2023 shock.
damping = this->GetArgFloat (3);
2027 if (m_num_args > 7) shock.
options = this->GetArgShockOptions(7);
2029 m_current_module->shocks.push_back(shock);
2032 Node::Ref Parser::_ParseNodeRef(std::string
const & node_id_str)
2034 if (m_sequential_importer.IsEnabled())
2037 int node_id_num =
PARSEINT(node_id_str);
2038 if (node_id_num < 0)
2044 unsigned int flags = Node::Ref::IMPORT_STATE_IS_VALID |
2045 Node::Ref::REGULAR_STATE_IS_VALID | Node::Ref::REGULAR_STATE_IS_NAMED;
2046 if (m_any_named_node_defined)
2048 flags |= Node::Ref::IMPORT_STATE_MUST_CHECK_NAMED_FIRST;
2050 return Node::Ref(node_id_str, node_id_num, flags, m_current_line_number);
2055 return Node::Ref(node_id_str, 0, Node::Ref::REGULAR_STATE_IS_VALID | Node::Ref::REGULAR_STATE_IS_NAMED, m_current_line_number);
2059 void Parser::ParseDirectiveSetDefaultMinimass()
2061 if (! this->CheckNumArguments(2)) {
return; }
2063 m_set_default_minimass = std::shared_ptr<DefaultMinimass>(
new DefaultMinimass());
2064 m_set_default_minimass->min_mass_Kg = this->GetArgFloat(1);
2067 void Parser::ParseDirectiveSetInertiaDefaults()
2069 if (! this->CheckNumArguments(2)) {
return; }
2071 float start_delay = this->GetArgFloat(1);
2072 float stop_delay = 0;
2073 if (m_num_args > 2) { stop_delay = this->GetArgFloat(2); }
2075 if (start_delay < 0 || stop_delay < 0)
2077 m_user_default_inertia = m_ror_default_inertia;
2087 if (m_num_args > 4) { i->
stop_function = this->GetArgStr(4); }
2089 m_user_default_inertia = std::shared_ptr<Inertia>(i);
2092 void Parser::ParseScrewprops()
2094 if (! this->CheckNumArguments(4)) {
return; }
2098 screwprop.
prop_node = this->GetArgNodeRef(0);
2099 screwprop.
back_node = this->GetArgNodeRef(1);
2100 screwprop.
top_node = this->GetArgNodeRef(2);
2101 screwprop.
power = this->GetArgFloat (3);
2103 m_current_module->screwprops.push_back(screwprop);
2106 void Parser::ParseScripts()
2108 if (!this->CheckNumArguments(1)) {
return; }
2112 script.
filename = this->GetArgStr(0);
2114 m_current_module->scripts.push_back(script);
2117 void Parser::ParseRotatorsUnified()
2119 if (! this->CheckNumArguments(13)) {
return; }
2124 rotator.
axis_nodes[0] = this->GetArgNodeRef( 0);
2125 rotator.
axis_nodes[1] = this->GetArgNodeRef( 1);
2134 rotator.
rate = this->GetArgFloat (10);
2140 if (m_current_block == Keyword::ROTATORS2)
2142 if (! this->CheckNumArguments(16)) {
return; }
2143 if (m_num_args > 13) { rotator.
rotating_force = this->GetArgFloat(13); }
2144 if (m_num_args > 14) { rotator.
tolerance = this->GetArgFloat(14); }
2145 if (m_num_args > 15) { rotator.
description = this->GetArgStr (15); }
2150 this->ParseOptionalInertia(rotator.
inertia, 13 + offset);
2151 if (m_num_args > 17 + offset) { rotator.
engine_coupling = this->GetArgFloat(17 + offset); }
2152 if (m_num_args > 18 + offset) { rotator.
needs_engine = this->GetArgBool (18 + offset); }
2154 if (m_current_block == Keyword::ROTATORS2)
2156 m_current_module->rotators2.push_back(rotator);
2160 m_current_module->rotators.push_back(rotator);
2164 void Parser::ParseFileinfo()
2166 if (! this->CheckNumArguments(2)) {
return; }
2170 fileinfo.
unique_id = this->GetArgStr(1);
2171 Ogre::StringUtil::trim(fileinfo.
unique_id);
2173 if (m_num_args > 2) { fileinfo.
category_id = this->GetArgInt(2); }
2174 if (m_num_args > 3) { fileinfo.
file_version = this->GetArgInt(3); }
2176 m_current_module->fileinfo.push_back(fileinfo);
2178 m_current_block = Keyword::INVALID;
2181 void Parser::ParseRopes()
2183 if (! this->CheckNumArguments(2)) {
return; }
2188 rope.
root_node = this->GetArgNodeRef(0);
2189 rope.
end_node = this->GetArgNodeRef(1);
2191 if (m_num_args > 2) { rope.
invisible = (this->GetArgChar(2) ==
'i'); }
2193 m_current_module->ropes.push_back(rope);
2196 void Parser::ParseRopables()
2198 if (! this->CheckNumArguments(1)) {
return; }
2201 ropable.
node = this->GetArgNodeRef(0);
2203 if (m_num_args > 1) { ropable.
group = this->GetArgInt(1); }
2204 if (m_num_args > 2) { ropable.
has_multilock = (this->GetArgInt(2) == 1); }
2206 m_current_module->ropables.push_back(ropable);
2209 void Parser::ParseRailGroups()
2211 Ogre::StringVector args = Ogre::StringUtil::split(m_current_line,
",");
2212 m_num_args = (int)args.size();
2213 if (! this->CheckNumArguments(3)) {
return; }
2216 railgroup.
id = this->ParseArgInt(args[0].c_str());
2218 for (
auto itor = args.begin() + 1; itor != args.end(); itor++)
2220 railgroup.
node_list.push_back( this->_ParseNodeRef(*itor));
2223 m_current_module->railgroups.push_back(railgroup);
2226 void Parser::ParseProps()
2228 if (! this->CheckNumArguments(10)) {
return; }
2234 prop.
offset.x = this->GetArgFloat (3);
2235 prop.
offset.y = this->GetArgFloat (4);
2236 prop.
offset.z = this->GetArgFloat (5);
2237 prop.
rotation.x = this->GetArgFloat (6);
2238 prop.
rotation.y = this->GetArgFloat (7);
2239 prop.
rotation.z = this->GetArgFloat (8);
2243 if ((prop.
special == SpecialProp::BEACON) && (m_num_args >= 14))
2249 this->GetArgFloat(11), this->GetArgFloat(12), this->GetArgFloat(13));
2251 else if (prop.
special == SpecialProp::DASHBOARD_LEFT ||
2252 prop.
special == SpecialProp::DASHBOARD_RIGHT)
2255 if (m_num_args > 13)
2263 m_current_module->props.push_back(prop);
2266 void Parser::ParsePistonprops()
2268 if (!this->CheckNumArguments(10)) {
return; }
2272 pistonprop.
axis_node = this->GetArgNodeRef (1);
2277 pistonprop.
couple_node = this->GetArgNullableNode(6);
2279 pistonprop.
pitch = this->GetArgFloat (8);
2280 pistonprop.
airfoil = this->GetArgStr (9);
2282 m_current_module->pistonprops.push_back(pistonprop);
2286 void Parser::ParseParticles()
2288 if (!this->CheckNumArguments(3)) {
return; }
2295 m_current_module->particles.push_back(particle);
2299 void Parser::_TrimTrailingComments(std::string
const & line_in, std::string & line_out)
2303 int comment_start =
static_cast<int>(line_in.find_first_of(
";"));
2304 if (comment_start != Ogre::String::npos)
2306 line_out = line_in.substr(0, comment_start);
2310 comment_start =
static_cast<int>(line_in.find_last_of(
"/"));
2311 if (comment_start != Ogre::String::npos)
2313 while (comment_start >= 0)
2315 char c = line_in[comment_start - 1];
2316 if (c !=
'/' && c !=
' ' && c !=
'\t')
2322 line_out = line_in.substr(0, comment_start);
2329 void Parser::ParseNodesUnified()
2331 if (! this->CheckNumArguments(4)) {
return; }
2339 if (m_current_block == Keyword::NODES2)
2341 std::string node_name = this->GetArgStr(0);
2343 if (m_sequential_importer.IsEnabled())
2345 m_sequential_importer.AddNamedNode(node_name);
2347 m_any_named_node_defined =
true;
2351 const unsigned int node_num = this->GetArgUint(0);
2353 if (m_sequential_importer.IsEnabled())
2355 m_sequential_importer.AddNumberedNode(node_num);
2359 node.
position.x = this->GetArgFloat(1);
2360 node.
position.y = this->GetArgFloat(2);
2361 node.
position.z = this->GetArgFloat(3);
2364 node.
options = this->GetArgNodeOptions(4);
2368 if (node.
options & Node::OPTION_l_LOAD_WEIGHT)
2376 "Node has load-weight-override value specified, but option 'l' is not present. Ignoring value...");
2380 m_current_module->nodes.push_back(node);
2383 void Parser::ParseMinimass()
2385 if (! this->CheckNumArguments(1)) {
return; }
2389 if (m_num_args > 1) { mm.
option = this->GetArgMinimassOption(1); }
2391 m_current_module->minimass.push_back(mm);
2392 m_current_block = Keyword::INVALID;
2395 void Parser::ParseFlexBodyWheel()
2397 if (! this->CheckNumArguments(16)) {
return; }
2403 flexbody_wheel.
tyre_radius = this->GetArgFloat ( 0);
2404 flexbody_wheel.
rim_radius = this->GetArgFloat ( 1);
2405 flexbody_wheel.
width = this->GetArgFloat ( 2);
2406 flexbody_wheel.
num_rays = this->GetArgInt ( 3);
2407 flexbody_wheel.
nodes[0] = this->GetArgNodeRef ( 4);
2408 flexbody_wheel.
nodes[1] = this->GetArgNodeRef ( 5);
2409 flexbody_wheel.
rigidity_node = this->GetArgRigidityNode ( 6);
2410 flexbody_wheel.
braking = this->GetArgBraking ( 7);
2411 flexbody_wheel.
propulsion = this->GetArgPropulsion ( 8);
2413 flexbody_wheel.
mass = this->GetArgFloat (10);
2417 flexbody_wheel.
rim_damping = this->GetArgFloat (14);
2418 flexbody_wheel.
side = this->GetArgWheelSide (15);
2420 if (m_num_args > 16) { flexbody_wheel.
rim_mesh_name = this->GetArgStr(16); }
2421 if (m_num_args > 17) { flexbody_wheel.
tyre_mesh_name = this->GetArgStr(17); }
2423 if (m_sequential_importer.IsEnabled())
2428 m_current_module->flexbodywheels.push_back(flexbody_wheel);
2431 void Parser::ParseMaterialFlareBindings()
2433 if (! this->CheckNumArguments(2)) {
return; }
2439 m_current_module->materialflarebindings.push_back(binding);
2442 void Parser::ParseManagedMaterials()
2444 if (! this->CheckNumArguments(2)) {
return; }
2447 managed_mat.
options = m_current_managed_material_options;
2448 managed_mat.
name = this->GetArgStr(0);
2449 managed_mat.
type = this->GetArgManagedMatType(1);
2451 if (managed_mat.
type != ManagedMaterialType::INVALID)
2453 if (! this->CheckNumArguments(3)) {
return; }
2457 if (managed_mat.
type == ManagedMaterialType::MESH_STANDARD ||
2458 managed_mat.
type == ManagedMaterialType::MESH_TRANSPARENT)
2460 if (m_num_args > 3) { managed_mat.
specular_map = this->GetArgManagedTex(3); }
2462 else if (managed_mat.
type == ManagedMaterialType::FLEXMESH_STANDARD ||
2463 managed_mat.
type == ManagedMaterialType::FLEXMESH_TRANSPARENT)
2466 if (m_num_args > 4) { managed_mat.
specular_map = this->GetArgManagedTex(4); }
2469 m_current_module->managedmaterials.push_back(managed_mat);
2473 void Parser::ParseLockgroups()
2475 if (! this->CheckNumArguments(2)) {
return; }
2478 lockgroup.
number = this->GetArgInt(0);
2480 for (
int i = 1; i < m_num_args; ++i)
2482 lockgroup.
nodes.push_back(this->GetArgNodeRef(i));
2485 m_current_module->lockgroups.push_back(lockgroup);
2488 void Parser::ParseHydros()
2490 if (! this->CheckNumArguments(3)) {
return; }
2497 hydro.
nodes[0] = this->GetArgNodeRef(0);
2498 hydro.
nodes[1] = this->GetArgNodeRef(1);
2501 if (m_num_args > 3) { hydro.
options = this->GetArgHydroOptions(3); }
2505 hydro.
options |= Hydro::OPTION_n_INPUT_NORMAL;
2508 this->ParseOptionalInertia(hydro.
inertia, 4);
2510 m_current_module->hydros.push_back(hydro);
2513 void Parser::ParseOptionalInertia(
Inertia & inertia,
int index)
2516 if (m_num_args > index) { inertia.
stop_delay_factor = this->GetArgFloat(index++); }
2517 if (m_num_args > index) { inertia.
start_function = this->GetArgStr (index++); }
2518 if (m_num_args > index) { inertia.
stop_function = this->GetArgStr (index++); }
2523 for (
char c: options_str)
2527 case (
char)DifferentialType::o_OPEN:
2528 case (
char)DifferentialType::l_LOCKED:
2529 case (
char)DifferentialType::s_SPLIT:
2530 case (
char)DifferentialType::v_VISCOUS:
2536 fmt::format(
"ignoring invalid differential type '{}'", c));
2542 void Parser::ParseBeams()
2544 if (! this->CheckNumArguments(2)) {
return; }
2547 beam.
defaults = m_user_beam_defaults;
2550 beam.
nodes[0] = this->GetArgNodeRef(0);
2551 beam.
nodes[1] = this->GetArgNodeRef(1);
2552 if (m_num_args > 2) beam.
options = this->GetArgBeamOptions(2);
2556 float support_break_limit = 0.0f;
2557 float support_break_factor = this->GetArgInt(3);
2558 if (support_break_factor > 0.0f)
2560 support_break_limit = support_break_factor;
2566 m_current_module->beams.push_back(beam);
2569 void Parser::ParseAnimator()
2571 auto args = Ogre::StringUtil::split(m_current_line,
",");
2572 if (args.size() < 4) {
return; }
2579 animator.
nodes[0] = this->_ParseNodeRef(args[0]);
2580 animator.
nodes[1] = this->_ParseNodeRef(args[1]);
2584 Ogre::StringVector attrs = Ogre::StringUtil::split(args[3],
"|");
2586 auto itor = attrs.begin();
2587 auto endi = attrs.end();
2588 for (; itor != endi; ++itor)
2590 Ogre::String token = *itor;
2591 Ogre::StringUtil::trim(token);
2592 std::smatch results;
2593 bool is_shortlimit =
false;
2596 if (std::regex_search(token, results, Regexes::PARSE_ANIMATORS_NUMBERED_KEYWORD))
2598 if (results[1] ==
"throttle") animator.
aero_animator.
flags |= AeroAnimator::OPTION_THROTTLE;
2599 else if (results[1] ==
"rpm") animator.
aero_animator.
flags |= AeroAnimator::OPTION_RPM;
2600 else if (results[1] ==
"aerotorq") animator.
aero_animator.
flags |= AeroAnimator::OPTION_TORQUE;
2601 else if (results[1] ==
"aeropit") animator.
aero_animator.
flags |= AeroAnimator::OPTION_PITCH;
2602 else if (results[1] ==
"aerostatus") animator.
aero_animator.
flags |= AeroAnimator::OPTION_STATUS;
2606 else if ((is_shortlimit = (token.compare(0, 10,
"shortlimit") == 0)) || (token.compare(0, 9,
"longlimit") == 0))
2608 Ogre::StringVector fields = Ogre::StringUtil::split(token,
":");
2609 if (fields.size() > 1)
2613 animator.
short_limit = std::strtod(fields[1].c_str(),
nullptr);
2614 animator.
flags |= Animator::OPTION_SHORT_LIMIT;
2618 animator.
long_limit = std::strtod(fields[1].c_str(),
nullptr);
2619 animator.
flags |= Animator::OPTION_LONG_LIMIT;
2626 if (token ==
"vis") animator.
flags |= Animator::OPTION_VISIBLE;
2627 else if (token ==
"inv") animator.
flags |= Animator::OPTION_INVISIBLE;
2628 else if (token ==
"airspeed") animator.
flags |= Animator::OPTION_AIRSPEED;
2629 else if (token ==
"vvi") animator.
flags |= Animator::OPTION_VERTICAL_VELOCITY;
2630 else if (token ==
"altimeter100k") animator.
flags |= Animator::OPTION_ALTIMETER_100K;
2631 else if (token ==
"altimeter10k") animator.
flags |= Animator::OPTION_ALTIMETER_10K;
2632 else if (token ==
"altimeter1k") animator.
flags |= Animator::OPTION_ALTIMETER_1K;
2633 else if (token ==
"aoa") animator.
flags |= Animator::OPTION_ANGLE_OF_ATTACK;
2634 else if (token ==
"flap") animator.
flags |= Animator::OPTION_FLAP;
2635 else if (token ==
"airbrake") animator.
flags |= Animator::OPTION_AIR_BRAKE;
2636 else if (token ==
"roll") animator.
flags |= Animator::OPTION_ROLL;
2637 else if (token ==
"pitch") animator.
flags |= Animator::OPTION_PITCH;
2638 else if (token ==
"brakes") animator.
flags |= Animator::OPTION_BRAKES;
2639 else if (token ==
"accel") animator.
flags |= Animator::OPTION_ACCEL;
2640 else if (token ==
"clutch") animator.
flags |= Animator::OPTION_CLUTCH;
2641 else if (token ==
"speedo") animator.
flags |= Animator::OPTION_SPEEDO;
2642 else if (token ==
"tacho") animator.
flags |= Animator::OPTION_TACHO;
2643 else if (token ==
"turbo") animator.
flags |= Animator::OPTION_TURBO;
2644 else if (token ==
"parking") animator.
flags |= Animator::OPTION_PARKING;
2645 else if (token ==
"shifterman1") animator.
flags |= Animator::OPTION_SHIFT_LEFT_RIGHT;
2646 else if (token ==
"shifterman2") animator.
flags |= Animator::OPTION_SHIFT_BACK_FORTH;
2647 else if (token ==
"sequential") animator.
flags |= Animator::OPTION_SEQUENTIAL_SHIFT;
2648 else if (token ==
"shifterlin") animator.
flags |= Animator::OPTION_GEAR_SELECT;
2649 else if (token ==
"torque") animator.
flags |= Animator::OPTION_TORQUE;
2650 else if (token ==
"difflock") animator.
flags |= Animator::OPTION_DIFFLOCK;
2651 else if (token ==
"rudderboat") animator.
flags |= Animator::OPTION_BOAT_RUDDER;
2652 else if (token ==
"throttleboat") animator.
flags |= Animator::OPTION_BOAT_THROTTLE;
2656 m_current_module->animators.push_back(animator);
2659 void Parser::ParseAuthor()
2661 if (! this->CheckNumArguments(2)) {
return; }
2664 if (m_num_args > 1) { author.
type = this->GetArgStr(1); }
2666 if (m_num_args > 3) { author.
name = this->GetArgStr(3); }
2667 if (m_num_args > 4) { author.
email = this->GetArgStr(4); }
2669 m_current_module->author.push_back(author);
2670 m_current_block = Keyword::INVALID;
2683 m_filename, m_current_line_number,
KeywordToString(m_log_keyword), msg));
2686 Keyword Parser::IdentifyKeyword(
const std::string& line)
2689 std::smatch results;
2690 std::regex_search(line, results, Regexes::IDENTIFY_KEYWORD_IGNORE_CASE);
2694 for (
unsigned int i = 1; i < results.size(); i++)
2696 std::ssub_match sub = results[i];
2704 return Keyword::INVALID;
2707 void Parser::Prepare()
2709 m_current_block = Keyword::INVALID;
2710 m_current_line_number = 1;
2712 m_any_named_node_defined =
false;
2713 m_current_detacher_group = 0;
2715 m_user_default_inertia = m_ror_default_inertia;
2716 m_user_node_defaults = m_ror_node_defaults;
2719 m_user_beam_defaults = std::shared_ptr<BeamDefaults>(
new BeamDefaults);
2722 m_user_beam_defaults->deformation_threshold =
BEAM_DEFORM;
2723 m_user_beam_defaults->breaking_threshold =
BEAM_BREAK;
2726 m_root_module = m_definition->root_module;
2727 m_current_module = m_definition->root_module;
2729 m_sequential_importer.Init(
true);
2734 if (
keyword == Keyword::INVALID)
2737 if (m_current_submesh !=
nullptr)
2739 m_current_module->submeshes.push_back(*m_current_submesh);
2740 m_current_submesh.reset();
2744 if (m_current_camera_rail !=
nullptr)
2746 if (m_current_camera_rail->nodes.size() == 0)
2752 m_current_module->camerarail.push_back(*m_current_camera_rail);
2753 m_current_camera_rail.reset();
2757 else if (
keyword == Keyword::CAMERARAIL)
2759 this->BeginBlock(Keyword::INVALID);
2760 m_current_camera_rail = std::shared_ptr<CameraRail>(
new CameraRail() );
2768 std::string new_module_name;
2769 if (
keyword == Keyword::END_SECTION)
2771 if (m_current_module == m_root_module)
2778 else if (
keyword == Keyword::SECTION)
2780 if (!this->CheckNumArguments(3))
2785 new_module_name = this->GetArgStr(2);
2786 if (new_module_name == m_current_module->name)
2794 this->BeginBlock(Keyword::INVALID);
2798 m_current_module = m_root_module;
2802 auto search_itor = m_definition->user_modules.find(new_module_name);
2803 if (search_itor != m_definition->user_modules.end())
2805 m_current_module = search_itor->second;
2809 m_current_module = std::make_shared<Document::Module>(new_module_name);
2810 m_definition->user_modules.insert(std::make_pair(new_module_name, m_current_module));
2814 void Parser::ParseDirectiveSection()
2816 this->ProcessChangeModuleLine(Keyword::SECTION);
2819 void Parser::ParseDirectiveSectionConfig()
2824 void Parser::Finalize()
2826 this->BeginBlock(Keyword::INVALID);
2828 if (m_sequential_importer.IsEnabled())
2830 m_sequential_importer.Process( m_definition );
2834 std::string Parser::GetArgStr(
int index)
2836 return std::string(m_args[index].start, m_args[index].length);
2839 char Parser::GetArgChar(
int index)
2841 return *(m_args[index].start);
2846 char c = this->GetArgChar(index);
2855 fmt::format(
"Bad arg~{} 'side' (value: {}), parsing as 'l' for backwards compatibility.", index + 1, c));
2860 long Parser::GetArgLong(
int index)
2863 char* out_end =
nullptr;
2864 long res = std::strtol(m_args[index].start, &out_end, 10);
2868 fmt::format(
"Cannot parse argument [{}] as integer, errno: {}", index + 1, errno));
2871 if (out_end == m_args[index].start)
2874 fmt::format(
"Argument [{}] is not valid integer", index + 1));
2877 else if (out_end != (m_args[index].start + m_args[index].length))
2880 fmt::format(
"Integer argument [{}] has invalid trailing characters", index + 1));
2885 int Parser::GetArgInt(
int index)
2887 return static_cast<int>(this->GetArgLong(index));
2892 std::string rigidity_node = this->GetArgStr(index);
2893 if (rigidity_node !=
"9999")
2895 return this->GetArgNodeRef(index);
2902 int p = this->GetArgInt(index);
2905 case (
int)WheelPropulsion::NONE:
2906 case (
int)WheelPropulsion::FORWARD:
2907 case (
int)WheelPropulsion::BACKWARD:
2912 fmt::format(
"Bad value of param ~{} (propulsion), using 0 (no propulsion)", index + 1));
2913 return WheelPropulsion::NONE;
2919 int b = this->GetArgInt(index);
2922 case (
int)WheelBraking::NONE:
2923 case (
int)WheelBraking::FOOT_HAND:
2924 case (
int)WheelBraking::FOOT_HAND_SKID_LEFT:
2925 case (
int)WheelBraking::FOOT_HAND_SKID_RIGHT:
2926 case (
int)WheelBraking::FOOT_ONLY:
2931 fmt::format(
"Bad value of param ~{} (braking), using 0 (not braked)", index + 1));
2932 return WheelBraking::NONE;
2938 return this->_ParseNodeRef(this->GetArgStr(index));
2943 if (! (Ogre::StringConverter::parseReal(this->GetArgStr(index)) == -1.f))
2945 return this->GetArgNodeRef(index);
2950 unsigned Parser::GetArgUint(
int index)
2952 return static_cast<unsigned>(this->GetArgLong(index));
2957 char in = this->GetArgChar(index);
2978 fmt::format(
"Invalid flare type '{}', falling back to type 'f' (front light)...", in));
2985 std::string str = this->GetArgStr(index);
2991 fmt::format(
"Invalid ExtCameraMode '{}', falling back to type 'classic'...", str));
2995 float Parser::GetArgFloat(
int index)
2997 return (
float) Ogre::StringConverter::parseReal(this->GetArgStr(index), 0.f);
3000 float Parser::ParseArgFloat(
const char* str)
3002 return (
float) Ogre::StringConverter::parseReal(str, 0.f);
3005 float Parser::ParseArgFloat(std::string
const & str)
3007 return this->ParseArgFloat(str.c_str());
3010 unsigned Parser::ParseArgUint(
const char* str)
3013 long res = std::strtol(str,
nullptr, 10);
3017 fmt::format(
"Cannot parse argument '{}' as int, errno: {}", str, errno));
3020 return static_cast<unsigned>(res);
3023 unsigned Parser::ParseArgUint(std::string
const & str)
3025 return this->ParseArgUint(str.c_str());
3028 int Parser::ParseArgInt(
const char* str)
3030 return static_cast<int>(this->ParseArgUint(str));
3033 bool Parser::GetArgBool(
int index)
3035 return Ogre::StringConverter::parseBool(this->GetArgStr(index));
3040 char c = this->GetArgChar(index);
3043 case (
char)WingControlSurface::n_NONE:
3044 case (
char)WingControlSurface::a_RIGHT_AILERON:
3045 case (
char)WingControlSurface::b_LEFT_AILERON:
3046 case (
char)WingControlSurface::f_FLAP:
3047 case (
char)WingControlSurface::e_ELEVATOR:
3048 case (
char)WingControlSurface::r_RUDDER:
3049 case (
char)WingControlSurface::S_RIGHT_HAND_STABILATOR:
3050 case (
char)WingControlSurface::T_LEFT_HAND_STABILATOR:
3051 case (
char)WingControlSurface::c_RIGHT_ELEVON:
3052 case (
char)WingControlSurface::d_LEFT_ELEVON:
3053 case (
char)WingControlSurface::g_RIGHT_FLAPERON:
3054 case (
char)WingControlSurface::h_LEFT_FLAPERON:
3055 case (
char)WingControlSurface::U_RIGHT_HAND_TAILERON:
3056 case (
char)WingControlSurface::V_LEFT_HAND_TAILERON:
3057 case (
char)WingControlSurface::i_RIGHT_RUDDERVATOR:
3058 case (
char)WingControlSurface::j_LEFT_RUDDERVATOR:
3062 fmt::format(
"invalid WingControlSurface '{}', falling back to 'n' (none)", c);
3063 return WingControlSurface::n_NONE;
3067 std::string Parser::GetArgManagedTex(
int index)
3069 std::string tex_name = this->GetArgStr(index);
3070 return (tex_name.at(0) !=
'-') ? tex_name :
"";
3075 switch (this->GetArgStr(index)[0])
3077 case (
char)MinimassOption::l_SKIP_LOADED:
3078 return MinimassOption::l_SKIP_LOADED;
3080 case (
char)MinimassOption::n_DUMMY:
3081 return MinimassOption::n_DUMMY;
3085 fmt::format(
"Not a valid minimass option: {}, falling back to 'n' (dummy)", this->GetArgStr(index)));
3086 return MinimassOption::n_DUMMY;
3093 for (
char c: this->GetArgStr(index))
3097 case (
char)CabOption::c_CONTACT: ret |= Cab::OPTION_c_CONTACT ;
break;
3098 case (
char)CabOption::b_BUOYANT: ret |= Cab::OPTION_b_BUOYANT ;
break;
3099 case (
char)CabOption::p_10xTOUGHER: ret |= Cab::OPTION_p_10xTOUGHER ;
break;
3100 case (
char)CabOption::u_INVULNERABLE: ret |= Cab::OPTION_u_INVULNERABLE ;
break;
3101 case (
char)CabOption::s_BUOYANT_NO_DRAG: ret |= Cab::OPTION_s_BUOYANT_NO_DRAG ;
break;
3102 case (
char)CabOption::r_BUOYANT_ONLY_DRAG: ret |= Cab::OPTION_r_BUOYANT_ONLY_DRAG ;
break;
3103 case (
char)CabOption::D_CONTACT_BUOYANT: ret |= Cab::OPTION_D_CONTACT_BUOYANT ;
break;
3104 case (
char)CabOption::F_10xTOUGHER_BUOYANT: ret |= Cab::OPTION_F_10xTOUGHER_BUOYANT ;
break;
3105 case (
char)CabOption::S_INVULNERABLE_BUOYANT: ret |= Cab::OPTION_S_INVULNERABLE_BUOYANT;
break;
3118 for (
char c: this->GetArgStr(index))
3122 case (
char)TriggerOption::i_INVISIBLE : ret |= Trigger::OPTION_i_INVISIBLE;
break;
3123 case (
char)TriggerOption::c_COMMAND_STYLE : ret |= Trigger::OPTION_c_COMMAND_STYLE;
break;
3124 case (
char)TriggerOption::x_START_DISABLED : ret |= Trigger::OPTION_x_START_DISABLED;
break;
3125 case (
char)TriggerOption::b_KEY_BLOCKER : ret |= Trigger::OPTION_b_KEY_BLOCKER;
break;
3126 case (
char)TriggerOption::B_TRIGGER_BLOCKER : ret |= Trigger::OPTION_B_TRIGGER_BLOCKER;
break;
3127 case (
char)TriggerOption::A_INV_TRIGGER_BLOCKER: ret |= Trigger::OPTION_A_INV_TRIGGER_BLOCKER;
break;
3128 case (
char)TriggerOption::s_CMD_NUM_SWITCH : ret |= Trigger::OPTION_s_CMD_NUM_SWITCH;
break;
3129 case (
char)TriggerOption::h_UNLOCKS_HOOK_GROUP : ret |= Trigger::OPTION_h_UNLOCKS_HOOK_GROUP;
break;
3130 case (
char)TriggerOption::H_LOCKS_HOOK_GROUP : ret |= Trigger::OPTION_H_LOCKS_HOOK_GROUP;
break;
3131 case (
char)TriggerOption::t_CONTINUOUS : ret |= Trigger::OPTION_t_CONTINUOUS;
break;
3132 case (
char)TriggerOption::E_ENGINE_TRIGGER : ret |= Trigger::OPTION_E_ENGINE_TRIGGER;
break;
3145 for (
char c: this->GetArgStr(index))
3149 case (
char)BeamOption::i_INVISIBLE: ret |= Beam::OPTION_i_INVISIBLE;
break;
3150 case (
char)BeamOption::r_ROPE : ret |= Beam::OPTION_r_ROPE ;
break;
3151 case (
char)BeamOption::s_SUPPORT : ret |= Beam::OPTION_s_SUPPORT ;
break;
3153 case (
char)BeamOption::v_DUMMY:
break;
3166 for (
char c: this->GetArgStr(index))
3170 case (
char)HydroOption::j_INVISIBLE : ret |= Hydro::OPTION_j_INVISIBLE ;
break;
3171 case (
char)HydroOption::s_DISABLE_ON_HIGH_SPEED : ret |= Hydro::OPTION_s_DISABLE_ON_HIGH_SPEED ;
break;
3172 case (
char)HydroOption::a_INPUT_AILERON : ret |= Hydro::OPTION_a_INPUT_AILERON ;
break;
3173 case (
char)HydroOption::r_INPUT_RUDDER : ret |= Hydro::OPTION_r_INPUT_RUDDER ;
break;
3174 case (
char)HydroOption::e_INPUT_ELEVATOR : ret |= Hydro::OPTION_e_INPUT_ELEVATOR ;
break;
3175 case (
char)HydroOption::u_INPUT_AILERON_ELEVATOR : ret |= Hydro::OPTION_u_INPUT_AILERON_ELEVATOR ;
break;
3176 case (
char)HydroOption::v_INPUT_InvAILERON_ELEVATOR: ret |= Hydro::OPTION_v_INPUT_InvAILERON_ELEVATOR;
break;
3177 case (
char)HydroOption::x_INPUT_AILERON_RUDDER : ret |= Hydro::OPTION_x_INPUT_AILERON_RUDDER ;
break;
3178 case (
char)HydroOption::y_INPUT_InvAILERON_RUDDER : ret |= Hydro::OPTION_y_INPUT_InvAILERON_RUDDER ;
break;
3179 case (
char)HydroOption::g_INPUT_ELEVATOR_RUDDER : ret |= Hydro::OPTION_g_INPUT_ELEVATOR_RUDDER ;
break;
3180 case (
char)HydroOption::h_INPUT_InvELEVATOR_RUDDER : ret |= Hydro::OPTION_h_INPUT_InvELEVATOR_RUDDER ;
break;
3181 case (
char)HydroOption::n_INPUT_NORMAL : ret |= Hydro::OPTION_n_INPUT_NORMAL ;
break;
3183 case (
char)HydroOption::i_INVISIBLE_INPUT_NORMAL:
3188 ret |= Hydro::OPTION_n_INPUT_NORMAL;
3190 ret |= Hydro::OPTION_j_INVISIBLE;
3205 for (
char c: this->GetArgStr(index))
3209 case (
char)ShockOption::i_INVISIBLE : ret |= Shock::OPTION_i_INVISIBLE ;
break;
3210 case (
char)ShockOption::L_ACTIVE_LEFT : ret |= Shock::OPTION_L_ACTIVE_LEFT ;
break;
3211 case (
char)ShockOption::R_ACTIVE_RIGHT : ret |= Shock::OPTION_R_ACTIVE_RIGHT;
break;
3212 case (
char)ShockOption::m_METRIC : ret |= Shock::OPTION_m_METRIC ;
break;
3214 case (
char)ShockOption::n_DUMMY:
break;
3215 case (
char)ShockOption::v_DUMMY:
break;
3228 for (
char c: this->GetArgStr(index))
3232 case (
char)Shock2Option::i_INVISIBLE: ret |= Shock2::OPTION_i_INVISIBLE;
break;
3233 case (
char)Shock2Option::s_SOFT_BUMP_BOUNDS: ret |= Shock2::OPTION_s_SOFT_BUMP_BOUNDS;
break;
3234 case (
char)Shock2Option::m_METRIC: ret |= Shock2::OPTION_m_METRIC;
break;
3235 case (
char)Shock2Option::M_ABSOLUTE_METRIC: ret |= Shock2::OPTION_M_ABSOLUTE_METRIC;
break;
3237 case (
char)Shock2Option::n_DUMMY:
break;
3238 case (
char)Shock2Option::v_DUMMY:
break;
3251 for (
char c: this->GetArgStr(index))
3255 case (
char)Shock3Option::i_INVISIBLE: ret |= Shock3::OPTION_i_INVISIBLE;
break;
3256 case (
char)Shock3Option::m_METRIC: ret |= Shock3::OPTION_m_METRIC;
break;
3257 case (
char)Shock3Option::M_ABSOLUTE_METRIC: ret |= Shock3::OPTION_M_ABSOLUTE_METRIC;
break;
3259 case (
char)Shock3Option::n_DUMMY:
break;
3260 case (
char)Shock3Option::v_DUMMY:
break;
3273 for (
char c: this->GetArgStr(index))
3277 case (
char)NodeOption::m_NO_MOUSE_GRAB : ret |= Node::OPTION_m_NO_MOUSE_GRAB ;
break;
3278 case (
char)NodeOption::f_NO_SPARKS : ret |= Node::OPTION_f_NO_SPARKS ;
break;
3279 case (
char)NodeOption::x_EXHAUST_POINT : ret |= Node::OPTION_x_EXHAUST_POINT ;
break;
3280 case (
char)NodeOption::y_EXHAUST_DIRECTION : ret |= Node::OPTION_y_EXHAUST_DIRECTION ;
break;
3281 case (
char)NodeOption::c_NO_GROUND_CONTACT : ret |= Node::OPTION_c_NO_GROUND_CONTACT ;
break;
3282 case (
char)NodeOption::h_HOOK_POINT : ret |= Node::OPTION_h_HOOK_POINT ;
break;
3283 case (
char)NodeOption::e_TERRAIN_EDIT_POINT: ret |= Node::OPTION_e_TERRAIN_EDIT_POINT;
break;
3284 case (
char)NodeOption::b_EXTRA_BUOYANCY : ret |= Node::OPTION_b_EXTRA_BUOYANCY ;
break;
3285 case (
char)NodeOption::p_NO_PARTICLES : ret |= Node::OPTION_p_NO_PARTICLES ;
break;
3286 case (
char)NodeOption::L_LOG : ret |= Node::OPTION_L_LOG ;
break;
3287 case (
char)NodeOption::l_LOAD_WEIGHT : ret |= Node::OPTION_l_LOAD_WEIGHT ;
break;
3289 case (
char)NodeOption::n_DUMMY:
break;
3301 if (str.find(
"leftmirror" ) != std::string::npos) {
return SpecialProp::MIRROR_LEFT; }
3302 if (str.find(
"rightmirror" ) != std::string::npos) {
return SpecialProp::MIRROR_RIGHT; }
3303 if (str.find(
"dashboard-rh") != std::string::npos) {
return SpecialProp::DASHBOARD_RIGHT; }
3304 if (str.find(
"dashboard" ) != std::string::npos) {
return SpecialProp::DASHBOARD_LEFT; }
3305 if (Ogre::StringUtil::startsWith(str,
"spinprop",
false) ) {
return SpecialProp::AERO_PROP_SPIN; }
3306 if (Ogre::StringUtil::startsWith(str,
"pale",
false) ) {
return SpecialProp::AERO_PROP_BLADE; }
3307 if (Ogre::StringUtil::startsWith(str,
"seat",
false) ) {
return SpecialProp::DRIVER_SEAT; }
3308 if (Ogre::StringUtil::startsWith(str,
"seat2",
false) ) {
return SpecialProp::DRIVER_SEAT_2; }
3309 if (Ogre::StringUtil::startsWith(str,
"beacon",
false) ) {
return SpecialProp::BEACON; }
3310 if (Ogre::StringUtil::startsWith(str,
"redbeacon",
false)) {
return SpecialProp::REDBEACON; }
3311 if (Ogre::StringUtil::startsWith(str,
"lightb",
false) ) {
return SpecialProp::LIGHTBAR; }
3312 return SpecialProp::NONE;
3317 char c = this->GetArgChar(index);
3320 case (
char)EngineType::t_TRUCK:
3321 case (
char)EngineType::c_CAR:
3322 case (
char)EngineType::e_ECAR:
3326 fmt::format(
"invalid EngineType '{}', falling back to 't' (truck)", c);
3327 return EngineType::t_TRUCK;
3333 std::string str = this->GetArgStr(index);
3334 if (str ==
"mesh_standard")
return ManagedMaterialType::MESH_STANDARD;
3335 if (str ==
"mesh_transparent")
return ManagedMaterialType::MESH_TRANSPARENT;
3336 if (str ==
"flexmesh_standard")
return ManagedMaterialType::FLEXMESH_STANDARD;
3337 if (str ==
"flexmesh_transparent")
return ManagedMaterialType::FLEXMESH_TRANSPARENT;
3340 fmt::format(
"Not a valid ManagedMaterialType: '{}'", str));
3341 return ManagedMaterialType::INVALID;
3344 int Parser::TokenizeCurrentLine()
3347 const char* cur_char = m_current_line;
3349 while ((*cur_char !=
'\0') && (cur_arg < Parser::LINE_MAX_ARGS))
3352 if ((arg_len == 0) && is_arg)
3354 m_args[cur_arg].start = cur_char;
3357 else if ((arg_len > 0) && !is_arg)
3359 m_args[cur_arg].length = arg_len;
3371 m_args[cur_arg].length = arg_len;
3375 m_num_args = cur_arg;
3379 void Parser::ProcessOgreStream(Ogre::DataStream* stream, Ogre::String resource_group)
3381 m_resource_group = resource_group;
3382 m_filename = stream->getName();
3384 char raw_line_buf[LINE_BUFFER_LENGTH];
3385 while (!stream->eof())
3389 stream->readLine(raw_line_buf, LINE_BUFFER_LENGTH);
3391 catch (Ogre::Exception &ex)
3394 fmt::format(
"Could not read truck file: {}", ex.getFullDescription()));
3398 this->ProcessRawLine(raw_line_buf);
3402 void Parser::ProcessRawLine(
const char* raw_line_buf)
3404 const char* raw_start = raw_line_buf;
3405 const char* raw_end = raw_line_buf +
strnlen(raw_line_buf, LINE_BUFFER_LENGTH);
3408 while (
IsWhitespace(*raw_start) && (raw_start != raw_end))
3414 if ((raw_start == raw_end) || (*raw_start ==
';') || (*raw_start ==
'/'))
3416 ++m_current_line_number;
3421 memset(m_current_line, 0, LINE_BUFFER_LENGTH);
3422 char* out_start = m_current_line;
3423 utf8::replace_invalid(raw_start, raw_end, out_start,
'?');
3426 this->ProcessCurrentLine();
3427 ++m_current_line_number;