| 349 | } |
| 350 | |
| 351 | void CRender::LoadSectors(IReader* fs) |
| 352 | { |
| 353 | // allocate memory for portals |
| 354 | const u32 size = fs->find_chunk(fsL_PORTALS); |
| 355 | R_ASSERT(0 == size % sizeof(CPortal::level_portal_data_t)); |
| 356 | |
| 357 | // load sectors |
| 358 | xr_vector<CSector::level_sector_data_t> sectors_data; |
| 359 | |
| 360 | float largest_sector_vol = 0.0f; |
| 361 | |
| 362 | // load sectors |
| 363 | IReader* S = fs->open_chunk(fsL_SECTORS); |
| 364 | for (u32 i = 0;; i++) |
| 365 | { |
| 366 | IReader* P = S->open_chunk(i); |
| 367 | if (!P) |
| 368 | break; |
| 369 | |
| 370 | { |
| 371 | u32 size = P->find_chunk(fsP_Portals); |
| 372 | R_ASSERT(0 == (size & 1)); |
| 373 | u32 portals_in_sector = size / sizeof(u16); |
| 374 | |
| 375 | auto& sector_data = sectors_data.emplace_back(); |
| 376 | sector_data.portals_id.reserve(portals_in_sector); |
| 377 | while (portals_in_sector) |
| 378 | { |
| 379 | const u16 ID = P->r_u16(); |
| 380 | sector_data.portals_id.emplace_back(ID); |
| 381 | --portals_in_sector; |
| 382 | } |
| 383 | |
| 384 | size = P->find_chunk(fsP_Root); |
| 385 | R_ASSERT(size == 4); |
| 386 | sector_data.root_id = P->r_u32(); |
| 387 | |
| 388 | // Search for default sector - assume "default" or "outdoor" sector is the largest one |
| 389 | // XXX: hack: need to know real outdoor sector |
| 390 | auto* V = smart_cast<dxRender_Visual*>(RImplementation.getVisual(sector_data.root_id)); |
| 391 | const float vol = V->getVisData().box.getvolume(); |
| 392 | if (vol > largest_sector_vol) |
| 393 | { |
| 394 | largest_sector_vol = vol; |
| 395 | largest_sector_id = /*static_cast<IRender_Sector::sector_id_t>*/(i); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | P->close(); |
| 400 | } |
| 401 | S->close(); |
| 402 | |
| 403 | const u32 portals_count = size / sizeof(CPortal::level_portal_data_t); |
| 404 | xr_vector<CPortal::level_portal_data_t> portals_data{portals_count}; |
| 405 | |
| 406 | // load portals |
| 407 | if (portals_count) |
| 408 | { |
nothing calls this directly
no test coverage detected