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 ==
"torque") { animation.
source |= Animation::SOURCE_TORQUE; }
1188 else if (value ==
"heading") { animation.
source |= Animation::SOURCE_HEADING; }
1189 else if (value ==
"difflock") { animation.
source |= Animation::SOURCE_DIFFLOCK; }
1190 else if (value ==
"rudderboat") { animation.
source |= Animation::SOURCE_BOAT_RUDDER; }
1191 else if (value ==
"throttleboat") { animation.
source |= Animation::SOURCE_BOAT_THROTTLE; }
1192 else if (value ==
"steeringwheel") { animation.
source |= Animation::SOURCE_STEERING_WHEEL; }
1193 else if (value ==
"aileron") { animation.
source |= Animation::SOURCE_AILERON; }
1194 else if (value ==
"elevator") { animation.
source |= Animation::SOURCE_ELEVATOR; }
1195 else if (value ==
"rudderair") { animation.
source |= Animation::SOURCE_AIR_RUDDER; }
1196 else if (value ==
"permanent") { animation.
source |= Animation::SOURCE_PERMANENT; }
1197 else if (value ==
"event") { animation.
source |= Animation::SOURCE_EVENT; }
1198 else if (value ==
"dashboard") { animation.
source |= Animation::SOURCE_DASHBOARD; }
1199 else if (value ==
"signalstalk") { animation.
source |= Animation::SOURCE_SIGNALSTALK; }
1204 if (entry[1].compare(0, 8,
"throttle") == 0)
1206 motor_source.
source = Animation::MotorSource::SOURCE_AERO_THROTTLE;
1207 motor_source.
motor = this->ParseArgUint(entry[1].substr(8));
1209 else if (entry[1].compare(0, 3,
"rpm") == 0)
1211 motor_source.
source = Animation::MotorSource::SOURCE_AERO_RPM;
1212 motor_source.
motor = this->ParseArgUint(entry[1].substr(3));
1214 else if (entry[1].compare(0, 8,
"aerotorq") == 0)
1216 motor_source.
source = Animation::MotorSource::SOURCE_AERO_TORQUE;
1217 motor_source.
motor = this->ParseArgUint(entry[1].substr(8));
1219 else if (entry[1].compare(0, 7,
"aeropit") == 0)
1221 motor_source.
source = Animation::MotorSource::SOURCE_AERO_PITCH;
1222 motor_source.
motor = this->ParseArgUint(entry[1].substr(7));
1224 else if (entry[1].compare(0, 10,
"aerostatus") == 0)
1226 motor_source.
source = Animation::MotorSource::SOURCE_AERO_STATUS;
1227 motor_source.
motor = this->ParseArgUint(entry[1].substr(10));
1231 snprintf(warn_msg, WARN_LEN,
"Invalid 'source': %s, ignoring...", entry[1].c_str());
1240 snprintf(warn_msg, WARN_LEN,
"Invalid keyword: %s, ignoring...", entry[0].c_str());
1245 snprintf(warn_msg, WARN_LEN,
"Invalid item: %s, ignoring...", entry[0].c_str());
1248 if (warn_msg[0] !=
'\0')
1251 fmt::format(
"Ignoring invalid token '{}' ({})", itor->c_str(), warn_msg));
1255 m_current_module->props.back().animations.push_back(animation);
1258 void Parser::ParseAntiLockBrakes()
1261 Ogre::StringVector tokens = Ogre::StringUtil::split(m_current_line + 15,
",");
1262 m_num_args = (int)tokens.size();
1263 if (! this->CheckNumArguments(2)) {
return; }
1266 alb.
min_speed = this->ParseArgInt (tokens[1].c_str());
1268 if (tokens.size() > 3) { alb.
pulse_per_sec = this->ParseArgFloat(tokens[2].c_str()); }
1270 for (
unsigned int i=3; i<tokens.size(); i++)
1272 Ogre::StringVector args2 = Ogre::StringUtil::split(tokens[i],
":");
1273 Ogre::StringUtil::trim(args2[0]);
1274 Ogre::StringUtil::toLowerCase(args2[0]);
1275 if (args2[0] ==
"mode" && args2.size() == 2)
1277 Ogre::StringVector attrs = Ogre::StringUtil::split(args2[1],
"&");
1278 auto itor = attrs.begin();
1279 auto endi = attrs.end();
1280 for (; itor != endi; ++itor)
1282 std::string attr = *itor;
1283 Ogre::StringUtil::trim(attr);
1284 Ogre::StringUtil::toLowerCase(attr);
1286 else if (strncmp(attr.c_str(),
"notoggle", 8) == 0) { alb.
attr_no_toggle =
true; }
1287 else if (strncmp(attr.c_str(),
"on", 2) == 0) { alb.
attr_is_on =
true; }
1288 else if (strncmp(attr.c_str(),
"off", 3) == 0) { alb.
attr_is_on =
false; }
1300 m_current_module->antilockbrakes.push_back(alb);
1303 void Parser::ParseEngoption()
1305 if (! this->CheckNumArguments(1)) {
return; }
1308 engoption.
inertia = this->GetArgFloat(0);
1310 if (m_num_args > 1) { engoption.
type = this->GetArgEngineType(1); }
1311 if (m_num_args > 2) { engoption.
clutch_force = this->GetArgFloat(2); }
1312 if (m_num_args > 3) { engoption.
shift_time = this->GetArgFloat(3); }
1313 if (m_num_args > 4) { engoption.
clutch_time = this->GetArgFloat(4); }
1314 if (m_num_args > 5) { engoption.
post_shift_time = this->GetArgFloat(5); }
1315 if (m_num_args > 6) { engoption.
stall_rpm = this->GetArgFloat(6); }
1316 if (m_num_args > 7) { engoption.
idle_rpm = this->GetArgFloat(7); }
1319 if (m_num_args > 10){ engoption.
braking_torque = this->GetArgFloat(10);}
1321 m_current_module->engoption.push_back(engoption);
1324 void Parser::ParseEngturbo()
1326 if (! this->CheckNumArguments(4)) {
return; }
1329 engturbo.
version = this->GetArgInt ( 0);
1331 engturbo.
nturbos = this->GetArgInt ( 2);
1332 engturbo.
param1 = this->GetArgFloat( 3);
1334 if (m_num_args > 4) { engturbo.
param2 = this->GetArgFloat( 4); }
1335 if (m_num_args > 5) { engturbo.
param3 = this->GetArgFloat( 5); }
1336 if (m_num_args > 6) { engturbo.
param4 = this->GetArgFloat( 6); }
1337 if (m_num_args > 7) { engturbo.
param5 = this->GetArgFloat( 7); }
1338 if (m_num_args > 8) { engturbo.
param6 = this->GetArgFloat( 8); }
1339 if (m_num_args > 9) { engturbo.
param7 = this->GetArgFloat( 9); }
1340 if (m_num_args > 10) { engturbo.
param8 = this->GetArgFloat(10); }
1341 if (m_num_args > 11) { engturbo.
param9 = this->GetArgFloat(11); }
1342 if (m_num_args > 12) { engturbo.
param10 = this->GetArgFloat(12); }
1343 if (m_num_args > 13) { engturbo.
param11 = this->GetArgFloat(13); }
1351 m_current_module->engturbo.push_back(engturbo);
1354 void Parser::ParseEngine()
1356 if (! this->CheckNumArguments(6)) {
return; }
1361 engine.
torque = this->GetArgFloat(2);
1367 for (
int i = 6; i < m_num_args; i++)
1369 float ratio = this->GetArgFloat(i);
1383 m_current_module->engine.push_back(engine);
1386 void Parser::ParseContacter()
1388 if (! this->CheckNumArguments(1)) {
return; }
1390 m_current_module->contacters.push_back(this->GetArgNodeRef(0));
1393 void Parser::ParseCommandsUnified()
1395 const bool is_commands2 = (m_current_block == Keyword::COMMANDS2);
1396 const int max_args = (is_commands2 ? 8 : 7);
1397 if (! this->CheckNumArguments(max_args)) {
return; }
1405 command2.
nodes[0] = this->GetArgNodeRef(pos++);
1406 command2.
nodes[1] = this->GetArgNodeRef(pos++);
1421 command2.
extend_key = this->GetArgInt (pos++);
1423 if (m_num_args <= max_args)
1425 m_current_module->commands2.push_back(command2);
1430 std::string options_str = this->GetArgStr(pos++);
1432 for (
auto itor = options_str.begin(); itor != options_str.end(); ++itor)
1434 const char c = *itor;
1435 if ((winner == 0) && (c ==
'o' || c ==
'p' || c ==
'c')) { winner = c; }
1470 if (
ignored != 0 && winner ==
'c')
1473 "Command cannot be one-pressed and self centering at the same time, ignoring flag '%c'");
1475 else if (
ignored != 0 && (winner ==
'o' || winner ==
'p'))
1478 "Command already has a one-pressed c.mode, ignoring flag '%c'");
1481 if (m_num_args > pos) { command2.
description = this->GetArgStr (pos++);}
1483 if (m_num_args > pos) { ParseOptionalInertia(command2.
inertia, pos); pos += 4; }
1485 if (m_num_args > pos) { command2.
affect_engine = this->GetArgFloat(pos++);}
1486 if (m_num_args > pos) { command2.
needs_engine = this->GetArgBool (pos++);}
1487 if (m_num_args > pos) { command2.
plays_sound = this->GetArgBool (pos++);}
1489 m_current_module->commands2.push_back(command2);
1492 void Parser::ParseCollisionBox()
1496 Ogre::StringVector tokens = Ogre::StringUtil::split(m_current_line,
",");
1497 Ogre::StringVector::iterator iter = tokens.begin();
1498 for ( ; iter != tokens.end(); iter++)
1500 collisionbox.
nodes.push_back( this->_ParseNodeRef(*iter) );
1503 m_current_module->collisionboxes.push_back(collisionbox);
1506 void Parser::ParseCinecam()
1508 if (! this->CheckNumArguments(11)) {
return; }
1515 cinecam.
position.x = this->GetArgFloat ( 0);
1516 cinecam.
position.y = this->GetArgFloat ( 1);
1517 cinecam.
position.z = this->GetArgFloat ( 2);
1518 cinecam.
nodes[0] = this->GetArgNodeRef( 3);
1519 cinecam.
nodes[1] = this->GetArgNodeRef( 4);
1520 cinecam.
nodes[2] = this->GetArgNodeRef( 5);
1521 cinecam.
nodes[3] = this->GetArgNodeRef( 6);
1522 cinecam.
nodes[4] = this->GetArgNodeRef( 7);
1523 cinecam.
nodes[5] = this->GetArgNodeRef( 8);
1524 cinecam.
nodes[6] = this->GetArgNodeRef( 9);
1525 cinecam.
nodes[7] = this->GetArgNodeRef(10);
1528 if (m_num_args > 11) { cinecam.
spring = this->GetArgFloat(11); }
1529 if (m_num_args > 12) { cinecam.
damping = this->GetArgFloat(12); }
1531 if (m_num_args > 13)
1533 float value = this->GetArgFloat(13);
1538 if (m_sequential_importer.IsEnabled())
1540 m_sequential_importer.AddGeneratedNode(Keyword::CINECAM);
1543 m_current_module->cinecam.push_back(cinecam);
1546 void Parser::ParseCameraRails()
1548 m_current_camera_rail->nodes.push_back( this->GetArgNodeRef(0) );
1551 void Parser::ParseBrakes()
1553 if (!this->CheckNumArguments(1)) {
return; }
1561 m_current_module->brakes.push_back(brakes);
1564 void Parser::ParseAxles()
1568 Ogre::StringVector tokens = Ogre::StringUtil::split(m_current_line,
",");
1569 Ogre::StringVector::iterator iter = tokens.begin();
1570 for ( ; iter != tokens.end(); iter++)
1572 std::smatch results;
1573 if (! std::regex_search(*iter, results, Regexes::SECTION_AXLES_PROPERTY))
1580 if (results[1].matched)
1582 unsigned int wheel_index =
PARSEINT(results[2]) - 1;
1583 axle.
wheels[wheel_index][0] = _ParseNodeRef(results[3]);
1584 axle.
wheels[wheel_index][1] = _ParseNodeRef(results[4]);
1586 else if (results[5].matched)
1588 this->_ParseDifferentialTypes(axle.
options, results[6].str());
1592 m_current_module->axles.push_back(axle);
1595 void Parser::ParseInterAxles()
1597 auto args = Ogre::StringUtil::split(m_current_line,
",");
1598 if (args.size() < 2) {
return; }
1602 interaxle.
a1 = this->ParseArgInt(args[0].c_str()) - 1;
1603 interaxle.
a2 = this->ParseArgInt(args[1].c_str()) - 1;
1605 std::smatch results;
1606 if (! std::regex_search(args[2], results, Regexes::SECTION_AXLES_PROPERTY))
1613 if (results[5].matched)
1615 this->_ParseDifferentialTypes(interaxle.
options, results[6].str());
1618 m_current_module->interaxles.push_back(interaxle);
1621 void Parser::ParseAirbrakes()
1623 if (! this->CheckNumArguments(14)) {
return; }
1630 airbrake.
offset.x = this->GetArgFloat ( 4);
1631 airbrake.
offset.y = this->GetArgFloat ( 5);
1632 airbrake.
offset.z = this->GetArgFloat ( 6);
1633 airbrake.
width = this->GetArgFloat ( 7);
1634 airbrake.
height = this->GetArgFloat ( 8);
1641 m_current_module->airbrakes.push_back(airbrake);
1644 void Parser::ParseAssetpacks()
1646 if (! this->CheckNumArguments(1)) {
return; }
1650 assetpack.
filename = this->GetArgStr(0);
1652 m_current_module->assetpacks.push_back(assetpack);
1655 void Parser::ParseVideoCamera()
1657 if (! this->CheckNumArguments(19)) {
return; }
1662 videocamera.
left_node = this->GetArgNodeRef ( 1);
1663 videocamera.
bottom_node = this->GetArgNodeRef ( 2);
1666 videocamera.
offset.x = this->GetArgFloat ( 5);
1667 videocamera.
offset.y = this->GetArgFloat ( 6);
1668 videocamera.
offset.z = this->GetArgFloat ( 7);
1669 videocamera.
rotation.x = this->GetArgFloat ( 8);
1670 videocamera.
rotation.y = this->GetArgFloat ( 9);
1671 videocamera.
rotation.z = this->GetArgFloat (10);
1681 if (m_num_args > 19) { videocamera.
camera_name = this->GetArgStr(19); }
1683 m_current_module->videocameras.push_back(videocamera);
1686 void Parser::ParseCameras()
1688 if (! this->CheckNumArguments(3)) {
return; }
1692 camera.
back_node = this->GetArgNodeRef(1);
1693 camera.
left_node = this->GetArgNodeRef(2);
1695 m_current_module->cameras.push_back(camera);
1698 void Parser::ParseTurbopropsUnified()
1700 bool is_turboprop_2 = m_current_block == Keyword::TURBOPROPS2;
1702 if (! this->CheckNumArguments(is_turboprop_2 ? 9 : 8)) {
return; }
1707 turboprop.
axis_node = this->GetArgNodeRef(1);
1717 turboprop.
couple_node = this->GetArgNullableNode(6);
1723 turboprop.
airfoil = this->GetArgStr (7 + offset);
1725 m_current_module->turboprops2.push_back(turboprop);
1728 void Parser::ParseTurbojets()
1730 if (! this->CheckNumArguments(9)) {
return; }
1733 turbojet.
front_node = this->GetArgNodeRef(0);
1734 turbojet.
back_node = this->GetArgNodeRef(1);
1735 turbojet.
side_node = this->GetArgNodeRef(2);
1743 m_current_module->turbojets.push_back(turbojet);
1746 void Parser::ParseTriggers()
1748 if (! this->CheckNumArguments(6)) {
return; }
1753 trigger.
nodes[0] = this->GetArgNodeRef(0);
1754 trigger.
nodes[1] = this->GetArgNodeRef(1);
1759 if (m_num_args > 6) trigger.
options = this->GetArgTriggerOptions(6);
1760 if (m_num_args > 7) trigger.
boundary_timer = this->GetArgFloat(7);
1762 m_current_module->triggers.push_back(trigger);
1765 void Parser::ParseTorqueCurve()
1767 if (m_current_module->torquecurve.size() == 0)
1769 m_current_module->torquecurve.push_back(
TorqueCurve());
1772 Ogre::StringVector args = Ogre::StringUtil::split(m_current_line,
",");
1774 if (args.size() == 1u)
1776 m_current_module->torquecurve[0].predefined_func_name = args[0];
1778 else if (args.size() == 2u)
1781 sample.
power = this->ParseArgFloat(args[0].c_str());
1783 m_current_module->torquecurve[0].samples.push_back(sample);
1792 void Parser::ParseTies()
1794 if (! this->CheckNumArguments(5)) {
return; }
1808 for (
char c: this->GetArgStr(5))
1812 case (
char)TieOption::n_DUMMY:
1813 case (
char)TieOption::v_DUMMY:
1816 case (
char)TieOption::i_INVISIBLE:
1817 tie.
options |= Tie::OPTION_i_INVISIBLE;
1820 case (
char)TieOption::s_NO_SELF_LOCK:
1821 tie.
options |= Tie::OPTION_s_DISABLE_SELF_LOCK;
1832 if (m_num_args > 6) { tie.
max_stress = this->GetArgFloat (6); }
1833 if (m_num_args > 7) { tie.
group = this->GetArgInt (7); }
1835 m_current_module->ties.push_back(tie);
1838 void Parser::ParseSoundsources()
1840 if (! this->CheckNumArguments(2)) {
return; }
1843 soundsource.
node = this->GetArgNodeRef(0);
1846 m_current_module->soundsources.push_back(soundsource);
1849 void Parser::ParseSoundsources2()
1851 if (! this->CheckNumArguments(3)) {
return; }
1854 soundsource2.
node = this->GetArgNodeRef(0);
1855 soundsource2.
mode = this->GetArgInt(1);
1858 if (soundsource2.
mode < -2)
1861 fmt::format(
"invalid mode {}, falling back to default -2", soundsource2.
mode));
1862 soundsource2.
mode = -2;
1865 m_current_module->soundsources2.push_back(soundsource2);
1868 void Parser::ParseSlidenodes()
1870 Ogre::StringVector args = Ogre::StringUtil::split(m_current_line,
", ");
1871 m_num_args = (int)args.size();
1872 if (! this->CheckNumArguments(2)) {
return; }
1875 slidenode.
slide_node = this->_ParseNodeRef(args[0]);
1877 bool in_rail_node_list =
true;
1879 for (
auto itor = args.begin() + 1; itor != args.end(); ++itor)
1881 char c = toupper(itor->at(0));
1885 slidenode.
spring_rate = this->ParseArgFloat(itor->substr(1));
1887 in_rail_node_list =
false;
1890 slidenode.
break_force = this->ParseArgFloat(itor->substr(1));
1892 in_rail_node_list =
false;
1895 slidenode.
tolerance = this->ParseArgFloat(itor->substr(1));
1897 in_rail_node_list =
false;
1902 in_rail_node_list =
false;
1905 slidenode.
railgroup_id = this->ParseArgFloat(itor->substr(1));
1907 in_rail_node_list =
false;
1912 in_rail_node_list =
false;
1915 switch (itor->at(1))
1931 fmt::format(
"Ignoring invalid option '{}'", itor->at(1)));
1934 in_rail_node_list =
false;
1937 if (in_rail_node_list)
1943 m_current_module->slidenodes.push_back(slidenode);
1946 void Parser::ParseShock3()
1948 if (! this->CheckNumArguments(15)) {
return; }
1954 shock_3.
nodes[0] = this->GetArgNodeRef( 0);
1955 shock_3.
nodes[1] = this->GetArgNodeRef( 1);
1956 shock_3.
spring_in = this->GetArgFloat ( 2);
1957 shock_3.
damp_in = this->GetArgFloat ( 3);
1962 shock_3.
damp_out = this->GetArgFloat ( 8);
1970 if (m_num_args > 15) shock_3.
options = this->GetArgShock3Options(15);
1972 m_current_module->shocks3.push_back(shock_3);
1975 void Parser::ParseShock2()
1977 if (! this->CheckNumArguments(13)) {
return; }
1983 shock_2.
nodes[0] = this->GetArgNodeRef( 0);
1984 shock_2.
nodes[1] = this->GetArgNodeRef( 1);
1985 shock_2.
spring_in = this->GetArgFloat ( 2);
1986 shock_2.
damp_in = this->GetArgFloat ( 3);
1990 shock_2.
damp_out = this->GetArgFloat ( 7);
1997 if (m_num_args > 13) shock_2.
options = this->GetArgShock2Options(13);
1999 m_current_module->shocks2.push_back(shock_2);
2002 void Parser::ParseShock()
2004 if (! this->CheckNumArguments(7)) {
return; }
2010 shock.
nodes[0] = this->GetArgNodeRef(0);
2011 shock.
nodes[1] = this->GetArgNodeRef(1);
2013 shock.
damping = this->GetArgFloat (3);
2017 if (m_num_args > 7) shock.
options = this->GetArgShockOptions(7);
2019 m_current_module->shocks.push_back(shock);
2022 Node::Ref Parser::_ParseNodeRef(std::string
const & node_id_str)
2024 if (m_sequential_importer.IsEnabled())
2027 int node_id_num =
PARSEINT(node_id_str);
2028 if (node_id_num < 0)
2034 unsigned int flags = Node::Ref::IMPORT_STATE_IS_VALID |
2035 Node::Ref::REGULAR_STATE_IS_VALID | Node::Ref::REGULAR_STATE_IS_NAMED;
2036 if (m_any_named_node_defined)
2038 flags |= Node::Ref::IMPORT_STATE_MUST_CHECK_NAMED_FIRST;
2040 return Node::Ref(node_id_str, node_id_num, flags, m_current_line_number);
2045 return Node::Ref(node_id_str, 0, Node::Ref::REGULAR_STATE_IS_VALID | Node::Ref::REGULAR_STATE_IS_NAMED, m_current_line_number);
2049 void Parser::ParseDirectiveSetDefaultMinimass()
2051 if (! this->CheckNumArguments(2)) {
return; }
2053 m_set_default_minimass = std::shared_ptr<DefaultMinimass>(
new DefaultMinimass());
2054 m_set_default_minimass->min_mass_Kg = this->GetArgFloat(1);
2057 void Parser::ParseDirectiveSetInertiaDefaults()
2059 if (! this->CheckNumArguments(2)) {
return; }
2061 float start_delay = this->GetArgFloat(1);
2062 float stop_delay = 0;
2063 if (m_num_args > 2) { stop_delay = this->GetArgFloat(2); }
2065 if (start_delay < 0 || stop_delay < 0)
2067 m_user_default_inertia = m_ror_default_inertia;
2077 if (m_num_args > 4) { i->
stop_function = this->GetArgStr(4); }
2079 m_user_default_inertia = std::shared_ptr<Inertia>(i);
2082 void Parser::ParseScrewprops()
2084 if (! this->CheckNumArguments(4)) {
return; }
2088 screwprop.
prop_node = this->GetArgNodeRef(0);
2089 screwprop.
back_node = this->GetArgNodeRef(1);
2090 screwprop.
top_node = this->GetArgNodeRef(2);
2091 screwprop.
power = this->GetArgFloat (3);
2093 m_current_module->screwprops.push_back(screwprop);
2096 void Parser::ParseScripts()
2098 if (!this->CheckNumArguments(1)) {
return; }
2102 script.
filename = this->GetArgStr(0);
2104 m_current_module->scripts.push_back(script);
2107 void Parser::ParseRotatorsUnified()
2109 if (! this->CheckNumArguments(13)) {
return; }
2114 rotator.
axis_nodes[0] = this->GetArgNodeRef( 0);
2115 rotator.
axis_nodes[1] = this->GetArgNodeRef( 1);
2124 rotator.
rate = this->GetArgFloat (10);
2130 if (m_current_block == Keyword::ROTATORS2)
2132 if (! this->CheckNumArguments(16)) {
return; }
2133 if (m_num_args > 13) { rotator.
rotating_force = this->GetArgFloat(13); }
2134 if (m_num_args > 14) { rotator.
tolerance = this->GetArgFloat(14); }
2135 if (m_num_args > 15) { rotator.
description = this->GetArgStr (15); }
2140 this->ParseOptionalInertia(rotator.
inertia, 13 + offset);
2141 if (m_num_args > 17 + offset) { rotator.
engine_coupling = this->GetArgFloat(17 + offset); }
2142 if (m_num_args > 18 + offset) { rotator.
needs_engine = this->GetArgBool (18 + offset); }
2144 if (m_current_block == Keyword::ROTATORS2)
2146 m_current_module->rotators2.push_back(rotator);
2150 m_current_module->rotators.push_back(rotator);
2154 void Parser::ParseFileinfo()
2156 if (! this->CheckNumArguments(2)) {
return; }
2160 fileinfo.
unique_id = this->GetArgStr(1);
2161 Ogre::StringUtil::trim(fileinfo.
unique_id);
2163 if (m_num_args > 2) { fileinfo.
category_id = this->GetArgInt(2); }
2164 if (m_num_args > 3) { fileinfo.
file_version = this->GetArgInt(3); }
2166 m_current_module->fileinfo.push_back(fileinfo);
2168 m_current_block = Keyword::INVALID;
2171 void Parser::ParseRopes()
2173 if (! this->CheckNumArguments(2)) {
return; }
2178 rope.
root_node = this->GetArgNodeRef(0);
2179 rope.
end_node = this->GetArgNodeRef(1);
2181 if (m_num_args > 2) { rope.
invisible = (this->GetArgChar(2) ==
'i'); }
2183 m_current_module->ropes.push_back(rope);
2186 void Parser::ParseRopables()
2188 if (! this->CheckNumArguments(1)) {
return; }
2191 ropable.
node = this->GetArgNodeRef(0);
2193 if (m_num_args > 1) { ropable.
group = this->GetArgInt(1); }
2194 if (m_num_args > 2) { ropable.
has_multilock = (this->GetArgInt(2) == 1); }
2196 m_current_module->ropables.push_back(ropable);
2199 void Parser::ParseRailGroups()
2201 Ogre::StringVector args = Ogre::StringUtil::split(m_current_line,
",");
2202 m_num_args = (int)args.size();
2203 if (! this->CheckNumArguments(3)) {
return; }
2206 railgroup.
id = this->ParseArgInt(args[0].c_str());
2208 for (
auto itor = args.begin() + 1; itor != args.end(); itor++)
2210 railgroup.
node_list.push_back( this->_ParseNodeRef(*itor));
2213 m_current_module->railgroups.push_back(railgroup);
2216 void Parser::ParseProps()
2218 if (! this->CheckNumArguments(10)) {
return; }
2224 prop.
offset.x = this->GetArgFloat (3);
2225 prop.
offset.y = this->GetArgFloat (4);
2226 prop.
offset.z = this->GetArgFloat (5);
2227 prop.
rotation.x = this->GetArgFloat (6);
2228 prop.
rotation.y = this->GetArgFloat (7);
2229 prop.
rotation.z = this->GetArgFloat (8);
2233 if ((prop.
special == SpecialProp::BEACON) && (m_num_args >= 14))
2239 this->GetArgFloat(11), this->GetArgFloat(12), this->GetArgFloat(13));
2241 else if (prop.
special == SpecialProp::DASHBOARD_LEFT ||
2242 prop.
special == SpecialProp::DASHBOARD_RIGHT)
2245 if (m_num_args > 13)
2253 m_current_module->props.push_back(prop);
2256 void Parser::ParsePistonprops()
2258 if (!this->CheckNumArguments(10)) {
return; }
2262 pistonprop.
axis_node = this->GetArgNodeRef (1);
2267 pistonprop.
couple_node = this->GetArgNullableNode(6);
2269 pistonprop.
pitch = this->GetArgFloat (8);
2270 pistonprop.
airfoil = this->GetArgStr (9);
2272 m_current_module->pistonprops.push_back(pistonprop);
2276 void Parser::ParseParticles()
2278 if (!this->CheckNumArguments(3)) {
return; }
2285 m_current_module->particles.push_back(particle);
2289 void Parser::_TrimTrailingComments(std::string
const & line_in, std::string & line_out)
2293 int comment_start =
static_cast<int>(line_in.find_first_of(
";"));
2294 if (comment_start != Ogre::String::npos)
2296 line_out = line_in.substr(0, comment_start);
2300 comment_start =
static_cast<int>(line_in.find_last_of(
"/"));
2301 if (comment_start != Ogre::String::npos)
2303 while (comment_start >= 0)
2305 char c = line_in[comment_start - 1];
2306 if (c !=
'/' && c !=
' ' && c !=
'\t')
2312 line_out = line_in.substr(0, comment_start);
2319 void Parser::ParseNodesUnified()
2321 if (! this->CheckNumArguments(4)) {
return; }
2329 if (m_current_block == Keyword::NODES2)
2331 std::string node_name = this->GetArgStr(0);
2333 if (m_sequential_importer.IsEnabled())
2335 m_sequential_importer.AddNamedNode(node_name);
2337 m_any_named_node_defined =
true;
2341 const unsigned int node_num = this->GetArgUint(0);
2343 if (m_sequential_importer.IsEnabled())
2345 m_sequential_importer.AddNumberedNode(node_num);
2349 node.
position.x = this->GetArgFloat(1);
2350 node.
position.y = this->GetArgFloat(2);
2351 node.
position.z = this->GetArgFloat(3);
2354 node.
options = this->GetArgNodeOptions(4);
2358 if (node.
options & Node::OPTION_l_LOAD_WEIGHT)
2366 "Node has load-weight-override value specified, but option 'l' is not present. Ignoring value...");
2370 m_current_module->nodes.push_back(node);
2373 void Parser::ParseMinimass()
2375 if (! this->CheckNumArguments(1)) {
return; }
2379 if (m_num_args > 1) { mm.
option = this->GetArgMinimassOption(1); }
2381 m_current_module->minimass.push_back(mm);
2382 m_current_block = Keyword::INVALID;
2385 void Parser::ParseFlexBodyWheel()
2387 if (! this->CheckNumArguments(16)) {
return; }
2393 flexbody_wheel.
tyre_radius = this->GetArgFloat ( 0);
2394 flexbody_wheel.
rim_radius = this->GetArgFloat ( 1);
2395 flexbody_wheel.
width = this->GetArgFloat ( 2);
2396 flexbody_wheel.
num_rays = this->GetArgInt ( 3);
2397 flexbody_wheel.
nodes[0] = this->GetArgNodeRef ( 4);
2398 flexbody_wheel.
nodes[1] = this->GetArgNodeRef ( 5);
2399 flexbody_wheel.
rigidity_node = this->GetArgRigidityNode ( 6);
2400 flexbody_wheel.
braking = this->GetArgBraking ( 7);
2401 flexbody_wheel.
propulsion = this->GetArgPropulsion ( 8);
2403 flexbody_wheel.
mass = this->GetArgFloat (10);
2407 flexbody_wheel.
rim_damping = this->GetArgFloat (14);
2408 flexbody_wheel.
side = this->GetArgWheelSide (15);
2410 if (m_num_args > 16) { flexbody_wheel.
rim_mesh_name = this->GetArgStr(16); }
2411 if (m_num_args > 17) { flexbody_wheel.
tyre_mesh_name = this->GetArgStr(17); }
2413 if (m_sequential_importer.IsEnabled())
2418 m_current_module->flexbodywheels.push_back(flexbody_wheel);
2421 void Parser::ParseMaterialFlareBindings()
2423 if (! this->CheckNumArguments(2)) {
return; }
2429 m_current_module->materialflarebindings.push_back(binding);
2432 void Parser::ParseManagedMaterials()
2434 if (! this->CheckNumArguments(2)) {
return; }
2437 managed_mat.
options = m_current_managed_material_options;
2438 managed_mat.
name = this->GetArgStr(0);
2439 managed_mat.
type = this->GetArgManagedMatType(1);
2441 if (managed_mat.
type != ManagedMaterialType::INVALID)
2443 if (! this->CheckNumArguments(3)) {
return; }
2447 if (managed_mat.
type == ManagedMaterialType::MESH_STANDARD ||
2448 managed_mat.
type == ManagedMaterialType::MESH_TRANSPARENT)
2450 if (m_num_args > 3) { managed_mat.
specular_map = this->GetArgManagedTex(3); }
2452 else if (managed_mat.
type == ManagedMaterialType::FLEXMESH_STANDARD ||
2453 managed_mat.
type == ManagedMaterialType::FLEXMESH_TRANSPARENT)
2456 if (m_num_args > 4) { managed_mat.
specular_map = this->GetArgManagedTex(4); }
2459 m_current_module->managedmaterials.push_back(managed_mat);
2463 void Parser::ParseLockgroups()
2465 if (! this->CheckNumArguments(2)) {
return; }
2468 lockgroup.
number = this->GetArgInt(0);
2470 for (
int i = 1; i < m_num_args; ++i)
2472 lockgroup.
nodes.push_back(this->GetArgNodeRef(i));
2475 m_current_module->lockgroups.push_back(lockgroup);
2478 void Parser::ParseHydros()
2480 if (! this->CheckNumArguments(3)) {
return; }
2487 hydro.
nodes[0] = this->GetArgNodeRef(0);
2488 hydro.
nodes[1] = this->GetArgNodeRef(1);
2491 if (m_num_args > 3) { hydro.
options = this->GetArgHydroOptions(3); }
2495 hydro.
options |= Hydro::OPTION_n_INPUT_NORMAL;
2498 this->ParseOptionalInertia(hydro.
inertia, 4);
2500 m_current_module->hydros.push_back(hydro);
2503 void Parser::ParseOptionalInertia(
Inertia & inertia,
int index)
2506 if (m_num_args > index) { inertia.
stop_delay_factor = this->GetArgFloat(index++); }
2507 if (m_num_args > index) { inertia.
start_function = this->GetArgStr (index++); }
2508 if (m_num_args > index) { inertia.
stop_function = this->GetArgStr (index++); }
2513 for (
char c: options_str)
2517 case (
char)DifferentialType::o_OPEN:
2518 case (
char)DifferentialType::l_LOCKED:
2519 case (
char)DifferentialType::s_SPLIT:
2520 case (
char)DifferentialType::v_VISCOUS:
2526 fmt::format(
"ignoring invalid differential type '{}'", c));
2532 void Parser::ParseBeams()
2534 if (! this->CheckNumArguments(2)) {
return; }
2537 beam.
defaults = m_user_beam_defaults;
2540 beam.
nodes[0] = this->GetArgNodeRef(0);
2541 beam.
nodes[1] = this->GetArgNodeRef(1);
2542 if (m_num_args > 2) beam.
options = this->GetArgBeamOptions(2);
2546 float support_break_limit = 0.0f;
2547 float support_break_factor = this->GetArgInt(3);
2548 if (support_break_factor > 0.0f)
2550 support_break_limit = support_break_factor;
2556 m_current_module->beams.push_back(beam);
2559 void Parser::ParseAnimator()
2561 auto args = Ogre::StringUtil::split(m_current_line,
",");
2562 if (args.size() < 4) {
return; }
2569 animator.
nodes[0] = this->_ParseNodeRef(args[0]);
2570 animator.
nodes[1] = this->_ParseNodeRef(args[1]);
2574 Ogre::StringVector attrs = Ogre::StringUtil::split(args[3],
"|");
2576 auto itor = attrs.begin();
2577 auto endi = attrs.end();
2578 for (; itor != endi; ++itor)
2580 Ogre::String token = *itor;
2581 Ogre::StringUtil::trim(token);
2582 std::smatch results;
2583 bool is_shortlimit =
false;
2586 if (std::regex_search(token, results, Regexes::PARSE_ANIMATORS_NUMBERED_KEYWORD))
2588 if (results[1] ==
"throttle") animator.
aero_animator.
flags |= AeroAnimator::OPTION_THROTTLE;
2589 else if (results[1] ==
"rpm") animator.
aero_animator.
flags |= AeroAnimator::OPTION_RPM;
2590 else if (results[1] ==
"aerotorq") animator.
aero_animator.
flags |= AeroAnimator::OPTION_TORQUE;
2591 else if (results[1] ==
"aeropit") animator.
aero_animator.
flags |= AeroAnimator::OPTION_PITCH;
2592 else if (results[1] ==
"aerostatus") animator.
aero_animator.
flags |= AeroAnimator::OPTION_STATUS;
2596 else if ((is_shortlimit = (token.compare(0, 10,
"shortlimit") == 0)) || (token.compare(0, 9,
"longlimit") == 0))
2598 Ogre::StringVector fields = Ogre::StringUtil::split(token,
":");
2599 if (fields.size() > 1)
2603 animator.
short_limit = std::strtod(fields[1].c_str(),
nullptr);
2604 animator.
flags |= Animator::OPTION_SHORT_LIMIT;
2608 animator.
long_limit = std::strtod(fields[1].c_str(),
nullptr);
2609 animator.
flags |= Animator::OPTION_LONG_LIMIT;
2616 if (token ==
"vis") animator.
flags |= Animator::OPTION_VISIBLE;
2617 else if (token ==
"inv") animator.
flags |= Animator::OPTION_INVISIBLE;
2618 else if (token ==
"airspeed") animator.
flags |= Animator::OPTION_AIRSPEED;
2619 else if (token ==
"vvi") animator.
flags |= Animator::OPTION_VERTICAL_VELOCITY;
2620 else if (token ==
"altimeter100k") animator.
flags |= Animator::OPTION_ALTIMETER_100K;
2621 else if (token ==
"altimeter10k") animator.
flags |= Animator::OPTION_ALTIMETER_10K;
2622 else if (token ==
"altimeter1k") animator.
flags |= Animator::OPTION_ALTIMETER_1K;
2623 else if (token ==
"aoa") animator.
flags |= Animator::OPTION_ANGLE_OF_ATTACK;
2624 else if (token ==
"flap") animator.
flags |= Animator::OPTION_FLAP;
2625 else if (token ==
"airbrake") animator.
flags |= Animator::OPTION_AIR_BRAKE;
2626 else if (token ==
"roll") animator.
flags |= Animator::OPTION_ROLL;
2627 else if (token ==
"pitch") animator.
flags |= Animator::OPTION_PITCH;
2628 else if (token ==
"brakes") animator.
flags |= Animator::OPTION_BRAKES;
2629 else if (token ==
"accel") animator.
flags |= Animator::OPTION_ACCEL;
2630 else if (token ==
"clutch") animator.
flags |= Animator::OPTION_CLUTCH;
2631 else if (token ==
"speedo") animator.
flags |= Animator::OPTION_SPEEDO;
2632 else if (token ==
"tacho") animator.
flags |= Animator::OPTION_TACHO;
2633 else if (token ==
"turbo") animator.
flags |= Animator::OPTION_TURBO;
2634 else if (token ==
"parking") animator.
flags |= Animator::OPTION_PARKING;
2635 else if (token ==
"shifterman1") animator.
flags |= Animator::OPTION_SHIFT_LEFT_RIGHT;
2636 else if (token ==
"shifterman2") animator.
flags |= Animator::OPTION_SHIFT_BACK_FORTH;
2637 else if (token ==
"sequential") animator.
flags |= Animator::OPTION_SEQUENTIAL_SHIFT;
2638 else if (token ==
"shifterlin") animator.
flags |= Animator::OPTION_GEAR_SELECT;
2639 else if (token ==
"torque") animator.
flags |= Animator::OPTION_TORQUE;
2640 else if (token ==
"difflock") animator.
flags |= Animator::OPTION_DIFFLOCK;
2641 else if (token ==
"rudderboat") animator.
flags |= Animator::OPTION_BOAT_RUDDER;
2642 else if (token ==
"throttleboat") animator.
flags |= Animator::OPTION_BOAT_THROTTLE;
2646 m_current_module->animators.push_back(animator);
2649 void Parser::ParseAuthor()
2651 if (! this->CheckNumArguments(2)) {
return; }
2654 if (m_num_args > 1) { author.
type = this->GetArgStr(1); }
2656 if (m_num_args > 3) { author.
name = this->GetArgStr(3); }
2657 if (m_num_args > 4) { author.
email = this->GetArgStr(4); }
2659 m_current_module->author.push_back(author);
2660 m_current_block = Keyword::INVALID;
2673 m_filename, m_current_line_number,
KeywordToString(m_log_keyword), msg));
2676 Keyword Parser::IdentifyKeyword(
const std::string& line)
2679 std::smatch results;
2680 std::regex_search(line, results, Regexes::IDENTIFY_KEYWORD_IGNORE_CASE);
2684 for (
unsigned int i = 1; i < results.size(); i++)
2686 std::ssub_match sub = results[i];
2694 return Keyword::INVALID;
2697 void Parser::Prepare()
2699 m_current_block = Keyword::INVALID;
2700 m_current_line_number = 1;
2702 m_any_named_node_defined =
false;
2703 m_current_detacher_group = 0;
2705 m_user_default_inertia = m_ror_default_inertia;
2706 m_user_node_defaults = m_ror_node_defaults;
2709 m_user_beam_defaults = std::shared_ptr<BeamDefaults>(
new BeamDefaults);
2712 m_user_beam_defaults->deformation_threshold =
BEAM_DEFORM;
2713 m_user_beam_defaults->breaking_threshold =
BEAM_BREAK;
2716 m_root_module = m_definition->root_module;
2717 m_current_module = m_definition->root_module;
2719 m_sequential_importer.Init(
true);
2724 if (
keyword == Keyword::INVALID)
2727 if (m_current_submesh !=
nullptr)
2729 m_current_module->submeshes.push_back(*m_current_submesh);
2730 m_current_submesh.reset();
2734 if (m_current_camera_rail !=
nullptr)
2736 if (m_current_camera_rail->nodes.size() == 0)
2742 m_current_module->camerarail.push_back(*m_current_camera_rail);
2743 m_current_camera_rail.reset();
2747 else if (
keyword == Keyword::CAMERARAIL)
2749 this->BeginBlock(Keyword::INVALID);
2750 m_current_camera_rail = std::shared_ptr<CameraRail>(
new CameraRail() );
2758 std::string new_module_name;
2759 if (
keyword == Keyword::END_SECTION)
2761 if (m_current_module == m_root_module)
2768 else if (
keyword == Keyword::SECTION)
2770 if (!this->CheckNumArguments(3))
2775 new_module_name = this->GetArgStr(2);
2776 if (new_module_name == m_current_module->name)
2784 this->BeginBlock(Keyword::INVALID);
2788 m_current_module = m_root_module;
2792 auto search_itor = m_definition->user_modules.find(new_module_name);
2793 if (search_itor != m_definition->user_modules.end())
2795 m_current_module = search_itor->second;
2799 m_current_module = std::make_shared<Document::Module>(new_module_name);
2800 m_definition->user_modules.insert(std::make_pair(new_module_name, m_current_module));
2804 void Parser::ParseDirectiveSection()
2806 this->ProcessChangeModuleLine(Keyword::SECTION);
2809 void Parser::ParseDirectiveSectionConfig()
2814 void Parser::Finalize()
2816 this->BeginBlock(Keyword::INVALID);
2818 if (m_sequential_importer.IsEnabled())
2820 m_sequential_importer.Process( m_definition );
2824 std::string Parser::GetArgStr(
int index)
2826 return std::string(m_args[index].start, m_args[index].length);
2829 char Parser::GetArgChar(
int index)
2831 return *(m_args[index].start);
2836 char c = this->GetArgChar(index);
2845 fmt::format(
"Bad arg~{} 'side' (value: {}), parsing as 'l' for backwards compatibility.", index + 1, c));
2850 long Parser::GetArgLong(
int index)
2853 char* out_end =
nullptr;
2854 long res = std::strtol(m_args[index].start, &out_end, 10);
2858 fmt::format(
"Cannot parse argument [{}] as integer, errno: {}", index + 1, errno));
2861 if (out_end == m_args[index].start)
2864 fmt::format(
"Argument [{}] is not valid integer", index + 1));
2867 else if (out_end != (m_args[index].start + m_args[index].length))
2870 fmt::format(
"Integer argument [{}] has invalid trailing characters", index + 1));
2875 int Parser::GetArgInt(
int index)
2877 return static_cast<int>(this->GetArgLong(index));
2882 std::string rigidity_node = this->GetArgStr(index);
2883 if (rigidity_node !=
"9999")
2885 return this->GetArgNodeRef(index);
2892 int p = this->GetArgInt(index);
2895 case (
int)WheelPropulsion::NONE:
2896 case (
int)WheelPropulsion::FORWARD:
2897 case (
int)WheelPropulsion::BACKWARD:
2902 fmt::format(
"Bad value of param ~{} (propulsion), using 0 (no propulsion)", index + 1));
2903 return WheelPropulsion::NONE;
2909 int b = this->GetArgInt(index);
2912 case (
int)WheelBraking::NONE:
2913 case (
int)WheelBraking::FOOT_HAND:
2914 case (
int)WheelBraking::FOOT_HAND_SKID_LEFT:
2915 case (
int)WheelBraking::FOOT_HAND_SKID_RIGHT:
2916 case (
int)WheelBraking::FOOT_ONLY:
2921 fmt::format(
"Bad value of param ~{} (braking), using 0 (not braked)", index + 1));
2922 return WheelBraking::NONE;
2928 return this->_ParseNodeRef(this->GetArgStr(index));
2933 if (! (Ogre::StringConverter::parseReal(this->GetArgStr(index)) == -1.f))
2935 return this->GetArgNodeRef(index);
2940 unsigned Parser::GetArgUint(
int index)
2942 return static_cast<unsigned>(this->GetArgLong(index));
2947 char in = this->GetArgChar(index);
2968 fmt::format(
"Invalid flare type '{}', falling back to type 'f' (front light)...", in));
2975 std::string str = this->GetArgStr(index);
2981 fmt::format(
"Invalid ExtCameraMode '{}', falling back to type 'classic'...", str));
2985 float Parser::GetArgFloat(
int index)
2987 return (
float) Ogre::StringConverter::parseReal(this->GetArgStr(index), 0.f);
2990 float Parser::ParseArgFloat(
const char* str)
2992 return (
float) Ogre::StringConverter::parseReal(str, 0.f);
2995 float Parser::ParseArgFloat(std::string
const & str)
2997 return this->ParseArgFloat(str.c_str());
3000 unsigned Parser::ParseArgUint(
const char* str)
3003 long res = std::strtol(str,
nullptr, 10);
3007 fmt::format(
"Cannot parse argument '{}' as int, errno: {}", str, errno));
3010 return static_cast<unsigned>(res);
3013 unsigned Parser::ParseArgUint(std::string
const & str)
3015 return this->ParseArgUint(str.c_str());
3018 int Parser::ParseArgInt(
const char* str)
3020 return static_cast<int>(this->ParseArgUint(str));
3023 bool Parser::GetArgBool(
int index)
3025 return Ogre::StringConverter::parseBool(this->GetArgStr(index));
3030 char c = this->GetArgChar(index);
3033 case (
char)WingControlSurface::n_NONE:
3034 case (
char)WingControlSurface::a_RIGHT_AILERON:
3035 case (
char)WingControlSurface::b_LEFT_AILERON:
3036 case (
char)WingControlSurface::f_FLAP:
3037 case (
char)WingControlSurface::e_ELEVATOR:
3038 case (
char)WingControlSurface::r_RUDDER:
3039 case (
char)WingControlSurface::S_RIGHT_HAND_STABILATOR:
3040 case (
char)WingControlSurface::T_LEFT_HAND_STABILATOR:
3041 case (
char)WingControlSurface::c_RIGHT_ELEVON:
3042 case (
char)WingControlSurface::d_LEFT_ELEVON:
3043 case (
char)WingControlSurface::g_RIGHT_FLAPERON:
3044 case (
char)WingControlSurface::h_LEFT_FLAPERON:
3045 case (
char)WingControlSurface::U_RIGHT_HAND_TAILERON:
3046 case (
char)WingControlSurface::V_LEFT_HAND_TAILERON:
3047 case (
char)WingControlSurface::i_RIGHT_RUDDERVATOR:
3048 case (
char)WingControlSurface::j_LEFT_RUDDERVATOR:
3052 fmt::format(
"invalid WingControlSurface '{}', falling back to 'n' (none)", c);
3053 return WingControlSurface::n_NONE;
3057 std::string Parser::GetArgManagedTex(
int index)
3059 std::string tex_name = this->GetArgStr(index);
3060 return (tex_name.at(0) !=
'-') ? tex_name :
"";
3065 switch (this->GetArgStr(index)[0])
3067 case (
char)MinimassOption::l_SKIP_LOADED:
3068 return MinimassOption::l_SKIP_LOADED;
3070 case (
char)MinimassOption::n_DUMMY:
3071 return MinimassOption::n_DUMMY;
3075 fmt::format(
"Not a valid minimass option: {}, falling back to 'n' (dummy)", this->GetArgStr(index)));
3076 return MinimassOption::n_DUMMY;
3083 for (
char c: this->GetArgStr(index))
3087 case (
char)CabOption::c_CONTACT: ret |= Cab::OPTION_c_CONTACT ;
break;
3088 case (
char)CabOption::b_BUOYANT: ret |= Cab::OPTION_b_BUOYANT ;
break;
3089 case (
char)CabOption::p_10xTOUGHER: ret |= Cab::OPTION_p_10xTOUGHER ;
break;
3090 case (
char)CabOption::u_INVULNERABLE: ret |= Cab::OPTION_u_INVULNERABLE ;
break;
3091 case (
char)CabOption::s_BUOYANT_NO_DRAG: ret |= Cab::OPTION_s_BUOYANT_NO_DRAG ;
break;
3092 case (
char)CabOption::r_BUOYANT_ONLY_DRAG: ret |= Cab::OPTION_r_BUOYANT_ONLY_DRAG ;
break;
3093 case (
char)CabOption::D_CONTACT_BUOYANT: ret |= Cab::OPTION_D_CONTACT_BUOYANT ;
break;
3094 case (
char)CabOption::F_10xTOUGHER_BUOYANT: ret |= Cab::OPTION_F_10xTOUGHER_BUOYANT ;
break;
3095 case (
char)CabOption::S_INVULNERABLE_BUOYANT: ret |= Cab::OPTION_S_INVULNERABLE_BUOYANT;
break;
3108 for (
char c: this->GetArgStr(index))
3112 case (
char)TriggerOption::i_INVISIBLE : ret |= Trigger::OPTION_i_INVISIBLE;
break;
3113 case (
char)TriggerOption::c_COMMAND_STYLE : ret |= Trigger::OPTION_c_COMMAND_STYLE;
break;
3114 case (
char)TriggerOption::x_START_DISABLED : ret |= Trigger::OPTION_x_START_DISABLED;
break;
3115 case (
char)TriggerOption::b_KEY_BLOCKER : ret |= Trigger::OPTION_b_KEY_BLOCKER;
break;
3116 case (
char)TriggerOption::B_TRIGGER_BLOCKER : ret |= Trigger::OPTION_B_TRIGGER_BLOCKER;
break;
3117 case (
char)TriggerOption::A_INV_TRIGGER_BLOCKER: ret |= Trigger::OPTION_A_INV_TRIGGER_BLOCKER;
break;
3118 case (
char)TriggerOption::s_CMD_NUM_SWITCH : ret |= Trigger::OPTION_s_CMD_NUM_SWITCH;
break;
3119 case (
char)TriggerOption::h_UNLOCKS_HOOK_GROUP : ret |= Trigger::OPTION_h_UNLOCKS_HOOK_GROUP;
break;
3120 case (
char)TriggerOption::H_LOCKS_HOOK_GROUP : ret |= Trigger::OPTION_H_LOCKS_HOOK_GROUP;
break;
3121 case (
char)TriggerOption::t_CONTINUOUS : ret |= Trigger::OPTION_t_CONTINUOUS;
break;
3122 case (
char)TriggerOption::E_ENGINE_TRIGGER : ret |= Trigger::OPTION_E_ENGINE_TRIGGER;
break;
3135 for (
char c: this->GetArgStr(index))
3139 case (
char)BeamOption::i_INVISIBLE: ret |= Beam::OPTION_i_INVISIBLE;
break;
3140 case (
char)BeamOption::r_ROPE : ret |= Beam::OPTION_r_ROPE ;
break;
3141 case (
char)BeamOption::s_SUPPORT : ret |= Beam::OPTION_s_SUPPORT ;
break;
3143 case (
char)BeamOption::v_DUMMY:
break;
3156 for (
char c: this->GetArgStr(index))
3160 case (
char)HydroOption::j_INVISIBLE : ret |= Hydro::OPTION_j_INVISIBLE ;
break;
3161 case (
char)HydroOption::s_DISABLE_ON_HIGH_SPEED : ret |= Hydro::OPTION_s_DISABLE_ON_HIGH_SPEED ;
break;
3162 case (
char)HydroOption::a_INPUT_AILERON : ret |= Hydro::OPTION_a_INPUT_AILERON ;
break;
3163 case (
char)HydroOption::r_INPUT_RUDDER : ret |= Hydro::OPTION_r_INPUT_RUDDER ;
break;
3164 case (
char)HydroOption::e_INPUT_ELEVATOR : ret |= Hydro::OPTION_e_INPUT_ELEVATOR ;
break;
3165 case (
char)HydroOption::u_INPUT_AILERON_ELEVATOR : ret |= Hydro::OPTION_u_INPUT_AILERON_ELEVATOR ;
break;
3166 case (
char)HydroOption::v_INPUT_InvAILERON_ELEVATOR: ret |= Hydro::OPTION_v_INPUT_InvAILERON_ELEVATOR;
break;
3167 case (
char)HydroOption::x_INPUT_AILERON_RUDDER : ret |= Hydro::OPTION_x_INPUT_AILERON_RUDDER ;
break;
3168 case (
char)HydroOption::y_INPUT_InvAILERON_RUDDER : ret |= Hydro::OPTION_y_INPUT_InvAILERON_RUDDER ;
break;
3169 case (
char)HydroOption::g_INPUT_ELEVATOR_RUDDER : ret |= Hydro::OPTION_g_INPUT_ELEVATOR_RUDDER ;
break;
3170 case (
char)HydroOption::h_INPUT_InvELEVATOR_RUDDER : ret |= Hydro::OPTION_h_INPUT_InvELEVATOR_RUDDER ;
break;
3171 case (
char)HydroOption::n_INPUT_NORMAL : ret |= Hydro::OPTION_n_INPUT_NORMAL ;
break;
3173 case (
char)HydroOption::i_INVISIBLE_INPUT_NORMAL:
3178 ret |= Hydro::OPTION_n_INPUT_NORMAL;
3180 ret |= Hydro::OPTION_j_INVISIBLE;
3195 for (
char c: this->GetArgStr(index))
3199 case (
char)ShockOption::i_INVISIBLE : ret |= Shock::OPTION_i_INVISIBLE ;
break;
3200 case (
char)ShockOption::L_ACTIVE_LEFT : ret |= Shock::OPTION_L_ACTIVE_LEFT ;
break;
3201 case (
char)ShockOption::R_ACTIVE_RIGHT : ret |= Shock::OPTION_R_ACTIVE_RIGHT;
break;
3202 case (
char)ShockOption::m_METRIC : ret |= Shock::OPTION_m_METRIC ;
break;
3204 case (
char)ShockOption::n_DUMMY:
break;
3205 case (
char)ShockOption::v_DUMMY:
break;
3218 for (
char c: this->GetArgStr(index))
3222 case (
char)Shock2Option::i_INVISIBLE: ret |= Shock2::OPTION_i_INVISIBLE;
break;
3223 case (
char)Shock2Option::s_SOFT_BUMP_BOUNDS: ret |= Shock2::OPTION_s_SOFT_BUMP_BOUNDS;
break;
3224 case (
char)Shock2Option::m_METRIC: ret |= Shock2::OPTION_m_METRIC;
break;
3225 case (
char)Shock2Option::M_ABSOLUTE_METRIC: ret |= Shock2::OPTION_M_ABSOLUTE_METRIC;
break;
3227 case (
char)Shock2Option::n_DUMMY:
break;
3228 case (
char)Shock2Option::v_DUMMY:
break;
3241 for (
char c: this->GetArgStr(index))
3245 case (
char)Shock3Option::i_INVISIBLE: ret |= Shock3::OPTION_i_INVISIBLE;
break;
3246 case (
char)Shock3Option::m_METRIC: ret |= Shock3::OPTION_m_METRIC;
break;
3247 case (
char)Shock3Option::M_ABSOLUTE_METRIC: ret |= Shock3::OPTION_M_ABSOLUTE_METRIC;
break;
3249 case (
char)Shock3Option::n_DUMMY:
break;
3250 case (
char)Shock3Option::v_DUMMY:
break;
3263 for (
char c: this->GetArgStr(index))
3267 case (
char)NodeOption::m_NO_MOUSE_GRAB : ret |= Node::OPTION_m_NO_MOUSE_GRAB ;
break;
3268 case (
char)NodeOption::f_NO_SPARKS : ret |= Node::OPTION_f_NO_SPARKS ;
break;
3269 case (
char)NodeOption::x_EXHAUST_POINT : ret |= Node::OPTION_x_EXHAUST_POINT ;
break;
3270 case (
char)NodeOption::y_EXHAUST_DIRECTION : ret |= Node::OPTION_y_EXHAUST_DIRECTION ;
break;
3271 case (
char)NodeOption::c_NO_GROUND_CONTACT : ret |= Node::OPTION_c_NO_GROUND_CONTACT ;
break;
3272 case (
char)NodeOption::h_HOOK_POINT : ret |= Node::OPTION_h_HOOK_POINT ;
break;
3273 case (
char)NodeOption::e_TERRAIN_EDIT_POINT: ret |= Node::OPTION_e_TERRAIN_EDIT_POINT;
break;
3274 case (
char)NodeOption::b_EXTRA_BUOYANCY : ret |= Node::OPTION_b_EXTRA_BUOYANCY ;
break;
3275 case (
char)NodeOption::p_NO_PARTICLES : ret |= Node::OPTION_p_NO_PARTICLES ;
break;
3276 case (
char)NodeOption::L_LOG : ret |= Node::OPTION_L_LOG ;
break;
3277 case (
char)NodeOption::l_LOAD_WEIGHT : ret |= Node::OPTION_l_LOAD_WEIGHT ;
break;
3279 case (
char)NodeOption::n_DUMMY:
break;
3291 if (str.find(
"leftmirror" ) != std::string::npos) {
return SpecialProp::MIRROR_LEFT; }
3292 if (str.find(
"rightmirror" ) != std::string::npos) {
return SpecialProp::MIRROR_RIGHT; }
3293 if (str.find(
"dashboard-rh") != std::string::npos) {
return SpecialProp::DASHBOARD_RIGHT; }
3294 if (str.find(
"dashboard" ) != std::string::npos) {
return SpecialProp::DASHBOARD_LEFT; }
3295 if (Ogre::StringUtil::startsWith(str,
"spinprop",
false) ) {
return SpecialProp::AERO_PROP_SPIN; }
3296 if (Ogre::StringUtil::startsWith(str,
"pale",
false) ) {
return SpecialProp::AERO_PROP_BLADE; }
3297 if (Ogre::StringUtil::startsWith(str,
"seat",
false) ) {
return SpecialProp::DRIVER_SEAT; }
3298 if (Ogre::StringUtil::startsWith(str,
"seat2",
false) ) {
return SpecialProp::DRIVER_SEAT_2; }
3299 if (Ogre::StringUtil::startsWith(str,
"beacon",
false) ) {
return SpecialProp::BEACON; }
3300 if (Ogre::StringUtil::startsWith(str,
"redbeacon",
false)) {
return SpecialProp::REDBEACON; }
3301 if (Ogre::StringUtil::startsWith(str,
"lightb",
false) ) {
return SpecialProp::LIGHTBAR; }
3302 return SpecialProp::NONE;
3307 char c = this->GetArgChar(index);
3310 case (
char)EngineType::t_TRUCK:
3311 case (
char)EngineType::c_CAR:
3312 case (
char)EngineType::e_ECAR:
3316 fmt::format(
"invalid EngineType '{}', falling back to 't' (truck)", c);
3317 return EngineType::t_TRUCK;
3323 std::string str = this->GetArgStr(index);
3324 if (str ==
"mesh_standard")
return ManagedMaterialType::MESH_STANDARD;
3325 if (str ==
"mesh_transparent")
return ManagedMaterialType::MESH_TRANSPARENT;
3326 if (str ==
"flexmesh_standard")
return ManagedMaterialType::FLEXMESH_STANDARD;
3327 if (str ==
"flexmesh_transparent")
return ManagedMaterialType::FLEXMESH_TRANSPARENT;
3330 fmt::format(
"Not a valid ManagedMaterialType: '{}'", str));
3331 return ManagedMaterialType::INVALID;
3334 int Parser::TokenizeCurrentLine()
3337 const char* cur_char = m_current_line;
3339 while ((*cur_char !=
'\0') && (cur_arg < Parser::LINE_MAX_ARGS))
3342 if ((arg_len == 0) && is_arg)
3344 m_args[cur_arg].start = cur_char;
3347 else if ((arg_len > 0) && !is_arg)
3349 m_args[cur_arg].length = arg_len;
3361 m_args[cur_arg].length = arg_len;
3365 m_num_args = cur_arg;
3369 void Parser::ProcessOgreStream(Ogre::DataStream* stream, Ogre::String resource_group)
3371 m_resource_group = resource_group;
3372 m_filename = stream->getName();
3374 char raw_line_buf[LINE_BUFFER_LENGTH];
3375 while (!stream->eof())
3379 stream->readLine(raw_line_buf, LINE_BUFFER_LENGTH);
3381 catch (Ogre::Exception &ex)
3384 fmt::format(
"Could not read truck file: {}", ex.getFullDescription()));
3388 this->ProcessRawLine(raw_line_buf);
3392 void Parser::ProcessRawLine(
const char* raw_line_buf)
3394 const char* raw_start = raw_line_buf;
3395 const char* raw_end = raw_line_buf +
strnlen(raw_line_buf, LINE_BUFFER_LENGTH);
3398 while (
IsWhitespace(*raw_start) && (raw_start != raw_end))
3404 if ((raw_start == raw_end) || (*raw_start ==
';') || (*raw_start ==
'/'))
3406 ++m_current_line_number;
3411 memset(m_current_line, 0, LINE_BUFFER_LENGTH);
3412 char* out_start = m_current_line;
3413 utf8::replace_invalid(raw_start, raw_end, out_start,
'?');
3416 this->ProcessCurrentLine();
3417 ++m_current_line_number;