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; }
624 m_user_beam_defaults = std::shared_ptr<BeamDefaults>(
new BeamDefaults(d) );
628 void Parser::ParseDirectivePropCameraMode()
630 if (! this->CheckNumArguments(2)) {
return; }
632 if (m_current_module->props.size() > 0)
634 m_current_module->props[m_current_module->props.size() - 1].camera_settings.mode = this->GetArgInt(1);
642 void Parser::ParseDirectiveSubmesh()
644 this->BeginBlock(Keyword::INVALID);
645 m_current_submesh = std::shared_ptr<Submesh>(
new Submesh() );
648 void Parser::ParseDirectiveBackmesh()
650 if (m_current_submesh)
652 m_current_submesh->backmesh =
true;
664 case Keyword::DISABLEDEFAULTSOUNDS: m_definition->disable_default_sounds =
true;
return;
665 case Keyword::ENABLE_ADVANCED_DEFORMATION: m_definition->enable_advanced_deformation =
true;
return;
666 case Keyword::FORWARDCOMMANDS: m_definition->forward_commands =
true;
return;
667 case Keyword::IMPORTCOMMANDS: m_definition->import_commands =
true;
return;
668 case Keyword::HIDEINCHOOSER: m_definition->hide_in_chooser =
true;
return;
669 case Keyword::LOCKGROUP_DEFAULT_NOLOCK: m_definition->lockgroup_default_nolock =
true;
return;
670 case Keyword::RESCUER: m_definition->rescuer =
true;
return;
671 case Keyword::ROLLON: m_definition->rollon =
true;
return;
672 case Keyword::SLIDENODE_CONNECT_INSTANTLY: m_definition->slide_nodes_connect_instantly =
true;
return;
684 mesh_wheel.
rim_radius = this->GetArgFloat ( 1);
685 mesh_wheel.
width = this->GetArgFloat ( 2);
686 mesh_wheel.
num_rays = this->GetArgInt ( 3);
687 mesh_wheel.
nodes[0] = this->GetArgNodeRef ( 4);
688 mesh_wheel.
nodes[1] = this->GetArgNodeRef ( 5);
690 mesh_wheel.
braking = this->GetArgBraking ( 7);
691 mesh_wheel.
propulsion = this->GetArgPropulsion ( 8);
693 mesh_wheel.
mass = this->GetArgFloat (10);
694 mesh_wheel.
spring = this->GetArgFloat (11);
695 mesh_wheel.
damping = this->GetArgFloat (12);
696 mesh_wheel.
side = this->GetArgWheelSide (13);
697 mesh_wheel.
mesh_name = this->GetArgStr (14);
701 void Parser::ParseMeshWheel()
703 if (! this->CheckNumArguments(16)) {
return; }
706 this->_ParseBaseMeshWheel(mesh_wheel);
708 if (m_sequential_importer.IsEnabled())
713 m_current_module->meshwheels.push_back(mesh_wheel);
717 void Parser::ParseMeshWheel2()
719 if (! this->CheckNumArguments(16)) {
return; }
722 this->_ParseBaseMeshWheel(mesh_wheel);
724 if (m_sequential_importer.IsEnabled())
729 m_current_module->meshwheels2.push_back(mesh_wheel);
733 void Parser::ParseHook()
735 if (! this->CheckNumArguments(1)) {
return; }
738 hook.
node = this->GetArgNodeRef(0);
741 while (i < m_num_args)
743 std::string attr = this->GetArgStr(i);
744 Ogre::StringUtil::trim(attr);
745 const bool has_value = (i < (m_num_args - 1));
748 if (has_value && (attr ==
"hookrange") ) { hook.
option_hook_range = this->GetArgFloat(++i); }
749 else if (has_value && (attr ==
"speedcoef") ) { hook.
option_speed_coef = this->GetArgFloat(++i); }
750 else if (has_value && (attr ==
"maxforce") ) { hook.
option_max_force = this->GetArgFloat(++i); }
751 else if (has_value && (attr ==
"timer") ) { hook.
option_timer = this->GetArgFloat(++i); }
752 else if (has_value && (attr ==
"hookgroup" || attr ==
"hgroup") ) { hook.
option_hookgroup = this->GetArgInt (++i); }
753 else if (has_value && (attr ==
"lockgroup" || attr ==
"lgroup") ) { hook.
option_lockgroup = this->GetArgInt (++i); }
754 else if (has_value && (attr ==
"shortlimit" || attr ==
"short_limit")) { hook.
option_min_range_meters = this->GetArgFloat(++i); }
756 else if ((attr ==
"selflock") ||(attr ==
"self-lock") ||(attr ==
"self_lock") ) { hook.
flag_self_lock =
true; }
757 else if ((attr ==
"autolock") ||(attr ==
"auto-lock") ||(attr ==
"auto_lock") ) { hook.
flag_auto_lock =
true; }
758 else if ((attr ==
"nodisable")||(attr ==
"no-disable")||(attr ==
"no_disable")) { hook.
flag_no_disable =
true; }
759 else if ((attr ==
"norope") ||(attr ==
"no-rope") ||(attr ==
"no_rope") ) { hook.
flag_no_rope =
true; }
760 else if ((attr ==
"visible") ||(attr ==
"vis") ) { hook.
flag_visible =
true; }
768 m_current_module->hooks.push_back(hook);
772 void Parser::ParseHelp()
776 m_current_module->help.push_back(h);
779 void Parser::ParseGuiSettings()
781 if (! this->CheckNumArguments(2)) {
return; }
784 gs.
key = this->GetArgStr(0);
785 gs.
value = this->GetArgStr(1);
787 m_current_module->guisettings.push_back(gs);
791 void Parser::ParseGuid()
793 if (! this->CheckNumArguments(2)) {
return; }
796 g.
guid = this->GetArgStr(1);
798 m_current_module->guid.push_back(g);
802 void Parser::ParseGlobals()
804 if (! this->CheckNumArguments(2)) {
return; }
807 globals.
dry_mass = this->GetArgFloat(0);
810 if (m_num_args > 2) { globals.
material_name = this->GetArgStr(2); }
812 m_current_module->globals.push_back(globals);
816 void Parser::ParseFusedrag()
818 if (! this->CheckNumArguments(3)) {
return; }
822 fusedrag.
rear_node = this->GetArgNodeRef(1);
824 if (this->GetArgStr(2) ==
"autocalc")
830 if (m_num_args > 4) { fusedrag.
airfoil_name = this->GetArgStr (4); }
837 if (m_num_args > 3) { fusedrag.
airfoil_name = this->GetArgStr(3); }
840 m_current_module->fusedrag.push_back(fusedrag);
844 void Parser::ParseDirectiveFlexbodyCameraMode()
846 if (! this->CheckNumArguments(2)) {
return; }
848 if (m_current_module->flexbodies.size() > 0)
850 m_current_module->flexbodies[m_current_module->flexbodies.size() - 1].camera_settings.mode = this->GetArgInt(1);
858 void Parser::ParseCab()
860 if (! this->CheckNumArguments(3)) {
return; }
862 if (!m_current_submesh)
869 cab.
nodes[0] = this->GetArgNodeRef(0);
870 cab.
nodes[1] = this->GetArgNodeRef(1);
871 cab.
nodes[2] = this->GetArgNodeRef(2);
872 if (m_num_args > 3) cab.
options = this->GetArgCabOptions(3);
874 m_current_submesh->cab_triangles.push_back(cab);
878 void Parser::ParseTexcoords()
880 if (! this->CheckNumArguments(3)) {
return; }
882 if (!m_current_submesh)
889 texcoord.
node = this->GetArgNodeRef(0);
890 texcoord.
u = this->GetArgFloat (1);
891 texcoord.
v = this->GetArgFloat (2);
893 m_current_submesh->texcoords.push_back(texcoord);
897 void Parser::ParseFlexbody()
899 if (! this->CheckNumArguments(10)) {
return; }
905 flexbody.
offset.x = this->GetArgFloat (3);
906 flexbody.
offset.y = this->GetArgFloat (4);
907 flexbody.
offset.z = this->GetArgFloat (5);
908 flexbody.
rotation.x = this->GetArgFloat (6);
909 flexbody.
rotation.y = this->GetArgFloat (7);
910 flexbody.
rotation.z = this->GetArgFloat (8);
911 flexbody.
mesh_name = this->GetArgStr (9);
913 m_current_module->flexbodies.push_back(flexbody);
917 void Parser::ParseDirectiveForset()
919 if (m_current_module->flexbodies.size() == 0)
925 Parser::ProcessForsetLine(m_current_module->flexbodies.back(), m_current_line, m_current_line_number);
928 void Parser::ParseDirectiveForvert()
930 if (m_current_module->flexbodies.size() == 0)
936 if (!this->CheckNumArguments(4)) {
return; }
940 forvert.
node_ref = this->GetArgNodeRef(1);
941 forvert.
node_x = this->GetArgNodeRef(2);
942 forvert.
node_y = this->GetArgNodeRef(3);
946 const char* input_pos = std::strstr(m_current_line,
"verts:");
953 std::string input = input_pos;
954 std::regex pattern(R
"((\d+)\s*-\s*(\d+)|(\d+))");
957 std::string::const_iterator searchStart(input.cbegin());
958 while (std::regex_search(searchStart, input.cend(), matches, pattern))
960 if (matches[1].matched && matches[2].matched)
963 int start = std::stoi(matches[1].str());
964 int end = std::stoi(matches[2].str());
965 for (
int i = start; i <= end; ++i)
968 m_current_module->flexbodies.back().forvert.push_back(forvert);
971 else if (matches[3].matched)
974 forvert.
vert_index = std::stoi(matches[3].str());
975 m_current_module->flexbodies.back().forvert.push_back(forvert);
977 searchStart = matches.suffix().first;
981 void Parser::ProcessForsetLine(
RigDef::Flexbody& def,
const std::string& _line,
int line_number )
991 std::string line = _line;
992 char* pos = &line[0] + 6;
993 while (*pos ==
' ' || *pos ==
':' || *pos ==
',') { pos++; }
1000 while (*end !=
'-' && *end !=
',' && *end != 0) end++;
1003 val1 = strtoul(pos, 0, 10);
1008 while (*end !=
',' && *end != 0) end++;
1011 val2 = strtoul(pos, 0, 10);
1015 Node::Ref(std::to_string(val1), val1, Node::Ref::IMPORT_STATE_IS_VALID, line_number),
1016 Node::Ref(std::to_string(val2), val2, Node::Ref::IMPORT_STATE_IS_VALID, line_number)));
1028 void Parser::ParseFlaresUnified()
1030 const bool is_flares2 = (m_current_block == Keyword::FLARES2);
1031 if (! this->CheckNumArguments(is_flares2 ? 6 : 5)) {
return; }
1038 flare2.
offset.x = this->GetArgFloat (pos++);
1039 flare2.
offset.y = this->GetArgFloat (pos++);
1041 if (m_current_block == Keyword::FLARES2)
1043 flare2.
offset.z = this->GetArgFloat(pos++);
1046 if (m_num_args > pos) { flare2.
type = this->GetArgFlareType(pos++); }
1048 if (m_num_args > pos)
1050 switch (flare2.
type)
1060 if (m_num_args > pos) { flare2.
size = this->GetArgFloat (pos++); }
1061 if (m_num_args > pos) { flare2.
material_name = this->GetArgStr (pos++); }
1063 m_current_module->flares2.push_back(flare2);
1067 void Parser::ParseFlares3()
1069 const bool is_flares2 = (m_current_block == Keyword::FLARES2);
1070 if (! this->CheckNumArguments(is_flares2 ? 6 : 5)) {
return; }
1078 flare3.
offset.x = this->GetArgFloat(3);
1079 flare3.
offset.y = this->GetArgFloat(4);
1080 flare3.
offset.z = this->GetArgFloat(5);
1081 if (m_num_args > 6) { flare3.
type = this->GetArgFlareType(6); }
1085 switch (flare3.
type)
1094 if (m_num_args > 9) { flare3.
size = this->GetArgFloat (9); }
1095 if (m_num_args > 10) { flare3.
material_name = this->GetArgStr (10); }
1097 m_current_module->flares3.push_back(flare3);
1101 void Parser::ParseFixes()
1103 m_current_module->fixes.push_back(this->GetArgNodeRef(0));
1106 void Parser::ParseExtCamera()
1108 if (! this->CheckNumArguments(2)) {
return; }
1111 extcam.
mode = this->GetArgExtCameraMode(1);
1112 if (m_num_args > 2) { extcam.
node = this->GetArgNodeRef(2); }
1114 m_current_module->extcamera.push_back(extcam);
1118 void Parser::ParseExhaust()
1120 if (! this->CheckNumArguments(2)) {
return; }
1127 if (m_num_args > 3) { exhaust.
particle_name = this->GetArgStr(3); }
1129 m_current_module->exhausts.push_back(exhaust);
1133 void Parser::ParseFileFormatVersion()
1135 if (! this->CheckNumArguments(2)) {
return; }
1138 ffv.
version = this->GetArgInt(1);
1140 m_current_module->fileformatversion.push_back(ffv);
1141 m_current_block = Keyword::INVALID;
1144 void Parser::ParseDirectiveDefaultSkin()
1146 if (!this->CheckNumArguments(2)) {
return; }
1152 m_current_module->default_skin.push_back(data);
1156 void Parser::ParseDirectiveDetacherGroup()
1158 if (! this->CheckNumArguments(2)) {
return; }
1160 if (this->GetArgStr(1) ==
"end")
1162 m_current_detacher_group = 0;
1166 m_current_detacher_group = this->GetArgInt(1);
1170 void Parser::ParseCruiseControl()
1172 if (! this->CheckNumArguments(3)) {
return; }
1175 cruise_control.
min_speed = this->GetArgFloat(1);
1176 cruise_control.
autobrake = this->GetArgInt(2);
1178 m_current_module->cruisecontrol.push_back(cruise_control);
1182 void Parser::ParseDescription()
1184 m_current_module->description.push_back(m_current_line);
1187 void Parser::ParseDirectiveAddAnimation()
1189 Ogre::StringVector tokens = Ogre::StringUtil::split(m_current_line + 14,
",");
1190 m_num_args = (int)tokens.size();
1191 if (! this->CheckNumArguments(4)) {
return; }
1193 if (m_current_module->props.size() == 0)
1200 animation.
ratio = this->ParseArgFloat(tokens[0].c_str());
1201 animation.
lower_limit = this->ParseArgFloat(tokens[1].c_str());
1202 animation.
upper_limit = this->ParseArgFloat(tokens[2].c_str());
1204 for (
auto itor = tokens.begin() + 3; itor != tokens.end(); ++itor)
1206 Ogre::StringVector entry = Ogre::StringUtil::split(*itor,
":");
1207 Ogre::StringUtil::trim(entry[0]);
1208 if (entry.size() > 1) Ogre::StringUtil::trim(entry[1]);
1210 const int WARN_LEN = 500;
1211 char warn_msg[WARN_LEN] =
"";
1213 if (entry.size() == 1)
1215 if (entry[0] ==
"autoanimate") { animation.
mode |= Animation::MODE_AUTO_ANIMATE; }
1216 else if (entry[0] ==
"noflip") { animation.
mode |= Animation::MODE_NO_FLIP; }
1217 else if (entry[0] ==
"bounce") { animation.
mode |= Animation::MODE_BOUNCE; }
1218 else if (entry[0] ==
"eventlock") { animation.
mode |= Animation::MODE_EVENT_LOCK; }
1220 else { snprintf(warn_msg, WARN_LEN,
"Invalid keyword: %s", entry[0].c_str()); }
1222 else if (entry.size() == 2 && (entry[0] ==
"mode" || entry[0] ==
"event" || entry[0] ==
"source" || entry[0] ==
"link"))
1224 Ogre::StringVector values = Ogre::StringUtil::split(entry[1],
"|");
1225 if (entry[0] ==
"mode")
1227 for (
auto itor = values.begin(); itor != values.end(); ++itor)
1229 std::string value = *itor;
1230 Ogre::StringUtil::trim(value);
1232 if (value ==
"x-rotation") { animation.
mode |= Animation::MODE_ROTATION_X; }
1233 else if (value ==
"y-rotation") { animation.
mode |= Animation::MODE_ROTATION_Y; }
1234 else if (value ==
"z-rotation") { animation.
mode |= Animation::MODE_ROTATION_Z; }
1235 else if (value ==
"x-offset" ) { animation.
mode |= Animation::MODE_OFFSET_X; }
1236 else if (value ==
"y-offset" ) { animation.
mode |= Animation::MODE_OFFSET_Y; }
1237 else if (value ==
"z-offset" ) { animation.
mode |= Animation::MODE_OFFSET_Z; }
1239 else { snprintf(warn_msg, WARN_LEN,
"Invalid 'mode': %s, ignoring...", entry[1].c_str()); }
1242 else if (entry[0] ==
"event")
1245 Ogre::StringUtil::trim(animation.
event_name);
1246 Ogre::StringUtil::toUpperCase(animation.
event_name);
1248 else if (entry[0] ==
"link")
1253 else if (entry[0] ==
"source")
1255 for (
auto itor = values.begin(); itor != values.end(); ++itor)
1257 std::string value = *itor;
1258 Ogre::StringUtil::trim(value);
1260 if (value ==
"airspeed") { animation.
source |= Animation::SOURCE_AIRSPEED; }
1261 else if (value ==
"vvi") { animation.
source |= Animation::SOURCE_VERTICAL_VELOCITY; }
1262 else if (value ==
"altimeter100k") { animation.
source |= Animation::SOURCE_ALTIMETER_100K; }
1263 else if (value ==
"altimeter10k") { animation.
source |= Animation::SOURCE_ALTIMETER_10K; }
1264 else if (value ==
"altimeter1k") { animation.
source |= Animation::SOURCE_ALTIMETER_1K; }
1265 else if (value ==
"aoa") { animation.
source |= Animation::SOURCE_ANGLE_OF_ATTACK; }
1266 else if (value ==
"flap") { animation.
source |= Animation::SOURCE_FLAP; }
1267 else if (value ==
"airbrake") { animation.
source |= Animation::SOURCE_AIR_BRAKE; }
1268 else if (value ==
"roll") { animation.
source |= Animation::SOURCE_ROLL; }
1269 else if (value ==
"pitch") { animation.
source |= Animation::SOURCE_PITCH; }
1270 else if (value ==
"brakes") { animation.
source |= Animation::SOURCE_BRAKES; }
1271 else if (value ==
"accel") { animation.
source |= Animation::SOURCE_ACCEL; }
1272 else if (value ==
"clutch") { animation.
source |= Animation::SOURCE_CLUTCH; }
1273 else if (value ==
"speedo") { animation.
source |= Animation::SOURCE_SPEEDO; }
1274 else if (value ==
"tacho") { animation.
source |= Animation::SOURCE_TACHO; }
1275 else if (value ==
"turbo") { animation.
source |= Animation::SOURCE_TURBO; }
1276 else if (value ==
"parking") { animation.
source |= Animation::SOURCE_PARKING; }
1277 else if (value ==
"shifterman1") { animation.
source |= Animation::SOURCE_SHIFT_LEFT_RIGHT; }
1278 else if (value ==
"shifterman2") { animation.
source |= Animation::SOURCE_SHIFT_BACK_FORTH; }
1279 else if (value ==
"sequential") { animation.
source |= Animation::SOURCE_SEQUENTIAL_SHIFT; }
1280 else if (value ==
"shifterlin") { animation.
source |= Animation::SOURCE_SHIFTERLIN; }
1281 else if (value ==
"autoshifterlin"){ animation.
source |= Animation::SOURCE_AUTOSHIFTERLIN; }
1282 else if (value ==
"torque") { animation.
source |= Animation::SOURCE_TORQUE; }
1283 else if (value ==
"heading") { animation.
source |= Animation::SOURCE_HEADING; }
1284 else if (value ==
"difflock") { animation.
source |= Animation::SOURCE_DIFFLOCK; }
1285 else if (value ==
"rudderboat") { animation.
source |= Animation::SOURCE_BOAT_RUDDER; }
1286 else if (value ==
"throttleboat") { animation.
source |= Animation::SOURCE_BOAT_THROTTLE; }
1287 else if (value ==
"steeringwheel") { animation.
source |= Animation::SOURCE_STEERING_WHEEL; }
1288 else if (value ==
"aileron") { animation.
source |= Animation::SOURCE_AILERON; }
1289 else if (value ==
"elevator") { animation.
source |= Animation::SOURCE_ELEVATOR; }
1290 else if (value ==
"rudderair") { animation.
source |= Animation::SOURCE_AIR_RUDDER; }
1291 else if (value ==
"permanent") { animation.
source |= Animation::SOURCE_PERMANENT; }
1292 else if (value ==
"event") { animation.
source |= Animation::SOURCE_EVENT; }
1293 else if (value ==
"dashboard") { animation.
source |= Animation::SOURCE_DASHBOARD; }
1294 else if (value ==
"signalstalk") { animation.
source |= Animation::SOURCE_SIGNALSTALK; }
1295 else if (value ==
"gearreverse") { animation.
source |= Animation::SOURCE_GEAR_REVERSE; }
1296 else if (value ==
"gearneutral") { animation.
source |= Animation::SOURCE_GEAR_NEUTRAL; }
1302 if (entry[1].compare(0, 8,
"throttle") == 0)
1304 motor_source.
source = Animation::MotorSource::SOURCE_AERO_THROTTLE;
1305 motor_source.
motor = this->ParseArgUint(entry[1].substr(8));
1307 else if (entry[1].compare(0, 3,
"rpm") == 0)
1309 motor_source.
source = Animation::MotorSource::SOURCE_AERO_RPM;
1310 motor_source.
motor = this->ParseArgUint(entry[1].substr(3));
1312 else if (entry[1].compare(0, 8,
"aerotorq") == 0)
1314 motor_source.
source = Animation::MotorSource::SOURCE_AERO_TORQUE;
1315 motor_source.
motor = this->ParseArgUint(entry[1].substr(8));
1317 else if (entry[1].compare(0, 7,
"aeropit") == 0)
1319 motor_source.
source = Animation::MotorSource::SOURCE_AERO_PITCH;
1320 motor_source.
motor = this->ParseArgUint(entry[1].substr(7));
1322 else if (entry[1].compare(0, 10,
"aerostatus") == 0)
1324 motor_source.
source = Animation::MotorSource::SOURCE_AERO_STATUS;
1325 motor_source.
motor = this->ParseArgUint(entry[1].substr(10));
1328 else if (entry[1].compare(0, 4,
"gear") == 0)
1330 motor_source.
source = Animation::MotorSource::SOURCE_GEAR_FORWARD;
1331 motor_source.
motor = this->ParseArgUint(entry[1].substr(4));
1335 snprintf(warn_msg, WARN_LEN,
"Invalid 'source': %s, ignoring...", entry[1].c_str());
1344 snprintf(warn_msg, WARN_LEN,
"Invalid keyword: %s, ignoring...", entry[0].c_str());
1349 snprintf(warn_msg, WARN_LEN,
"Invalid item: %s, ignoring...", entry[0].c_str());
1352 if (warn_msg[0] !=
'\0')
1355 fmt::format(
"Ignoring invalid token '{}' ({})", itor->c_str(), warn_msg));
1359 m_current_module->props.back().animations.push_back(animation);
1362 void Parser::ParseAntiLockBrakes()
1365 Ogre::StringVector tokens = Ogre::StringUtil::split(m_current_line + 15,
",");
1366 m_num_args = (int)tokens.size();
1367 if (! this->CheckNumArguments(2)) {
return; }
1370 alb.
min_speed = this->ParseArgInt (tokens[1].c_str());
1372 if (tokens.size() > 3) { alb.
pulse_per_sec = this->ParseArgFloat(tokens[2].c_str()); }
1374 for (
unsigned int i=3; i<tokens.size(); i++)
1376 Ogre::StringVector args2 = Ogre::StringUtil::split(tokens[i],
":");
1377 Ogre::StringUtil::trim(args2[0]);
1378 Ogre::StringUtil::toLowerCase(args2[0]);
1379 if (args2[0] ==
"mode" && args2.size() == 2)
1381 Ogre::StringVector attrs = Ogre::StringUtil::split(args2[1],
"&");
1382 auto itor = attrs.begin();
1383 auto endi = attrs.end();
1384 for (; itor != endi; ++itor)
1386 std::string attr = *itor;
1387 Ogre::StringUtil::trim(attr);
1388 Ogre::StringUtil::toLowerCase(attr);
1390 else if (strncmp(attr.c_str(),
"notoggle", 8) == 0) { alb.
attr_no_toggle =
true; }
1391 else if (strncmp(attr.c_str(),
"on", 2) == 0) { alb.
attr_is_on =
true; }
1392 else if (strncmp(attr.c_str(),
"off", 3) == 0) { alb.
attr_is_on =
false; }
1404 m_current_module->antilockbrakes.push_back(alb);
1408 void Parser::ParseEngoption()
1410 if (! this->CheckNumArguments(1)) {
return; }
1413 engoption.
inertia = this->GetArgFloat(0);
1415 if (m_num_args > 1) { engoption.
type = this->GetArgEngineType(1); }
1416 if (m_num_args > 2) { engoption.
clutch_force = this->GetArgFloat(2); }
1417 if (m_num_args > 3) { engoption.
shift_time = this->GetArgFloat(3); }
1418 if (m_num_args > 4) { engoption.
clutch_time = this->GetArgFloat(4); }
1419 if (m_num_args > 5) { engoption.
post_shift_time = this->GetArgFloat(5); }
1420 if (m_num_args > 6) { engoption.
stall_rpm = this->GetArgFloat(6); }
1421 if (m_num_args > 7) { engoption.
idle_rpm = this->GetArgFloat(7); }
1424 if (m_num_args > 10){ engoption.
braking_torque = this->GetArgFloat(10);}
1426 m_current_module->engoption.push_back(engoption);
1430 void Parser::ParseEngturbo()
1432 if (! this->CheckNumArguments(4)) {
return; }
1435 engturbo.
version = this->GetArgInt ( 0);
1437 engturbo.
nturbos = this->GetArgInt ( 2);
1438 engturbo.
param1 = this->GetArgFloat( 3);
1440 if (m_num_args > 4) { engturbo.
param2 = this->GetArgFloat( 4); }
1441 if (m_num_args > 5) { engturbo.
param3 = this->GetArgFloat( 5); }
1442 if (m_num_args > 6) { engturbo.
param4 = this->GetArgFloat( 6); }
1443 if (m_num_args > 7) { engturbo.
param5 = this->GetArgFloat( 7); }
1444 if (m_num_args > 8) { engturbo.
param6 = this->GetArgFloat( 8); }
1445 if (m_num_args > 9) { engturbo.
param7 = this->GetArgFloat( 9); }
1446 if (m_num_args > 10) { engturbo.
param8 = this->GetArgFloat(10); }
1447 if (m_num_args > 11) { engturbo.
param9 = this->GetArgFloat(11); }
1448 if (m_num_args > 12) { engturbo.
param10 = this->GetArgFloat(12); }
1449 if (m_num_args > 13) { engturbo.
param11 = this->GetArgFloat(13); }
1457 m_current_module->engturbo.push_back(engturbo);
1461 void Parser::ParseEngine()
1463 if (! this->CheckNumArguments(6)) {
return; }
1468 engine.
torque = this->GetArgFloat(2);
1474 for (
int i = 6; i < m_num_args; i++)
1476 float ratio = this->GetArgFloat(i);
1490 m_current_module->engine.push_back(engine);
1494 void Parser::ParseContacter()
1496 if (! this->CheckNumArguments(1)) {
return; }
1498 m_current_module->contacters.push_back(this->GetArgNodeRef(0));
1502 void Parser::ParseCommandsUnified()
1504 const bool is_commands2 = (m_current_block == Keyword::COMMANDS2);
1505 const int max_args = (is_commands2 ? 8 : 7);
1506 if (! this->CheckNumArguments(max_args)) {
return; }
1514 command2.
nodes[0] = this->GetArgNodeRef(pos++);
1515 command2.
nodes[1] = this->GetArgNodeRef(pos++);
1530 command2.
extend_key = this->GetArgInt (pos++);
1532 if (m_num_args <= max_args)
1534 m_current_module->commands2.push_back(command2);
1539 std::string options_str = this->GetArgStr(pos++);
1541 for (
auto itor = options_str.begin(); itor != options_str.end(); ++itor)
1543 const char c = *itor;
1544 if ((winner == 0) && (c ==
'o' || c ==
'p' || c ==
'c')) { winner = c; }
1579 if (
ignored != 0 && winner ==
'c')
1582 "Command cannot be one-pressed and self centering at the same time, ignoring flag '%c'");
1584 else if (
ignored != 0 && (winner ==
'o' || winner ==
'p'))
1587 "Command already has a one-pressed c.mode, ignoring flag '%c'");
1590 if (m_num_args > pos) { command2.
description = this->GetArgStr (pos++);}
1592 if (m_num_args > pos) { ParseOptionalInertia(command2.
inertia, pos); pos += 4; }
1594 if (m_num_args > pos) { command2.
affect_engine = this->GetArgFloat(pos++);}
1595 if (m_num_args > pos) { command2.
needs_engine = this->GetArgBool (pos++);}
1596 if (m_num_args > pos) { command2.
plays_sound = this->GetArgBool (pos++);}
1598 m_current_module->commands2.push_back(command2);
1602 void Parser::ParseCollisionBox()
1606 Ogre::StringVector tokens = Ogre::StringUtil::split(m_current_line,
",");
1607 Ogre::StringVector::iterator iter = tokens.begin();
1608 for ( ; iter != tokens.end(); iter++)
1610 collisionbox.
nodes.push_back( this->_ParseNodeRef(*iter) );
1613 m_current_module->collisionboxes.push_back(collisionbox);
1617 void Parser::ParseCinecam()
1619 if (! this->CheckNumArguments(11)) {
return; }
1626 cinecam.
position.x = this->GetArgFloat ( 0);
1627 cinecam.
position.y = this->GetArgFloat ( 1);
1628 cinecam.
position.z = this->GetArgFloat ( 2);
1629 cinecam.
nodes[0] = this->GetArgNodeRef( 3);
1630 cinecam.
nodes[1] = this->GetArgNodeRef( 4);
1631 cinecam.
nodes[2] = this->GetArgNodeRef( 5);
1632 cinecam.
nodes[3] = this->GetArgNodeRef( 6);
1633 cinecam.
nodes[4] = this->GetArgNodeRef( 7);
1634 cinecam.
nodes[5] = this->GetArgNodeRef( 8);
1635 cinecam.
nodes[6] = this->GetArgNodeRef( 9);
1636 cinecam.
nodes[7] = this->GetArgNodeRef(10);
1639 if (m_num_args > 11) { cinecam.
spring = this->GetArgFloat(11); }
1640 if (m_num_args > 12) { cinecam.
damping = this->GetArgFloat(12); }
1642 if (m_num_args > 13)
1644 float value = this->GetArgFloat(13);
1649 if (m_sequential_importer.IsEnabled())
1651 m_sequential_importer.AddGeneratedNode(Keyword::CINECAM);
1654 m_current_module->cinecam.push_back(cinecam);
1658 void Parser::ParseCameraRails()
1660 m_current_camera_rail->nodes.push_back( this->GetArgNodeRef(0) );
1663 void Parser::ParseBrakes()
1665 if (!this->CheckNumArguments(1)) {
return; }
1673 m_current_module->brakes.push_back(brakes);
1677 void Parser::ParseAxles()
1681 Ogre::StringVector tokens = Ogre::StringUtil::split(m_current_line,
",");
1682 Ogre::StringVector::iterator iter = tokens.begin();
1683 for ( ; iter != tokens.end(); iter++)
1685 std::smatch results;
1686 if (! std::regex_search(*iter, results, Regexes::SECTION_AXLES_PROPERTY))
1693 if (results[1].matched)
1695 unsigned int wheel_index =
PARSEINT(results[2]) - 1;
1696 axle.
wheels[wheel_index][0] = _ParseNodeRef(results[3]);
1697 axle.
wheels[wheel_index][1] = _ParseNodeRef(results[4]);
1699 else if (results[5].matched)
1701 this->_ParseDifferentialTypes(axle.
options, results[6].str());
1705 m_current_module->axles.push_back(axle);
1709 void Parser::ParseInterAxles()
1711 auto args = Ogre::StringUtil::split(m_current_line,
",");
1712 if (args.size() < 2) {
return; }
1716 interaxle.
a1 = this->ParseArgInt(args[0].c_str()) - 1;
1717 interaxle.
a2 = this->ParseArgInt(args[1].c_str()) - 1;
1719 std::smatch results;
1720 if (! std::regex_search(args[2], results, Regexes::SECTION_AXLES_PROPERTY))
1727 if (results[5].matched)
1729 this->_ParseDifferentialTypes(interaxle.
options, results[6].str());
1732 m_current_module->interaxles.push_back(interaxle);
1736 void Parser::ParseAirbrakes()
1738 if (! this->CheckNumArguments(14)) {
return; }
1745 airbrake.
offset.x = this->GetArgFloat ( 4);
1746 airbrake.
offset.y = this->GetArgFloat ( 5);
1747 airbrake.
offset.z = this->GetArgFloat ( 6);
1748 airbrake.
width = this->GetArgFloat ( 7);
1749 airbrake.
height = this->GetArgFloat ( 8);
1756 m_current_module->airbrakes.push_back(airbrake);
1757 this->FlushPendingDocComment(m_current_module->airbrakes.size(), Keyword::AIRBRAKES);
1760 void Parser::ParseAssetpacks()
1762 if (! this->CheckNumArguments(1)) {
return; }
1766 assetpack.
filename = this->GetArgStr(0);
1768 m_current_module->assetpacks.push_back(assetpack);
1769 this->FlushPendingDocComment(m_current_module->assetpacks.size(), Keyword::ASSETPACKS);
1772 void Parser::ParseVideoCamera()
1774 if (! this->CheckNumArguments(19)) {
return; }
1779 videocamera.
left_node = this->GetArgNodeRef ( 1);
1780 videocamera.
bottom_node = this->GetArgNodeRef ( 2);
1783 videocamera.
offset.x = this->GetArgFloat ( 5);
1784 videocamera.
offset.y = this->GetArgFloat ( 6);
1785 videocamera.
offset.z = this->GetArgFloat ( 7);
1786 videocamera.
rotation.x = this->GetArgFloat ( 8);
1787 videocamera.
rotation.y = this->GetArgFloat ( 9);
1788 videocamera.
rotation.z = this->GetArgFloat (10);
1794 videocamera.
camera_role = this->GetArgVideoCamRole(16);
1798 if (m_num_args > 19) { videocamera.
camera_name = this->GetArgStr(19); }
1800 m_current_module->videocameras.push_back(videocamera);
1801 this->FlushPendingDocComment(m_current_module->videocameras.size(), Keyword::VIDEOCAMERA);
1804 void Parser::ParseCameras()
1806 if (! this->CheckNumArguments(3)) {
return; }
1810 camera.
back_node = this->GetArgNodeRef(1);
1811 camera.
left_node = this->GetArgNodeRef(2);
1813 m_current_module->cameras.push_back(camera);
1814 this->FlushPendingDocComment(m_current_module->cameras.size(), Keyword::CAMERAS);
1817 void Parser::ParseTurbopropsUnified()
1819 bool is_turboprop_2 = m_current_block == Keyword::TURBOPROPS2;
1821 if (! this->CheckNumArguments(is_turboprop_2 ? 9 : 8)) {
return; }
1826 turboprop.
axis_node = this->GetArgNodeRef(1);
1836 turboprop.
couple_node = this->GetArgNullableNode(6);
1842 turboprop.
airfoil = this->GetArgStr (7 + offset);
1844 m_current_module->turboprops2.push_back(turboprop);
1845 this->FlushPendingDocComment(m_current_module->turboprops2.size(), Keyword::TURBOPROPS2);
1848 void Parser::ParseTurbojets()
1850 if (! this->CheckNumArguments(9)) {
return; }
1853 turbojet.
front_node = this->GetArgNodeRef(0);
1854 turbojet.
back_node = this->GetArgNodeRef(1);
1855 turbojet.
side_node = this->GetArgNodeRef(2);
1863 m_current_module->turbojets.push_back(turbojet);
1864 this->FlushPendingDocComment(m_current_module->turbojets.size(), Keyword::TURBOJETS);
1867 void Parser::ParseTriggers()
1869 if (! this->CheckNumArguments(6)) {
return; }
1874 trigger.
nodes[0] = this->GetArgNodeRef(0);
1875 trigger.
nodes[1] = this->GetArgNodeRef(1);
1880 if (m_num_args > 6) trigger.
options = this->GetArgTriggerOptions(6);
1881 if (m_num_args > 7) trigger.
boundary_timer = this->GetArgFloat(7);
1883 m_current_module->triggers.push_back(trigger);
1884 this->FlushPendingDocComment(m_current_module->triggers.size(), Keyword::TRIGGERS);
1887 void Parser::ParseTorqueCurve()
1889 if (m_current_module->torquecurve.size() == 0)
1891 m_current_module->torquecurve.push_back(
TorqueCurve());
1894 Ogre::StringVector args = Ogre::StringUtil::split(m_current_line,
",");
1896 if (args.size() == 1u)
1898 m_current_module->torquecurve[0].predefined_func_name = args[0];
1900 else if (args.size() == 2u)
1903 sample.
power = this->ParseArgFloat(args[0].c_str());
1905 m_current_module->torquecurve[0].samples.push_back(sample);
1914 void Parser::ParseTies()
1916 if (! this->CheckNumArguments(5)) {
return; }
1930 for (
char c: this->GetArgStr(5))
1934 case (
char)TieOption::n_DUMMY:
1935 case (
char)TieOption::v_DUMMY:
1938 case (
char)TieOption::i_INVISIBLE:
1939 tie.
options |= Tie::OPTION_i_INVISIBLE;
1942 case (
char)TieOption::s_NO_SELF_LOCK:
1943 tie.
options |= Tie::OPTION_s_DISABLE_SELF_LOCK;
1954 if (m_num_args > 6) { tie.
max_stress = this->GetArgFloat (6); }
1955 if (m_num_args > 7) { tie.
group = this->GetArgInt (7); }
1957 m_current_module->ties.push_back(tie);
1958 this->FlushPendingDocComment(m_current_module->ties.size(), Keyword::TIES);
1961 void Parser::ParseSoundsources()
1963 if (! this->CheckNumArguments(2)) {
return; }
1966 soundsource.
node = this->GetArgNodeRef(0);
1969 m_current_module->soundsources.push_back(soundsource);
1970 this->FlushPendingDocComment(m_current_module->soundsources.size(), Keyword::SOUNDSOURCES);
1973 void Parser::ParseSoundsources2()
1975 if (! this->CheckNumArguments(3)) {
return; }
1978 soundsource2.
node = this->GetArgNodeRef(0);
1979 soundsource2.
mode = this->GetArgInt(1);
1982 if (soundsource2.
mode < -2)
1985 fmt::format(
"invalid mode {}, falling back to default -2", soundsource2.
mode));
1986 soundsource2.
mode = -2;
1989 m_current_module->soundsources2.push_back(soundsource2);
1990 this->FlushPendingDocComment(m_current_module->soundsources2.size(), Keyword::SOUNDSOURCES2);
1993 void Parser::ParseSlidenodes()
1995 Ogre::StringVector args = Ogre::StringUtil::split(m_current_line,
", ");
1996 m_num_args = (int)args.size();
1997 if (! this->CheckNumArguments(2)) {
return; }
2000 slidenode.
slide_node = this->_ParseNodeRef(args[0]);
2002 bool in_rail_node_list =
true;
2004 for (
auto itor = args.begin() + 1; itor != args.end(); ++itor)
2006 char c = toupper(itor->at(0));
2010 slidenode.
spring_rate = this->ParseArgFloat(itor->substr(1));
2012 in_rail_node_list =
false;
2015 slidenode.
break_force = this->ParseArgFloat(itor->substr(1));
2017 in_rail_node_list =
false;
2020 slidenode.
tolerance = this->ParseArgFloat(itor->substr(1));
2022 in_rail_node_list =
false;
2027 in_rail_node_list =
false;
2030 slidenode.
railgroup_id = this->ParseArgFloat(itor->substr(1));
2032 in_rail_node_list =
false;
2037 in_rail_node_list =
false;
2040 switch (itor->at(1))
2056 fmt::format(
"Ignoring invalid option '{}'", itor->at(1)));
2059 in_rail_node_list =
false;
2062 if (in_rail_node_list)
2068 m_current_module->slidenodes.push_back(slidenode);
2069 this->FlushPendingDocComment(m_current_module->slidenodes.size(), Keyword::SLIDENODES);
2072 void Parser::ParseShock3()
2074 if (! this->CheckNumArguments(15)) {
return; }
2080 shock_3.
nodes[0] = this->GetArgNodeRef( 0);
2081 shock_3.
nodes[1] = this->GetArgNodeRef( 1);
2082 shock_3.
spring_in = this->GetArgFloat ( 2);
2083 shock_3.
damp_in = this->GetArgFloat ( 3);
2088 shock_3.
damp_out = this->GetArgFloat ( 8);
2096 if (m_num_args > 15) shock_3.
options = this->GetArgShock3Options(15);
2098 m_current_module->shocks3.push_back(shock_3);
2099 this->FlushPendingDocComment(m_current_module->shocks3.size(), Keyword::SHOCKS3);
2102 void Parser::ParseShock2()
2104 if (! this->CheckNumArguments(13)) {
return; }
2110 shock_2.
nodes[0] = this->GetArgNodeRef( 0);
2111 shock_2.
nodes[1] = this->GetArgNodeRef( 1);
2112 shock_2.
spring_in = this->GetArgFloat ( 2);
2113 shock_2.
damp_in = this->GetArgFloat ( 3);
2117 shock_2.
damp_out = this->GetArgFloat ( 7);
2124 if (m_num_args > 13) shock_2.
options = this->GetArgShock2Options(13);
2126 m_current_module->shocks2.push_back(shock_2);
2127 this->FlushPendingDocComment(m_current_module->shocks2.size(), Keyword::SHOCKS2);
2130 void Parser::ParseShock()
2132 if (! this->CheckNumArguments(7)) {
return; }
2138 shock.
nodes[0] = this->GetArgNodeRef(0);
2139 shock.
nodes[1] = this->GetArgNodeRef(1);
2141 shock.
damping = this->GetArgFloat (3);
2145 if (m_num_args > 7) shock.
options = this->GetArgShockOptions(7);
2147 m_current_module->shocks.push_back(shock);
2148 this->FlushPendingDocComment(m_current_module->shocks.size(), Keyword::SHOCKS);
2151 Node::Ref Parser::_ParseNodeRef(std::string
const & node_id_str)
2153 if (m_sequential_importer.IsEnabled())
2156 int node_id_num =
PARSEINT(node_id_str);
2157 if (node_id_num < 0)
2163 unsigned int flags = Node::Ref::IMPORT_STATE_IS_VALID |
2164 Node::Ref::REGULAR_STATE_IS_VALID | Node::Ref::REGULAR_STATE_IS_NAMED;
2165 if (m_any_named_node_defined)
2167 flags |= Node::Ref::IMPORT_STATE_MUST_CHECK_NAMED_FIRST;
2169 return Node::Ref(node_id_str, node_id_num, flags, m_current_line_number);
2174 return Node::Ref(node_id_str, 0, Node::Ref::REGULAR_STATE_IS_VALID | Node::Ref::REGULAR_STATE_IS_NAMED, m_current_line_number);
2178 void Parser::ParseDirectiveSetDefaultMinimass()
2180 if (! this->CheckNumArguments(2)) {
return; }
2182 m_set_default_minimass = std::shared_ptr<DefaultMinimass>(
new DefaultMinimass());
2183 m_set_default_minimass->min_mass_Kg = this->GetArgFloat(1);
2186 void Parser::ParseFlaregroupsNoImport()
2190 if (!this->CheckNumArguments(1)) {
return; }
2193 fni.
type = this->GetArgFlareType(0);
2208 m_current_module->flaregroups_no_import.push_back(fni);
2211 void Parser::ParseDirectiveSetInertiaDefaults()
2213 if (! this->CheckNumArguments(2)) {
return; }
2215 float start_delay = this->GetArgFloat(1);
2216 float stop_delay = 0;
2217 if (m_num_args > 2) { stop_delay = this->GetArgFloat(2); }
2219 if (start_delay < 0 || stop_delay < 0)
2221 m_user_default_inertia = m_ror_default_inertia;
2231 if (m_num_args > 4) { i->
stop_function = this->GetArgStr(4); }
2233 m_user_default_inertia = std::shared_ptr<Inertia>(i);
2236 void Parser::ParseScrewprops()
2238 if (! this->CheckNumArguments(4)) {
return; }
2242 screwprop.
prop_node = this->GetArgNodeRef(0);
2243 screwprop.
back_node = this->GetArgNodeRef(1);
2244 screwprop.
top_node = this->GetArgNodeRef(2);
2245 screwprop.
power = this->GetArgFloat (3);
2247 m_current_module->screwprops.push_back(screwprop);
2248 this->FlushPendingDocComment(m_current_module->screwprops.size(), Keyword::SCREWPROPS);
2251 void Parser::ParseScripts()
2253 if (!this->CheckNumArguments(1)) {
return; }
2257 script.
filename = this->GetArgStr(0);
2259 m_current_module->scripts.push_back(script);
2260 this->FlushPendingDocComment(m_current_module->scripts.size(), Keyword::SCRIPTS);
2263 void Parser::ParseRotatorsUnified()
2265 if (! this->CheckNumArguments(13)) {
return; }
2270 rotator.
axis_nodes[0] = this->GetArgNodeRef( 0);
2271 rotator.
axis_nodes[1] = this->GetArgNodeRef( 1);
2280 rotator.
rate = this->GetArgFloat (10);
2286 if (m_current_block == Keyword::ROTATORS2)
2288 if (! this->CheckNumArguments(16)) {
return; }
2289 if (m_num_args > 13) { rotator.
rotating_force = this->GetArgFloat(13); }
2290 if (m_num_args > 14) { rotator.
tolerance = this->GetArgFloat(14); }
2291 if (m_num_args > 15) { rotator.
description = this->GetArgStr (15); }
2296 this->ParseOptionalInertia(rotator.
inertia, 13 + offset);
2297 if (m_num_args > 17 + offset) { rotator.
engine_coupling = this->GetArgFloat(17 + offset); }
2298 if (m_num_args > 18 + offset) { rotator.
needs_engine = this->GetArgBool (18 + offset); }
2300 if (m_current_block == Keyword::ROTATORS2)
2302 m_current_module->rotators2.push_back(rotator);
2303 this->FlushPendingDocComment(m_current_module->rotators2.size(), Keyword::ROTATORS2);
2307 m_current_module->rotators.push_back(rotator);
2308 this->FlushPendingDocComment(m_current_module->rotators.size(), Keyword::ROTATORS);
2312 void Parser::ParseFileinfo()
2314 if (! this->CheckNumArguments(2)) {
return; }
2318 fileinfo.
unique_id = this->GetArgStr(1);
2319 Ogre::StringUtil::trim(fileinfo.
unique_id);
2321 if (m_num_args > 2) { fileinfo.
category_id = this->GetArgInt(2); }
2322 if (m_num_args > 3) { fileinfo.
file_version = this->GetArgInt(3); }
2324 m_current_module->fileinfo.push_back(fileinfo);
2326 m_current_block = Keyword::INVALID;
2329 void Parser::ParseRopes()
2331 if (! this->CheckNumArguments(2)) {
return; }
2336 rope.
root_node = this->GetArgNodeRef(0);
2337 rope.
end_node = this->GetArgNodeRef(1);
2339 if (m_num_args > 2) { rope.
invisible = (this->GetArgChar(2) ==
'i'); }
2341 m_current_module->ropes.push_back(rope);
2342 this->FlushPendingDocComment(m_current_module->ropes.size(), Keyword::ROPES);
2345 void Parser::ParseRopables()
2347 if (! this->CheckNumArguments(1)) {
return; }
2350 ropable.
node = this->GetArgNodeRef(0);
2352 if (m_num_args > 1) { ropable.
group = this->GetArgInt(1); }
2353 if (m_num_args > 2) { ropable.
has_multilock = (this->GetArgInt(2) == 1); }
2355 m_current_module->ropables.push_back(ropable);
2356 this->FlushPendingDocComment(m_current_module->ropables.size(), Keyword::ROPABLES);
2359 void Parser::ParseRailGroups()
2361 Ogre::StringVector args = Ogre::StringUtil::split(m_current_line,
",");
2362 m_num_args = (int)args.size();
2363 if (! this->CheckNumArguments(3)) {
return; }
2366 railgroup.
id = this->ParseArgInt(args[0].c_str());
2368 for (
auto itor = args.begin() + 1; itor != args.end(); itor++)
2370 railgroup.
node_list.push_back( this->_ParseNodeRef(*itor));
2373 m_current_module->railgroups.push_back(railgroup);
2374 this->FlushPendingDocComment(m_current_module->railgroups.size(), Keyword::RAILGROUPS);
2377 void Parser::ParseProps()
2379 if (! this->CheckNumArguments(10)) {
return; }
2385 prop.
offset.x = this->GetArgFloat (3);
2386 prop.
offset.y = this->GetArgFloat (4);
2387 prop.
offset.z = this->GetArgFloat (5);
2388 prop.
rotation.x = this->GetArgFloat (6);
2389 prop.
rotation.y = this->GetArgFloat (7);
2390 prop.
rotation.z = this->GetArgFloat (8);
2394 if ((prop.
special == SpecialProp::BEACON) && (m_num_args >= 14))
2400 this->GetArgFloat(11), this->GetArgFloat(12), this->GetArgFloat(13));
2402 else if (prop.
special == SpecialProp::DASHBOARD_LEFT ||
2403 prop.
special == SpecialProp::DASHBOARD_RIGHT)
2406 if (m_num_args > 13)
2414 m_current_module->props.push_back(prop);
2415 this->FlushPendingDocComment(m_current_module->props.size(), Keyword::PROPS);
2418 void Parser::ParsePistonprops()
2420 if (!this->CheckNumArguments(10)) {
return; }
2424 pistonprop.
axis_node = this->GetArgNodeRef (1);
2429 pistonprop.
couple_node = this->GetArgNullableNode(6);
2431 pistonprop.
pitch = this->GetArgFloat (8);
2432 pistonprop.
airfoil = this->GetArgStr (9);
2434 m_current_module->pistonprops.push_back(pistonprop);
2435 this->FlushPendingDocComment(m_current_module->pistonprops.size(), Keyword::PISTONPROPS);
2438 void Parser::ParseParticles()
2440 if (!this->CheckNumArguments(3)) {
return; }
2447 m_current_module->particles.push_back(particle);
2448 this->FlushPendingDocComment(m_current_module->particles.size(), Keyword::PARTICLES);
2452 void Parser::_TrimTrailingComments(std::string
const & line_in, std::string & line_out)
2456 int comment_start =
static_cast<int>(line_in.find_first_of(
";"));
2457 if (comment_start != Ogre::String::npos)
2459 line_out = line_in.substr(0, comment_start);
2463 comment_start =
static_cast<int>(line_in.find_last_of(
"/"));
2464 if (comment_start != Ogre::String::npos)
2466 while (comment_start >= 0)
2468 char c = line_in[comment_start - 1];
2469 if (c !=
'/' && c !=
' ' && c !=
'\t')
2475 line_out = line_in.substr(0, comment_start);
2482 void Parser::ParseNodesUnified()
2484 if (! this->CheckNumArguments(4)) {
return; }
2492 if (m_current_block == Keyword::NODES2)
2494 std::string node_name = this->GetArgStr(0);
2496 if (m_sequential_importer.IsEnabled())
2498 m_sequential_importer.AddNamedNode(node_name);
2500 m_any_named_node_defined =
true;
2504 const unsigned int node_num = this->GetArgUint(0);
2506 if (m_sequential_importer.IsEnabled())
2508 m_sequential_importer.AddNumberedNode(node_num);
2512 node.
position.x = this->GetArgFloat(1);
2513 node.
position.y = this->GetArgFloat(2);
2514 node.
position.z = this->GetArgFloat(3);
2517 node.
options = this->GetArgNodeOptions(4);
2521 if (node.
options & Node::OPTION_l_LOAD_WEIGHT)
2529 "Node has load-weight-override value specified, but option 'l' is not present. Ignoring value...");
2533 m_current_module->nodes.push_back(node);
2534 this->FlushPendingDocComment(m_current_module->nodes.size(), Keyword::NODES);
2537 void Parser::ParseMinimass()
2539 if (! this->CheckNumArguments(1)) {
return; }
2543 if (m_num_args > 1) { mm.
option = this->GetArgMinimassOption(1); }
2545 m_current_module->minimass.push_back(mm);
2546 m_current_block = Keyword::INVALID;
2549 void Parser::ParseFlexBodyWheel()
2551 if (! this->CheckNumArguments(16)) {
return; }
2557 flexbody_wheel.
tyre_radius = this->GetArgFloat ( 0);
2558 flexbody_wheel.
rim_radius = this->GetArgFloat ( 1);
2559 flexbody_wheel.
width = this->GetArgFloat ( 2);
2560 flexbody_wheel.
num_rays = this->GetArgInt ( 3);
2561 flexbody_wheel.
nodes[0] = this->GetArgNodeRef ( 4);
2562 flexbody_wheel.
nodes[1] = this->GetArgNodeRef ( 5);
2563 flexbody_wheel.
rigidity_node = this->GetArgRigidityNode ( 6);
2564 flexbody_wheel.
braking = this->GetArgBraking ( 7);
2565 flexbody_wheel.
propulsion = this->GetArgPropulsion ( 8);
2567 flexbody_wheel.
mass = this->GetArgFloat (10);
2571 flexbody_wheel.
rim_damping = this->GetArgFloat (14);
2572 flexbody_wheel.
side = this->GetArgWheelSide (15);
2574 if (m_num_args > 16) { flexbody_wheel.
rim_mesh_name = this->GetArgStr(16); }
2575 if (m_num_args > 17) { flexbody_wheel.
tyre_mesh_name = this->GetArgStr(17); }
2577 if (m_sequential_importer.IsEnabled())
2582 m_current_module->flexbodywheels.push_back(flexbody_wheel);
2583 this->FlushPendingDocComment(m_current_module->flexbodywheels.size(), Keyword::FLEXBODYWHEELS);
2586 void Parser::ParseMaterialFlareBindings()
2588 if (! this->CheckNumArguments(2)) {
return; }
2594 m_current_module->materialflarebindings.push_back(binding);
2595 this->FlushPendingDocComment(m_current_module->materialflarebindings.size(), Keyword::MATERIALFLAREBINDINGS);
2598 void Parser::ParseManagedMaterials()
2600 if (! this->CheckNumArguments(2)) {
return; }
2603 managed_mat.
options = m_current_managed_material_options;
2604 managed_mat.
name = this->GetArgStr(0);
2605 managed_mat.
type = this->GetArgManagedMatType(1);
2607 if (managed_mat.
type != ManagedMaterialType::INVALID)
2609 if (! this->CheckNumArguments(3)) {
return; }
2613 if (managed_mat.
type == ManagedMaterialType::MESH_STANDARD ||
2614 managed_mat.
type == ManagedMaterialType::MESH_TRANSPARENT)
2616 if (m_num_args > 3) { managed_mat.
specular_map = this->GetArgManagedTex(3); }
2618 else if (managed_mat.
type == ManagedMaterialType::FLEXMESH_STANDARD ||
2619 managed_mat.
type == ManagedMaterialType::FLEXMESH_TRANSPARENT)
2622 if (m_num_args > 4) { managed_mat.
specular_map = this->GetArgManagedTex(4); }
2625 m_current_module->managedmaterials.push_back(managed_mat);
2626 this->FlushPendingDocComment(m_current_module->managedmaterials.size(), Keyword::MANAGEDMATERIALS);
2630 void Parser::ParseLockgroups()
2632 if (! this->CheckNumArguments(2)) {
return; }
2635 lockgroup.
number = this->GetArgInt(0);
2637 for (
int i = 1; i < m_num_args; ++i)
2639 lockgroup.
nodes.push_back(this->GetArgNodeRef(i));
2642 m_current_module->lockgroups.push_back(lockgroup);
2643 this->FlushPendingDocComment(m_current_module->lockgroups.size(), Keyword::LOCKGROUPS);
2646 void Parser::ParseHydros()
2648 if (! this->CheckNumArguments(3)) {
return; }
2655 hydro.
nodes[0] = this->GetArgNodeRef(0);
2656 hydro.
nodes[1] = this->GetArgNodeRef(1);
2659 if (m_num_args > 3) { hydro.
options = this->GetArgHydroOptions(3); }
2663 hydro.
options |= Hydro::OPTION_n_INPUT_NORMAL;
2666 this->ParseOptionalInertia(hydro.
inertia, 4);
2668 m_current_module->hydros.push_back(hydro);
2669 this->FlushPendingDocComment(m_current_module->hydros.size(), Keyword::HYDROS);
2672 void Parser::ParseOptionalInertia(
Inertia & inertia,
int index)
2675 if (m_num_args > index) { inertia.
stop_delay_factor = this->GetArgFloat(index++); }
2676 if (m_num_args > index) { inertia.
start_function = this->GetArgStr (index++); }
2677 if (m_num_args > index) { inertia.
stop_function = this->GetArgStr (index++); }
2682 for (
char c: options_str)
2686 case (
char)DifferentialType::o_OPEN:
2687 case (
char)DifferentialType::l_LOCKED:
2688 case (
char)DifferentialType::s_SPLIT:
2689 case (
char)DifferentialType::v_VISCOUS:
2695 fmt::format(
"ignoring invalid differential type '{}'", c));
2701 void Parser::ParseBeams()
2703 if (! this->CheckNumArguments(2)) {
return; }
2706 beam.
defaults = m_user_beam_defaults;
2709 beam.
nodes[0] = this->GetArgNodeRef(0);
2710 beam.
nodes[1] = this->GetArgNodeRef(1);
2711 if (m_num_args > 2) beam.
options = this->GetArgBeamOptions(2);
2715 float support_break_limit = 0.0f;
2716 float support_break_factor = this->GetArgInt(3);
2717 if (support_break_factor > 0.0f)
2719 support_break_limit = support_break_factor;
2725 m_current_module->beams.push_back(beam);
2726 this->FlushPendingDocComment(m_current_module->beams.size(), Keyword::BEAMS);
2729 void Parser::ParseAnimator()
2731 auto args = Ogre::StringUtil::split(m_current_line,
",");
2732 if (args.size() < 4) {
return; }
2739 animator.
nodes[0] = this->_ParseNodeRef(args[0]);
2740 animator.
nodes[1] = this->_ParseNodeRef(args[1]);
2744 Ogre::StringVector attrs = Ogre::StringUtil::split(args[3],
"|");
2746 auto itor = attrs.begin();
2747 auto endi = attrs.end();
2748 for (; itor != endi; ++itor)
2750 Ogre::String token = *itor;
2751 Ogre::StringUtil::trim(token);
2752 std::smatch results;
2753 bool is_shortlimit =
false;
2756 if (std::regex_search(token, results, Regexes::PARSE_ANIMATORS_NUMBERED_KEYWORD))
2758 if (results[1] ==
"throttle") animator.
aero_animator.
flags |= AeroAnimator::OPTION_THROTTLE;
2759 else if (results[1] ==
"rpm") animator.
aero_animator.
flags |= AeroAnimator::OPTION_RPM;
2760 else if (results[1] ==
"aerotorq") animator.
aero_animator.
flags |= AeroAnimator::OPTION_TORQUE;
2761 else if (results[1] ==
"aeropit") animator.
aero_animator.
flags |= AeroAnimator::OPTION_PITCH;
2762 else if (results[1] ==
"aerostatus") animator.
aero_animator.
flags |= AeroAnimator::OPTION_STATUS;
2766 else if ((is_shortlimit = (token.compare(0, 10,
"shortlimit") == 0)) || (token.compare(0, 9,
"longlimit") == 0))
2768 Ogre::StringVector fields = Ogre::StringUtil::split(token,
":");
2769 if (fields.size() > 1)
2773 animator.
short_limit = std::strtod(fields[1].c_str(),
nullptr);
2774 animator.
flags |= Animator::OPTION_SHORT_LIMIT;
2778 animator.
long_limit = std::strtod(fields[1].c_str(),
nullptr);
2779 animator.
flags |= Animator::OPTION_LONG_LIMIT;
2786 if (token ==
"vis") animator.
flags |= Animator::OPTION_VISIBLE;
2787 else if (token ==
"inv") animator.
flags |= Animator::OPTION_INVISIBLE;
2788 else if (token ==
"airspeed") animator.
flags |= Animator::OPTION_AIRSPEED;
2789 else if (token ==
"vvi") animator.
flags |= Animator::OPTION_VERTICAL_VELOCITY;
2790 else if (token ==
"altimeter100k") animator.
flags |= Animator::OPTION_ALTIMETER_100K;
2791 else if (token ==
"altimeter10k") animator.
flags |= Animator::OPTION_ALTIMETER_10K;
2792 else if (token ==
"altimeter1k") animator.
flags |= Animator::OPTION_ALTIMETER_1K;
2793 else if (token ==
"aoa") animator.
flags |= Animator::OPTION_ANGLE_OF_ATTACK;
2794 else if (token ==
"flap") animator.
flags |= Animator::OPTION_FLAP;
2795 else if (token ==
"airbrake") animator.
flags |= Animator::OPTION_AIR_BRAKE;
2796 else if (token ==
"roll") animator.
flags |= Animator::OPTION_ROLL;
2797 else if (token ==
"pitch") animator.
flags |= Animator::OPTION_PITCH;
2798 else if (token ==
"brakes") animator.
flags |= Animator::OPTION_BRAKES;
2799 else if (token ==
"accel") animator.
flags |= Animator::OPTION_ACCEL;
2800 else if (token ==
"clutch") animator.
flags |= Animator::OPTION_CLUTCH;
2801 else if (token ==
"speedo") animator.
flags |= Animator::OPTION_SPEEDO;
2802 else if (token ==
"tacho") animator.
flags |= Animator::OPTION_TACHO;
2803 else if (token ==
"turbo") animator.
flags |= Animator::OPTION_TURBO;
2804 else if (token ==
"parking") animator.
flags |= Animator::OPTION_PARKING;
2805 else if (token ==
"shifterman1") animator.
flags |= Animator::OPTION_SHIFT_LEFT_RIGHT;
2806 else if (token ==
"shifterman2") animator.
flags |= Animator::OPTION_SHIFT_BACK_FORTH;
2807 else if (token ==
"sequential") animator.
flags |= Animator::OPTION_SEQUENTIAL_SHIFT;
2808 else if (token ==
"shifterlin") animator.
flags |= Animator::OPTION_GEAR_SELECT;
2809 else if (token ==
"torque") animator.
flags |= Animator::OPTION_TORQUE;
2810 else if (token ==
"difflock") animator.
flags |= Animator::OPTION_DIFFLOCK;
2811 else if (token ==
"rudderboat") animator.
flags |= Animator::OPTION_BOAT_RUDDER;
2812 else if (token ==
"throttleboat") animator.
flags |= Animator::OPTION_BOAT_THROTTLE;
2816 m_current_module->animators.push_back(animator);
2817 this->FlushPendingDocComment(m_current_module->animators.size(), Keyword::ANIMATORS);
2820 void Parser::ParseAuthor()
2822 if (! this->CheckNumArguments(2)) {
return; }
2825 if (m_num_args > 1) { author.
type = this->GetArgStr(1); }
2827 if (m_num_args > 3) { author.
name = this->GetArgStr(3); }
2828 if (m_num_args > 4) { author.
email = this->GetArgStr(4); }
2830 m_current_module->author.push_back(author);
2831 this->FlushPendingDocComment(m_current_module->author.size(), Keyword::AUTHOR);
2832 m_current_block = Keyword::INVALID;
2845 m_filename, m_current_line_number,
KeywordToString(m_log_keyword), msg));
2848 Keyword Parser::IdentifyKeyword(
const std::string& line)
2851 std::smatch results;
2852 std::regex_search(line, results, Regexes::IDENTIFY_KEYWORD_IGNORE_CASE);
2856 for (
unsigned int i = 1; i < results.size(); i++)
2858 std::ssub_match sub = results[i];
2866 return Keyword::INVALID;
2869 void Parser::Prepare()
2871 m_current_block = Keyword::INVALID;
2872 m_current_line_number = 1;
2874 m_any_named_node_defined =
false;
2875 m_current_detacher_group = 0;
2877 m_user_default_inertia = m_ror_default_inertia;
2878 m_user_node_defaults = m_ror_node_defaults;
2881 m_user_beam_defaults = std::shared_ptr<BeamDefaults>(
new BeamDefaults);
2884 m_user_beam_defaults->deformation_threshold =
BEAM_DEFORM;
2885 m_user_beam_defaults->breaking_threshold =
BEAM_BREAK;
2888 m_root_module = m_definition->root_module;
2889 m_current_module = m_definition->root_module;
2891 m_sequential_importer.Init(
true);
2896 if (
keyword == Keyword::INVALID)
2899 if (m_current_submesh !=
nullptr)
2901 m_current_module->submeshes.push_back(*m_current_submesh);
2902 m_current_submesh.reset();
2906 if (m_current_camera_rail !=
nullptr)
2908 if (m_current_camera_rail->nodes.size() == 0)
2914 m_current_module->camerarail.push_back(*m_current_camera_rail);
2915 m_current_camera_rail.reset();
2919 else if (
keyword == Keyword::CAMERARAIL)
2921 this->BeginBlock(Keyword::INVALID);
2922 m_current_camera_rail = std::shared_ptr<CameraRail>(
new CameraRail() );
2930 std::string new_module_name;
2931 if (
keyword == Keyword::END_SECTION)
2933 if (m_current_module == m_root_module)
2940 else if (
keyword == Keyword::SECTION)
2942 if (!this->CheckNumArguments(3))
2947 new_module_name = this->GetArgStr(2);
2948 if (new_module_name == m_current_module->name)
2956 this->BeginBlock(Keyword::INVALID);
2960 m_current_module = m_root_module;
2964 auto search_itor = m_definition->user_modules.find(new_module_name);
2965 if (search_itor != m_definition->user_modules.end())
2967 m_current_module = search_itor->second;
2971 m_current_module = std::make_shared<Document::Module>(new_module_name);
2972 m_definition->user_modules.insert(std::make_pair(new_module_name, m_current_module));
2978 if (m_pending_doc_comment.comment_text ==
"" || vectorlen == 0)
2983 m_pending_doc_comment.commented_keyword =
keyword;
2984 m_pending_doc_comment.commented_datapos =
static_cast<int>(vectorlen - 1);
2985 m_current_module->_comments.push_back(m_pending_doc_comment);
2990 void Parser::ParseDirectiveSection()
2992 this->ProcessChangeModuleLine(Keyword::SECTION);
2995 void Parser::ParseDirectiveSectionConfig()
3000 void Parser::Finalize()
3002 this->BeginBlock(Keyword::INVALID);
3004 if (m_sequential_importer.IsEnabled())
3006 m_sequential_importer.Process( m_definition );
3010 std::string Parser::GetArgStr(
int index)
3012 return std::string(m_args[index].start, m_args[index].length);
3015 char Parser::GetArgChar(
int index)
3017 return *(m_args[index].start);
3022 char c = this->GetArgChar(index);
3031 fmt::format(
"Bad arg~{} 'side' (value: {}), parsing as 'l' for backwards compatibility.", index + 1, c));
3036 long Parser::GetArgLong(
int index)
3039 char* out_end =
nullptr;
3040 long res = std::strtol(m_args[index].start, &out_end, 10);
3044 fmt::format(
"Cannot parse argument [{}] as integer, errno: {}", index + 1, errno));
3047 if (out_end == m_args[index].start)
3050 fmt::format(
"Argument [{}] is not valid integer", index + 1));
3053 else if (out_end != (m_args[index].start + m_args[index].length))
3056 fmt::format(
"Integer argument [{}] has invalid trailing characters", index + 1));
3061 int Parser::GetArgInt(
int index)
3063 return static_cast<int>(this->GetArgLong(index));
3068 std::string rigidity_node = this->GetArgStr(index);
3069 if (rigidity_node !=
"9999")
3071 return this->GetArgNodeRef(index);
3078 int p = this->GetArgInt(index);
3088 fmt::format(
"Bad value of param ~{} (propulsion), using 0 (no propulsion)", index + 1));
3095 int b = this->GetArgInt(index);
3107 fmt::format(
"Bad value of param ~{} (braking), using 0 (not braked)", index + 1));
3114 return this->_ParseNodeRef(this->GetArgStr(index));
3119 if (! (Ogre::StringConverter::parseReal(this->GetArgStr(index)) == -1.f))
3121 return this->GetArgNodeRef(index);
3126 unsigned Parser::GetArgUint(
int index)
3128 return static_cast<unsigned>(this->GetArgLong(index));
3133 char in = this->GetArgChar(index);
3154 fmt::format(
"Invalid flare type '{}', falling back to type 'f' (front light)...", in));
3161 std::string str = this->GetArgStr(index);
3167 fmt::format(
"Invalid ExtCameraMode '{}', falling back to type 'classic'...", str));
3171 float Parser::GetArgFloat(
int index)
3173 return (
float) Ogre::StringConverter::parseReal(this->GetArgStr(index), 0.f);
3176 float Parser::ParseArgFloat(
const char* str)
3178 return (
float) Ogre::StringConverter::parseReal(str, 0.f);
3181 float Parser::ParseArgFloat(std::string
const & str)
3183 return this->ParseArgFloat(str.c_str());
3186 unsigned Parser::ParseArgUint(
const char* str)
3189 long res = std::strtol(str,
nullptr, 10);
3193 fmt::format(
"Cannot parse argument '{}' as int, errno: {}", str, errno));
3196 return static_cast<unsigned>(res);
3199 unsigned Parser::ParseArgUint(std::string
const & str)
3201 return this->ParseArgUint(str.c_str());
3204 int Parser::ParseArgInt(
const char* str)
3206 return static_cast<int>(this->ParseArgUint(str));
3209 bool Parser::GetArgBool(
int index)
3211 return Ogre::StringConverter::parseBool(this->GetArgStr(index));
3216 char c = this->GetArgChar(index);
3219 case (
char)WingControlSurface::n_NONE:
3220 case (
char)WingControlSurface::a_RIGHT_AILERON:
3221 case (
char)WingControlSurface::b_LEFT_AILERON:
3222 case (
char)WingControlSurface::f_FLAP:
3223 case (
char)WingControlSurface::e_ELEVATOR:
3224 case (
char)WingControlSurface::r_RUDDER:
3225 case (
char)WingControlSurface::S_RIGHT_HAND_STABILATOR:
3226 case (
char)WingControlSurface::T_LEFT_HAND_STABILATOR:
3227 case (
char)WingControlSurface::c_RIGHT_ELEVON:
3228 case (
char)WingControlSurface::d_LEFT_ELEVON:
3229 case (
char)WingControlSurface::g_RIGHT_FLAPERON:
3230 case (
char)WingControlSurface::h_LEFT_FLAPERON:
3231 case (
char)WingControlSurface::U_RIGHT_HAND_TAILERON:
3232 case (
char)WingControlSurface::V_LEFT_HAND_TAILERON:
3233 case (
char)WingControlSurface::i_RIGHT_RUDDERVATOR:
3234 case (
char)WingControlSurface::j_LEFT_RUDDERVATOR:
3238 fmt::format(
"invalid WingControlSurface '{}', falling back to 'n' (none)", c);
3239 return WingControlSurface::n_NONE;
3243 std::string Parser::GetArgManagedTex(
int index)
3245 std::string tex_name = this->GetArgStr(index);
3246 return (tex_name.at(0) !=
'-') ? tex_name :
"";
3251 switch (this->GetArgStr(index)[0])
3253 case (
char)MinimassOption::l_SKIP_LOADED:
3254 return MinimassOption::l_SKIP_LOADED;
3256 case (
char)MinimassOption::n_DUMMY:
3257 return MinimassOption::n_DUMMY;
3261 fmt::format(
"Not a valid minimass option: {}, falling back to 'n' (dummy)", this->GetArgStr(index)));
3262 return MinimassOption::n_DUMMY;
3269 for (
char c: this->GetArgStr(index))
3273 case (
char)CabOption::n_DUMMY:
break;
3274 case (
char)CabOption::c_CONTACT: ret |= Cab::OPTION_c_CONTACT ;
break;
3275 case (
char)CabOption::b_BUOYANT: ret |= Cab::OPTION_b_BUOYANT ;
break;
3276 case (
char)CabOption::p_10xTOUGHER: ret |= Cab::OPTION_p_10xTOUGHER ;
break;
3277 case (
char)CabOption::u_INVULNERABLE: ret |= Cab::OPTION_u_INVULNERABLE ;
break;
3278 case (
char)CabOption::s_BUOYANT_NO_DRAG: ret |= Cab::OPTION_s_BUOYANT_NO_DRAG ;
break;
3279 case (
char)CabOption::r_BUOYANT_ONLY_DRAG: ret |= Cab::OPTION_r_BUOYANT_ONLY_DRAG ;
break;
3280 case (
char)CabOption::D_CONTACT_BUOYANT: ret |= Cab::OPTION_D_CONTACT_BUOYANT ;
break;
3281 case (
char)CabOption::F_10xTOUGHER_BUOYANT: ret |= Cab::OPTION_F_10xTOUGHER_BUOYANT ;
break;
3282 case (
char)CabOption::S_INVULNERABLE_BUOYANT: ret |= Cab::OPTION_S_INVULNERABLE_BUOYANT;
break;
3295 for (
char c: this->GetArgStr(index))
3299 case (
char)TriggerOption::i_INVISIBLE : ret |= Trigger::OPTION_i_INVISIBLE;
break;
3300 case (
char)TriggerOption::c_COMMAND_STYLE : ret |= Trigger::OPTION_c_COMMAND_STYLE;
break;
3301 case (
char)TriggerOption::x_START_DISABLED : ret |= Trigger::OPTION_x_START_DISABLED;
break;
3302 case (
char)TriggerOption::b_KEY_BLOCKER : ret |= Trigger::OPTION_b_KEY_BLOCKER;
break;
3303 case (
char)TriggerOption::B_TRIGGER_BLOCKER : ret |= Trigger::OPTION_B_TRIGGER_BLOCKER;
break;
3304 case (
char)TriggerOption::A_INV_TRIGGER_BLOCKER: ret |= Trigger::OPTION_A_INV_TRIGGER_BLOCKER;
break;
3305 case (
char)TriggerOption::s_CMD_NUM_SWITCH : ret |= Trigger::OPTION_s_CMD_NUM_SWITCH;
break;
3306 case (
char)TriggerOption::h_UNLOCKS_HOOK_GROUP : ret |= Trigger::OPTION_h_UNLOCKS_HOOK_GROUP;
break;
3307 case (
char)TriggerOption::H_LOCKS_HOOK_GROUP : ret |= Trigger::OPTION_H_LOCKS_HOOK_GROUP;
break;
3308 case (
char)TriggerOption::t_CONTINUOUS : ret |= Trigger::OPTION_t_CONTINUOUS;
break;
3309 case (
char)TriggerOption::E_ENGINE_TRIGGER : ret |= Trigger::OPTION_E_ENGINE_TRIGGER;
break;
3322 for (
char c: this->GetArgStr(index))
3326 case (
char)BeamOption::i_INVISIBLE: ret |= Beam::OPTION_i_INVISIBLE;
break;
3327 case (
char)BeamOption::r_ROPE : ret |= Beam::OPTION_r_ROPE ;
break;
3328 case (
char)BeamOption::s_SUPPORT : ret |= Beam::OPTION_s_SUPPORT ;
break;
3330 case (
char)BeamOption::v_DUMMY:
break;
3343 for (
char c: this->GetArgStr(index))
3347 case (
char)HydroOption::j_INVISIBLE : ret |= Hydro::OPTION_j_INVISIBLE ;
break;
3348 case (
char)HydroOption::s_DISABLE_ON_HIGH_SPEED : ret |= Hydro::OPTION_s_DISABLE_ON_HIGH_SPEED ;
break;
3349 case (
char)HydroOption::a_INPUT_AILERON : ret |= Hydro::OPTION_a_INPUT_AILERON ;
break;
3350 case (
char)HydroOption::r_INPUT_RUDDER : ret |= Hydro::OPTION_r_INPUT_RUDDER ;
break;
3351 case (
char)HydroOption::e_INPUT_ELEVATOR : ret |= Hydro::OPTION_e_INPUT_ELEVATOR ;
break;
3352 case (
char)HydroOption::u_INPUT_AILERON_ELEVATOR : ret |= Hydro::OPTION_u_INPUT_AILERON_ELEVATOR ;
break;
3353 case (
char)HydroOption::v_INPUT_InvAILERON_ELEVATOR: ret |= Hydro::OPTION_v_INPUT_InvAILERON_ELEVATOR;
break;
3354 case (
char)HydroOption::x_INPUT_AILERON_RUDDER : ret |= Hydro::OPTION_x_INPUT_AILERON_RUDDER ;
break;
3355 case (
char)HydroOption::y_INPUT_InvAILERON_RUDDER : ret |= Hydro::OPTION_y_INPUT_InvAILERON_RUDDER ;
break;
3356 case (
char)HydroOption::g_INPUT_ELEVATOR_RUDDER : ret |= Hydro::OPTION_g_INPUT_ELEVATOR_RUDDER ;
break;
3357 case (
char)HydroOption::h_INPUT_InvELEVATOR_RUDDER : ret |= Hydro::OPTION_h_INPUT_InvELEVATOR_RUDDER ;
break;
3358 case (
char)HydroOption::n_INPUT_NORMAL : ret |= Hydro::OPTION_n_INPUT_NORMAL ;
break;
3360 case (
char)HydroOption::i_INVISIBLE_INPUT_NORMAL:
3365 ret |= Hydro::OPTION_n_INPUT_NORMAL;
3367 ret |= Hydro::OPTION_j_INVISIBLE;
3382 for (
char c: this->GetArgStr(index))
3386 case (
char)ShockOption::i_INVISIBLE : ret |= Shock::OPTION_i_INVISIBLE ;
break;
3387 case (
char)ShockOption::L_ACTIVE_LEFT : ret |= Shock::OPTION_L_ACTIVE_LEFT ;
break;
3388 case (
char)ShockOption::R_ACTIVE_RIGHT : ret |= Shock::OPTION_R_ACTIVE_RIGHT;
break;
3389 case (
char)ShockOption::m_METRIC : ret |= Shock::OPTION_m_METRIC ;
break;
3391 case (
char)ShockOption::n_DUMMY:
break;
3392 case (
char)ShockOption::v_DUMMY:
break;
3405 for (
char c: this->GetArgStr(index))
3409 case (
char)Shock2Option::i_INVISIBLE: ret |= Shock2::OPTION_i_INVISIBLE;
break;
3410 case (
char)Shock2Option::s_SOFT_BUMP_BOUNDS: ret |= Shock2::OPTION_s_SOFT_BUMP_BOUNDS;
break;
3411 case (
char)Shock2Option::m_METRIC: ret |= Shock2::OPTION_m_METRIC;
break;
3412 case (
char)Shock2Option::M_ABSOLUTE_METRIC: ret |= Shock2::OPTION_M_ABSOLUTE_METRIC;
break;
3414 case (
char)Shock2Option::n_DUMMY:
break;
3415 case (
char)Shock2Option::v_DUMMY:
break;
3428 for (
char c: this->GetArgStr(index))
3432 case (
char)Shock3Option::i_INVISIBLE: ret |= Shock3::OPTION_i_INVISIBLE;
break;
3433 case (
char)Shock3Option::m_METRIC: ret |= Shock3::OPTION_m_METRIC;
break;
3434 case (
char)Shock3Option::M_ABSOLUTE_METRIC: ret |= Shock3::OPTION_M_ABSOLUTE_METRIC;
break;
3436 case (
char)Shock3Option::n_DUMMY:
break;
3437 case (
char)Shock3Option::v_DUMMY:
break;
3450 for (
char c: this->GetArgStr(index))
3454 case (
char)NodeOption::m_NO_MOUSE_GRAB : ret |= Node::OPTION_m_NO_MOUSE_GRAB ;
break;
3455 case (
char)NodeOption::f_NO_SPARKS : ret |= Node::OPTION_f_NO_SPARKS ;
break;
3456 case (
char)NodeOption::x_EXHAUST_POINT : ret |= Node::OPTION_x_EXHAUST_POINT ;
break;
3457 case (
char)NodeOption::y_EXHAUST_DIRECTION : ret |= Node::OPTION_y_EXHAUST_DIRECTION ;
break;
3458 case (
char)NodeOption::c_NO_GROUND_CONTACT : ret |= Node::OPTION_c_NO_GROUND_CONTACT ;
break;
3459 case (
char)NodeOption::h_HOOK_POINT : ret |= Node::OPTION_h_HOOK_POINT ;
break;
3460 case (
char)NodeOption::e_TERRAIN_EDIT_POINT: ret |= Node::OPTION_e_TERRAIN_EDIT_POINT;
break;
3461 case (
char)NodeOption::b_EXTRA_BUOYANCY : ret |= Node::OPTION_b_EXTRA_BUOYANCY ;
break;
3462 case (
char)NodeOption::p_NO_PARTICLES : ret |= Node::OPTION_p_NO_PARTICLES ;
break;
3463 case (
char)NodeOption::L_LOG : ret |= Node::OPTION_L_LOG ;
break;
3464 case (
char)NodeOption::l_LOAD_WEIGHT : ret |= Node::OPTION_l_LOAD_WEIGHT ;
break;
3466 case (
char)NodeOption::n_DUMMY:
break;
3478 if (str.find(
"leftmirror" ) != std::string::npos) {
return SpecialProp::MIRROR_LEFT; }
3479 if (str.find(
"rightmirror" ) != std::string::npos) {
return SpecialProp::MIRROR_RIGHT; }
3480 if (str.find(
"dashboard-rh") != std::string::npos) {
return SpecialProp::DASHBOARD_RIGHT; }
3481 if (str.find(
"dashboard" ) != std::string::npos) {
return SpecialProp::DASHBOARD_LEFT; }
3482 if (Ogre::StringUtil::startsWith(str,
"spinprop",
false) ) {
return SpecialProp::AERO_PROP_SPIN; }
3483 if (Ogre::StringUtil::startsWith(str,
"pale",
false) ) {
return SpecialProp::AERO_PROP_BLADE; }
3484 if (Ogre::StringUtil::startsWith(str,
"seat",
false) ) {
return SpecialProp::DRIVER_SEAT; }
3485 if (Ogre::StringUtil::startsWith(str,
"seat2",
false) ) {
return SpecialProp::DRIVER_SEAT_2; }
3486 if (Ogre::StringUtil::startsWith(str,
"beacon",
false) ) {
return SpecialProp::BEACON; }
3487 if (Ogre::StringUtil::startsWith(str,
"redbeacon",
false)) {
return SpecialProp::REDBEACON; }
3488 if (Ogre::StringUtil::startsWith(str,
"lightb",
false) ) {
return SpecialProp::LIGHTBAR; }
3489 return SpecialProp::NONE;
3494 char c = this->GetArgChar(index);
3497 case (
char)EngineType::t_TRUCK:
3498 case (
char)EngineType::c_CAR:
3499 case (
char)EngineType::e_ECAR:
3503 fmt::format(
"invalid EngineType '{}', falling back to 't' (truck)", c);
3504 return EngineType::t_TRUCK;
3510 std::string str = this->GetArgStr(index);
3511 if (str ==
"mesh_standard")
return ManagedMaterialType::MESH_STANDARD;
3512 if (str ==
"mesh_transparent")
return ManagedMaterialType::MESH_TRANSPARENT;
3513 if (str ==
"flexmesh_standard")
return ManagedMaterialType::FLEXMESH_STANDARD;
3514 if (str ==
"flexmesh_transparent")
return ManagedMaterialType::FLEXMESH_TRANSPARENT;
3517 fmt::format(
"Not a valid ManagedMaterialType: '{}'", str));
3518 return ManagedMaterialType::INVALID;
3523 int role = this->GetArgInt(index);
3532 fmt::format(
"Invalid value of 'camera role' ({}), videocamera will not work", role));
3537 int Parser::TokenizeCurrentLine()
3540 const char* cur_char = m_current_line;
3542 while ((*cur_char !=
'\0') && (cur_arg < Parser::LINE_MAX_ARGS))
3545 if ((arg_len == 0) && is_arg)
3547 m_args[cur_arg].start = cur_char;
3550 else if ((arg_len > 0) && !is_arg)
3552 m_args[cur_arg].length = arg_len;
3564 m_args[cur_arg].length = arg_len;
3568 m_num_args = cur_arg;
3572 void Parser::ProcessOgreStream(Ogre::DataStream* stream, Ogre::String resource_group)
3574 m_resource_group = resource_group;
3575 m_filename = stream->getName();
3577 char raw_line_buf[LINE_BUFFER_LENGTH];
3578 while (!stream->eof())
3582 stream->readLine(raw_line_buf, LINE_BUFFER_LENGTH - 1);
3583 raw_line_buf[LINE_BUFFER_LENGTH - 1] =
'\0';
3585 catch (Ogre::Exception &ex)
3588 fmt::format(
"Could not read truck file: {}", ex.getFullDescription()));
3592 this->ProcessRawLine(raw_line_buf);
3596 void Parser::ProcessRawLine(
const char* raw_line_buf)
3598 const char* raw_start = raw_line_buf;
3599 const char* raw_end = raw_line_buf +
strnlen(raw_line_buf, LINE_BUFFER_LENGTH);
3602 while (
IsWhitespace(*raw_start) && (raw_start != raw_end))
3608 if (raw_start == raw_end)
3610 ++m_current_line_number;
3615 if ((*raw_start ==
';') || (*raw_start ==
'/'))
3617 m_pending_doc_comment.comment_text += raw_line_buf;
3618 m_pending_doc_comment.comment_text +=
'\n';
3619 ++m_current_line_number;
3624 memset(m_current_line, 0, LINE_BUFFER_LENGTH);
3625 char* out_start = m_current_line;
3626 utf8::replace_invalid(raw_start, raw_end, out_start,
'?');
3629 this->ProcessCurrentLine();
3630 ++m_current_line_number;