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_definition->name ==
"" && m_current_line !=
"")
81 m_definition->name = m_current_line;
86 if (m_current_block != Keyword::COMMENT &&
87 m_current_block != Keyword::DESCRIPTION)
89 this->TokenizeCurrentLine();
95 char c = tolower(m_current_line[0]);
96 if (c >=
'a' && c <=
'z')
98 keyword = Parser::IdentifyKeyword(m_current_line);
104 case Keyword::INVALID:
108 case Keyword::DISABLEDEFAULTSOUNDS:
109 case Keyword::ENABLE_ADVANCED_DEFORMATION:
110 case Keyword::FORWARDCOMMANDS:
111 case Keyword::HIDEINCHOOSER:
112 case Keyword::IMPORTCOMMANDS:
113 case Keyword::LOCKGROUP_DEFAULT_NOLOCK:
114 case Keyword::RESCUER:
115 case Keyword::ROLLON:
116 case Keyword::SLIDENODE_CONNECT_INSTANTLY:
117 this->ProcessGlobalDirective(
keyword);
119 case Keyword::END_SECTION:
120 this->ProcessChangeModuleLine(
keyword);
124 case Keyword::ADD_ANIMATION:
125 this->ParseDirectiveAddAnimation();
127 case Keyword::ANTILOCKBRAKES:
128 this->ParseAntiLockBrakes();
130 case Keyword::AUTHOR:
133 case Keyword::BACKMESH:
134 this->ParseDirectiveBackmesh();
136 case Keyword::CRUISECONTROL:
137 this->ParseCruiseControl();
139 case Keyword::DEFAULT_SKIN:
140 this->ParseDirectiveDefaultSkin();
142 case Keyword::DETACHER_GROUP:
143 this->ParseDirectiveDetacherGroup();
145 case Keyword::EXTCAMERA:
146 this->ParseExtCamera();
148 case Keyword::FILEFORMATVERSION:
149 this->ParseFileFormatVersion();
151 case Keyword::FILEINFO:
152 this->ParseFileinfo();
154 case Keyword::FLEXBODY_CAMERA_MODE:
155 this->ParseDirectiveFlexbodyCameraMode();
157 case Keyword::FORSET:
158 this->ParseDirectiveForset();
160 case Keyword::FORVERT:
161 this->ParseDirectiveForvert();
166 case Keyword::PROP_CAMERA_MODE:
167 this->ParseDirectivePropCameraMode();
169 case Keyword::SECTION:
170 this->ParseDirectiveSection();
172 case Keyword::SET_BEAM_DEFAULTS:
173 this->ParseDirectiveSetBeamDefaults();
175 case Keyword::SET_BEAM_DEFAULTS_SCALE:
176 this->ParseDirectiveSetBeamDefaultsScale();
178 case Keyword::SET_COLLISION_RANGE:
179 this->ParseSetCollisionRange();
181 case Keyword::SET_DEFAULT_MINIMASS:
182 this->ParseDirectiveSetDefaultMinimass();
184 case Keyword::SET_INERTIA_DEFAULTS:
185 this->ParseDirectiveSetInertiaDefaults();
187 case Keyword::SET_MANAGEDMATERIALS_OPTIONS:
188 this->ParseDirectiveSetManagedMaterialsOptions();
190 case Keyword::SET_NODE_DEFAULTS:
191 this->ParseDirectiveSetNodeDefaults();
193 case Keyword::SET_SKELETON_SETTINGS:
194 this->ParseSetSkeletonSettings();
196 case Keyword::SPEEDLIMITER:
197 this->ParseSpeedLimiter();
199 case Keyword::SUBMESH:
200 this->ParseDirectiveSubmesh();
202 case Keyword::SUBMESH_GROUNDMODEL:
203 this->ParseSubmeshGroundModel();
205 case Keyword::TRACTIONCONTROL:
206 this->ParseTractionControl();
210 case Keyword::END_COMMENT:
211 case Keyword::END_DESCRIPTION:
213 this->BeginBlock(Keyword::INVALID);
217 case Keyword::ENVMAP:
218 case Keyword::HOOKGROUP:
219 case Keyword::NODECOLLISION:
220 case Keyword::RIGIDIFIERS:
230 if ((
keyword == Keyword::NODES ||
keyword == Keyword::NODES2) && m_current_module->_hint_nodes12_start_linenumber == -1)
232 m_current_module->_hint_nodes12_start_linenumber = (int)m_current_line_number;
234 else if (
keyword == Keyword::BEAMS && m_current_module->_hint_beams_start_linenumber == -1)
236 m_current_module->_hint_beams_start_linenumber = (int)m_current_line_number;
238 else if (m_current_module->_hint_nodes12_end_linenumber == -1)
240 m_current_module->_hint_nodes12_start_linenumber = (int)m_current_line_number - 1;
242 else if (m_current_module->_hint_beams_end_linenumber == -1)
244 m_current_module->_hint_beams_start_linenumber = (int)m_current_line_number - 1;
248 m_log_keyword = m_current_block;
249 switch (m_current_block)
251 case Keyword::AIRBRAKES: this->ParseAirbrakes();
return;
252 case Keyword::ANIMATORS: this->ParseAnimator();
return;
253 case Keyword::ASSETPACKS: this->ParseAssetpacks();
return;
254 case Keyword::AXLES: this->ParseAxles();
return;
255 case Keyword::BEAMS: this->ParseBeams();
return;
256 case Keyword::BRAKES: this->ParseBrakes();
return;
257 case Keyword::CAMERAS: this->ParseCameras();
return;
258 case Keyword::CAB: this->ParseCab();
return;
259 case Keyword::CAMERARAIL: this->ParseCameraRails();
return;
260 case Keyword::CINECAM: this->ParseCinecam();
return;
261 case Keyword::COMMANDS:
262 case Keyword::COMMANDS2: this->ParseCommandsUnified();
return;
263 case Keyword::COLLISIONBOXES: this->ParseCollisionBox();
return;
264 case Keyword::CONTACTERS: this->ParseContacter();
return;
265 case Keyword::DESCRIPTION: this->ParseDescription();
return;
266 case Keyword::ENGINE: this->ParseEngine();
return;
267 case Keyword::ENGOPTION: this->ParseEngoption();
return;
268 case Keyword::ENGTURBO: this->ParseEngturbo();
return;
269 case Keyword::EXHAUSTS: this->ParseExhaust();
return;
270 case Keyword::FIXES: this->ParseFixes();
return;
271 case Keyword::FLARES:
272 case Keyword::FLARES2: this->ParseFlaresUnified();
return;
273 case Keyword::FLARES3: this->ParseFlares3();
return;
274 case Keyword::FLAREGROUPS_NO_IMPORT:this->ParseFlaregroupsNoImport();
return;
275 case Keyword::FLEXBODIES: this->ParseFlexbody();
return;
276 case Keyword::FLEXBODYWHEELS: this->ParseFlexBodyWheel();
return;
277 case Keyword::FUSEDRAG: this->ParseFusedrag();
return;
278 case Keyword::GLOBALS: this->ParseGlobals();
return;
279 case Keyword::GUISETTINGS: this->ParseGuiSettings();
return;
280 case Keyword::HELP: this->ParseHelp();
return;
281 case Keyword::HOOKS: this->ParseHook();
return;
282 case Keyword::HYDROS: this->ParseHydros();
return;
283 case Keyword::INTERAXLES: this->ParseInterAxles();
return;
284 case Keyword::LOCKGROUPS: this->ParseLockgroups();
return;
285 case Keyword::MANAGEDMATERIALS: this->ParseManagedMaterials();
return;
286 case Keyword::MATERIALFLAREBINDINGS:this->ParseMaterialFlareBindings();
return;
287 case Keyword::MESHWHEELS: this->ParseMeshWheel();
return;
288 case Keyword::MESHWHEELS2: this->ParseMeshWheel2();
return;
289 case Keyword::MINIMASS: this->ParseMinimass();
return;
291 case Keyword::NODES2: this->ParseNodesUnified();
return;
292 case Keyword::PARTICLES: this->ParseParticles();
return;
293 case Keyword::PISTONPROPS: this->ParsePistonprops();
return;
294 case Keyword::PROPS: this->ParseProps();
return;
295 case Keyword::RAILGROUPS: this->ParseRailGroups();
return;
296 case Keyword::ROPABLES: this->ParseRopables();
return;
297 case Keyword::ROPES: this->ParseRopes();
return;
298 case Keyword::ROTATORS:
299 case Keyword::ROTATORS2: this->ParseRotatorsUnified();
return;
300 case Keyword::SCREWPROPS: this->ParseScrewprops();
return;
301 case Keyword::SCRIPTS: this->ParseScripts();
return;
302 case Keyword::SHOCKS: this->ParseShock();
return;
303 case Keyword::SHOCKS2: this->ParseShock2();
return;
304 case Keyword::SHOCKS3: this->ParseShock3();
return;
305 case Keyword::SLIDENODES: this->ParseSlidenodes();
return;
306 case Keyword::SOUNDSOURCES: this->ParseSoundsources();
return;
307 case Keyword::SOUNDSOURCES2: this->ParseSoundsources2();
return;
308 case Keyword::TEXCOORDS: this->ParseTexcoords();
return;
309 case Keyword::TIES: this->ParseTies();
return;
310 case Keyword::TORQUECURVE: this->ParseTorqueCurve();
return;
311 case Keyword::TRANSFERCASE: this->ParseTransferCase();
return;
312 case Keyword::TRIGGERS: this->ParseTriggers();
return;
313 case Keyword::TURBOJETS: this->ParseTurbojets();
return;
314 case Keyword::TURBOPROPS:
315 case Keyword::TURBOPROPS2: this->ParseTurbopropsUnified();
return;
316 case Keyword::VIDEOCAMERA: this->ParseVideoCamera();
return;
317 case Keyword::WHEELDETACHERS: this->ParseWheelDetachers();
return;
318 case Keyword::WHEELS: this->ParseWheel();
return;
319 case Keyword::WHEELS2: this->ParseWheel2();
return;
320 case Keyword::WINGS: this->ParseWing();
return;
325 bool Parser::CheckNumArguments(
int min_args)
327 if (min_args > m_num_args)
330 fmt::format(
"Not enough arguments (got {}, {} needed), skipping line", m_num_args, min_args));
340 void Parser::ParseWing()
342 if (!this->CheckNumArguments(16)) {
return; }
346 for (
int i = 0; i < 8; i++) { wing.
nodes[i] = this->GetArgNodeRef (i); }
347 for (
int i = 8; i < 16; i++) { wing.
tex_coords[i-8] = this->GetArgFloat (i); }
349 if (m_num_args > 16) { wing.
control_surface = this->GetArgWingSurface (16); }
350 if (m_num_args > 17) { wing.
chord_point = this->GetArgFloat (17); }
351 if (m_num_args > 18) { wing.
min_deflection = this->GetArgFloat (18); }
352 if (m_num_args > 19) { wing.
max_deflection = this->GetArgFloat (19); }
353 if (m_num_args > 20) { wing.
airfoil = this->GetArgStr (20); }
354 if (m_num_args > 21) { wing.
efficacy_coef = this->GetArgFloat (21); }
356 m_current_module->wings.push_back(wing);
360 void Parser::ParseSetCollisionRange()
362 if (! this->CheckNumArguments(2)) {
return; }
367 m_current_module->set_collision_range.push_back(cr);
371 void Parser::ParseWheel2()
373 if (!this->CheckNumArguments(17)) {
return; }
381 wheel_2.
width = this->GetArgFloat ( 2);
382 wheel_2.
num_rays = this->GetArgInt ( 3);
383 wheel_2.
nodes[0] = this->GetArgNodeRef ( 4);
384 wheel_2.
nodes[1] = this->GetArgNodeRef ( 5);
386 wheel_2.
braking = this->GetArgBraking ( 7);
387 wheel_2.
propulsion = this->GetArgPropulsion ( 8);
389 wheel_2.
mass = this->GetArgFloat (10);
397 if (m_sequential_importer.IsEnabled())
402 m_current_module->wheels2.push_back(wheel_2);
406 void Parser::ParseWheel()
408 if (! this->CheckNumArguments(14)) {
return; }
414 wheel.
radius = this->GetArgFloat ( 0);
415 wheel.
width = this->GetArgFloat ( 1);
416 wheel.
num_rays = this->GetArgInt ( 2);
417 wheel.
nodes[0] = this->GetArgNodeRef ( 3);
418 wheel.
nodes[1] = this->GetArgNodeRef ( 4);
420 wheel.
braking = this->GetArgBraking ( 6);
421 wheel.
propulsion = this->GetArgPropulsion ( 7);
423 wheel.
mass = this->GetArgFloat ( 9);
425 wheel.
damping = this->GetArgFloat (11);
429 if (m_sequential_importer.IsEnabled())
434 m_current_module->wheels.push_back(wheel);
438 void Parser::ParseWheelDetachers()
440 if (! this->CheckNumArguments(2)) {
return; }
444 wheeldetacher.
wheel_id = this->GetArgInt(0);
447 m_current_module->wheeldetachers.push_back(wheeldetacher);
451 void Parser::ParseTractionControl()
453 Ogre::StringVector tokens = Ogre::StringUtil::split(m_current_line + 15,
",");
454 m_num_args = (int)tokens.size();
455 if (! this->CheckNumArguments(2)) {
return; }
459 tc.
wheel_slip = this->ParseArgFloat(tokens[1].c_str());
460 if (tokens.size() > 2) { tc.
fade_speed = this->ParseArgFloat(tokens[2].c_str()); }
461 if (tokens.size() > 3) { tc.
pulse_per_sec = this->ParseArgFloat(tokens[3].c_str()); }
463 for (
unsigned int i=4; i<tokens.size(); i++)
465 Ogre::StringVector args2 = Ogre::StringUtil::split(tokens[i],
":");
466 Ogre::StringUtil::trim(args2[0]);
467 Ogre::StringUtil::toLowerCase(args2[0]);
469 if (args2[0] ==
"mode" && args2.size() == 2)
471 Ogre::StringVector attrs = Ogre::StringUtil::split(args2[1],
"&");
472 auto itor = attrs.begin();
473 auto endi = attrs.end();
474 for (; itor != endi; ++itor)
476 std::string attr = *itor;
477 Ogre::StringUtil::trim(attr);
478 Ogre::StringUtil::toLowerCase(attr);
480 else if (strncmp(attr.c_str(),
"notoggle", 8) == 0) { tc.
attr_no_toggle =
true; }
481 else if (strncmp(attr.c_str(),
"on", 2) == 0) { tc.
attr_is_on =
true; }
482 else if (strncmp(attr.c_str(),
"off", 3) == 0) { tc.
attr_is_on =
false; }
494 m_current_module->tractioncontrol.push_back(tc);
498 void Parser::ParseTransferCase()
500 if (! this->CheckNumArguments(2)) {
return; }
504 tc.
a1 = this->GetArgInt(0) - 1;
505 tc.
a2 = this->GetArgInt(1) - 1;
506 if (m_num_args > 2) { tc.
has_2wd = this->GetArgInt(2); }
507 if (m_num_args > 3) { tc.
has_2wd_lo = this->GetArgInt(3); }
508 for (
int i = 4; i < m_num_args; i++) { tc.
gear_ratios.push_back(this->GetArgFloat(i)); }
510 m_current_module->transfercase.push_back(tc);
514 void Parser::ParseSubmeshGroundModel()
516 if (!this->CheckNumArguments(2)) {
return; }
518 m_current_module->submesh_groundmodel.push_back(this->GetArgStr(1));
522 void Parser::ParseSpeedLimiter()
524 if (! this->CheckNumArguments(2)) {
return; }
530 m_current_module->speedlimiter.push_back(sl);
534 void Parser::ParseSetSkeletonSettings()
536 if (! this->CheckNumArguments(2)) {
return; }
538 if (m_current_module->set_skeleton_settings.size() == 0)
552 void Parser::ParseDirectiveSetNodeDefaults()
554 if (!this->CheckNumArguments(2)) {
return; }
556 float load_weight = this->GetArgFloat(1);
557 float friction = (m_num_args > 2) ? this->GetArgFloat(2) : -1;
558 float volume = (m_num_args > 3) ? this->GetArgFloat(3) : -1;
559 float surface = (m_num_args > 4) ? this->GetArgFloat(4) : -1;
561 m_user_node_defaults = std::shared_ptr<NodeDefaults>(
new NodeDefaults(*m_user_node_defaults) );
563 m_user_node_defaults->load_weight = (load_weight < 0) ? m_ror_node_defaults->load_weight : load_weight;
564 m_user_node_defaults->friction = (friction < 0) ? m_ror_node_defaults->friction : friction;
565 m_user_node_defaults->volume = (volume < 0) ? m_ror_node_defaults->volume : volume;
566 m_user_node_defaults->surface = (surface < 0) ? m_ror_node_defaults->surface : surface;
568 if (m_num_args > 5) m_user_node_defaults->options = this->GetArgNodeOptions(5);
571 void Parser::ParseDirectiveSetManagedMaterialsOptions()
573 if (! this->CheckNumArguments(2)) {
return; }
576 m_current_managed_material_options.double_sided = (this->GetArgChar(1) !=
'0');
579 void Parser::ParseDirectiveSetBeamDefaultsScale()
581 if (! this->CheckNumArguments(5)) {
return; }
590 m_user_beam_defaults = std::shared_ptr<BeamDefaults>(b);
593 void Parser::ParseDirectiveSetBeamDefaults()
595 if (! this->CheckNumArguments(2)) {
return; }
622 m_user_beam_defaults = std::shared_ptr<BeamDefaults>(
new BeamDefaults(d) );
626 void Parser::ParseDirectivePropCameraMode()
628 if (! this->CheckNumArguments(2)) {
return; }
630 if (m_current_module->props.size() > 0)
632 m_current_module->props[m_current_module->props.size() - 1].camera_settings.mode = this->GetArgInt(1);
640 void Parser::ParseDirectiveSubmesh()
642 this->BeginBlock(Keyword::INVALID);
643 m_current_submesh = std::shared_ptr<Submesh>(
new Submesh() );
646 void Parser::ParseDirectiveBackmesh()
648 if (m_current_submesh)
650 m_current_submesh->backmesh =
true;
662 case Keyword::DISABLEDEFAULTSOUNDS: m_definition->disable_default_sounds =
true;
return;
663 case Keyword::ENABLE_ADVANCED_DEFORMATION: m_definition->enable_advanced_deformation =
true;
return;
664 case Keyword::FORWARDCOMMANDS: m_definition->forward_commands =
true;
return;
665 case Keyword::IMPORTCOMMANDS: m_definition->import_commands =
true;
return;
666 case Keyword::HIDEINCHOOSER: m_definition->hide_in_chooser =
true;
return;
667 case Keyword::LOCKGROUP_DEFAULT_NOLOCK: m_definition->lockgroup_default_nolock =
true;
return;
668 case Keyword::RESCUER: m_definition->rescuer =
true;
return;
669 case Keyword::ROLLON: m_definition->rollon =
true;
return;
670 case Keyword::SLIDENODE_CONNECT_INSTANTLY: m_definition->slide_nodes_connect_instantly =
true;
return;
682 mesh_wheel.
rim_radius = this->GetArgFloat ( 1);
683 mesh_wheel.
width = this->GetArgFloat ( 2);
684 mesh_wheel.
num_rays = this->GetArgInt ( 3);
685 mesh_wheel.
nodes[0] = this->GetArgNodeRef ( 4);
686 mesh_wheel.
nodes[1] = this->GetArgNodeRef ( 5);
688 mesh_wheel.
braking = this->GetArgBraking ( 7);
689 mesh_wheel.
propulsion = this->GetArgPropulsion ( 8);
691 mesh_wheel.
mass = this->GetArgFloat (10);
692 mesh_wheel.
spring = this->GetArgFloat (11);
693 mesh_wheel.
damping = this->GetArgFloat (12);
694 mesh_wheel.
side = this->GetArgWheelSide (13);
695 mesh_wheel.
mesh_name = this->GetArgStr (14);
699 void Parser::ParseMeshWheel()
701 if (! this->CheckNumArguments(16)) {
return; }
704 this->_ParseBaseMeshWheel(mesh_wheel);
706 if (m_sequential_importer.IsEnabled())
711 m_current_module->meshwheels.push_back(mesh_wheel);
715 void Parser::ParseMeshWheel2()
717 if (! this->CheckNumArguments(16)) {
return; }
720 this->_ParseBaseMeshWheel(mesh_wheel);
722 if (m_sequential_importer.IsEnabled())
727 m_current_module->meshwheels2.push_back(mesh_wheel);
731 void Parser::ParseHook()
733 if (! this->CheckNumArguments(1)) {
return; }
736 hook.
node = this->GetArgNodeRef(0);
739 while (i < m_num_args)
741 std::string attr = this->GetArgStr(i);
742 Ogre::StringUtil::trim(attr);
743 const bool has_value = (i < (m_num_args - 1));
746 if (has_value && (attr ==
"hookrange") ) { hook.
option_hook_range = this->GetArgFloat(++i); }
747 else if (has_value && (attr ==
"speedcoef") ) { hook.
option_speed_coef = this->GetArgFloat(++i); }
748 else if (has_value && (attr ==
"maxforce") ) { hook.
option_max_force = this->GetArgFloat(++i); }
749 else if (has_value && (attr ==
"timer") ) { hook.
option_timer = this->GetArgFloat(++i); }
750 else if (has_value && (attr ==
"hookgroup" || attr ==
"hgroup") ) { hook.
option_hookgroup = this->GetArgInt (++i); }
751 else if (has_value && (attr ==
"lockgroup" || attr ==
"lgroup") ) { hook.
option_lockgroup = this->GetArgInt (++i); }
752 else if (has_value && (attr ==
"shortlimit" || attr ==
"short_limit")) { hook.
option_min_range_meters = this->GetArgFloat(++i); }
754 else if ((attr ==
"selflock") ||(attr ==
"self-lock") ||(attr ==
"self_lock") ) { hook.
flag_self_lock =
true; }
755 else if ((attr ==
"autolock") ||(attr ==
"auto-lock") ||(attr ==
"auto_lock") ) { hook.
flag_auto_lock =
true; }
756 else if ((attr ==
"nodisable")||(attr ==
"no-disable")||(attr ==
"no_disable")) { hook.
flag_no_disable =
true; }
757 else if ((attr ==
"norope") ||(attr ==
"no-rope") ||(attr ==
"no_rope") ) { hook.
flag_no_rope =
true; }
758 else if ((attr ==
"visible") ||(attr ==
"vis") ) { hook.
flag_visible =
true; }
766 m_current_module->hooks.push_back(hook);
770 void Parser::ParseHelp()
774 m_current_module->help.push_back(h);
777 void Parser::ParseGuiSettings()
779 if (! this->CheckNumArguments(2)) {
return; }
782 gs.
key = this->GetArgStr(0);
783 gs.
value = this->GetArgStr(1);
785 m_current_module->guisettings.push_back(gs);
789 void Parser::ParseGuid()
791 if (! this->CheckNumArguments(2)) {
return; }
794 g.
guid = this->GetArgStr(1);
796 m_current_module->guid.push_back(g);
800 void Parser::ParseGlobals()
802 if (! this->CheckNumArguments(2)) {
return; }
805 globals.
dry_mass = this->GetArgFloat(0);
808 if (m_num_args > 2) { globals.
material_name = this->GetArgStr(2); }
810 m_current_module->globals.push_back(globals);
814 void Parser::ParseFusedrag()
816 if (! this->CheckNumArguments(3)) {
return; }
820 fusedrag.
rear_node = this->GetArgNodeRef(1);
822 if (this->GetArgStr(2) ==
"autocalc")
828 if (m_num_args > 4) { fusedrag.
airfoil_name = this->GetArgStr (4); }
835 if (m_num_args > 3) { fusedrag.
airfoil_name = this->GetArgStr(3); }
838 m_current_module->fusedrag.push_back(fusedrag);
842 void Parser::ParseDirectiveFlexbodyCameraMode()
844 if (! this->CheckNumArguments(2)) {
return; }
846 if (m_current_module->flexbodies.size() > 0)
848 m_current_module->flexbodies[m_current_module->flexbodies.size() - 1].camera_settings.mode = this->GetArgInt(1);
856 void Parser::ParseCab()
858 if (! this->CheckNumArguments(3)) {
return; }
860 if (!m_current_submesh)
867 cab.
nodes[0] = this->GetArgNodeRef(0);
868 cab.
nodes[1] = this->GetArgNodeRef(1);
869 cab.
nodes[2] = this->GetArgNodeRef(2);
870 if (m_num_args > 3) cab.
options = this->GetArgCabOptions(3);
872 m_current_submesh->cab_triangles.push_back(cab);
876 void Parser::ParseTexcoords()
878 if (! this->CheckNumArguments(3)) {
return; }
880 if (!m_current_submesh)
887 texcoord.
node = this->GetArgNodeRef(0);
888 texcoord.
u = this->GetArgFloat (1);
889 texcoord.
v = this->GetArgFloat (2);
891 m_current_submesh->texcoords.push_back(texcoord);
895 void Parser::ParseFlexbody()
897 if (! this->CheckNumArguments(10)) {
return; }
903 flexbody.
offset.x = this->GetArgFloat (3);
904 flexbody.
offset.y = this->GetArgFloat (4);
905 flexbody.
offset.z = this->GetArgFloat (5);
906 flexbody.
rotation.x = this->GetArgFloat (6);
907 flexbody.
rotation.y = this->GetArgFloat (7);
908 flexbody.
rotation.z = this->GetArgFloat (8);
909 flexbody.
mesh_name = this->GetArgStr (9);
911 m_current_module->flexbodies.push_back(flexbody);
915 void Parser::ParseDirectiveForset()
917 if (m_current_module->flexbodies.size() == 0)
923 Parser::ProcessForsetLine(m_current_module->flexbodies.back(), m_current_line, m_current_line_number);
926 void Parser::ParseDirectiveForvert()
928 if (m_current_module->flexbodies.size() == 0)
934 if (!this->CheckNumArguments(4)) {
return; }
938 forvert.
node_ref = this->GetArgNodeRef(1);
939 forvert.
node_x = this->GetArgNodeRef(2);
940 forvert.
node_y = this->GetArgNodeRef(3);
944 const char* input_pos = std::strstr(m_current_line,
"verts:");
951 std::string input = input_pos;
952 std::regex pattern(R
"((\d+)\s*-\s*(\d+)|(\d+))");
955 std::string::const_iterator searchStart(input.cbegin());
956 while (std::regex_search(searchStart, input.cend(), matches, pattern))
958 if (matches[1].matched && matches[2].matched)
961 int start = std::stoi(matches[1].str());
962 int end = std::stoi(matches[2].str());
963 for (
int i = start; i <= end; ++i)
966 m_current_module->flexbodies.back().forvert.push_back(forvert);
969 else if (matches[3].matched)
972 forvert.
vert_index = std::stoi(matches[3].str());
973 m_current_module->flexbodies.back().forvert.push_back(forvert);
975 searchStart = matches.suffix().first;
979 void Parser::ProcessForsetLine(
RigDef::Flexbody& def,
const std::string& _line,
int line_number )
989 std::string line = _line;
990 char* pos = &line[0] + 6;
991 while (*pos ==
' ' || *pos ==
':' || *pos ==
',') { pos++; }
998 while (*end !=
'-' && *end !=
',' && *end != 0) end++;
1001 val1 = strtoul(pos, 0, 10);
1006 while (*end !=
',' && *end != 0) end++;
1009 val2 = strtoul(pos, 0, 10);
1013 Node::Ref(std::to_string(val1), val1, Node::Ref::IMPORT_STATE_IS_VALID, line_number),
1014 Node::Ref(std::to_string(val2), val2, Node::Ref::IMPORT_STATE_IS_VALID, line_number)));
1026 void Parser::ParseFlaresUnified()
1028 const bool is_flares2 = (m_current_block == Keyword::FLARES2);
1029 if (! this->CheckNumArguments(is_flares2 ? 6 : 5)) {
return; }
1036 flare2.
offset.x = this->GetArgFloat (pos++);
1037 flare2.
offset.y = this->GetArgFloat (pos++);
1039 if (m_current_block == Keyword::FLARES2)
1041 flare2.
offset.z = this->GetArgFloat(pos++);
1044 if (m_num_args > pos) { flare2.
type = this->GetArgFlareType(pos++); }
1046 if (m_num_args > pos)
1048 switch (flare2.
type)
1058 if (m_num_args > pos) { flare2.
size = this->GetArgFloat (pos++); }
1059 if (m_num_args > pos) { flare2.
material_name = this->GetArgStr (pos++); }
1061 m_current_module->flares2.push_back(flare2);
1065 void Parser::ParseFlares3()
1067 const bool is_flares2 = (m_current_block == Keyword::FLARES2);
1068 if (! this->CheckNumArguments(is_flares2 ? 6 : 5)) {
return; }
1076 flare3.
offset.x = this->GetArgFloat(3);
1077 flare3.
offset.y = this->GetArgFloat(4);
1078 flare3.
offset.z = this->GetArgFloat(5);
1079 if (m_num_args > 6) { flare3.
type = this->GetArgFlareType(6); }
1083 switch (flare3.
type)
1092 if (m_num_args > 9) { flare3.
size = this->GetArgFloat (9); }
1093 if (m_num_args > 10) { flare3.
material_name = this->GetArgStr (10); }
1095 m_current_module->flares3.push_back(flare3);
1099 void Parser::ParseFixes()
1101 m_current_module->fixes.push_back(this->GetArgNodeRef(0));
1104 void Parser::ParseExtCamera()
1106 if (! this->CheckNumArguments(2)) {
return; }
1109 extcam.
mode = this->GetArgExtCameraMode(1);
1110 if (m_num_args > 2) { extcam.
node = this->GetArgNodeRef(2); }
1112 m_current_module->extcamera.push_back(extcam);
1116 void Parser::ParseExhaust()
1118 if (! this->CheckNumArguments(2)) {
return; }
1125 if (m_num_args > 3) { exhaust.
particle_name = this->GetArgStr(3); }
1127 m_current_module->exhausts.push_back(exhaust);
1131 void Parser::ParseFileFormatVersion()
1133 if (! this->CheckNumArguments(2)) {
return; }
1136 ffv.
version = this->GetArgInt(1);
1138 m_current_module->fileformatversion.push_back(ffv);
1139 m_current_block = Keyword::INVALID;
1142 void Parser::ParseDirectiveDefaultSkin()
1144 if (!this->CheckNumArguments(2)) {
return; }
1150 m_current_module->default_skin.push_back(data);
1154 void Parser::ParseDirectiveDetacherGroup()
1156 if (! this->CheckNumArguments(2)) {
return; }
1158 if (this->GetArgStr(1) ==
"end")
1160 m_current_detacher_group = 0;
1164 m_current_detacher_group = this->GetArgInt(1);
1168 void Parser::ParseCruiseControl()
1170 if (! this->CheckNumArguments(3)) {
return; }
1173 cruise_control.
min_speed = this->GetArgFloat(1);
1174 cruise_control.
autobrake = this->GetArgInt(2);
1176 m_current_module->cruisecontrol.push_back(cruise_control);
1180 void Parser::ParseDescription()
1182 m_current_module->description.push_back(m_current_line);
1185 void Parser::ParseDirectiveAddAnimation()
1187 Ogre::StringVector tokens = Ogre::StringUtil::split(m_current_line + 14,
",");
1188 m_num_args = (int)tokens.size();
1189 if (! this->CheckNumArguments(4)) {
return; }
1191 if (m_current_module->props.size() == 0)
1198 animation.
ratio = this->ParseArgFloat(tokens[0].c_str());
1199 animation.
lower_limit = this->ParseArgFloat(tokens[1].c_str());
1200 animation.
upper_limit = this->ParseArgFloat(tokens[2].c_str());
1202 for (
auto itor = tokens.begin() + 3; itor != tokens.end(); ++itor)
1204 Ogre::StringVector entry = Ogre::StringUtil::split(*itor,
":");
1205 Ogre::StringUtil::trim(entry[0]);
1206 if (entry.size() > 1) Ogre::StringUtil::trim(entry[1]);
1208 const int WARN_LEN = 500;
1209 char warn_msg[WARN_LEN] =
"";
1211 if (entry.size() == 1)
1213 if (entry[0] ==
"autoanimate") { animation.
mode |= Animation::MODE_AUTO_ANIMATE; }
1214 else if (entry[0] ==
"noflip") { animation.
mode |= Animation::MODE_NO_FLIP; }
1215 else if (entry[0] ==
"bounce") { animation.
mode |= Animation::MODE_BOUNCE; }
1216 else if (entry[0] ==
"eventlock") { animation.
mode |= Animation::MODE_EVENT_LOCK; }
1218 else { snprintf(warn_msg, WARN_LEN,
"Invalid keyword: %s", entry[0].c_str()); }
1220 else if (entry.size() == 2 && (entry[0] ==
"mode" || entry[0] ==
"event" || entry[0] ==
"source" || entry[0] ==
"link"))
1222 Ogre::StringVector values = Ogre::StringUtil::split(entry[1],
"|");
1223 if (entry[0] ==
"mode")
1225 for (
auto itor = values.begin(); itor != values.end(); ++itor)
1227 std::string value = *itor;
1228 Ogre::StringUtil::trim(value);
1230 if (value ==
"x-rotation") { animation.
mode |= Animation::MODE_ROTATION_X; }
1231 else if (value ==
"y-rotation") { animation.
mode |= Animation::MODE_ROTATION_Y; }
1232 else if (value ==
"z-rotation") { animation.
mode |= Animation::MODE_ROTATION_Z; }
1233 else if (value ==
"x-offset" ) { animation.
mode |= Animation::MODE_OFFSET_X; }
1234 else if (value ==
"y-offset" ) { animation.
mode |= Animation::MODE_OFFSET_Y; }
1235 else if (value ==
"z-offset" ) { animation.
mode |= Animation::MODE_OFFSET_Z; }
1237 else { snprintf(warn_msg, WARN_LEN,
"Invalid 'mode': %s, ignoring...", entry[1].c_str()); }
1240 else if (entry[0] ==
"event")
1243 Ogre::StringUtil::trim(animation.
event_name);
1244 Ogre::StringUtil::toUpperCase(animation.
event_name);
1246 else if (entry[0] ==
"link")
1251 else if (entry[0] ==
"source")
1253 for (
auto itor = values.begin(); itor != values.end(); ++itor)
1255 std::string value = *itor;
1256 Ogre::StringUtil::trim(value);
1258 if (value ==
"airspeed") { animation.
source |= Animation::SOURCE_AIRSPEED; }
1259 else if (value ==
"vvi") { animation.
source |= Animation::SOURCE_VERTICAL_VELOCITY; }
1260 else if (value ==
"altimeter100k") { animation.
source |= Animation::SOURCE_ALTIMETER_100K; }
1261 else if (value ==
"altimeter10k") { animation.
source |= Animation::SOURCE_ALTIMETER_10K; }
1262 else if (value ==
"altimeter1k") { animation.
source |= Animation::SOURCE_ALTIMETER_1K; }
1263 else if (value ==
"aoa") { animation.
source |= Animation::SOURCE_ANGLE_OF_ATTACK; }
1264 else if (value ==
"flap") { animation.
source |= Animation::SOURCE_FLAP; }
1265 else if (value ==
"airbrake") { animation.
source |= Animation::SOURCE_AIR_BRAKE; }
1266 else if (value ==
"roll") { animation.
source |= Animation::SOURCE_ROLL; }
1267 else if (value ==
"pitch") { animation.
source |= Animation::SOURCE_PITCH; }
1268 else if (value ==
"brakes") { animation.
source |= Animation::SOURCE_BRAKES; }
1269 else if (value ==
"accel") { animation.
source |= Animation::SOURCE_ACCEL; }
1270 else if (value ==
"clutch") { animation.
source |= Animation::SOURCE_CLUTCH; }
1271 else if (value ==
"speedo") { animation.
source |= Animation::SOURCE_SPEEDO; }
1272 else if (value ==
"tacho") { animation.
source |= Animation::SOURCE_TACHO; }
1273 else if (value ==
"turbo") { animation.
source |= Animation::SOURCE_TURBO; }
1274 else if (value ==
"parking") { animation.
source |= Animation::SOURCE_PARKING; }
1275 else if (value ==
"shifterman1") { animation.
source |= Animation::SOURCE_SHIFT_LEFT_RIGHT; }
1276 else if (value ==
"shifterman2") { animation.
source |= Animation::SOURCE_SHIFT_BACK_FORTH; }
1277 else if (value ==
"sequential") { animation.
source |= Animation::SOURCE_SEQUENTIAL_SHIFT; }
1278 else if (value ==
"shifterlin") { animation.
source |= Animation::SOURCE_SHIFTERLIN; }
1279 else if (value ==
"autoshifterlin"){ animation.
source |= Animation::SOURCE_AUTOSHIFTERLIN; }
1280 else if (value ==
"torque") { animation.
source |= Animation::SOURCE_TORQUE; }
1281 else if (value ==
"heading") { animation.
source |= Animation::SOURCE_HEADING; }
1282 else if (value ==
"difflock") { animation.
source |= Animation::SOURCE_DIFFLOCK; }
1283 else if (value ==
"rudderboat") { animation.
source |= Animation::SOURCE_BOAT_RUDDER; }
1284 else if (value ==
"throttleboat") { animation.
source |= Animation::SOURCE_BOAT_THROTTLE; }
1285 else if (value ==
"steeringwheel") { animation.
source |= Animation::SOURCE_STEERING_WHEEL; }
1286 else if (value ==
"aileron") { animation.
source |= Animation::SOURCE_AILERON; }
1287 else if (value ==
"elevator") { animation.
source |= Animation::SOURCE_ELEVATOR; }
1288 else if (value ==
"rudderair") { animation.
source |= Animation::SOURCE_AIR_RUDDER; }
1289 else if (value ==
"permanent") { animation.
source |= Animation::SOURCE_PERMANENT; }
1290 else if (value ==
"event") { animation.
source |= Animation::SOURCE_EVENT; }
1291 else if (value ==
"dashboard") { animation.
source |= Animation::SOURCE_DASHBOARD; }
1292 else if (value ==
"signalstalk") { animation.
source |= Animation::SOURCE_SIGNALSTALK; }
1293 else if (value ==
"gearreverse") { animation.
source |= Animation::SOURCE_GEAR_REVERSE; }
1294 else if (value ==
"gearneutral") { animation.
source |= Animation::SOURCE_GEAR_NEUTRAL; }
1300 if (entry[1].compare(0, 8,
"throttle") == 0)
1302 motor_source.
source = Animation::MotorSource::SOURCE_AERO_THROTTLE;
1303 motor_source.
motor = this->ParseArgUint(entry[1].substr(8));
1305 else if (entry[1].compare(0, 3,
"rpm") == 0)
1307 motor_source.
source = Animation::MotorSource::SOURCE_AERO_RPM;
1308 motor_source.
motor = this->ParseArgUint(entry[1].substr(3));
1310 else if (entry[1].compare(0, 8,
"aerotorq") == 0)
1312 motor_source.
source = Animation::MotorSource::SOURCE_AERO_TORQUE;
1313 motor_source.
motor = this->ParseArgUint(entry[1].substr(8));
1315 else if (entry[1].compare(0, 7,
"aeropit") == 0)
1317 motor_source.
source = Animation::MotorSource::SOURCE_AERO_PITCH;
1318 motor_source.
motor = this->ParseArgUint(entry[1].substr(7));
1320 else if (entry[1].compare(0, 10,
"aerostatus") == 0)
1322 motor_source.
source = Animation::MotorSource::SOURCE_AERO_STATUS;
1323 motor_source.
motor = this->ParseArgUint(entry[1].substr(10));
1326 else if (entry[1].compare(0, 4,
"gear") == 0)
1328 motor_source.
source = Animation::MotorSource::SOURCE_GEAR_FORWARD;
1329 motor_source.
motor = this->ParseArgUint(entry[1].substr(4));
1333 snprintf(warn_msg, WARN_LEN,
"Invalid 'source': %s, ignoring...", entry[1].c_str());
1342 snprintf(warn_msg, WARN_LEN,
"Invalid keyword: %s, ignoring...", entry[0].c_str());
1347 snprintf(warn_msg, WARN_LEN,
"Invalid item: %s, ignoring...", entry[0].c_str());
1350 if (warn_msg[0] !=
'\0')
1353 fmt::format(
"Ignoring invalid token '{}' ({})", itor->c_str(), warn_msg));
1357 m_current_module->props.back().animations.push_back(animation);
1360 void Parser::ParseAntiLockBrakes()
1363 Ogre::StringVector tokens = Ogre::StringUtil::split(m_current_line + 15,
",");
1364 m_num_args = (int)tokens.size();
1365 if (! this->CheckNumArguments(2)) {
return; }
1368 alb.
min_speed = this->ParseArgInt (tokens[1].c_str());
1370 if (tokens.size() > 3) { alb.
pulse_per_sec = this->ParseArgFloat(tokens[2].c_str()); }
1372 for (
unsigned int i=3; i<tokens.size(); i++)
1374 Ogre::StringVector args2 = Ogre::StringUtil::split(tokens[i],
":");
1375 Ogre::StringUtil::trim(args2[0]);
1376 Ogre::StringUtil::toLowerCase(args2[0]);
1377 if (args2[0] ==
"mode" && args2.size() == 2)
1379 Ogre::StringVector attrs = Ogre::StringUtil::split(args2[1],
"&");
1380 auto itor = attrs.begin();
1381 auto endi = attrs.end();
1382 for (; itor != endi; ++itor)
1384 std::string attr = *itor;
1385 Ogre::StringUtil::trim(attr);
1386 Ogre::StringUtil::toLowerCase(attr);
1388 else if (strncmp(attr.c_str(),
"notoggle", 8) == 0) { alb.
attr_no_toggle =
true; }
1389 else if (strncmp(attr.c_str(),
"on", 2) == 0) { alb.
attr_is_on =
true; }
1390 else if (strncmp(attr.c_str(),
"off", 3) == 0) { alb.
attr_is_on =
false; }
1402 m_current_module->antilockbrakes.push_back(alb);
1406 void Parser::ParseEngoption()
1408 if (! this->CheckNumArguments(1)) {
return; }
1411 engoption.
inertia = this->GetArgFloat(0);
1413 if (m_num_args > 1) { engoption.
type = this->GetArgEngineType(1); }
1414 if (m_num_args > 2) { engoption.
clutch_force = this->GetArgFloat(2); }
1415 if (m_num_args > 3) { engoption.
shift_time = this->GetArgFloat(3); }
1416 if (m_num_args > 4) { engoption.
clutch_time = this->GetArgFloat(4); }
1417 if (m_num_args > 5) { engoption.
post_shift_time = this->GetArgFloat(5); }
1418 if (m_num_args > 6) { engoption.
stall_rpm = this->GetArgFloat(6); }
1419 if (m_num_args > 7) { engoption.
idle_rpm = this->GetArgFloat(7); }
1422 if (m_num_args > 10){ engoption.
braking_torque = this->GetArgFloat(10);}
1424 m_current_module->engoption.push_back(engoption);
1428 void Parser::ParseEngturbo()
1430 if (! this->CheckNumArguments(4)) {
return; }
1433 engturbo.
version = this->GetArgInt ( 0);
1435 engturbo.
nturbos = this->GetArgInt ( 2);
1436 engturbo.
param1 = this->GetArgFloat( 3);
1438 if (m_num_args > 4) { engturbo.
param2 = this->GetArgFloat( 4); }
1439 if (m_num_args > 5) { engturbo.
param3 = this->GetArgFloat( 5); }
1440 if (m_num_args > 6) { engturbo.
param4 = this->GetArgFloat( 6); }
1441 if (m_num_args > 7) { engturbo.
param5 = this->GetArgFloat( 7); }
1442 if (m_num_args > 8) { engturbo.
param6 = this->GetArgFloat( 8); }
1443 if (m_num_args > 9) { engturbo.
param7 = this->GetArgFloat( 9); }
1444 if (m_num_args > 10) { engturbo.
param8 = this->GetArgFloat(10); }
1445 if (m_num_args > 11) { engturbo.
param9 = this->GetArgFloat(11); }
1446 if (m_num_args > 12) { engturbo.
param10 = this->GetArgFloat(12); }
1447 if (m_num_args > 13) { engturbo.
param11 = this->GetArgFloat(13); }
1455 m_current_module->engturbo.push_back(engturbo);
1459 void Parser::ParseEngine()
1461 if (! this->CheckNumArguments(6)) {
return; }
1466 engine.
torque = this->GetArgFloat(2);
1472 for (
int i = 6; i < m_num_args; i++)
1474 float ratio = this->GetArgFloat(i);
1488 m_current_module->engine.push_back(engine);
1492 void Parser::ParseContacter()
1494 if (! this->CheckNumArguments(1)) {
return; }
1496 m_current_module->contacters.push_back(this->GetArgNodeRef(0));
1500 void Parser::ParseCommandsUnified()
1502 const bool is_commands2 = (m_current_block == Keyword::COMMANDS2);
1503 const int max_args = (is_commands2 ? 8 : 7);
1504 if (! this->CheckNumArguments(max_args)) {
return; }
1512 command2.
nodes[0] = this->GetArgNodeRef(pos++);
1513 command2.
nodes[1] = this->GetArgNodeRef(pos++);
1528 command2.
extend_key = this->GetArgInt (pos++);
1530 if (m_num_args <= max_args)
1532 m_current_module->commands2.push_back(command2);
1537 std::string options_str = this->GetArgStr(pos++);
1539 for (
auto itor = options_str.begin(); itor != options_str.end(); ++itor)
1541 const char c = *itor;
1542 if ((winner == 0) && (c ==
'o' || c ==
'p' || c ==
'c')) { winner = c; }
1577 if (
ignored != 0 && winner ==
'c')
1580 "Command cannot be one-pressed and self centering at the same time, ignoring flag '%c'");
1582 else if (
ignored != 0 && (winner ==
'o' || winner ==
'p'))
1585 "Command already has a one-pressed c.mode, ignoring flag '%c'");
1588 if (m_num_args > pos) { command2.
description = this->GetArgStr (pos++);}
1590 if (m_num_args > pos) { ParseOptionalInertia(command2.
inertia, pos); pos += 4; }
1592 if (m_num_args > pos) { command2.
affect_engine = this->GetArgFloat(pos++);}
1593 if (m_num_args > pos) { command2.
needs_engine = this->GetArgBool (pos++);}
1594 if (m_num_args > pos) { command2.
plays_sound = this->GetArgBool (pos++);}
1596 m_current_module->commands2.push_back(command2);
1600 void Parser::ParseCollisionBox()
1604 Ogre::StringVector tokens = Ogre::StringUtil::split(m_current_line,
",");
1605 Ogre::StringVector::iterator iter = tokens.begin();
1606 for ( ; iter != tokens.end(); iter++)
1608 collisionbox.
nodes.push_back( this->_ParseNodeRef(*iter) );
1611 m_current_module->collisionboxes.push_back(collisionbox);
1615 void Parser::ParseCinecam()
1617 if (! this->CheckNumArguments(11)) {
return; }
1624 cinecam.
position.x = this->GetArgFloat ( 0);
1625 cinecam.
position.y = this->GetArgFloat ( 1);
1626 cinecam.
position.z = this->GetArgFloat ( 2);
1627 cinecam.
nodes[0] = this->GetArgNodeRef( 3);
1628 cinecam.
nodes[1] = this->GetArgNodeRef( 4);
1629 cinecam.
nodes[2] = this->GetArgNodeRef( 5);
1630 cinecam.
nodes[3] = this->GetArgNodeRef( 6);
1631 cinecam.
nodes[4] = this->GetArgNodeRef( 7);
1632 cinecam.
nodes[5] = this->GetArgNodeRef( 8);
1633 cinecam.
nodes[6] = this->GetArgNodeRef( 9);
1634 cinecam.
nodes[7] = this->GetArgNodeRef(10);
1637 if (m_num_args > 11) { cinecam.
spring = this->GetArgFloat(11); }
1638 if (m_num_args > 12) { cinecam.
damping = this->GetArgFloat(12); }
1640 if (m_num_args > 13)
1642 float value = this->GetArgFloat(13);
1647 if (m_sequential_importer.IsEnabled())
1649 m_sequential_importer.AddGeneratedNode(Keyword::CINECAM);
1652 m_current_module->cinecam.push_back(cinecam);
1656 void Parser::ParseCameraRails()
1658 m_current_camera_rail->nodes.push_back( this->GetArgNodeRef(0) );
1661 void Parser::ParseBrakes()
1663 if (!this->CheckNumArguments(1)) {
return; }
1671 m_current_module->brakes.push_back(brakes);
1675 void Parser::ParseAxles()
1679 Ogre::StringVector tokens = Ogre::StringUtil::split(m_current_line,
",");
1680 Ogre::StringVector::iterator iter = tokens.begin();
1681 for ( ; iter != tokens.end(); iter++)
1683 std::smatch results;
1684 if (! std::regex_search(*iter, results, Regexes::SECTION_AXLES_PROPERTY))
1691 if (results[1].matched)
1693 unsigned int wheel_index =
PARSEINT(results[2]) - 1;
1694 axle.
wheels[wheel_index][0] = _ParseNodeRef(results[3]);
1695 axle.
wheels[wheel_index][1] = _ParseNodeRef(results[4]);
1697 else if (results[5].matched)
1699 this->_ParseDifferentialTypes(axle.
options, results[6].str());
1703 m_current_module->axles.push_back(axle);
1707 void Parser::ParseInterAxles()
1709 auto args = Ogre::StringUtil::split(m_current_line,
",");
1710 if (args.size() < 2) {
return; }
1714 interaxle.
a1 = this->ParseArgInt(args[0].c_str()) - 1;
1715 interaxle.
a2 = this->ParseArgInt(args[1].c_str()) - 1;
1717 std::smatch results;
1718 if (! std::regex_search(args[2], results, Regexes::SECTION_AXLES_PROPERTY))
1725 if (results[5].matched)
1727 this->_ParseDifferentialTypes(interaxle.
options, results[6].str());
1730 m_current_module->interaxles.push_back(interaxle);
1734 void Parser::ParseAirbrakes()
1736 if (! this->CheckNumArguments(14)) {
return; }
1743 airbrake.
offset.x = this->GetArgFloat ( 4);
1744 airbrake.
offset.y = this->GetArgFloat ( 5);
1745 airbrake.
offset.z = this->GetArgFloat ( 6);
1746 airbrake.
width = this->GetArgFloat ( 7);
1747 airbrake.
height = this->GetArgFloat ( 8);
1754 m_current_module->airbrakes.push_back(airbrake);
1755 this->FlushPendingDocComment(m_current_module->airbrakes.size(), Keyword::AIRBRAKES);
1758 void Parser::ParseAssetpacks()
1760 if (! this->CheckNumArguments(1)) {
return; }
1764 assetpack.
filename = this->GetArgStr(0);
1766 m_current_module->assetpacks.push_back(assetpack);
1767 this->FlushPendingDocComment(m_current_module->assetpacks.size(), Keyword::ASSETPACKS);
1770 void Parser::ParseVideoCamera()
1772 if (! this->CheckNumArguments(19)) {
return; }
1777 videocamera.
left_node = this->GetArgNodeRef ( 1);
1778 videocamera.
bottom_node = this->GetArgNodeRef ( 2);
1781 videocamera.
offset.x = this->GetArgFloat ( 5);
1782 videocamera.
offset.y = this->GetArgFloat ( 6);
1783 videocamera.
offset.z = this->GetArgFloat ( 7);
1784 videocamera.
rotation.x = this->GetArgFloat ( 8);
1785 videocamera.
rotation.y = this->GetArgFloat ( 9);
1786 videocamera.
rotation.z = this->GetArgFloat (10);
1792 videocamera.
camera_role = this->GetArgVideoCamRole(16);
1796 if (m_num_args > 19) { videocamera.
camera_name = this->GetArgStr(19); }
1798 m_current_module->videocameras.push_back(videocamera);
1799 this->FlushPendingDocComment(m_current_module->videocameras.size(), Keyword::VIDEOCAMERA);
1802 void Parser::ParseCameras()
1804 if (! this->CheckNumArguments(3)) {
return; }
1808 camera.
back_node = this->GetArgNodeRef(1);
1809 camera.
left_node = this->GetArgNodeRef(2);
1811 m_current_module->cameras.push_back(camera);
1812 this->FlushPendingDocComment(m_current_module->cameras.size(), Keyword::CAMERAS);
1815 void Parser::ParseTurbopropsUnified()
1817 bool is_turboprop_2 = m_current_block == Keyword::TURBOPROPS2;
1819 if (! this->CheckNumArguments(is_turboprop_2 ? 9 : 8)) {
return; }
1824 turboprop.
axis_node = this->GetArgNodeRef(1);
1834 turboprop.
couple_node = this->GetArgNullableNode(6);
1840 turboprop.
airfoil = this->GetArgStr (7 + offset);
1842 m_current_module->turboprops2.push_back(turboprop);
1843 this->FlushPendingDocComment(m_current_module->turboprops2.size(), Keyword::TURBOPROPS2);
1846 void Parser::ParseTurbojets()
1848 if (! this->CheckNumArguments(9)) {
return; }
1851 turbojet.
front_node = this->GetArgNodeRef(0);
1852 turbojet.
back_node = this->GetArgNodeRef(1);
1853 turbojet.
side_node = this->GetArgNodeRef(2);
1861 m_current_module->turbojets.push_back(turbojet);
1862 this->FlushPendingDocComment(m_current_module->turbojets.size(), Keyword::TURBOJETS);
1865 void Parser::ParseTriggers()
1867 if (! this->CheckNumArguments(6)) {
return; }
1872 trigger.
nodes[0] = this->GetArgNodeRef(0);
1873 trigger.
nodes[1] = this->GetArgNodeRef(1);
1878 if (m_num_args > 6) trigger.
options = this->GetArgTriggerOptions(6);
1879 if (m_num_args > 7) trigger.
boundary_timer = this->GetArgFloat(7);
1881 m_current_module->triggers.push_back(trigger);
1882 this->FlushPendingDocComment(m_current_module->triggers.size(), Keyword::TRIGGERS);
1885 void Parser::ParseTorqueCurve()
1887 if (m_current_module->torquecurve.size() == 0)
1889 m_current_module->torquecurve.push_back(
TorqueCurve());
1892 Ogre::StringVector args = Ogre::StringUtil::split(m_current_line,
",");
1894 if (args.size() == 1u)
1896 m_current_module->torquecurve[0].predefined_func_name = args[0];
1898 else if (args.size() == 2u)
1901 sample.
power = this->ParseArgFloat(args[0].c_str());
1903 m_current_module->torquecurve[0].samples.push_back(sample);
1912 void Parser::ParseTies()
1914 if (! this->CheckNumArguments(5)) {
return; }
1928 for (
char c: this->GetArgStr(5))
1932 case (
char)TieOption::n_DUMMY:
1933 case (
char)TieOption::v_DUMMY:
1936 case (
char)TieOption::i_INVISIBLE:
1937 tie.
options |= Tie::OPTION_i_INVISIBLE;
1940 case (
char)TieOption::s_NO_SELF_LOCK:
1941 tie.
options |= Tie::OPTION_s_DISABLE_SELF_LOCK;
1952 if (m_num_args > 6) { tie.
max_stress = this->GetArgFloat (6); }
1953 if (m_num_args > 7) { tie.
group = this->GetArgInt (7); }
1955 m_current_module->ties.push_back(tie);
1956 this->FlushPendingDocComment(m_current_module->ties.size(), Keyword::TIES);
1959 void Parser::ParseSoundsources()
1961 if (! this->CheckNumArguments(2)) {
return; }
1964 soundsource.
node = this->GetArgNodeRef(0);
1967 m_current_module->soundsources.push_back(soundsource);
1968 this->FlushPendingDocComment(m_current_module->soundsources.size(), Keyword::SOUNDSOURCES);
1971 void Parser::ParseSoundsources2()
1973 if (! this->CheckNumArguments(3)) {
return; }
1976 soundsource2.
node = this->GetArgNodeRef(0);
1977 soundsource2.
mode = this->GetArgInt(1);
1980 if (soundsource2.
mode < -2)
1983 fmt::format(
"invalid mode {}, falling back to default -2", soundsource2.
mode));
1984 soundsource2.
mode = -2;
1987 m_current_module->soundsources2.push_back(soundsource2);
1988 this->FlushPendingDocComment(m_current_module->soundsources2.size(), Keyword::SOUNDSOURCES2);
1991 void Parser::ParseSlidenodes()
1993 Ogre::StringVector args = Ogre::StringUtil::split(m_current_line,
", ");
1994 m_num_args = (int)args.size();
1995 if (! this->CheckNumArguments(2)) {
return; }
1998 slidenode.
slide_node = this->_ParseNodeRef(args[0]);
2000 bool in_rail_node_list =
true;
2002 for (
auto itor = args.begin() + 1; itor != args.end(); ++itor)
2004 char c = toupper(itor->at(0));
2008 slidenode.
spring_rate = this->ParseArgFloat(itor->substr(1));
2010 in_rail_node_list =
false;
2013 slidenode.
break_force = this->ParseArgFloat(itor->substr(1));
2015 in_rail_node_list =
false;
2018 slidenode.
tolerance = this->ParseArgFloat(itor->substr(1));
2020 in_rail_node_list =
false;
2025 in_rail_node_list =
false;
2028 slidenode.
railgroup_id = this->ParseArgFloat(itor->substr(1));
2030 in_rail_node_list =
false;
2035 in_rail_node_list =
false;
2038 switch (itor->at(1))
2054 fmt::format(
"Ignoring invalid option '{}'", itor->at(1)));
2057 in_rail_node_list =
false;
2060 if (in_rail_node_list)
2066 m_current_module->slidenodes.push_back(slidenode);
2067 this->FlushPendingDocComment(m_current_module->slidenodes.size(), Keyword::SLIDENODES);
2070 void Parser::ParseShock3()
2072 if (! this->CheckNumArguments(15)) {
return; }
2078 shock_3.
nodes[0] = this->GetArgNodeRef( 0);
2079 shock_3.
nodes[1] = this->GetArgNodeRef( 1);
2080 shock_3.
spring_in = this->GetArgFloat ( 2);
2081 shock_3.
damp_in = this->GetArgFloat ( 3);
2086 shock_3.
damp_out = this->GetArgFloat ( 8);
2094 if (m_num_args > 15) shock_3.
options = this->GetArgShock3Options(15);
2096 m_current_module->shocks3.push_back(shock_3);
2097 this->FlushPendingDocComment(m_current_module->shocks3.size(), Keyword::SHOCKS3);
2100 void Parser::ParseShock2()
2102 if (! this->CheckNumArguments(13)) {
return; }
2108 shock_2.
nodes[0] = this->GetArgNodeRef( 0);
2109 shock_2.
nodes[1] = this->GetArgNodeRef( 1);
2110 shock_2.
spring_in = this->GetArgFloat ( 2);
2111 shock_2.
damp_in = this->GetArgFloat ( 3);
2115 shock_2.
damp_out = this->GetArgFloat ( 7);
2122 if (m_num_args > 13) shock_2.
options = this->GetArgShock2Options(13);
2124 m_current_module->shocks2.push_back(shock_2);
2125 this->FlushPendingDocComment(m_current_module->shocks2.size(), Keyword::SHOCKS2);
2128 void Parser::ParseShock()
2130 if (! this->CheckNumArguments(7)) {
return; }
2136 shock.
nodes[0] = this->GetArgNodeRef(0);
2137 shock.
nodes[1] = this->GetArgNodeRef(1);
2139 shock.
damping = this->GetArgFloat (3);
2143 if (m_num_args > 7) shock.
options = this->GetArgShockOptions(7);
2145 m_current_module->shocks.push_back(shock);
2146 this->FlushPendingDocComment(m_current_module->shocks.size(), Keyword::SHOCKS);
2149 Node::Ref Parser::_ParseNodeRef(std::string
const & node_id_str)
2151 if (m_sequential_importer.IsEnabled())
2154 int node_id_num =
PARSEINT(node_id_str);
2155 if (node_id_num < 0)
2161 unsigned int flags = Node::Ref::IMPORT_STATE_IS_VALID |
2162 Node::Ref::REGULAR_STATE_IS_VALID | Node::Ref::REGULAR_STATE_IS_NAMED;
2163 if (m_any_named_node_defined)
2165 flags |= Node::Ref::IMPORT_STATE_MUST_CHECK_NAMED_FIRST;
2167 return Node::Ref(node_id_str, node_id_num, flags, m_current_line_number);
2172 return Node::Ref(node_id_str, 0, Node::Ref::REGULAR_STATE_IS_VALID | Node::Ref::REGULAR_STATE_IS_NAMED, m_current_line_number);
2176 void Parser::ParseDirectiveSetDefaultMinimass()
2178 if (! this->CheckNumArguments(2)) {
return; }
2180 m_set_default_minimass = std::shared_ptr<DefaultMinimass>(
new DefaultMinimass());
2181 m_set_default_minimass->min_mass_Kg = this->GetArgFloat(1);
2184 void Parser::ParseFlaregroupsNoImport()
2188 if (!this->CheckNumArguments(1)) {
return; }
2191 fni.
type = this->GetArgFlareType(0);
2206 m_current_module->flaregroups_no_import.push_back(fni);
2209 void Parser::ParseDirectiveSetInertiaDefaults()
2211 if (! this->CheckNumArguments(2)) {
return; }
2213 float start_delay = this->GetArgFloat(1);
2214 float stop_delay = 0;
2215 if (m_num_args > 2) { stop_delay = this->GetArgFloat(2); }
2217 if (start_delay < 0 || stop_delay < 0)
2219 m_user_default_inertia = m_ror_default_inertia;
2229 if (m_num_args > 4) { i->
stop_function = this->GetArgStr(4); }
2231 m_user_default_inertia = std::shared_ptr<Inertia>(i);
2234 void Parser::ParseScrewprops()
2236 if (! this->CheckNumArguments(4)) {
return; }
2240 screwprop.
prop_node = this->GetArgNodeRef(0);
2241 screwprop.
back_node = this->GetArgNodeRef(1);
2242 screwprop.
top_node = this->GetArgNodeRef(2);
2243 screwprop.
power = this->GetArgFloat (3);
2245 m_current_module->screwprops.push_back(screwprop);
2246 this->FlushPendingDocComment(m_current_module->screwprops.size(), Keyword::SCREWPROPS);
2249 void Parser::ParseScripts()
2251 if (!this->CheckNumArguments(1)) {
return; }
2255 script.
filename = this->GetArgStr(0);
2257 m_current_module->scripts.push_back(script);
2258 this->FlushPendingDocComment(m_current_module->scripts.size(), Keyword::SCRIPTS);
2261 void Parser::ParseRotatorsUnified()
2263 if (! this->CheckNumArguments(13)) {
return; }
2268 rotator.
axis_nodes[0] = this->GetArgNodeRef( 0);
2269 rotator.
axis_nodes[1] = this->GetArgNodeRef( 1);
2278 rotator.
rate = this->GetArgFloat (10);
2284 if (m_current_block == Keyword::ROTATORS2)
2286 if (! this->CheckNumArguments(16)) {
return; }
2287 if (m_num_args > 13) { rotator.
rotating_force = this->GetArgFloat(13); }
2288 if (m_num_args > 14) { rotator.
tolerance = this->GetArgFloat(14); }
2289 if (m_num_args > 15) { rotator.
description = this->GetArgStr (15); }
2294 this->ParseOptionalInertia(rotator.
inertia, 13 + offset);
2295 if (m_num_args > 17 + offset) { rotator.
engine_coupling = this->GetArgFloat(17 + offset); }
2296 if (m_num_args > 18 + offset) { rotator.
needs_engine = this->GetArgBool (18 + offset); }
2298 if (m_current_block == Keyword::ROTATORS2)
2300 m_current_module->rotators2.push_back(rotator);
2301 this->FlushPendingDocComment(m_current_module->rotators2.size(), Keyword::ROTATORS2);
2305 m_current_module->rotators.push_back(rotator);
2306 this->FlushPendingDocComment(m_current_module->rotators.size(), Keyword::ROTATORS);
2310 void Parser::ParseFileinfo()
2312 if (! this->CheckNumArguments(2)) {
return; }
2316 fileinfo.
unique_id = this->GetArgStr(1);
2317 Ogre::StringUtil::trim(fileinfo.
unique_id);
2319 if (m_num_args > 2) { fileinfo.
category_id = this->GetArgInt(2); }
2320 if (m_num_args > 3) { fileinfo.
file_version = this->GetArgInt(3); }
2322 m_current_module->fileinfo.push_back(fileinfo);
2324 m_current_block = Keyword::INVALID;
2327 void Parser::ParseRopes()
2329 if (! this->CheckNumArguments(2)) {
return; }
2334 rope.
root_node = this->GetArgNodeRef(0);
2335 rope.
end_node = this->GetArgNodeRef(1);
2337 if (m_num_args > 2) { rope.
invisible = (this->GetArgChar(2) ==
'i'); }
2339 m_current_module->ropes.push_back(rope);
2340 this->FlushPendingDocComment(m_current_module->ropes.size(), Keyword::ROPES);
2343 void Parser::ParseRopables()
2345 if (! this->CheckNumArguments(1)) {
return; }
2348 ropable.
node = this->GetArgNodeRef(0);
2350 if (m_num_args > 1) { ropable.
group = this->GetArgInt(1); }
2351 if (m_num_args > 2) { ropable.
has_multilock = (this->GetArgInt(2) == 1); }
2353 m_current_module->ropables.push_back(ropable);
2354 this->FlushPendingDocComment(m_current_module->ropables.size(), Keyword::ROPABLES);
2357 void Parser::ParseRailGroups()
2359 Ogre::StringVector args = Ogre::StringUtil::split(m_current_line,
",");
2360 m_num_args = (int)args.size();
2361 if (! this->CheckNumArguments(3)) {
return; }
2364 railgroup.
id = this->ParseArgInt(args[0].c_str());
2366 for (
auto itor = args.begin() + 1; itor != args.end(); itor++)
2368 railgroup.
node_list.push_back( this->_ParseNodeRef(*itor));
2371 m_current_module->railgroups.push_back(railgroup);
2372 this->FlushPendingDocComment(m_current_module->railgroups.size(), Keyword::RAILGROUPS);
2375 void Parser::ParseProps()
2377 if (! this->CheckNumArguments(10)) {
return; }
2383 prop.
offset.x = this->GetArgFloat (3);
2384 prop.
offset.y = this->GetArgFloat (4);
2385 prop.
offset.z = this->GetArgFloat (5);
2386 prop.
rotation.x = this->GetArgFloat (6);
2387 prop.
rotation.y = this->GetArgFloat (7);
2388 prop.
rotation.z = this->GetArgFloat (8);
2392 if ((prop.
special == SpecialProp::BEACON) && (m_num_args >= 14))
2398 this->GetArgFloat(11), this->GetArgFloat(12), this->GetArgFloat(13));
2400 else if (prop.
special == SpecialProp::DASHBOARD_LEFT ||
2401 prop.
special == SpecialProp::DASHBOARD_RIGHT)
2404 if (m_num_args > 13)
2412 m_current_module->props.push_back(prop);
2413 this->FlushPendingDocComment(m_current_module->props.size(), Keyword::PROPS);
2416 void Parser::ParsePistonprops()
2418 if (!this->CheckNumArguments(10)) {
return; }
2422 pistonprop.
axis_node = this->GetArgNodeRef (1);
2427 pistonprop.
couple_node = this->GetArgNullableNode(6);
2429 pistonprop.
pitch = this->GetArgFloat (8);
2430 pistonprop.
airfoil = this->GetArgStr (9);
2432 m_current_module->pistonprops.push_back(pistonprop);
2433 this->FlushPendingDocComment(m_current_module->pistonprops.size(), Keyword::PISTONPROPS);
2436 void Parser::ParseParticles()
2438 if (!this->CheckNumArguments(3)) {
return; }
2445 m_current_module->particles.push_back(particle);
2446 this->FlushPendingDocComment(m_current_module->particles.size(), Keyword::PARTICLES);
2450 void Parser::_TrimTrailingComments(std::string
const & line_in, std::string & line_out)
2454 int comment_start =
static_cast<int>(line_in.find_first_of(
";"));
2455 if (comment_start != Ogre::String::npos)
2457 line_out = line_in.substr(0, comment_start);
2461 comment_start =
static_cast<int>(line_in.find_last_of(
"/"));
2462 if (comment_start != Ogre::String::npos)
2464 while (comment_start >= 0)
2466 char c = line_in[comment_start - 1];
2467 if (c !=
'/' && c !=
' ' && c !=
'\t')
2473 line_out = line_in.substr(0, comment_start);
2480 void Parser::ParseNodesUnified()
2482 if (! this->CheckNumArguments(4)) {
return; }
2490 if (m_current_block == Keyword::NODES2)
2492 std::string node_name = this->GetArgStr(0);
2494 if (m_sequential_importer.IsEnabled())
2496 m_sequential_importer.AddNamedNode(node_name);
2498 m_any_named_node_defined =
true;
2502 const unsigned int node_num = this->GetArgUint(0);
2504 if (m_sequential_importer.IsEnabled())
2506 m_sequential_importer.AddNumberedNode(node_num);
2510 node.
position.x = this->GetArgFloat(1);
2511 node.
position.y = this->GetArgFloat(2);
2512 node.
position.z = this->GetArgFloat(3);
2515 node.
options = this->GetArgNodeOptions(4);
2519 if (node.
options & Node::OPTION_l_LOAD_WEIGHT)
2527 "Node has load-weight-override value specified, but option 'l' is not present. Ignoring value...");
2531 m_current_module->nodes.push_back(node);
2532 this->FlushPendingDocComment(m_current_module->nodes.size(), Keyword::NODES);
2535 void Parser::ParseMinimass()
2537 if (! this->CheckNumArguments(1)) {
return; }
2541 if (m_num_args > 1) { mm.
option = this->GetArgMinimassOption(1); }
2543 m_current_module->minimass.push_back(mm);
2544 m_current_block = Keyword::INVALID;
2547 void Parser::ParseFlexBodyWheel()
2549 if (! this->CheckNumArguments(16)) {
return; }
2555 flexbody_wheel.
tyre_radius = this->GetArgFloat ( 0);
2556 flexbody_wheel.
rim_radius = this->GetArgFloat ( 1);
2557 flexbody_wheel.
width = this->GetArgFloat ( 2);
2558 flexbody_wheel.
num_rays = this->GetArgInt ( 3);
2559 flexbody_wheel.
nodes[0] = this->GetArgNodeRef ( 4);
2560 flexbody_wheel.
nodes[1] = this->GetArgNodeRef ( 5);
2561 flexbody_wheel.
rigidity_node = this->GetArgRigidityNode ( 6);
2562 flexbody_wheel.
braking = this->GetArgBraking ( 7);
2563 flexbody_wheel.
propulsion = this->GetArgPropulsion ( 8);
2565 flexbody_wheel.
mass = this->GetArgFloat (10);
2569 flexbody_wheel.
rim_damping = this->GetArgFloat (14);
2570 flexbody_wheel.
side = this->GetArgWheelSide (15);
2572 if (m_num_args > 16) { flexbody_wheel.
rim_mesh_name = this->GetArgStr(16); }
2573 if (m_num_args > 17) { flexbody_wheel.
tyre_mesh_name = this->GetArgStr(17); }
2575 if (m_sequential_importer.IsEnabled())
2580 m_current_module->flexbodywheels.push_back(flexbody_wheel);
2581 this->FlushPendingDocComment(m_current_module->flexbodywheels.size(), Keyword::FLEXBODYWHEELS);
2584 void Parser::ParseMaterialFlareBindings()
2586 if (! this->CheckNumArguments(2)) {
return; }
2592 m_current_module->materialflarebindings.push_back(binding);
2593 this->FlushPendingDocComment(m_current_module->materialflarebindings.size(), Keyword::MATERIALFLAREBINDINGS);
2596 void Parser::ParseManagedMaterials()
2598 if (! this->CheckNumArguments(2)) {
return; }
2601 managed_mat.
options = m_current_managed_material_options;
2602 managed_mat.
name = this->GetArgStr(0);
2603 managed_mat.
type = this->GetArgManagedMatType(1);
2605 if (managed_mat.
type != ManagedMaterialType::INVALID)
2607 if (! this->CheckNumArguments(3)) {
return; }
2611 if (managed_mat.
type == ManagedMaterialType::MESH_STANDARD ||
2612 managed_mat.
type == ManagedMaterialType::MESH_TRANSPARENT)
2614 if (m_num_args > 3) { managed_mat.
specular_map = this->GetArgManagedTex(3); }
2616 else if (managed_mat.
type == ManagedMaterialType::FLEXMESH_STANDARD ||
2617 managed_mat.
type == ManagedMaterialType::FLEXMESH_TRANSPARENT)
2620 if (m_num_args > 4) { managed_mat.
specular_map = this->GetArgManagedTex(4); }
2623 m_current_module->managedmaterials.push_back(managed_mat);
2624 this->FlushPendingDocComment(m_current_module->managedmaterials.size(), Keyword::MANAGEDMATERIALS);
2628 void Parser::ParseLockgroups()
2630 if (! this->CheckNumArguments(2)) {
return; }
2633 lockgroup.
number = this->GetArgInt(0);
2635 for (
int i = 1; i < m_num_args; ++i)
2637 lockgroup.
nodes.push_back(this->GetArgNodeRef(i));
2640 m_current_module->lockgroups.push_back(lockgroup);
2641 this->FlushPendingDocComment(m_current_module->lockgroups.size(), Keyword::LOCKGROUPS);
2644 void Parser::ParseHydros()
2646 if (! this->CheckNumArguments(3)) {
return; }
2653 hydro.
nodes[0] = this->GetArgNodeRef(0);
2654 hydro.
nodes[1] = this->GetArgNodeRef(1);
2657 if (m_num_args > 3) { hydro.
options = this->GetArgHydroOptions(3); }
2661 hydro.
options |= Hydro::OPTION_n_INPUT_NORMAL;
2664 this->ParseOptionalInertia(hydro.
inertia, 4);
2666 m_current_module->hydros.push_back(hydro);
2667 this->FlushPendingDocComment(m_current_module->hydros.size(), Keyword::HYDROS);
2670 void Parser::ParseOptionalInertia(
Inertia & inertia,
int index)
2673 if (m_num_args > index) { inertia.
stop_delay_factor = this->GetArgFloat(index++); }
2674 if (m_num_args > index) { inertia.
start_function = this->GetArgStr (index++); }
2675 if (m_num_args > index) { inertia.
stop_function = this->GetArgStr (index++); }
2680 for (
char c: options_str)
2684 case (
char)DifferentialType::o_OPEN:
2685 case (
char)DifferentialType::l_LOCKED:
2686 case (
char)DifferentialType::s_SPLIT:
2687 case (
char)DifferentialType::v_VISCOUS:
2693 fmt::format(
"ignoring invalid differential type '{}'", c));
2699 void Parser::ParseBeams()
2701 if (! this->CheckNumArguments(2)) {
return; }
2704 beam.
defaults = m_user_beam_defaults;
2707 beam.
nodes[0] = this->GetArgNodeRef(0);
2708 beam.
nodes[1] = this->GetArgNodeRef(1);
2709 if (m_num_args > 2) beam.
options = this->GetArgBeamOptions(2);
2713 float support_break_limit = 0.0f;
2714 float support_break_factor = this->GetArgInt(3);
2715 if (support_break_factor > 0.0f)
2717 support_break_limit = support_break_factor;
2723 m_current_module->beams.push_back(beam);
2724 this->FlushPendingDocComment(m_current_module->beams.size(), Keyword::BEAMS);
2727 void Parser::ParseAnimator()
2729 auto args = Ogre::StringUtil::split(m_current_line,
",");
2730 if (args.size() < 4) {
return; }
2737 animator.
nodes[0] = this->_ParseNodeRef(args[0]);
2738 animator.
nodes[1] = this->_ParseNodeRef(args[1]);
2742 Ogre::StringVector attrs = Ogre::StringUtil::split(args[3],
"|");
2744 auto itor = attrs.begin();
2745 auto endi = attrs.end();
2746 for (; itor != endi; ++itor)
2748 Ogre::String token = *itor;
2749 Ogre::StringUtil::trim(token);
2750 std::smatch results;
2751 bool is_shortlimit =
false;
2754 if (std::regex_search(token, results, Regexes::PARSE_ANIMATORS_NUMBERED_KEYWORD))
2756 if (results[1] ==
"throttle") animator.
aero_animator.
flags |= AeroAnimator::OPTION_THROTTLE;
2757 else if (results[1] ==
"rpm") animator.
aero_animator.
flags |= AeroAnimator::OPTION_RPM;
2758 else if (results[1] ==
"aerotorq") animator.
aero_animator.
flags |= AeroAnimator::OPTION_TORQUE;
2759 else if (results[1] ==
"aeropit") animator.
aero_animator.
flags |= AeroAnimator::OPTION_PITCH;
2760 else if (results[1] ==
"aerostatus") animator.
aero_animator.
flags |= AeroAnimator::OPTION_STATUS;
2764 else if ((is_shortlimit = (token.compare(0, 10,
"shortlimit") == 0)) || (token.compare(0, 9,
"longlimit") == 0))
2766 Ogre::StringVector fields = Ogre::StringUtil::split(token,
":");
2767 if (fields.size() > 1)
2771 animator.
short_limit = std::strtod(fields[1].c_str(),
nullptr);
2772 animator.
flags |= Animator::OPTION_SHORT_LIMIT;
2776 animator.
long_limit = std::strtod(fields[1].c_str(),
nullptr);
2777 animator.
flags |= Animator::OPTION_LONG_LIMIT;
2784 if (token ==
"vis") animator.
flags |= Animator::OPTION_VISIBLE;
2785 else if (token ==
"inv") animator.
flags |= Animator::OPTION_INVISIBLE;
2786 else if (token ==
"airspeed") animator.
flags |= Animator::OPTION_AIRSPEED;
2787 else if (token ==
"vvi") animator.
flags |= Animator::OPTION_VERTICAL_VELOCITY;
2788 else if (token ==
"altimeter100k") animator.
flags |= Animator::OPTION_ALTIMETER_100K;
2789 else if (token ==
"altimeter10k") animator.
flags |= Animator::OPTION_ALTIMETER_10K;
2790 else if (token ==
"altimeter1k") animator.
flags |= Animator::OPTION_ALTIMETER_1K;
2791 else if (token ==
"aoa") animator.
flags |= Animator::OPTION_ANGLE_OF_ATTACK;
2792 else if (token ==
"flap") animator.
flags |= Animator::OPTION_FLAP;
2793 else if (token ==
"airbrake") animator.
flags |= Animator::OPTION_AIR_BRAKE;
2794 else if (token ==
"roll") animator.
flags |= Animator::OPTION_ROLL;
2795 else if (token ==
"pitch") animator.
flags |= Animator::OPTION_PITCH;
2796 else if (token ==
"brakes") animator.
flags |= Animator::OPTION_BRAKES;
2797 else if (token ==
"accel") animator.
flags |= Animator::OPTION_ACCEL;
2798 else if (token ==
"clutch") animator.
flags |= Animator::OPTION_CLUTCH;
2799 else if (token ==
"speedo") animator.
flags |= Animator::OPTION_SPEEDO;
2800 else if (token ==
"tacho") animator.
flags |= Animator::OPTION_TACHO;
2801 else if (token ==
"turbo") animator.
flags |= Animator::OPTION_TURBO;
2802 else if (token ==
"parking") animator.
flags |= Animator::OPTION_PARKING;
2803 else if (token ==
"shifterman1") animator.
flags |= Animator::OPTION_SHIFT_LEFT_RIGHT;
2804 else if (token ==
"shifterman2") animator.
flags |= Animator::OPTION_SHIFT_BACK_FORTH;
2805 else if (token ==
"sequential") animator.
flags |= Animator::OPTION_SEQUENTIAL_SHIFT;
2806 else if (token ==
"shifterlin") animator.
flags |= Animator::OPTION_GEAR_SELECT;
2807 else if (token ==
"torque") animator.
flags |= Animator::OPTION_TORQUE;
2808 else if (token ==
"difflock") animator.
flags |= Animator::OPTION_DIFFLOCK;
2809 else if (token ==
"rudderboat") animator.
flags |= Animator::OPTION_BOAT_RUDDER;
2810 else if (token ==
"throttleboat") animator.
flags |= Animator::OPTION_BOAT_THROTTLE;
2814 m_current_module->animators.push_back(animator);
2815 this->FlushPendingDocComment(m_current_module->animators.size(), Keyword::ANIMATORS);
2818 void Parser::ParseAuthor()
2820 if (! this->CheckNumArguments(2)) {
return; }
2823 if (m_num_args > 1) { author.
type = this->GetArgStr(1); }
2825 if (m_num_args > 3) { author.
name = this->GetArgStr(3); }
2826 if (m_num_args > 4) { author.
email = this->GetArgStr(4); }
2828 m_current_module->author.push_back(author);
2829 this->FlushPendingDocComment(m_current_module->author.size(), Keyword::AUTHOR);
2830 m_current_block = Keyword::INVALID;
2843 m_filename, m_current_line_number,
KeywordToString(m_log_keyword), msg));
2846 Keyword Parser::IdentifyKeyword(
const std::string& line)
2849 std::smatch results;
2850 std::regex_search(line, results, Regexes::IDENTIFY_KEYWORD_IGNORE_CASE);
2854 for (
unsigned int i = 1; i < results.size(); i++)
2856 std::ssub_match sub = results[i];
2864 return Keyword::INVALID;
2867 void Parser::Prepare()
2869 m_current_block = Keyword::INVALID;
2870 m_current_line_number = 1;
2872 m_any_named_node_defined =
false;
2873 m_current_detacher_group = 0;
2875 m_user_default_inertia = m_ror_default_inertia;
2876 m_user_node_defaults = m_ror_node_defaults;
2879 m_user_beam_defaults = std::shared_ptr<BeamDefaults>(
new BeamDefaults);
2882 m_user_beam_defaults->deformation_threshold =
BEAM_DEFORM;
2883 m_user_beam_defaults->breaking_threshold =
BEAM_BREAK;
2886 m_root_module = m_definition->root_module;
2887 m_current_module = m_definition->root_module;
2889 m_sequential_importer.Init(
true);
2894 if (
keyword == Keyword::INVALID)
2897 if (m_current_submesh !=
nullptr)
2899 m_current_module->submeshes.push_back(*m_current_submesh);
2900 m_current_submesh.reset();
2904 if (m_current_camera_rail !=
nullptr)
2906 if (m_current_camera_rail->nodes.size() == 0)
2912 m_current_module->camerarail.push_back(*m_current_camera_rail);
2913 m_current_camera_rail.reset();
2917 else if (
keyword == Keyword::CAMERARAIL)
2919 this->BeginBlock(Keyword::INVALID);
2920 m_current_camera_rail = std::shared_ptr<CameraRail>(
new CameraRail() );
2928 std::string new_module_name;
2929 if (
keyword == Keyword::END_SECTION)
2931 if (m_current_module == m_root_module)
2938 else if (
keyword == Keyword::SECTION)
2940 if (!this->CheckNumArguments(3))
2945 new_module_name = this->GetArgStr(2);
2946 if (new_module_name == m_current_module->name)
2954 this->BeginBlock(Keyword::INVALID);
2958 m_current_module = m_root_module;
2962 auto search_itor = m_definition->user_modules.find(new_module_name);
2963 if (search_itor != m_definition->user_modules.end())
2965 m_current_module = search_itor->second;
2969 m_current_module = std::make_shared<Document::Module>(new_module_name);
2970 m_definition->user_modules.insert(std::make_pair(new_module_name, m_current_module));
2976 if (m_pending_doc_comment.comment_text ==
"" || vectorlen == 0)
2981 m_pending_doc_comment.commented_keyword =
keyword;
2982 m_pending_doc_comment.commented_datapos =
static_cast<int>(vectorlen - 1);
2983 m_current_module->_comments.push_back(m_pending_doc_comment);
2988 void Parser::ParseDirectiveSection()
2990 this->ProcessChangeModuleLine(Keyword::SECTION);
2993 void Parser::ParseDirectiveSectionConfig()
2998 void Parser::Finalize()
3000 this->BeginBlock(Keyword::INVALID);
3002 if (m_sequential_importer.IsEnabled())
3004 m_sequential_importer.Process( m_definition );
3008 std::string Parser::GetArgStr(
int index)
3010 return std::string(m_args[index].start, m_args[index].length);
3013 char Parser::GetArgChar(
int index)
3015 return *(m_args[index].start);
3020 char c = this->GetArgChar(index);
3029 fmt::format(
"Bad arg~{} 'side' (value: {}), parsing as 'l' for backwards compatibility.", index + 1, c));
3034 long Parser::GetArgLong(
int index)
3037 char* out_end =
nullptr;
3038 long res = std::strtol(m_args[index].start, &out_end, 10);
3042 fmt::format(
"Cannot parse argument [{}] as integer, errno: {}", index + 1, errno));
3045 if (out_end == m_args[index].start)
3048 fmt::format(
"Argument [{}] is not valid integer", index + 1));
3051 else if (out_end != (m_args[index].start + m_args[index].length))
3054 fmt::format(
"Integer argument [{}] has invalid trailing characters", index + 1));
3059 int Parser::GetArgInt(
int index)
3061 return static_cast<int>(this->GetArgLong(index));
3066 std::string rigidity_node = this->GetArgStr(index);
3067 if (rigidity_node !=
"9999")
3069 return this->GetArgNodeRef(index);
3076 int p = this->GetArgInt(index);
3086 fmt::format(
"Bad value of param ~{} (propulsion), using 0 (no propulsion)", index + 1));
3093 int b = this->GetArgInt(index);
3105 fmt::format(
"Bad value of param ~{} (braking), using 0 (not braked)", index + 1));
3112 return this->_ParseNodeRef(this->GetArgStr(index));
3117 if (! (Ogre::StringConverter::parseReal(this->GetArgStr(index)) == -1.f))
3119 return this->GetArgNodeRef(index);
3124 unsigned Parser::GetArgUint(
int index)
3126 return static_cast<unsigned>(this->GetArgLong(index));
3131 char in = this->GetArgChar(index);
3152 fmt::format(
"Invalid flare type '{}', falling back to type 'f' (front light)...", in));
3159 std::string str = this->GetArgStr(index);
3165 fmt::format(
"Invalid ExtCameraMode '{}', falling back to type 'classic'...", str));
3169 float Parser::GetArgFloat(
int index)
3171 return (
float) Ogre::StringConverter::parseReal(this->GetArgStr(index), 0.f);
3174 float Parser::ParseArgFloat(
const char* str)
3176 return (
float) Ogre::StringConverter::parseReal(str, 0.f);
3179 float Parser::ParseArgFloat(std::string
const & str)
3181 return this->ParseArgFloat(str.c_str());
3184 unsigned Parser::ParseArgUint(
const char* str)
3187 long res = std::strtol(str,
nullptr, 10);
3191 fmt::format(
"Cannot parse argument '{}' as int, errno: {}", str, errno));
3194 return static_cast<unsigned>(res);
3197 unsigned Parser::ParseArgUint(std::string
const & str)
3199 return this->ParseArgUint(str.c_str());
3202 int Parser::ParseArgInt(
const char* str)
3204 return static_cast<int>(this->ParseArgUint(str));
3207 bool Parser::GetArgBool(
int index)
3209 return Ogre::StringConverter::parseBool(this->GetArgStr(index));
3214 char c = this->GetArgChar(index);
3217 case (
char)WingControlSurface::n_NONE:
3218 case (
char)WingControlSurface::a_RIGHT_AILERON:
3219 case (
char)WingControlSurface::b_LEFT_AILERON:
3220 case (
char)WingControlSurface::f_FLAP:
3221 case (
char)WingControlSurface::e_ELEVATOR:
3222 case (
char)WingControlSurface::r_RUDDER:
3223 case (
char)WingControlSurface::S_RIGHT_HAND_STABILATOR:
3224 case (
char)WingControlSurface::T_LEFT_HAND_STABILATOR:
3225 case (
char)WingControlSurface::c_RIGHT_ELEVON:
3226 case (
char)WingControlSurface::d_LEFT_ELEVON:
3227 case (
char)WingControlSurface::g_RIGHT_FLAPERON:
3228 case (
char)WingControlSurface::h_LEFT_FLAPERON:
3229 case (
char)WingControlSurface::U_RIGHT_HAND_TAILERON:
3230 case (
char)WingControlSurface::V_LEFT_HAND_TAILERON:
3231 case (
char)WingControlSurface::i_RIGHT_RUDDERVATOR:
3232 case (
char)WingControlSurface::j_LEFT_RUDDERVATOR:
3236 fmt::format(
"invalid WingControlSurface '{}', falling back to 'n' (none)", c);
3237 return WingControlSurface::n_NONE;
3241 std::string Parser::GetArgManagedTex(
int index)
3243 std::string tex_name = this->GetArgStr(index);
3244 return (tex_name.at(0) !=
'-') ? tex_name :
"";
3249 switch (this->GetArgStr(index)[0])
3251 case (
char)MinimassOption::l_SKIP_LOADED:
3252 return MinimassOption::l_SKIP_LOADED;
3254 case (
char)MinimassOption::n_DUMMY:
3255 return MinimassOption::n_DUMMY;
3259 fmt::format(
"Not a valid minimass option: {}, falling back to 'n' (dummy)", this->GetArgStr(index)));
3260 return MinimassOption::n_DUMMY;
3267 for (
char c: this->GetArgStr(index))
3271 case (
char)CabOption::n_DUMMY:
break;
3272 case (
char)CabOption::c_CONTACT: ret |= Cab::OPTION_c_CONTACT ;
break;
3273 case (
char)CabOption::b_BUOYANT: ret |= Cab::OPTION_b_BUOYANT ;
break;
3274 case (
char)CabOption::p_10xTOUGHER: ret |= Cab::OPTION_p_10xTOUGHER ;
break;
3275 case (
char)CabOption::u_INVULNERABLE: ret |= Cab::OPTION_u_INVULNERABLE ;
break;
3276 case (
char)CabOption::s_BUOYANT_NO_DRAG: ret |= Cab::OPTION_s_BUOYANT_NO_DRAG ;
break;
3277 case (
char)CabOption::r_BUOYANT_ONLY_DRAG: ret |= Cab::OPTION_r_BUOYANT_ONLY_DRAG ;
break;
3278 case (
char)CabOption::D_CONTACT_BUOYANT: ret |= Cab::OPTION_D_CONTACT_BUOYANT ;
break;
3279 case (
char)CabOption::F_10xTOUGHER_BUOYANT: ret |= Cab::OPTION_F_10xTOUGHER_BUOYANT ;
break;
3280 case (
char)CabOption::S_INVULNERABLE_BUOYANT: ret |= Cab::OPTION_S_INVULNERABLE_BUOYANT;
break;
3293 for (
char c: this->GetArgStr(index))
3297 case (
char)TriggerOption::i_INVISIBLE : ret |= Trigger::OPTION_i_INVISIBLE;
break;
3298 case (
char)TriggerOption::c_COMMAND_STYLE : ret |= Trigger::OPTION_c_COMMAND_STYLE;
break;
3299 case (
char)TriggerOption::x_START_DISABLED : ret |= Trigger::OPTION_x_START_DISABLED;
break;
3300 case (
char)TriggerOption::b_KEY_BLOCKER : ret |= Trigger::OPTION_b_KEY_BLOCKER;
break;
3301 case (
char)TriggerOption::B_TRIGGER_BLOCKER : ret |= Trigger::OPTION_B_TRIGGER_BLOCKER;
break;
3302 case (
char)TriggerOption::A_INV_TRIGGER_BLOCKER: ret |= Trigger::OPTION_A_INV_TRIGGER_BLOCKER;
break;
3303 case (
char)TriggerOption::s_CMD_NUM_SWITCH : ret |= Trigger::OPTION_s_CMD_NUM_SWITCH;
break;
3304 case (
char)TriggerOption::h_UNLOCKS_HOOK_GROUP : ret |= Trigger::OPTION_h_UNLOCKS_HOOK_GROUP;
break;
3305 case (
char)TriggerOption::H_LOCKS_HOOK_GROUP : ret |= Trigger::OPTION_H_LOCKS_HOOK_GROUP;
break;
3306 case (
char)TriggerOption::t_CONTINUOUS : ret |= Trigger::OPTION_t_CONTINUOUS;
break;
3307 case (
char)TriggerOption::E_ENGINE_TRIGGER : ret |= Trigger::OPTION_E_ENGINE_TRIGGER;
break;
3320 for (
char c: this->GetArgStr(index))
3324 case (
char)BeamOption::i_INVISIBLE: ret |= Beam::OPTION_i_INVISIBLE;
break;
3325 case (
char)BeamOption::r_ROPE : ret |= Beam::OPTION_r_ROPE ;
break;
3326 case (
char)BeamOption::s_SUPPORT : ret |= Beam::OPTION_s_SUPPORT ;
break;
3328 case (
char)BeamOption::v_DUMMY:
break;
3341 for (
char c: this->GetArgStr(index))
3345 case (
char)HydroOption::j_INVISIBLE : ret |= Hydro::OPTION_j_INVISIBLE ;
break;
3346 case (
char)HydroOption::s_DISABLE_ON_HIGH_SPEED : ret |= Hydro::OPTION_s_DISABLE_ON_HIGH_SPEED ;
break;
3347 case (
char)HydroOption::a_INPUT_AILERON : ret |= Hydro::OPTION_a_INPUT_AILERON ;
break;
3348 case (
char)HydroOption::r_INPUT_RUDDER : ret |= Hydro::OPTION_r_INPUT_RUDDER ;
break;
3349 case (
char)HydroOption::e_INPUT_ELEVATOR : ret |= Hydro::OPTION_e_INPUT_ELEVATOR ;
break;
3350 case (
char)HydroOption::u_INPUT_AILERON_ELEVATOR : ret |= Hydro::OPTION_u_INPUT_AILERON_ELEVATOR ;
break;
3351 case (
char)HydroOption::v_INPUT_InvAILERON_ELEVATOR: ret |= Hydro::OPTION_v_INPUT_InvAILERON_ELEVATOR;
break;
3352 case (
char)HydroOption::x_INPUT_AILERON_RUDDER : ret |= Hydro::OPTION_x_INPUT_AILERON_RUDDER ;
break;
3353 case (
char)HydroOption::y_INPUT_InvAILERON_RUDDER : ret |= Hydro::OPTION_y_INPUT_InvAILERON_RUDDER ;
break;
3354 case (
char)HydroOption::g_INPUT_ELEVATOR_RUDDER : ret |= Hydro::OPTION_g_INPUT_ELEVATOR_RUDDER ;
break;
3355 case (
char)HydroOption::h_INPUT_InvELEVATOR_RUDDER : ret |= Hydro::OPTION_h_INPUT_InvELEVATOR_RUDDER ;
break;
3356 case (
char)HydroOption::n_INPUT_NORMAL : ret |= Hydro::OPTION_n_INPUT_NORMAL ;
break;
3358 case (
char)HydroOption::i_INVISIBLE_INPUT_NORMAL:
3363 ret |= Hydro::OPTION_n_INPUT_NORMAL;
3365 ret |= Hydro::OPTION_j_INVISIBLE;
3380 for (
char c: this->GetArgStr(index))
3384 case (
char)ShockOption::i_INVISIBLE : ret |= Shock::OPTION_i_INVISIBLE ;
break;
3385 case (
char)ShockOption::L_ACTIVE_LEFT : ret |= Shock::OPTION_L_ACTIVE_LEFT ;
break;
3386 case (
char)ShockOption::R_ACTIVE_RIGHT : ret |= Shock::OPTION_R_ACTIVE_RIGHT;
break;
3387 case (
char)ShockOption::m_METRIC : ret |= Shock::OPTION_m_METRIC ;
break;
3389 case (
char)ShockOption::n_DUMMY:
break;
3390 case (
char)ShockOption::v_DUMMY:
break;
3403 for (
char c: this->GetArgStr(index))
3407 case (
char)Shock2Option::i_INVISIBLE: ret |= Shock2::OPTION_i_INVISIBLE;
break;
3408 case (
char)Shock2Option::s_SOFT_BUMP_BOUNDS: ret |= Shock2::OPTION_s_SOFT_BUMP_BOUNDS;
break;
3409 case (
char)Shock2Option::m_METRIC: ret |= Shock2::OPTION_m_METRIC;
break;
3410 case (
char)Shock2Option::M_ABSOLUTE_METRIC: ret |= Shock2::OPTION_M_ABSOLUTE_METRIC;
break;
3412 case (
char)Shock2Option::n_DUMMY:
break;
3413 case (
char)Shock2Option::v_DUMMY:
break;
3426 for (
char c: this->GetArgStr(index))
3430 case (
char)Shock3Option::i_INVISIBLE: ret |= Shock3::OPTION_i_INVISIBLE;
break;
3431 case (
char)Shock3Option::m_METRIC: ret |= Shock3::OPTION_m_METRIC;
break;
3432 case (
char)Shock3Option::M_ABSOLUTE_METRIC: ret |= Shock3::OPTION_M_ABSOLUTE_METRIC;
break;
3434 case (
char)Shock3Option::n_DUMMY:
break;
3435 case (
char)Shock3Option::v_DUMMY:
break;
3448 for (
char c: this->GetArgStr(index))
3452 case (
char)NodeOption::m_NO_MOUSE_GRAB : ret |= Node::OPTION_m_NO_MOUSE_GRAB ;
break;
3453 case (
char)NodeOption::f_NO_SPARKS : ret |= Node::OPTION_f_NO_SPARKS ;
break;
3454 case (
char)NodeOption::x_EXHAUST_POINT : ret |= Node::OPTION_x_EXHAUST_POINT ;
break;
3455 case (
char)NodeOption::y_EXHAUST_DIRECTION : ret |= Node::OPTION_y_EXHAUST_DIRECTION ;
break;
3456 case (
char)NodeOption::c_NO_GROUND_CONTACT : ret |= Node::OPTION_c_NO_GROUND_CONTACT ;
break;
3457 case (
char)NodeOption::h_HOOK_POINT : ret |= Node::OPTION_h_HOOK_POINT ;
break;
3458 case (
char)NodeOption::e_TERRAIN_EDIT_POINT: ret |= Node::OPTION_e_TERRAIN_EDIT_POINT;
break;
3459 case (
char)NodeOption::b_EXTRA_BUOYANCY : ret |= Node::OPTION_b_EXTRA_BUOYANCY ;
break;
3460 case (
char)NodeOption::p_NO_PARTICLES : ret |= Node::OPTION_p_NO_PARTICLES ;
break;
3461 case (
char)NodeOption::L_LOG : ret |= Node::OPTION_L_LOG ;
break;
3462 case (
char)NodeOption::l_LOAD_WEIGHT : ret |= Node::OPTION_l_LOAD_WEIGHT ;
break;
3464 case (
char)NodeOption::n_DUMMY:
break;
3476 if (str.find(
"leftmirror" ) != std::string::npos) {
return SpecialProp::MIRROR_LEFT; }
3477 if (str.find(
"rightmirror" ) != std::string::npos) {
return SpecialProp::MIRROR_RIGHT; }
3478 if (str.find(
"dashboard-rh") != std::string::npos) {
return SpecialProp::DASHBOARD_RIGHT; }
3479 if (str.find(
"dashboard" ) != std::string::npos) {
return SpecialProp::DASHBOARD_LEFT; }
3480 if (Ogre::StringUtil::startsWith(str,
"spinprop",
false) ) {
return SpecialProp::AERO_PROP_SPIN; }
3481 if (Ogre::StringUtil::startsWith(str,
"pale",
false) ) {
return SpecialProp::AERO_PROP_BLADE; }
3482 if (Ogre::StringUtil::startsWith(str,
"seat",
false) ) {
return SpecialProp::DRIVER_SEAT; }
3483 if (Ogre::StringUtil::startsWith(str,
"seat2",
false) ) {
return SpecialProp::DRIVER_SEAT_2; }
3484 if (Ogre::StringUtil::startsWith(str,
"beacon",
false) ) {
return SpecialProp::BEACON; }
3485 if (Ogre::StringUtil::startsWith(str,
"redbeacon",
false)) {
return SpecialProp::REDBEACON; }
3486 if (Ogre::StringUtil::startsWith(str,
"lightb",
false) ) {
return SpecialProp::LIGHTBAR; }
3487 return SpecialProp::NONE;
3492 char c = this->GetArgChar(index);
3495 case (
char)EngineType::t_TRUCK:
3496 case (
char)EngineType::c_CAR:
3497 case (
char)EngineType::e_ECAR:
3501 fmt::format(
"invalid EngineType '{}', falling back to 't' (truck)", c);
3502 return EngineType::t_TRUCK;
3508 std::string str = this->GetArgStr(index);
3509 if (str ==
"mesh_standard")
return ManagedMaterialType::MESH_STANDARD;
3510 if (str ==
"mesh_transparent")
return ManagedMaterialType::MESH_TRANSPARENT;
3511 if (str ==
"flexmesh_standard")
return ManagedMaterialType::FLEXMESH_STANDARD;
3512 if (str ==
"flexmesh_transparent")
return ManagedMaterialType::FLEXMESH_TRANSPARENT;
3515 fmt::format(
"Not a valid ManagedMaterialType: '{}'", str));
3516 return ManagedMaterialType::INVALID;
3521 int role = this->GetArgInt(index);
3530 fmt::format(
"Invalid value of 'camera role' ({}), videocamera will not work", role));
3535 int Parser::TokenizeCurrentLine()
3538 const char* cur_char = m_current_line;
3540 while ((*cur_char !=
'\0') && (cur_arg < Parser::LINE_MAX_ARGS))
3543 if ((arg_len == 0) && is_arg)
3545 m_args[cur_arg].start = cur_char;
3548 else if ((arg_len > 0) && !is_arg)
3550 m_args[cur_arg].length = arg_len;
3562 m_args[cur_arg].length = arg_len;
3566 m_num_args = cur_arg;
3570 void Parser::ProcessOgreStream(Ogre::DataStream* stream, Ogre::String resource_group)
3572 m_resource_group = resource_group;
3573 m_filename = stream->getName();
3575 char raw_line_buf[LINE_BUFFER_LENGTH];
3576 while (!stream->eof())
3580 stream->readLine(raw_line_buf, LINE_BUFFER_LENGTH - 1);
3581 raw_line_buf[LINE_BUFFER_LENGTH - 1] =
'\0';
3583 catch (Ogre::Exception &ex)
3586 fmt::format(
"Could not read truck file: {}", ex.getFullDescription()));
3590 this->ProcessRawLine(raw_line_buf);
3594 void Parser::ProcessRawLine(
const char* raw_line_buf)
3596 const char* raw_start = raw_line_buf;
3597 const char* raw_end = raw_line_buf +
strnlen(raw_line_buf, LINE_BUFFER_LENGTH);
3600 while (
IsWhitespace(*raw_start) && (raw_start != raw_end))
3606 if (raw_start == raw_end)
3608 ++m_current_line_number;
3613 if ((*raw_start ==
';') || (*raw_start ==
'/'))
3615 m_pending_doc_comment.comment_text += raw_line_buf;
3616 m_pending_doc_comment.comment_text +=
'\n';
3617 ++m_current_line_number;
3622 memset(m_current_line, 0, LINE_BUFFER_LENGTH);
3623 char* out_start = m_current_line;
3624 utf8::replace_invalid(raw_start, raw_end, out_start,
'?');
3627 this->ProcessCurrentLine();
3628 ++m_current_line_number;