33 bool keep_reading =
true;
34 while (keep_reading && !stream->eof())
37 keep_reading = this->ProcessLine(raw_line_buf);
44 if ((line !=
nullptr) && (line[0] != 0))
47 result = this->ProcessCurrentLine();
55 m_ctx.header_done =
false;
56 m_ctx.header_scale = Ogre::Vector3::ZERO;
57 this->ResetCBoxContext();
58 m_def = std::make_shared<ODefFile>();
63 std::shared_ptr<ODefFile> def = m_def;
68 inline bool StartsWith(std::string
const & line,
const char* test)
70 return line.compare(0, strlen(test), test) == 0;
76 if (!m_ctx.header_done)
78 if (strcmp(m_cur_line,
"LOD") == 0)
83 if (m_ctx.header_mesh_name.empty())
85 m_ctx.header_mesh_name = m_cur_line;
89 sscanf(m_cur_line,
"%f, %f, %f", &m_ctx.header_scale.x, &m_ctx.header_scale.y, &m_ctx.header_scale.z);
91 m_def->header.mesh_name = m_ctx.header_mesh_name;
92 m_def->header.scale = m_ctx.header_scale;
93 m_ctx.header_done =
true;
97 std::string line_str = m_cur_line;
98 Ogre::StringUtil::trim(line_str);
100 if ((line_str[0] == 0) || (line_str[0] ==
'/') || (line_str[0] ==
';'))
105 if (line_str ==
"end")
110 if (line_str ==
"movable")
114 else if (line_str ==
"standard")
116 m_def->mode_standard =
true;
120 if (line_str.compare(10, 3,
"vor") == 0) { m_def->localizers.push_back(
LOCALIZER_VOR );
return true; }
121 if (line_str.compare(10, 3,
"ndb") == 0) { m_def->localizers.push_back(
LOCALIZER_NDB );
return true; }
122 if (line_str.compare(10, 1,
"v" ) == 0) { m_def->localizers.push_back(
LOCALIZER_VERTICAL );
return true; }
123 if (line_str.compare(10, 1,
"h" ) == 0) { m_def->localizers.push_back(
LOCALIZER_HORIZONTAL);
return true; }
125 LOG(
"[RoR|ODef] Invalid line: " + line_str);
130 sscanf(line_str.c_str(),
"sound %200s", tmp);
131 m_def->sounds.push_back(tmp);
133 else if (
StartsWith(line_str,
"particleSystem"))
136 char instance_name[201] =
"";
137 char template_name[201] =
"";
138 int res = sscanf(line_str.c_str(),
"particleSystem %f, %f, %f, %f, %200s %200s",
139 &psys.
scale, &psys.
pos.x, &psys.
pos.y, &psys.
pos.z, instance_name, template_name);
145 m_def->particle_systems.push_back(psys);
148 else if (
StartsWith(line_str,
"setMeshMaterial") && line_str.length() > 16)
150 m_def->mat_name = line_str.substr(16);
152 else if (
StartsWith(line_str,
"generateMaterialShaders") && line_str.length() > 24)
154 m_def->mat_name_generate = line_str.substr(24);
156 else if (
StartsWith(line_str,
"playanimation"))
159 char anim_name[201] =
"";
160 sscanf(line_str.c_str(),
"playanimation %f, %f, %200s", &anim.
speed_min, &anim.
speed_max, anim_name);
161 anim.
name = anim_name;
164 m_def->animations.push_back(anim);
167 else if (
StartsWith(line_str,
"drawTextOnMeshTexture"))
170 char font_name[201] =
"";
172 int res = sscanf(line_str.c_str(),
173 "drawTextOnMeshTexture %f, %f, %f, %f, %f, %f, %f, %f, %c, %i, %i, %200s %500s",
174 &tp.
x, &tp.
y, &tp.
w, &tp.
h, &tp.
r, &tp.
g, &tp.
b, &tp.
a,
181 m_def->texture_prints.push_back(tp);
184 LOG(
"[RoR|ODef] Warning: invalid 'drawTextOnMeshTexture' line.");
189 int res = sscanf(line_str.c_str(),
"spotlight %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f",
194 m_def->spotlights.push_back(sl);
198 LOG(
"[RoR|ODef] Warning: invalid 'spotlight' line.");
204 int res = sscanf(line_str.c_str(),
"pointlight %f, %f, %f, %f, %f, %f, %f, %f, %f, %f",
209 m_def->point_lights.push_back(pl);
213 LOG(
"[RoR|ODef] Warning: invalid 'pointlight' line.");
218 else if ((line_str ==
"beginbox") || (line_str ==
"beginmesh"))
220 this->ResetCBoxContext();
224 sscanf(line_str.c_str(),
"boxcoords %f, %f, %f, %f, %f, %f",
225 &m_ctx.cbox_aabb_min.x, &m_ctx.cbox_aabb_max.x,
226 &m_ctx.cbox_aabb_min.y, &m_ctx.cbox_aabb_max.y,
227 &m_ctx.cbox_aabb_min.z, &m_ctx.cbox_aabb_max.z);
232 sscanf(line_str.c_str(),
"mesh %200s", tmp);
233 m_ctx.cbox_mesh_name = tmp;
237 sscanf(line_str.c_str(),
"rotate %f, %f, %f",
238 &m_ctx.cbox_rotation.x, &m_ctx.cbox_rotation.y, &m_ctx.cbox_rotation.z);
239 m_ctx.cbox_is_rotating =
true;
243 sscanf(line_str.c_str(),
"forcecamera %f, %f, %f",
244 &m_ctx.cbox_cam_pos.x, &m_ctx.cbox_cam_pos.y, &m_ctx.cbox_cam_pos.z);
245 m_ctx.cbox_force_cam =
true;
249 sscanf(line_str.c_str(),
"direction %f, %f, %f",
250 &m_ctx.cbox_direction.x, &m_ctx.cbox_direction.y, &m_ctx.cbox_direction.z);
252 else if (
StartsWith(line_str,
"frictionconfig") && line_str.length() > 15)
254 m_def->groundmodel_files.push_back(line_str.substr(15));
256 else if ((
StartsWith(line_str,
"stdfriction") ||
StartsWith(line_str,
"usefriction")) && line_str.length() > 12)
258 m_ctx.cbox_groundmodel_name = line_str.substr(12);
260 else if (line_str ==
"virtual")
262 m_ctx.cbox_is_virtual =
true;
266 char ev_name[301] =
"";
267 char ev_type[301] =
"";
268 sscanf(line_str.c_str(),
"event %300s %300s", ev_name, ev_type);
269 m_ctx.cbox_event_name = ev_name;
271 if (!strncmp(ev_type,
"avatar", 6)) { m_ctx.cbox_event_filter =
EVENT_AVATAR; }
272 else if (!strncmp(ev_type,
"truck_wheels", 12)) { m_ctx.cbox_event_filter =
EVENT_TRUCK_WHEELS; }
273 else if (!strncmp(ev_type,
"truck", 5)) { m_ctx.cbox_event_filter =
EVENT_TRUCK; }
274 else if (!strncmp(ev_type,
"airplane", 8)) { m_ctx.cbox_event_filter =
EVENT_AIRPLANE; }
275 else if (!strncmp(ev_type,
"boat", 4)) { m_ctx.cbox_event_filter =
EVENT_BOAT; }
276 else { m_ctx.cbox_event_filter =
EVENT_ALL; }
279 if (!strncmp(ev_name,
"spawnzone", 9)) { m_ctx.cbox_event_filter =
EVENT_AVATAR; }
281 else if (line_str ==
"endbox")
283 m_def->collision_boxes.emplace_back(
284 m_ctx.cbox_aabb_min, m_ctx.cbox_aabb_max,
285 m_ctx.cbox_rotation, m_ctx.cbox_cam_pos,
286 m_ctx.cbox_direction, m_ctx.header_scale,
287 m_ctx.cbox_event_name, m_ctx.cbox_event_filter,
288 m_ctx.cbox_is_rotating, m_ctx.cbox_is_virtual, m_ctx.cbox_force_cam);
290 else if (line_str ==
"endmesh")
292 m_def->collision_meshes.emplace_back(
293 m_ctx.cbox_mesh_name, m_ctx.header_scale, m_ctx.cbox_groundmodel_name);
295 else if (line_str ==
"nocast")
297 m_def->header.cast_shadows =
false;
305 m_ctx.cbox_direction = Ogre::Vector3::ZERO;
306 m_ctx.cbox_is_rotating =
false;
307 m_ctx.cbox_is_virtual =
false;
308 m_ctx.cbox_force_cam =
false;
310 m_ctx.cbox_event_name.clear();
311 m_ctx.cbox_mesh_name.clear();
312 m_ctx.cbox_groundmodel_name =
"concrete";