| 4270 | } |
| 4271 | |
| 4272 | static int ParseCollisionNormalsFile(SceneGraph* scenegraph, const std::vector<char>& file) { |
| 4273 | PROFILER_ZONE(g_profiler_ctx, "ParseCollisionNormalsFile"); |
| 4274 | char header_buf[64] = {'\0'}; |
| 4275 | int index = 0; |
| 4276 | memread(header_buf, strlen(kCollisionNormalIdentifier), 1, file, index); |
| 4277 | if (strcmp(header_buf, kCollisionNormalIdentifier) != 0) { |
| 4278 | const int kBufSize = 512; |
| 4279 | char buf[kBufSize]; |
| 4280 | FormatString(buf, kBufSize, "Collision normal header '%s' does not match expected '%s'", header_buf, kCollisionNormalIdentifier); |
| 4281 | DisplayError("Error", buf); |
| 4282 | return -1; |
| 4283 | } |
| 4284 | int version; |
| 4285 | memread(&version, sizeof(int), 1, file, index); |
| 4286 | if (version <= 0 || version > kCollisionNormalVersion) { |
| 4287 | const int kBufSize = 512; |
| 4288 | char buf[kBufSize]; |
| 4289 | FormatString(buf, kBufSize, "Collision normal version '%d' does not match expected '%d'", version, kCollisionNormalVersion); |
| 4290 | DisplayError("Error", buf); |
| 4291 | return -2; |
| 4292 | } |
| 4293 | int num_objects; |
| 4294 | memread(&num_objects, sizeof(int), 1, file, index); |
| 4295 | std::vector<vec4> normal_buf; |
| 4296 | std::vector<int> ledge_line_buf; |
| 4297 | for (int i = 0; i < num_objects; ++i) { |
| 4298 | int id; |
| 4299 | memread(&id, sizeof(int), 1, file, index); |
| 4300 | Object* obj = scenegraph->GetObjectFromID(id); |
| 4301 | int num_normals; |
| 4302 | memread(&num_normals, sizeof(int), 1, file, index); |
| 4303 | normal_buf.resize(num_normals); |
| 4304 | if (num_normals > 0) { |
| 4305 | memread(&normal_buf[0], sizeof(vec4) * num_normals, 1, file, index); |
| 4306 | } |
| 4307 | if (version >= 2) { |
| 4308 | int num_ledge_lines; |
| 4309 | memread(&num_ledge_lines, sizeof(int), 1, file, index); |
| 4310 | if (num_ledge_lines > 0) { |
| 4311 | ledge_line_buf.resize(num_ledge_lines); |
| 4312 | memread(&ledge_line_buf[0], sizeof(int) * num_ledge_lines, 1, file, index); |
| 4313 | } |
| 4314 | } |
| 4315 | if (obj && obj->GetType() == _env_object) { |
| 4316 | EnvObject* eo = (EnvObject*)obj; |
| 4317 | eo->normal_override_custom = normal_buf; |
| 4318 | eo->normal_override_buffer_dirty = true; |
| 4319 | if (version >= 2) { |
| 4320 | eo->ledge_lines = ledge_line_buf; |
| 4321 | } |
| 4322 | } |
| 4323 | } |
| 4324 | return 0; |
| 4325 | } |
| 4326 | |
| 4327 | void LoadCollisionNormals(SceneGraph* scenegraph) { |
| 4328 | PROFILER_ZONE(g_profiler_ctx, "LoadCollisionNormals"); |
no test coverage detected