RigsofRods
Soft-body Physics Simulation
ODefFileFormat.h
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2016-2017 Petr Ohlidal
4 
5  For more information, see http://www.rigsofrods.org/
6 
7  Rigs of Rods is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License version 3, as
9  published by the Free Software Foundation.
10 
11  Rigs of Rods is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "SimData.h"
23 
24 #include <OgreColourValue.h>
25 #include <OgreDataStream.h>
26 #include <OgreVector3.h>
27 
28 #include <memory>
29 #include <string>
30 
31 #ifdef DELETE // Windows hack: The `EventType::DELETE` name collides with `DELETE` from <winnt.h> which *MAY* be included at this point.
32 # undef DELETE
33 #endif
34 
35 namespace RoR {
36 
38 {
39  ODefCollisionBox(Ogre::Vector3 min, Ogre::Vector3 max, Ogre::Vector3 rot,
40  Ogre::Vector3 campos, Ogre::Vector3 dir, Ogre::Vector3 scal,
41  std::string ev_name, CollisionEventFilter ev_filter, bool is_rot, bool is_virt, bool forcecam):
42 
43  aabb_min(min), aabb_max(max), box_rot(rot), cam_pos(campos), direction(dir), scale(scal),
44  event_name(ev_name), event_filter(ev_filter),
45  is_rotating(is_rot), is_virtual(is_virt), force_cam_pos(forcecam)
46  {}
47 
48  Ogre::Vector3 aabb_min;
49  Ogre::Vector3 aabb_max;
50  Ogre::Vector3 box_rot;
51  Ogre::Vector3 cam_pos;
52  Ogre::Vector3 direction;
53  Ogre::Vector3 scale;
54  std::string event_name;
56 
57  // Flags
58  bool is_rotating:1;
59  bool is_virtual:1;
60  bool force_cam_pos:1;
61 };
62 
64 {
65  ODefCollisionMesh(std::string meshname, Ogre::Vector3 scal, std::string gmodelname):
66  mesh_name(meshname), scale(scal), groundmodel_name(gmodelname)
67  {}
68 
69  std::string mesh_name;
70  Ogre::Vector3 scale;
71  std::string groundmodel_name;
72 };
73 
75 {
76  std::string instance_name;
77  std::string template_name;
78  Ogre::Vector3 pos = Ogre::Vector3::ZERO;
79  float scale = 0.f;
80 };
81 
83 {
84  float speed_min=0.f, speed_max=0.f;
85  std::string name;
86 };
87 
89 {
90  std::string font_name;
91  int font_size = 0;
92  int font_dpi = 0;
93  std::string text;
94  char option = '\0';
95 
96  float x=0, y=0, w=0, h=0;
97  float a=0, r=0, g=0, b=0;
98 };
99 
101 {
102  Ogre::Vector3 pos = Ogre::Vector3::ZERO;
103  Ogre::Vector3 dir = Ogre::Vector3::ZERO;
104  float range = 0.f;
105  float angle_inner = 0.f;
106  float angle_outer = 0.f;
107  Ogre::ColourValue color = Ogre::ColourValue::Black;
108 };
109 
111 {
112  Ogre::Vector3 pos = Ogre::Vector3::ZERO;
113  Ogre::Vector3 dir = Ogre::Vector3::ZERO;
114  float range = 0.f;
115  Ogre::ColourValue color = Ogre::ColourValue::Black;
116 };
117 
118 struct ODefFile
119 {
121  {
122  std::string mesh_name;
123  Ogre::Vector3 scale;
124  bool cast_shadows = true;
125  } header;
126 
127  bool mode_standard = false;
128  std::vector<LocalizerType> localizers;
129  std::list<std::string> sounds;
130  std::list<std::string> groundmodel_files;
131  std::list<ODefCollisionBox> collision_boxes;
132  std::list<ODefCollisionMesh> collision_meshes;
133  std::list<ODefParticleSys> particle_systems;
134  std::list<ODefAnimation> animations;
135  std::list<ODefTexPrint> texture_prints;
136  std::list<ODefSpotlight> spotlights;
137  std::list<ODefPointLight> point_lights;
138  std::string mat_name;
139  std::string mat_name_generate;
140 };
141 
142 // -----------------------------------------------------------------------------
144 {
145 public:
146  void Prepare();
147  bool ProcessLine(const char* line);
148  void ProcessOgreStream(Ogre::DataStream* stream);
149  std::shared_ptr<ODefFile> Finalize();
150 
151 private:
152  bool ProcessCurrentLine();
153  void ResetCBoxContext();
154 
156  {
158  std::string header_mesh_name;
159  Ogre::Vector3 header_scale;
160  // Collision boxes or meshes
161  Ogre::Vector3 cbox_direction;
165  Ogre::Vector3 cbox_rotation;
166  Ogre::Vector3 cbox_cam_pos;
168  std::string cbox_event_name;
169  std::string cbox_mesh_name;
171  Ogre::Vector3 cbox_aabb_min;
172  Ogre::Vector3 cbox_aabb_max;
173  } m_ctx;
174 
175  std::shared_ptr<ODefFile> m_def;
177  const char* m_cur_line;
178 };
179 
180 } // namespace RoR
RoR::ODefFile::ODefFileHeader
Definition: ODefFileFormat.h:120
RoR::ODefSpotlight::range
float range
Definition: ODefFileFormat.h:104
RoR::ODefFile::mode_standard
bool mode_standard
Definition: ODefFileFormat.h:127
RoR::ODefTexPrint::option
char option
Definition: ODefFileFormat.h:94
RoR::ODefParser::ODefParserContext::cbox_aabb_min
Ogre::Vector3 cbox_aabb_min
Definition: ODefFileFormat.h:171
RoR::ODefAnimation::name
std::string name
Definition: ODefFileFormat.h:85
RoR::ODefTexPrint::y
float y
Definition: ODefFileFormat.h:96
RoR::ODefTexPrint
Definition: ODefFileFormat.h:88
RoR::ODefSpotlight::dir
Ogre::Vector3 dir
Definition: ODefFileFormat.h:103
RoR::ODefParser::ProcessOgreStream
void ProcessOgreStream(Ogre::DataStream *stream)
Definition: ODefFileFormat.cpp:30
RoR::ODefParser::m_def
std::shared_ptr< ODefFile > m_def
Definition: ODefFileFormat.h:175
RoR::ODefFile::texture_prints
std::list< ODefTexPrint > texture_prints
Section 'drawTextOnMeshTexture'.
Definition: ODefFileFormat.h:135
RoR::ODefParser::Finalize
std::shared_ptr< ODefFile > Finalize()
Passes ownership.
Definition: ODefFileFormat.cpp:61
RoR::ODefParser::m_ctx
struct RoR::ODefParser::ODefParserContext m_ctx
Parser context.
RoR::ODefTexPrint::r
float r
Definition: ODefFileFormat.h:97
RoR::ODefParser::ODefParserContext::header_done
bool header_done
Definition: ODefFileFormat.h:157
RoR::CollisionEventFilter
CollisionEventFilter
Definition: SimData.h:45
RoR::ODefCollisionBox::cam_pos
Ogre::Vector3 cam_pos
Definition: ODefFileFormat.h:51
RoR::ODefCollisionBox::is_virtual
bool is_virtual
Definition: ODefFileFormat.h:59
RoR::ODefTexPrint::a
float a
Definition: ODefFileFormat.h:97
RoR::ODefParticleSys::template_name
std::string template_name
Definition: ODefFileFormat.h:77
RoR::ODefPointLight
Definition: ODefFileFormat.h:110
RoR::ODefParser::ODefParserContext::cbox_direction
Ogre::Vector3 cbox_direction
Definition: ODefFileFormat.h:161
RoR::ODefTexPrint::x
float x
Definition: ODefFileFormat.h:96
RoR::ODefCollisionBox::scale
Ogre::Vector3 scale
Definition: ODefFileFormat.h:53
RoR::ODefTexPrint::font_dpi
int font_dpi
Definition: ODefFileFormat.h:92
RoR::ODefCollisionBox::is_rotating
bool is_rotating
Definition: ODefFileFormat.h:58
RoR::ODefCollisionMesh::groundmodel_name
std::string groundmodel_name
Definition: ODefFileFormat.h:71
RoR::ODefFile::collision_boxes
std::list< ODefCollisionBox > collision_boxes
Definition: ODefFileFormat.h:131
RoR::ODefCollisionBox::aabb_max
Ogre::Vector3 aabb_max
Definition: ODefFileFormat.h:49
RoR::ODefParser::ODefParserContext::cbox_event_filter
CollisionEventFilter cbox_event_filter
Definition: ODefFileFormat.h:167
RoR::ODefFile::header
struct RoR::ODefFile::ODefFileHeader header
RoR::ODefParticleSys::pos
Ogre::Vector3 pos
Definition: ODefFileFormat.h:78
RoR::ODefParser::ODefParserContext::header_mesh_name
std::string header_mesh_name
Definition: ODefFileFormat.h:158
RoR::ODefParticleSys::instance_name
std::string instance_name
Definition: ODefFileFormat.h:76
RoR::ODefTexPrint::g
float g
Definition: ODefFileFormat.h:97
RoR::ODefCollisionMesh
Definition: ODefFileFormat.h:63
RoR::ODefFile::groundmodel_files
std::list< std::string > groundmodel_files
Definition: ODefFileFormat.h:130
RoR::ODefParser::ODefParserContext::header_scale
Ogre::Vector3 header_scale
Definition: ODefFileFormat.h:159
RoR::ODefSpotlight::angle_outer
float angle_outer
Degrees.
Definition: ODefFileFormat.h:106
SimData.h
Core data structures for simulation; Everything affected by by either physics, network or user intera...
RoR::ODefParser::ODefParserContext::cbox_aabb_max
Ogre::Vector3 cbox_aabb_max
Definition: ODefFileFormat.h:172
RoR::ODefFile::collision_meshes
std::list< ODefCollisionMesh > collision_meshes
Definition: ODefFileFormat.h:132
RoR::ODefFile::animations
std::list< ODefAnimation > animations
Definition: ODefFileFormat.h:134
RoR::ODefParticleSys
Definition: ODefFileFormat.h:74
RoR::ODefFile::ODefFileHeader::scale
Ogre::Vector3 scale
Definition: ODefFileFormat.h:123
RoR::ODefCollisionBox::box_rot
Ogre::Vector3 box_rot
Definition: ODefFileFormat.h:50
RoR::ODefCollisionBox::force_cam_pos
bool force_cam_pos
Definition: ODefFileFormat.h:60
RoR::ODefFile::spotlights
std::list< ODefSpotlight > spotlights
Definition: ODefFileFormat.h:136
RoR::ODefPointLight::pos
Ogre::Vector3 pos
Definition: ODefFileFormat.h:112
RoR::ODefFile::point_lights
std::list< ODefPointLight > point_lights
Definition: ODefFileFormat.h:137
RoR::ODefParser::ODefParserContext::cbox_groundmodel_name
std::string cbox_groundmodel_name
Definition: ODefFileFormat.h:170
RoR::ODefParser::m_cur_line
const char * m_cur_line
Definition: ODefFileFormat.h:177
RoR::ODefParser::ODefParserContext::cbox_is_rotating
bool cbox_is_rotating
Definition: ODefFileFormat.h:162
RoR::ODefPointLight::dir
Ogre::Vector3 dir
Definition: ODefFileFormat.h:113
RoR::ODefPointLight::range
float range
Definition: ODefFileFormat.h:114
RoR::ODefCollisionBox
Definition: ODefFileFormat.h:37
RoR::ODefTexPrint::font_name
std::string font_name
Definition: ODefFileFormat.h:90
RoR::ODefParser::ODefParserContext::cbox_rotation
Ogre::Vector3 cbox_rotation
Definition: ODefFileFormat.h:165
RoR::ODefSpotlight::color
Ogre::ColourValue color
Definition: ODefFileFormat.h:107
RoR::ODefParser::ProcessLine
bool ProcessLine(const char *line)
Definition: ODefFileFormat.cpp:41
RoR::ODefSpotlight::pos
Ogre::Vector3 pos
Definition: ODefFileFormat.h:102
RoR::ODefCollisionBox::ODefCollisionBox
ODefCollisionBox(Ogre::Vector3 min, Ogre::Vector3 max, Ogre::Vector3 rot, Ogre::Vector3 campos, Ogre::Vector3 dir, Ogre::Vector3 scal, std::string ev_name, CollisionEventFilter ev_filter, bool is_rot, bool is_virt, bool forcecam)
Definition: ODefFileFormat.h:39
RoR::ODefCollisionBox::direction
Ogre::Vector3 direction
Definition: ODefFileFormat.h:52
RoR::ODefPointLight::color
Ogre::ColourValue color
Definition: ODefFileFormat.h:115
RoR::ODefParser::Prepare
void Prepare()
Definition: ODefFileFormat.cpp:53
RoR::ODefFile::particle_systems
std::list< ODefParticleSys > particle_systems
Definition: ODefFileFormat.h:133
RoR::ODefCollisionMesh::ODefCollisionMesh
ODefCollisionMesh(std::string meshname, Ogre::Vector3 scal, std::string gmodelname)
Definition: ODefFileFormat.h:65
RoR::ODefTexPrint::b
float b
Definition: ODefFileFormat.h:97
RoR::ODefAnimation::speed_min
float speed_min
Definition: ODefFileFormat.h:84
RoR::ODefParser::ResetCBoxContext
void ResetCBoxContext()
Definition: ODefFileFormat.cpp:303
RoR::ODefCollisionMesh::scale
Ogre::Vector3 scale
Definition: ODefFileFormat.h:70
RoR::ODefParser::ODefParserContext::cbox_force_cam
bool cbox_force_cam
Definition: ODefFileFormat.h:164
RoR::ODefCollisionBox::aabb_min
Ogre::Vector3 aabb_min
Definition: ODefFileFormat.h:48
RoR::ODefFile::mat_name_generate
std::string mat_name_generate
Section 'generateMaterialShaders'.
Definition: ODefFileFormat.h:139
RoR::ODefParser::ODefParserContext::cbox_cam_pos
Ogre::Vector3 cbox_cam_pos
Section 'forcecamera'.
Definition: ODefFileFormat.h:166
RoR::ODefCollisionMesh::mesh_name
std::string mesh_name
Definition: ODefFileFormat.h:69
RoR::ODefParser::ODefParserContext::cbox_event_name
std::string cbox_event_name
Definition: ODefFileFormat.h:168
RoR::ODefTexPrint::font_size
int font_size
Definition: ODefFileFormat.h:91
RoR::ODefParser
Definition: ODefFileFormat.h:143
RoR::ODefFile::ODefFileHeader::mesh_name
std::string mesh_name
Definition: ODefFileFormat.h:122
RoR::ODefAnimation::speed_max
float speed_max
Definition: ODefFileFormat.h:84
RoR::ODefFile
Definition: ODefFileFormat.h:118
RoR::ODefTexPrint::w
float w
Definition: ODefFileFormat.h:96
RoR::ODefParser::ODefParserContext::cbox_is_virtual
bool cbox_is_virtual
Definition: ODefFileFormat.h:163
RoR::ODefParser::m_line_number
int m_line_number
Definition: ODefFileFormat.h:176
RoR::ODefParser::ODefParserContext
Definition: ODefFileFormat.h:155
RoR::ODefFile::sounds
std::list< std::string > sounds
Definition: ODefFileFormat.h:129
RoR::ODefTexPrint::text
std::string text
Definition: ODefFileFormat.h:93
RoR::ODefFile::localizers
std::vector< LocalizerType > localizers
Definition: ODefFileFormat.h:128
RoR::ODefFile::ODefFileHeader::cast_shadows
bool cast_shadows
Definition: ODefFileFormat.h:124
RoR::ODefParser::ProcessCurrentLine
bool ProcessCurrentLine()
Definition: ODefFileFormat.cpp:74
RoR
Definition: AppContext.h:36
RoR::ODefFile::mat_name
std::string mat_name
Section 'setMeshMaterial'.
Definition: ODefFileFormat.h:138
RoR::ODefAnimation
Definition: ODefFileFormat.h:82
RoR::ODefParticleSys::scale
float scale
Definition: ODefFileFormat.h:79
RoR::ODefSpotlight
Definition: ODefFileFormat.h:100
RoR::ODefParser::ODefParserContext::cbox_mesh_name
std::string cbox_mesh_name
Definition: ODefFileFormat.h:169
RoR::ODefCollisionBox::event_name
std::string event_name
Definition: ODefFileFormat.h:54
RoR::ODefCollisionBox::event_filter
CollisionEventFilter event_filter
Definition: ODefFileFormat.h:55
RoR::ODefTexPrint::h
float h
Definition: ODefFileFormat.h:96
RoR::ODefSpotlight::angle_inner
float angle_inner
Degrees.
Definition: ODefFileFormat.h:105